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

LTP GCOV extension - code coverage report
Current view: directory - var/php_gcov/PHP_5_2/Zend - zend_stack.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 63
Code covered: 58.7 % Executed lines: 37
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | Zend Engine                                                          |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1998-2009 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 272374 2008-12-31 11:17:49Z sebastian $ */
      21                 : 
      22                 : #include "zend.h"
      23                 : #include "zend_stack.h"
      24                 : 
      25                 : ZEND_API int zend_stack_init(zend_stack *stack)
      26          122282 : {
      27          122282 :         stack->top = 0;
      28          122282 :         stack->elements = (void **) emalloc(sizeof(void **) * STACK_BLOCK_SIZE);
      29          122282 :         if (!stack->elements) {
      30               0 :                 return FAILURE;
      31                 :         } else {
      32          122282 :                 stack->max = STACK_BLOCK_SIZE;
      33          122282 :                 return SUCCESS;
      34                 :         }
      35                 : }
      36                 : 
      37                 : ZEND_API int zend_stack_push(zend_stack *stack, void *element, int size)
      38          627641 : {
      39          627641 :         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          627641 :         stack->elements[stack->top] = (void *) emalloc(size);
      47          627641 :         memcpy(stack->elements[stack->top], element, size);
      48          627641 :         return stack->top++;
      49                 : }
      50                 : 
      51                 : 
      52                 : ZEND_API int zend_stack_top(zend_stack *stack, void **element)
      53          731388 : {
      54          731388 :         if (stack->top > 0) {
      55          731388 :                 *element = stack->elements[stack->top - 1];
      56          731388 :                 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          627543 : {
      66          627543 :         if (stack->top > 0) {
      67          627543 :                 efree(stack->elements[--stack->top]);
      68                 :         }
      69          627543 :         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          122406 : {
      97                 :         register int i;
      98                 : 
      99          122498 :         for (i = 0; i < stack->top; i++) {
     100              92 :                 efree(stack->elements[i]);
     101                 :         }
     102                 : 
     103          122406 :         if (stack->elements) {
     104          122406 :                 efree(stack->elements);
     105                 :         }
     106          122406 :         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           95570 : {
     124                 :         int i;
     125                 : 
     126           95570 :         switch (type) {
     127                 :                 case ZEND_STACK_APPLY_TOPDOWN:
     128           96234 :                         for (i=stack->top-1; i>=0; i--) {
     129           58574 :                                 if (apply_function(stack->elements[i])) {
     130           57910 :                                         break;
     131                 :                                 }
     132                 :                         }
     133           95570 :                         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           95570 : }
     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               6 : {
     147                 :         int i;
     148                 : 
     149               6 :         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              22 :                         for (i=0; i<stack->top; i++) {
     159              16 :                                 if (apply_function(stack->elements[i], arg)) {
     160               0 :                                         break;
     161                 :                                 }
     162                 :                         }
     163                 :                         break;
     164                 :         }
     165               6 : }
     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

Generated at Thu, 19 Nov 2009 08:20:04 +0000 (5 days ago)

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