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-01-26 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       23426 : static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */
      68             : {
      69       23426 :         if (!new_value) {
      70         183 :                 EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED;
      71             :         } else {
      72       23243 :                 EG(error_reporting) = atoi(new_value->val);
      73             :         }
      74       23426 :         return SUCCESS;
      75             : }
      76             : /* }}} */
      77             : 
      78       20805 : static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
      79             : {
      80       20805 :         OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
      81             : 
      82       20805 :         if (GC_G(gc_enabled)) {
      83       20798 :                 gc_init();
      84             :         }
      85             : 
      86       20805 :         return SUCCESS;
      87             : }
      88             : /* }}} */
      89             : 
      90       20786 : static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
      91             : {
      92       20786 :         if (!CG(multibyte)) {
      93       20754 :                 return FAILURE;
      94             :         }
      95          32 :         if (!zend_multibyte_get_functions()) {
      96          32 :                 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        1346 : 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        5970 :         for (i = 0; i < indent; i++) {
     142        4624 :                 ZEND_PUTS_EX(" ");
     143             :         }
     144        1346 :         ZEND_PUTS_EX("(\n");
     145        1346 :         indent += PRINT_ZVAL_INDENT;
     146       14212 :         ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, string_key, tmp) {
     147        6314 :                 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       45506 :                 for (i = 0; i < indent; i++) {
     154       39192 :                         ZEND_PUTS_EX(" ");
     155             :                 }
     156        6314 :                 ZEND_PUTS_EX("[");
     157        6314 :                 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        1968 :                         snprintf(key, sizeof(key), ZEND_LONG_FMT, num_key);
     179        1968 :                         ZEND_PUTS_EX(key);
     180             :                 }
     181        6314 :                 ZEND_PUTS_EX("] => ");
     182        6314 :                 zend_print_zval_r_ex(write_func, tmp, indent+PRINT_ZVAL_INDENT);
     183        6314 :                 ZEND_PUTS_EX("\n");
     184             :         } ZEND_HASH_FOREACH_END();
     185        1346 :         indent -= PRINT_ZVAL_INDENT;
     186        5970 :         for (i = 0; i < indent; i++) {
     187        4624 :                 ZEND_PUTS_EX(" ");
     188             :         }
     189        1346 :         ZEND_PUTS_EX(")\n");
     190        1346 : }
     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      603615 : ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
     217             : {
     218      603615 :         if (Z_TYPE_P(expr) == IS_STRING) {
     219          87 :                 return 0;
     220             :         } else {
     221      603528 :                 ZVAL_STR(expr_copy, _zval_get_string_func(expr));
     222      603526 :                 return 1;
     223             :         }
     224             : }
     225             : /* }}} */
     226             : 
     227        1069 : ZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */
     228             : {
     229        1069 :         return zend_print_zval_ex(zend_write, expr, indent);
     230             : }
     231             : /* }}} */
     232             : 
     233        7277 : ZEND_API size_t zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
     234             : {
     235        7277 :         zend_string *str = zval_get_string(expr);
     236        7277 :         size_t len = str->len;
     237             : 
     238        7277 :         if (len != 0) {
     239        6971 :                 write_func(str->val, len);
     240             :         }
     241             : 
     242             :         zend_string_release(str);
     243        7277 :         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        1252 : ZEND_API void zend_print_zval_r(zval *expr, int indent) /* {{{ */
     294             : {
     295        1252 :         zend_print_zval_r_ex(zend_write, expr, indent);
     296        1252 : }
     297             : /* }}} */
     298             : 
     299        7567 : ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
     300             : {
     301        7567 :         ZVAL_DEREF(expr);
     302        7567 :         switch (Z_TYPE_P(expr)) {
     303             :                 case IS_ARRAY:
     304        1062 :                         ZEND_PUTS_EX("Array\n");
     305        3186 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
     306        2124 :                             ++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        1062 :                         print_hash(write_func, Z_ARRVAL_P(expr), indent, 0);
     312        1062 :                         if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
     313        1062 :                                 Z_ARRVAL_P(expr)->u.v.nApplyCount--;
     314             :                         }
     315        1062 :                         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        6208 :                         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       20786 : static void zend_set_default_compile_time_values(void) /* {{{ */
     367             : {
     368             :         /* default compile-time values */
     369       20786 :         CG(short_tags) = short_tags_default;
     370       20786 :         CG(compiler_options) = compiler_options_default;
     371       20786 : }
     372             : /* }}} */
     373             : 
     374       20786 : static void zend_init_exception_op(void) /* {{{ */
     375             : {
     376       20786 :         memset(EG(exception_op), 0, sizeof(EG(exception_op)));
     377       20786 :         EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION;
     378       20786 :         EG(exception_op)[0].op1_type = IS_UNUSED;
     379       20786 :         EG(exception_op)[0].op2_type = IS_UNUSED;
     380       20786 :         EG(exception_op)[0].result_type = IS_UNUSED;
     381       20786 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op));
     382       20786 :         EG(exception_op)[1].opcode = ZEND_HANDLE_EXCEPTION;
     383       20786 :         EG(exception_op)[1].op1_type = IS_UNUSED;
     384       20786 :         EG(exception_op)[1].op2_type = IS_UNUSED;
     385       20786 :         EG(exception_op)[1].result_type = IS_UNUSED;
     386       20786 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+1);
     387       20786 :         EG(exception_op)[2].opcode = ZEND_HANDLE_EXCEPTION;
     388       20786 :         EG(exception_op)[2].op1_type = IS_UNUSED;
     389       20786 :         EG(exception_op)[2].op2_type = IS_UNUSED;
     390       20786 :         EG(exception_op)[2].result_type = IS_UNUSED;
     391       20786 :         ZEND_VM_SET_OPCODE_HANDLER(EG(exception_op)+2);
     392       20786 : }
     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       20786 : static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p) /* {{{ */
     520             : {
     521       20786 :         memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
     522       20786 : }
     523             : /* }}} */
     524             : 
     525       20786 : static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p) /* {{{ */
     526             : {
     527       20786 :         memset(scanner_globals_p, 0, sizeof(*scanner_globals_p));
     528       20786 : }
     529             : /* }}} */
     530             : 
     531             : void zend_init_opcodes_handlers(void);
     532             : 
     533     1499285 : static void module_destructor_zval(zval *zv) /* {{{ */
     534             : {
     535     1499285 :         zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv);
     536             : 
     537     1499285 :         module_destructor(module);
     538     1499285 :         free(module);
     539     1499285 : }
     540             : /* }}} */
     541             : 
     542      187380 : static void auto_global_dtor(zval *zv) /* {{{ */
     543             : {
     544      187380 :         free(Z_PTR_P(zv));
     545      187380 : }
     546             : /* }}} */
     547             : 
     548         170 : static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */
     549             : {
     550             :         zval globals;
     551             : 
     552         170 :         ZVAL_ARR(&globals, &EG(symbol_table));
     553         170 :         ZVAL_NEW_REF(&globals, &globals);
     554         170 :         zend_hash_update(&EG(symbol_table).ht, name, &globals);
     555         170 :         return 0;
     556             : }
     557             : /* }}} */
     558             : 
     559       20786 : int zend_startup(zend_utility_functions *utility_functions, char **extensions) /* {{{ */
     560             : {
     561             : #ifdef ZTS
     562             :         zend_compiler_globals *compiler_globals;
     563             :         zend_executor_globals *executor_globals;
     564             :         extern ZEND_API ts_rsrc_id ini_scanner_globals_id;
     565             :         extern ZEND_API ts_rsrc_id language_scanner_globals_id;
     566             :         ZEND_TSRMLS_CACHE_UPDATE;
     567             : #else
     568             :         extern zend_ini_scanner_globals ini_scanner_globals;
     569             :         extern zend_php_scanner_globals language_scanner_globals;
     570             : #endif
     571             : 
     572       20786 :         start_memory_manager();
     573             : 
     574       20786 :         virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */
     575             : 
     576             : #if defined(__FreeBSD__) || defined(__DragonFly__)
     577             :         /* FreeBSD and DragonFly floating point precision fix */
     578             :         fpsetmask(0);
     579             : #endif
     580             : 
     581       20786 :         zend_startup_strtod();
     582       20786 :         zend_startup_extensions_mechanism();
     583             : 
     584             :         /* Set up utility functions and values */
     585       20786 :         zend_error_cb = utility_functions->error_function;
     586       20786 :         zend_printf = utility_functions->printf_function;
     587       20786 :         zend_write = (zend_write_func_t) utility_functions->write_function;
     588       20786 :         zend_fopen = utility_functions->fopen_function;
     589       20786 :         if (!zend_fopen) {
     590           0 :                 zend_fopen = zend_fopen_wrapper;
     591             :         }
     592       20786 :         zend_stream_open_function = utility_functions->stream_open_function;
     593       20786 :         zend_message_dispatcher_p = utility_functions->message_handler;
     594             : #ifndef ZEND_SIGNALS
     595       20786 :         zend_block_interruptions = utility_functions->block_interruptions;
     596       20786 :         zend_unblock_interruptions = utility_functions->unblock_interruptions;
     597             : #endif
     598       20786 :         zend_get_configuration_directive_p = utility_functions->get_configuration_directive;
     599       20786 :         zend_ticks_function = utility_functions->ticks_function;
     600       20786 :         zend_on_timeout = utility_functions->on_timeout;
     601       20786 :         zend_vspprintf = utility_functions->vspprintf_function;
     602       20786 :         zend_vstrpprintf = utility_functions->vstrpprintf_function;
     603       20786 :         zend_getenv = utility_functions->getenv_function;
     604       20786 :         zend_resolve_path = utility_functions->resolve_path_function;
     605             : 
     606             : #if HAVE_DTRACE
     607             : /* build with dtrace support */
     608             :         zend_compile_file = dtrace_compile_file;
     609             :         zend_execute_ex = dtrace_execute_ex;
     610             :         zend_execute_internal = dtrace_execute_internal;
     611             : #else
     612       20786 :         zend_compile_file = compile_file;
     613       20786 :         zend_execute_ex = execute_ex;
     614       20786 :         zend_execute_internal = NULL;
     615             : #endif /* HAVE_SYS_SDT_H */
     616       20786 :         zend_compile_string = compile_string;
     617       20786 :         zend_throw_exception_hook = NULL;
     618             : 
     619             :         /* Set up the default garbage collection implementation. */
     620       20786 :         gc_collect_cycles = zend_gc_collect_cycles;
     621             : 
     622       20786 :         zend_init_opcodes_handlers();
     623             : 
     624             :         /* set up version */
     625       20786 :         zend_version_info = strdup(ZEND_CORE_VERSION_INFO);
     626       20786 :         zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO) - 1;
     627             : 
     628       20786 :         GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable));
     629       20786 :         GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     630       20786 :         GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     631       20786 :         GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable));
     632             : 
     633       20786 :         zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0);
     634       20786 :         zend_hash_init_ex(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1, 0);
     635       20786 :         zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0);
     636       20786 :         zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1, 0);
     637             : 
     638       20786 :         zend_hash_init_ex(&module_registry, 32, NULL, module_destructor_zval, 1, 0);
     639       20786 :         zend_init_rsrc_list_dtors();
     640             : 
     641             : #ifdef ZTS
     642             :         ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor);
     643             :         ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor);
     644             :         ts_allocate_id(&language_scanner_globals_id, sizeof(zend_php_scanner_globals), (ts_allocate_ctor) php_scanner_globals_ctor, NULL);
     645             :         ts_allocate_id(&ini_scanner_globals_id, sizeof(zend_ini_scanner_globals), (ts_allocate_ctor) ini_scanner_globals_ctor, NULL);
     646             :         compiler_globals = ts_resource(compiler_globals_id);
     647             :         executor_globals = ts_resource(executor_globals_id);
     648             : 
     649             :         compiler_globals_dtor(compiler_globals);
     650             :         compiler_globals->in_compilation = 0;
     651             :         compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable));
     652             :         compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable));
     653             : 
     654             :         *compiler_globals->function_table = *GLOBAL_FUNCTION_TABLE;
     655             :         *compiler_globals->class_table = *GLOBAL_CLASS_TABLE;
     656             :         compiler_globals->auto_globals = GLOBAL_AUTO_GLOBALS_TABLE;
     657             : 
     658             :         zend_hash_destroy(executor_globals->zend_constants);
     659             :         *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE;
     660             : #else
     661       20786 :         ini_scanner_globals_ctor(&ini_scanner_globals);
     662       20786 :         php_scanner_globals_ctor(&language_scanner_globals);
     663       20786 :         zend_set_default_compile_time_values();
     664       20786 :         ZVAL_UNDEF(&EG(user_error_handler));
     665       20786 :         ZVAL_UNDEF(&EG(user_exception_handler));
     666             : #endif
     667             : 
     668       20786 :         zend_interned_strings_init();
     669       20786 :         zend_startup_builtin_functions();
     670       20786 :         zend_register_standard_constants();
     671       20786 :         zend_register_auto_global(zend_string_init("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals);
     672             : 
     673             : #ifndef ZTS
     674       20786 :         zend_init_rsrc_plist();
     675       20786 :         zend_init_exception_op();
     676             : #endif
     677             : 
     678       20786 :         zend_ini_startup();
     679             : 
     680             : #ifdef ZTS
     681             :         tsrm_set_new_thread_end_handler(zend_new_thread_end_handler);
     682             : #endif
     683             : 
     684       20786 :         return SUCCESS;
     685             : }
     686             : /* }}} */
     687             : 
     688       20786 : void zend_register_standard_ini_entries(void) /* {{{ */
     689             : {
     690       20786 :         int module_number = 0;
     691             : 
     692       20786 :         REGISTER_INI_ENTRIES();
     693       20786 : }
     694             : /* }}} */
     695             : 
     696             : /* Unlink the global (r/o) copies of the class, function and constant tables,
     697             :  * and use a fresh r/w copy for the startup thread
     698             :  */
     699       20786 : void zend_post_startup(void) /* {{{ */
     700             : {
     701             : #ifdef ZTS
     702             :         zend_encoding **script_encoding_list;
     703             : 
     704             :         zend_compiler_globals *compiler_globals = ts_resource(compiler_globals_id);
     705             :         zend_executor_globals *executor_globals = ts_resource(executor_globals_id);
     706             : 
     707             :         *GLOBAL_FUNCTION_TABLE = *compiler_globals->function_table;
     708             :         *GLOBAL_CLASS_TABLE = *compiler_globals->class_table;
     709             :         *GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants;
     710             : 
     711             :         short_tags_default = CG(short_tags);
     712             :         compiler_options_default = CG(compiler_options);
     713             : 
     714             :         zend_destroy_rsrc_list(&EG(persistent_list));
     715             :         free(compiler_globals->function_table);
     716             :         free(compiler_globals->class_table);
     717             :         if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
     718             :                 compiler_globals_ctor(compiler_globals);
     719             :                 compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
     720             :         } else {
     721             :                 compiler_globals_ctor(compiler_globals);
     722             :         }
     723             :         free(EG(zend_constants));
     724             : 
     725             :         virtual_cwd_deactivate();
     726             : 
     727             :         executor_globals_ctor(executor_globals);
     728             :         global_persistent_list = &EG(persistent_list);
     729             :         zend_copy_ini_directives();
     730             : #else
     731       20786 :         virtual_cwd_deactivate();
     732             : #endif
     733       20786 : }
     734             : /* }}} */
     735             : 
     736       20820 : void zend_shutdown(void) /* {{{ */
     737             : {
     738             : #ifdef ZEND_SIGNALS
     739             :         zend_signal_shutdown();
     740             : #endif
     741       20820 :         zend_destroy_rsrc_list(&EG(persistent_list));
     742       20820 :         if (EG(active))
     743             :         {
     744             :                 /*
     745             :                  * The order of destruction is important here.
     746             :                  * See bugs #65463 and 66036.
     747             :                  */
     748             :                 zend_function *func;
     749             :                 zend_class_entry *ce;
     750             : 
     751           0 :                 ZEND_HASH_REVERSE_FOREACH_PTR(GLOBAL_FUNCTION_TABLE, func) {
     752           0 :                         if (func->type == ZEND_USER_FUNCTION) {
     753           0 :                                 zend_cleanup_op_array_data((zend_op_array *) func);
     754             :                         }
     755             :                 } ZEND_HASH_FOREACH_END();
     756           0 :                 ZEND_HASH_REVERSE_FOREACH_PTR(GLOBAL_CLASS_TABLE, ce) {
     757           0 :                         if (ce->type == ZEND_USER_CLASS) {
     758           0 :                                 zend_cleanup_user_class_data(ce);
     759             :                         } else {
     760           0 :                                 break;
     761             :                         }
     762             :                 } ZEND_HASH_FOREACH_END();
     763           0 :                 zend_cleanup_internal_classes();
     764           0 :                 zend_hash_reverse_apply(GLOBAL_FUNCTION_TABLE, (apply_func_t) clean_non_persistent_function_full);
     765           0 :                 zend_hash_reverse_apply(GLOBAL_CLASS_TABLE, (apply_func_t) clean_non_persistent_class_full);
     766             :         }
     767       20820 :         zend_destroy_modules();
     768             : 
     769       20820 :         virtual_cwd_deactivate();
     770       20820 :         virtual_cwd_shutdown();
     771             : 
     772       20820 :         zend_hash_destroy(GLOBAL_FUNCTION_TABLE);
     773       20820 :         zend_hash_destroy(GLOBAL_CLASS_TABLE);
     774             : 
     775       20820 :         zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE);
     776       20820 :         free(GLOBAL_AUTO_GLOBALS_TABLE);
     777             : 
     778       20820 :         zend_shutdown_extensions();
     779       20820 :         free(zend_version_info);
     780             : 
     781       20820 :         free(GLOBAL_FUNCTION_TABLE);
     782       20820 :         free(GLOBAL_CLASS_TABLE);
     783             : 
     784       20820 :         zend_hash_destroy(GLOBAL_CONSTANTS_TABLE);
     785       20820 :         free(GLOBAL_CONSTANTS_TABLE);
     786       20820 :         zend_shutdown_strtod();
     787             : 
     788             : #ifdef ZTS
     789             :         GLOBAL_FUNCTION_TABLE = NULL;
     790             :         GLOBAL_CLASS_TABLE = NULL;
     791             :         GLOBAL_AUTO_GLOBALS_TABLE = NULL;
     792             :         GLOBAL_CONSTANTS_TABLE = NULL;
     793             : #endif
     794       20820 :         zend_destroy_rsrc_list_dtors();
     795             : 
     796       20820 :         zend_interned_strings_dtor();
     797       20820 : }
     798             : /* }}} */
     799             : 
     800       20786 : void zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */
     801             : {
     802       20786 :         zend_uv = *utility_values;
     803       20786 :         zend_uv.import_use_extension_length = (uint)strlen(zend_uv.import_use_extension);
     804       20786 : }
     805             : /* }}} */
     806             : 
     807             : /* this should be compatible with the standard zenderror */
     808          39 : void zenderror(const char *error) /* {{{ */
     809             : {
     810          39 :         zend_error(E_PARSE, "%s", error);
     811          39 : }
     812             : /* }}} */
     813             : 
     814             : BEGIN_EXTERN_C()
     815        2198 : ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
     816             : {
     817             : 
     818        2198 :         if (!EG(bailout)) {
     819           0 :                 zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno);
     820           0 :                 exit(-1);
     821             :         }
     822        2198 :         CG(unclean_shutdown) = 1;
     823        2198 :         CG(active_class_entry) = NULL;
     824        2198 :         CG(in_compilation) = 0;
     825        2198 :         EG(current_execute_data) = NULL;
     826        2198 :         LONGJMP(*EG(bailout), FAILURE);
     827             : }
     828             : /* }}} */
     829             : END_EXTERN_C()
     830             : 
     831       20627 : ZEND_API void zend_append_version_info(const zend_extension *extension) /* {{{ */
     832             : {
     833             :         char *new_info;
     834             :         uint new_info_length;
     835             : 
     836       82508 :         new_info_length = (uint)(sizeof("    with  v, , by \n")
     837       20627 :                                                 + strlen(extension->name)
     838       20627 :                                                 + strlen(extension->version)
     839       20627 :                                                 + strlen(extension->copyright)
     840       20627 :                                                 + strlen(extension->author));
     841             : 
     842       20627 :         new_info = (char *) malloc(new_info_length + 1);
     843             : 
     844       20627 :         snprintf(new_info, new_info_length, "    with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author);
     845             : 
     846       20627 :         zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length + 1);
     847       20627 :         strncat(zend_version_info, new_info, new_info_length);
     848       20627 :         zend_version_info_length += new_info_length;
     849       20627 :         free(new_info);
     850       20627 : }
     851             : /* }}} */
     852             : 
     853         167 : ZEND_API char *get_zend_version(void) /* {{{ */
     854             : {
     855         167 :         return zend_version_info;
     856             : }
     857             : /* }}} */
     858             : 
     859       20743 : ZEND_API void zend_activate(void) /* {{{ */
     860             : {
     861             : #ifdef ZTS
     862             :         virtual_cwd_activate();
     863             : #endif
     864       20743 :         gc_reset();
     865       20743 :         init_compiler();
     866       20743 :         init_executor();
     867       20743 :         startup_scanner();
     868       20743 : }
     869             : /* }}} */
     870             : 
     871       20779 : void zend_call_destructors(void) /* {{{ */
     872             : {
     873       20779 :         zend_try {
     874       20779 :                 shutdown_destructors();
     875       20779 :         } zend_end_try();
     876       20779 : }
     877             : /* }}} */
     878             : 
     879       20779 : ZEND_API void zend_deactivate(void) /* {{{ */
     880             : {
     881             :         /* we're no longer executing anything */
     882       20779 :         EG(current_execute_data) = NULL;
     883             : 
     884       20779 :         zend_try {
     885       20779 :                 shutdown_scanner();
     886       20779 :         } zend_end_try();
     887             : 
     888             :         /* shutdown_executor() takes care of its own bailout handling */
     889       20779 :         shutdown_executor();
     890             : 
     891       20779 :         zend_try {
     892       20779 :                 shutdown_compiler();
     893       20779 :         } zend_end_try();
     894             : 
     895       20779 :         zend_destroy_rsrc_list(&EG(regular_list));
     896             : 
     897             : #if ZEND_DEBUG
     898             :         if (GC_G(gc_enabled) && !CG(unclean_shutdown)) {
     899             :                 gc_collect_cycles();
     900             :         }
     901             : #endif
     902             : 
     903             : #if GC_BENCH
     904             :         fprintf(stderr, "GC Statistics\n");
     905             :         fprintf(stderr, "-------------\n");
     906             :         fprintf(stderr, "Runs:               %d\n", GC_G(gc_runs));
     907             :         fprintf(stderr, "Collected:          %d\n", GC_G(collected));
     908             :         fprintf(stderr, "Root buffer length: %d\n", GC_G(root_buf_length));
     909             :         fprintf(stderr, "Root buffer peak:   %d\n\n", GC_G(root_buf_peak));
     910             :         fprintf(stderr, "      Possible            Remove from  Marked\n");
     911             :         fprintf(stderr, "        Root    Buffered     buffer     grey\n");
     912             :         fprintf(stderr, "      --------  --------  -----------  ------\n");
     913             :         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));
     914             :         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));
     915             : #endif
     916             : 
     917       20779 :         zend_try {
     918       20779 :                 zend_ini_deactivate();
     919       20779 :         } zend_end_try();
     920       20779 : }
     921             : /* }}} */
     922             : 
     923             : BEGIN_EXTERN_C()
     924          34 : ZEND_API void zend_message_dispatcher(zend_long message, const void *data) /* {{{ */
     925             : {
     926          34 :         if (zend_message_dispatcher_p) {
     927          34 :                 zend_message_dispatcher_p(message, data);
     928             :         }
     929          31 : }
     930             : /* }}} */
     931             : END_EXTERN_C()
     932             : 
     933     5611185 : ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */
     934             : {
     935     5611185 :         if (zend_get_configuration_directive_p) {
     936     5611185 :                 return zend_get_configuration_directive_p(name);
     937             :         } else {
     938           0 :                 return NULL;
     939             :         }
     940             : }
     941             : /* }}} */
     942             : 
     943             : #define SAVE_STACK(stack) do { \
     944             :                 if (CG(stack).top) { \
     945             :                         memcpy(&stack, &CG(stack), sizeof(zend_stack)); \
     946             :                         CG(stack).top = CG(stack).max = 0; \
     947             :                         CG(stack).elements = NULL; \
     948             :                 } else { \
     949             :                         stack.top = 0; \
     950             :                 } \
     951             :         } while (0)
     952             : 
     953             : #define RESTORE_STACK(stack) do { \
     954             :                 if (stack.top) { \
     955             :                         zend_stack_destroy(&CG(stack)); \
     956             :                         memcpy(&CG(stack), &stack, sizeof(zend_stack)); \
     957             :                 } \
     958             :         } while (0)
     959             : 
     960             : #if !defined(ZEND_WIN32) && !defined(DARWIN)
     961      377333 : ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
     962             : #else
     963             : static void zend_error_va_list(int type, const char *format, va_list args)
     964             : #endif
     965             : {
     966             :         char *str;
     967             :         int len;
     968             : #if !defined(ZEND_WIN32) && !defined(DARWIN)
     969             :         va_list args;
     970             : #endif
     971             :         va_list usr_copy;
     972             :         zval params[5];
     973             :         zval retval;
     974             :         const char *error_filename;
     975      377333 :         uint error_lineno = 0;
     976             :         zval orig_user_error_handler;
     977             :         zend_bool in_compilation;
     978             :         zend_class_entry *saved_class_entry;
     979             :         zend_stack loop_var_stack;
     980             :         zend_stack delayed_oplines_stack;
     981             :         zend_stack context_stack;
     982             :         zend_array *symbol_table;
     983             : 
     984             :         /* Report about uncaught exception in case of fatal errors */
     985      377333 :         if (EG(exception)) {
     986             :                 zend_execute_data *ex;
     987             :                 const zend_op *opline;
     988             : 
     989          44 :                 switch (type) {
     990             :                         case E_CORE_ERROR:
     991             :                         case E_ERROR:
     992             :                         case E_RECOVERABLE_ERROR:
     993             :                         case E_PARSE:
     994             :                         case E_COMPILE_ERROR:
     995             :                         case E_USER_ERROR:
     996           3 :                                 ex = EG(current_execute_data);
     997           3 :                                 opline = NULL;
     998           8 :                                 while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
     999           2 :                                         ex = ex->prev_execute_data;
    1000             :                                 }
    1001           4 :                                 if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION &&
    1002           1 :                                     EG(opline_before_exception)) {
    1003           1 :                                         opline = EG(opline_before_exception);
    1004             :                                 }
    1005           3 :                                 zend_exception_error(EG(exception), E_WARNING);
    1006           3 :                                 EG(exception) = NULL;
    1007           3 :                                 if (opline) {
    1008           1 :                                         ex->opline = opline;
    1009             :                                 }
    1010             :                                 break;
    1011             :                         default:
    1012             :                                 break;
    1013             :                 }
    1014             :         }
    1015             : 
    1016             :         /* Obtain relevant filename and lineno */
    1017      377333 :         switch (type) {
    1018             :                 case E_CORE_ERROR:
    1019             :                 case E_CORE_WARNING:
    1020           5 :                         error_filename = NULL;
    1021           5 :                         error_lineno = 0;
    1022           5 :                         break;
    1023             :                 case E_PARSE:
    1024             :                 case E_COMPILE_ERROR:
    1025             :                 case E_COMPILE_WARNING:
    1026             :                 case E_ERROR:
    1027             :                 case E_NOTICE:
    1028             :                 case E_STRICT:
    1029             :                 case E_DEPRECATED:
    1030             :                 case E_WARNING:
    1031             :                 case E_USER_ERROR:
    1032             :                 case E_USER_WARNING:
    1033             :                 case E_USER_NOTICE:
    1034             :                 case E_USER_DEPRECATED:
    1035             :                 case E_RECOVERABLE_ERROR:
    1036      377328 :                         if (zend_is_compiling()) {
    1037         317 :                                 error_filename = zend_get_compiled_filename()->val;
    1038         317 :                                 error_lineno = zend_get_compiled_lineno();
    1039      377011 :                         } else if (zend_is_executing()) {
    1040      376973 :                                 error_filename = zend_get_executed_filename();
    1041      376973 :                                 if (error_filename[0] == '[') { /* [no active file] */
    1042           6 :                                         error_filename = NULL;
    1043           6 :                                         error_lineno = 0;
    1044             :                                 } else {
    1045      376967 :                                         error_lineno = zend_get_executed_lineno();
    1046             :                                 }
    1047             :                         } else {
    1048          38 :                                 error_filename = NULL;
    1049          38 :                                 error_lineno = 0;
    1050             :                         }
    1051      377328 :                         break;
    1052             :                 default:
    1053           0 :                         error_filename = NULL;
    1054           0 :                         error_lineno = 0;
    1055             :                         break;
    1056             :         }
    1057      377333 :         if (!error_filename) {
    1058          49 :                 error_filename = "Unknown";
    1059             :         }
    1060             : 
    1061             : #ifdef HAVE_DTRACE
    1062             :         if(DTRACE_ERROR_ENABLED()) {
    1063             :                 char *dtrace_error_buffer;
    1064             :                 va_start(args, format);
    1065             :                 zend_vspprintf(&dtrace_error_buffer, 0, format, args);
    1066             :                 DTRACE_ERROR(dtrace_error_buffer, (char *)error_filename, error_lineno);
    1067             :                 efree(dtrace_error_buffer);
    1068             :                 va_end(args);
    1069             :         }
    1070             : #endif /* HAVE_DTRACE */
    1071             : 
    1072             : #if !defined(ZEND_WIN32) && !defined(DARWIN)
    1073      377333 :         va_start(args, format);
    1074             : #endif
    1075             : 
    1076             :         /* if we don't have a user defined error handler */
    1077      757712 :         if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF
    1078        3758 :                 || !(EG(user_error_handler_error_reporting) & type)
    1079        3728 :                 || EG(error_handling) != EH_NORMAL) {
    1080      373605 :                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1081        3728 :         } else switch (type) {
    1082             :                 case E_ERROR:
    1083             :                 case E_PARSE:
    1084             :                 case E_CORE_ERROR:
    1085             :                 case E_CORE_WARNING:
    1086             :                 case E_COMPILE_ERROR:
    1087             :                 case E_COMPILE_WARNING:
    1088             :                         /* The error may not be safe to handle in user-space */
    1089           5 :                         zend_error_cb(type, error_filename, error_lineno, format, args);
    1090           0 :                         break;
    1091             :                 default:
    1092             :                         /* Handle the error in user space */
    1093             : /* va_copy() is __va_copy() in old gcc versions.
    1094             :  * According to the autoconf manual, using
    1095             :  * memcpy(&dst, &src, sizeof(va_list))
    1096             :  * gives maximum portability. */
    1097             : #ifndef va_copy
    1098             : # ifdef __va_copy
    1099             : #  define va_copy(dest, src)    __va_copy((dest), (src))
    1100             : # else
    1101             : #  define va_copy(dest, src)    memcpy(&(dest), &(src), sizeof(va_list))
    1102             : # endif
    1103             : #endif
    1104        3723 :                         va_copy(usr_copy, args);
    1105        3723 :                         len = (int)zend_vspprintf(&str, 0, format, usr_copy);
    1106        7446 :                         ZVAL_NEW_STR(&params[1], zend_string_init(str, len, 0));
    1107        3723 :                         efree(str);
    1108             : #ifdef va_copy
    1109        3723 :                         va_end(usr_copy);
    1110             : #endif
    1111             : 
    1112        3723 :                         ZVAL_LONG(&params[0], type);
    1113             : 
    1114        3723 :                         if (error_filename) {
    1115        7446 :                                 ZVAL_STRING(&params[2], error_filename);
    1116             :                         } else {
    1117           0 :                                 ZVAL_NULL(&params[2]);
    1118             :                         }
    1119             : 
    1120        3723 :                         ZVAL_LONG(&params[3], error_lineno);
    1121             : 
    1122        3723 :                         symbol_table = zend_rebuild_symbol_table();
    1123             : 
    1124             :                         /* during shutdown the symbol table table can be still null */
    1125        3723 :                         if (!symbol_table) {
    1126           0 :                                 ZVAL_NULL(&params[4]);
    1127             :                         } else {
    1128        3723 :                                 ZVAL_NEW_ARR(&params[4]);
    1129        3723 :                                 zend_array_dup(Z_ARRVAL(params[4]), &symbol_table->ht);
    1130             :                         }
    1131             : 
    1132        3723 :                         ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler));
    1133        3723 :                         ZVAL_UNDEF(&EG(user_error_handler));
    1134             : 
    1135             :                         /* User error handler may include() additinal PHP files.
    1136             :                          * If an error was generated during comilation PHP will compile
    1137             :                          * such scripts recursivly, but some CG() variables may be
    1138             :                          * inconsistent. */
    1139             : 
    1140        3723 :                         in_compilation = CG(in_compilation);
    1141        3723 :                         if (in_compilation) {
    1142           2 :                                 saved_class_entry = CG(active_class_entry);
    1143           2 :                                 CG(active_class_entry) = NULL;
    1144           2 :                                 SAVE_STACK(loop_var_stack);
    1145           2 :                                 SAVE_STACK(delayed_oplines_stack);
    1146           2 :                                 SAVE_STACK(context_stack);
    1147           2 :                                 CG(in_compilation) = 0;
    1148             :                         }
    1149             : 
    1150        3723 :                         ZVAL_UNDEF(&retval);
    1151        3723 :                         if (call_user_function_ex(CG(function_table), NULL, &orig_user_error_handler, &retval, 5, params, 1, NULL) == SUCCESS) {
    1152        3723 :                                 if (Z_TYPE(retval) != IS_UNDEF) {
    1153        3699 :                                         if (Z_TYPE(retval) == IS_FALSE) {
    1154           1 :                                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1155             :                                         }
    1156        3699 :                                         zval_ptr_dtor(&retval);
    1157             :                                 }
    1158           0 :                         } else if (!EG(exception)) {
    1159             :                                 /* The user error handler failed, use built-in error handler */
    1160           0 :                                 zend_error_cb(type, error_filename, error_lineno, format, args);
    1161             :                         }
    1162             : 
    1163        3723 :                         if (in_compilation) {
    1164           2 :                                 CG(active_class_entry) = saved_class_entry;
    1165           2 :                                 RESTORE_STACK(loop_var_stack);
    1166           2 :                                 RESTORE_STACK(delayed_oplines_stack);
    1167           2 :                                 RESTORE_STACK(context_stack);
    1168           2 :                                 CG(in_compilation) = 1;
    1169             :                         }
    1170             : 
    1171        3723 :                         zval_ptr_dtor(&params[4]);
    1172        3723 :                         zval_ptr_dtor(&params[3]);
    1173        3723 :                         zval_ptr_dtor(&params[2]);
    1174        3723 :                         zval_ptr_dtor(&params[1]);
    1175        3723 :                         zval_ptr_dtor(&params[0]);
    1176             : 
    1177        3723 :                         if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF) {
    1178        3723 :                                 ZVAL_COPY_VALUE(&EG(user_error_handler), &orig_user_error_handler);
    1179             :                         } else {
    1180           0 :                                 zval_ptr_dtor(&orig_user_error_handler);
    1181             :                         }
    1182             :                         break;
    1183             :         }
    1184             : 
    1185             : #if !defined(ZEND_WIN32) && !defined(DARWIN)
    1186      376616 :         va_end(args);
    1187             : #endif
    1188             : 
    1189      376616 :         if (type == E_PARSE) {
    1190             :                 /* eval() errors do not affect exit_status */
    1191          85 :                 if (!(EG(current_execute_data) &&
    1192          16 :                         EG(current_execute_data)->func &&
    1193          16 :                         ZEND_USER_CODE(EG(current_execute_data)->func->type) &&
    1194           7 :                         EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL &&
    1195           7 :                         EG(current_execute_data)->opline->extended_value == ZEND_EVAL)) {
    1196          36 :                         EG(exit_status) = 255;
    1197             :                 }
    1198             :         }
    1199      376616 : }
    1200             : /* }}} */
    1201             : 
    1202             : #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__))
    1203             : void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn));
    1204             : #elif defined(ZEND_WIN32) || defined(DARWIN)
    1205             : ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
    1206             : {
    1207             :         va_list va;
    1208             : 
    1209             :         va_start(va, format);
    1210             :         zend_error_va_list(type, format, va);
    1211             :         va_end(va);
    1212             : }
    1213             : 
    1214             : ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
    1215             : {
    1216             :         va_list va;
    1217             : 
    1218             :         va_start(va, format);
    1219             :         zend_error_va_list(type, format, va);
    1220             :         va_end(va);
    1221             : }
    1222             : /* }}} */
    1223             : #endif
    1224             : 
    1225           0 : ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) /* {{{ */
    1226             : {
    1227             : #if ZEND_DEBUG
    1228             :         va_list args;
    1229             : 
    1230             :         va_start(args, format);
    1231             : #       ifdef ZEND_WIN32
    1232             :         {
    1233             :                 char output_buf[1024];
    1234             : 
    1235             :                 vsnprintf(output_buf, 1024, format, args);
    1236             :                 OutputDebugString(output_buf);
    1237             :                 OutputDebugString("\n");
    1238             :                 if (trigger_break && IsDebuggerPresent()) {
    1239             :                         DebugBreak();
    1240             :                 }
    1241             :         }
    1242             : #       else
    1243             :         vfprintf(stderr, format, args);
    1244             :         fprintf(stderr, "\n");
    1245             : #       endif
    1246             :         va_end(args);
    1247             : #endif
    1248           0 : }
    1249             : /* }}} */
    1250             : 
    1251       20684 : ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */
    1252             : {
    1253             :         va_list files;
    1254             :         int i;
    1255             :         zend_file_handle *file_handle;
    1256             :         zend_op_array *op_array;
    1257             : 
    1258       20684 :         va_start(files, file_count);
    1259       79032 :         for (i = 0; i < file_count; i++) {
    1260       60200 :                 file_handle = va_arg(files, zend_file_handle *);
    1261       60200 :                 if (!file_handle) {
    1262       39515 :                         continue;
    1263             :                 }
    1264             : 
    1265       20685 :                 op_array = zend_compile_file(file_handle, type);
    1266       20460 :                 if (file_handle->opened_path) {
    1267       20457 :                         zend_hash_str_add_empty_element(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path));
    1268             :                 }
    1269       20460 :                 zend_destroy_file_handle(file_handle);
    1270       20460 :                 if (op_array) {
    1271       20460 :                         zend_execute(op_array, retval);
    1272       18939 :                         zend_exception_restore();
    1273       18939 :                         if (EG(exception)) {
    1274         114 :                                 if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) {
    1275             :                                         zval orig_user_exception_handler;
    1276             :                                         zval params[1], retval2;
    1277             :                                         zend_object *old_exception;
    1278          10 :                                         old_exception = EG(exception);
    1279          10 :                                         EG(exception) = NULL;
    1280          10 :                                         ZVAL_OBJ(&params[0], old_exception);
    1281          10 :                                         ZVAL_COPY_VALUE(&orig_user_exception_handler, &EG(user_exception_handler));
    1282          10 :                                         ZVAL_UNDEF(&retval2);
    1283          10 :                                         if (call_user_function_ex(CG(function_table), NULL, &orig_user_exception_handler, &retval2, 1, params, 1, NULL) == SUCCESS) {
    1284           8 :                                                 zval_ptr_dtor(&retval2);
    1285           8 :                                                 if (EG(exception)) {
    1286           0 :                                                         OBJ_RELEASE(EG(exception));
    1287           0 :                                                         EG(exception) = NULL;
    1288             :                                                 }
    1289             :                                                 OBJ_RELEASE(old_exception);
    1290             :                                         } else {
    1291           0 :                                                 EG(exception) = old_exception;
    1292           0 :                                                 zend_exception_error(EG(exception), E_ERROR);
    1293             :                                         }
    1294             :                                 } else {
    1295         104 :                                         zend_exception_error(EG(exception), E_ERROR);
    1296             :                                 }
    1297             :                         }
    1298       18833 :                         destroy_op_array(op_array);
    1299       18833 :                         efree_size(op_array, sizeof(zend_op_array));
    1300           0 :                 } else if (type==ZEND_REQUIRE) {
    1301           0 :                         va_end(files);
    1302           0 :                         return FAILURE;
    1303             :                 }
    1304             :         }
    1305       18832 :         va_end(files);
    1306             : 
    1307       18832 :         return SUCCESS;
    1308             : }
    1309             : /* }}} */
    1310             : 
    1311             : #define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s"
    1312             : 
    1313        1080 : ZEND_API char *zend_make_compiled_string_description(const char *name) /* {{{ */
    1314             : {
    1315             :         const char *cur_filename;
    1316             :         int cur_lineno;
    1317             :         char *compiled_string_description;
    1318             : 
    1319        1080 :         if (zend_is_compiling()) {
    1320           0 :                 cur_filename = zend_get_compiled_filename()->val;
    1321           0 :                 cur_lineno = zend_get_compiled_lineno();
    1322        1080 :         } else if (zend_is_executing()) {
    1323        1080 :                 cur_filename = zend_get_executed_filename();
    1324        1080 :                 cur_lineno = zend_get_executed_lineno();
    1325             :         } else {
    1326           0 :                 cur_filename = "Unknown";
    1327           0 :                 cur_lineno = 0;
    1328             :         }
    1329             : 
    1330        1080 :         zend_spprintf(&compiled_string_description, 0, COMPILED_STRING_DESCRIPTION_FORMAT, cur_filename, cur_lineno, name);
    1331        1080 :         return compiled_string_description;
    1332             : }
    1333             : /* }}} */
    1334             : 
    1335       20627 : void free_estring(char **str_p) /* {{{ */
    1336             : {
    1337       20627 :         efree(*str_p);
    1338       20627 : }
    1339             : /* }}} */
    1340             : 
    1341       29428 : void free_string_zval(zval *zv) /* {{{ */
    1342             : {
    1343       29428 :         zend_string *str = Z_PTR_P(zv);
    1344             :         zend_string_release(str);
    1345       29428 : }
    1346             : /* }}} */
    1347             : 
    1348             : /*
    1349             :  * Local variables:
    1350             :  * tab-width: 4
    1351             :  * c-basic-offset: 4
    1352             :  * indent-tabs-mode: t
    1353             :  * End:
    1354             :  */

Generated by: LCOV version 1.10

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

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