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: 111 122 91.0 %
Date: 2015-05-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     1250454 : ZEND_API void ZEND_FASTCALL _zval_dtor_func(zend_refcounted *p ZEND_FILE_LINE_DC)
      31             : {
      32     1250454 :         switch (GC_TYPE(p)) {
      33             :                 case IS_STRING:
      34             :                 case IS_CONSTANT: {
      35       90958 :                                 zend_string *str = (zend_string*)p;
      36             :                                 CHECK_ZVAL_STRING_REL(str);
      37             :                                 zend_string_release(str);
      38       90958 :                                 break;
      39             :                         }
      40             :                 case IS_ARRAY: {
      41     1096828 :                                 zend_array *arr = (zend_array*)p;
      42             : 
      43             :                                 ZEND_ASSERT(GC_REFCOUNT(arr) <= 1);
      44             : 
      45             :                                 /* break possible cycles */
      46     1096828 :                                 GC_REMOVE_FROM_BUFFER(arr);
      47     1096828 :                                 GC_TYPE_INFO(arr) = IS_NULL | (GC_WHITE << 16);
      48     1096828 :                                 zend_array_destroy(arr);
      49     1096828 :                                 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        1212 :                                 zend_object *obj = (zend_object*)p;
      60             : 
      61             :                                 OBJ_RELEASE(obj);
      62        1212 :                                 break;
      63             :                         }
      64             :                 case IS_RESOURCE: {
      65       61453 :                                 zend_resource *res = (zend_resource*)p;
      66             : 
      67       61453 :                                 if (--GC_REFCOUNT(res) == 0) {
      68             :                                         /* destroy resource */
      69       61448 :                                         zend_list_free(res);
      70             :                                 }
      71       61453 :                                 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     1250454 : }
      86             : 
      87    21008125 : ZEND_API void ZEND_FASTCALL _zval_dtor_func_for_ptr(zend_refcounted *p ZEND_FILE_LINE_DC)
      88             : {
      89    21008125 :         switch (GC_TYPE(p)) {
      90             :                 case IS_STRING:
      91             :                 case IS_CONSTANT: {
      92    17025210 :                                 zend_string *str = (zend_string*)p;
      93             :                                 CHECK_ZVAL_STRING_REL(str);
      94             :                                 zend_string_free(str);
      95    17025210 :                                 break;
      96             :                         }
      97             :                 case IS_ARRAY: {
      98     2313483 :                                 zend_array *arr = (zend_array*)p;
      99             : 
     100             :                                 /* break possible cycles */
     101     2313483 :                                 GC_REMOVE_FROM_BUFFER(arr);
     102     2313483 :                                 GC_TYPE_INFO(arr) = IS_NULL | (GC_WHITE << 16);
     103     2313483 :                                 zend_array_destroy(arr);
     104     2313481 :                                 break;
     105             :                         }
     106             :                 case IS_CONSTANT_AST: {
     107         121 :                                 zend_ast_ref *ast = (zend_ast_ref*)p;
     108             : 
     109         121 :                                 zend_ast_destroy_and_free(ast->ast);
     110         121 :                                 efree_size(ast, sizeof(zend_ast_ref));
     111         121 :                                 break;
     112             :                         }
     113             :                 case IS_OBJECT: {
     114     1317893 :                                 zend_object *obj = (zend_object*)p;
     115             : 
     116     1317893 :                                 zend_objects_store_del(obj);
     117     1317889 :                                 break;
     118             :                         }
     119             :                 case IS_RESOURCE: {
     120       96990 :                                 zend_resource *res = (zend_resource*)p;
     121             : 
     122             :                                 /* destroy resource */
     123       96990 :                                 zend_list_free(res);
     124       96990 :                                 break;
     125             :                         }
     126             :                 case IS_REFERENCE: {
     127      254428 :                                 zend_reference *ref = (zend_reference*)p;
     128             : 
     129      254428 :                                 i_zval_ptr_dtor(&ref->val ZEND_FILE_LINE_RELAY_CC);
     130      254428 :                                 efree_size(ref, sizeof(zend_reference));
     131             :                                 break;
     132             :                         }
     133             :                 default:
     134             :                         break;
     135             :         }
     136    21008119 : }
     137             : 
     138    51248592 : ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC)
     139             : {
     140    51248592 :         switch (Z_TYPE_P(zvalue)) {
     141             :                 case IS_STRING:
     142             :                 case IS_CONSTANT:
     143             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     144     1969488 :                         zend_string_release(Z_STR_P(zvalue));
     145     1969488 :                         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    51248592 : }
     168             : 
     169     2058408 : ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC)
     170             : {
     171     2058408 :         switch (Z_TYPE_P(zvalue)) {
     172             :                 case IS_STRING:
     173             :                 case IS_CONSTANT:
     174             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     175      817128 :                         zend_string_free(Z_STR_P(zvalue));
     176      817128 :                         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     1241280 :                                 zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
     185             : 
     186     1241280 :                                 zval_internal_ptr_dtor(&ref->val);
     187     1241280 :                                 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     2058408 : }
     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      866216 : ZEND_API void zval_add_ref(zval *p)
     205             : {
     206      866216 :         if (Z_REFCOUNTED_P(p)) {
     207      863562 :                 if (Z_ISREF_P(p) && Z_REFCOUNT_P(p) == 1) {
     208           5 :                         ZVAL_COPY(p, Z_REFVAL_P(p));
     209             :                 } else {
     210             :                         Z_ADDREF_P(p);
     211             :                 }
     212             :         }
     213      866216 : }
     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     1506158 : ZEND_API void ZEND_FASTCALL _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC)
     227             : {
     228     1506158 :         if (EXPECTED(Z_TYPE_P(zvalue) == IS_ARRAY)) {
     229     1257949 :                 ZVAL_ARR(zvalue, zend_array_dup(Z_ARRVAL_P(zvalue)));
     230      496581 :         } else if (EXPECTED(Z_TYPE_P(zvalue) == IS_STRING) ||
     231         164 :                    EXPECTED(Z_TYPE_P(zvalue) == IS_CONSTANT)) {
     232             :                 CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     233      496416 :                 Z_STR_P(zvalue) = zend_string_dup(Z_STR_P(zvalue), 0);
     234           1 :         } else if (EXPECTED(Z_TYPE_P(zvalue) == IS_CONSTANT_AST)) {
     235           1 :                 zend_ast_ref *ast = emalloc(sizeof(zend_ast_ref));
     236             : 
     237           1 :                 GC_REFCOUNT(ast) = 1;
     238           1 :                 GC_TYPE_INFO(ast) = IS_CONSTANT_AST;
     239           1 :                 ast->ast = zend_ast_copy(Z_ASTVAL_P(zvalue));
     240           1 :                 Z_AST_P(zvalue) = ast;
     241             :         }
     242     1506158 : }
     243             : 
     244             : 
     245        1028 : ZEND_API size_t zend_print_variable(zval *var)
     246             : {
     247        1028 :         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         135 : 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         135 :         HashTable *target = va_arg(args, HashTable*);
     281             :         zend_bool is_ref;
     282             :         zval tmp;
     283             : 
     284         135 :         if (Z_CONST_FLAGS_P(p) & (IS_LEXICAL_VAR|IS_LEXICAL_REF)) {
     285         128 :                 is_ref = Z_CONST_FLAGS_P(p) & IS_LEXICAL_REF;
     286             : 
     287         128 :                 symbol_table = zend_rebuild_symbol_table();
     288         128 :                 p = zend_hash_find(symbol_table, key->key);
     289         128 :                 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         125 :                         if (Z_TYPE_P(p) == IS_INDIRECT) {
     301         125 :                                 p = Z_INDIRECT_P(p);
     302         125 :                                 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         125 :                         if (is_ref) {
     313          37 :                                 ZVAL_MAKE_REF(p);
     314             :                                 Z_ADDREF_P(p);
     315          88 :                         } else if (Z_ISREF_P(p)) {
     316          11 :                                 ZVAL_DUP(&tmp, Z_REFVAL_P(p));
     317          11 :                                 p = &tmp;
     318          77 :                         } 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         135 :         zend_hash_add(target, key->key, p);
     326         135 :         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 Thu, 21 May 2015 19:58:49 +0000 (5 days ago)

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