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

Generated by: LCOV version 1.10

Generated at Wed, 24 Aug 2016 12:20:17 +0000 (3 hours ago)

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