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: 2016-02-09 Functions: 9 11 81.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Tue, 09 Feb 2016 10:48:38 +0000 (2 days ago)

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