PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_stack.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 56 65 86.2 %
Date: 2014-10-22 Functions: 11 12 91.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        | 
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #include "zend.h"
      23             : #include "zend_stack.h"
      24             : 
      25             : #define ZEND_STACK_ELEMENT(stack, n) ((void *)((char *) (stack)->elements + (stack)->size * (n)))
      26             : 
      27      233466 : ZEND_API int zend_stack_init(zend_stack *stack, int size)
      28             : {
      29      233466 :         stack->size = size;
      30      233466 :         stack->top = 0;
      31      233466 :         stack->max = 0;
      32      233466 :         stack->elements = NULL;
      33      233466 :         return SUCCESS;
      34             : }
      35             : 
      36     1312398 : ZEND_API int zend_stack_push(zend_stack *stack, const void *element)
      37             : {
      38             :         /* We need to allocate more memory */
      39     1312398 :         if (stack->top >= stack->max) {
      40      115827 :                 stack->max += STACK_BLOCK_SIZE;
      41      115827 :                 stack->elements = safe_erealloc(stack->elements, stack->size, stack->max, 0);
      42             :         }
      43     1312398 :         memcpy(ZEND_STACK_ELEMENT(stack, stack->top), element, stack->size);
      44     1312398 :         return stack->top++;
      45             : }
      46             : 
      47             : 
      48      480467 : ZEND_API void *zend_stack_top(const zend_stack *stack)
      49             : {
      50      480467 :         if (stack->top > 0) {
      51      474983 :                 return ZEND_STACK_ELEMENT(stack, stack->top - 1);
      52             :         } else {
      53        5484 :                 return NULL;
      54             :         }
      55             : }
      56             : 
      57             : 
      58      339384 : ZEND_API int zend_stack_del_top(zend_stack *stack)
      59             : {
      60      339384 :         --stack->top;
      61      339384 :         return SUCCESS;
      62             : }
      63             : 
      64             : 
      65           0 : ZEND_API int zend_stack_int_top(const zend_stack *stack)
      66             : {
      67           0 :         int *e = zend_stack_top(stack);
      68           0 :         if (e) {
      69           0 :                 return *e;
      70             :         } else {
      71           0 :                 return FAILURE;
      72             :         }
      73             : }
      74             : 
      75             : 
      76      181812 : ZEND_API int zend_stack_is_empty(const zend_stack *stack)
      77             : {
      78      181812 :         return stack->top == 0;
      79             : }
      80             : 
      81             : 
      82      213939 : ZEND_API int zend_stack_destroy(zend_stack *stack)
      83             : {
      84      213939 :         if (stack->elements) {
      85       70559 :                 efree(stack->elements);
      86       70559 :                 stack->elements = NULL;
      87             :         }
      88             : 
      89      213939 :         return SUCCESS;
      90             : }
      91             : 
      92             : 
      93      127553 : ZEND_API void *zend_stack_base(const zend_stack *stack)
      94             : {
      95      127553 :         return stack->elements;
      96             : }
      97             : 
      98             : 
      99      969419 : ZEND_API int zend_stack_count(const zend_stack *stack)
     100             : {
     101      969419 :         return stack->top;
     102             : }
     103             : 
     104             : 
     105       43566 : ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element))
     106             : {
     107             :         int i;
     108             : 
     109       43566 :         switch (type) {
     110             :                 case ZEND_STACK_APPLY_TOPDOWN:
     111       44176 :                         for (i=stack->top-1; i>=0; i--) {
     112       43574 :                                 if (apply_function(ZEND_STACK_ELEMENT(stack, i))) {
     113       42964 :                                         break;
     114             :                                 }
     115             :                         }
     116       43566 :                         break;
     117             :                 case ZEND_STACK_APPLY_BOTTOMUP:
     118           0 :                         for (i=0; i<stack->top; i++) {
     119           0 :                                 if (apply_function(ZEND_STACK_ELEMENT(stack, i))) {
     120           0 :                                         break;
     121             :                                 }
     122             :                         }
     123             :                         break;
     124             :         }
     125       43566 : }
     126             : 
     127             : 
     128      657519 : ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
     129             : {
     130             :         int i;
     131             : 
     132      657519 :         switch (type) {
     133             :                 case ZEND_STACK_APPLY_TOPDOWN:
     134      657510 :                         for (i=stack->top-1; i>=0; i--) {
     135      657510 :                                 if (apply_function(ZEND_STACK_ELEMENT(stack, i), arg)) {
     136      657510 :                                         break;
     137             :                                 }
     138             :                         }
     139      657510 :                         break;
     140             :                 case ZEND_STACK_APPLY_BOTTOMUP:
     141          27 :                         for (i=0; i<stack->top; i++) {
     142          18 :                                 if (apply_function(ZEND_STACK_ELEMENT(stack, i), arg)) {
     143           0 :                                         break;
     144             :                                 }
     145             :                         }
     146             :                         break;
     147             :         }
     148      657519 : }
     149             : 
     150       61248 : ZEND_API void zend_stack_clean(zend_stack *stack, void (*func)(void *), zend_bool free_elements)
     151             : {
     152             :         int i;
     153             : 
     154       61248 :         if (func) {
     155       40838 :                 for (i = 0; i < stack->top; i++) {
     156           6 :                         func(ZEND_STACK_ELEMENT(stack, i));
     157             :                 }
     158             :         }
     159       61248 :         if (free_elements) {
     160       61248 :                 if (stack->elements) {
     161           7 :                         efree(stack->elements);
     162           7 :                         stack->elements = NULL;
     163             :                 }
     164       61248 :                 stack->top = stack->max = 0;
     165             :         }
     166       61248 : }
     167             : 
     168             : /*
     169             :  * Local variables:
     170             :  * tab-width: 4
     171             :  * c-basic-offset: 4
     172             :  * indent-tabs-mode: t
     173             :  * End:
     174             :  */

Generated by: LCOV version 1.10

Generated at Wed, 22 Oct 2014 07:24:45 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.