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

Generated by: LCOV version 1.10

Generated at Tue, 14 Oct 2014 07:25:37 +0000 (7 days ago)

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