From c0d060f5c02db168f1de895b41afffbc6e3cacfb Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:04:26 +0800 Subject: Bump year --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 14ae75e38d..2ef74ad106 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ - | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) | + | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From 47c902777297ce895aa915c13efdb00881af3669 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:06:16 +0800 Subject: Bump year --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index c7f157c4d5..e973a67a92 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ - | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) | + | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From c081ce628f0d76d44784d7bb8e06428b06142ac0 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:08:10 +0800 Subject: Bump year --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index c7f157c4d5..e973a67a92 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ - | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) | + | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From f4cfaf36e23ca47da3e352e1c60909104c059647 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 10 Feb 2014 10:04:30 +0400 Subject: Use better data structures (incomplete) --- Zend/zend_exceptions.c | 237 ++++++++++++++++++++++++++----------------------- 1 file changed, 125 insertions(+), 112 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index e973a67a92..938f885d0b 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -34,26 +34,29 @@ static zend_class_entry *error_exception_ce; static zend_object_handlers default_exception_handlers; ZEND_API void (*zend_throw_exception_hook)(zval *ex TSRMLS_DC); -void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC) +void zend_exception_set_previous(zend_object *exception, zend_object *add_previous TSRMLS_DC) { - zval *previous; + zval tmp, *previous, zv, *pzv; if (exception == add_previous || !add_previous || !exception) { return; } - if (Z_TYPE_P(add_previous) != IS_OBJECT && !instanceof_function(Z_OBJCE_P(add_previous), default_exception_ce TSRMLS_CC)) { + ZVAL_OBJ(&tmp, add_previous); + if (!instanceof_function(Z_OBJCE(tmp), default_exception_ce TSRMLS_CC)) { zend_error(E_ERROR, "Cannot set non exception as previous exception"); return; } - while (exception && exception != add_previous && Z_OBJ_HANDLE_P(exception) != Z_OBJ_HANDLE_P(add_previous)) { - previous = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 1 TSRMLS_CC); + ZVAL_OBJ(&zv, exception); + pzv = &zv; + do { + previous = zend_read_property(default_exception_ce, pzv, "previous", sizeof("previous")-1, 1 TSRMLS_CC); if (Z_TYPE_P(previous) == IS_NULL) { - zend_update_property(default_exception_ce, exception, "previous", sizeof("previous")-1, add_previous TSRMLS_CC); - Z_DELREF_P(add_previous); + zend_update_property(default_exception_ce, pzv, "previous", sizeof("previous")-1, &tmp TSRMLS_CC); + add_previous->gc.refcount--; return; } - exception = previous; - } + pzv = previous; + } while (pzv && Z_OBJ_P(pzv) != add_previous); } void zend_exception_save(TSRMLS_D) /* {{{ */ @@ -98,9 +101,9 @@ void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ #endif /* HAVE_DTRACE */ if (exception != NULL) { - zval *previous = EG(exception); - zend_exception_set_previous(exception, EG(exception) TSRMLS_CC); - EG(exception) = exception; + zend_object *previous = EG(exception); + zend_exception_set_previous(Z_OBJ_P(exception), EG(exception) TSRMLS_CC); + EG(exception) = Z_OBJ_P(exception); if (previous) { return; } @@ -129,13 +132,14 @@ void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ ZEND_API void zend_clear_exception(TSRMLS_D) /* {{{ */ { if (EG(prev_exception)) { - zval_ptr_dtor(&EG(prev_exception)); + +//??? zval_ptr_dtor(&EG(prev_exception)); EG(prev_exception) = NULL; } if (!EG(exception)) { return; } - zval_ptr_dtor(&EG(exception)); +//??? zval_ptr_dtor(&EG(exception)); EG(exception) = NULL; EG(current_execute_data)->opline = EG(opline_before_exception); #if ZEND_DEBUG @@ -144,37 +148,34 @@ ZEND_API void zend_clear_exception(TSRMLS_D) /* {{{ */ } /* }}} */ -static zend_object_value zend_default_exception_new_ex(zend_class_entry *class_type, int skip_top_traces TSRMLS_DC) /* {{{ */ +static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type, int skip_top_traces TSRMLS_DC) /* {{{ */ { zval obj; zend_object *object; - zval *trace; + zval trace; - Z_OBJVAL(obj) = zend_objects_new(&object, class_type TSRMLS_CC); + Z_OBJ(obj) = object = zend_objects_new(class_type TSRMLS_CC); Z_OBJ_HT(obj) = &default_exception_handlers; object_properties_init(object, class_type); - ALLOC_ZVAL(trace); - Z_UNSET_ISREF_P(trace); - Z_SET_REFCOUNT_P(trace, 0); - zend_fetch_debug_backtrace(trace, skip_top_traces, 0, 0 TSRMLS_CC); + zend_fetch_debug_backtrace(&trace, skip_top_traces, 0, 0 TSRMLS_CC); zend_update_property_string(default_exception_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); zend_update_property_long(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); - zend_update_property(default_exception_ce, &obj, "trace", sizeof("trace")-1, trace TSRMLS_CC); + zend_update_property(default_exception_ce, &obj, "trace", sizeof("trace")-1, &trace TSRMLS_CC); - return Z_OBJVAL(obj); + return object; } /* }}} */ -static zend_object_value zend_default_exception_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ +static zend_object *zend_default_exception_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ { return zend_default_exception_new_ex(class_type, 0 TSRMLS_CC); } /* }}} */ -static zend_object_value zend_error_exception_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ +static zend_object *zend_error_exception_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ { return zend_default_exception_new_ex(class_type, 2 TSRMLS_CC); } @@ -268,9 +269,8 @@ static void _default_exception_get_entry(zval *object, char *name, int name_len, value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC); - *return_value = *value; - zval_copy_ctor(return_value); - INIT_PZVAL(return_value); + ZVAL_DUP(return_value, value); +//??? INIT_PZVAL(return_value); } /* }}} */ @@ -350,19 +350,21 @@ ZEND_METHOD(error_exception, getSeverity) #define TRACE_APPEND_STR(val) \ TRACE_APPEND_STRL(val, sizeof(val)-1) -#define TRACE_APPEND_KEY(key) \ - if (zend_hash_find(ht, key, sizeof(key), (void**)&tmp) == SUCCESS) { \ - if (Z_TYPE_PP(tmp) != IS_STRING) { \ - zend_error(E_WARNING, "Value for %s is no string", key); \ - TRACE_APPEND_STR("[unknown]"); \ - } else { \ - TRACE_APPEND_STRL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); \ - } \ - } +#define TRACE_APPEND_KEY(key) do { \ + tmp = zend_hash_str_find(ht, key, sizeof(key)-1); \ + if (tmp) { \ + if (Z_TYPE_P(tmp) != IS_STRING) { \ + zend_error(E_WARNING, "Value for %s is no string", key); \ + TRACE_APPEND_STR("[unknown]"); \ + } else { \ + TRACE_APPEND_STRL(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ + } \ + } \ + } while (0) /* }}} */ -static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { char **str; int *len; @@ -376,20 +378,20 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z * but that could cause some E_NOTICE and also damn long lines. */ - switch (Z_TYPE_PP(arg)) { + switch (Z_TYPE_P(arg)) { case IS_NULL: TRACE_APPEND_STR("NULL, "); break; case IS_STRING: { int l_added; TRACE_APPEND_CHR('\''); - if (Z_STRLEN_PP(arg) > 15) { - TRACE_APPEND_STRL(Z_STRVAL_PP(arg), 15); + if (Z_STRLEN_P(arg) > 15) { + TRACE_APPEND_STRL(Z_STRVAL_P(arg), 15); TRACE_APPEND_STR("...', "); l_added = 15 + 6 + 1; /* +1 because of while (--l_added) */ } else { - l_added = Z_STRLEN_PP(arg); - TRACE_APPEND_STRL(Z_STRVAL_PP(arg), l_added); + l_added = Z_STRLEN_P(arg); + TRACE_APPEND_STRL(Z_STRVAL_P(arg), l_added); TRACE_APPEND_STR("', "); l_added += 3 + 1; } @@ -401,7 +403,7 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z break; } case IS_BOOL: - if (Z_LVAL_PP(arg)) { + if (Z_LVAL_P(arg)) { TRACE_APPEND_STR("true, "); } else { TRACE_APPEND_STR("false, "); @@ -411,7 +413,7 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z TRACE_APPEND_STR("Resource id #"); /* break; */ case IS_LONG: { - long lval = Z_LVAL_PP(arg); + long lval = Z_LVAL_P(arg); char s_tmp[MAX_LENGTH_OF_LONG + 1]; int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */ TRACE_APPEND_STRL(s_tmp, l_tmp); @@ -419,7 +421,7 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z break; } case IS_DOUBLE: { - double dval = Z_DVAL_PP(arg); + double dval = Z_DVAL_P(arg); char *s_tmp; int l_tmp; @@ -435,18 +437,16 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z TRACE_APPEND_STR("Array, "); break; case IS_OBJECT: { - const char *class_name; - zend_uint class_name_len; - int dup; + zend_string *class_name; TRACE_APPEND_STR("Object("); - dup = zend_get_object_classname(*arg, &class_name, &class_name_len TSRMLS_CC); + class_name = zend_get_object_classname(arg TSRMLS_CC); - TRACE_APPEND_STRL(class_name, class_name_len); - if(!dup) { - efree((char*)class_name); - } + TRACE_APPEND_STRL(class_name->val, class_name->len); +//??? if(!dup) { +//??? efree((char*)class_name); +//??? } TRACE_APPEND_STR("), "); break; @@ -458,15 +458,15 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z } /* }}} */ -static int _build_trace_string(zval **frame TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { char *s_tmp, **str; int *len, *num; long line; - HashTable *ht = Z_ARRVAL_PP(frame); - zval **file, **tmp; + HashTable *ht = Z_ARRVAL_P(frame); + zval *file, *tmp; - if (Z_TYPE_PP(frame) != IS_ARRAY) { + if (Z_TYPE_P(frame) != IS_ARRAY) { zend_error(E_WARNING, "Expected array for frame %lu", hash_key->h); return ZEND_HASH_APPLY_KEEP; } @@ -479,14 +479,16 @@ static int _build_trace_string(zval **frame TSRMLS_DC, int num_args, va_list arg sprintf(s_tmp, "#%d ", (*num)++); TRACE_APPEND_STRL(s_tmp, strlen(s_tmp)); efree(s_tmp); - if (zend_hash_find(ht, "file", sizeof("file"), (void**)&file) == SUCCESS) { - if (Z_TYPE_PP(file) != IS_STRING) { + file = zend_hash_str_find(ht, "file", sizeof("file")-1); + if (file) { + if (Z_TYPE_P(file) != IS_STRING) { zend_error(E_WARNING, "Function name is no string"); TRACE_APPEND_STR("[unknown function]"); } else{ - if (zend_hash_find(ht, "line", sizeof("line"), (void**)&tmp) == SUCCESS) { - if (Z_TYPE_PP(tmp) == IS_LONG) { - line = Z_LVAL_PP(tmp); + tmp = zend_hash_str_find(ht, "line", sizeof("line")-1); + if (tmp) { + if (Z_TYPE_P(tmp) == IS_LONG) { + line = Z_LVAL_P(tmp); } else { zend_error(E_WARNING, "Line is no long"); line = 0; @@ -494,8 +496,8 @@ static int _build_trace_string(zval **frame TSRMLS_DC, int num_args, va_list arg } else { line = 0; } - s_tmp = emalloc(Z_STRLEN_PP(file) + MAX_LENGTH_OF_LONG + 4 + 1); - sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_PP(file), line); + s_tmp = emalloc(Z_STRLEN_P(file) + MAX_LENGTH_OF_LONG + 4 + 1); + sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_P(file), line); TRACE_APPEND_STRL(s_tmp, strlen(s_tmp)); efree(s_tmp); } @@ -506,10 +508,11 @@ static int _build_trace_string(zval **frame TSRMLS_DC, int num_args, va_list arg TRACE_APPEND_KEY("type"); TRACE_APPEND_KEY("function"); TRACE_APPEND_CHR('('); - if (zend_hash_find(ht, "args", sizeof("args"), (void**)&tmp) == SUCCESS) { - if (Z_TYPE_PP(tmp) == IS_ARRAY) { + tmp = zend_hash_str_find(ht, "args", sizeof("args")-1); + if (tmp) { + if (Z_TYPE_P(tmp) == IS_ARRAY) { int last_len = *len; - zend_hash_apply_with_arguments(Z_ARRVAL_PP(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 2, str, len); + zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 2, str, len); if (last_len != *len) { *len -= 2; /* remove last ', ' */ } @@ -544,7 +547,8 @@ ZEND_METHOD(exception, getTraceAsString) efree(s_tmp); res[res_len] = '\0'; - RETURN_STRINGL(res, res_len, 0); +//??? RETURN_STRINGL(res, res_len, 0); + RETURN_STRINGL(res, res_len); } /* }}} */ @@ -587,7 +591,7 @@ ZEND_METHOD(exception, __toString) str = estrndup("", 0); exception = getThis(); - ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1, 1); + ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1); while (exception && Z_TYPE_P(exception) == IS_OBJECT) { prev_str = str; @@ -601,20 +605,20 @@ ZEND_METHOD(exception, __toString) fci.size = sizeof(fci); fci.function_table = &Z_OBJCE_P(exception)->function_table; - fci.function_name = &fname; + ZVAL_COPY_VALUE(&fci.function_name, &fname); fci.symbol_table = NULL; fci.object_ptr = exception; - fci.retval_ptr_ptr = &trace; +//??? fci.retval_ptr_ptr = &trace; fci.param_count = 0; fci.params = NULL; fci.no_separation = 1; zend_call_function(&fci, NULL TSRMLS_CC); - if (Z_TYPE_P(trace) != IS_STRING) { - zval_ptr_dtor(&trace); - trace = NULL; - } +//??? if (Z_TYPE_P(trace) != IS_STRING) { +//??? zval_ptr_dtor(&trace); +//??? trace = NULL; +//??? } if (Z_STRLEN(message) > 0) { len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s", @@ -634,9 +638,9 @@ ZEND_METHOD(exception, __toString) exception = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 0 TSRMLS_CC); - if (trace) { - zval_ptr_dtor(&trace); - } +//??? if (trace) { +//??? zval_ptr_dtor(&trace); +//??? } } zval_dtor(&fname); @@ -645,7 +649,8 @@ ZEND_METHOD(exception, __toString) * the result in uncaught exception handlers without memleaks. */ zend_update_property_string(default_exception_ce, getThis(), "string", sizeof("string")-1, str TSRMLS_CC); - RETURN_STRINGL(str, len, 0); +//??? RETURN_STRINGL(str, len, 0); + RETURN_STRINGL(str, len); } /* }}} */ @@ -714,7 +719,7 @@ void zend_register_default_exception(TSRMLS_D) /* {{{ */ zend_declare_property_null(default_exception_ce, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE TSRMLS_CC); INIT_CLASS_ENTRY(ce, "ErrorException", error_exception_functions); - error_exception_ce = zend_register_internal_class_ex(&ce, default_exception_ce, NULL TSRMLS_CC); + error_exception_ce = zend_register_internal_class_ex(&ce, default_exception_ce TSRMLS_CC); error_exception_ce->create_object = zend_error_exception_new; zend_declare_property_long(error_exception_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED TSRMLS_CC); } @@ -732,11 +737,10 @@ ZEND_API zend_class_entry *zend_get_error_exception(TSRMLS_D) /* {{{ */ } /* }}} */ -ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, const char *message, long code TSRMLS_DC) /* {{{ */ +ZEND_API zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, long code TSRMLS_DC) /* {{{ */ { - zval *ex; + zval ex; - MAKE_STD_ZVAL(ex); if (exception_ce) { if (!instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) { zend_error(E_NOTICE, "Exceptions must be derived from the Exception base class"); @@ -745,41 +749,43 @@ ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, const char } else { exception_ce = default_exception_ce; } - object_init_ex(ex, exception_ce); + object_init_ex(&ex, exception_ce); if (message) { - zend_update_property_string(default_exception_ce, ex, "message", sizeof("message")-1, message TSRMLS_CC); + zend_update_property_string(default_exception_ce, &ex, "message", sizeof("message")-1, message TSRMLS_CC); } if (code) { - zend_update_property_long(default_exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC); + zend_update_property_long(default_exception_ce, &ex, "code", sizeof("code")-1, code TSRMLS_CC); } - zend_throw_exception_internal(ex TSRMLS_CC); - return ex; + zend_throw_exception_internal(&ex TSRMLS_CC); + return Z_OBJ(ex); } /* }}} */ -ZEND_API zval * zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, const char *format, ...) /* {{{ */ +ZEND_API zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, const char *format, ...) /* {{{ */ { va_list arg; char *message; - zval *zexception; + zend_object *obj; va_start(arg, format); zend_vspprintf(&message, 0, format, arg); va_end(arg); - zexception = zend_throw_exception(exception_ce, message, code TSRMLS_CC); + obj = zend_throw_exception(exception_ce, message, code TSRMLS_CC); efree(message); - return zexception; + return obj; } /* }}} */ -ZEND_API zval * zend_throw_error_exception(zend_class_entry *exception_ce, const char *message, long code, int severity TSRMLS_DC) /* {{{ */ +ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce, const char *message, long code, int severity TSRMLS_DC) /* {{{ */ { - zval *ex = zend_throw_exception(exception_ce, message, code TSRMLS_CC); - zend_update_property_long(default_exception_ce, ex, "severity", sizeof("severity")-1, severity TSRMLS_CC); - return ex; + zval ex; + zend_object *obj = zend_throw_exception(exception_ce, message, code TSRMLS_CC); + ZVAL_OBJ(&ex, obj); + zend_update_property_long(default_exception_ce, &ex, "severity", sizeof("severity")-1, severity TSRMLS_CC); + return obj; } /* }}} */ @@ -794,29 +800,36 @@ static void zend_error_va(int type, const char *file, uint lineno, const char *f /* }}} */ /* This function doesn't return if it uses E_ERROR */ -ZEND_API void zend_exception_error(zval *exception, int severity TSRMLS_DC) /* {{{ */ +ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* {{{ */ { - zend_class_entry *ce_exception = Z_OBJCE_P(exception); + zval exception; + zend_class_entry *ce_exception; + + ZVAL_OBJ(&exception, ex); + ce_exception = Z_OBJCE(exception); if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) { - zval *str, *file, *line; + zval tmp, *str, *file, *line; EG(exception) = NULL; - zend_call_method_with_0_params(&exception, ce_exception, NULL, "__tostring", &str); + zend_call_method_with_0_params(&exception, ce_exception, NULL, "__tostring", &tmp); if (!EG(exception)) { - if (Z_TYPE_P(str) != IS_STRING) { - zend_error(E_WARNING, "%s::__toString() must return a string", ce_exception->name); + if (Z_TYPE(tmp) != IS_STRING) { + zend_error(E_WARNING, "%s::__toString() must return a string", ce_exception->name->val); } else { - zend_update_property_string(default_exception_ce, exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name : Z_STRVAL_P(str) TSRMLS_CC); + zend_update_property_string(default_exception_ce, &exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name->val : Z_STRVAL(tmp) TSRMLS_CC); } } - zval_ptr_dtor(&str); + zval_ptr_dtor(&tmp); if (EG(exception)) { + zval zv; + + ZVAL_OBJ(&zv, EG(exception)); /* do the best we can to inform about the inner exception */ if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) { - file = zend_read_property(default_exception_ce, EG(exception), "file", sizeof("file")-1, 1 TSRMLS_CC); - line = zend_read_property(default_exception_ce, EG(exception), "line", sizeof("line")-1, 1 TSRMLS_CC); + file = zend_read_property(default_exception_ce, &zv, "file", sizeof("file")-1, 1 TSRMLS_CC); + line = zend_read_property(default_exception_ce, &zv, "line", sizeof("line")-1, 1 TSRMLS_CC); convert_to_string(file); file = (Z_STRLEN_P(file) > 0) ? file : NULL; @@ -825,12 +838,12 @@ ZEND_API void zend_exception_error(zval *exception, int severity TSRMLS_DC) /* { file = NULL; line = NULL; } - zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_LVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE_P(EG(exception))->name, ce_exception->name); + zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_LVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE(zv)->name->val, ce_exception->name->val); } - str = zend_read_property(default_exception_ce, exception, "string", sizeof("string")-1, 1 TSRMLS_CC); - file = zend_read_property(default_exception_ce, exception, "file", sizeof("file")-1, 1 TSRMLS_CC); - line = zend_read_property(default_exception_ce, exception, "line", sizeof("line")-1, 1 TSRMLS_CC); + str = zend_read_property(default_exception_ce, &exception, "string", sizeof("string")-1, 1 TSRMLS_CC); + file = zend_read_property(default_exception_ce, &exception, "file", sizeof("file")-1, 1 TSRMLS_CC); + line = zend_read_property(default_exception_ce, &exception, "line", sizeof("line")-1, 1 TSRMLS_CC); convert_to_string(str); convert_to_string(file); @@ -838,7 +851,7 @@ ZEND_API void zend_exception_error(zval *exception, int severity TSRMLS_DC) /* { zend_error_va(severity, (Z_STRLEN_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_LVAL_P(line), "Uncaught %s\n thrown", Z_STRVAL_P(str)); } else { - zend_error(severity, "Uncaught exception '%s'", ce_exception->name); + zend_error(severity, "Uncaught exception '%s'", ce_exception->name->val); } } /* }}} */ -- cgit v1.2.1 From 17bf59f895b886a3cc279ac91873588129d1a374 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 14 Feb 2014 17:48:45 +0400 Subject: Use better data structures (incomplete) --- Zend/zend_exceptions.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 938f885d0b..4e1a2b6d59 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -133,13 +133,13 @@ ZEND_API void zend_clear_exception(TSRMLS_D) /* {{{ */ { if (EG(prev_exception)) { -//??? zval_ptr_dtor(&EG(prev_exception)); + OBJ_RELEASE(EG(prev_exception)); EG(prev_exception) = NULL; } if (!EG(exception)) { return; } -//??? zval_ptr_dtor(&EG(exception)); + OBJ_RELEASE(EG(exception)); EG(exception) = NULL; EG(current_execute_data)->opline = EG(opline_before_exception); #if ZEND_DEBUG @@ -269,8 +269,7 @@ static void _default_exception_get_entry(zval *object, char *name, int name_len, value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC); - ZVAL_DUP(return_value, value); -//??? INIT_PZVAL(return_value); + ZVAL_DUP_DEREF(return_value, value); } /* }}} */ @@ -580,7 +579,7 @@ int zend_spprintf(char **message, int max_len, const char *format, ...) /* {{{ * Obtain the string representation of the Exception object */ ZEND_METHOD(exception, __toString) { - zval message, file, line, *trace, *exception; + zval message, file, line, trace, *exception; char *str, *prev_str; int len = 0; zend_fcall_info fci; @@ -608,27 +607,27 @@ ZEND_METHOD(exception, __toString) ZVAL_COPY_VALUE(&fci.function_name, &fname); fci.symbol_table = NULL; fci.object_ptr = exception; -//??? fci.retval_ptr_ptr = &trace; + fci.retval = &trace; fci.param_count = 0; fci.params = NULL; fci.no_separation = 1; zend_call_function(&fci, NULL TSRMLS_CC); -//??? if (Z_TYPE_P(trace) != IS_STRING) { -//??? zval_ptr_dtor(&trace); -//??? trace = NULL; -//??? } + if (Z_TYPE(trace) != IS_STRING) { + zval_ptr_dtor(&trace); + ZVAL_UNDEF(&trace); + } if (Z_STRLEN(message) > 0) { len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s", Z_OBJCE_P(exception)->name, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line), - (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n", + (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", len ? "\n\nNext " : "", prev_str); } else { len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s", Z_OBJCE_P(exception)->name, Z_STRVAL(file), Z_LVAL(line), - (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n", + (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", len ? "\n\nNext " : "", prev_str); } efree(prev_str); @@ -638,9 +637,7 @@ ZEND_METHOD(exception, __toString) exception = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 0 TSRMLS_CC); -//??? if (trace) { -//??? zval_ptr_dtor(&trace); -//??? } + zval_ptr_dtor(&trace); } zval_dtor(&fname); -- cgit v1.2.1 From 6a3a33405b4dbe55a2ca70b1162a79125b6dd2d6 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 19 Feb 2014 12:13:43 +0800 Subject: Use zend_string avoid mem wasting --- Zend/zend_exceptions.c | 88 +++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 47 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 4e1a2b6d59..196b9aa320 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -334,29 +334,27 @@ ZEND_METHOD(error_exception, getSeverity) /* }}} */ /* {{{ gettraceasstring() macros */ -#define TRACE_APPEND_CHR(chr) \ - *str = (char*)erealloc(*str, *len + 1 + 1); \ - (*str)[(*len)++] = chr +#define TRACE_APPEND_CHR(chr) \ + str = STR_REALLOC(str, str->len + 1, 0); \ + str->val[str->len - 1] = chr -#define TRACE_APPEND_STRL(val, vallen) \ - { \ - int l = vallen; \ - *str = (char*)erealloc(*str, *len + l + 1); \ - memcpy((*str) + *len, val, l); \ - *len += l; \ +#define TRACE_APPEND_STRL(v, l) \ + { \ + str = STR_REALLOC(str, str->len + (l), 0); \ + memcpy(str->val + str->len - (l), (v), (l)); \ } -#define TRACE_APPEND_STR(val) \ - TRACE_APPEND_STRL(val, sizeof(val)-1) +#define TRACE_APPEND_STR(v) \ + TRACE_APPEND_STRL((v), sizeof((v))-1) #define TRACE_APPEND_KEY(key) do { \ - tmp = zend_hash_str_find(ht, key, sizeof(key)-1); \ - if (tmp) { \ - if (Z_TYPE_P(tmp) != IS_STRING) { \ - zend_error(E_WARNING, "Value for %s is no string", key); \ - TRACE_APPEND_STR("[unknown]"); \ + tmp = zend_hash_str_find(ht, key, sizeof(key)-1); \ + if (tmp) { \ + if (Z_TYPE_P(tmp) != IS_STRING) { \ + zend_error(E_WARNING, "Value for %s is no string", key); \ + TRACE_APPEND_STR("[unknown]"); \ } else { \ - TRACE_APPEND_STRL(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ + TRACE_APPEND_STRL(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ } \ } \ } while (0) @@ -365,11 +363,9 @@ ZEND_METHOD(error_exception, getSeverity) static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { - char **str; - int *len; + zend_string *str; - str = va_arg(args, char**); - len = va_arg(args, int*); + str = va_arg(args, zend_string*); /* the trivial way would be to do: * conver_to_string_ex(arg); @@ -395,8 +391,8 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze l_added += 3 + 1; } while (--l_added) { - if ((*str)[*len - l_added] < 32) { - (*str)[*len - l_added] = '?'; + if (str->val[str->len - l_added] < 32) { + str->val[str->len - l_added] = '?'; } } break; @@ -459,24 +455,24 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { - char *s_tmp, **str; - int *len, *num; + char *s_tmp; + int len, *num; long line; HashTable *ht = Z_ARRVAL_P(frame); zval *file, *tmp; + zend_string *str; if (Z_TYPE_P(frame) != IS_ARRAY) { zend_error(E_WARNING, "Expected array for frame %lu", hash_key->h); return ZEND_HASH_APPLY_KEEP; } - str = va_arg(args, char**); - len = va_arg(args, int*); + str = va_arg(args, zend_string*); num = va_arg(args, int*); s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1); - sprintf(s_tmp, "#%d ", (*num)++); - TRACE_APPEND_STRL(s_tmp, strlen(s_tmp)); + len = sprintf(s_tmp, "#%d ", (*num)++); + TRACE_APPEND_STRL(s_tmp, len); efree(s_tmp); file = zend_hash_str_find(ht, "file", sizeof("file")-1); if (file) { @@ -496,8 +492,8 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args line = 0; } s_tmp = emalloc(Z_STRLEN_P(file) + MAX_LENGTH_OF_LONG + 4 + 1); - sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_P(file), line); - TRACE_APPEND_STRL(s_tmp, strlen(s_tmp)); + len = sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_P(file), line); + TRACE_APPEND_STRL(s_tmp, len); efree(s_tmp); } } else { @@ -510,10 +506,10 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args tmp = zend_hash_str_find(ht, "args", sizeof("args")-1); if (tmp) { if (Z_TYPE_P(tmp) == IS_ARRAY) { - int last_len = *len; - zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 2, str, len); - if (last_len != *len) { - *len -= 2; /* remove last ', ' */ + int last_len = str->len; + zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 1, str); + if (last_len != str->len) { + str->len -= 2; /* remove last ', ' */ } } else { zend_error(E_WARNING, "args element is no array"); @@ -529,25 +525,23 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args ZEND_METHOD(exception, getTraceAsString) { zval *trace; - char *res, **str, *s_tmp; - int res_len = 0, *len = &res_len, num = 0; + zend_string *str; + int num = 0, len; + char s_tmp[MAX_LENGTH_OF_LONG + 7 + 1 + 1]; DEFAULT_0_PARAMS; - res = estrdup(""); - str = &res; + str = STR_ALLOC(0, 0); trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC); - zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 3, str, len, &num); + zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 2, str, &num); - s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 7 + 1); - sprintf(s_tmp, "#%d {main}", num); - TRACE_APPEND_STRL(s_tmp, strlen(s_tmp)); - efree(s_tmp); + len = sprintf(s_tmp, "#%d {main}", num); + TRACE_APPEND_STRL(s_tmp, len); + + str->val[str->len] = '\0'; - res[res_len] = '\0'; -//??? RETURN_STRINGL(res, res_len, 0); - RETURN_STRINGL(res, res_len); + RETURN_STR(str); } /* }}} */ -- cgit v1.2.1 From 9067dbcd0d8d8bed6c723d274b162182f33281ea Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 19 Feb 2014 12:03:01 +0400 Subject: Use better data structures (incomplete) --- Zend/zend_exceptions.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 196b9aa320..9473751ae4 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -363,9 +363,10 @@ ZEND_METHOD(error_exception, getSeverity) static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { - zend_string *str; + zend_string *str, **str_ptr; - str = va_arg(args, zend_string*); + str_ptr = va_arg(args, zend_string**); + str = *str_ptr; /* the trivial way would be to do: * conver_to_string_ex(arg); @@ -373,6 +374,9 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze * but that could cause some E_NOTICE and also damn long lines. */ + if (Z_TYPE_P(arg) == IS_REFERENCE) { + arg = Z_REFVAL_P(arg); + } switch (Z_TYPE_P(arg)) { case IS_NULL: TRACE_APPEND_STR("NULL, "); @@ -449,6 +453,7 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze default: break; } + *str_ptr = str; return ZEND_HASH_APPLY_KEEP; } /* }}} */ @@ -460,14 +465,15 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args long line; HashTable *ht = Z_ARRVAL_P(frame); zval *file, *tmp; - zend_string *str; + zend_string *str, **str_ptr; if (Z_TYPE_P(frame) != IS_ARRAY) { zend_error(E_WARNING, "Expected array for frame %lu", hash_key->h); return ZEND_HASH_APPLY_KEEP; } - str = va_arg(args, zend_string*); + str_ptr = va_arg(args, zend_string**); + str = *str_ptr; num = va_arg(args, int*); s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1); @@ -507,7 +513,7 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args if (tmp) { if (Z_TYPE_P(tmp) == IS_ARRAY) { int last_len = str->len; - zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 1, str); + zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 1, &str); if (last_len != str->len) { str->len -= 2; /* remove last ', ' */ } @@ -516,6 +522,7 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args } } TRACE_APPEND_STR(")\n"); + *str_ptr = str; return ZEND_HASH_APPLY_KEEP; } /* }}} */ @@ -534,7 +541,7 @@ ZEND_METHOD(exception, getTraceAsString) str = STR_ALLOC(0, 0); trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC); - zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 2, str, &num); + zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 2, &str, &num); len = sprintf(s_tmp, "#%d {main}", num); TRACE_APPEND_STRL(s_tmp, len); @@ -615,12 +622,12 @@ ZEND_METHOD(exception, __toString) if (Z_STRLEN(message) > 0) { len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line), + Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line), (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", len ? "\n\nNext " : "", prev_str); } else { len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name, Z_STRVAL(file), Z_LVAL(line), + Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_LVAL(line), (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", len ? "\n\nNext " : "", prev_str); } -- cgit v1.2.1 From afa03a470ef90a53f2b59a8175f77afdb6b5a651 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Thu, 20 Feb 2014 17:39:58 +0100 Subject: Use nicer output for characters < 32 and > 126 in exception strings Using question marks might confuse more than it helps. Users are wondering what happened to their string... --- Zend/zend_exceptions.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 2ef74ad106..ced1ebf639 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -360,6 +360,11 @@ ZEND_METHOD(error_exception, getSeverity) } \ } + +#define TRACE_ARG_APPEND(vallen) \ + *str = (char*)erealloc(*str, *len + 1 + vallen); \ + memcpy((*str) + *len - l_added + 1 + vallen, (*str) + *len - l_added + 1, l_added); + /* }}} */ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ @@ -371,7 +376,7 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z len = va_arg(args, int*); /* the trivial way would be to do: - * conver_to_string_ex(arg); + * convert_to_string_ex(arg); * append it and kill the now tmp arg. * but that could cause some E_NOTICE and also damn long lines. */ @@ -394,8 +399,58 @@ static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, z l_added += 3 + 1; } while (--l_added) { - if ((*str)[*len - l_added] < 32) { - (*str)[*len - l_added] = '?'; + unsigned char chr = (*str)[*len - l_added]; + if (chr < 32 || chr == '\\' || chr > 126) { + (*str)[*len - l_added] = '\\'; + + switch (chr) { + case '\n': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'n'; + break; + case '\r': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'r'; + break; + case '\t': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 't'; + break; + case '\f': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'f'; + break; + case '\v': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'v'; + break; +#ifndef PHP_WIN32 + case '\e': +#else + case VK_ESCAPE: +#endif + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = 'e'; + break; + case '\\': + TRACE_ARG_APPEND(1); + (*str)[++(*len) - l_added] = '\\'; + break; + default: + TRACE_ARG_APPEND(3); + (*str)[*len - l_added + 1] = 'x'; + if ((chr >> 4) < 10) { + (*str)[*len - l_added + 2] = (chr >> 4) + '0'; + } else { + (*str)[*len - l_added + 2] = (chr >> 4) + 'A' - 10; + } + if (chr % 16 < 10) { + (*str)[*len - l_added + 3] = chr % 16 + '0'; + } else { + (*str)[*len - l_added + 3] = chr % 16 + 'A' - 10; + } + *len += 3; + } } } break; -- cgit v1.2.1 From 6fbea9ce6a6382d7999b6f6059c16348ee50ecda Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 21 Feb 2014 16:14:42 +0400 Subject: Fixed exception constructor --- Zend/zend_exceptions.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 9473751ae4..48779b47ec 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -160,6 +160,7 @@ static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type, object_properties_init(object, class_type); zend_fetch_debug_backtrace(&trace, skip_top_traces, 0, 0 TSRMLS_CC); + Z_SET_REFCOUNT(trace, 0); zend_update_property_string(default_exception_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); zend_update_property_long(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); @@ -194,19 +195,19 @@ ZEND_METHOD(exception, __clone) Exception constructor */ ZEND_METHOD(exception, __construct) { - char *message = NULL; + zend_string *message = NULL; long code = 0; zval *object, *previous = NULL; - int argc = ZEND_NUM_ARGS(), message_len; + int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|slO!", &message, &message_len, &code, &previous, default_exception_ce) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|SlO!", &message, &code, &previous, default_exception_ce) == FAILURE) { zend_error(E_ERROR, "Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]])"); } object = getThis(); if (message) { - zend_update_property_stringl(default_exception_ce, object, "message", sizeof("message")-1, message, message_len TSRMLS_CC); + zend_update_property_str(default_exception_ce, object, "message", sizeof("message")-1, message TSRMLS_CC); } if (code) { -- cgit v1.2.1 From 6454684212b4687167cc058ad77972f2d456cf20 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 21 Feb 2014 22:59:51 +0400 Subject: Use better data structures (incomplete) --- Zend/zend_exceptions.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 48779b47ec..791f7a25c5 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -409,9 +409,15 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze TRACE_APPEND_STR("false, "); } break; - case IS_RESOURCE: + case IS_RESOURCE: { + long lval = Z_RES_HANDLE_P(arg); + char s_tmp[MAX_LENGTH_OF_LONG + 1]; + int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */ TRACE_APPEND_STR("Resource id #"); - /* break; */ + TRACE_APPEND_STRL(s_tmp, l_tmp); + TRACE_APPEND_STR(", "); + break; + } case IS_LONG: { long lval = Z_LVAL_P(arg); char s_tmp[MAX_LENGTH_OF_LONG + 1]; -- cgit v1.2.1 From e49c0804dafa5a3baad7ceff8f82d17260124bac Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 26 Feb 2014 17:36:39 +0400 Subject: Temporary memory leak fix (should be done in a better way) --- Zend/zend_exceptions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 791f7a25c5..531ec345b7 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -655,7 +655,8 @@ ZEND_METHOD(exception, __toString) zend_update_property_string(default_exception_ce, getThis(), "string", sizeof("string")-1, str TSRMLS_CC); //??? RETURN_STRINGL(str, len, 0); - RETURN_STRINGL(str, len); + RETVAL_STRINGL(str, len); + efree(str); } /* }}} */ -- cgit v1.2.1 From 54d559d893f07098e56bee4489d514726dc96f7d Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 27 Mar 2014 11:50:45 +0400 Subject: Replaced (Z_TYPE(x) == IS_REFERENCE) with (Z_ISREF(x)) --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 531ec345b7..c798a768c4 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -375,7 +375,7 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze * but that could cause some E_NOTICE and also damn long lines. */ - if (Z_TYPE_P(arg) == IS_REFERENCE) { + if (Z_ISREF_P(arg)) { arg = Z_REFVAL_P(arg); } switch (Z_TYPE_P(arg)) { -- cgit v1.2.1 From c6cba554544d9dc676d1cfa99447364c95768664 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 27 Mar 2014 13:39:09 +0400 Subject: Use ZVAL_DEREF() macro --- Zend/zend_exceptions.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index c798a768c4..5ba0ae3bc3 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -375,9 +375,7 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze * but that could cause some E_NOTICE and also damn long lines. */ - if (Z_ISREF_P(arg)) { - arg = Z_REFVAL_P(arg); - } + ZVAL_DEREF(arg); switch (Z_TYPE_P(arg)) { case IS_NULL: TRACE_APPEND_STR("NULL, "); -- cgit v1.2.1 From ea85451b65b904d0670c4011c819a15431720432 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 28 Mar 2014 02:11:22 +0400 Subject: Refactored data structures to keep zend_object* instead of a whole zval in some places --- Zend/zend_exceptions.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 5ba0ae3bc3..5cb2e6f618 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -92,7 +92,7 @@ void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ zend_uint name_len; if (exception != NULL) { - zend_get_object_classname(exception, &classname, &name_len TSRMLS_CC); + zend_get_object_classname(Z_OBJ_P(exception), &classname, &name_len TSRMLS_CC); DTRACE_EXCEPTION_THROWN((char *)classname); } else { DTRACE_EXCEPTION_THROWN(NULL); @@ -445,7 +445,7 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze TRACE_APPEND_STR("Object("); - class_name = zend_get_object_classname(arg TSRMLS_CC); + class_name = zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC); TRACE_APPEND_STRL(class_name->val, class_name->len); //??? if(!dup) { @@ -612,7 +612,7 @@ ZEND_METHOD(exception, __toString) fci.function_table = &Z_OBJCE_P(exception)->function_table; ZVAL_COPY_VALUE(&fci.function_name, &fname); fci.symbol_table = NULL; - fci.object_ptr = exception; + fci.object = Z_OBJ_P(exception); fci.retval = &trace; fci.param_count = 0; fci.params = NULL; -- cgit v1.2.1 From d8099d0468426dbee59f540048376653535270ce Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 2 Apr 2014 14:34:44 +0400 Subject: Changed data layout to allow more efficient operations --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 5cb2e6f618..e661a64976 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -52,7 +52,7 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo previous = zend_read_property(default_exception_ce, pzv, "previous", sizeof("previous")-1, 1 TSRMLS_CC); if (Z_TYPE_P(previous) == IS_NULL) { zend_update_property(default_exception_ce, pzv, "previous", sizeof("previous")-1, &tmp TSRMLS_CC); - add_previous->gc.refcount--; + GC_REFCOUNT(add_previous)--; return; } pzv = previous; -- cgit v1.2.1 From 76cc99fe60d1e446a0250b4d778f02bcdbd7fc09 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 3 Apr 2014 15:26:23 +0400 Subject: Refactored ZVAL flags usage to simplify various checks (e.g. Z_REFCOUNTED(), candidate for GC, etc) --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index e661a64976..c59dd9d9dd 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -553,7 +553,7 @@ ZEND_METHOD(exception, getTraceAsString) str->val[str->len] = '\0'; - RETURN_STR(str); + RETURN_NEW_STR(str); } /* }}} */ -- cgit v1.2.1 From 0e273217cfd1e72b5109a880fb4334edd2f61448 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 7 Apr 2014 17:14:38 +0200 Subject: Fix Linux specific fail in error traces Linux apparently does not like memcpy in overlapping regions... --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 9b7d3689c6..e4570269e3 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -363,7 +363,7 @@ ZEND_METHOD(error_exception, getSeverity) #define TRACE_ARG_APPEND(vallen) \ *str = (char*)erealloc(*str, *len + 1 + vallen); \ - memcpy((*str) + *len - l_added + 1 + vallen, (*str) + *len - l_added + 1, l_added); + memmove((*str) + *len - l_added + 1 + vallen, (*str) + *len - l_added + 1, l_added); /* }}} */ -- cgit v1.2.1 From 050d7e38ad4163e7fa65e26724d3516ce7b33601 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 15 Apr 2014 15:40:40 +0400 Subject: Cleanup (1-st round) --- Zend/zend_exceptions.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index c59dd9d9dd..4272adedbd 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -448,10 +448,6 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze class_name = zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC); TRACE_APPEND_STRL(class_name->val, class_name->len); -//??? if(!dup) { -//??? efree((char*)class_name); -//??? } - TRACE_APPEND_STR("), "); break; } @@ -652,7 +648,7 @@ ZEND_METHOD(exception, __toString) * the result in uncaught exception handlers without memleaks. */ zend_update_property_string(default_exception_ce, getThis(), "string", sizeof("string")-1, str TSRMLS_CC); -//??? RETURN_STRINGL(str, len, 0); + // TODO: avoid reallocation ??? RETVAL_STRINGL(str, len); efree(str); } -- cgit v1.2.1 From 17d027ed47c1f07b397a611431d28ad0e0107146 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 30 Apr 2014 18:32:42 +0400 Subject: Split IS_BOOL into IS_FALSE and IS_TRUE --- Zend/zend_exceptions.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 137d9c97f8..8b89796179 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -456,12 +456,11 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze } break; } - case IS_BOOL: - if (Z_LVAL_P(arg)) { - TRACE_APPEND_STR("true, "); - } else { - TRACE_APPEND_STR("false, "); - } + case IS_FALSE: + TRACE_APPEND_STR("false, "); + break; + case IS_TRUE: + TRACE_APPEND_STR("true, "); break; case IS_RESOURCE: { long lval = Z_RES_HANDLE_P(arg); -- cgit v1.2.1 From 88c550a7998d4af00767237b89f020ae3acac61b Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 10 May 2014 00:21:49 +0800 Subject: Added vstrpprintf strpprintf to avoid duplicate string (the function name maybe improvement) --- Zend/zend_exceptions.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 8b89796179..ae0ae834e4 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -618,7 +618,7 @@ ZEND_METHOD(exception, getPrevious) previous = zend_read_property(default_exception_ce, getThis(), "previous", sizeof("previous")-1, 1 TSRMLS_CC); RETURN_ZVAL(previous, 1, 0); -} +} /* }}} */ int zend_spprintf(char **message, int max_len, const char *format, ...) /* {{{ */ { @@ -632,19 +632,30 @@ int zend_spprintf(char **message, int max_len, const char *format, ...) /* {{{ * } /* }}} */ +zend_string *zend_strpprintf(int max_len, const char *format, ...) /* {{{ */ +{ + va_list arg; + zend_string *str; + + va_start(arg, format); + str = zend_vstrpprintf(max_len, format, arg); + va_end(arg); + return str; +} +/* }}} */ + /* {{{ proto string Exception::__toString() Obtain the string representation of the Exception object */ ZEND_METHOD(exception, __toString) { zval message, file, line, trace, *exception; - char *str, *prev_str; - int len = 0; + zend_string *str, *prev_str; zend_fcall_info fci; zval fname; DEFAULT_0_PARAMS; - str = estrndup("", 0); + str = STR_EMPTY_ALLOC(); exception = getThis(); ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1); @@ -677,17 +688,17 @@ ZEND_METHOD(exception, __toString) } if (Z_STRLEN(message) > 0) { - len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line), - (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", - len ? "\n\nNext " : "", prev_str); + str = zend_strpprintf(0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s", + Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line), + (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", + prev_str->len ? "\n\nNext " : "", prev_str->val); } else { - len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_LVAL(line), - (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", - len ? "\n\nNext " : "", prev_str); + str = zend_strpprintf(0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s", + Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_LVAL(line), + (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", + prev_str->len ? "\n\nNext " : "", prev_str->val); } - efree(prev_str); + STR_RELEASE(prev_str); zval_dtor(&message); zval_dtor(&file); zval_dtor(&line); @@ -701,11 +712,9 @@ ZEND_METHOD(exception, __toString) /* We store the result in the private property string so we can access * the result in uncaught exception handlers without memleaks. */ - zend_update_property_string(default_exception_ce, getThis(), "string", sizeof("string")-1, str TSRMLS_CC); + zend_update_property_str(default_exception_ce, getThis(), "string", sizeof("string")-1, str TSRMLS_CC); - // TODO: avoid reallocation ??? - RETVAL_STRINGL(str, len); - efree(str); + RETURN_STR(str); } /* }}} */ -- cgit v1.2.1 From bc357eaf3f9524f6a8c635c5d0f7b3f45aca5a5c Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sun, 25 May 2014 20:04:35 +0800 Subject: Fixed apply_func_args_t --- Zend/zend_exceptions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index ae0ae834e4..2c967d578c 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -569,7 +569,7 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args if (tmp) { if (Z_TYPE_P(tmp) == IS_ARRAY) { int last_len = str->len; - zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 1, &str); + zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, _build_trace_args, 1, &str); if (last_len != str->len) { str->len -= 2; /* remove last ', ' */ } @@ -597,7 +597,7 @@ ZEND_METHOD(exception, getTraceAsString) str = STR_ALLOC(0, 0); trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC); - zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 2, &str, &num); + zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, _build_trace_string, 2, &str, &num); len = sprintf(s_tmp, "#%d {main}", num); TRACE_APPEND_STRL(s_tmp, len); -- cgit v1.2.1 From d0d62d3bb0a18dc3d202ba2c70fab09938c9b99f Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 28 May 2014 18:45:01 +0400 Subject: Use new zend_hash API --- Zend/zend_exceptions.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 2c967d578c..f78123124a 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -369,12 +369,9 @@ ZEND_METHOD(error_exception, getSeverity) /* }}} */ -static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ */ { - zend_string *str, **str_ptr; - - str_ptr = va_arg(args, zend_string**); - str = *str_ptr; + zend_string *str = *str_ptr; /* the trivial way would be to do: * convert_to_string_ex(arg); @@ -510,28 +507,24 @@ static int _build_trace_args(zval *arg TSRMLS_DC, int num_args, va_list args, ze break; } *str_ptr = str; - return ZEND_HASH_APPLY_KEEP; } /* }}} */ -static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static void _build_trace_string(zval *frame, ulong index, zend_string **str_ptr, int *num TSRMLS_DC) /* {{{ */ { char *s_tmp; - int len, *num; + int len; long line; - HashTable *ht = Z_ARRVAL_P(frame); + HashTable *ht; zval *file, *tmp; - zend_string *str, **str_ptr; + zend_string *str = *str_ptr; if (Z_TYPE_P(frame) != IS_ARRAY) { - zend_error(E_WARNING, "Expected array for frame %lu", hash_key->h); - return ZEND_HASH_APPLY_KEEP; + zend_error(E_WARNING, "Expected array for frame %lu", index); + return; } - str_ptr = va_arg(args, zend_string**); - str = *str_ptr; - num = va_arg(args, int*); - + ht = Z_ARRVAL_P(frame); s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1); len = sprintf(s_tmp, "#%d ", (*num)++); TRACE_APPEND_STRL(s_tmp, len); @@ -569,7 +562,12 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args if (tmp) { if (Z_TYPE_P(tmp) == IS_ARRAY) { int last_len = str->len; - zend_hash_apply_with_arguments(Z_ARRVAL_P(tmp) TSRMLS_CC, _build_trace_args, 1, &str); + zval *arg; + + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmp), arg) { + _build_trace_args(arg, &str TSRMLS_CC); + } ZEND_HASH_FOREACH_END(); + if (last_len != str->len) { str->len -= 2; /* remove last ', ' */ } @@ -579,7 +577,6 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args } TRACE_APPEND_STR(")\n"); *str_ptr = str; - return ZEND_HASH_APPLY_KEEP; } /* }}} */ @@ -587,8 +584,9 @@ static int _build_trace_string(zval *frame TSRMLS_DC, int num_args, va_list args Obtain the backtrace for the exception as a string (instead of an array) */ ZEND_METHOD(exception, getTraceAsString) { - zval *trace; - zend_string *str; + zval *trace, *frame; + ulong index; + zend_string *str, *key; int num = 0, len; char s_tmp[MAX_LENGTH_OF_LONG + 7 + 1 + 1]; @@ -597,7 +595,9 @@ ZEND_METHOD(exception, getTraceAsString) str = STR_ALLOC(0, 0); trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC); - zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, _build_trace_string, 2, &str, &num); + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(trace), index, key, frame) { + _build_trace_string(frame, index, &str, &num TSRMLS_CC); + } ZEND_HASH_FOREACH_END(); len = sprintf(s_tmp, "#%d {main}", num); TRACE_APPEND_STRL(s_tmp, len); -- cgit v1.2.1 From 0427ae08fb8dde00993277c3e7f9d98abfa159a8 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 3 Jun 2014 00:36:31 +0400 Subject: cleanup --- Zend/zend_exceptions.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index f78123124a..a8e57c950a 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -270,7 +270,11 @@ static void _default_exception_get_entry(zval *object, char *name, int name_len, value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC); - ZVAL_DUP_DEREF(return_value, value); + if (UNEXPECTED(Z_ISREF_P(return_value))) { + ZVAL_DUP(return_value, Z_REFVAL_P(value)); + } else { + ZVAL_COPY(return_value, value); + } } /* }}} */ -- cgit v1.2.1 From 0c5a1b835ea8d2ef47d3fa1a162d9333ec2686b5 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 23 Jun 2014 17:02:22 +0400 Subject: Fixed refcounting bug --- Zend/zend_exceptions.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index a8e57c950a..0f59e254d7 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -269,12 +269,7 @@ static void _default_exception_get_entry(zval *object, char *name, int name_len, zval *value; value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC); - - if (UNEXPECTED(Z_ISREF_P(return_value))) { - ZVAL_DUP(return_value, Z_REFVAL_P(value)); - } else { - ZVAL_COPY(return_value, value); - } + ZVAL_COPY(return_value, value); } /* }}} */ -- cgit v1.2.1 From 5aa91be509731eb46acff242412941325122ab03 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 7 Jul 2014 15:50:44 +0400 Subject: Simplify call-frame handling --- Zend/zend_exceptions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 0f59e254d7..90487bf762 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -119,7 +119,8 @@ void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ zend_throw_exception_hook(exception TSRMLS_CC); } - if (EG(current_execute_data)->opline == NULL || + if (!EG(current_execute_data)->func || + !ZEND_USER_CODE(EG(current_execute_data)->func->common.type) || (EG(current_execute_data)->opline+1)->opcode == ZEND_HANDLE_EXCEPTION) { /* no need to rethrow the exception */ return; -- cgit v1.2.1 From ea17b018d834038f2e65b1716c0cbc02a27a7838 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 22 Jul 2014 11:12:49 +0400 Subject: Fixed dtrace support --- Zend/zend_exceptions.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 90487bf762..754927b577 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -88,12 +88,11 @@ void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ { #ifdef HAVE_DTRACE if (DTRACE_EXCEPTION_THROWN_ENABLED()) { - const char *classname; - zend_uint name_len; + zend_string *classname; if (exception != NULL) { - zend_get_object_classname(Z_OBJ_P(exception), &classname, &name_len TSRMLS_CC); - DTRACE_EXCEPTION_THROWN((char *)classname); + classname = zend_get_object_classname(Z_OBJ_P(exception) TSRMLS_CC); + DTRACE_EXCEPTION_THROWN(classname->val); } else { DTRACE_EXCEPTION_THROWN(NULL); } -- cgit v1.2.1 From 8ee2a4a9b5de682c0b37670e1f4f86242b1650ce Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 Aug 2014 11:16:11 +0200 Subject: first shot on merging the core fro the int64 branch --- Zend/zend_exceptions.c | 64 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 754927b577..401a85f870 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -163,7 +163,7 @@ static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type, Z_SET_REFCOUNT(trace, 0); zend_update_property_string(default_exception_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); - zend_update_property_long(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); + zend_update_property_int(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); zend_update_property(default_exception_ce, &obj, "trace", sizeof("trace")-1, &trace TSRMLS_CC); return object; @@ -211,7 +211,7 @@ ZEND_METHOD(exception, __construct) } if (code) { - zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC); + zend_update_property_int(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC); } if (previous) { @@ -240,21 +240,21 @@ ZEND_METHOD(error_exception, __construct) } if (code) { - zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC); + zend_update_property_int(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC); } if (previous) { zend_update_property(default_exception_ce, object, "previous", sizeof("previous")-1, previous TSRMLS_CC); } - zend_update_property_long(default_exception_ce, object, "severity", sizeof("severity")-1, severity TSRMLS_CC); + zend_update_property_int(default_exception_ce, object, "severity", sizeof("severity")-1, severity TSRMLS_CC); if (argc >= 4) { zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, filename TSRMLS_CC); if (argc < 5) { lineno = 0; /* invalidate lineno */ } - zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, lineno TSRMLS_CC); + zend_update_property_int(default_exception_ce, object, "line", sizeof("line")-1, lineno TSRMLS_CC); } } /* }}} */ @@ -354,7 +354,7 @@ ZEND_METHOD(error_exception, getSeverity) zend_error(E_WARNING, "Value for %s is no string", key); \ TRACE_APPEND_STR("[unknown]"); \ } else { \ - TRACE_APPEND_STRL(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ + TRACE_APPEND_STRL(Z_STRVAL_P(tmp), Z_STRSIZE_P(tmp)); \ } \ } \ } while (0) @@ -386,12 +386,12 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ case IS_STRING: { int l_added; TRACE_APPEND_CHR('\''); - if (Z_STRLEN_P(arg) > 15) { + if (Z_STRSIZE_P(arg) > 15) { TRACE_APPEND_STRL(Z_STRVAL_P(arg), 15); TRACE_APPEND_STR("...', "); l_added = 15 + 6 + 1; /* +1 because of while (--l_added) */ } else { - l_added = Z_STRLEN_P(arg); + l_added = Z_STRSIZE_P(arg); TRACE_APPEND_STRL(Z_STRVAL_P(arg), l_added); TRACE_APPEND_STR("', "); l_added += 3 + 1; @@ -460,16 +460,16 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ break; case IS_RESOURCE: { long lval = Z_RES_HANDLE_P(arg); - char s_tmp[MAX_LENGTH_OF_LONG + 1]; + char s_tmp[MAX_LENGTH_OF_ZEND_INT + 1]; int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */ TRACE_APPEND_STR("Resource id #"); TRACE_APPEND_STRL(s_tmp, l_tmp); TRACE_APPEND_STR(", "); break; } - case IS_LONG: { - long lval = Z_LVAL_P(arg); - char s_tmp[MAX_LENGTH_OF_LONG + 1]; + case IS_INT: { + long lval = Z_IVAL_P(arg); + char s_tmp[MAX_LENGTH_OF_ZEND_INT + 1]; int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */ TRACE_APPEND_STRL(s_tmp, l_tmp); TRACE_APPEND_STR(", "); @@ -524,7 +524,7 @@ static void _build_trace_string(zval *frame, ulong index, zend_string **str_ptr, } ht = Z_ARRVAL_P(frame); - s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1); + s_tmp = emalloc(1 + MAX_LENGTH_OF_ZEND_INT + 1 + 1); len = sprintf(s_tmp, "#%d ", (*num)++); TRACE_APPEND_STRL(s_tmp, len); efree(s_tmp); @@ -536,8 +536,8 @@ static void _build_trace_string(zval *frame, ulong index, zend_string **str_ptr, } else{ tmp = zend_hash_str_find(ht, "line", sizeof("line")-1); if (tmp) { - if (Z_TYPE_P(tmp) == IS_LONG) { - line = Z_LVAL_P(tmp); + if (Z_TYPE_P(tmp) == IS_INT) { + line = Z_IVAL_P(tmp); } else { zend_error(E_WARNING, "Line is no long"); line = 0; @@ -545,7 +545,7 @@ static void _build_trace_string(zval *frame, ulong index, zend_string **str_ptr, } else { line = 0; } - s_tmp = emalloc(Z_STRLEN_P(file) + MAX_LENGTH_OF_LONG + 4 + 1); + s_tmp = emalloc(Z_STRSIZE_P(file) + MAX_LENGTH_OF_ZEND_INT + 4 + 1); len = sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_P(file), line); TRACE_APPEND_STRL(s_tmp, len); efree(s_tmp); @@ -587,7 +587,7 @@ ZEND_METHOD(exception, getTraceAsString) ulong index; zend_string *str, *key; int num = 0, len; - char s_tmp[MAX_LENGTH_OF_LONG + 7 + 1 + 1]; + char s_tmp[MAX_LENGTH_OF_ZEND_INT + 7 + 1 + 1]; DEFAULT_0_PARAMS; @@ -667,7 +667,7 @@ ZEND_METHOD(exception, __toString) convert_to_string(&message); convert_to_string(&file); - convert_to_long(&line); + convert_to_int(&line); fci.size = sizeof(fci); fci.function_table = &Z_OBJCE_P(exception)->function_table; @@ -686,15 +686,15 @@ ZEND_METHOD(exception, __toString) ZVAL_UNDEF(&trace); } - if (Z_STRLEN(message) > 0) { + if (Z_STRSIZE(message) > 0) { str = zend_strpprintf(0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line), - (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", + Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_IVAL(line), + (Z_TYPE(trace) == IS_STRING && Z_STRSIZE(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", prev_str->len ? "\n\nNext " : "", prev_str->val); } else { str = zend_strpprintf(0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_LVAL(line), - (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", + Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_IVAL(line), + (Z_TYPE(trace) == IS_STRING && Z_STRSIZE(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", prev_str->len ? "\n\nNext " : "", prev_str->val); } STR_RELEASE(prev_str); @@ -775,7 +775,7 @@ void zend_register_default_exception(TSRMLS_D) /* {{{ */ zend_declare_property_string(default_exception_ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_string(default_exception_ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_long(default_exception_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_int(default_exception_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(default_exception_ce, "file", sizeof("file")-1, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(default_exception_ce, "line", sizeof("line")-1, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(default_exception_ce, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE TSRMLS_CC); @@ -784,7 +784,7 @@ void zend_register_default_exception(TSRMLS_D) /* {{{ */ INIT_CLASS_ENTRY(ce, "ErrorException", error_exception_functions); error_exception_ce = zend_register_internal_class_ex(&ce, default_exception_ce TSRMLS_CC); error_exception_ce->create_object = zend_error_exception_new; - zend_declare_property_long(error_exception_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_int(error_exception_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED TSRMLS_CC); } /* }}} */ @@ -819,7 +819,7 @@ ZEND_API zend_object *zend_throw_exception(zend_class_entry *exception_ce, const zend_update_property_string(default_exception_ce, &ex, "message", sizeof("message")-1, message TSRMLS_CC); } if (code) { - zend_update_property_long(default_exception_ce, &ex, "code", sizeof("code")-1, code TSRMLS_CC); + zend_update_property_int(default_exception_ce, &ex, "code", sizeof("code")-1, code TSRMLS_CC); } zend_throw_exception_internal(&ex TSRMLS_CC); @@ -847,7 +847,7 @@ ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce, zval ex; zend_object *obj = zend_throw_exception(exception_ce, message, code TSRMLS_CC); ZVAL_OBJ(&ex, obj); - zend_update_property_long(default_exception_ce, &ex, "severity", sizeof("severity")-1, severity TSRMLS_CC); + zend_update_property_int(default_exception_ce, &ex, "severity", sizeof("severity")-1, severity TSRMLS_CC); return obj; } /* }}} */ @@ -895,13 +895,13 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { line = zend_read_property(default_exception_ce, &zv, "line", sizeof("line")-1, 1 TSRMLS_CC); convert_to_string(file); - file = (Z_STRLEN_P(file) > 0) ? file : NULL; - line = (Z_TYPE_P(line) == IS_LONG) ? line : NULL; + file = (Z_STRSIZE_P(file) > 0) ? file : NULL; + line = (Z_TYPE_P(line) == IS_INT) ? line : NULL; } else { file = NULL; line = NULL; } - zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_LVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE(zv)->name->val, ce_exception->name->val); + zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_IVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE(zv)->name->val, ce_exception->name->val); } str = zend_read_property(default_exception_ce, &exception, "string", sizeof("string")-1, 1 TSRMLS_CC); @@ -910,9 +910,9 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { convert_to_string(str); convert_to_string(file); - convert_to_long(line); + convert_to_int(line); - zend_error_va(severity, (Z_STRLEN_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_LVAL_P(line), "Uncaught %s\n thrown", Z_STRVAL_P(str)); + zend_error_va(severity, (Z_STRSIZE_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_IVAL_P(line), "Uncaught %s\n thrown", Z_STRVAL_P(str)); } else { zend_error(severity, "Uncaught exception '%s'", ce_exception->name->val); } -- cgit v1.2.1 From 5bb25776a00e1074d1230a311043b00f7cce9252 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 16 Aug 2014 15:34:04 +0200 Subject: further fixes on core --- Zend/zend_exceptions.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 401a85f870..9fda5d4289 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -459,7 +459,7 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ TRACE_APPEND_STR("true, "); break; case IS_RESOURCE: { - long lval = Z_RES_HANDLE_P(arg); + zend_int_t lval = Z_RES_HANDLE_P(arg); char s_tmp[MAX_LENGTH_OF_ZEND_INT + 1]; int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */ TRACE_APPEND_STR("Resource id #"); @@ -468,7 +468,7 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ break; } case IS_INT: { - long lval = Z_IVAL_P(arg); + zend_int_t lval = Z_IVAL_P(arg); char s_tmp[MAX_LENGTH_OF_ZEND_INT + 1]; int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */ TRACE_APPEND_STRL(s_tmp, l_tmp); @@ -509,7 +509,7 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ } /* }}} */ -static void _build_trace_string(zval *frame, ulong index, zend_string **str_ptr, int *num TSRMLS_DC) /* {{{ */ +static void _build_trace_string(zval *frame, zend_uint_t index, zend_string **str_ptr, int *num TSRMLS_DC) /* {{{ */ { char *s_tmp; int len; @@ -584,7 +584,7 @@ static void _build_trace_string(zval *frame, ulong index, zend_string **str_ptr, ZEND_METHOD(exception, getTraceAsString) { zval *trace, *frame; - ulong index; + zend_uint_t index; zend_string *str, *key; int num = 0, len; char s_tmp[MAX_LENGTH_OF_ZEND_INT + 7 + 1 + 1]; -- cgit v1.2.1 From 16b4d90fa99ef656557d1cb83609dda542f36637 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 21 Aug 2014 14:30:52 +0400 Subject: Separate values before conversion --- Zend/zend_exceptions.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 754927b577..e632ce42d5 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -665,9 +665,9 @@ ZEND_METHOD(exception, __toString) _default_exception_get_entry(exception, "file", sizeof("file")-1, &file TSRMLS_CC); _default_exception_get_entry(exception, "line", sizeof("line")-1, &line TSRMLS_CC); - convert_to_string(&message); - convert_to_string(&file); - convert_to_long(&line); + convert_to_string_ex(&message); + convert_to_string_ex(&file); + convert_to_long_ex(&line); fci.size = sizeof(fci); fci.function_table = &Z_OBJCE_P(exception)->function_table; @@ -894,7 +894,7 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { file = zend_read_property(default_exception_ce, &zv, "file", sizeof("file")-1, 1 TSRMLS_CC); line = zend_read_property(default_exception_ce, &zv, "line", sizeof("line")-1, 1 TSRMLS_CC); - convert_to_string(file); + convert_to_string_ex(file); file = (Z_STRLEN_P(file) > 0) ? file : NULL; line = (Z_TYPE_P(line) == IS_LONG) ? line : NULL; } else { @@ -908,9 +908,9 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { file = zend_read_property(default_exception_ce, &exception, "file", sizeof("file")-1, 1 TSRMLS_CC); line = zend_read_property(default_exception_ce, &exception, "line", sizeof("line")-1, 1 TSRMLS_CC); - convert_to_string(str); - convert_to_string(file); - convert_to_long(line); + convert_to_string_ex(str); + convert_to_string_ex(file); + convert_to_long_ex(line); zend_error_va(severity, (Z_STRLEN_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_LVAL_P(line), "Uncaught %s\n thrown", Z_STRVAL_P(str)); } else { -- cgit v1.2.1 From 70de6180d5a022806212d2b6eebbba48af827940 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sun, 24 Aug 2014 02:35:34 +0200 Subject: fixes to %pd format usage --- Zend/zend_exceptions.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 6d5aa720fa..766cf7e210 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -461,7 +461,7 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ case IS_RESOURCE: { zend_int_t lval = Z_RES_HANDLE_P(arg); char s_tmp[MAX_LENGTH_OF_ZEND_INT + 1]; - int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */ + int l_tmp = zend_sprintf(s_tmp, ZEND_INT_FMT, lval); /* SAFE */ TRACE_APPEND_STR("Resource id #"); TRACE_APPEND_STRL(s_tmp, l_tmp); TRACE_APPEND_STR(", "); @@ -470,7 +470,7 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ case IS_INT: { zend_int_t lval = Z_IVAL_P(arg); char s_tmp[MAX_LENGTH_OF_ZEND_INT + 1]; - int l_tmp = zend_sprintf(s_tmp, "%ld", lval); /* SAFE */ + int l_tmp = zend_sprintf(s_tmp, ZEND_INT_FMT, lval); /* SAFE */ TRACE_APPEND_STRL(s_tmp, l_tmp); TRACE_APPEND_STR(", "); break; @@ -519,7 +519,7 @@ static void _build_trace_string(zval *frame, zend_uint_t index, zend_string **st zend_string *str = *str_ptr; if (Z_TYPE_P(frame) != IS_ARRAY) { - zend_error(E_WARNING, "Expected array for frame %lu", index); + zend_error(E_WARNING, "Expected array for frame %pu", index); return; } -- cgit v1.2.1 From c3e3c98ec666812daaaca896cf5ef758a8a6df14 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 19:24:55 +0200 Subject: master renames phase 1 --- Zend/zend_exceptions.c | 80 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 766cf7e210..efc5efae9f 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -163,7 +163,7 @@ static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type, Z_SET_REFCOUNT(trace, 0); zend_update_property_string(default_exception_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); - zend_update_property_int(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); + zend_update_property_long(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); zend_update_property(default_exception_ce, &obj, "trace", sizeof("trace")-1, &trace TSRMLS_CC); return object; @@ -196,7 +196,7 @@ ZEND_METHOD(exception, __clone) ZEND_METHOD(exception, __construct) { zend_string *message = NULL; - long code = 0; + zend_long code = 0; zval *object, *previous = NULL; int argc = ZEND_NUM_ARGS(); @@ -211,7 +211,7 @@ ZEND_METHOD(exception, __construct) } if (code) { - zend_update_property_int(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC); + zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC); } if (previous) { @@ -225,7 +225,7 @@ ZEND_METHOD(exception, __construct) ZEND_METHOD(error_exception, __construct) { char *message = NULL, *filename = NULL; - long code = 0, severity = E_ERROR, lineno; + zend_long code = 0, severity = E_ERROR, lineno; zval *object, *previous = NULL; int argc = ZEND_NUM_ARGS(), message_len, filename_len; @@ -240,21 +240,21 @@ ZEND_METHOD(error_exception, __construct) } if (code) { - zend_update_property_int(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC); + zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC); } if (previous) { zend_update_property(default_exception_ce, object, "previous", sizeof("previous")-1, previous TSRMLS_CC); } - zend_update_property_int(default_exception_ce, object, "severity", sizeof("severity")-1, severity TSRMLS_CC); + zend_update_property_long(default_exception_ce, object, "severity", sizeof("severity")-1, severity TSRMLS_CC); if (argc >= 4) { zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, filename TSRMLS_CC); if (argc < 5) { lineno = 0; /* invalidate lineno */ } - zend_update_property_int(default_exception_ce, object, "line", sizeof("line")-1, lineno TSRMLS_CC); + zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, lineno TSRMLS_CC); } } /* }}} */ @@ -335,12 +335,12 @@ ZEND_METHOD(error_exception, getSeverity) /* {{{ gettraceasstring() macros */ #define TRACE_APPEND_CHR(chr) \ - str = STR_REALLOC(str, str->len + 1, 0); \ + str = zend_string_realloc(str, str->len + 1, 0); \ str->val[str->len - 1] = chr #define TRACE_APPEND_STRL(v, l) \ { \ - str = STR_REALLOC(str, str->len + (l), 0); \ + str = zend_string_realloc(str, str->len + (l), 0); \ memcpy(str->val + str->len - (l), (v), (l)); \ } @@ -354,7 +354,7 @@ ZEND_METHOD(error_exception, getSeverity) zend_error(E_WARNING, "Value for %s is no string", key); \ TRACE_APPEND_STR("[unknown]"); \ } else { \ - TRACE_APPEND_STRL(Z_STRVAL_P(tmp), Z_STRSIZE_P(tmp)); \ + TRACE_APPEND_STRL(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ } \ } \ } while (0) @@ -362,7 +362,7 @@ ZEND_METHOD(error_exception, getSeverity) #define TRACE_ARG_APPEND(vallen) do { \ int len = str->len; \ - str = STR_REALLOC(str, len + vallen, 0); \ + str = zend_string_realloc(str, len + vallen, 0); \ memmove(str->val + len - l_added + 1 + vallen, str->val + len - l_added + 1, l_added); \ } while (0) @@ -386,12 +386,12 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ case IS_STRING: { int l_added; TRACE_APPEND_CHR('\''); - if (Z_STRSIZE_P(arg) > 15) { + if (Z_STRLEN_P(arg) > 15) { TRACE_APPEND_STRL(Z_STRVAL_P(arg), 15); TRACE_APPEND_STR("...', "); l_added = 15 + 6 + 1; /* +1 because of while (--l_added) */ } else { - l_added = Z_STRSIZE_P(arg); + l_added = Z_STRLEN_P(arg); TRACE_APPEND_STRL(Z_STRVAL_P(arg), l_added); TRACE_APPEND_STR("', "); l_added += 3 + 1; @@ -459,17 +459,17 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ TRACE_APPEND_STR("true, "); break; case IS_RESOURCE: { - zend_int_t lval = Z_RES_HANDLE_P(arg); - char s_tmp[MAX_LENGTH_OF_ZEND_INT + 1]; + zend_long lval = Z_RES_HANDLE_P(arg); + char s_tmp[MAX_LENGTH_OF_LONG + 1]; int l_tmp = zend_sprintf(s_tmp, ZEND_INT_FMT, lval); /* SAFE */ TRACE_APPEND_STR("Resource id #"); TRACE_APPEND_STRL(s_tmp, l_tmp); TRACE_APPEND_STR(", "); break; } - case IS_INT: { - zend_int_t lval = Z_IVAL_P(arg); - char s_tmp[MAX_LENGTH_OF_ZEND_INT + 1]; + case IS_LONG: { + zend_long lval = Z_LVAL_P(arg); + char s_tmp[MAX_LENGTH_OF_LONG + 1]; int l_tmp = zend_sprintf(s_tmp, ZEND_INT_FMT, lval); /* SAFE */ TRACE_APPEND_STRL(s_tmp, l_tmp); TRACE_APPEND_STR(", "); @@ -509,7 +509,7 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ } /* }}} */ -static void _build_trace_string(zval *frame, zend_uint_t index, zend_string **str_ptr, int *num TSRMLS_DC) /* {{{ */ +static void _build_trace_string(zval *frame, zend_ulong index, zend_string **str_ptr, int *num TSRMLS_DC) /* {{{ */ { char *s_tmp; int len; @@ -524,7 +524,7 @@ static void _build_trace_string(zval *frame, zend_uint_t index, zend_string **st } ht = Z_ARRVAL_P(frame); - s_tmp = emalloc(1 + MAX_LENGTH_OF_ZEND_INT + 1 + 1); + s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1); len = sprintf(s_tmp, "#%d ", (*num)++); TRACE_APPEND_STRL(s_tmp, len); efree(s_tmp); @@ -536,8 +536,8 @@ static void _build_trace_string(zval *frame, zend_uint_t index, zend_string **st } else{ tmp = zend_hash_str_find(ht, "line", sizeof("line")-1); if (tmp) { - if (Z_TYPE_P(tmp) == IS_INT) { - line = Z_IVAL_P(tmp); + if (Z_TYPE_P(tmp) == IS_LONG) { + line = Z_LVAL_P(tmp); } else { zend_error(E_WARNING, "Line is no long"); line = 0; @@ -545,7 +545,7 @@ static void _build_trace_string(zval *frame, zend_uint_t index, zend_string **st } else { line = 0; } - s_tmp = emalloc(Z_STRSIZE_P(file) + MAX_LENGTH_OF_ZEND_INT + 4 + 1); + s_tmp = emalloc(Z_STRLEN_P(file) + MAX_LENGTH_OF_LONG + 4 + 1); len = sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_P(file), line); TRACE_APPEND_STRL(s_tmp, len); efree(s_tmp); @@ -584,14 +584,14 @@ static void _build_trace_string(zval *frame, zend_uint_t index, zend_string **st ZEND_METHOD(exception, getTraceAsString) { zval *trace, *frame; - zend_uint_t index; + zend_ulong index; zend_string *str, *key; int num = 0, len; - char s_tmp[MAX_LENGTH_OF_ZEND_INT + 7 + 1 + 1]; + char s_tmp[MAX_LENGTH_OF_LONG + 7 + 1 + 1]; DEFAULT_0_PARAMS; - str = STR_ALLOC(0, 0); + str = zend_string_alloc(0, 0); trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC); ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(trace), index, key, frame) { @@ -686,18 +686,18 @@ ZEND_METHOD(exception, __toString) ZVAL_UNDEF(&trace); } - if (Z_STRSIZE(message) > 0) { + if (Z_STRLEN(message) > 0) { str = zend_strpprintf(0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_IVAL(line), - (Z_TYPE(trace) == IS_STRING && Z_STRSIZE(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", + Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line), + (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", prev_str->len ? "\n\nNext " : "", prev_str->val); } else { str = zend_strpprintf(0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_IVAL(line), - (Z_TYPE(trace) == IS_STRING && Z_STRSIZE(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", + Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_LVAL(line), + (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", prev_str->len ? "\n\nNext " : "", prev_str->val); } - STR_RELEASE(prev_str); + zend_string_release(prev_str); zval_dtor(&message); zval_dtor(&file); zval_dtor(&line); @@ -775,7 +775,7 @@ void zend_register_default_exception(TSRMLS_D) /* {{{ */ zend_declare_property_string(default_exception_ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_string(default_exception_ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC); - zend_declare_property_int(default_exception_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(default_exception_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(default_exception_ce, "file", sizeof("file")-1, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(default_exception_ce, "line", sizeof("line")-1, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(default_exception_ce, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE TSRMLS_CC); @@ -784,7 +784,7 @@ void zend_register_default_exception(TSRMLS_D) /* {{{ */ INIT_CLASS_ENTRY(ce, "ErrorException", error_exception_functions); error_exception_ce = zend_register_internal_class_ex(&ce, default_exception_ce TSRMLS_CC); error_exception_ce->create_object = zend_error_exception_new; - zend_declare_property_int(error_exception_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(error_exception_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED TSRMLS_CC); } /* }}} */ @@ -819,7 +819,7 @@ ZEND_API zend_object *zend_throw_exception(zend_class_entry *exception_ce, const zend_update_property_string(default_exception_ce, &ex, "message", sizeof("message")-1, message TSRMLS_CC); } if (code) { - zend_update_property_int(default_exception_ce, &ex, "code", sizeof("code")-1, code TSRMLS_CC); + zend_update_property_long(default_exception_ce, &ex, "code", sizeof("code")-1, code TSRMLS_CC); } zend_throw_exception_internal(&ex TSRMLS_CC); @@ -847,7 +847,7 @@ ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce, zval ex; zend_object *obj = zend_throw_exception(exception_ce, message, code TSRMLS_CC); ZVAL_OBJ(&ex, obj); - zend_update_property_int(default_exception_ce, &ex, "severity", sizeof("severity")-1, severity TSRMLS_CC); + zend_update_property_long(default_exception_ce, &ex, "severity", sizeof("severity")-1, severity TSRMLS_CC); return obj; } /* }}} */ @@ -895,13 +895,13 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { line = zend_read_property(default_exception_ce, &zv, "line", sizeof("line")-1, 1 TSRMLS_CC); convert_to_string_ex(file); - file = (Z_STRSIZE_P(file) > 0) ? file : NULL; - line = (Z_TYPE_P(line) == IS_INT) ? line : NULL; + file = (Z_STRLEN_P(file) > 0) ? file : NULL; + line = (Z_TYPE_P(line) == IS_LONG) ? line : NULL; } else { file = NULL; line = NULL; } - zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_IVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE(zv)->name->val, ce_exception->name->val); + zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_LVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE(zv)->name->val, ce_exception->name->val); } str = zend_read_property(default_exception_ce, &exception, "string", sizeof("string")-1, 1 TSRMLS_CC); @@ -912,7 +912,7 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { convert_to_string_ex(file); convert_to_int_ex(line); - zend_error_va(severity, (Z_STRSIZE_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_IVAL_P(line), "Uncaught %s\n thrown", Z_STRVAL_P(str)); + zend_error_va(severity, (Z_STRLEN_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_LVAL_P(line), "Uncaught %s\n thrown", Z_STRVAL_P(str)); } else { zend_error(severity, "Uncaught exception '%s'", ce_exception->name->val); } -- cgit v1.2.1 From 4d997f63d98c663b2d9acccd3655572652f61c7d Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 20:22:49 +0200 Subject: master renames phase 3 --- Zend/zend_exceptions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index efc5efae9f..ff408d0bfd 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -461,7 +461,7 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ case IS_RESOURCE: { zend_long lval = Z_RES_HANDLE_P(arg); char s_tmp[MAX_LENGTH_OF_LONG + 1]; - int l_tmp = zend_sprintf(s_tmp, ZEND_INT_FMT, lval); /* SAFE */ + int l_tmp = zend_sprintf(s_tmp, ZEND_LONG_FMT, lval); /* SAFE */ TRACE_APPEND_STR("Resource id #"); TRACE_APPEND_STRL(s_tmp, l_tmp); TRACE_APPEND_STR(", "); @@ -470,7 +470,7 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ case IS_LONG: { zend_long lval = Z_LVAL_P(arg); char s_tmp[MAX_LENGTH_OF_LONG + 1]; - int l_tmp = zend_sprintf(s_tmp, ZEND_INT_FMT, lval); /* SAFE */ + int l_tmp = zend_sprintf(s_tmp, ZEND_LONG_FMT, lval); /* SAFE */ TRACE_APPEND_STRL(s_tmp, l_tmp); TRACE_APPEND_STR(", "); break; -- cgit v1.2.1 From af59e92b24c8f624672720d47ef65bd8457728b9 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 25 Aug 2014 21:51:49 +0200 Subject: master renames phase 7 --- Zend/zend_exceptions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index ff408d0bfd..bec30cd006 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -667,7 +667,7 @@ ZEND_METHOD(exception, __toString) convert_to_string_ex(&message); convert_to_string_ex(&file); - convert_to_int_ex(&line); + convert_to_long_ex(&line); fci.size = sizeof(fci); fci.function_table = &Z_OBJCE_P(exception)->function_table; @@ -910,7 +910,7 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { convert_to_string_ex(str); convert_to_string_ex(file); - convert_to_int_ex(line); + convert_to_long_ex(line); zend_error_va(severity, (Z_STRLEN_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_LVAL_P(line), "Uncaught %s\n thrown", Z_STRVAL_P(str)); } else { -- cgit v1.2.1 From d2a3bf9daf41471c93327d5aaafbef8a7dde9053 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 25 Aug 2014 23:05:05 +0200 Subject: Fix compiler warnings --- Zend/zend_exceptions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index bec30cd006..d8e183edf5 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -585,7 +585,7 @@ ZEND_METHOD(exception, getTraceAsString) { zval *trace, *frame; zend_ulong index; - zend_string *str, *key; + zend_string *str; int num = 0, len; char s_tmp[MAX_LENGTH_OF_LONG + 7 + 1 + 1]; @@ -594,7 +594,7 @@ ZEND_METHOD(exception, getTraceAsString) str = zend_string_alloc(0, 0); trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(trace), index, key, frame) { + ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(trace), index, frame) { _build_trace_string(frame, index, &str, &num TSRMLS_CC); } ZEND_HASH_FOREACH_END(); -- cgit v1.2.1 From b63ab83256868db44eecedde319a4c2a27a5a10f Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 26 Aug 2014 13:20:21 +0200 Subject: several signature and data type fixes --- Zend/zend_exceptions.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index d8e183edf5..c246b18726 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -513,7 +513,7 @@ static void _build_trace_string(zval *frame, zend_ulong index, zend_string **str { char *s_tmp; int len; - long line; + zend_long line; HashTable *ht; zval *file, *tmp; zend_string *str = *str_ptr; @@ -800,7 +800,7 @@ ZEND_API zend_class_entry *zend_get_error_exception(TSRMLS_D) /* {{{ */ } /* }}} */ -ZEND_API zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, long code TSRMLS_DC) /* {{{ */ +ZEND_API zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code TSRMLS_DC) /* {{{ */ { zval ex; @@ -827,7 +827,7 @@ ZEND_API zend_object *zend_throw_exception(zend_class_entry *exception_ce, const } /* }}} */ -ZEND_API zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, const char *format, ...) /* {{{ */ +ZEND_API zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code TSRMLS_DC, const char *format, ...) /* {{{ */ { va_list arg; char *message; @@ -842,7 +842,7 @@ ZEND_API zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, lo } /* }}} */ -ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce, const char *message, long code, int severity TSRMLS_DC) /* {{{ */ +ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce, const char *message, zend_long code, int severity TSRMLS_DC) /* {{{ */ { zval ex; zend_object *obj = zend_throw_exception(exception_ce, message, code TSRMLS_CC); -- cgit v1.2.1 From 3234480827b27ff5d3469a732167afd289632a96 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 27 Aug 2014 15:31:48 +0200 Subject: first show to make 's' work with size_t --- Zend/zend_exceptions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index c246b18726..50089bf1df 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -227,7 +227,8 @@ ZEND_METHOD(error_exception, __construct) char *message = NULL, *filename = NULL; zend_long code = 0, severity = E_ERROR, lineno; zval *object, *previous = NULL; - int argc = ZEND_NUM_ARGS(), message_len, filename_len; + int argc = ZEND_NUM_ARGS(); + size_t message_len, filename_len; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|sllslO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, default_exception_ce) == FAILURE) { zend_error(E_ERROR, "Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Exception $previous = NULL]]]]]])"); -- cgit v1.2.1 From 7f6d2b124b24b23d37280fb1511de9f5a27d3f1a Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 28 Aug 2014 15:41:03 +0200 Subject: fix format --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 50089bf1df..c5193ce7b6 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -547,7 +547,7 @@ static void _build_trace_string(zval *frame, zend_ulong index, zend_string **str line = 0; } s_tmp = emalloc(Z_STRLEN_P(file) + MAX_LENGTH_OF_LONG + 4 + 1); - len = sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_P(file), line); + len = sprintf(s_tmp, "%s(" ZEND_LONG_FMT "): ", Z_STRVAL_P(file), line); TRACE_APPEND_STRL(s_tmp, len); efree(s_tmp); } -- cgit v1.2.1 From babcad063f3042d5fb374b5013c5c742407c1bd2 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 19 Sep 2014 12:14:46 +0200 Subject: fix length data types --- Zend/zend_exceptions.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index c5193ce7b6..9a270c0c10 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -362,7 +362,7 @@ ZEND_METHOD(error_exception, getSeverity) #define TRACE_ARG_APPEND(vallen) do { \ - int len = str->len; \ + size_t len = str->len; \ str = zend_string_realloc(str, len + vallen, 0); \ memmove(str->val + len - l_added + 1 + vallen, str->val + len - l_added + 1, l_added); \ } while (0) @@ -620,10 +620,10 @@ ZEND_METHOD(exception, getPrevious) RETURN_ZVAL(previous, 1, 0); } /* }}} */ -int zend_spprintf(char **message, int max_len, const char *format, ...) /* {{{ */ +size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */ { va_list arg; - int len; + size_t len; va_start(arg, format); len = zend_vspprintf(message, max_len, format, arg); @@ -632,7 +632,7 @@ int zend_spprintf(char **message, int max_len, const char *format, ...) /* {{{ * } /* }}} */ -zend_string *zend_strpprintf(int max_len, const char *format, ...) /* {{{ */ +zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */ { va_list arg; zend_string *str; -- cgit v1.2.1 From e0df8cc8100f31534718e69cc41981e6c7490b20 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 21 Sep 2014 00:21:41 +0200 Subject: Use smart_str for exception stack traces --- Zend/zend_exceptions.c | 279 ++++++++++++++++++++----------------------------- 1 file changed, 113 insertions(+), 166 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 9a270c0c10..8d3145ca23 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -28,6 +28,7 @@ #include "zend_exceptions.h" #include "zend_vm.h" #include "zend_dtrace.h" +#include "zend_smart_str.h" static zend_class_entry *default_exception_ce; static zend_class_entry *error_exception_ce; @@ -334,45 +335,78 @@ ZEND_METHOD(error_exception, getSeverity) } /* }}} */ -/* {{{ gettraceasstring() macros */ -#define TRACE_APPEND_CHR(chr) \ - str = zend_string_realloc(str, str->len + 1, 0); \ - str->val[str->len - 1] = chr - -#define TRACE_APPEND_STRL(v, l) \ - { \ - str = zend_string_realloc(str, str->len + (l), 0); \ - memcpy(str->val + str->len - (l), (v), (l)); \ - } - -#define TRACE_APPEND_STR(v) \ - TRACE_APPEND_STRL((v), sizeof((v))-1) - #define TRACE_APPEND_KEY(key) do { \ tmp = zend_hash_str_find(ht, key, sizeof(key)-1); \ if (tmp) { \ if (Z_TYPE_P(tmp) != IS_STRING) { \ zend_error(E_WARNING, "Value for %s is no string", key); \ - TRACE_APPEND_STR("[unknown]"); \ + smart_str_appends(str, "[unknown]"); \ } else { \ - TRACE_APPEND_STRL(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ + smart_str_appendl(str, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ } \ } \ } while (0) +/* Windows uses VK_ESCAPE instead of \e */ +#ifndef VK_ESCAPE +#define VK_ESCAPE '\e' +#endif -#define TRACE_ARG_APPEND(vallen) do { \ - size_t len = str->len; \ - str = zend_string_realloc(str, len + vallen, 0); \ - memmove(str->val + len - l_added + 1 + vallen, str->val + len - l_added + 1, l_added); \ - } while (0) +static size_t compute_escaped_string_len(const char *s, size_t l) { + size_t i, len = l; + for (i = 0; i < l; ++i) { + char c = s[i]; + if (c == '\n' || c == '\r' || c == '\t' || + c == '\f' || c == '\v' || c == '\\' || c == VK_ESCAPE) { + len += 1; + } else if (c < 32 || c > 126) { + len += 3; + } + } + return len; +} -/* }}} */ +static void smart_str_append_escaped(smart_str *str, const char *s, size_t l) { + char *res; + size_t i, len = compute_escaped_string_len(s, l); + + smart_str_alloc(str, len, 0); + res = &str->s->val[str->s->len]; + str->s->len += len; + + for (i = 0; i < l; ++i) { + char c = s[i]; + if (c < 32 || c == '\\' || c > 126) { + *res++ = '\\'; + switch (c) { + case '\n': *res++ = 'n'; break; + case '\r': *res++ = 'r'; break; + case '\t': *res++ = 't'; break; + case '\f': *res++ = 'f'; break; + case '\v': *res++ = 'v'; break; + case '\\': *res++ = '\\'; break; + case VK_ESCAPE: *res++ = 'e'; break; + default: + *res++ = 'x'; + if ((c >> 4) < 10) { + *res++ = (c >> 4) + '0'; + } else { + *res++ = (c >> 4) + 'A' - 10; + } + if ((c & 0xf) < 10) { + *res++ = (c & 0xf) + '0'; + } else { + *res++ = (c & 0xf) + 'A' - 10; + } + } + } else { + *res++ = c; + } + } +} -static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ */ +static void _build_trace_args(zval *arg, smart_str *str TSRMLS_DC) /* {{{ */ { - zend_string *str = *str_ptr; - /* the trivial way would be to do: * convert_to_string_ex(arg); * append it and kill the now tmp arg. @@ -382,159 +416,71 @@ static void _build_trace_args(zval *arg, zend_string **str_ptr TSRMLS_DC) /* {{{ ZVAL_DEREF(arg); switch (Z_TYPE_P(arg)) { case IS_NULL: - TRACE_APPEND_STR("NULL, "); + smart_str_appends(str, "NULL, "); break; - case IS_STRING: { - int l_added; - TRACE_APPEND_CHR('\''); + case IS_STRING: + smart_str_appendc(str, '\''); + smart_str_append_escaped(str, Z_STRVAL_P(arg), MIN(Z_STRLEN_P(arg), 15)); if (Z_STRLEN_P(arg) > 15) { - TRACE_APPEND_STRL(Z_STRVAL_P(arg), 15); - TRACE_APPEND_STR("...', "); - l_added = 15 + 6 + 1; /* +1 because of while (--l_added) */ + smart_str_appends(str, "...', "); } else { - l_added = Z_STRLEN_P(arg); - TRACE_APPEND_STRL(Z_STRVAL_P(arg), l_added); - TRACE_APPEND_STR("', "); - l_added += 3 + 1; - } - while (--l_added) { - unsigned char chr = str->val[str->len - l_added]; - if (chr < 32 || chr == '\\' || chr > 126) { - str->val[str->len - l_added] = '\\'; - - switch (chr) { - case '\n': - TRACE_ARG_APPEND(1); - str->val[str->len - l_added] = 'n'; - break; - case '\r': - TRACE_ARG_APPEND(1); - str->val[str->len - l_added] = 'r'; - break; - case '\t': - TRACE_ARG_APPEND(1); - str->val[str->len - l_added] = 't'; - break; - case '\f': - TRACE_ARG_APPEND(1); - str->val[str->len - l_added] = 'f'; - break; - case '\v': - TRACE_ARG_APPEND(1); - str->val[str->len - l_added] = 'v'; - break; -#ifndef PHP_WIN32 - case '\e': -#else - case VK_ESCAPE: -#endif - TRACE_ARG_APPEND(1); - str->val[str->len - l_added] = 'e'; - break; - case '\\': - TRACE_ARG_APPEND(1); - str->val[str->len - l_added] = '\\'; - break; - default: - TRACE_ARG_APPEND(3); - str->val[str->len - l_added - 2] = 'x'; - if ((chr >> 4) < 10) { - str->val[str->len - l_added - 1] = (chr >> 4) + '0'; - } else { - str->val[str->len - l_added - 1] = (chr >> 4) + 'A' - 10; - } - if (chr % 16 < 10) { - str->val[str->len - l_added] = chr % 16 + '0'; - } else { - str->val[str->len - l_added] = chr % 16 + 'A' - 10; - } - } - } + smart_str_appends(str, "', "); } break; - } case IS_FALSE: - TRACE_APPEND_STR("false, "); + smart_str_appends(str, "false, "); break; case IS_TRUE: - TRACE_APPEND_STR("true, "); + smart_str_appends(str, "true, "); break; - case IS_RESOURCE: { - zend_long lval = Z_RES_HANDLE_P(arg); - char s_tmp[MAX_LENGTH_OF_LONG + 1]; - int l_tmp = zend_sprintf(s_tmp, ZEND_LONG_FMT, lval); /* SAFE */ - TRACE_APPEND_STR("Resource id #"); - TRACE_APPEND_STRL(s_tmp, l_tmp); - TRACE_APPEND_STR(", "); + case IS_RESOURCE: + smart_str_appends(str, "Resource id #"); + smart_str_append_long(str, Z_RES_HANDLE_P(arg)); + smart_str_appends(str, ", "); break; - } - case IS_LONG: { - zend_long lval = Z_LVAL_P(arg); - char s_tmp[MAX_LENGTH_OF_LONG + 1]; - int l_tmp = zend_sprintf(s_tmp, ZEND_LONG_FMT, lval); /* SAFE */ - TRACE_APPEND_STRL(s_tmp, l_tmp); - TRACE_APPEND_STR(", "); + case IS_LONG: + smart_str_append_long(str, Z_LVAL_P(arg)); + smart_str_appends(str, ", "); break; - } case IS_DOUBLE: { double dval = Z_DVAL_P(arg); - char *s_tmp; - int l_tmp; - - s_tmp = emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1); - l_tmp = zend_sprintf(s_tmp, "%.*G", (int) EG(precision), dval); /* SAFE */ - TRACE_APPEND_STRL(s_tmp, l_tmp); - /* %G already handles removing trailing zeros from the fractional part, yay */ + char *s_tmp = emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1); + int l_tmp = zend_sprintf(s_tmp, "%.*G", (int) EG(precision), dval); /* SAFE */ + smart_str_appendl(str, s_tmp, l_tmp); + smart_str_appends(str, ", "); efree(s_tmp); - TRACE_APPEND_STR(", "); break; } case IS_ARRAY: - TRACE_APPEND_STR("Array, "); + smart_str_appends(str, "Array, "); break; case IS_OBJECT: { - zend_string *class_name; - - TRACE_APPEND_STR("Object("); - - class_name = zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC); + zend_string *class_name = zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC); - TRACE_APPEND_STRL(class_name->val, class_name->len); - TRACE_APPEND_STR("), "); + smart_str_appends(str, "Object("); + smart_str_appendl(str, class_name->val, class_name->len); + smart_str_appends(str, "), "); break; } - default: - break; } - *str_ptr = str; } /* }}} */ -static void _build_trace_string(zval *frame, zend_ulong index, zend_string **str_ptr, int *num TSRMLS_DC) /* {{{ */ +static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num TSRMLS_DC) /* {{{ */ { - char *s_tmp; - int len; - zend_long line; - HashTable *ht; zval *file, *tmp; - zend_string *str = *str_ptr; - if (Z_TYPE_P(frame) != IS_ARRAY) { - zend_error(E_WARNING, "Expected array for frame %pu", index); - return; - } + smart_str_appendc(str, '#'); + smart_str_append_long(str, num); + smart_str_appendc(str, ' '); - ht = Z_ARRVAL_P(frame); - s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1); - len = sprintf(s_tmp, "#%d ", (*num)++); - TRACE_APPEND_STRL(s_tmp, len); - efree(s_tmp); file = zend_hash_str_find(ht, "file", sizeof("file")-1); if (file) { if (Z_TYPE_P(file) != IS_STRING) { zend_error(E_WARNING, "Function name is no string"); - TRACE_APPEND_STR("[unknown function]"); + smart_str_appends(str, "[unknown function]"); } else{ + zend_long line; tmp = zend_hash_str_find(ht, "line", sizeof("line")-1); if (tmp) { if (Z_TYPE_P(tmp) == IS_LONG) { @@ -546,37 +492,36 @@ static void _build_trace_string(zval *frame, zend_ulong index, zend_string **str } else { line = 0; } - s_tmp = emalloc(Z_STRLEN_P(file) + MAX_LENGTH_OF_LONG + 4 + 1); - len = sprintf(s_tmp, "%s(" ZEND_LONG_FMT "): ", Z_STRVAL_P(file), line); - TRACE_APPEND_STRL(s_tmp, len); - efree(s_tmp); + smart_str_appendl(str, Z_STRVAL_P(file), Z_STRLEN_P(file)); + smart_str_appendc(str, '('); + smart_str_append_long(str, line); + smart_str_appends(str, "): "); } } else { - TRACE_APPEND_STR("[internal function]: "); + smart_str_appends(str, "[internal function]: "); } TRACE_APPEND_KEY("class"); TRACE_APPEND_KEY("type"); TRACE_APPEND_KEY("function"); - TRACE_APPEND_CHR('('); + smart_str_appendc(str, '('); tmp = zend_hash_str_find(ht, "args", sizeof("args")-1); if (tmp) { if (Z_TYPE_P(tmp) == IS_ARRAY) { - int last_len = str->len; + size_t last_len = str->s->len; zval *arg; ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmp), arg) { - _build_trace_args(arg, &str TSRMLS_CC); + _build_trace_args(arg, str TSRMLS_CC); } ZEND_HASH_FOREACH_END(); - if (last_len != str->len) { - str->len -= 2; /* remove last ', ' */ + if (last_len != str->s->len) { + str->s->len -= 2; /* remove last ', ' */ } } else { zend_error(E_WARNING, "args element is no array"); } } - TRACE_APPEND_STR(")\n"); - *str_ptr = str; + smart_str_appends(str, ")\n"); } /* }}} */ @@ -586,25 +531,27 @@ ZEND_METHOD(exception, getTraceAsString) { zval *trace, *frame; zend_ulong index; - zend_string *str; - int num = 0, len; - char s_tmp[MAX_LENGTH_OF_LONG + 7 + 1 + 1]; + smart_str str = {0}; + uint32_t num = 0; DEFAULT_0_PARAMS; - str = zend_string_alloc(0, 0); - trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC); ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(trace), index, frame) { - _build_trace_string(frame, index, &str, &num TSRMLS_CC); - } ZEND_HASH_FOREACH_END(); + if (Z_TYPE_P(frame) != IS_ARRAY) { + zend_error(E_WARNING, "Expected array for frame %pu", index); + continue; + } - len = sprintf(s_tmp, "#%d {main}", num); - TRACE_APPEND_STRL(s_tmp, len); + _build_trace_string(&str, Z_ARRVAL_P(frame), num++ TSRMLS_CC); + } ZEND_HASH_FOREACH_END(); - str->val[str->len] = '\0'; + smart_str_appendc(&str, '#'); + smart_str_append_long(&str, num); + smart_str_appends(&str, " {main}"); + smart_str_0(&str); - RETURN_NEW_STR(str); + RETURN_NEW_STR(str.s); } /* }}} */ -- cgit v1.2.1 From a770d29df74515197c76efdf1a64d9794c27b4af Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 21 Sep 2014 20:47:07 +0200 Subject: Add smart_str_append for appending zend_strings Also replaces usages in Zend/ and ext/standard --- Zend/zend_exceptions.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 8d3145ca23..999b6d790e 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -342,7 +342,7 @@ ZEND_METHOD(error_exception, getSeverity) zend_error(E_WARNING, "Value for %s is no string", key); \ smart_str_appends(str, "[unknown]"); \ } else { \ - smart_str_appendl(str, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp)); \ + smart_str_append(str, Z_STR_P(tmp)); \ } \ } \ } while (0) @@ -454,14 +454,11 @@ static void _build_trace_args(zval *arg, smart_str *str TSRMLS_DC) /* {{{ */ case IS_ARRAY: smart_str_appends(str, "Array, "); break; - case IS_OBJECT: { - zend_string *class_name = zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC); - + case IS_OBJECT: smart_str_appends(str, "Object("); - smart_str_appendl(str, class_name->val, class_name->len); + smart_str_append(str, zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC)); smart_str_appends(str, "), "); break; - } } } /* }}} */ @@ -492,7 +489,7 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num TSRM } else { line = 0; } - smart_str_appendl(str, Z_STRVAL_P(file), Z_STRLEN_P(file)); + smart_str_append(str, Z_STR_P(file)); smart_str_appendc(str, '('); smart_str_append_long(str, line); smart_str_appends(str, "): "); -- cgit v1.2.1 From c4419e7a5bcbe30f568b17164ae30799aaaa5aba Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 1 Oct 2014 16:37:21 +0400 Subject: Expose zend_throw_exception_internal() --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 999b6d790e..b3770526db 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -85,7 +85,7 @@ void zend_exception_restore(TSRMLS_D) /* {{{ */ } /* }}} */ -void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ +ZEND_API void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ { #ifdef HAVE_DTRACE if (DTRACE_EXCEPTION_THROWN_ENABLED()) { -- cgit v1.2.1 From 2a0c4edfdaca8339eed8caa1cc1947c68225dbc3 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 6 Oct 2014 20:14:30 +0200 Subject: Drop convert_to usage in zend_exceptions To make everything work correctly with refs. I'm unsure whether the GET_PROPERTY_SILENT distinction is really necessary, because the choice seemed pretty random, but kept it around. --- Zend/zend_exceptions.c | 105 ++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 57 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index b3770526db..6e4ee2fd30 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -266,14 +266,10 @@ ZEND_METHOD(error_exception, __construct) return; \ } -static void _default_exception_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) /* {{{ */ -{ - zval *value; - - value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC); - ZVAL_COPY(return_value, value); -} -/* }}} */ +#define GET_PROPERTY(object, name) \ + zend_read_property(default_exception_ce, (object), name, sizeof(name) - 1, 0 TSRMLS_CC) +#define GET_PROPERTY_SILENT(object, name) \ + zend_read_property(default_exception_ce, (object), name, sizeof(name) - 1, 1 TSRMLS_CC) /* {{{ proto string Exception::getFile() Get the file in which the exception occurred */ @@ -281,7 +277,7 @@ ZEND_METHOD(exception, getFile) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "file", sizeof("file")-1, return_value TSRMLS_CC); + ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "file")); } /* }}} */ @@ -291,7 +287,7 @@ ZEND_METHOD(exception, getLine) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "line", sizeof("line")-1, return_value TSRMLS_CC); + ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "line")); } /* }}} */ @@ -301,7 +297,7 @@ ZEND_METHOD(exception, getMessage) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "message", sizeof("message")-1, return_value TSRMLS_CC); + ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "message")); } /* }}} */ @@ -311,7 +307,7 @@ ZEND_METHOD(exception, getCode) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "code", sizeof("code")-1, return_value TSRMLS_CC); + ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "code")); } /* }}} */ @@ -321,7 +317,7 @@ ZEND_METHOD(exception, getTrace) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "trace", sizeof("trace")-1, return_value TSRMLS_CC); + ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "trace")); } /* }}} */ @@ -331,7 +327,7 @@ ZEND_METHOD(error_exception, getSeverity) { DEFAULT_0_PARAMS; - _default_exception_get_entry(getThis(), "severity", sizeof("severity")-1, return_value TSRMLS_CC); + ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "severity")); } /* }}} */ @@ -407,7 +403,7 @@ static void smart_str_append_escaped(smart_str *str, const char *s, size_t l) { static void _build_trace_args(zval *arg, smart_str *str TSRMLS_DC) /* {{{ */ { - /* the trivial way would be to do: + /* the trivial way would be to do * convert_to_string_ex(arg); * append it and kill the now tmp arg. * but that could cause some E_NOTICE and also damn long lines. @@ -556,12 +552,9 @@ ZEND_METHOD(exception, getTraceAsString) Return previous Exception or NULL. */ ZEND_METHOD(exception, getPrevious) { - zval *previous; - DEFAULT_0_PARAMS; - previous = zend_read_property(default_exception_ce, getThis(), "previous", sizeof("previous")-1, 1 TSRMLS_CC); - RETURN_ZVAL(previous, 1, 0); + ZVAL_COPY(return_value, GET_PROPERTY_SILENT(getThis(), "previous")); } /* }}} */ size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */ @@ -592,8 +585,8 @@ zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */ Obtain the string representation of the Exception object */ ZEND_METHOD(exception, __toString) { - zval message, file, line, trace, *exception; - zend_string *str, *prev_str; + zval trace, *exception; + zend_string *str; zend_fcall_info fci; zval fname; @@ -605,14 +598,10 @@ ZEND_METHOD(exception, __toString) ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1); while (exception && Z_TYPE_P(exception) == IS_OBJECT) { - prev_str = str; - _default_exception_get_entry(exception, "message", sizeof("message")-1, &message TSRMLS_CC); - _default_exception_get_entry(exception, "file", sizeof("file")-1, &file TSRMLS_CC); - _default_exception_get_entry(exception, "line", sizeof("line")-1, &line TSRMLS_CC); - - convert_to_string_ex(&message); - convert_to_string_ex(&file); - convert_to_long_ex(&line); + zend_string *prev_str = str; + zend_string *message = zval_get_string(GET_PROPERTY(exception, "message")); + zend_string *file = zval_get_string(GET_PROPERTY(exception, "file")); + zend_long line = zval_get_long(GET_PROPERTY(exception, "line")); fci.size = sizeof(fci); fci.function_table = &Z_OBJCE_P(exception)->function_table; @@ -631,26 +620,26 @@ ZEND_METHOD(exception, __toString) ZVAL_UNDEF(&trace); } - if (Z_STRLEN(message) > 0) { - str = zend_strpprintf(0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name->val, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line), + if (message->len > 0) { + str = zend_strpprintf(0, "exception '%s' with message '%s' in %s:" ZEND_LONG_FMT + "\nStack trace:\n%s%s%s", + Z_OBJCE_P(exception)->name->val, message->val, file->val, line, (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", prev_str->len ? "\n\nNext " : "", prev_str->val); } else { - str = zend_strpprintf(0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s", - Z_OBJCE_P(exception)->name->val, Z_STRVAL(file), Z_LVAL(line), + str = zend_strpprintf(0, "exception '%s' in %s:" ZEND_LONG_FMT + "\nStack trace:\n%s%s%s", + Z_OBJCE_P(exception)->name->val, file->val, line, (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n", prev_str->len ? "\n\nNext " : "", prev_str->val); } - zend_string_release(prev_str); - zval_dtor(&message); - zval_dtor(&file); - zval_dtor(&line); - - exception = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 0 TSRMLS_CC); + zend_string_release(prev_str); + zend_string_release(message); + zend_string_release(file); zval_ptr_dtor(&trace); + exception = GET_PROPERTY(exception, "previous"); } zval_dtor(&fname); @@ -816,7 +805,9 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { ZVAL_OBJ(&exception, ex); ce_exception = Z_OBJCE(exception); if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) { - zval tmp, *str, *file, *line; + zval tmp; + zend_string *str, *file = NULL; + zend_long line = 0; EG(exception) = NULL; @@ -836,28 +827,28 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity TSRMLS_DC) /* { ZVAL_OBJ(&zv, EG(exception)); /* do the best we can to inform about the inner exception */ if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) { - file = zend_read_property(default_exception_ce, &zv, "file", sizeof("file")-1, 1 TSRMLS_CC); - line = zend_read_property(default_exception_ce, &zv, "line", sizeof("line")-1, 1 TSRMLS_CC); + file = zval_get_string(GET_PROPERTY_SILENT(&zv, "file")); + line = zval_get_long(GET_PROPERTY_SILENT(&zv, "line")); + } - convert_to_string_ex(file); - file = (Z_STRLEN_P(file) > 0) ? file : NULL; - line = (Z_TYPE_P(line) == IS_LONG) ? line : NULL; - } else { - file = NULL; - line = NULL; + zend_error_va(E_WARNING, (file && file->len > 0) ? file->val : NULL, line, + "Uncaught %s in exception handling during call to %s::__tostring()", + Z_OBJCE(zv)->name->val, ce_exception->name->val); + + if (file) { + zend_string_release(file); } - zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_LVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE(zv)->name->val, ce_exception->name->val); } - str = zend_read_property(default_exception_ce, &exception, "string", sizeof("string")-1, 1 TSRMLS_CC); - file = zend_read_property(default_exception_ce, &exception, "file", sizeof("file")-1, 1 TSRMLS_CC); - line = zend_read_property(default_exception_ce, &exception, "line", sizeof("line")-1, 1 TSRMLS_CC); + str = zval_get_string(GET_PROPERTY_SILENT(&exception, "string")); + file = zval_get_string(GET_PROPERTY_SILENT(&exception, "file")); + line = zval_get_long(GET_PROPERTY_SILENT(&exception, "line")); - convert_to_string_ex(str); - convert_to_string_ex(file); - convert_to_long_ex(line); + zend_error_va(severity, (file && file->len > 0) ? file->val : NULL, line, + "Uncaught %s\n thrown", str->val); - zend_error_va(severity, (Z_STRLEN_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_LVAL_P(line), "Uncaught %s\n thrown", Z_STRVAL_P(str)); + zend_string_release(str); + zend_string_release(file); } else { zend_error(severity, "Uncaught exception '%s'", ce_exception->name->val); } -- cgit v1.2.1 From df79b9b27af70afe502979c84a981d36ed9d86a8 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 9 Oct 2014 19:15:07 +0200 Subject: Update get_class_name semantics * get_class_name is now only used for displaying the class name in debugging functions like var_dump, print_r, etc. It is no longer used in get_class() etc. * As it is no longer used in get_parent_class() the parent argument is now gone. This also fixes incorrect parent classes being reported in COM. * get_class_name is now always required (previously some places made it optional and some required it) and is also required to return a non-NULL value. * Remove zend_get_object_classname. This also fixes a number of potential leaks due to incorrect usage of this function. --- Zend/zend_exceptions.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 6e4ee2fd30..f9c1a509a6 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -89,11 +89,8 @@ ZEND_API void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ { #ifdef HAVE_DTRACE if (DTRACE_EXCEPTION_THROWN_ENABLED()) { - zend_string *classname; - if (exception != NULL) { - classname = zend_get_object_classname(Z_OBJ_P(exception) TSRMLS_CC); - DTRACE_EXCEPTION_THROWN(classname->val); + DTRACE_EXCEPTION_THROWN(Z_OBJ_P(exception)->ce->val); } else { DTRACE_EXCEPTION_THROWN(NULL); } @@ -452,7 +449,7 @@ static void _build_trace_args(zval *arg, smart_str *str TSRMLS_DC) /* {{{ */ break; case IS_OBJECT: smart_str_appends(str, "Object("); - smart_str_append(str, zend_get_object_classname(Z_OBJ_P(arg) TSRMLS_CC)); + smart_str_append(str, Z_OBJCE_P(arg)->name); smart_str_appends(str, "), "); break; } -- cgit v1.2.1 From 1480d26fb926ef67746a3a3c70c940a0d9055072 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 20 Oct 2014 12:51:02 +0400 Subject: fixed compilation error --- Zend/zend_exceptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index f9c1a509a6..4159a46d3c 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -90,7 +90,7 @@ ZEND_API void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ #ifdef HAVE_DTRACE if (DTRACE_EXCEPTION_THROWN_ENABLED()) { if (exception != NULL) { - DTRACE_EXCEPTION_THROWN(Z_OBJ_P(exception)->ce->val); + DTRACE_EXCEPTION_THROWN(Z_OBJ_P(exception)->ce->name->val); } else { DTRACE_EXCEPTION_THROWN(NULL); } -- cgit v1.2.1