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.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 437 488 89.5 %
Date: 2015-04-14 Functions: 37 39 94.9 %
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 "zend.h"
      23             : #include "zend_extensions.h"
      24             : #include "zend_modules.h"
      25             : #include "zend_constants.h"
      26             : #include "zend_list.h"
      27             : #include "zend_API.h"
      28             : #include "zend_exceptions.h"
      29             : #include "zend_builtin_functions.h"
      30             : #include "zend_ini.h"
      31             : #include "zend_vm.h"
      32             : #include "zend_dtrace.h"
      33             : #include "zend_virtual_cwd.h"
      34             : 
      35             : #ifdef ZTS
      36             : # define GLOBAL_FUNCTION_TABLE          global_function_table
      37             : # define GLOBAL_CLASS_TABLE                     global_class_table
      38             : # define GLOBAL_CONSTANTS_TABLE         global_constants_table
      39             : # define GLOBAL_AUTO_GLOBALS_TABLE      global_auto_globals_table
      40             : #else
      41             : # define GLOBAL_FUNCTION_TABLE          CG(function_table)
      42             : # define GLOBAL_CLASS_TABLE                     CG(class_table)
      43             : # define GLOBAL_AUTO_GLOBALS_TABLE      CG(auto_globals)
      44             : # define GLOBAL_CONSTANTS_TABLE         EG(zend_constants)
      45             : #endif
      46             : 
      47             : /* true multithread-shared globals */
      48             : ZEND_API zend_class_entry *zend_standard_class_def = NULL;
      49             : ZEND_API size_t (*zend_printf)(const char *format, ...);
      50             : ZEND_API zend_write_func_t zend_write;
      51             : ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
      52             : ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle);
      53             : ZEND_API void (*zend_block_interruptions)(void);
      54             : ZEND_API void (*zend_unblock_interruptions)(void);
      55             : ZEND_API void (*zend_ticks_function)(int ticks);
      56             : ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
      57             : size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
      58             : zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap);
      59             : ZEND_API char *(*zend_getenv)(char *name, size_t name_len);
      60             : ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len);
      61             : 
      62             : void (*zend_on_timeout)(int seconds);
      63             : 
      64             : static void (*zend_message_dispatcher_p)(zend_long message, const void *data);
      65             : static zval *(*zend_get_configuration_directive_p)(zend_string *name);
      66             : 
      67       23493 : static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
      68             : {
      69       23493 :         if (!new_value) {
      70         183 :                 EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
      71             :         } else {
      72       23310 :                 EG(error_reporting) = atoi(new_value->val);
      73             :         }
      74       23493 :         return SUCCESS;
      75             : }
      76             : /* }}} */
      77             : 
      78       20890 : static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
      79             : {
      80       20890 :         OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
      81             : 
      82       20890 :         if (GC_G(gc_enabled)) {
      83       20883 :                 gc_init();
      84             :         }
      85             : 
      86       20890 :         return SUCCESS;
      87             : }
      88             : /* }}} */
      89             : 
      90       20871 : static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
      91             : {
      92       20871 :         if (!CG(multibyte)) {
      93       20836 :                 return FAILURE;
      94             :         }
      95          35 :         if (!zend_multibyte_get_functions()) {
      96          35 :                 return SUCCESS;
      97             :         }
      98           0 :         return zend_multibyte_set_script_encoding_by_string(new_value ? new_value->val : NULL, new_value ? new_value->len : 0);
      99             : }
     100             : /* }}} */
     101             : 
     102             : 
     103             : ZEND_INI_BEGIN()
     104             :         ZEND_INI_ENTRY("error_reporting",                             NULL,           ZEND_INI_ALL,           OnUpdateErrorReporting)
     105             :         STD_ZEND_INI_BOOLEAN("zend.enable_gc",                                "1",  ZEND_INI_ALL,           OnUpdateGCEnabled,      gc_enabled,     zend_gc_globals,        gc_globals)
     106             :         STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte,      zend_compiler_globals, compiler_globals)
     107             :         ZEND_INI_ENTRY("zend.script_encoding",                        NULL,           ZEND_INI_ALL,           OnUpdateScriptEncoding)
     108             :         STD_ZEND_INI_BOOLEAN("zend.detect_unicode",                   "1",  ZEND_INI_ALL,           OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
     109             : #ifdef ZEND_SIGNALS
     110             :         STD_ZEND_INI_BOOLEAN("zend.signal_check", "0", ZEND_INI_SYSTEM, OnUpdateBool, check, zend_signal_globals_t, zend_signal_globals)
     111             : #endif
     112             : ZEND_INI_END()
     113             : 
     114             : 
     115             : #ifdef ZTS
     116             : ZEND_API int compiler_globals_id;
     117             : ZEND_API int executor_globals_id;
     118             : static HashTable *global_function_table = NULL;
     119             : static HashTable *global_class_table = NULL;
     120             : static HashTable *global_constants_table = NULL;
     121             : static HashTable *global_auto_globals_table = NULL;
     122             : static HashTable *global_persistent_list = NULL;
     123             : ZEND_TSRMLS_CACHE_DEFINE;
     124             : #endif
     125             : 
     126             : ZEND_API zend_utility_values zend_uv;
     127             : 
     128             : /* version information */
     129             : static char *zend_version_info;
     130             : static uint zend_version_info_length;
     131             : #define ZEND_CORE_VERSION_INFO  "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2015 Zend Technologies\n"
     132             : #define PRINT_ZVAL_INDENT 4
     133             : 
     134        1347 : static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object) /* {{{ */
     135             : {
     136             :         zval *tmp;
     137             :         zend_string *string_key;
     138             :         zend_ulong num_key;
     139             :         int i;
     140             : 
     141        5971 :         for (i = 0; i < indent; i++) {
     142        4624 :                 ZEND_PUTS_EX(" ");
     143             :         }
     144        1347 :         ZEND_PUTS_EX("(\n");
     145        1347 :         indent += PRINT_ZVAL_INDENT;
     146       14215 :         ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, string_key, tmp) {
     147        6315 :                 if (Z_TYPE_P(tmp) == IS_INDIRECT) {
     148         394 :                         tmp = Z_INDIRECT_P(tmp);
     149         394 :                         if (Z_TYPE_P(tmp) == IS_UNDEF) {
     150           0 :                                 continue;
     151             :                         }
     152             :                 }
     153       45511 :                 for (i = 0; i < indent; i++) {
     154       39196 :                         ZEND_PUTS_EX(" ");
     155             :                 }
     156        6315 :                 ZEND_PUTS_EX("[");
     157        6315 :                 if (string_key) {
     158        4346 :                         if (is_object) {
     159             :                                 const char *prop_name, *class_name;
     160             :                                 size_t prop_len;
     161         753 :                                 int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len);
     162             : 
     163         753 :                                 ZEND_WRITE_EX(prop_name, prop_len);
     164         753 :                                 if (class_name && mangled == SUCCESS) {
     165         215 :                                         if (class_name[0]=='*') {
     166         105 :                                                 ZEND_PUTS_EX(":protected");
     167             :                                         } else {
     168         110 :                                                 ZEND_PUTS_EX(":");
     169         110 :                                                 ZEND_PUTS_EX(class_name);
     170         110 :                                                 ZEND_PUTS_EX(":private");
     171             :                                         }
     172             :                                 }
     173             :                         } else {
     174        3593 :                                 ZEND_WRITE_EX(string_key->val, string_key->len);
     175             :                         }
     176             :                 } else {
     177             :                         char key[25];
     178        1969 :                         snprintf(key, sizeof(key), ZEND_LONG_FMT, num_key);
     179        1969 :                         ZEND_PUTS_EX(key);
     180             :                 }
     181        6315 :                 ZEND_PUTS_EX("] => ");
     182        6315 :                 zend_print_zval_r_ex(write_func, tmp, indent+PRINT_ZVAL_INDENT);
     183        6315 :                 ZEND_PUTS_EX("\n");
     184             :         } ZEND_HASH_FOREACH_END();
     185        1347 :         indent -= PRINT_ZVAL_INDENT;
     186        5971 :         for (i = 0; i < indent; i++) {
     187        4624 :                 ZEND_PUTS_EX(" ");
     188             :         }
     189        1347 :         ZEND_PUTS_EX(")\n");
     190        1347 : }
     191             : /* }}} */
     192             : 
     193          19 : static void print_flat_hash(HashTable *ht) /* {{{ */
     194             : {
     195             :         zval *tmp;
     196             :         zend_string *string_key;
     197             :         zend_ulong num_key;
     198          19 :         int i = 0;
     199             : 
     200         406 :         ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) {
     201         129 :                 if (i++ > 0) {
     202         120 :                         ZEND_PUTS(",");
     203             :                 }
     204         129 :                 ZEND_PUTS("[");
     205         129 :                 if (string_key) {
     206         125 :                         ZEND_WRITE(string_key->val, string_key->len);
     207             :                 } else {
     208           4 :                         zend_printf(ZEND_ULONG_FMT, num_key);
     209             :                 }
     210         129 :                 ZEND_PUTS("] => ");
     211         129 :                 zend_print_flat_zval_r(tmp);
     212             :         } ZEND_HASH_FOREACH_END();
     213          19 : }
     214             : /* }}} */
     215             : 
     216      603483 : ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
     217             : {
     218      603483 :         if (Z_TYPE_P(expr) == IS_STRING) {
     219           1 :                 return 0;
     220             :         } else {
     221      603482 :                 ZVAL_STR(expr_copy, _zval_get_string_func(expr));
     222      603480 :                 return 1;
     223             :         }
     224             : }
     225             : /* }}} */
     226             : 
     227        1056 : ZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */
     228             : {
     229        1056 :         return zend_print_zval_ex(zend_write, expr, indent);
     230             : }
     231             : /* }}} */
     232             : 
     233        7265 : ZEND_API size_t zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
     234             : {
     235        7265 :         zend_string *str = zval_get_string(expr);
     236        7265 :         size_t len = str->len;
     237             : 
     238        7265 :         if (len != 0) {
     239        6959 :                 write_func(str->val, len);
     240             :         }
     241             : 
     242             :         zend_string_release(str);
     243        7265 :         return len;
     244             : }
     245             : /* }}} */
     246             : 
     247         180 : ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
     248             : {
     249         180 :         switch (Z_TYPE_P(expr)) {
     250             :                 case IS_ARRAY:
     251          17 :                         ZEND_PUTS("Array (");
     252          51 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
     253          34 :                             ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
     254           0 :                                 ZEND_PUTS(" *RECURSION*");
     255           0 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     256           0 :                                 return;
     257             :                         }
     258          17 :                         print_flat_hash(Z_ARRVAL_P(expr));
     259          17 :                         ZEND_PUTS(")");
     260          17 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
     261          17 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     262             :                         }
     263          17 :                         break;
     264             :                 case IS_OBJECT:
     265             :                 {
     266           2 :                         HashTable *properties = NULL;
     267           2 :                         zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
     268           2 :                         zend_printf("%s Object (", class_name->val);
     269             :                         zend_string_release(class_name);
     270             : 
     271           2 :                         if (Z_OBJ_HANDLER_P(expr, get_properties)) {
     272           2 :                                 properties = Z_OBJPROP_P(expr);
     273             :                         }
     274           2 :                         if (properties) {
     275           2 :                                 if (++properties->u.v.nApplyCount>1) {
     276           0 :                                         ZEND_PUTS(" *RECURSION*");
     277           0 :                                         properties->u.v.nApplyCount--;
     278           0 :                                         return;
     279             :                                 }
     280           2 :                                 print_flat_hash(properties);
     281           2 :                                 properties->u.v.nApplyCount--;
     282             :                         }
     283           2 :                         ZEND_PUTS(")");
     284           2 :                         break;
     285             :                 }
     286             :                 default:
     287         161 :                         zend_print_variable(expr);
     288             :                         break;
     289             :         }
     290             : }
     291             : /* }}} */
     292             : 
     293        1253 : ZEND_API void zend_print_zval_r(zval *expr, int indent) /* {{{ */
     294             : {
     295        1253 :         zend_print_zval_r_ex(zend_write, expr, indent);
     296        1253 : }
     297             : /* }}} */
     298             : 
     299        7569 : ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
     300             : {
     301        7569 :         ZVAL_DEREF(expr);
     302        7569 :         switch (Z_TYPE_P(expr)) {
     303             :                 case IS_ARRAY:
     304        1063 :                         ZEND_PUTS_EX("Array\n");
     305        3189 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
     306        2126 :                             ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
     307           0 :                                 ZEND_PUTS_EX(" *RECURSION*");
     308           0 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     309           0 :                                 return;
     310             :                         }
     311        1063 :                         print_hash(write_func, Z_ARRVAL_P(expr), indent, 0);
     312        1063 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
     313        1063 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     314             :                         }
     315        1063 :                         break;
     316             :                 case IS_OBJECT:
     317             :                         {
     318             :                                 HashTable *properties;
     319             :                                 int is_temp;
     320             : 
     321         297 :                                 zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
     322         297 :                                 ZEND_PUTS_EX(class_name->val);
     323             :                                 zend_string_release(class_name);
     324             : 
     325         297 :                                 ZEND_PUTS_EX(" Object\n");
     326         297 :                                 if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
     327           0 :                                         break;
     328             :                                 }
     329         297 :                                 if (++properties->u.v.nApplyCount>1) {
     330          13 :                                         ZEND_PUTS_EX(" *RECURSION*");
     331          13 :                                         properties->u.v.nApplyCount--;
     332          13 :                                         return;
     333             :                                 }
     334         284 :                                 print_hash(write_func, properties, indent, 1);
     335         284 :                                 properties->u.v.nApplyCount--;
     336         284 :                                 if (is_temp) {
     337          19 :                                         zend_hash_destroy(properties);
     338          19 :                                         FREE_HASHTABLE(properties);
     339             :                                 }
     340         284 :                                 break;
     341             :                         }
     342             :                 default:
     343        6209 :                         zend_print_zval_ex(write_func, expr, indent);
     344             :                         break;
     345             :         }
     346             : }
     347             : /* }}} */
     348             : 
     349           0 : static FILE *zend_fopen_wrapper(const char *filename, char **opened_path) /* {{{ */
     350             : {
     351           0 :         if (opened_path) {
     352           0 :                 *opened_path = estrdup(filename);
     353             :         }
     354           0 :         return fopen(filename, "rb");
     355             : }
     356             : /* }}} */
     357             : 
     358             : #ifdef ZTS
     359             : static zend_bool short_tags_default      = 1;
     360             : static uint32_t compiler_options_default = ZEND_COMPILE_DEFAULT;
     361             : #else
     362             : # define short_tags_default                     1
     363             : # define compiler_options_default       ZEND_COMPILE_DEFAULT
     364             : #endif
     365             : 
     366       20871 : static void zend_set_default_compile_time_values(void) /* {{{ */
     367             : {
     368             :         /* default compile-time values */
     369       20871 :         CG(short_tags) = short_tags_default;
     370       20871 :         CG(compiler_options) = compiler_options_default;
     371       20871 : }
     372             : /* }}} */
     373             : 
     374       20871 : static void zend_init_exception_op(void) /* {{{ */
     375             : {
     376       20871 :         memset(EG(exception_op), 0, sizeof(EG(exception_op)));
     377       20871 :         EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
     378       20871 :         EG(exception_op)[0].op1_type = IS_UNUSED;
     379       20871 :         EG(exception_op)[0].op2_type = IS_UNUSED;
     380       20871 :         EG(exception_op)[0].result_type = IS_UNUSED;
     381       20871 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
     382       20871 :         EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
     383       20871 :         EG(exception_op)[1].op1_type = IS_UNUSED;
     384       20871 :         EG(exception_op)[1].op2_type = IS_UNUSED;
     385       20871 :         EG(exception_op)[1].result_type = IS_UNUSED;
     386       20871 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
     387       20871 :         EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
     388       20871 :         EG(exception_op)[2].op1_type = IS_UNUSED;
     389       20871 :         EG(exception_op)[2].op2_type = IS_UNUSED;
     390       20871 :         EG(exception_op)[2].result_type = IS_UNUSED;
     391       20871 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
     392       20871 : }
     393             : /* }}} */
     394             : 
     395             : #ifdef ZTS
     396             : static void function_copy_ctor(zval *zv)
     397             : {
     398             :         zend_function *old_func = Z_FUNC_P(zv);
     399             :         Z_FUNC_P(zv) = pemalloc(sizeof(zend_internal_function), 1);
     400             :         memcpy(Z_FUNC_P(zv), old_func, sizeof(zend_internal_function));
     401             :         function_add_ref(Z_FUNC_P(zv));
     402             : }
     403             : 
     404             : static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{{ */
     405             : {
     406             :         compiler_globals->compiled_filename = NULL;
     407             : 
     408             :         compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
     409             :         zend_hash_init_ex(compiler_globals->function_table, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
     410             :         zend_hash_copy(compiler_globals->function_table, global_function_table, function_copy_ctor);
     411             : 
     412             :         compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
     413             :         zend_hash_init_ex(compiler_globals->class_table, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
     414             :         zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref);
     415             : 
     416             :         zend_set_default_compile_time_values();
     417             : 
     418             :         compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable));
     419             :         zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0);
     420             :         zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL /* empty element */);
     421             : 
     422             :         compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table);
     423             :         if (compiler_globals->last_static_member) {
     424             :                 compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval*));
     425             :         } else {
     426             :                 compiler_globals->static_members_table = NULL;
     427             :         }
     428             :         compiler_globals->script_encoding_list = NULL;
     429             : 
     430             : #ifdef ZTS
     431             :         zend_interned_empty_string_init(&compiler_globals->empty_string);
     432             : 
     433             :         memset(compiler_globals->one_char_string, 0, sizeof(compiler_globals->one_char_string));
     434             : #endif
     435             : }
     436             : /* }}} */
     437             : 
     438             : static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{{ */
     439             : {
     440             :         if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) {
     441             :                 zend_hash_destroy(compiler_globals->function_table);
     442             :                 free(compiler_globals->function_table);
     443             :         }
     444             :         if (compiler_globals->class_table != GLOBAL_CLASS_TABLE) {
     445             :                 zend_hash_destroy(compiler_globals->class_table);
     446             :                 free(compiler_globals->class_table);
     447             :         }
     448             :         if (compiler_globals->auto_globals != GLOBAL_AUTO_GLOBALS_TABLE) {
     449             :                 zend_hash_destroy(compiler_globals->auto_globals);
     450             :                 free(compiler_globals->auto_globals);
     451             :         }
     452             :         if (compiler_globals->static_members_table) {
     453             :                 free(compiler_globals->static_members_table);
     454             :         }
     455             :         if (compiler_globals->script_encoding_list) {
     456             :                 pefree((char*)compiler_globals->script_encoding_list, 1);
     457             :         }
     458             :         compiler_globals->last_static_member = 0;
     459             : 
     460             : #ifdef ZTS
     461             :         zend_interned_empty_string_free(&compiler_globals->empty_string);
     462             : #endif
     463             : }
     464             : /* }}} */
     465             : 
     466             : static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{{ */
     467             : {
     468             :         ZEND_TSRMLS_CACHE_UPDATE;
     469             :         zend_startup_constants();
     470             :         zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE);
     471             :         zend_init_rsrc_plist();
     472             :         zend_init_exception_op();
     473             :         EG(lambda_count) = 0;
     474             :         ZVAL_UNDEF(&EG(user_error_handler));
     475             :         ZVAL_UNDEF(&EG(user_exception_handler));
     476             :         EG(in_autoload) = NULL;
     477             :         EG(current_execute_data) = NULL;
     478             :         EG(current_module) = NULL;
     479             :         EG(exit_status) = 0;
     480             : #if XPFPA_HAVE_CW
     481             :         EG(saved_fpu_cw) = 0;
     482             : #endif
     483             :         EG(saved_fpu_cw_ptr) = NULL;
     484             :         EG(active) = 0;
     485             : }
     486             : /* }}} */
     487             : 
     488             : static void executor_globals_dtor(zend_executor_globals *executor_globals) /* {{{ */
     489             : {
     490             : #ifdef ZTS
     491             :         zend_ini_dtor(executor_globals->ini_directives);
     492             : #else
     493             :         zend_ini_shutdown();
     494             : #endif
     495             :         if (&executor_globals->persistent_list != global_persistent_list) {
     496             :                 zend_destroy_rsrc_list(&executor_globals->persistent_list);
     497             :         }
     498             :         if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) {
     499             :                 zend_hash_destroy(executor_globals->zend_constants);
     500             :                 free(executor_globals->zend_constants);
     501             :         }
     502             : }
     503             : /* }}} */
     504             : 
     505             : static void zend_new_thread_end_handler(THREAD_T thread_id) /* {{{ */
     506             : {
     507             :         if (zend_copy_ini_directives() == SUCCESS) {
     508             :                 zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP);
     509             :         }
     510             : }
     511             : /* }}} */
     512             : #endif
     513             : 
     514             : #if defined(__FreeBSD__) || defined(__DragonFly__)
     515             : /* FreeBSD and DragonFly floating point precision fix */
     516             : #include <floatingpoint.h>
     517             : #endif
     518             : 
     519       20871 : static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p) /* {{{ */
     520             : {
     521       20871 :         memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
     522       20871 : }
     523             : /* }}} */
     524             : 
     525       20871 : static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p) /* {{{ */
     526             : {
     527       20871 :         memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
     528       20871 : }
     529             : /* }}} */
     530             : 
     531             : void zend_init_opcodes_handlers(void);
     532             : 
     533     1484500 : static void module_destructor_zval(zval *zv) /* {{{ */
     534             : {
     535     1484500 :         zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv);
     536             : 
     537     1484500 :         module_destructor(module);
     538     1484500 :         free(module);
     539     1484500 : }
     540             : /* }}} */
     541             : 
     542      188145 : static void auto_global_dtor(zval *zv) /* {{{ */
     543             : {
     544      188145 :         free(Z_PTR_P(zv));
     545      188145 : }
     546             : /* }}} */
     547             : 
     548         171 : static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */
     549             : {
     550             :         zval globals;
     551             : 
     552         171 :         ZVAL_ARR(&globals, &EG(symbol_table));
     553         171 :         Z_TYPE_INFO_P(&globals) = IS_ARRAY | (IS_TYPE_SYMBOLTABLE << Z_TYPE_FLAGS_SHIFT);
     554         171 :         ZVAL_NEW_REF(&globals, &globals);
     555         171 :         zend_hash_update(&EG(symbol_table), name, &globals);
     556         171 :         return 0;
     557             : }
     558             : /* }}} */
     559             : 
     560       20871 : int zend_startup(zend_utility_functions *utility_functions, char **extensions) /* {{{ */
     561             : {
     562             : #ifdef ZTS
     563             :         zend_compiler_globals *compiler_globals;
     564             :         zend_executor_globals *executor_globals;
     565             :         extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
     566             :         extern ZEND_API ts_rsrc_id language_scanner_globals_id;
     567             :         ZEND_TSRMLS_CACHE_UPDATE;
     568             : #else
     569             :         extern zend_ini_scanner_globals ini_scanner_globals;
     570             :         extern zend_php_scanner_globals language_scanner_globals;
     571             : #endif
     572             : 
     573       20871 :         start_memory_manager();
     574             : 
     575       20871 :         virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
     576             : 
     577             : #if defined(__FreeBSD__) || defined(__DragonFly__)
     578             :         /* FreeBSD and DragonFly floating point precision fix */
     579             :         fpsetmask(0);
     580             : #endif
     581             : 
     582       20871 :         zend_startup_strtod();
     583       20871 :         zend_startup_extensions_mechanism();
     584             : 
     585             :         /* Set up utility functions and values */
     586       20871 :         zend_error_cb = utility_functions->error_function;
     587       20871 :         zend_printf = utility_functions->printf_function;
     588       20871 :         zend_write = (zend_write_func_t) utility_functions->write_function;
     589       20871 :         zend_fopen = utility_functions->fopen_function;
     590       20871 :         if (!zend_fopen) {
     591           0 :                 zend_fopen = zend_fopen_wrapper;
     592             :         }
     593       20871 :         zend_stream_open_function = utility_functions->stream_open_function;
     594       20871 :         zend_message_dispatcher_p = utility_functions->message_handler;
     595             : #ifndef ZEND_SIGNALS
     596       20871 :         zend_block_interruptions = utility_functions->block_interruptions;
     597       20871 :         zend_unblock_interruptions = utility_functions->unblock_interruptions;
     598             : #endif
     599       20871 :         zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
     600       20871 :         zend_ticks_function = utility_functions->ticks_function;
     601       20871 :         zend_on_timeout = utility_functions->on_timeout;
     602       20871 :         zend_vspprintf = utility_functions->vspprintf_function;
     603       20871 :         zend_vstrpprintf = utility_functions->vstrpprintf_function;
     604       20871 :         zend_getenv = utility_functions->getenv_function;
     605       20871 :         zend_resolve_path = utility_functions->resolve_path_function;
     606             : 
     607             : #if HAVE_DTRACE
     608             : /* build with dtrace support */
     609             :         zend_compile_file = dtrace_compile_file;
     610             :         zend_execute_ex = dtrace_execute_ex;
     611             :         zend_execute_internal = dtrace_execute_internal;
     612             : #else
     613       20871 :         zend_compile_file = compile_file;
     614       20871 :         zend_execute_ex = execute_ex;
     615       20871 :         zend_execute_internal = NULL;
     616             : #endif /* HAVE_SYS_SDT_H */
     617       20871 :         zend_compile_string = compile_string;
     618       20871 :         zend_throw_exception_hook = NULL;
     619             : 
     620             :         /* Set up the default garbage collection implementation. */
     621       20871 :         gc_collect_cycles = zend_gc_collect_cycles;
     622             : 
     623       20871 :         zend_init_opcodes_handlers();
     624             : 
     625             :         /* set up version */
     626       20871 :         zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
     627       20871 :         zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
     628             : 
     629       20871 :         GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
     630       20871 :         GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     631       20871 :         GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     632       20871 :         GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     633             : 
     634       20871 :         zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
     635       20871 :         zend_hash_init_ex(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
     636       20871 :         zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0);
     637       20871 :         zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1, 0);
     638             : 
     639       20871 :         zend_hash_init_ex(&module_registry, 32, NULL, module_destructor_zval, 1, 0);
     640       20871 :         zend_init_rsrc_list_dtors();
     641             : 
     642             : #ifdef ZTS
     643             :         ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
     644             :         ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
     645             :         ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
     646             :         ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
     647             :         compiler_globals = ts_resource(compiler_globals_id);
     648             :         executor_globals = ts_resource(executor_globals_id);
     649             : 
     650             :         compiler_globals_dtor(compiler_globals);
     651             :         compiler_globals->in_compilation = 0;
     652             :         compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
     653             :         compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
     654             : 
     655             :         *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
     656             :         *compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
     657             :         compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
     658             : 
     659             :         zend_hash_destroy(executor_globals->zend_constants);
     660             :         *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
     661             : #else
     662       20871 :         ini_scanner_globals_ctor(&ini_scanner_globals);
     663       20871 :         php_scanner_globals_ctor(&language_scanner_globals);
     664       20871 :         zend_set_default_compile_time_values();
     665       20871 :         ZVAL_UNDEF(&EG(user_error_handler));
     666       20871 :         ZVAL_UNDEF(&EG(user_exception_handler));
     667             : #endif
     668             : 
     669       20871 :         zend_interned_strings_init();
     670       20871 :         zend_startup_builtin_functions();
     671       20871 :         zend_register_standard_constants();
     672       20871 :         zend_register_auto_global(zend_string_init("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals);
     673             : 
     674             : #ifndef ZTS
     675       20871 :         zend_init_rsrc_plist();
     676       20871 :         zend_init_exception_op();
     677             : #endif
     678             : 
     679       20871 :         zend_ini_startup();
     680             : 
     681             : #ifdef ZTS
     682             :         tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
     683             : #endif
     684             : 
     685       20871 :         return SUCCESS;
     686             : }
     687             : /* }}} */
     688             : 
     689       20871 : void zend_register_standard_ini_entries(void) /* {{{ */
     690             : {
     691       20871 :         int module_number = 0;
     692             : 
     693       20871 :         REGISTER_INI_ENTRIES();
     694       20871 : }
     695             : /* }}} */
     696             : 
     697             : /* Unlink the global (r/o) copies of the class, function and constant tables,
     698             :  * and use a fresh r/w copy for the startup thread
     699             :  */
     700       20871 : void zend_post_startup(void) /* {{{ */
     701             : {
     702             : #ifdef ZTS
     703             :         zend_encoding **script_encoding_list;
     704             : 
     705             :         zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
     706             :         zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
     707             : 
     708             :         *GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
     709             :         *GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
     710             :         *GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
     711             : 
     712             :         short_tags_default = CG(short_tags);
     713             :         compiler_options_default = CG(compiler_options);
     714             : 
     715             :         zend_destroy_rsrc_list(&EG(persistent_list));
     716             :         free(compiler_globals->function_table);
     717             :         free(compiler_globals->class_table);
     718             :         if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
     719             :                 compiler_globals_ctor(compiler_globals);
     720             :                 compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
     721             :         } else {
     722             :                 compiler_globals_ctor(compiler_globals);
     723             :         }
     724             :         free(EG(zend_constants));
     725             : 
     726             :         virtual_cwd_deactivate();
     727             : 
     728             :         executor_globals_ctor(executor_globals);
     729             :         global_persistent_list = &EG(persistent_list);
     730             :         zend_copy_ini_directives();
     731             : #else
     732       20871 :         virtual_cwd_deactivate();
     733             : #endif
     734       20871 : }
     735             : /* }}} */
     736             : 
     737       20905 : void zend_shutdown(void) /* {{{ */
     738             : {
     739             : #ifdef ZEND_SIGNALS
     740             :         zend_signal_shutdown();
     741             : #endif
     742       20905 :         zend_destroy_rsrc_list(&EG(persistent_list));
     743       20905 :         if (EG(active))
     744             :         {
     745             :                 /*
     746             :                  * The order of destruction is important here.
     747             :                  * See bugs #65463 and 66036.
     748             :                  */
     749             :                 zend_function *func;
     750             :                 zend_class_entry *ce;
     751             : 
     752           0 :                 ZEND_HASH_REVERSE_FOREACH_PTR(GLOBAL_FUNCTION_TABLE, func) {
     753           0 :                         if (func->type == ZEND_USER_FUNCTION) {
     754           0 :                                 zend_cleanup_op_array_data((zend_op_array *) func);
     755             :                         }
     756             :                 } ZEND_HASH_FOREACH_END();
     757           0 :                 ZEND_HASH_REVERSE_FOREACH_PTR(GLOBAL_CLASS_TABLE, ce) {
     758           0 :                         if (ce->type == ZEND_USER_CLASS) {
     759           0 :                                 zend_cleanup_user_class_data(ce);
     760             :                         } else {
     761           0 :                                 break;
     762             :                         }
     763             :                 } ZEND_HASH_FOREACH_END();
     764           0 :                 zend_cleanup_internal_classes();
     765           0 :                 zend_hash_reverse_apply(GLOBAL_FUNCTION_TABLE, (apply_func_t) clean_non_persistent_function_full);
     766           0 :                 zend_hash_reverse_apply(GLOBAL_CLASS_TABLE, (apply_func_t) clean_non_persistent_class_full);
     767             :         }
     768       20905 :         zend_destroy_modules();
     769             : 
     770       20905 :         virtual_cwd_deactivate();
     771       20905 :         virtual_cwd_shutdown();
     772             : 
     773       20905 :         zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
     774       20905 :         zend_hash_destroy(GLOBAL_CLASS_TABLE);
     775             : 
     776       20905 :         zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
     777       20905 :         free(GLOBAL_AUTO_GLOBALS_TABLE);
     778             : 
     779       20905 :         zend_shutdown_extensions();
     780       20905 :         free(zend_version_info);
     781             : 
     782       20905 :         free(GLOBAL_FUNCTION_TABLE);
     783       20905 :         free(GLOBAL_CLASS_TABLE);
     784             : 
     785       20905 :         zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
     786       20905 :         free(GLOBAL_CONSTANTS_TABLE);
     787       20905 :         zend_shutdown_strtod();
     788             : 
     789             : #ifdef ZTS
     790             :         GLOBAL_FUNCTION_TABLE = NULL;
     791             :         GLOBAL_CLASS_TABLE = NULL;
     792             :         GLOBAL_AUTO_GLOBALS_TABLE = NULL;
     793             :         GLOBAL_CONSTANTS_TABLE = NULL;
     794             : #endif
     795       20905 :         zend_destroy_rsrc_list_dtors();
     796             : 
     797       20905 :         zend_interned_strings_dtor();
     798       20905 : }
     799             : /* }}} */
     800             : 
     801       20871 : void zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
     802             : {
     803       20871 :         zend_uv = *utility_values;
     804       20871 :         zend_uv.import_use_extension_length = (uint)strlen(zend_uv.import_use_extension);
     805       20871 : }
     806             : /* }}} */
     807             : 
     808             : /* this should be compatible with the standard zenderror */
     809          38 : void zenderror(const char *error) /* {{{ */
     810             : {
     811          38 :         zend_error(E_PARSE, "%s", error);
     812          38 : }
     813             : /* }}} */
     814             : 
     815             : BEGIN_EXTERN_C()
     816        2223 : ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
     817             : {
     818             : 
     819        2223 :         if (!EG(bailout)) {
     820           0 :                 zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
     821           0 :                 exit(-1);
     822             :         }
     823        2223 :         CG(unclean_shutdown) = 1;
     824        2223 :         CG(active_class_entry) = NULL;
     825        2223 :         CG(in_compilation) = 0;
     826        2223 :         EG(current_execute_data) = NULL;
     827        2223 :         LONGJMP(*EG(bailout), FAILURE);
     828             : }
     829             : /* }}} */
     830             : END_EXTERN_C()
     831             : 
     832       20712 : ZEND_API void zend_append_version_info(const zend_extension *extension) /* {{{ */
     833             : {
     834             :         char *new_info;
     835             :         uint new_info_length;
     836             : 
     837       82848 :         new_info_length = (uint)(sizeof("    with  v, , by \n")
     838       20712 :                                                 + strlen(extension->name)
     839       20712 :                                                 + strlen(extension->version)
     840       20712 :                                                 + strlen(extension->copyright)
     841       20712 :                                                 + strlen(extension->author));
     842             : 
     843       20712 :         new_info = (char *) malloc(new_info_length + 1);
     844             : 
     845       20712 :         snprintf(new_info, new_info_length, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
     846             : 
     847       20712 :         zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
     848       20712 :         strncat(zend_version_info, new_info, new_info_length);
     849       20712 :         zend_version_info_length += new_info_length;
     850       20712 :         free(new_info);
     851       20712 : }
     852             : /* }}} */
     853             : 
     854         168 : ZEND_API char *get_zend_version(void) /* {{{ */
     855             : {
     856         168 :         return zend_version_info;
     857             : }
     858             : /* }}} */
     859             : 
     860       20828 : ZEND_API void zend_activate(void) /* {{{ */
     861             : {
     862             : #ifdef ZTS
     863             :         virtual_cwd_activate();
     864             : #endif
     865       20828 :         gc_reset();
     866       20828 :         init_compiler();
     867       20828 :         init_executor();
     868       20828 :         startup_scanner();
     869       20828 : }
     870             : /* }}} */
     871             : 
     872       20864 : void zend_call_destructors(void) /* {{{ */
     873             : {
     874       20864 :         zend_try {
     875       20864 :                 shutdown_destructors();
     876       20864 :         } zend_end_try();
     877       20864 : }
     878             : /* }}} */
     879             : 
     880       20864 : ZEND_API void zend_deactivate(void) /* {{{ */
     881             : {
     882             :         /* we're no longer executing anything */
     883       20864 :         EG(current_execute_data) = NULL;
     884             : 
     885       20864 :         zend_try {
     886       20864 :                 shutdown_scanner();
     887       20864 :         } zend_end_try();
     888             : 
     889             :         /* shutdown_executor() takes care of its own bailout handling */
     890       20864 :         shutdown_executor();
     891             : 
     892       20864 :         zend_try {
     893       20864 :                 shutdown_compiler();
     894       20864 :         } zend_end_try();
     895             : 
     896       20864 :         zend_destroy_rsrc_list(&EG(regular_list));
     897             : 
     898             : #if ZEND_DEBUG
     899             :         if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
     900             :                 gc_collect_cycles();
     901             :         }
     902             : #endif
     903             : 
     904             : #if GC_BENCH
     905             :         fprintf(stderr, "GC Statistics\n");
     906             :         fprintf(stderr, "-------------\n");
     907             :         fprintf(stderr, "Runs:               %d\n", GC_G(gc_runs));
     908             :         fprintf(stderr, "Collected:          %d\n", GC_G(collected));
     909             :         fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
     910             :         fprintf(stderr, "Root buffer peak:   %d\n\n", GC_G(root_buf_peak));
     911             :         fprintf(stderr, "      Possible            Remove from  Marked\n");
     912             :         fprintf(stderr, "        Root    Buffered     buffer     grey\n");
     913             :         fprintf(stderr, "      --------  --------  -----------  ------\n");
     914             :         fprintf(stderr, "ZVAL  %8d  %8d  %9d  %8d\n", GC_G(zval_possible_root), GC_G(zval_buffered), GC_G(zval_remove_from_buffer), GC_G(zval_marked_grey));
     915             :         fprintf(stderr, "ZOBJ  %8d  %8d  %9d  %8d\n", GC_G(zobj_possible_root), GC_G(zobj_buffered), GC_G(zobj_remove_from_buffer), GC_G(zobj_marked_grey));
     916             : #endif
     917             : 
     918       20864 :         zend_try {
     919       20864 :                 zend_ini_deactivate();
     920       20864 :         } zend_end_try();
     921       20864 : }
     922             : /* }}} */
     923             : 
     924             : BEGIN_EXTERN_C()
     925          34 : ZEND_API void zend_message_dispatcher(zend_long message, const void *data) /* {{{ */
     926             : {
     927          34 :         if (zend_message_dispatcher_p) {
     928          34 :                 zend_message_dispatcher_p(message, data);
     929             :         }
     930          31 : }
     931             : /* }}} */
     932             : END_EXTERN_C()
     933             : 
     934     5446296 : ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */
     935             : {
     936     5446296 :         if (zend_get_configuration_directive_p) {
     937     5446296 :                 return zend_get_configuration_directive_p(name);
     938             :         } else {
     939           0 :                 return NULL;
     940             :         }
     941             : }
     942             : /* }}} */
     943             : 
     944             : #define SAVE_STACK(stack) do { \
     945             :                 if (CG(stack).top) { \
     946             :                         memcpy(&stack, &CG(stack), sizeof(zend_stack)); \
     947             :                         CG(stack).top = CG(stack).max = 0; \
     948             :                         CG(stack).elements = NULL; \
     949             :                 } else { \
     950             :                         stack.top = 0; \
     951             :                 } \
     952             :         } while (0)
     953             : 
     954             : #define RESTORE_STACK(stack) do { \
     955             :                 if (stack.top) { \
     956             :                         zend_stack_destroy(&CG(stack)); \
     957             :                         memcpy(&CG(stack), &stack, sizeof(zend_stack)); \
     958             :                 } \
     959             :         } while (0)
     960             : 
     961             : #if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS)
     962      379083 : ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
     963             : #else
     964             : static void zend_error_va_list(int type, const char *format, va_list args)
     965             : #endif
     966             : {
     967             :         char *str;
     968             :         int len;
     969             : #if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS)
     970             :         va_list args;
     971             : #endif
     972             :         va_list usr_copy;
     973             :         zval params[5];
     974             :         zval retval;
     975             :         const char *error_filename;
     976      379083 :         uint error_lineno = 0;
     977             :         zval orig_user_error_handler;
     978             :         zend_bool in_compilation;
     979             :         zend_class_entry *saved_class_entry;
     980             :         zend_stack loop_var_stack;
     981             :         zend_stack delayed_oplines_stack;
     982             :         zend_stack context_stack;
     983             :         zend_array *symbol_table;
     984             : 
     985             :         /* Report about uncaught exception in case of fatal errors */
     986      379083 :         if (EG(exception)) {
     987             :                 zend_execute_data *ex;
     988             :                 const zend_op *opline;
     989             : 
     990          44 :                 switch (type) {
     991             :                         case E_CORE_ERROR:
     992             :                         case E_ERROR:
     993             :                         case E_RECOVERABLE_ERROR:
     994             :                         case E_PARSE:
     995             :                         case E_COMPILE_ERROR:
     996             :                         case E_USER_ERROR:
     997           3 :                                 ex = EG(current_execute_data);
     998           3 :                                 opline = NULL;
     999           8 :                                 while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
    1000           2 :                                         ex = ex->prev_execute_data;
    1001             :                                 }
    1002           4 :                                 if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
    1003           1 :                                     EG(opline_before_exception)) {
    1004           1 :                                         opline = EG(opline_before_exception);
    1005             :                                 }
    1006           3 :                                 zend_exception_error(EG(exception), E_WARNING);
    1007           3 :                                 EG(exception) = NULL;
    1008           3 :                                 if (opline) {
    1009           1 :                                         ex->opline = opline;
    1010             :                                 }
    1011             :                                 break;
    1012             :                         default:
    1013             :                                 break;
    1014             :                 }
    1015             :         }
    1016             : 
    1017             :         /* Obtain relevant filename and lineno */
    1018      379083 :         switch (type) {
    1019             :                 case E_CORE_ERROR:
    1020             :                 case E_CORE_WARNING:
    1021           5 :                         error_filename = NULL;
    1022           5 :                         error_lineno = 0;
    1023           5 :                         break;
    1024             :                 case E_PARSE:
    1025             :                 case E_COMPILE_ERROR:
    1026             :                 case E_COMPILE_WARNING:
    1027             :                 case E_ERROR:
    1028             :                 case E_NOTICE:
    1029             :                 case E_STRICT:
    1030             :                 case E_DEPRECATED:
    1031             :                 case E_WARNING:
    1032             :                 case E_USER_ERROR:
    1033             :                 case E_USER_WARNING:
    1034             :                 case E_USER_NOTICE:
    1035             :                 case E_USER_DEPRECATED:
    1036             :                 case E_RECOVERABLE_ERROR:
    1037      379078 :                         if (zend_is_compiling()) {
    1038         324 :                                 error_filename = zend_get_compiled_filename()->val;
    1039         324 :                                 error_lineno = zend_get_compiled_lineno();
    1040      378754 :                         } else if (zend_is_executing()) {
    1041      378716 :                                 error_filename = zend_get_executed_filename();
    1042      378716 :                                 if (error_filename[0] == '[') { /* [no active file] */
    1043           6 :                                         error_filename = NULL;
    1044           6 :                                         error_lineno = 0;
    1045             :                                 } else {
    1046      378710 :                                         error_lineno = zend_get_executed_lineno();
    1047             :                                 }
    1048             :                         } else {
    1049          38 :                                 error_filename = NULL;
    1050          38 :                                 error_lineno = 0;
    1051             :                         }
    1052      379078 :                         break;
    1053             :                 default:
    1054           0 :                         error_filename = NULL;
    1055           0 :                         error_lineno = 0;
    1056             :                         break;
    1057             :         }
    1058      379083 :         if (!error_filename) {
    1059          49 :                 error_filename = "Unknown";
    1060             :         }
    1061             : 
    1062             : #ifdef HAVE_DTRACE
    1063             :         if (DTRACE_ERROR_ENABLED()) {
    1064             :                 char *dtrace_error_buffer;
    1065             : #if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS)
    1066             :                 va_start(args, format);
    1067             : #endif
    1068             :                 zend_vspprintf(&dtrace_error_buffer, 0, format, args);
    1069             :                 DTRACE_ERROR(dtrace_error_buffer, (char *)error_filename, error_lineno);
    1070             :                 efree(dtrace_error_buffer);
    1071             : #if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS)
    1072             :                 va_end(args);
    1073             : #endif
    1074             :         }
    1075             : #endif /* HAVE_DTRACE */
    1076             : 
    1077             : #if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS)
    1078      379083 :         va_start(args, format);
    1079             : #endif
    1080             : 
    1081             :         /* if we don't have a user defined error handler */
    1082      761183 :         if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF
    1083        3758 :                 || !(EG(user_error_handler_error_reporting) & type)
    1084        3728 :                 || EG(error_handling) != EH_NORMAL) {
    1085      375355 :                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1086        3728 :         } else switch (type) {
    1087             :                 case E_ERROR:
    1088             :                 case E_PARSE:
    1089             :                 case E_CORE_ERROR:
    1090             :                 case E_CORE_WARNING:
    1091             :                 case E_COMPILE_ERROR:
    1092             :                 case E_COMPILE_WARNING:
    1093             :                         /* The error may not be safe to handle in user-space */
    1094           5 :                         zend_error_cb(type, error_filename, error_lineno, format, args);
    1095           0 :                         break;
    1096             :                 default:
    1097             :                         /* Handle the error in user space */
    1098             : /* va_copy() is __va_copy() in old gcc versions.
    1099             :  * According to the autoconf manual, using
    1100             :  * memcpy(&dst, &src, sizeof(va_list))
    1101             :  * gives maximum portability. */
    1102             : #ifndef va_copy
    1103             : # ifdef __va_copy
    1104             : #  define va_copy(dest, src)    __va_copy((dest), (src))
    1105             : # else
    1106             : #  define va_copy(dest, src)    memcpy(&(dest), &(src), sizeof(va_list))
    1107             : # endif
    1108             : #endif
    1109        3723 :                         va_copy(usr_copy, args);
    1110        3723 :                         len = (int)zend_vspprintf(&str, 0, format, usr_copy);
    1111        7446 :                         ZVAL_NEW_STR(&params[1], zend_string_init(str, len, 0));
    1112        3723 :                         efree(str);
    1113             : #ifdef va_copy
    1114        3723 :                         va_end(usr_copy);
    1115             : #endif
    1116             : 
    1117        3723 :                         ZVAL_LONG(&params[0], type);
    1118             : 
    1119        3723 :                         if (error_filename) {
    1120        7446 :                                 ZVAL_STRING(&params[2], error_filename);
    1121             :                         } else {
    1122           0 :                                 ZVAL_NULL(&params[2]);
    1123             :                         }
    1124             : 
    1125        3723 :                         ZVAL_LONG(&params[3], error_lineno);
    1126             : 
    1127        3723 :                         symbol_table = zend_rebuild_symbol_table();
    1128             : 
    1129             :                         /* during shutdown the symbol table table can be still null */
    1130        3723 :                         if (!symbol_table) {
    1131           0 :                                 ZVAL_NULL(&params[4]);
    1132             :                         } else {
    1133        3723 :                                 ZVAL_ARR(&params[4], zend_array_dup(symbol_table));
    1134             :                         }
    1135             : 
    1136        3723 :                         ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler));
    1137        3723 :                         ZVAL_UNDEF(&EG(user_error_handler));
    1138             : 
    1139             :                         /* User error handler may include() additinal PHP files.
    1140             :                          * If an error was generated during comilation PHP will compile
    1141             :                          * such scripts recursivly, but some CG() variables may be
    1142             :                          * inconsistent. */
    1143             : 
    1144        3723 :                         in_compilation = CG(in_compilation);
    1145        3723 :                         if (in_compilation) {
    1146           2 :                                 saved_class_entry = CG(active_class_entry);
    1147           2 :                                 CG(active_class_entry) = NULL;
    1148           2 :                                 SAVE_STACK(loop_var_stack);
    1149           2 :                                 SAVE_STACK(delayed_oplines_stack);
    1150           2 :                                 SAVE_STACK(context_stack);
    1151           2 :                                 CG(in_compilation) = 0;
    1152             :                         }
    1153             : 
    1154        3723 :                         ZVAL_UNDEF(&retval);
    1155        3723 :                         if (call_user_function_ex(CG(function_table), NULL, &orig_user_error_handler, &retval, 5, params, 1, NULL) == SUCCESS) {
    1156        3723 :                                 if (Z_TYPE(retval) != IS_UNDEF) {
    1157        3699 :                                         if (Z_TYPE(retval) == IS_FALSE) {
    1158           1 :                                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1159             :                                         }
    1160        3699 :                                         zval_ptr_dtor(&retval);
    1161             :                                 }
    1162           0 :                         } else if (!EG(exception)) {
    1163             :                                 /* The user error handler failed, use built-in error handler */
    1164           0 :                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1165             :                         }
    1166             : 
    1167        3723 :                         if (in_compilation) {
    1168           2 :                                 CG(active_class_entry) = saved_class_entry;
    1169           2 :                                 RESTORE_STACK(loop_var_stack);
    1170           2 :                                 RESTORE_STACK(delayed_oplines_stack);
    1171           2 :                                 RESTORE_STACK(context_stack);
    1172           2 :                                 CG(in_compilation) = 1;
    1173             :                         }
    1174             : 
    1175        3723 :                         zval_ptr_dtor(&params[4]);
    1176        3723 :                         zval_ptr_dtor(&params[3]);
    1177        3723 :                         zval_ptr_dtor(&params[2]);
    1178        3723 :                         zval_ptr_dtor(&params[1]);
    1179        3723 :                         zval_ptr_dtor(&params[0]);
    1180             : 
    1181        3723 :                         if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF) {
    1182        3723 :                                 ZVAL_COPY_VALUE(&EG(user_error_handler), &orig_user_error_handler);
    1183             :                         } else {
    1184           0 :                                 zval_ptr_dtor(&orig_user_error_handler);
    1185             :                         }
    1186             :                         break;
    1187             :         }
    1188             : 
    1189             : #if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS)
    1190      378337 :         va_end(args);
    1191             : #endif
    1192             : 
    1193      378337 :         if (type == E_PARSE) {
    1194             :                 /* eval() errors do not affect exit_status */
    1195          82 :                 if (!(EG(current_execute_data) &&
    1196          15 :                         EG(current_execute_data)->func &&
    1197          15 :                         ZEND_USER_CODE(EG(current_execute_data)->func->type) &&
    1198           7 :                         EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL &&
    1199           7 :                         EG(current_execute_data)->opline->extended_value == ZEND_EVAL)) {
    1200          35 :                         EG(exit_status) = 255;
    1201             :                 }
    1202             :         }
    1203      378337 : }
    1204             : /* }}} */
    1205             : 
    1206             : #ifdef HAVE_NORETURN
    1207             : # ifdef HAVE_NORETURN_ALIAS
    1208             : void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
    1209             : # else
    1210             : ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
    1211             : {
    1212             :         va_list va;
    1213             : 
    1214             :         va_start(va, format);
    1215             :         zend_error_va_list(type, format, va);
    1216             :         va_end(va);
    1217             : }
    1218             : 
    1219             : ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
    1220             : {
    1221             :         va_list va;
    1222             : 
    1223             :         va_start(va, format);
    1224             :         zend_error_va_list(type, format, va);
    1225             :         va_end(va);
    1226             : }
    1227             : /* }}} */
    1228             : # endif
    1229             : #endif
    1230             : 
    1231           0 : ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) /* {{{ */
    1232             : {
    1233             : #if ZEND_DEBUG
    1234             :         va_list args;
    1235             : 
    1236             :         va_start(args, format);
    1237             : #       ifdef ZEND_WIN32
    1238             :         {
    1239             :                 char output_buf[1024];
    1240             : 
    1241             :                 vsnprintf(output_buf, 1024, format, args);
    1242             :                 OutputDebugString(output_buf);
    1243             :                 OutputDebugString("\n");
    1244             :                 if (trigger_break && IsDebuggerPresent()) {
    1245             :                         DebugBreak();
    1246             :                 }
    1247             :         }
    1248             : #       else
    1249             :         vfprintf(stderr, format, args);
    1250             :         fprintf(stderr, "\n");
    1251             : #       endif
    1252             :         va_end(args);
    1253             : #endif
    1254           0 : }
    1255             : /* }}} */
    1256             : 
    1257       20769 : ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */
    1258             : {
    1259             :         va_list files;
    1260             :         int i;
    1261             :         zend_file_handle *file_handle;
    1262             :         zend_op_array *op_array;
    1263             : 
    1264       20769 :         va_start(files, file_count);
    1265       79354 :         for (i = 0; i < file_count; i++) {
    1266       60446 :                 file_handle = va_arg(files, zend_file_handle *);
    1267       60446 :                 if (!file_handle) {
    1268       39676 :                         continue;
    1269             :                 }
    1270             : 
    1271       20770 :                 op_array = zend_compile_file(file_handle, type);
    1272       20531 :                 if (file_handle->opened_path) {
    1273       20528 :                         zend_hash_str_add_empty_element(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path));
    1274             :                 }
    1275       20531 :                 zend_destroy_file_handle(file_handle);
    1276       20531 :                 if (op_array) {
    1277       20531 :                         zend_execute(op_array, retval);
    1278       19007 :                         zend_exception_restore();
    1279       19007 :                         if (EG(exception)) {
    1280         106 :                                 if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
    1281             :                                         zval orig_user_exception_handler;
    1282             :                                         zval params[1], retval2;
    1283             :                                         zend_object *old_exception;
    1284          10 :                                         old_exception = EG(exception);
    1285          10 :                                         EG(exception) = NULL;
    1286          10 :                                         ZVAL_OBJ(&params[0], old_exception);
    1287          10 :                                         ZVAL_COPY_VALUE(&orig_user_exception_handler, &EG(user_exception_handler));
    1288          10 :                                         ZVAL_UNDEF(&retval2);
    1289          10 :                                         if (call_user_function_ex(CG(function_table), NULL, &orig_user_exception_handler, &retval2, 1, params, 1, NULL) == SUCCESS) {
    1290           8 :                                                 zval_ptr_dtor(&retval2);
    1291           8 :                                                 if (EG(exception)) {
    1292           0 :                                                         OBJ_RELEASE(EG(exception));
    1293           0 :                                                         EG(exception) = NULL;
    1294             :                                                 }
    1295             :                                                 OBJ_RELEASE(old_exception);
    1296             :                                         } else {
    1297           0 :                                                 EG(exception) = old_exception;
    1298           0 :                                                 zend_exception_error(EG(exception), E_ERROR);
    1299             :                                         }
    1300             :                                 } else {
    1301          96 :                                         zend_exception_error(EG(exception), E_ERROR);
    1302             :                                 }
    1303             :                         }
    1304       18909 :                         destroy_op_array(op_array);
    1305       18909 :                         efree_size(op_array, sizeof(zend_op_array));
    1306           0 :                 } else if (type==ZEND_REQUIRE) {
    1307           0 :                         va_end(files);
    1308           0 :                         return FAILURE;
    1309             :                 }
    1310             :         }
    1311       18908 :         va_end(files);
    1312             : 
    1313       18908 :         return SUCCESS;
    1314             : }
    1315             : /* }}} */
    1316             : 
    1317             : #define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
    1318             : 
    1319        1060 : ZEND_API char *zend_make_compiled_string_description(const char *name) /* {{{ */
    1320             : {
    1321             :         const char *cur_filename;
    1322             :         int cur_lineno;
    1323             :         char *compiled_string_description;
    1324             : 
    1325        1060 :         if (zend_is_compiling()) {
    1326           0 :                 cur_filename = zend_get_compiled_filename()->val;
    1327           0 :                 cur_lineno = zend_get_compiled_lineno();
    1328        1060 :         } else if (zend_is_executing()) {
    1329        1060 :                 cur_filename = zend_get_executed_filename();
    1330        1060 :                 cur_lineno = zend_get_executed_lineno();
    1331             :         } else {
    1332           0 :                 cur_filename = "Unknown";
    1333           0 :                 cur_lineno = 0;
    1334             :         }
    1335             : 
    1336        1060 :         zend_spprintf(&compiled_string_description, 0, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
    1337        1060 :         return compiled_string_description;
    1338             : }
    1339             : /* }}} */
    1340             : 
    1341       20712 : void free_estring(char **str_p) /* {{{ */
    1342             : {
    1343       20712 :         efree(*str_p);
    1344       20712 : }
    1345             : /* }}} */
    1346             : 
    1347       29478 : void free_string_zval(zval *zv) /* {{{ */
    1348             : {
    1349       29478 :         zend_string *str = Z_PTR_P(zv);
    1350             :         zend_string_release(str);
    1351       29478 : }
    1352             : /* }}} */
    1353             : 
    1354             : /*
    1355             :  * Local variables:
    1356             :  * tab-width: 4
    1357             :  * c-basic-offset: 4
    1358             :  * indent-tabs-mode: t
    1359             :  * End:
    1360             :  */

Generated by: LCOV version 1.10

Generated at Tue, 14 Apr 2015 11:48:39 +0000 (5 days ago)

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