LTP GCOV extension - code coverage report
Current view: directory - Zend - zend_stack.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 63
Code covered: 49.2 % Executed lines: 31
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | Zend Engine                                                          |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1998-2007 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: zend_stack.c,v 1.16.2.1.2.1 2007/01/01 09:35:47 sebastian Exp $ */
      21                 : 
      22                 : #include "zend.h"
      23                 : #include "zend_stack.h"
      24                 : 
      25                 : ZEND_API int zend_stack_init(zend_stack *stack)
      26            1971 : {
      27            1971 :         stack->top = 0;
      28            1971 :         stack->elements = (void **) emalloc(sizeof(void **) * STACK_BLOCK_SIZE);
      29            1971 :         if (!stack->elements) {
      30               0 :                 return FAILURE;
      31                 :         } else {
      32            1971 :                 stack->max = STACK_BLOCK_SIZE;
      33            1971 :                 return SUCCESS;
      34                 :         }
      35                 : }
      36                 : 
      37                 : ZEND_API int zend_stack_push(zend_stack *stack, void *element, int size)
      38           14546 : {
      39           14546 :         if (stack->top >= stack->max) {                /* we need to allocate more memory */
      40               0 :                 stack->elements = (void **) erealloc(stack->elements,
      41                 :                                    (sizeof(void **) * (stack->max += STACK_BLOCK_SIZE)));
      42               0 :                 if (!stack->elements) {
      43               0 :                         return FAILURE;
      44                 :                 }
      45                 :         }
      46           14546 :         stack->elements[stack->top] = (void *) emalloc(size);
      47           14546 :         memcpy(stack->elements[stack->top], element, size);
      48           14546 :         return stack->top++;
      49                 : }
      50                 : 
      51                 : 
      52                 : ZEND_API int zend_stack_top(zend_stack *stack, void **element)
      53           16435 : {
      54           16435 :         if (stack->top > 0) {
      55           16435 :                 *element = stack->elements[stack->top - 1];
      56           16435 :                 return SUCCESS;
      57                 :         } else {
      58               0 :                 *element = NULL;
      59               0 :                 return FAILURE;
      60                 :         }
      61                 : }
      62                 : 
      63                 : 
      64                 : ZEND_API int zend_stack_del_top(zend_stack *stack)
      65           14546 : {
      66           14546 :         if (stack->top > 0) {
      67           14546 :                 efree(stack->elements[--stack->top]);
      68                 :         }
      69           14546 :         return SUCCESS;
      70                 : }
      71                 : 
      72                 : 
      73                 : ZEND_API int zend_stack_int_top(zend_stack *stack)
      74               0 : {
      75                 :         int *e;
      76                 : 
      77               0 :         if (zend_stack_top(stack, (void **) &e) == FAILURE) {
      78               0 :                 return FAILURE;                 /* this must be a negative number, since negative numbers can't be address numbers */
      79                 :         } else {
      80               0 :                 return *e;
      81                 :         }
      82                 : }
      83                 : 
      84                 : 
      85                 : ZEND_API int zend_stack_is_empty(zend_stack *stack)
      86               0 : {
      87               0 :         if (stack->top == 0) {
      88               0 :                 return 1;
      89                 :         } else {
      90               0 :                 return 0;
      91                 :         }
      92                 : }
      93                 : 
      94                 : 
      95                 : ZEND_API int zend_stack_destroy(zend_stack *stack)
      96            1971 : {
      97                 :         register int i;
      98                 : 
      99            1971 :         for (i = 0; i < stack->top; i++) {
     100               0 :                 efree(stack->elements[i]);
     101                 :         }
     102                 : 
     103            1971 :         if (stack->elements) {
     104            1971 :                 efree(stack->elements);
     105                 :         }
     106            1971 :         return SUCCESS;
     107                 : }
     108                 : 
     109                 : 
     110                 : ZEND_API void **zend_stack_base(zend_stack *stack)
     111               0 : {
     112               0 :         return stack->elements;
     113                 : }
     114                 : 
     115                 : 
     116                 : ZEND_API int zend_stack_count(zend_stack *stack)
     117               0 : {
     118               0 :         return stack->top;
     119                 : }
     120                 : 
     121                 : 
     122                 : ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element))
     123            2556 : {
     124                 :         int i;
     125                 : 
     126            2556 :         switch (type) {
     127                 :                 case ZEND_STACK_APPLY_TOPDOWN:
     128            2556 :                         for (i=stack->top-1; i>=0; i--) {
     129            1884 :                                 if (apply_function(stack->elements[i])) {
     130            1884 :                                         break;
     131                 :                                 }
     132                 :                         }
     133            2556 :                         break;
     134                 :                 case ZEND_STACK_APPLY_BOTTOMUP:
     135               0 :                         for (i=0; i<stack->top; i++) {
     136               0 :                                 if (apply_function(stack->elements[i])) {
     137               0 :                                         break;
     138                 :                                 }
     139                 :                         }
     140                 :                         break;
     141                 :         }
     142            2556 : }
     143                 : 
     144                 : 
     145                 : ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
     146               0 : {
     147                 :         int i;
     148                 : 
     149               0 :         switch (type) {
     150                 :                 case ZEND_STACK_APPLY_TOPDOWN:
     151               0 :                         for (i=stack->top-1; i>=0; i--) {
     152               0 :                                 if (apply_function(stack->elements[i], arg)) {
     153               0 :                                         break;
     154                 :                                 }
     155                 :                         }
     156               0 :                         break;
     157                 :                 case ZEND_STACK_APPLY_BOTTOMUP:
     158               0 :                         for (i=0; i<stack->top; i++) {
     159               0 :                                 if (apply_function(stack->elements[i], arg)) {
     160               0 :                                         break;
     161                 :                                 }
     162                 :                         }
     163                 :                         break;
     164                 :         }
     165               0 : }
     166                 : 
     167                 : /*
     168                 :  * Local variables:
     169                 :  * tab-width: 4
     170                 :  * c-basic-offset: 4
     171                 :  * indent-tabs-mode: t
     172                 :  * End:
     173                 :  */

Generated by: LTP GCOV extension version 1.5