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.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 81 82 98.8 %
Date: 2014-04-08 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2013 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_interfaces.h"
      27             : #include "zend_exceptions.h"
      28             : 
      29      947815 : ZEND_API void zend_object_std_init(zend_object *object, zend_class_entry *ce TSRMLS_DC)
      30             : {
      31      947815 :         ALLOC_HASHTABLE(object->properties);
      32      947815 :         zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
      33             : 
      34      947815 :         object->ce = ce;     
      35      947815 :         object->guards = NULL;
      36      947815 : }
      37             : 
      38     1738121 : ZEND_API void zend_object_std_dtor(zend_object *object TSRMLS_DC)
      39             : {
      40     1738121 :         if (object->guards) {
      41          66 :                 zend_hash_destroy(object->guards);
      42          66 :                 FREE_HASHTABLE(object->guards);              
      43             :         }
      44     1738121 :         if (object->properties) {
      45     1738121 :                 zend_hash_destroy(object->properties);
      46     1738121 :                 FREE_HASHTABLE(object->properties);
      47             :         }
      48     1738121 : }
      49             : 
      50     1337597 : ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handle handle TSRMLS_DC)
      51             : {
      52     1337597 :         zend_function *destructor = object ? object->ce->destructor : NULL;
      53             : 
      54     1337597 :         if (destructor) {
      55             :                 zval *old_exception;
      56             :                 zval *obj;
      57             :                 zend_object_store_bucket *obj_bucket;
      58             : 
      59       88404 :                 if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
      60           8 :                         if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) {
      61             :                                 /* Ensure that if we're calling a private function, we're allowed to do so.
      62             :                                  */
      63           4 :                                 if (object->ce != EG(scope)) {
      64           4 :                                         zend_class_entry *ce = object->ce;
      65             : 
      66           8 :                                         zend_error(EG(in_execution) ? E_ERROR : E_WARNING, 
      67             :                                                 "Call to private %s::__destruct() from context '%s'%s", 
      68             :                                                 ce->name, 
      69           4 :                                                 EG(scope) ? EG(scope)->name : "", 
      70           4 :                                                 EG(in_execution) ? "" : " during shutdown ignored");
      71           2 :                                         return;
      72             :                                 }
      73             :                         } else {
      74             :                                 /* Ensure that if we're calling a protected function, we're allowed to do so.
      75             :                                  */
      76           4 :                                 if (!zend_check_protected(destructor->common.scope, EG(scope))) {
      77           3 :                                         zend_class_entry *ce = object->ce;
      78             : 
      79           6 :                                         zend_error(EG(in_execution) ? E_ERROR : E_WARNING, 
      80             :                                                 "Call to protected %s::__destruct() from context '%s'%s", 
      81             :                                                 ce->name, 
      82           3 :                                                 EG(scope) ? EG(scope)->name : "", 
      83           3 :                                                 EG(in_execution) ? "" : " during shutdown ignored");
      84           2 :                                         return;
      85             :                                 }
      86             :                         }
      87             :                 }
      88             : 
      89       88397 :                 MAKE_STD_ZVAL(obj);
      90       88397 :                 Z_TYPE_P(obj) = IS_OBJECT;
      91       88397 :                 Z_OBJ_HANDLE_P(obj) = handle;
      92       88397 :                 obj_bucket = &EG(objects_store).object_buckets[handle];
      93       88397 :                 if (!obj_bucket->bucket.obj.handlers) {
      94       87412 :                         obj_bucket->bucket.obj.handlers = &std_object_handlers;
      95             :                 }
      96       88397 :                 Z_OBJ_HT_P(obj) = obj_bucket->bucket.obj.handlers;
      97       88397 :                 zval_copy_ctor(obj);
      98             : 
      99             :                 /* Make sure that destructors are protected from previously thrown exceptions.
     100             :                  * For example, if an exception was thrown in a function and when the function's
     101             :                  * local variable destruction results in a destructor being called.
     102             :                  */
     103       88397 :                 old_exception = NULL;
     104       88397 :                 if (EG(exception)) {
     105          29 :                         if (Z_OBJ_HANDLE_P(EG(exception)) == handle) {
     106           0 :                                 zend_error(E_ERROR, "Attempt to destruct pending exception");
     107             :                         } else {
     108          29 :                                 old_exception = EG(exception);
     109          29 :                                 EG(exception) = NULL;
     110             :                         }
     111             :                 }
     112       88397 :                 zend_call_method_with_0_params(&obj, object->ce, &destructor, ZEND_DESTRUCTOR_FUNC_NAME, NULL);
     113       88395 :                 if (old_exception) {
     114          29 :                         if (EG(exception)) {
     115           4 :                                 zend_exception_set_previous(EG(exception), old_exception TSRMLS_CC);
     116             :                         } else {
     117          25 :                                 EG(exception) = old_exception;
     118             :                         }
     119             :                 }
     120       88395 :                 zval_ptr_dtor(&obj);
     121             :         }
     122             : }
     123             : 
     124      792571 : ZEND_API void zend_objects_free_object_storage(zend_object *object TSRMLS_DC)
     125             : {
     126      792571 :         zend_object_std_dtor(object TSRMLS_CC);
     127      792571 :         efree(object);
     128      792571 : }
     129             : 
     130      790300 : ZEND_API zend_object_value zend_objects_new(zend_object **object, zend_class_entry *class_type TSRMLS_DC)
     131             : {       
     132             :         zend_object_value retval;
     133             : 
     134      790300 :         *object = emalloc(sizeof(zend_object));
     135      790300 :         (*object)->ce = class_type;
     136      790300 :         retval.handle = zend_objects_store_put(*object, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC);
     137      790300 :         retval.handlers = &std_object_handlers;
     138      790300 :         (*object)->guards = NULL;
     139      790300 :         return retval;
     140             : }
     141             : 
     142     6368806 : ZEND_API zend_object *zend_objects_get_address(const zval *zobject TSRMLS_DC)
     143             : {
     144     6368806 :         return (zend_object *)zend_object_store_get_object(zobject TSRMLS_CC);
     145             : }
     146             : 
     147      174311 : ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object_value new_obj_val, zend_object *old_object, zend_object_handle handle TSRMLS_DC)
     148             : {
     149      174311 :         zend_hash_copy(new_object->properties, old_object->properties, zval_copy_property_ctor(old_object->ce), (void *) NULL /* Not used anymore */, sizeof(zval *));
     150             : 
     151      174311 :         if (old_object->ce->clone) {
     152             :                 zval *new_obj;
     153             : 
     154           9 :                 MAKE_STD_ZVAL(new_obj);
     155           9 :                 new_obj->type = IS_OBJECT;
     156           9 :                 new_obj->value.obj = new_obj_val;
     157           9 :                 zval_copy_ctor(new_obj);
     158             : 
     159           9 :                 zend_call_method_with_0_params(&new_obj, old_object->ce, &old_object->ce->clone, ZEND_CLONE_FUNC_NAME, NULL);
     160             : 
     161           9 :                 zval_ptr_dtor(&new_obj);
     162             :         }
     163      174311 : }
     164             : 
     165          20 : ZEND_API zend_object_value zend_objects_clone_obj(zval *zobject TSRMLS_DC)
     166             : {
     167             :         zend_object_value new_obj_val;
     168             :         zend_object *old_object;
     169             :         zend_object *new_object;
     170          20 :         zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
     171             : 
     172             :         /* assume that create isn't overwritten, so when clone depends on the 
     173             :          * overwritten one then it must itself be overwritten */
     174          20 :         old_object = zend_objects_get_address(zobject TSRMLS_CC);
     175          20 :         new_obj_val = zend_objects_new(&new_object, old_object->ce TSRMLS_CC);
     176             : 
     177          20 :         ALLOC_HASHTABLE(new_object->properties);
     178          20 :         zend_hash_init(new_object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
     179             : 
     180          20 :         zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
     181             : 
     182          20 :         return new_obj_val;
     183             : }
     184             : 
     185             : /*
     186             :  * Local variables:
     187             :  * tab-width: 4
     188             :  * c-basic-offset: 4
     189             :  * indent-tabs-mode: t
     190             :  * End:
     191             :  */

Generated by: LCOV version 1.10

Generated at Tue, 08 Apr 2014 11:59:33 +0000 (9 days ago)

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