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

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:07 +0000 (5 days ago)

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