LTP GCOV extension - code coverage report
Current view: directory - Zend - zend_ptr_stack.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 44
Code covered: 47.7 % Executed lines: 21
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_ptr_stack.c,v 1.23.2.1.2.1 2007/01/01 09:35:47 sebastian Exp $ */
      21                 : 
      22                 : #include "zend.h"
      23                 : #include "zend_ptr_stack.h"
      24                 : #ifdef HAVE_STDARG_H
      25                 : # include <stdarg.h>
      26                 : #endif
      27                 : 
      28                 : ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack)
      29             876 : {
      30             876 :         stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE);
      31             876 :         stack->max = PTR_STACK_BLOCK_SIZE;
      32             876 :         stack->top = 0;
      33             876 : }
      34                 : 
      35                 : 
      36                 : ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...)
      37               0 : {
      38                 :         va_list ptr;
      39                 :         void *elem;
      40                 :         
      41               0 :         ZEND_PTR_STACK_RESIZE_IF_NEEDED(stack, count)
      42                 : 
      43               0 :         va_start(ptr, count);
      44               0 :         while (count>0) {
      45               0 :                 elem = va_arg(ptr, void *);
      46               0 :                 stack->top++;
      47               0 :                 *(stack->top_element++) = elem;
      48               0 :                 count--;
      49                 :         }
      50               0 :         va_end(ptr);
      51               0 : }
      52                 : 
      53                 : 
      54                 : ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...)
      55               0 : {
      56                 :         va_list ptr;
      57                 :         void **elem;
      58                 :         
      59               0 :         va_start(ptr, count);
      60               0 :         while (count>0) {
      61               0 :                 elem = va_arg(ptr, void **);
      62               0 :                 *elem = *(--stack->top_element);
      63               0 :                 stack->top--;
      64               0 :                 count--;
      65                 :         }
      66               0 :         va_end(ptr);
      67               0 : }
      68                 : 
      69                 : 
      70                 : 
      71                 : ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack)
      72             876 : {
      73             876 :         if (stack->elements) {
      74             876 :                 efree(stack->elements);
      75                 :         }
      76             876 : }
      77                 : 
      78                 : 
      79                 : ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *))
      80             438 : {
      81             438 :         int i = stack->top;
      82                 : 
      83             876 :         while (--i >= 0) {
      84               0 :                 func(stack->elements[i]);
      85                 :         }
      86             438 : }
      87                 : 
      88                 : 
      89                 : ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *), zend_bool free_elements)
      90             438 : {
      91             438 :         zend_ptr_stack_apply(stack, func);
      92             438 :         if (free_elements) {
      93             438 :                 int i = stack->top;
      94                 : 
      95             876 :                 while (--i >= 0) {
      96               0 :                         efree(stack->elements[i]);
      97                 :                 }
      98                 :         }
      99             438 :         stack->top = 0;
     100             438 :         stack->top_element = stack->elements;
     101             438 : }
     102                 : 
     103                 : 
     104                 : ZEND_API int zend_ptr_stack_num_elements(zend_ptr_stack *stack)
     105               0 : {
     106               0 :         return stack->top;
     107                 : }
     108                 : 
     109                 : /*
     110                 :  * Local variables:
     111                 :  * tab-width: 4
     112                 :  * c-basic-offset: 4
     113                 :  * indent-tabs-mode: t
     114                 :  * End:
     115                 :  */

Generated by: LTP GCOV extension version 1.5