diff options
Diffstat (limited to 'Zend/zend.c')
-rw-r--r-- | Zend/zend.c | 883 |
1 files changed, 410 insertions, 473 deletions
diff --git a/Zend/zend.c b/Zend/zend.c index ef4ad79748..1bd70ab292 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -46,29 +46,30 @@ /* true multithread-shared globals */ ZEND_API zend_class_entry *zend_standard_class_def = NULL; -ZEND_API int (*zend_printf)(const char *format, ...); +ZEND_API size_t (*zend_printf)(const char *format, ...); ZEND_API zend_write_func_t zend_write; -ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path TSRMLS_DC); -ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC); +ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path); +ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle); ZEND_API void (*zend_block_interruptions)(void); ZEND_API void (*zend_unblock_interruptions)(void); ZEND_API void (*zend_ticks_function)(int ticks); ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args); -int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap); -ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC); -ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len TSRMLS_DC); +size_t (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap); +zend_string *(*zend_vstrpprintf)(size_t max_len, const char *format, va_list ap); +ZEND_API char *(*zend_getenv)(char *name, size_t name_len); +ZEND_API char *(*zend_resolve_path)(const char *filename, int filename_len); -void (*zend_on_timeout)(int seconds TSRMLS_DC); +void (*zend_on_timeout)(int seconds); -static void (*zend_message_dispatcher_p)(long message, const void *data TSRMLS_DC); -static int (*zend_get_configuration_directive_p)(const char *name, uint name_length, zval *contents); +static void (*zend_message_dispatcher_p)(zend_long message, const void *data); +static zval *(*zend_get_configuration_directive_p)(zend_string *name); static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */ { if (!new_value) { EG(error_reporting) = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED; } else { - EG(error_reporting) = atoi(new_value); + EG(error_reporting) = atoi(new_value->val); } return SUCCESS; } @@ -76,10 +77,10 @@ static ZEND_INI_MH(OnUpdateErrorReporting) /* {{{ */ static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */ { - OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); + OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); if (GC_G(gc_enabled)) { - gc_init(TSRMLS_C); + gc_init(); } return SUCCESS; @@ -91,10 +92,10 @@ static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */ if (!CG(multibyte)) { return FAILURE; } - if (!zend_multibyte_get_functions(TSRMLS_C)) { + if (!zend_multibyte_get_functions()) { return SUCCESS; } - return zend_multibyte_set_script_encoding_by_string(new_value, new_value_length TSRMLS_CC); + return zend_multibyte_set_script_encoding_by_string(new_value ? new_value->val : NULL, new_value ? new_value->len : 0); } /* }}} */ @@ -119,25 +120,22 @@ static HashTable *global_class_table = NULL; static HashTable *global_constants_table = NULL; static HashTable *global_auto_globals_table = NULL; static HashTable *global_persistent_list = NULL; +ZEND_TSRMLS_CACHE_DEFINE; #endif ZEND_API zend_utility_values zend_uv; -ZEND_API zval zval_used_for_init; /* True global variable */ - /* version information */ static char *zend_version_info; static uint zend_version_info_length; #define ZEND_CORE_VERSION_INFO "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2015 Zend Technologies\n" #define PRINT_ZVAL_INDENT 4 -static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */ +static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object) /* {{{ */ { - zval **tmp; - char *string_key; - HashPosition iterator; - ulong num_key; - uint str_len; + zval *tmp; + zend_string *string_key; + zend_ulong num_key; int i; for (i = 0; i < indent; i++) { @@ -145,46 +143,45 @@ static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, } ZEND_PUTS_EX("(\n"); indent += PRINT_ZVAL_INDENT; - zend_hash_internal_pointer_reset_ex(ht, &iterator); - while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) { + ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, string_key, tmp) { + if (Z_TYPE_P(tmp) == IS_INDIRECT) { + tmp = Z_INDIRECT_P(tmp); + if (Z_TYPE_P(tmp) == IS_UNDEF) { + continue; + } + } for (i = 0; i < indent; i++) { ZEND_PUTS_EX(" "); } ZEND_PUTS_EX("["); - switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) { - case HASH_KEY_IS_STRING: - if (is_object) { - const char *prop_name, *class_name; - int prop_len; - int mangled = zend_unmangle_property_name_ex(string_key, str_len - 1, &class_name, &prop_name, &prop_len); - - ZEND_WRITE_EX(prop_name, prop_len); - if (class_name && mangled == SUCCESS) { - if (class_name[0]=='*') { - ZEND_PUTS_EX(":protected"); - } else { - ZEND_PUTS_EX(":"); - ZEND_PUTS_EX(class_name); - ZEND_PUTS_EX(":private"); - } + if (string_key) { + if (is_object) { + const char *prop_name, *class_name; + size_t prop_len; + int mangled = zend_unmangle_property_name_ex(string_key, &class_name, &prop_name, &prop_len); + + ZEND_WRITE_EX(prop_name, prop_len); + if (class_name && mangled == SUCCESS) { + if (class_name[0]=='*') { + ZEND_PUTS_EX(":protected"); + } else { + ZEND_PUTS_EX(":"); + ZEND_PUTS_EX(class_name); + ZEND_PUTS_EX(":private"); } - } else { - ZEND_WRITE_EX(string_key, str_len-1); - } - break; - case HASH_KEY_IS_LONG: - { - char key[25]; - snprintf(key, sizeof(key), "%ld", num_key); - ZEND_PUTS_EX(key); } - break; + } else { + ZEND_WRITE_EX(string_key->val, string_key->len); + } + } else { + char key[25]; + snprintf(key, sizeof(key), ZEND_LONG_FMT, num_key); + ZEND_PUTS_EX(key); } ZEND_PUTS_EX("] => "); - zend_print_zval_r_ex(write_func, *tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC); + zend_print_zval_r_ex(write_func, tmp, indent+PRINT_ZVAL_INDENT); ZEND_PUTS_EX("\n"); - zend_hash_move_forward_ex(ht, &iterator); - } + } ZEND_HASH_FOREACH_END(); indent -= PRINT_ZVAL_INDENT; for (i = 0; i < indent; i++) { ZEND_PUTS_EX(" "); @@ -193,192 +190,95 @@ static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, } /* }}} */ -static void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */ +static void print_flat_hash(HashTable *ht) /* {{{ */ { - zval **tmp; - char *string_key; - HashPosition iterator; - ulong num_key; - uint str_len; + zval *tmp; + zend_string *string_key; + zend_ulong num_key; int i = 0; - zend_hash_internal_pointer_reset_ex(ht, &iterator); - while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) { + ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, string_key, tmp) { if (i++ > 0) { ZEND_PUTS(","); } ZEND_PUTS("["); - switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) { - case HASH_KEY_IS_STRING: - ZEND_PUTS(string_key); - break; - case HASH_KEY_IS_LONG: - zend_printf("%ld", num_key); - break; + if (string_key) { + ZEND_WRITE(string_key->val, string_key->len); + } else { + zend_printf(ZEND_ULONG_FMT, num_key); } ZEND_PUTS("] => "); - zend_print_flat_zval_r(*tmp TSRMLS_CC); - zend_hash_move_forward_ex(ht, &iterator); - } + zend_print_flat_zval_r(tmp); + } ZEND_HASH_FOREACH_END(); } /* }}} */ -ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy) /* {{{ */ +ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */ { - if (Z_TYPE_P(expr)==IS_STRING) { - *use_copy = 0; - return; - } - switch (Z_TYPE_P(expr)) { - case IS_NULL: - Z_STRLEN_P(expr_copy) = 0; - Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC(); - break; - case IS_BOOL: - if (Z_LVAL_P(expr)) { - Z_STRLEN_P(expr_copy) = 1; - Z_STRVAL_P(expr_copy) = estrndup("1", 1); - } else { - Z_STRLEN_P(expr_copy) = 0; - Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC(); - } - break; - case IS_RESOURCE: - Z_STRVAL_P(expr_copy) = (char *) emalloc(sizeof("Resource id #") - 1 + MAX_LENGTH_OF_LONG); - Z_STRLEN_P(expr_copy) = snprintf(Z_STRVAL_P(expr_copy), sizeof("Resource id #") - 1 + MAX_LENGTH_OF_LONG, "Resource id #%ld", Z_LVAL_P(expr)); - break; - case IS_ARRAY: - zend_error(E_NOTICE, "Array to string conversion"); - Z_STRLEN_P(expr_copy) = sizeof("Array") - 1; - Z_STRVAL_P(expr_copy) = estrndup("Array", Z_STRLEN_P(expr_copy)); - break; - case IS_OBJECT: - { - TSRMLS_FETCH(); - - if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - break; - } - if (Z_OBJ_HANDLER_P(expr, cast_object)) { - zval *val; - - ALLOC_ZVAL(val); - INIT_PZVAL_COPY(val, expr); - zval_copy_ctor(val); - if (Z_OBJ_HANDLER_P(expr, cast_object)(val, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - zval_ptr_dtor(&val); - break; - } - zval_ptr_dtor(&val); - } - if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) { - zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC); - - Z_ADDREF_P(z); - if (Z_TYPE_P(z) != IS_OBJECT) { - zend_make_printable_zval(z, expr_copy, use_copy); - if (*use_copy) { - zval_ptr_dtor(&z); - } else { - ZVAL_ZVAL(expr_copy, z, 0, 1); - *use_copy = 1; - } - return; - } - zval_ptr_dtor(&z); - } - zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(expr)->name); - Z_STRLEN_P(expr_copy) = 0; - Z_STRVAL_P(expr_copy) = STR_EMPTY_ALLOC(); - } - break; - case IS_DOUBLE: - *expr_copy = *expr; - zval_copy_ctor(expr_copy); - zend_locale_sprintf_double(expr_copy ZEND_FILE_LINE_CC); - break; - default: - *expr_copy = *expr; - zval_copy_ctor(expr_copy); - convert_to_string(expr_copy); - break; + if (Z_TYPE_P(expr) == IS_STRING) { + return 0; + } else { + ZVAL_STR(expr_copy, _zval_get_string_func(expr)); + return 1; } - Z_TYPE_P(expr_copy) = IS_STRING; - *use_copy = 1; } /* }}} */ -ZEND_API int zend_print_zval(zval *expr, int indent) /* {{{ */ +ZEND_API size_t zend_print_zval(zval *expr, int indent) /* {{{ */ { return zend_print_zval_ex(zend_write, expr, indent); } /* }}} */ -ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */ +ZEND_API size_t zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */ { - zval expr_copy; - int use_copy; + zend_string *str = zval_get_string(expr); + size_t len = str->len; - zend_make_printable_zval(expr, &expr_copy, &use_copy); - if (use_copy) { - expr = &expr_copy; - } - if (Z_STRLEN_P(expr) == 0) { /* optimize away empty strings */ - if (use_copy) { - zval_dtor(expr); - } - return 0; + if (len != 0) { + write_func(str->val, len); } - write_func(Z_STRVAL_P(expr), Z_STRLEN_P(expr)); - if (use_copy) { - zval_dtor(expr); - } - return Z_STRLEN_P(expr); + + zend_string_release(str); + return len; } /* }}} */ -ZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */ +ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */ { switch (Z_TYPE_P(expr)) { case IS_ARRAY: ZEND_PUTS("Array ("); - if (++Z_ARRVAL_P(expr)->nApplyCount>1) { + if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) && + ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) { ZEND_PUTS(" *RECURSION*"); - Z_ARRVAL_P(expr)->nApplyCount--; + Z_ARRVAL_P(expr)->u.v.nApplyCount--; return; } - print_flat_hash(Z_ARRVAL_P(expr) TSRMLS_CC); + print_flat_hash(Z_ARRVAL_P(expr)); ZEND_PUTS(")"); - Z_ARRVAL_P(expr)->nApplyCount--; + if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) { + Z_ARRVAL_P(expr)->u.v.nApplyCount--; + } break; case IS_OBJECT: { HashTable *properties = NULL; - const char *class_name = NULL; - zend_uint clen; + zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr)); + zend_printf("%s Object (", class_name->val); + zend_string_release(class_name); - if (Z_OBJ_HANDLER_P(expr, get_class_name)) { - Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC); - } - if (class_name) { - zend_printf("%s Object (", class_name); - } else { - zend_printf("%s Object (", "Unknown Class"); - } - if (class_name) { - efree((char*)class_name); - } if (Z_OBJ_HANDLER_P(expr, get_properties)) { properties = Z_OBJPROP_P(expr); } if (properties) { - if (++properties->nApplyCount>1) { + if (++properties->u.v.nApplyCount>1) { ZEND_PUTS(" *RECURSION*"); - properties->nApplyCount--; + properties->u.v.nApplyCount--; return; } - print_flat_hash(properties TSRMLS_CC); - properties->nApplyCount--; + print_flat_hash(properties); + properties->u.v.nApplyCount--; } ZEND_PUTS(")"); break; @@ -390,57 +290,52 @@ ZEND_API void zend_print_flat_zval_r(zval *expr TSRMLS_DC) /* {{{ */ } /* }}} */ -ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC) /* {{{ */ +ZEND_API void zend_print_zval_r(zval *expr, int indent) /* {{{ */ { - zend_print_zval_r_ex(zend_write, expr, indent TSRMLS_CC); + zend_print_zval_r_ex(zend_write, expr, indent); } /* }}} */ -ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC) /* {{{ */ +ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */ { + ZVAL_DEREF(expr); switch (Z_TYPE_P(expr)) { case IS_ARRAY: ZEND_PUTS_EX("Array\n"); - if (++Z_ARRVAL_P(expr)->nApplyCount>1) { + if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) && + ++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) { ZEND_PUTS_EX(" *RECURSION*"); - Z_ARRVAL_P(expr)->nApplyCount--; + Z_ARRVAL_P(expr)->u.v.nApplyCount--; return; } - print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC); - Z_ARRVAL_P(expr)->nApplyCount--; + print_hash(write_func, Z_ARRVAL_P(expr), indent, 0); + if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) { + Z_ARRVAL_P(expr)->u.v.nApplyCount--; + } break; case IS_OBJECT: { HashTable *properties; - const char *class_name = NULL; - zend_uint clen; int is_temp; - if (Z_OBJ_HANDLER_P(expr, get_class_name)) { - Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC); - } - if (class_name) { - ZEND_PUTS_EX(class_name); - } else { - ZEND_PUTS_EX("Unknown Class"); - } + zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr)); + ZEND_PUTS_EX(class_name->val); + zend_string_release(class_name); + ZEND_PUTS_EX(" Object\n"); - if (class_name) { - efree((char*)class_name); - } if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) { break; } - if (++properties->nApplyCount>1) { + if (++properties->u.v.nApplyCount>1) { ZEND_PUTS_EX(" *RECURSION*"); - properties->nApplyCount--; + properties->u.v.nApplyCount--; return; } - print_hash(write_func, properties, indent, 1 TSRMLS_CC); - properties->nApplyCount--; + print_hash(write_func, properties, indent, 1); + properties->u.v.nApplyCount--; if (is_temp) { zend_hash_destroy(properties); - efree(properties); + FREE_HASHTABLE(properties); } break; } @@ -451,7 +346,7 @@ ZEND_API void zend_print_zval_r_ex(zend_write_func_t write_func, zval *expr, int } /* }}} */ -static FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_DC) /* {{{ */ +static FILE *zend_fopen_wrapper(const char *filename, char **opened_path) /* {{{ */ { if (opened_path) { *opened_path = estrdup(filename); @@ -461,25 +356,22 @@ static FILE *zend_fopen_wrapper(const char *filename, char **opened_path TSRMLS_ /* }}} */ #ifdef ZTS -static zend_bool asp_tags_default = 0; -static zend_bool short_tags_default = 1; -static zend_uint compiler_options_default = ZEND_COMPILE_DEFAULT; +static zend_bool short_tags_default = 1; +static uint32_t compiler_options_default = ZEND_COMPILE_DEFAULT; #else -# define asp_tags_default 0 # define short_tags_default 1 # define compiler_options_default ZEND_COMPILE_DEFAULT #endif -static void zend_set_default_compile_time_values(TSRMLS_D) /* {{{ */ +static void zend_set_default_compile_time_values(void) /* {{{ */ { /* default compile-time values */ - CG(asp_tags) = asp_tags_default; CG(short_tags) = short_tags_default; CG(compiler_options) = compiler_options_default; } /* }}} */ -static void zend_init_exception_op(TSRMLS_D) /* {{{ */ +static void zend_init_exception_op(void) /* {{{ */ { memset(EG(exception_op), 0, sizeof(EG(exception_op))); EG(exception_op)[0].opcode = ZEND_HANDLE_EXCEPTION; @@ -501,40 +393,49 @@ static void zend_init_exception_op(TSRMLS_D) /* {{{ */ /* }}} */ #ifdef ZTS -static void compiler_globals_ctor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */ +static void function_copy_ctor(zval *zv) { - zend_function tmp_func; - zend_class_entry *tmp_class; + zend_function *old_func = Z_FUNC_P(zv); + Z_FUNC_P(zv) = pemalloc(sizeof(zend_internal_function), 1); + memcpy(Z_FUNC_P(zv), old_func, sizeof(zend_internal_function)); + function_add_ref(Z_FUNC_P(zv)); +} +static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{{ */ +{ compiler_globals->compiled_filename = NULL; compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init_ex(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0); - zend_hash_copy(compiler_globals->function_table, global_function_table, NULL, &tmp_func, sizeof(zend_function)); + zend_hash_init_ex(compiler_globals->function_table, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0); + zend_hash_copy(compiler_globals->function_table, global_function_table, function_copy_ctor); compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init_ex(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0); - zend_hash_copy(compiler_globals->class_table, global_class_table, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry *)); - - zend_set_default_compile_time_values(TSRMLS_C); + zend_hash_init_ex(compiler_globals->class_table, 64, NULL, ZEND_CLASS_DTOR, 1, 0); + zend_hash_copy(compiler_globals->class_table, global_class_table, zend_class_add_ref); - CG(interactive) = 0; + zend_set_default_compile_time_values(); compiler_globals->auto_globals = (HashTable *) malloc(sizeof(HashTable)); zend_hash_init_ex(compiler_globals->auto_globals, 8, NULL, NULL, 1, 0); - zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL, NULL, sizeof(zend_auto_global) /* empty element */); + zend_hash_copy(compiler_globals->auto_globals, global_auto_globals_table, NULL /* empty element */); compiler_globals->last_static_member = zend_hash_num_elements(compiler_globals->class_table); if (compiler_globals->last_static_member) { - compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval**)); + compiler_globals->static_members_table = calloc(compiler_globals->last_static_member, sizeof(zval*)); } else { compiler_globals->static_members_table = NULL; } compiler_globals->script_encoding_list = NULL; + +#ifdef ZTS + zend_interned_empty_string_init(&compiler_globals->empty_string); + + memset(compiler_globals->one_char_string, 0, sizeof(compiler_globals->one_char_string)); +#endif } /* }}} */ -static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS_DC) /* {{{ */ +static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{{ */ { if (compiler_globals->function_table != GLOBAL_FUNCTION_TABLE) { zend_hash_destroy(compiler_globals->function_table); @@ -552,22 +453,26 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS free(compiler_globals->static_members_table); } if (compiler_globals->script_encoding_list) { - pefree(compiler_globals->script_encoding_list, 1); + pefree((char*)compiler_globals->script_encoding_list, 1); } compiler_globals->last_static_member = 0; + +#ifdef ZTS + zend_interned_empty_string_free(&compiler_globals->empty_string); +#endif } /* }}} */ -static void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */ +static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{{ */ { - zend_startup_constants(TSRMLS_C); + ZEND_TSRMLS_CACHE_UPDATE; + zend_startup_constants(); zend_copy_constants(EG(zend_constants), GLOBAL_CONSTANTS_TABLE); - zend_init_rsrc_plist(TSRMLS_C); - zend_init_exception_op(TSRMLS_C); + zend_init_rsrc_plist(); + zend_init_exception_op(); EG(lambda_count) = 0; - EG(user_error_handler) = NULL; - EG(user_exception_handler) = NULL; - EG(in_execution) = 0; + ZVAL_UNDEF(&EG(user_error_handler)); + ZVAL_UNDEF(&EG(user_exception_handler)); EG(in_autoload) = NULL; EG(current_execute_data) = NULL; EG(current_module) = NULL; @@ -580,11 +485,15 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals TSRMLS } /* }}} */ -static void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS_DC) /* {{{ */ +static void executor_globals_dtor(zend_executor_globals *executor_globals) /* {{{ */ { - zend_ini_shutdown(TSRMLS_C); +#ifdef ZTS + zend_ini_dtor(executor_globals->ini_directives); +#else + zend_ini_shutdown(); +#endif if (&executor_globals->persistent_list != global_persistent_list) { - zend_destroy_rsrc_list(&executor_globals->persistent_list TSRMLS_CC); + zend_destroy_rsrc_list(&executor_globals->persistent_list); } if (executor_globals->zend_constants != GLOBAL_CONSTANTS_TABLE) { zend_hash_destroy(executor_globals->zend_constants); @@ -593,10 +502,10 @@ static void executor_globals_dtor(zend_executor_globals *executor_globals TSRMLS } /* }}} */ -static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */ +static void zend_new_thread_end_handler(THREAD_T thread_id) /* {{{ */ { - if (zend_copy_ini_directives(TSRMLS_C) == SUCCESS) { - zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP TSRMLS_CC); + if (zend_copy_ini_directives() == SUCCESS) { + zend_ini_refresh_caches(ZEND_INI_STAGE_STARTUP); } } /* }}} */ @@ -607,13 +516,13 @@ static void zend_new_thread_end_handler(THREAD_T thread_id TSRMLS_DC) /* {{{ */ #include <floatingpoint.h> #endif -static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */ +static void ini_scanner_globals_ctor(zend_ini_scanner_globals *scanner_globals_p) /* {{{ */ { memset(scanner_globals_p, 0, sizeof(*scanner_globals_p)); } /* }}} */ -static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p TSRMLS_DC) /* {{{ */ +static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p) /* {{{ */ { memset(scanner_globals_p, 0, sizeof(*scanner_globals_p)); } @@ -621,33 +530,46 @@ static void php_scanner_globals_ctor(zend_php_scanner_globals *scanner_globals_p void zend_init_opcodes_handlers(void); -static zend_bool php_auto_globals_create_globals(const char *name, uint name_len TSRMLS_DC) /* {{{ */ +static void module_destructor_zval(zval *zv) /* {{{ */ +{ + zend_module_entry *module = (zend_module_entry*)Z_PTR_P(zv); + + module_destructor(module); + free(module); +} +/* }}} */ + +static void auto_global_dtor(zval *zv) /* {{{ */ +{ + free(Z_PTR_P(zv)); +} +/* }}} */ + +static zend_bool php_auto_globals_create_globals(zend_string *name) /* {{{ */ { - zval *globals; - - ALLOC_ZVAL(globals); - Z_SET_REFCOUNT_P(globals, 1); - Z_SET_ISREF_P(globals); - Z_TYPE_P(globals) = IS_ARRAY; - Z_ARRVAL_P(globals) = &EG(symbol_table); - zend_hash_update(&EG(symbol_table), name, name_len + 1, &globals, sizeof(zval *), NULL); + zval globals; + + ZVAL_ARR(&globals, &EG(symbol_table)); + ZVAL_NEW_REF(&globals, &globals); + zend_hash_update(&EG(symbol_table).ht, name, &globals); return 0; } /* }}} */ -int zend_startup(zend_utility_functions *utility_functions, char **extensions TSRMLS_DC) /* {{{ */ +int zend_startup(zend_utility_functions *utility_functions, char **extensions) /* {{{ */ { #ifdef ZTS zend_compiler_globals *compiler_globals; zend_executor_globals *executor_globals; extern ZEND_API ts_rsrc_id ini_scanner_globals_id; extern ZEND_API ts_rsrc_id language_scanner_globals_id; + ZEND_TSRMLS_CACHE_UPDATE; #else extern zend_ini_scanner_globals ini_scanner_globals; extern zend_php_scanner_globals language_scanner_globals; #endif - start_memory_manager(TSRMLS_C); + start_memory_manager(); virtual_cwd_startup(); /* Could use shutdown to free the main cwd but it would just slow it down for CGI */ @@ -677,6 +599,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS zend_ticks_function = utility_functions->ticks_function; zend_on_timeout = utility_functions->on_timeout; zend_vspprintf = utility_functions->vspprintf_function; + zend_vstrpprintf = utility_functions->vstrpprintf_function; zend_getenv = utility_functions->getenv_function; zend_resolve_path = utility_functions->resolve_path_function; @@ -693,6 +616,9 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS zend_compile_string = compile_string; zend_throw_exception_hook = NULL; + /* Set up the default garbage collection implementation. */ + gc_collect_cycles = zend_gc_collect_cycles; + zend_init_opcodes_handlers(); /* set up version */ @@ -704,19 +630,14 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS GLOBAL_AUTO_GLOBALS_TABLE = (HashTable *) malloc(sizeof(HashTable)); GLOBAL_CONSTANTS_TABLE = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0); - zend_hash_init_ex(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1, 0); - zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, NULL, 1, 0); - zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 20, NULL, ZEND_CONSTANT_DTOR, 1, 0); + zend_hash_init_ex(GLOBAL_FUNCTION_TABLE, 1024, NULL, ZEND_FUNCTION_DTOR, 1, 0); + zend_hash_init_ex(GLOBAL_CLASS_TABLE, 64, NULL, ZEND_CLASS_DTOR, 1, 0); + zend_hash_init_ex(GLOBAL_AUTO_GLOBALS_TABLE, 8, NULL, auto_global_dtor, 1, 0); + zend_hash_init_ex(GLOBAL_CONSTANTS_TABLE, 128, NULL, ZEND_CONSTANT_DTOR, 1, 0); - zend_hash_init_ex(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1, 0); + zend_hash_init_ex(&module_registry, 32, NULL, module_destructor_zval, 1, 0); zend_init_rsrc_list_dtors(); - /* This zval can be used to initialize allocate zval's to an uninit'ed value */ - Z_UNSET_ISREF(zval_used_for_init); - Z_SET_REFCOUNT(zval_used_for_init, 1); - Z_TYPE(zval_used_for_init) = IS_NULL; - #ifdef ZTS ts_allocate_id(&compiler_globals_id, sizeof(zend_compiler_globals), (ts_allocate_ctor) compiler_globals_ctor, (ts_allocate_dtor) compiler_globals_dtor); ts_allocate_id(&executor_globals_id, sizeof(zend_executor_globals), (ts_allocate_ctor) executor_globals_ctor, (ts_allocate_dtor) executor_globals_dtor); @@ -725,7 +646,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS compiler_globals = ts_resource(compiler_globals_id); executor_globals = ts_resource(executor_globals_id); - compiler_globals_dtor(compiler_globals TSRMLS_CC); + compiler_globals_dtor(compiler_globals); compiler_globals->in_compilation = 0; compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable)); compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable)); @@ -737,24 +658,24 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS zend_hash_destroy(executor_globals->zend_constants); *executor_globals->zend_constants = *GLOBAL_CONSTANTS_TABLE; #else - ini_scanner_globals_ctor(&ini_scanner_globals TSRMLS_CC); - php_scanner_globals_ctor(&language_scanner_globals TSRMLS_CC); - zend_set_default_compile_time_values(TSRMLS_C); - EG(user_error_handler) = NULL; - EG(user_exception_handler) = NULL; + ini_scanner_globals_ctor(&ini_scanner_globals); + php_scanner_globals_ctor(&language_scanner_globals); + zend_set_default_compile_time_values(); + ZVAL_UNDEF(&EG(user_error_handler)); + ZVAL_UNDEF(&EG(user_exception_handler)); #endif - zend_interned_strings_init(TSRMLS_C); - zend_startup_builtin_functions(TSRMLS_C); - zend_register_standard_constants(TSRMLS_C); - zend_register_auto_global("GLOBALS", sizeof("GLOBALS") - 1, 1, php_auto_globals_create_globals TSRMLS_CC); + zend_interned_strings_init(); + zend_startup_builtin_functions(); + zend_register_standard_constants(); + zend_register_auto_global(zend_string_init("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals); #ifndef ZTS - zend_init_rsrc_plist(TSRMLS_C); - zend_init_exception_op(TSRMLS_C); + zend_init_rsrc_plist(); + zend_init_exception_op(); #endif - zend_ini_startup(TSRMLS_C); + zend_ini_startup(); #ifdef ZTS tsrm_set_new_thread_end_handler(zend_new_thread_end_handler); @@ -764,7 +685,7 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions TS } /* }}} */ -void zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */ +void zend_register_standard_ini_entries(void) /* {{{ */ { int module_number = 0; @@ -775,7 +696,7 @@ void zend_register_standard_ini_entries(TSRMLS_D) /* {{{ */ /* Unlink the global (r/o) copies of the class, function and constant tables, * and use a fresh r/w copy for the startup thread */ -void zend_post_startup(TSRMLS_D) /* {{{ */ +void zend_post_startup(void) /* {{{ */ { #ifdef ZTS zend_encoding **script_encoding_list; @@ -787,56 +708,66 @@ void zend_post_startup(TSRMLS_D) /* {{{ */ *GLOBAL_CLASS_TABLE = *compiler_globals->class_table; *GLOBAL_CONSTANTS_TABLE = *executor_globals->zend_constants; - asp_tags_default = CG(asp_tags); short_tags_default = CG(short_tags); compiler_options_default = CG(compiler_options); - zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC); + zend_destroy_rsrc_list(&EG(persistent_list)); free(compiler_globals->function_table); free(compiler_globals->class_table); if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) { - compiler_globals_ctor(compiler_globals, tsrm_ls); + compiler_globals_ctor(compiler_globals); compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list; } else { - compiler_globals_ctor(compiler_globals, tsrm_ls); + compiler_globals_ctor(compiler_globals); } free(EG(zend_constants)); - virtual_cwd_deactivate(TSRMLS_C); + virtual_cwd_deactivate(); - executor_globals_ctor(executor_globals, tsrm_ls); + executor_globals_ctor(executor_globals); global_persistent_list = &EG(persistent_list); - zend_copy_ini_directives(TSRMLS_C); + zend_copy_ini_directives(); #else - virtual_cwd_deactivate(TSRMLS_C); + virtual_cwd_deactivate(); #endif } /* }}} */ -void zend_shutdown(TSRMLS_D) /* {{{ */ +void zend_shutdown(void) /* {{{ */ { #ifdef ZEND_SIGNALS - zend_signal_shutdown(TSRMLS_C); + zend_signal_shutdown(); #endif - zend_destroy_rsrc_list(&EG(persistent_list) TSRMLS_CC); - + zend_destroy_rsrc_list(&EG(persistent_list)); if (EG(active)) { /* * The order of destruction is important here. * See bugs #65463 and 66036. */ - zend_hash_reverse_apply(GLOBAL_FUNCTION_TABLE, (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC); - zend_hash_reverse_apply(GLOBAL_CLASS_TABLE, (apply_func_t) zend_cleanup_user_class_data TSRMLS_CC); - zend_cleanup_internal_classes(TSRMLS_C); - zend_hash_reverse_apply(GLOBAL_FUNCTION_TABLE, (apply_func_t) clean_non_persistent_function_full TSRMLS_CC); - zend_hash_reverse_apply(GLOBAL_CLASS_TABLE, (apply_func_t) clean_non_persistent_class_full TSRMLS_CC); - } + zend_function *func; + zend_class_entry *ce; + ZEND_HASH_REVERSE_FOREACH_PTR(GLOBAL_FUNCTION_TABLE, func) { + if (func->type == ZEND_USER_FUNCTION) { + zend_cleanup_op_array_data((zend_op_array *) func); + } + } ZEND_HASH_FOREACH_END(); + ZEND_HASH_REVERSE_FOREACH_PTR(GLOBAL_CLASS_TABLE, ce) { + if (ce->type == ZEND_USER_CLASS) { + zend_cleanup_user_class_data(ce); + } else { + break; + } + } ZEND_HASH_FOREACH_END(); + zend_cleanup_internal_classes(); + zend_hash_reverse_apply(GLOBAL_FUNCTION_TABLE, (apply_func_t) clean_non_persistent_function_full); + zend_hash_reverse_apply(GLOBAL_CLASS_TABLE, (apply_func_t) clean_non_persistent_class_full); + } zend_destroy_modules(); - virtual_cwd_deactivate(TSRMLS_C); - virtual_cwd_shutdown(); + virtual_cwd_deactivate(); + virtual_cwd_shutdown(); zend_hash_destroy(GLOBAL_FUNCTION_TABLE); zend_hash_destroy(GLOBAL_CLASS_TABLE); @@ -844,7 +775,7 @@ void zend_shutdown(TSRMLS_D) /* {{{ */ zend_hash_destroy(GLOBAL_AUTO_GLOBALS_TABLE); free(GLOBAL_AUTO_GLOBALS_TABLE); - zend_shutdown_extensions(TSRMLS_C); + zend_shutdown_extensions(); free(zend_version_info); free(GLOBAL_FUNCTION_TABLE); @@ -862,14 +793,14 @@ void zend_shutdown(TSRMLS_D) /* {{{ */ #endif zend_destroy_rsrc_list_dtors(); - zend_interned_strings_dtor(TSRMLS_C); + zend_interned_strings_dtor(); } /* }}} */ void zend_set_utility_values(zend_utility_values *utility_values) /* {{{ */ { zend_uv = *utility_values; - zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension); + zend_uv.import_use_extension_length = (uint)strlen(zend_uv.import_use_extension); } /* }}} */ @@ -883,7 +814,6 @@ void zenderror(const char *error) /* {{{ */ BEGIN_EXTERN_C() ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */ { - TSRMLS_FETCH(); if (!EG(bailout)) { zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno); @@ -891,7 +821,7 @@ ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */ } CG(unclean_shutdown) = 1; CG(active_class_entry) = NULL; - CG(in_compilation) = EG(in_execution) = 0; + CG(in_compilation) = 0; EG(current_execute_data) = NULL; LONGJMP(*EG(bailout), FAILURE); } @@ -903,11 +833,11 @@ ZEND_API void zend_append_version_info(const zend_extension *extension) /* {{{ * char *new_info; uint new_info_length; - new_info_length = sizeof(" with v, , by \n") + new_info_length = (uint)(sizeof(" with v, , by \n") + strlen(extension->name) + strlen(extension->version) + strlen(extension->copyright) - + strlen(extension->author); + + strlen(extension->author)); new_info = (char *) malloc(new_info_length + 1); @@ -926,48 +856,47 @@ ZEND_API char *get_zend_version(void) /* {{{ */ } /* }}} */ -ZEND_API void zend_activate(TSRMLS_D) /* {{{ */ +ZEND_API void zend_activate(void) /* {{{ */ { #ifdef ZTS - virtual_cwd_activate(TSRMLS_C); + virtual_cwd_activate(); #endif - gc_reset(TSRMLS_C); - init_compiler(TSRMLS_C); - init_executor(TSRMLS_C); - startup_scanner(TSRMLS_C); + gc_reset(); + init_compiler(); + init_executor(); + startup_scanner(); } /* }}} */ -void zend_call_destructors(TSRMLS_D) /* {{{ */ +void zend_call_destructors(void) /* {{{ */ { zend_try { - shutdown_destructors(TSRMLS_C); + shutdown_destructors(); } zend_end_try(); } /* }}} */ -ZEND_API void zend_deactivate(TSRMLS_D) /* {{{ */ +ZEND_API void zend_deactivate(void) /* {{{ */ { /* we're no longer executing anything */ - EG(opline_ptr) = NULL; - EG(active_symbol_table) = NULL; + EG(current_execute_data) = NULL; zend_try { - shutdown_scanner(TSRMLS_C); + shutdown_scanner(); } zend_end_try(); /* shutdown_executor() takes care of its own bailout handling */ - shutdown_executor(TSRMLS_C); + shutdown_executor(); zend_try { - shutdown_compiler(TSRMLS_C); + shutdown_compiler(); } zend_end_try(); - zend_destroy_rsrc_list(&EG(regular_list) TSRMLS_CC); + zend_destroy_rsrc_list(&EG(regular_list)); #if ZEND_DEBUG if (GC_G(gc_enabled) && !CG(unclean_shutdown)) { - gc_collect_cycles(TSRMLS_C); + gc_collect_cycles(); } #endif @@ -986,27 +915,27 @@ ZEND_API void zend_deactivate(TSRMLS_D) /* {{{ */ #endif zend_try { - zend_ini_deactivate(TSRMLS_C); + zend_ini_deactivate(); } zend_end_try(); } /* }}} */ BEGIN_EXTERN_C() -ZEND_API void zend_message_dispatcher(long message, const void *data TSRMLS_DC) /* {{{ */ +ZEND_API void zend_message_dispatcher(zend_long message, const void *data) /* {{{ */ { if (zend_message_dispatcher_p) { - zend_message_dispatcher_p(message, data TSRMLS_CC); + zend_message_dispatcher_p(message, data); } } /* }}} */ END_EXTERN_C() -ZEND_API int zend_get_configuration_directive(const char *name, uint name_length, zval *contents) /* {{{ */ +ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */ { if (zend_get_configuration_directive_p) { - return zend_get_configuration_directive_p(name, name_length, contents); + return zend_get_configuration_directive_p(name); } else { - return FAILURE; + return NULL; } } /* }}} */ @@ -1028,30 +957,35 @@ ZEND_API int zend_get_configuration_directive(const char *name, uint name_length } \ } while (0) +#if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS) ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ +#else +static void zend_error_va_list(int type, const char *format, va_list args) +#endif { + char *str; + int len; +#if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS) va_list args; +#endif va_list usr_copy; - zval ***params; - zval *retval; - zval *z_error_type, *z_error_message, *z_error_filename, *z_error_lineno, *z_context; + zval params[5]; + zval retval; const char *error_filename; - uint error_lineno; - zval *orig_user_error_handler; + uint error_lineno = 0; + zval orig_user_error_handler; zend_bool in_compilation; zend_class_entry *saved_class_entry; - zend_stack bp_stack; - zend_stack function_call_stack; - zend_stack switch_cond_stack; - zend_stack foreach_copy_stack; - zend_stack object_stack; - zend_stack declare_stack; - zend_stack list_stack; + zend_stack loop_var_stack; + zend_stack delayed_oplines_stack; zend_stack context_stack; - TSRMLS_FETCH(); + zend_array *symbol_table; /* Report about uncaught exception in case of fatal errors */ if (EG(exception)) { + zend_execute_data *ex; + const zend_op *opline; + switch (type) { case E_CORE_ERROR: case E_ERROR: @@ -1059,13 +993,19 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ case E_PARSE: case E_COMPILE_ERROR: case E_USER_ERROR: - if (zend_is_executing(TSRMLS_C)) { - error_lineno = zend_get_executed_lineno(TSRMLS_C); + ex = EG(current_execute_data); + opline = NULL; + while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { + ex = ex->prev_execute_data; } - zend_exception_error(EG(exception), E_WARNING TSRMLS_CC); + if (ex && ex->opline->opcode == ZEND_HANDLE_EXCEPTION && + EG(opline_before_exception)) { + opline = EG(opline_before_exception); + } + zend_exception_error(EG(exception), E_WARNING); EG(exception) = NULL; - if (zend_is_executing(TSRMLS_C) && EG(opline_ptr)) { - active_opline->lineno = error_lineno; + if (opline) { + ex->opline = opline; } break; default: @@ -1093,12 +1033,17 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ case E_USER_NOTICE: case E_USER_DEPRECATED: case E_RECOVERABLE_ERROR: - if (zend_is_compiling(TSRMLS_C)) { - error_filename = zend_get_compiled_filename(TSRMLS_C); - error_lineno = zend_get_compiled_lineno(TSRMLS_C); - } else if (zend_is_executing(TSRMLS_C)) { - error_filename = zend_get_executed_filename(TSRMLS_C); - error_lineno = zend_get_executed_lineno(TSRMLS_C); + if (zend_is_compiling()) { + error_filename = zend_get_compiled_filename()->val; + error_lineno = zend_get_compiled_lineno(); + } else if (zend_is_executing()) { + error_filename = zend_get_executed_filename(); + if (error_filename[0] == '[') { /* [no active file] */ + error_filename = NULL; + error_lineno = 0; + } else { + error_lineno = zend_get_executed_lineno(); + } } else { error_filename = NULL; error_lineno = 0; @@ -1114,20 +1059,26 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ } #ifdef HAVE_DTRACE - if(DTRACE_ERROR_ENABLED()) { + if (DTRACE_ERROR_ENABLED()) { char *dtrace_error_buffer; +#if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS) va_start(args, format); +#endif zend_vspprintf(&dtrace_error_buffer, 0, format, args); DTRACE_ERROR(dtrace_error_buffer, (char *)error_filename, error_lineno); efree(dtrace_error_buffer); +#if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS) va_end(args); +#endif } #endif /* HAVE_DTRACE */ +#if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS) va_start(args, format); +#endif /* if we don't have a user defined error handler */ - if (!EG(user_error_handler) + if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF || !(EG(user_error_handler_error_reporting) & type) || EG(error_handling) != EH_NORMAL) { zend_error_cb(type, error_filename, error_lineno, format, args); @@ -1143,12 +1094,6 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ break; default: /* Handle the error in user space */ - ALLOC_INIT_ZVAL(z_error_message); - ALLOC_INIT_ZVAL(z_error_type); - ALLOC_INIT_ZVAL(z_error_filename); - ALLOC_INIT_ZVAL(z_error_lineno); - ALLOC_INIT_ZVAL(z_context); - /* va_copy() is __va_copy() in old gcc versions. * According to the autoconf manual, using * memcpy(&dst, &src, sizeof(va_list)) @@ -1161,44 +1106,35 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ # endif #endif va_copy(usr_copy, args); - Z_STRLEN_P(z_error_message) = zend_vspprintf(&Z_STRVAL_P(z_error_message), 0, format, usr_copy); + len = (int)zend_vspprintf(&str, 0, format, usr_copy); + ZVAL_NEW_STR(¶ms[1], zend_string_init(str, len, 0)); + efree(str); #ifdef va_copy va_end(usr_copy); #endif - Z_TYPE_P(z_error_message) = IS_STRING; - Z_LVAL_P(z_error_type) = type; - Z_TYPE_P(z_error_type) = IS_LONG; + ZVAL_LONG(¶ms[0], type); if (error_filename) { - ZVAL_STRING(z_error_filename, error_filename, 1); + ZVAL_STRING(¶ms[2], error_filename); + } else { + ZVAL_NULL(¶ms[2]); } - Z_LVAL_P(z_error_lineno) = error_lineno; - Z_TYPE_P(z_error_lineno) = IS_LONG; + ZVAL_LONG(¶ms[3], error_lineno); - if (!EG(active_symbol_table)) { - zend_rebuild_symbol_table(TSRMLS_C); - } + symbol_table = zend_rebuild_symbol_table(); /* during shutdown the symbol table table can be still null */ - if (!EG(active_symbol_table)) { - Z_TYPE_P(z_context) = IS_NULL; + if (!symbol_table) { + ZVAL_NULL(¶ms[4]); } else { - Z_ARRVAL_P(z_context) = EG(active_symbol_table); - Z_TYPE_P(z_context) = IS_ARRAY; - zval_copy_ctor(z_context); + ZVAL_NEW_ARR(¶ms[4]); + zend_array_dup(Z_ARRVAL(params[4]), &symbol_table->ht); } - params = (zval ***) emalloc(sizeof(zval **)*5); - params[0] = &z_error_type; - params[1] = &z_error_message; - params[2] = &z_error_filename; - params[3] = &z_error_lineno; - params[4] = &z_context; - - orig_user_error_handler = EG(user_error_handler); - EG(user_error_handler) = NULL; + ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler)); + ZVAL_UNDEF(&EG(user_error_handler)); /* User error handler may include() additinal PHP files. * If an error was generated during comilation PHP will compile @@ -1209,20 +1145,16 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ if (in_compilation) { saved_class_entry = CG(active_class_entry); CG(active_class_entry) = NULL; - SAVE_STACK(bp_stack); - SAVE_STACK(function_call_stack); - SAVE_STACK(switch_cond_stack); - SAVE_STACK(foreach_copy_stack); - SAVE_STACK(object_stack); - SAVE_STACK(declare_stack); - SAVE_STACK(list_stack); + SAVE_STACK(loop_var_stack); + SAVE_STACK(delayed_oplines_stack); SAVE_STACK(context_stack); CG(in_compilation) = 0; } - if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC) == SUCCESS) { - if (retval) { - if (Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval) == 0) { + ZVAL_UNDEF(&retval); + if (call_user_function_ex(CG(function_table), NULL, &orig_user_error_handler, &retval, 5, params, 1, NULL) == SUCCESS) { + if (Z_TYPE(retval) != IS_UNDEF) { + if (Z_TYPE(retval) == IS_FALSE) { zend_error_cb(type, error_filename, error_lineno, format, args); } zval_ptr_dtor(&retval); @@ -1234,50 +1166,66 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ if (in_compilation) { CG(active_class_entry) = saved_class_entry; - RESTORE_STACK(bp_stack); - RESTORE_STACK(function_call_stack); - RESTORE_STACK(switch_cond_stack); - RESTORE_STACK(foreach_copy_stack); - RESTORE_STACK(object_stack); - RESTORE_STACK(declare_stack); - RESTORE_STACK(list_stack); + RESTORE_STACK(loop_var_stack); + RESTORE_STACK(delayed_oplines_stack); RESTORE_STACK(context_stack); CG(in_compilation) = 1; } - if (!EG(user_error_handler)) { - EG(user_error_handler) = orig_user_error_handler; - } - else { + zval_ptr_dtor(¶ms[4]); + zval_ptr_dtor(¶ms[3]); + zval_ptr_dtor(¶ms[2]); + zval_ptr_dtor(¶ms[1]); + zval_ptr_dtor(¶ms[0]); + + if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF) { + ZVAL_COPY_VALUE(&EG(user_error_handler), &orig_user_error_handler); + } else { zval_ptr_dtor(&orig_user_error_handler); } - - efree(params); - zval_ptr_dtor(&z_error_message); - zval_ptr_dtor(&z_error_type); - zval_ptr_dtor(&z_error_filename); - zval_ptr_dtor(&z_error_lineno); - zval_ptr_dtor(&z_context); break; } +#if !defined(HAVE_NORETURN) || defined(HAVE_NORETURN_ALIAS) va_end(args); +#endif if (type == E_PARSE) { /* eval() errors do not affect exit_status */ if (!(EG(current_execute_data) && - EG(current_execute_data)->opline && + EG(current_execute_data)->func && + ZEND_USER_CODE(EG(current_execute_data)->func->type) && EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL && EG(current_execute_data)->opline->extended_value == ZEND_EVAL)) { EG(exit_status) = 255; } - zend_init_compiler_data_structures(TSRMLS_C); } } /* }}} */ -#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__) +#ifdef HAVE_NORETURN +# ifdef HAVE_NORETURN_ALIAS void zend_error_noreturn(int type, const char *format, ...) __attribute__ ((alias("zend_error"),noreturn)); +# else +ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ +{ + va_list va; + + va_start(va, format); + zend_error_va_list(type, format, va); + va_end(va); +} + +ZEND_API ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) +{ + va_list va; + + va_start(va, format); + zend_error_va_list(type, format, va); + va_end(va); +} +/* }}} */ +# endif #endif ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) /* {{{ */ @@ -1306,14 +1254,12 @@ ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *form } /* }}} */ -ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...) /* {{{ */ +ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */ { va_list files; int i; zend_file_handle *file_handle; - zend_op_array *orig_op_array = EG(active_op_array); - zval **orig_retval_ptr_ptr = EG(return_value_ptr_ptr); - long orig_interactive = CG(interactive); + zend_op_array *op_array; va_start(files, file_count); for (i = 0; i < file_count; i++) { @@ -1322,63 +1268,47 @@ ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_co continue; } - if (orig_interactive) { - if (file_handle->filename[0] != '-' || file_handle->filename[1]) { - CG(interactive) = 0; - } else { - CG(interactive) = 1; - } - } - - EG(active_op_array) = zend_compile_file(file_handle, type TSRMLS_CC); + op_array = zend_compile_file(file_handle, type); if (file_handle->opened_path) { - int dummy = 1; - zend_hash_add(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path) + 1, (void *)&dummy, sizeof(int), NULL); + zend_hash_str_add_empty_element(&EG(included_files), file_handle->opened_path, strlen(file_handle->opened_path)); } - zend_destroy_file_handle(file_handle TSRMLS_CC); - if (EG(active_op_array)) { - EG(return_value_ptr_ptr) = retval ? retval : NULL; - zend_execute(EG(active_op_array) TSRMLS_CC); - zend_exception_restore(TSRMLS_C); + zend_destroy_file_handle(file_handle); + if (op_array) { + zend_execute(op_array, retval); + zend_exception_restore(); if (EG(exception)) { - if (EG(user_exception_handler)) { - zval *orig_user_exception_handler; - zval **params[1], *retval2, *old_exception; + if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { + zval orig_user_exception_handler; + zval params[1], retval2; + zend_object *old_exception; old_exception = EG(exception); EG(exception) = NULL; - params[0] = &old_exception; - orig_user_exception_handler = EG(user_exception_handler); - if (call_user_function_ex(CG(function_table), NULL, orig_user_exception_handler, &retval2, 1, params, 1, NULL TSRMLS_CC) == SUCCESS) { - if (retval2 != NULL) { - zval_ptr_dtor(&retval2); - } + ZVAL_OBJ(¶ms[0], old_exception); + ZVAL_COPY_VALUE(&orig_user_exception_handler, &EG(user_exception_handler)); + ZVAL_UNDEF(&retval2); + if (call_user_function_ex(CG(function_table), NULL, &orig_user_exception_handler, &retval2, 1, params, 1, NULL) == SUCCESS) { + zval_ptr_dtor(&retval2); if (EG(exception)) { - zval_ptr_dtor(&EG(exception)); + OBJ_RELEASE(EG(exception)); EG(exception) = NULL; } - zval_ptr_dtor(&old_exception); + OBJ_RELEASE(old_exception); } else { EG(exception) = old_exception; - zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); + zend_exception_error(EG(exception), E_ERROR); } } else { - zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); + zend_exception_error(EG(exception), E_ERROR); } } - destroy_op_array(EG(active_op_array) TSRMLS_CC); - efree(EG(active_op_array)); + destroy_op_array(op_array); + efree_size(op_array, sizeof(zend_op_array)); } else if (type==ZEND_REQUIRE) { va_end(files); - EG(active_op_array) = orig_op_array; - EG(return_value_ptr_ptr) = orig_retval_ptr_ptr; - CG(interactive) = orig_interactive; return FAILURE; } } va_end(files); - EG(active_op_array) = orig_op_array; - EG(return_value_ptr_ptr) = orig_retval_ptr_ptr; - CG(interactive) = orig_interactive; return SUCCESS; } @@ -1386,18 +1316,18 @@ ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_co #define COMPILED_STRING_DESCRIPTION_FORMAT "%s(%d) : %s" -ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC) /* {{{ */ +ZEND_API char *zend_make_compiled_string_description(const char *name) /* {{{ */ { const char *cur_filename; int cur_lineno; char *compiled_string_description; - if (zend_is_compiling(TSRMLS_C)) { - cur_filename = zend_get_compiled_filename(TSRMLS_C); - cur_lineno = zend_get_compiled_lineno(TSRMLS_C); - } else if (zend_is_executing(TSRMLS_C)) { - cur_filename = zend_get_executed_filename(TSRMLS_C); - cur_lineno = zend_get_executed_lineno(TSRMLS_C); + if (zend_is_compiling()) { + cur_filename = zend_get_compiled_filename()->val; + cur_lineno = zend_get_compiled_lineno(); + } else if (zend_is_executing()) { + cur_filename = zend_get_executed_filename(); + cur_lineno = zend_get_executed_lineno(); } else { cur_filename = "Unknown"; cur_lineno = 0; @@ -1414,6 +1344,13 @@ void free_estring(char **str_p) /* {{{ */ } /* }}} */ +void free_string_zval(zval *zv) /* {{{ */ +{ + zend_string *str = Z_PTR_P(zv); + zend_string_release(str); +} +/* }}} */ + /* * Local variables: * tab-width: 4 |