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: 2014-11-22 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 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     1392546 : ZEND_API void _zval_dtor_func(zend_refcounted *p ZEND_FILE_LINE_DC)
      31             : {
      32     1392546 :         switch (GC_TYPE(p)) {
      33             :                 case IS_STRING:
      34             :                 case IS_CONSTANT: {
      35      228589 :                                 zend_string *str = (zend_string*)p;
      36             :                                 CHECK_ZVAL_STRING_REL(str);
      37             :                                 zend_string_release(str);
      38      228589 :                                 break;
      39             :                         }
      40             :                 case IS_ARRAY: {
      41     1097776 :                                 zend_array *arr = (zend_array*)p;
      42             :                                 TSRMLS_FETCH();
      43             : 
      44     1097776 :                                 if (arr != &EG(symbol_table)) {
      45             :                                         /* break possible cycles */
      46     1097776 :                                         GC_TYPE(arr) = IS_NULL;
      47     1097776 :                                         GC_REMOVE_FROM_BUFFER(arr);
      48     1097776 :                                         zend_hash_destroy(&arr->ht);
      49     1097776 :                                         efree_size(arr, sizeof(zend_array));
      50             :                                 }
      51     1097776 :                                 break;
      52             :                         }
      53             :                 case IS_CONSTANT_AST: {
      54           0 :                                 zend_ast_ref *ast = (zend_ast_ref*)p;
      55             :                 
      56           0 :                                 zend_ast_destroy_and_free(ast->ast);
      57           0 :                                 efree_size(ast, sizeof(zend_ast_ref));
      58           0 :                                 break;
      59             :                         }
      60             :                 case IS_OBJECT: {
      61        5950 :                                 zend_object *obj = (zend_object*)p;
      62             :                                 TSRMLS_FETCH();
      63             : 
      64             :                                 OBJ_RELEASE(obj);
      65        5950 :                                 break;
      66             :                         }
      67             :                 case IS_RESOURCE: {
      68       60228 :                                 zend_resource *res = (zend_resource*)p;
      69             :                                 TSRMLS_FETCH();
      70             : 
      71       60228 :                                 if (--GC_REFCOUNT(res) == 0) {
      72             :                                         /* destroy resource */
      73       60221 :                                         zend_list_free(res);
      74             :                                 }
      75       60228 :                                 break;
      76             :                         }
      77             :                 case IS_REFERENCE: {
      78           3 :                                 zend_reference *ref = (zend_reference*)p;
      79           3 :                                 if (--GC_REFCOUNT(ref) == 0) {
      80           1 :                                         zval_ptr_dtor(&ref->val);
      81           1 :                                         efree_size(ref, sizeof(zend_reference));
      82             :                                 }
      83             :                                 break;
      84             :                         }
      85             :                 default:
      86             :                         break;
      87             :         }
      88     1392546 : }
      89             : 
      90    18645136 : ZEND_API void _zval_dtor_func_for_ptr(zend_refcounted *p ZEND_FILE_LINE_DC)
      91             : {
      92    18645136 :         switch (GC_TYPE(p)) {
      93             :                 case IS_STRING:
      94             :                 case IS_CONSTANT: {
      95    14574975 :                                 zend_string *str = (zend_string*)p;
      96             :                                 CHECK_ZVAL_STRING_REL(str);
      97             :                                 zend_string_free(str);
      98    14574975 :                                 break;
      99             :                         }
     100             :                 case IS_ARRAY: {
     101     2405838 :                                 zend_array *arr = (zend_array*)p;
     102             :                                 TSRMLS_FETCH();
     103             : 
     104     2405838 :                                 if (arr != &EG(symbol_table)) {
     105             :                                         /* break possible cycles */
     106     2405637 :                                         GC_TYPE(arr) = IS_NULL;
     107     2405637 :                                         GC_REMOVE_FROM_BUFFER(arr);
     108     2405637 :                                         zend_hash_destroy(&arr->ht);
     109     2405635 :                                         efree_size(arr, sizeof(zend_array));
     110             :                                 }
     111     2405836 :                                 break;
     112             :                         }
     113             :                 case IS_CONSTANT_AST: {
     114          59 :                                 zend_ast_ref *ast = (zend_ast_ref*)p;
     115             : 
     116          59 :                                 zend_ast_destroy_and_free(ast->ast);
     117          59 :                                 efree_size(ast, sizeof(zend_ast_ref));
     118          59 :                                 break;
     119             :                         }
     120             :                 case IS_OBJECT: {
     121     1327624 :                                 zend_object *obj = (zend_object*)p;
     122             :                                 TSRMLS_FETCH();
     123             : 
     124     1327624 :                                 zend_objects_store_del(obj TSRMLS_CC);
     125     1327616 :                                 break;
     126             :                         }
     127             :                 case IS_RESOURCE: {
     128       95245 :                                 zend_resource *res = (zend_resource*)p;
     129             :                                 TSRMLS_FETCH();
     130             : 
     131             :                                 /* destroy resource */
     132       95245 :                                 zend_list_free(res);
     133       95245 :                                 break;
     134             :                         }
     135             :                 case IS_REFERENCE: {
     136      241391 :                                 zend_reference *ref = (zend_reference*)p;
     137             : 
     138      241391 :                                 zval_ptr_dtor(&ref->val);
     139      241391 :                                 efree_size(ref, sizeof(zend_reference));
     140             :                                 break;
     141             :                         }
     142             :                 default:
     143             :                         break;
     144             :         }
     145    18645126 : }
     146             : 
     147    51290877 : ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC)
     148             : {
     149    51290877 :         switch (Z_TYPE_P(zvalue)) {
     150             :                 case IS_STRING:
     151             :                 case IS_CONSTANT:
     152             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     153     1889772 :                         zend_string_release(Z_STR_P(zvalue));
     154     1889772 :                         break;
     155             :                 case IS_ARRAY:
     156             :                 case IS_CONSTANT_AST:
     157             :                 case IS_OBJECT:
     158             :                 case IS_RESOURCE:
     159           0 :                         zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
     160           0 :                         break;
     161             :                 case IS_REFERENCE: {
     162           0 :                                 zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
     163             : 
     164           0 :                                 zval_internal_ptr_dtor(&ref->val);
     165           0 :                                 free(ref);
     166             :                                 break;
     167             :                         }
     168             :                 case IS_LONG:
     169             :                 case IS_DOUBLE:
     170             :                 case IS_FALSE:
     171             :                 case IS_TRUE:
     172             :                 case IS_NULL:
     173             :                 default:
     174             :                         break;
     175             :         }
     176    51290877 : }
     177             : 
     178     1977016 : ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC)
     179             : {
     180     1977016 :         switch (Z_TYPE_P(zvalue)) {
     181             :                 case IS_STRING:
     182             :                 case IS_CONSTANT:
     183             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     184      760017 :                         zend_string_free(Z_STR_P(zvalue));
     185      760017 :                         break;
     186             :                 case IS_ARRAY:
     187             :                 case IS_CONSTANT_AST:
     188             :                 case IS_OBJECT:
     189             :                 case IS_RESOURCE:
     190           0 :                         zend_error(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
     191           0 :                         break;
     192             :                 case IS_REFERENCE: {
     193     1216999 :                                 zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
     194             : 
     195     1216999 :                                 zval_internal_ptr_dtor(&ref->val);
     196     1216999 :                                 free(ref);
     197             :                                 break;
     198             :                         }
     199             :                 case IS_LONG:
     200             :                 case IS_DOUBLE:
     201             :                 case IS_FALSE:
     202             :                 case IS_TRUE:
     203             :                 case IS_NULL:
     204             :                 default:
     205             :                         break;
     206             :         }
     207     1977016 : }
     208             : 
     209     1062678 : ZEND_API void zval_add_ref(zval *p)
     210             : {
     211     1062678 :         if (Z_REFCOUNTED_P(p)) {
     212      869950 :                 if (Z_ISREF_P(p) && Z_REFCOUNT_P(p) == 1) {
     213           2 :                         ZVAL_COPY(p, Z_REFVAL_P(p));
     214             :                 } else {
     215             :                         Z_ADDREF_P(p);
     216             :                 }
     217             :         }
     218     1062678 : }
     219             : 
     220         133 : ZEND_API void zval_add_ref_unref(zval *p)
     221             : {
     222         133 :         if (Z_REFCOUNTED_P(p)) {
     223          20 :                 if (Z_ISREF_P(p)) {
     224           6 :                         ZVAL_COPY(p, Z_REFVAL_P(p));
     225             :                 } else {
     226             :                         Z_ADDREF_P(p);
     227             :                 }
     228             :         }
     229         133 : }
     230             : 
     231     1617506 : ZEND_API void _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC)
     232             : {
     233     1617506 :         switch (Z_TYPE_P(zvalue)) {
     234             :                 case IS_CONSTANT:
     235             :                 case IS_STRING:
     236             :                         CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
     237      657308 :                         Z_STR_P(zvalue) = zend_string_dup(Z_STR_P(zvalue), 0);
     238      328654 :                         break;
     239             :                 case IS_ARRAY: {
     240             :                                 HashTable *ht;
     241             :                                 TSRMLS_FETCH();
     242             : 
     243     1288850 :                                 if (Z_ARR_P(zvalue) == &EG(symbol_table)) {
     244           1 :                                         return; /* do nothing */
     245             :                                 }
     246     1288849 :                                 ht = Z_ARRVAL_P(zvalue);
     247     1288849 :                                 ZVAL_NEW_ARR(zvalue);
     248     1288849 :                                 zend_array_dup(Z_ARRVAL_P(zvalue), ht);
     249             :                         }
     250     1288849 :                         break;
     251             :                 case IS_CONSTANT_AST: {
     252           2 :                                 zend_ast_ref *ast = emalloc(sizeof(zend_ast_ref));
     253             : 
     254           2 :                                 GC_REFCOUNT(ast) = 1;
     255           2 :                                 GC_TYPE_INFO(ast) = IS_CONSTANT_AST;
     256           2 :                                 ast->ast = zend_ast_copy(Z_ASTVAL_P(zvalue));
     257           2 :                                 Z_AST_P(zvalue) = ast;
     258             :                         }
     259           2 :                         break;
     260             :                 case IS_OBJECT:
     261             :                 case IS_RESOURCE:
     262             :                 case IS_REFERENCE:
     263             :                         Z_ADDREF_P(zvalue);
     264             :                         break;
     265             :         }
     266             : }
     267             : 
     268             : 
     269      221647 : ZEND_API size_t zend_print_variable(zval *var TSRMLS_DC) 
     270             : {
     271      221647 :         return zend_print_zval(var, 0 TSRMLS_CC);
     272             : }
     273             : 
     274             : 
     275           6 : ZEND_API void _zval_dtor_wrapper(zval *zvalue)
     276             : {
     277             :         zval_dtor(zvalue);
     278           6 : }
     279             : 
     280             : 
     281             : #if ZEND_DEBUG
     282             : ZEND_API void _zval_copy_ctor_wrapper(zval *zvalue)
     283             : {
     284             :         zval_copy_ctor(zvalue);
     285             : }
     286             : 
     287             : 
     288             : ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue)
     289             : {
     290             :         zval_internal_dtor(zvalue);
     291             : }
     292             : 
     293             : 
     294             : ZEND_API void _zval_ptr_dtor_wrapper(zval *zval_ptr)
     295             : {
     296             :         zval_ptr_dtor(zval_ptr);
     297             : }
     298             : 
     299             : 
     300             : ZEND_API void _zval_internal_ptr_dtor_wrapper(zval *zval_ptr)
     301             : {
     302             :         zval_internal_ptr_dtor(zval_ptr);
     303             : }
     304             : #endif
     305             : 
     306         129 : ZEND_API int zval_copy_static_var(zval *p TSRMLS_DC, int num_args, va_list args, zend_hash_key *key) /* {{{ */
     307             : {
     308             :         zend_array *symbol_table;
     309         129 :         HashTable *target = va_arg(args, HashTable*);
     310             :         zend_bool is_ref;
     311             :         zval tmp;
     312             :   
     313         129 :         if (Z_CONST_FLAGS_P(p) & (IS_LEXICAL_VAR|IS_LEXICAL_REF)) {
     314         114 :                 is_ref = Z_CONST_FLAGS_P(p) & IS_LEXICAL_REF;
     315             :     
     316         114 :                 symbol_table = zend_rebuild_symbol_table(TSRMLS_C);
     317         114 :                 p = zend_hash_find(&symbol_table->ht, key->key);
     318         114 :                 if (!p) {
     319           3 :                         p = &tmp;
     320           3 :                         ZVAL_NULL(&tmp);
     321           3 :                         if (is_ref) {
     322           0 :                                 ZVAL_NEW_REF(&tmp, &tmp);
     323           0 :                                 zend_hash_add_new(&symbol_table->ht, key->key, &tmp);
     324             :                                 Z_ADDREF_P(p);
     325             :                         } else {
     326           3 :                                 zend_error(E_NOTICE,"Undefined variable: %s", key->key->val);
     327             :                         }
     328             :                 } else {
     329         111 :                         if (Z_TYPE_P(p) == IS_INDIRECT) {
     330         111 :                                 p = Z_INDIRECT_P(p);
     331         111 :                                 if (Z_TYPE_P(p) == IS_UNDEF) {
     332           6 :                                         if (!is_ref) {
     333           1 :                                                 zend_error(E_NOTICE,"Undefined variable: %s", key->key->val);
     334           1 :                                                 p = &tmp;
     335           1 :                                                 ZVAL_NULL(&tmp);
     336             :                                         } else {
     337           5 :                                                 ZVAL_NULL(p);
     338             :                                         }
     339             :                                 }
     340             :                         }
     341         111 :                         if (is_ref) {
     342          72 :                                 ZVAL_MAKE_REF(p);
     343             :                                 Z_ADDREF_P(p);
     344          75 :                         } else if (Z_ISREF_P(p)) {
     345          11 :                                 ZVAL_DUP(&tmp, Z_REFVAL_P(p));
     346          11 :                                 p = &tmp;
     347          64 :                         } else if (Z_REFCOUNTED_P(p)) {
     348             :                                 Z_ADDREF_P(p);
     349             :                         }
     350             :                 }
     351          15 :         } else if (Z_REFCOUNTED_P(p)) {
     352             :                 Z_ADDREF_P(p);
     353             :         } 
     354         129 :         zend_hash_add(target, key->key, p);
     355         129 :         return ZEND_HASH_APPLY_KEEP;
     356             : }
     357             : /* }}} */
     358             : 
     359             : /*
     360             :  * Local variables:
     361             :  * tab-width: 4
     362             :  * c-basic-offset: 4
     363             :  * indent-tabs-mode: t
     364             :  * End:
     365             :  */

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:09 +0000 (3 days ago)

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