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

Generated by: LCOV version 1.10

Generated at Mon, 27 Jul 2015 02:32:12 +0000 (3 days ago)

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