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: 118 131 90.1 %
Date: 2015-01-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     1255552 : ZEND_API void _zval_dtor_func(zend_refcounted *p ZEND_FILE_LINE_DC)
      31             : {
      32     1255552 :         switch (GC_TYPE(p)) {
      33             :                 case IS_STRING:
      34             :                 case IS_CONSTANT: {
      35       90966 :                                 zend_string *str = (zend_string*)p;
      36             :                                 CHECK_ZVAL_STRING_REL(str);
      37             :                                 zend_string_release(str);
      38       90966 :                                 break;
      39             :                         }
      40             :                 case IS_ARRAY: {
      41     1102233 :                                 zend_array *arr = (zend_array*)p;
      42             : 
      43     1102233 :                                 if (arr != &EG(symbol_table)) {
      44             :                                         /* break possible cycles */
      45     1102233 :                                         GC_TYPE(arr) = IS_NULL;
      46     1102233 :                                         GC_REMOVE_FROM_BUFFER(arr);
      47     1102233 :                                         zend_array_destroy(&arr->ht);
      48     1102233 :                                         efree_size(arr, sizeof(zend_array));
      49             :                                 }
      50     1102233 :                                 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        1287 :                                 zend_object *obj = (zend_object*)p;
      61             : 
      62             :                                 OBJ_RELEASE(obj);
      63        1287 :                                 break;
      64             :                         }
      65             :                 case IS_RESOURCE: {
      66       61063 :                                 zend_resource *res = (zend_resource*)p;
      67             : 
      68       61063 :                                 if (--GC_REFCOUNT(res) == 0) {
      69             :                                         /* destroy resource */
      70       61058 :                                         zend_list_free(res);
      71             :                                 }
      72       61063 :                                 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     1255552 : }
      87             : 
      88    17270934 : ZEND_API void _zval_dtor_func_for_ptr(zend_refcounted *p ZEND_FILE_LINE_DC)
      89             : {
      90    17270934 :         switch (GC_TYPE(p)) {
      91             :                 case IS_STRING:
      92             :                 case IS_CONSTANT: {
      93    13180776 :                                 zend_string *str = (zend_string*)p;
      94             :                                 CHECK_ZVAL_STRING_REL(str);
      95             :                                 zend_string_free(str);
      96    13180776 :                                 break;
      97             :                         }
      98             :                 case IS_ARRAY: {
      99     2421913 :                                 zend_array *arr = (zend_array*)p;
     100             : 
     101     2421913 :                                 if (arr != &EG(symbol_table)) {
     102             :                                         /* break possible cycles */
     103     2421712 :                                         GC_TYPE(arr) = IS_NULL;
     104     2421712 :                                         GC_REMOVE_FROM_BUFFER(arr);
     105     2421712 :                                         zend_array_destroy(&arr->ht);
     106     2421710 :                                         efree_size(arr, sizeof(zend_array));
     107             :                                 }
     108     2421911 :                                 break;
     109             :                         }
     110             :                 case IS_CONSTANT_AST: {
     111          59 :                                 zend_ast_ref *ast = (zend_ast_ref*)p;
     112             : 
     113          59 :                                 zend_ast_destroy_and_free(ast->ast);
     114          59 :                                 efree_size(ast, sizeof(zend_ast_ref));
     115          59 :                                 break;
     116             :                         }
     117             :                 case IS_OBJECT: {
     118     1328398 :                                 zend_object *obj = (zend_object*)p;
     119             : 
     120     1328398 :                                 zend_objects_store_del(obj);
     121     1328390 :                                 break;
     122             :                         }
     123             :                 case IS_RESOURCE: {
     124       96406 :                                 zend_resource *res = (zend_resource*)p;
     125             : 
     126             :                                 /* destroy resource */
     127       96406 :                                 zend_list_free(res);
     128       96406 :                                 break;
     129             :                         }
     130             :                 case IS_REFERENCE: {
     131      243377 :                                 zend_reference *ref = (zend_reference*)p;
     132             : 
     133      243377 :                                 i_zval_ptr_dtor(&ref->val ZEND_FILE_LINE_RELAY_CC);
     134      243377 :                                 efree_size(ref, sizeof(zend_reference));
     135             :                                 break;
     136             :                         }
     137             :                 default:
     138             :                         break;
     139             :         }
     140    17270924 : }
     141             : 
     142    52050000 : ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC)
     143             : {
     144    52050000 :         switch (Z_TYPE_P(zvalue)) {
     145             :                 case IS_STRING:
     146             :                 case IS_CONSTANT:
     147             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     148     1915440 :                         zend_string_release(Z_STR_P(zvalue));
     149     1915440 :                         break;
     150             :                 case IS_ARRAY:
     151             :                 case IS_CONSTANT_AST:
     152             :                 case IS_OBJECT:
     153             :                 case IS_RESOURCE:
     154           0 :                         zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
     155           0 :                         break;
     156             :                 case IS_REFERENCE: {
     157           0 :                                 zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
     158             : 
     159           0 :                                 zval_internal_ptr_dtor(&ref->val);
     160           0 :                                 free(ref);
     161             :                                 break;
     162             :                         }
     163             :                 case IS_LONG:
     164             :                 case IS_DOUBLE:
     165             :                 case IS_FALSE:
     166             :                 case IS_TRUE:
     167             :                 case IS_NULL:
     168             :                 default:
     169             :                         break;
     170             :         }
     171    52050000 : }
     172             : 
     173     2024672 : ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC)
     174             : {
     175     2024672 :         switch (Z_TYPE_P(zvalue)) {
     176             :                 case IS_STRING:
     177             :                 case IS_CONSTANT:
     178             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     179      791160 :                         zend_string_free(Z_STR_P(zvalue));
     180      791160 :                         break;
     181             :                 case IS_ARRAY:
     182             :                 case IS_CONSTANT_AST:
     183             :                 case IS_OBJECT:
     184             :                 case IS_RESOURCE:
     185           0 :                         zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
     186           0 :                         break;
     187             :                 case IS_REFERENCE: {
     188     1233512 :                                 zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
     189             : 
     190     1233512 :                                 zval_internal_ptr_dtor(&ref->val);
     191     1233512 :                                 free(ref);
     192             :                                 break;
     193             :                         }
     194             :                 case IS_LONG:
     195             :                 case IS_DOUBLE:
     196             :                 case IS_FALSE:
     197             :                 case IS_TRUE:
     198             :                 case IS_NULL:
     199             :                 default:
     200             :                         break;
     201             :         }
     202     2024672 : }
     203             : 
     204             : /* This function should only be used as a copy constructor, i.e. it
     205             :  * should only be called AFTER a zval has been copied to another
     206             :  * location using ZVAL_COPY_VALUE. Do not call it before copying,
     207             :  * otherwise a reference may be leaked. */
     208      873959 : ZEND_API void zval_add_ref(zval *p)
     209             : {
     210      873959 :         if (Z_REFCOUNTED_P(p)) {
     211      871301 :                 if (Z_ISREF_P(p) && Z_REFCOUNT_P(p) == 1) {
     212           5 :                         ZVAL_COPY(p, Z_REFVAL_P(p));
     213             :                 } else {
     214             :                         Z_ADDREF_P(p);
     215             :                 }
     216             :         }
     217      873959 : }
     218             : 
     219         134 : ZEND_API void zval_add_ref_unref(zval *p)
     220             : {
     221         134 :         if (Z_REFCOUNTED_P(p)) {
     222          20 :                 if (Z_ISREF_P(p)) {
     223           6 :                         ZVAL_COPY(p, Z_REFVAL_P(p));
     224             :                 } else {
     225             :                         Z_ADDREF_P(p);
     226             :                 }
     227             :         }
     228         134 : }
     229             : 
     230     1570296 : ZEND_API void _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC)
     231             : {
     232     1570296 :         switch (Z_TYPE_P(zvalue)) {
     233             :                 case IS_CONSTANT:
     234             :                 case IS_STRING:
     235             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     236      553952 :                         Z_STR_P(zvalue) = zend_string_dup(Z_STR_P(zvalue), 0);
     237      276976 :                         break;
     238             :                 case IS_ARRAY: {
     239             :                                 HashTable *ht;
     240             : 
     241     1293318 :                                 if (Z_ARR_P(zvalue) == &EG(symbol_table)) {
     242           1 :                                         return; /* do nothing */
     243             :                                 }
     244     1293317 :                                 ht = Z_ARRVAL_P(zvalue);
     245     1293317 :                                 ZVAL_NEW_ARR(zvalue);
     246     1293317 :                                 zend_array_dup(Z_ARRVAL_P(zvalue), ht);
     247             :                         }
     248     1293317 :                         break;
     249             :                 case IS_CONSTANT_AST: {
     250           2 :                                 zend_ast_ref *ast = emalloc(sizeof(zend_ast_ref));
     251             : 
     252           2 :                                 GC_REFCOUNT(ast) = 1;
     253           2 :                                 GC_TYPE_INFO(ast) = IS_CONSTANT_AST;
     254           2 :                                 ast->ast = zend_ast_copy(Z_ASTVAL_P(zvalue));
     255           2 :                                 Z_AST_P(zvalue) = ast;
     256             :                         }
     257           2 :                         break;
     258             :                 case IS_OBJECT:
     259             :                 case IS_RESOURCE:
     260             :                 case IS_REFERENCE:
     261             :                         Z_ADDREF_P(zvalue);
     262             :                         break;
     263             :         }
     264             : }
     265             : 
     266             : 
     267        1037 : ZEND_API size_t zend_print_variable(zval *var)
     268             : {
     269        1037 :         return zend_print_zval(var, 0);
     270             : }
     271             : 
     272             : 
     273           6 : ZEND_API void _zval_dtor_wrapper(zval *zvalue)
     274             : {
     275             :         zval_dtor(zvalue);
     276           6 : }
     277             : 
     278             : 
     279             : #if ZEND_DEBUG
     280             : ZEND_API void _zval_copy_ctor_wrapper(zval *zvalue)
     281             : {
     282             :         zval_copy_ctor(zvalue);
     283             : }
     284             : 
     285             : 
     286             : ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue)
     287             : {
     288             :         zval_internal_dtor(zvalue);
     289             : }
     290             : 
     291             : 
     292             : ZEND_API void _zval_ptr_dtor_wrapper(zval *zval_ptr)
     293             : {
     294             : 
     295             :         i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_CC);
     296             : }
     297             : 
     298             : 
     299             : ZEND_API void _zval_internal_ptr_dtor_wrapper(zval *zval_ptr)
     300             : {
     301             :         zval_internal_ptr_dtor(zval_ptr);
     302             : }
     303             : #endif
     304             : 
     305         130 : ZEND_API int zval_copy_static_var(zval *p, int num_args, va_list args, zend_hash_key *key) /* {{{ */
     306             : {
     307             :         zend_array *symbol_table;
     308         130 :         HashTable *target = va_arg(args, HashTable*);
     309             :         zend_bool is_ref;
     310             :         zval tmp;
     311             : 
     312         130 :         if (Z_CONST_FLAGS_P(p) & (IS_LEXICAL_VAR|IS_LEXICAL_REF)) {
     313         115 :                 is_ref = Z_CONST_FLAGS_P(p) & IS_LEXICAL_REF;
     314             : 
     315         115 :                 symbol_table = zend_rebuild_symbol_table();
     316         115 :                 p = zend_hash_find(&symbol_table->ht, key->key);
     317         115 :                 if (!p) {
     318           3 :                         p = &tmp;
     319           3 :                         ZVAL_NULL(&tmp);
     320           3 :                         if (is_ref) {
     321           0 :                                 ZVAL_NEW_REF(&tmp, &tmp);
     322           0 :                                 zend_hash_add_new(&symbol_table->ht, key->key, &tmp);
     323             :                                 Z_ADDREF_P(p);
     324             :                         } else {
     325           3 :                                 zend_error(E_NOTICE,"Undefined variable: %s", key->key->val);
     326             :                         }
     327             :                 } else {
     328         112 :                         if (Z_TYPE_P(p) == IS_INDIRECT) {
     329         112 :                                 p = Z_INDIRECT_P(p);
     330         112 :                                 if (Z_TYPE_P(p) == IS_UNDEF) {
     331           6 :                                         if (!is_ref) {
     332           1 :                                                 zend_error(E_NOTICE,"Undefined variable: %s", key->key->val);
     333           1 :                                                 p = &tmp;
     334           1 :                                                 ZVAL_NULL(&tmp);
     335             :                                         } else {
     336           5 :                                                 ZVAL_NULL(p);
     337             :                                         }
     338             :                                 }
     339             :                         }
     340         112 :                         if (is_ref) {
     341          72 :                                 ZVAL_MAKE_REF(p);
     342             :                                 Z_ADDREF_P(p);
     343          76 :                         } else if (Z_ISREF_P(p)) {
     344          11 :                                 ZVAL_DUP(&tmp, Z_REFVAL_P(p));
     345          11 :                                 p = &tmp;
     346          65 :                         } else if (Z_REFCOUNTED_P(p)) {
     347             :                                 Z_ADDREF_P(p);
     348             :                         }
     349             :                 }
     350          15 :         } else if (Z_REFCOUNTED_P(p)) {
     351             :                 Z_ADDREF_P(p);
     352             :         }
     353         130 :         zend_hash_add(target, key->key, p);
     354         130 :         return ZEND_HASH_APPLY_KEEP;
     355             : }
     356             : /* }}} */
     357             : 
     358             : /*
     359             :  * Local variables:
     360             :  * tab-width: 4
     361             :  * c-basic-offset: 4
     362             :  * indent-tabs-mode: t
     363             :  * End:
     364             :  */

Generated by: LCOV version 1.10

Generated at Mon, 26 Jan 2015 14:46:38 +0000 (5 days ago)

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