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: 43 63 68.3 %
Date: 2014-07-13 Functions: 8 11 72.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2013 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      281560 : ZEND_API int zend_stack_init(zend_stack *stack)
      26             : {
      27      281560 :         stack->top = 0;
      28      281560 :         stack->elements = (void **) emalloc(sizeof(void **) * STACK_BLOCK_SIZE);
      29      281560 :         if (!stack->elements) {
      30           0 :                 return FAILURE;
      31             :         } else {
      32      281560 :                 stack->max = STACK_BLOCK_SIZE;
      33      281560 :                 return SUCCESS;
      34             :         }
      35             : }
      36             : 
      37     2740297 : ZEND_API int zend_stack_push(zend_stack *stack, const void *element, int size)
      38             : {
      39     2740297 :         if (stack->top >= stack->max) {                /* we need to allocate more memory */
      40        1248 :                 stack->elements = (void **) erealloc(stack->elements,
      41             :                                    (sizeof(void **) * (stack->max += STACK_BLOCK_SIZE)));
      42        1248 :                 if (!stack->elements) {
      43           0 :                         return FAILURE;
      44             :                 }
      45             :         }
      46     2740297 :         stack->elements[stack->top] = (void *) emalloc(size);
      47     2740297 :         memcpy(stack->elements[stack->top], element, size);
      48     2740297 :         return stack->top++;
      49             : }
      50             : 
      51             : 
      52     2559082 : ZEND_API int zend_stack_top(const zend_stack *stack, void **element)
      53             : {
      54     2559082 :         if (stack->top > 0) {
      55     2559082 :                 *element = stack->elements[stack->top - 1];
      56     2559082 :                 return SUCCESS;
      57             :         } else {
      58           0 :                 *element = NULL;
      59           0 :                 return FAILURE;
      60             :         }
      61             : }
      62             : 
      63             : 
      64     1996774 : ZEND_API int zend_stack_del_top(zend_stack *stack)
      65             : {
      66     1996774 :         if (stack->top > 0) {
      67     1996774 :                 efree(stack->elements[--stack->top]);
      68             :         }
      69     1996774 :         return SUCCESS;
      70             : }
      71             : 
      72             : 
      73           0 : ZEND_API int zend_stack_int_top(const zend_stack *stack)
      74             : {
      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      198513 : ZEND_API int zend_stack_is_empty(const zend_stack *stack)
      86             : {
      87      198513 :         if (stack->top == 0) {
      88       29388 :                 return 1;
      89             :         } else {
      90      169125 :                 return 0;
      91             :         }
      92             : }
      93             : 
      94             : 
      95      281474 : ZEND_API int zend_stack_destroy(zend_stack *stack)
      96             : {
      97             :         int i;
      98             : 
      99      281474 :         if (stack->elements) {
     100     1024977 :                 for (i = 0; i < stack->top; i++) {
     101      743507 :                         efree(stack->elements[i]);
     102             :                 }
     103             : 
     104      281470 :                 efree(stack->elements);
     105             :         }
     106             : 
     107      281474 :         return SUCCESS;
     108             : }
     109             : 
     110             : 
     111           0 : ZEND_API void **zend_stack_base(const zend_stack *stack)
     112             : {
     113           0 :         return stack->elements;
     114             : }
     115             : 
     116             : 
     117           0 : ZEND_API int zend_stack_count(const zend_stack *stack)
     118             : {
     119           0 :         return stack->top;
     120             : }
     121             : 
     122             : 
     123      233150 : ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element))
     124             : {
     125             :         int i;
     126             : 
     127      233150 :         switch (type) {
     128             :                 case ZEND_STACK_APPLY_TOPDOWN:
     129      233763 :                         for (i=stack->top-1; i>=0; i--) {
     130      173763 :                                 if (apply_function(stack->elements[i])) {
     131      173150 :                                         break;
     132             :                                 }
     133             :                         }
     134      233150 :                         break;
     135             :                 case ZEND_STACK_APPLY_BOTTOMUP:
     136           0 :                         for (i=0; i<stack->top; i++) {
     137           0 :                                 if (apply_function(stack->elements[i])) {
     138           0 :                                         break;
     139             :                                 }
     140             :                         }
     141             :                         break;
     142             :         }
     143      233150 : }
     144             : 
     145             : 
     146           6 : ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
     147             : {
     148             :         int i;
     149             : 
     150           6 :         switch (type) {
     151             :                 case ZEND_STACK_APPLY_TOPDOWN:
     152           0 :                         for (i=stack->top-1; i>=0; i--) {
     153           0 :                                 if (apply_function(stack->elements[i], arg)) {
     154           0 :                                         break;
     155             :                                 }
     156             :                         }
     157           0 :                         break;
     158             :                 case ZEND_STACK_APPLY_BOTTOMUP:
     159          22 :                         for (i=0; i<stack->top; i++) {
     160          16 :                                 if (apply_function(stack->elements[i], arg)) {
     161           0 :                                         break;
     162             :                                 }
     163             :                         }
     164             :                         break;
     165             :         }
     166           6 : }
     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 Sun, 13 Jul 2014 23:57:45 +0000 (8 days ago)

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