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: 53 62 85.5 %
Date: 2014-07-21 Functions: 10 11 90.9 %
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      329659 : ZEND_API int zend_stack_init(zend_stack *stack)
      26             : {
      27      329659 :         stack->top = 0;
      28      329659 :         stack->max = 0;
      29      329659 :         stack->elements = NULL;
      30      329659 :         return SUCCESS;
      31             : }
      32             : 
      33     2833388 : ZEND_API int zend_stack_push(zend_stack *stack, const void *element, int size)
      34             : {
      35     2833388 :         if (stack->top >= stack->max) {                /* we need to allocate more memory */
      36      125675 :                 stack->elements = (void **) erealloc(stack->elements,
      37             :                                    (sizeof(void **) * (stack->max += STACK_BLOCK_SIZE)));
      38      125675 :                 if (!stack->elements) {
      39           0 :                         return FAILURE;
      40             :                 }
      41             :         }
      42     2833388 :         stack->elements[stack->top] = (void *) emalloc(size);
      43     2833388 :         memcpy(stack->elements[stack->top], element, size);
      44     2833388 :         return stack->top++;
      45             : }
      46             : 
      47             : 
      48     2826153 : ZEND_API int zend_stack_top(const zend_stack *stack, void **element)
      49             : {
      50     2826153 :         if (stack->top > 0) {
      51     2820655 :                 *element = stack->elements[stack->top - 1];
      52     2820655 :                 return SUCCESS;
      53             :         } else {
      54        5498 :                 *element = NULL;
      55        5498 :                 return FAILURE;
      56             :         }
      57             : }
      58             : 
      59             : 
      60     1961216 : ZEND_API int zend_stack_del_top(zend_stack *stack)
      61             : {
      62     1961216 :         if (stack->top > 0) {
      63     1961216 :                 efree(stack->elements[--stack->top]);
      64             :         }
      65     1961216 :         return SUCCESS;
      66             : }
      67             : 
      68             : 
      69           0 : ZEND_API int zend_stack_int_top(const zend_stack *stack)
      70             : {
      71             :         int *e;
      72             : 
      73           0 :         if (zend_stack_top(stack, (void **) &e) == FAILURE) {
      74           0 :                 return FAILURE;                 /* this must be a negative number, since negative numbers can't be address numbers */
      75             :         } else {
      76           0 :                 return *e;
      77             :         }
      78             : }
      79             : 
      80             : 
      81      201223 : ZEND_API int zend_stack_is_empty(const zend_stack *stack)
      82             : {
      83      201223 :         if (stack->top == 0) {
      84           1 :                 return 1;
      85             :         } else {
      86      201222 :                 return 0;
      87             :         }
      88             : }
      89             : 
      90             : 
      91      309113 : ZEND_API int zend_stack_destroy(zend_stack *stack)
      92             : {
      93             :         int i;
      94             : 
      95      309113 :         if (stack->elements) {
      96      996617 :                 for (i = 0; i < stack->top; i++) {
      97      872115 :                         efree(stack->elements[i]);
      98             :                 }
      99      124502 :                 efree(stack->elements);
     100      124502 :                 stack->elements = NULL;
     101             :         }
     102             : 
     103      309113 :         return SUCCESS;
     104             : }
     105             : 
     106             : 
     107           5 : ZEND_API void **zend_stack_base(const zend_stack *stack)
     108             : {
     109           5 :         return stack->elements;
     110             : }
     111             : 
     112             : 
     113      770777 : ZEND_API int zend_stack_count(const zend_stack *stack)
     114             : {
     115      770777 :         return stack->top;
     116             : }
     117             : 
     118             : 
     119      228158 : ZEND_API void zend_stack_apply(zend_stack *stack, int type, int (*apply_function)(void *element))
     120             : {
     121             :         int i;
     122             : 
     123      228158 :         switch (type) {
     124             :                 case ZEND_STACK_APPLY_TOPDOWN:
     125      228789 :                         for (i=stack->top-1; i>=0; i--) {
     126      163555 :                                 if (apply_function(stack->elements[i])) {
     127      162924 :                                         break;
     128             :                                 }
     129             :                         }
     130      228158 :                         break;
     131             :                 case ZEND_STACK_APPLY_BOTTOMUP:
     132           0 :                         for (i=0; i<stack->top; i++) {
     133           0 :                                 if (apply_function(stack->elements[i])) {
     134           0 :                                         break;
     135             :                                 }
     136             :                         }
     137             :                         break;
     138             :         }
     139      228158 : }
     140             : 
     141             : 
     142      713026 : ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
     143             : {
     144             :         int i;
     145             : 
     146      713026 :         switch (type) {
     147             :                 case ZEND_STACK_APPLY_TOPDOWN:
     148      713017 :                         for (i=stack->top-1; i>=0; i--) {
     149      713017 :                                 if (apply_function(stack->elements[i], arg)) {
     150      713017 :                                         break;
     151             :                                 }
     152             :                         }
     153      713017 :                         break;
     154             :                 case ZEND_STACK_APPLY_BOTTOMUP:
     155          27 :                         for (i=0; i<stack->top; i++) {
     156          18 :                                 if (apply_function(stack->elements[i], arg)) {
     157           0 :                                         break;
     158             :                                 }
     159             :                         }
     160             :                         break;
     161             :         }
     162      713026 : }
     163             : 
     164             : /*
     165             :  * Local variables:
     166             :  * tab-width: 4
     167             :  * c-basic-offset: 4
     168             :  * indent-tabs-mode: t
     169             :  * End:
     170             :  */

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:06 +0000 (2 days ago)

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