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: 92 94 97.9 %
Date: 2015-04-14 Functions: 6 6 100.0 %
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_interfaces.h"
      27             : #include "zend_exceptions.h"
      28             : 
      29     1428045 : ZEND_API void zend_object_std_init(zend_object *object, zend_class_entry *ce)
      30             : {
      31     1428045 :         GC_REFCOUNT(object) = 1;
      32     1428045 :         GC_TYPE_INFO(object) = IS_OBJECT;
      33     1428045 :         object->ce = ce;
      34     1428045 :         object->properties = NULL;
      35     1428045 :         zend_objects_store_put(object);
      36     1428045 :         if (EXPECTED(ce->default_properties_count != 0)) {
      37      112252 :                 zval *p = object->properties_table;
      38      112252 :                 zval *end = p + ce->default_properties_count;
      39             : 
      40             :                 do {
      41      259150 :                         ZVAL_UNDEF(p);
      42      259150 :                         p++;
      43      259150 :                 } while (p != end);
      44             :         }
      45     1428045 :         if (ce->ce_flags & ZEND_ACC_USE_GUARDS) {
      46          93 :                 GC_FLAGS(object) |= IS_OBJ_USE_GUARDS;
      47          93 :                 ZVAL_UNDEF(&object->properties_table[ce->default_properties_count]);
      48          93 :                 Z_PTR(object->properties_table[ce->default_properties_count]) = NULL;
      49             :         }
      50     1428045 : }
      51             : 
      52     1426466 : ZEND_API void zend_object_std_dtor(zend_object *object)
      53             : {
      54             :         int i, count;
      55             : 
      56     1426466 :         if (object->properties) {
      57      216726 :                 zend_array_destroy(object->properties);
      58      216726 :                 FREE_HASHTABLE(object->properties);
      59             :         }
      60     1426466 :         count = object->ce->default_properties_count;
      61     1685676 :         for (i = 0; i < count; i++) {
      62      259210 :                 i_zval_ptr_dtor(&object->properties_table[i] ZEND_FILE_LINE_CC);
      63             :         }
      64     1426466 :         if (GC_FLAGS(object) & IS_OBJ_HAS_GUARDS) {
      65          70 :                 HashTable *guards = Z_PTR(object->properties_table[count]);
      66             : 
      67             :                 ZEND_ASSERT(guards != NULL);
      68          70 :                 zend_hash_destroy(guards);
      69          70 :                 FREE_HASHTABLE(guards);
      70             :         }
      71     1426466 : }
      72             : 
      73     1021798 : ZEND_API void zend_objects_destroy_object(zend_object *object)
      74             : {
      75     1021798 :         zend_function *destructor = object ? object->ce->destructor : NULL;
      76             : 
      77     1021798 :         if (destructor) {
      78             :                 zend_object *old_exception;
      79             :                 zval obj;
      80             : 
      81       98403 :                 if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
      82           8 :                         if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) {
      83             :                                 /* Ensure that if we're calling a private function, we're allowed to do so.
      84             :                                  */
      85           4 :                                 if (object->ce != EG(scope)) {
      86           4 :                                         zend_class_entry *ce = object->ce;
      87             : 
      88          12 :                                         zend_error(EG(current_execute_data) ? E_ERROR : E_WARNING,
      89             :                                                 "Call to private %s::__destruct() from context '%s'%s",
      90           4 :                                                 ce->name->val,
      91           4 :                                                 EG(scope) ? EG(scope)->name->val : "",
      92           4 :                                                 EG(current_execute_data) ? "" : " during shutdown ignored");
      93           2 :                                         return;
      94             :                                 }
      95             :                         } else {
      96             :                                 /* Ensure that if we're calling a protected function, we're allowed to do so.
      97             :                                  */
      98           4 :                                 if (!zend_check_protected(zend_get_function_root_class(destructor), EG(scope))) {
      99           3 :                                         zend_class_entry *ce = object->ce;
     100             : 
     101           9 :                                         zend_error(EG(current_execute_data) ? E_ERROR : E_WARNING,
     102             :                                                 "Call to protected %s::__destruct() from context '%s'%s",
     103           3 :                                                 ce->name->val,
     104           3 :                                                 EG(scope) ? EG(scope)->name->val : "",
     105           3 :                                                 EG(current_execute_data) ? "" : " during shutdown ignored");
     106           2 :                                         return;
     107             :                                 }
     108             :                         }
     109             :                 }
     110             : 
     111       98396 :                 ZVAL_OBJ(&obj, object);
     112             :                 Z_ADDREF(obj);
     113             : 
     114             :                 /* Make sure that destructors are protected from previously thrown exceptions.
     115             :                  * For example, if an exception was thrown in a function and when the function's
     116             :                  * local variable destruction results in a destructor being called.
     117             :                  */
     118       98396 :                 old_exception = NULL;
     119       98396 :                 if (EG(exception)) {
     120          22 :                         if (EG(exception) == object) {
     121           0 :                                 zend_error(E_ERROR, "Attempt to destruct pending exception");
     122             :                         } else {
     123          22 :                                 old_exception = EG(exception);
     124          22 :                                 EG(exception) = NULL;
     125             :                         }
     126             :                 }
     127       98396 :                 zend_call_method_with_0_params(&obj, object->ce, &destructor, ZEND_DESTRUCTOR_FUNC_NAME, NULL);
     128       98393 :                 if (old_exception) {
     129          22 :                         if (EG(exception)) {
     130           3 :                                 zend_exception_set_previous(EG(exception), old_exception);
     131             :                         } else {
     132          19 :                                 EG(exception) = old_exception;
     133             :                         }
     134             :                 }
     135       98393 :                 zval_ptr_dtor(&obj);
     136             :         }
     137             : }
     138             : 
     139      409774 : ZEND_API zend_object *zend_objects_new(zend_class_entry *ce)
     140             : {
     141      409774 :         zend_object *object = emalloc(sizeof(zend_object) + zend_object_properties_size(ce));
     142             : 
     143      409774 :         zend_object_std_init(object, ce);
     144      409774 :         object->handlers = &std_object_handlers;
     145      409774 :         return object;
     146             : }
     147             : 
     148      174350 : ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object *old_object)
     149             : {
     150             :         int i;
     151             : 
     152      174350 :         if (old_object->ce->default_properties_count) {
     153          50 :                 for (i = 0; i < old_object->ce->default_properties_count; i++) {
     154          36 :                         zval_ptr_dtor(&new_object->properties_table[i]);
     155          36 :                         ZVAL_COPY_VALUE(&new_object->properties_table[i], &old_object->properties_table[i]);
     156          36 :                         zval_add_ref(&new_object->properties_table[i]);
     157             :                 }
     158             :         }
     159      174350 :         if (old_object->properties) {
     160             :                 zval *prop, new_prop;
     161             :                 zend_ulong num_key;
     162             :                 zend_string *key;
     163             : 
     164          23 :                 if (!new_object->properties) {
     165          21 :                         ALLOC_HASHTABLE(new_object->properties);
     166          21 :                         zend_hash_init(new_object->properties, zend_hash_num_elements(old_object->properties), NULL, ZVAL_PTR_DTOR, 0);
     167             :                 }
     168             : 
     169         143 :                 ZEND_HASH_FOREACH_KEY_VAL(old_object->properties, num_key, key, prop) {
     170          60 :                         if (Z_TYPE_P(prop) == IS_INDIRECT) {
     171          14 :                                 ZVAL_INDIRECT(&new_prop, new_object->properties_table + (Z_INDIRECT_P(prop) - old_object->properties_table));
     172             :                         } else {
     173          46 :                                 ZVAL_COPY_VALUE(&new_prop, prop);
     174          46 :                                 zval_add_ref(&new_prop);
     175             :                         }
     176          60 :                         if (key) {
     177          60 :                                 zend_hash_add_new(new_object->properties, key, &new_prop);
     178             :                         } else {
     179           0 :                                 zend_hash_index_add_new(new_object->properties, num_key, &new_prop);
     180             :                         }
     181             :                 } ZEND_HASH_FOREACH_END();
     182             :         }
     183             : 
     184      174350 :         if (old_object->ce->clone) {
     185             :                 zval new_obj;
     186             : 
     187          11 :                 ZVAL_OBJ(&new_obj, new_object);
     188             :                 zval_copy_ctor(&new_obj);
     189          11 :                 zend_call_method_with_0_params(&new_obj, old_object->ce, &old_object->ce->clone, ZEND_CLONE_FUNC_NAME, NULL);
     190          11 :                 zval_ptr_dtor(&new_obj);
     191             :         }
     192      174350 : }
     193             : 
     194          37 : ZEND_API zend_object *zend_objects_clone_obj(zval *zobject)
     195             : {
     196             :         zend_object *old_object;
     197             :         zend_object *new_object;
     198             : 
     199             :         /* assume that create isn't overwritten, so when clone depends on the
     200             :          * overwritten one then it must itself be overwritten */
     201          37 :         old_object = Z_OBJ_P(zobject);
     202          37 :         new_object = zend_objects_new(old_object->ce);
     203             : 
     204          37 :         zend_objects_clone_members(new_object, old_object);
     205             : 
     206          37 :         return new_object;
     207             : }
     208             : 
     209             : /*
     210             :  * Local variables:
     211             :  * tab-width: 4
     212             :  * c-basic-offset: 4
     213             :  * indent-tabs-mode: t
     214             :  * End:
     215             :  */

Generated by: LCOV version 1.10

Generated at Tue, 14 Apr 2015 11:48:39 +0000 (10 days ago)

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