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_variables.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 113 126 89.7 %
Date: 2015-02-21 Functions: 10 10 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 <stdio.h>
      23             : #include "zend.h"
      24             : #include "zend_API.h"
      25             : #include "zend_ast.h"
      26             : #include "zend_globals.h"
      27             : #include "zend_constants.h"
      28             : #include "zend_list.h"
      29             : 
      30     1258204 : ZEND_API void _zval_dtor_func(zend_refcounted *p ZEND_FILE_LINE_DC)
      31             : {
      32     1258204 :         switch (GC_TYPE(p)) {
      33             :                 case IS_STRING:
      34             :                 case IS_CONSTANT: {
      35       92554 :                                 zend_string *str = (zend_string*)p;
      36             :                                 CHECK_ZVAL_STRING_REL(str);
      37             :                                 zend_string_release(str);
      38       92554 :                                 break;
      39             :                         }
      40             :                 case IS_ARRAY: {
      41     1103073 :                                 zend_array *arr = (zend_array*)p;
      42             : 
      43             :                                 ZEND_ASSERT(GC_REFCOUNT(arr) <= 1);
      44             : 
      45             :                                 /* break possible cycles */
      46     1103073 :                                 GC_TYPE(arr) = IS_NULL;
      47     1103073 :                                 GC_REMOVE_FROM_BUFFER(arr);
      48     1103073 :                                 zend_array_destroy(arr);
      49     1103073 :                                 efree_size(arr, sizeof(zend_array));
      50     1103073 :                                 break;
      51             :                         }
      52             :                 case IS_CONSTANT_AST: {
      53           0 :                                 zend_ast_ref *ast = (zend_ast_ref*)p;
      54             : 
      55           0 :                                 zend_ast_destroy_and_free(ast->ast);
      56           0 :                                 efree_size(ast, sizeof(zend_ast_ref));
      57           0 :                                 break;
      58             :                         }
      59             :                 case IS_OBJECT: {
      60        1256 :                                 zend_object *obj = (zend_object*)p;
      61             : 
      62             :                                 OBJ_RELEASE(obj);
      63        1256 :                                 break;
      64             :                         }
      65             :                 case IS_RESOURCE: {
      66       61318 :                                 zend_resource *res = (zend_resource*)p;
      67             : 
      68       61318 :                                 if (--GC_REFCOUNT(res) == 0) {
      69             :                                         /* destroy resource */
      70       61313 :                                         zend_list_free(res);
      71             :                                 }
      72       61318 :                                 break;
      73             :                         }
      74             :                 case IS_REFERENCE: {
      75           3 :                                 zend_reference *ref = (zend_reference*)p;
      76           3 :                                 if (--GC_REFCOUNT(ref) == 0) {
      77             : 
      78           1 :                                         i_zval_ptr_dtor(&ref->val ZEND_FILE_LINE_RELAY_CC);
      79           1 :                                         efree_size(ref, sizeof(zend_reference));
      80             :                                 }
      81             :                                 break;
      82             :                         }
      83             :                 default:
      84             :                         break;
      85             :         }
      86     1258204 : }
      87             : 
      88    16860816 : ZEND_API void _zval_dtor_func_for_ptr(zend_refcounted *p ZEND_FILE_LINE_DC)
      89             : {
      90    16860816 :         switch (GC_TYPE(p)) {
      91             :                 case IS_STRING:
      92             :                 case IS_CONSTANT: {
      93    12789923 :                                 zend_string *str = (zend_string*)p;
      94             :                                 CHECK_ZVAL_STRING_REL(str);
      95             :                                 zend_string_free(str);
      96    12789923 :                                 break;
      97             :                         }
      98             :                 case IS_ARRAY: {
      99     2396410 :                                 zend_array *arr = (zend_array*)p;
     100             : 
     101             :                                 /* break possible cycles */
     102     2396410 :                                 GC_TYPE(arr) = IS_NULL;
     103     2396410 :                                 GC_REMOVE_FROM_BUFFER(arr);
     104     2396410 :                                 zend_array_destroy(arr);
     105     2396408 :                                 efree_size(arr, sizeof(zend_array));
     106     2396408 :                                 break;
     107             :                         }
     108             :                 case IS_CONSTANT_AST: {
     109          59 :                                 zend_ast_ref *ast = (zend_ast_ref*)p;
     110             : 
     111          59 :                                 zend_ast_destroy_and_free(ast->ast);
     112          59 :                                 efree_size(ast, sizeof(zend_ast_ref));
     113          59 :                                 break;
     114             :                         }
     115             :                 case IS_OBJECT: {
     116     1333498 :                                 zend_object *obj = (zend_object*)p;
     117             : 
     118     1333498 :                                 zend_objects_store_del(obj);
     119     1333490 :                                 break;
     120             :                         }
     121             :                 case IS_RESOURCE: {
     122       96801 :                                 zend_resource *res = (zend_resource*)p;
     123             : 
     124             :                                 /* destroy resource */
     125       96801 :                                 zend_list_free(res);
     126       96801 :                                 break;
     127             :                         }
     128             :                 case IS_REFERENCE: {
     129      244125 :                                 zend_reference *ref = (zend_reference*)p;
     130             : 
     131      244125 :                                 i_zval_ptr_dtor(&ref->val ZEND_FILE_LINE_RELAY_CC);
     132      244125 :                                 efree_size(ref, sizeof(zend_reference));
     133             :                                 break;
     134             :                         }
     135             :                 default:
     136             :                         break;
     137             :         }
     138    16860806 : }
     139             : 
     140    50840960 : ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC)
     141             : {
     142    50840960 :         switch (Z_TYPE_P(zvalue)) {
     143             :                 case IS_STRING:
     144             :                 case IS_CONSTANT:
     145             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     146     1923260 :                         zend_string_release(Z_STR_P(zvalue));
     147     1923260 :                         break;
     148             :                 case IS_ARRAY:
     149             :                 case IS_CONSTANT_AST:
     150             :                 case IS_OBJECT:
     151             :                 case IS_RESOURCE:
     152           0 :                         zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
     153           0 :                         break;
     154             :                 case IS_REFERENCE: {
     155           0 :                                 zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
     156             : 
     157           0 :                                 zval_internal_ptr_dtor(&ref->val);
     158           0 :                                 free(ref);
     159             :                                 break;
     160             :                         }
     161             :                 case IS_LONG:
     162             :                 case IS_DOUBLE:
     163             :                 case IS_FALSE:
     164             :                 case IS_TRUE:
     165             :                 case IS_NULL:
     166             :                 default:
     167             :                         break;
     168             :         }
     169    50840960 : }
     170             : 
     171     2032921 : ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC)
     172             : {
     173     2032921 :         switch (Z_TYPE_P(zvalue)) {
     174             :                 case IS_STRING:
     175             :                 case IS_CONSTANT:
     176             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     177      794390 :                         zend_string_free(Z_STR_P(zvalue));
     178      794390 :                         break;
     179             :                 case IS_ARRAY:
     180             :                 case IS_CONSTANT_AST:
     181             :                 case IS_OBJECT:
     182             :                 case IS_RESOURCE:
     183           0 :                         zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
     184           0 :                         break;
     185             :                 case IS_REFERENCE: {
     186     1238531 :                                 zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
     187             : 
     188     1238531 :                                 zval_internal_ptr_dtor(&ref->val);
     189     1238531 :                                 free(ref);
     190             :                                 break;
     191             :                         }
     192             :                 case IS_LONG:
     193             :                 case IS_DOUBLE:
     194             :                 case IS_FALSE:
     195             :                 case IS_TRUE:
     196             :                 case IS_NULL:
     197             :                 default:
     198             :                         break;
     199             :         }
     200     2032921 : }
     201             : 
     202             : /* This function should only be used as a copy constructor, i.e. it
     203             :  * should only be called AFTER a zval has been copied to another
     204             :  * location using ZVAL_COPY_VALUE. Do not call it before copying,
     205             :  * otherwise a reference may be leaked. */
     206      874146 : ZEND_API void zval_add_ref(zval *p)
     207             : {
     208      874146 :         if (Z_REFCOUNTED_P(p)) {
     209      871488 :                 if (Z_ISREF_P(p) && Z_REFCOUNT_P(p) == 1) {
     210           5 :                         ZVAL_COPY(p, Z_REFVAL_P(p));
     211             :                 } else {
     212             :                         Z_ADDREF_P(p);
     213             :                 }
     214             :         }
     215      874146 : }
     216             : 
     217         134 : ZEND_API void zval_add_ref_unref(zval *p)
     218             : {
     219         134 :         if (Z_REFCOUNTED_P(p)) {
     220          20 :                 if (Z_ISREF_P(p)) {
     221           6 :                         ZVAL_COPY(p, Z_REFVAL_P(p));
     222             :                 } else {
     223             :                         Z_ADDREF_P(p);
     224             :                 }
     225             :         }
     226         134 : }
     227             : 
     228     1544150 : ZEND_API void _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC)
     229             : {
     230     1544150 :         switch (Z_TYPE_P(zvalue)) {
     231             :                 case IS_CONSTANT:
     232             :                 case IS_STRING:
     233             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     234      557072 :                         Z_STR_P(zvalue) = zend_string_dup(Z_STR_P(zvalue), 0);
     235      278536 :                         break;
     236             :                 case IS_ARRAY:
     237     1265613 :                         ZVAL_ARR(zvalue, zend_array_dup(Z_ARRVAL_P(zvalue)));
     238     1265613 :                         break;
     239             :                 case IS_CONSTANT_AST: {
     240           1 :                                 zend_ast_ref *ast = emalloc(sizeof(zend_ast_ref));
     241             : 
     242           1 :                                 GC_REFCOUNT(ast) = 1;
     243           1 :                                 GC_TYPE_INFO(ast) = IS_CONSTANT_AST;
     244           1 :                                 ast->ast = zend_ast_copy(Z_ASTVAL_P(zvalue));
     245           1 :                                 Z_AST_P(zvalue) = ast;
     246             :                         }
     247           1 :                         break;
     248             :                 case IS_OBJECT:
     249             :                 case IS_RESOURCE:
     250             :                 case IS_REFERENCE:
     251             :                         Z_ADDREF_P(zvalue);
     252             :                         break;
     253             :         }
     254     1544150 : }
     255             : 
     256             : 
     257        1023 : ZEND_API size_t zend_print_variable(zval *var)
     258             : {
     259        1023 :         return zend_print_zval(var, 0);
     260             : }
     261             : 
     262             : 
     263           6 : ZEND_API void _zval_dtor_wrapper(zval *zvalue)
     264             : {
     265             :         zval_dtor(zvalue);
     266           6 : }
     267             : 
     268             : 
     269             : #if ZEND_DEBUG
     270             : ZEND_API void _zval_copy_ctor_wrapper(zval *zvalue)
     271             : {
     272             :         zval_copy_ctor(zvalue);
     273             : }
     274             : 
     275             : 
     276             : ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue)
     277             : {
     278             :         zval_internal_dtor(zvalue);
     279             : }
     280             : 
     281             : 
     282             : ZEND_API void _zval_ptr_dtor_wrapper(zval *zval_ptr)
     283             : {
     284             : 
     285             :         i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_CC);
     286             : }
     287             : 
     288             : 
     289             : ZEND_API void _zval_internal_ptr_dtor_wrapper(zval *zval_ptr)
     290             : {
     291             :         zval_internal_ptr_dtor(zval_ptr);
     292             : }
     293             : #endif
     294             : 
     295         134 : ZEND_API int zval_copy_static_var(zval *p, int num_args, va_list args, zend_hash_key *key) /* {{{ */
     296             : {
     297             :         zend_array *symbol_table;
     298         134 :         HashTable *target = va_arg(args, HashTable*);
     299             :         zend_bool is_ref;
     300             :         zval tmp;
     301             : 
     302         134 :         if (Z_CONST_FLAGS_P(p) & (IS_LEXICAL_VAR|IS_LEXICAL_REF)) {
     303         119 :                 is_ref = Z_CONST_FLAGS_P(p) & IS_LEXICAL_REF;
     304             : 
     305         119 :                 symbol_table = zend_rebuild_symbol_table();
     306         119 :                 p = zend_hash_find(symbol_table, key->key);
     307         119 :                 if (!p) {
     308           3 :                         p = &tmp;
     309           3 :                         ZVAL_NULL(&tmp);
     310           3 :                         if (is_ref) {
     311           0 :                                 ZVAL_NEW_REF(&tmp, &tmp);
     312           0 :                                 zend_hash_add_new(symbol_table, key->key, &tmp);
     313             :                                 Z_ADDREF_P(p);
     314             :                         } else {
     315           3 :                                 zend_error(E_NOTICE,"Undefined variable: %s", key->key->val);
     316             :                         }
     317             :                 } else {
     318         116 :                         if (Z_TYPE_P(p) == IS_INDIRECT) {
     319         116 :                                 p = Z_INDIRECT_P(p);
     320         116 :                                 if (Z_TYPE_P(p) == IS_UNDEF) {
     321           6 :                                         if (!is_ref) {
     322           1 :                                                 zend_error(E_NOTICE,"Undefined variable: %s", key->key->val);
     323           1 :                                                 p = &tmp;
     324           1 :                                                 ZVAL_NULL(&tmp);
     325             :                                         } else {
     326           5 :                                                 ZVAL_NULL(p);
     327             :                                         }
     328             :                                 }
     329             :                         }
     330         116 :                         if (is_ref) {
     331          72 :                                 ZVAL_MAKE_REF(p);
     332             :                                 Z_ADDREF_P(p);
     333          80 :                         } else if (Z_ISREF_P(p)) {
     334          11 :                                 ZVAL_DUP(&tmp, Z_REFVAL_P(p));
     335          11 :                                 p = &tmp;
     336          69 :                         } else if (Z_REFCOUNTED_P(p)) {
     337             :                                 Z_ADDREF_P(p);
     338             :                         }
     339             :                 }
     340          15 :         } else if (Z_REFCOUNTED_P(p)) {
     341             :                 Z_ADDREF_P(p);
     342             :         }
     343         134 :         zend_hash_add(target, key->key, p);
     344         134 :         return ZEND_HASH_APPLY_KEEP;
     345             : }
     346             : /* }}} */
     347             : 
     348             : /*
     349             :  * Local variables:
     350             :  * tab-width: 4
     351             :  * c-basic-offset: 4
     352             :  * indent-tabs-mode: t
     353             :  * End:
     354             :  */

Generated by: LCOV version 1.10

Generated at Sat, 21 Feb 2015 16:01:43 +0000 (6 days ago)

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