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

Generated by: LCOV version 1.10

Generated at Wed, 02 Sep 2015 17:19:03 +0000 (19 hours ago)

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