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_objects_API.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 99 112 88.4 %
Date: 2015-08-29 Functions: 9 11 81.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 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_globals.h"
      24             : #include "zend_variables.h"
      25             : #include "zend_API.h"
      26             : #include "zend_objects_API.h"
      27             : 
      28       21248 : ZEND_API void zend_objects_store_init(zend_objects_store *objects, uint32_t init_size)
      29             : {
      30       21248 :         objects->object_buckets = (zend_object **) emalloc(init_size * sizeof(zend_object*));
      31       21248 :         objects->top = 1; /* Skip 0 so that handles are true */
      32       21248 :         objects->size = init_size;
      33       21248 :         objects->free_list_head = -1;
      34       21248 :         memset(&objects->object_buckets[0], 0, sizeof(zend_object*));
      35       21248 : }
      36             : 
      37       21286 : ZEND_API void zend_objects_store_destroy(zend_objects_store *objects)
      38             : {
      39       21286 :         efree(objects->object_buckets);
      40       21286 :         objects->object_buckets = NULL;
      41       21286 : }
      42             : 
      43       21286 : ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects)
      44             : {
      45       21286 :         if (objects->top > 1) {
      46        7470 :                 zend_object **obj_ptr = objects->object_buckets + 1;
      47        7470 :                 zend_object **end = objects->object_buckets + objects->top;
      48             : 
      49             :                 do {
      50      187952 :                         zend_object *obj = *obj_ptr;
      51             : 
      52      187952 :                         if (IS_OBJ_VALID(obj)) {
      53      102574 :                                 if (!(GC_FLAGS(obj) & IS_OBJ_DESTRUCTOR_CALLED)) {
      54      101887 :                                         GC_FLAGS(obj) |= IS_OBJ_DESTRUCTOR_CALLED;
      55      101887 :                                         GC_REFCOUNT(obj)++;
      56      101887 :                                         obj->handlers->dtor_obj(obj);
      57      101887 :                                         GC_REFCOUNT(obj)--;
      58             :                                 }
      59             :                         }
      60      187952 :                         obj_ptr++;
      61      187952 :                 } while (obj_ptr != end);
      62             :         }
      63       21286 : }
      64             : 
      65         924 : ZEND_API void zend_objects_store_mark_destructed(zend_objects_store *objects)
      66             : {
      67         924 :         if (objects->object_buckets && objects->top > 1) {
      68         547 :                 zend_object **obj_ptr = objects->object_buckets + 1;
      69         547 :                 zend_object **end = objects->object_buckets + objects->top;
      70             : 
      71             :                 do {
      72        1098 :                         zend_object *obj = *obj_ptr;
      73             : 
      74        1098 :                         if (IS_OBJ_VALID(obj)) {
      75         986 :                                 GC_FLAGS(obj) |= IS_OBJ_DESTRUCTOR_CALLED;
      76             :                         }
      77        1098 :                         obj_ptr++;
      78        1098 :                 } while (obj_ptr != end);
      79             :         }
      80         924 : }
      81             : 
      82       21286 : ZEND_API void zend_objects_store_free_object_storage(zend_objects_store *objects)
      83             : {
      84             :         zend_object **obj_ptr, **end, *obj;
      85             : 
      86       21286 :         if (objects->top <= 1) {
      87       13814 :                 return;
      88             :         }
      89             : 
      90             :         /* Free object contents, but don't free objects themselves, so they show up as leaks */
      91        7472 :         end = objects->object_buckets + 1;
      92        7472 :         obj_ptr = objects->object_buckets + objects->top;
      93             : 
      94             :         do {
      95      187960 :                 obj_ptr--;
      96      187960 :                 obj = *obj_ptr;
      97      187960 :                 if (IS_OBJ_VALID(obj)) {
      98        9509 :                         if (!(GC_FLAGS(obj) & IS_OBJ_FREE_CALLED)) {
      99        9509 :                                 GC_FLAGS(obj) |= IS_OBJ_FREE_CALLED;
     100        9509 :                                 if (obj->handlers->free_obj) {
     101        9509 :                                         GC_REFCOUNT(obj)++;
     102        9509 :                                         obj->handlers->free_obj(obj);
     103        9509 :                                         GC_REFCOUNT(obj)--;
     104             :                                 }
     105             :                         }
     106             :                 }
     107      187960 :         } while (obj_ptr != end);
     108             : }
     109             : 
     110             : 
     111             : /* Store objects API */
     112             : 
     113     1469931 : ZEND_API void zend_objects_store_put(zend_object *object)
     114             : {
     115             :         int handle;
     116             : 
     117     1469931 :         if (EG(objects_store).free_list_head != -1) {
     118     1281978 :                 handle = EG(objects_store).free_list_head;
     119     1281978 :                 EG(objects_store).free_list_head = GET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle]);
     120             :         } else {
     121      187953 :                 if (EG(objects_store).top == EG(objects_store).size) {
     122          31 :                         EG(objects_store).size <<= 1;
     123          31 :                         EG(objects_store).object_buckets = (zend_object **) erealloc(EG(objects_store).object_buckets, EG(objects_store).size * sizeof(zend_object*));
     124             :                 }
     125      187953 :                 handle = EG(objects_store).top++;
     126             :         }
     127     1469931 :         object->handle = handle;
     128     1469931 :         EG(objects_store).object_buckets[handle] = object;
     129     1469931 : }
     130             : 
     131             : #define ZEND_OBJECTS_STORE_ADD_TO_FREE_LIST(handle)                                                                                                                     \
     132             :             SET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle], EG(objects_store).free_list_head);  \
     133             :                         EG(objects_store).free_list_head = handle;
     134             : 
     135           0 : ZEND_API void zend_objects_store_free(zend_object *object) /* {{{ */
     136             : {
     137           0 :         uint32_t handle = object->handle;
     138           0 :         void *ptr = ((char*)object) - object->handlers->offset;
     139             : 
     140           0 :         GC_REMOVE_FROM_BUFFER(object);
     141           0 :         efree(ptr);
     142           0 :         ZEND_OBJECTS_STORE_ADD_TO_FREE_LIST(handle);
     143           0 : }
     144             : /* }}} */
     145             : 
     146     1371865 : ZEND_API void zend_objects_store_del(zend_object *object) /* {{{ */
     147             : {
     148             :         /*      Make sure we hold a reference count during the destructor call
     149             :                 otherwise, when the destructor ends the storage might be freed
     150             :                 when the refcount reaches 0 a second time
     151             :          */
     152     2743730 :         if (EG(objects_store).object_buckets &&
     153     1371865 :             IS_OBJ_VALID(EG(objects_store).object_buckets[object->handle])) {
     154     1371811 :                 if (GC_REFCOUNT(object) == 0) {
     155     1371811 :                         int failure = 0;
     156             : 
     157     1371811 :                         if (!(GC_FLAGS(object) & IS_OBJ_DESTRUCTOR_CALLED)) {
     158     1287977 :                                 GC_FLAGS(object) |= IS_OBJ_DESTRUCTOR_CALLED;
     159             : 
     160     1287977 :                                 if (object->handlers->dtor_obj) {
     161     1287977 :                                         GC_REFCOUNT(object)++;
     162     1287977 :                                         zend_try {
     163     1287977 :                                                 object->handlers->dtor_obj(object);
     164           4 :                                         } zend_catch {
     165           4 :                                                 failure = 1;
     166     1287977 :                                         } zend_end_try();
     167     1287977 :                                         GC_REFCOUNT(object)--;
     168             :                                 }
     169             :                         }
     170             : 
     171     1371811 :                         if (GC_REFCOUNT(object) == 0) {
     172     1371804 :                                 uint32_t handle = object->handle;
     173             :                                 void *ptr;
     174             : 
     175     1371804 :                                 EG(objects_store).object_buckets[handle] = SET_OBJ_INVALID(object);
     176     1371804 :                                 if (!(GC_FLAGS(object) & IS_OBJ_FREE_CALLED)) {
     177     1371750 :                                         GC_FLAGS(object) |= IS_OBJ_FREE_CALLED;
     178     1371750 :                                         if (object->handlers->free_obj) {
     179     1371750 :                                                 zend_try {
     180     1371750 :                                                         GC_REFCOUNT(object)++;
     181     1371750 :                                                         object->handlers->free_obj(object);
     182     1371750 :                                                         GC_REFCOUNT(object)--;
     183           0 :                                                 } zend_catch {
     184           0 :                                                         failure = 1;
     185     1371750 :                                                 } zend_end_try();
     186             :                                         }
     187             :                                 }
     188     1371804 :                                 ptr = ((char*)object) - object->handlers->offset;
     189     1371804 :                                 GC_REMOVE_FROM_BUFFER(object);
     190     1371804 :                                 efree(ptr);
     191     1371804 :                                 ZEND_OBJECTS_STORE_ADD_TO_FREE_LIST(handle);
     192             :                         }
     193             : 
     194     1371811 :                         if (failure) {
     195           4 :                                 zend_bailout();
     196             :                         }
     197             :                 } else {
     198           0 :                         GC_REFCOUNT(object)--;
     199             :                 }
     200             :         }
     201     1371861 : }
     202             : /* }}} */
     203             : 
     204             : /* zend_object_store_set_object:
     205             :  * It is ONLY valid to call this function from within the constructor of an
     206             :  * overloaded object.  Its purpose is to set the object pointer for the object
     207             :  * when you can't possibly know its value until you have parsed the arguments
     208             :  * from the constructor function.  You MUST NOT use this function for any other
     209             :  * weird games, or call it at any other time after the object is constructed.
     210             :  * */
     211           0 : ZEND_API void zend_object_store_set_object(zval *zobject, zend_object *object)
     212             : {
     213           0 :         EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(zobject)] = object;
     214           0 : }
     215             : 
     216             : /* Called when the ctor was terminated by an exception */
     217         409 : ZEND_API void zend_object_store_ctor_failed(zend_object *obj)
     218             : {
     219         409 :         GC_FLAGS(obj) |= IS_OBJ_DESTRUCTOR_CALLED;
     220         409 : }
     221             : 
     222     1022376 : ZEND_API zend_object_handlers *zend_get_std_object_handlers(void)
     223             : {
     224     1022376 :         return &std_object_handlers;
     225             : }
     226             : 
     227             : /*
     228             :  * Local variables:
     229             :  * tab-width: 4
     230             :  * c-basic-offset: 4
     231             :  * indent-tabs-mode: t
     232             :  * End:
     233             :  */

Generated by: LCOV version 1.10

Generated at Sat, 29 Aug 2015 10:22:11 +0000 (38 hours ago)

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