From b66eb866c94d82f7b99ffc130fff5cfb2ff145b6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 23 Apr 2021 10:57:12 +0200 Subject: [PATCH] Convert last_error_file to zend_string --- ext/standard/basic_functions.c | 5 +++-- main/main.c | 6 +++--- main/php_globals.h | 2 +- sapi/cli/php_cli_server.c | 2 +- sapi/phpdbg/phpdbg_info.c | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 0424bd9ab16..a614b40210e 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1510,7 +1510,8 @@ PHP_FUNCTION(error_get_last) add_assoc_long_ex(return_value, "type", sizeof("type")-1, PG(last_error_type)); add_assoc_str_ex(return_value, "message", sizeof("message")-1, zend_string_copy(PG(last_error_message))); - add_assoc_string_ex(return_value, "file", sizeof("file")-1, PG(last_error_file)?PG(last_error_file):"-"); + add_assoc_str_ex(return_value, "file", sizeof("file")-1, + zend_string_copy(PG(last_error_file))); add_assoc_long_ex(return_value, "line", sizeof("line")-1, PG(last_error_lineno)); } } @@ -1529,7 +1530,7 @@ PHP_FUNCTION(error_clear_last) PG(last_error_message) = NULL; if (PG(last_error_file)) { - free(PG(last_error_file)); + zend_string_release(PG(last_error_file)); PG(last_error_file) = NULL; } } diff --git a/main/main.c b/main/main.c index 1988f3855a8..6fcfb47c273 100644 --- a/main/main.c +++ b/main/main.c @@ -1144,7 +1144,7 @@ static void clear_last_error() { PG(last_error_message) = NULL; } if (PG(last_error_file)) { - free(PG(last_error_file)); + zend_string_release(PG(last_error_file)); PG(last_error_file) = NULL; } } @@ -1188,7 +1188,7 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c if (zend_string_equals(PG(last_error_message), message) || (!PG(ignore_repeated_source) && ((PG(last_error_lineno) != (int)error_lineno) - || strcmp(PG(last_error_file), ZSTR_VAL(error_filename))))) { + || !zend_string_equals(PG(last_error_file), error_filename)))) { display = 1; } else { display = 0; @@ -1227,7 +1227,7 @@ static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, c } PG(last_error_type) = type; PG(last_error_message) = zend_string_copy(message); - PG(last_error_file) = strdup(ZSTR_VAL(error_filename)); + PG(last_error_file) = zend_string_copy(error_filename); PG(last_error_lineno) = error_lineno; } diff --git a/main/php_globals.h b/main/php_globals.h index e619694d18a..71f2dbbf836 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -134,7 +134,7 @@ struct _php_core_globals { int last_error_type; zend_string *last_error_message; - char *last_error_file; + zend_string *last_error_file; int last_error_lineno; char *php_sys_temp_dir; diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index cb993b5bb60..17e979cc0a9 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -1169,7 +1169,7 @@ static void php_cli_server_log_response(php_cli_server_client *client, int statu /* error */ if (append_error_message) { spprintf(&error_buf, 0, " - %s in %s on line %d", - ZSTR_VAL(PG(last_error_message)), PG(last_error_file), PG(last_error_lineno)); + ZSTR_VAL(PG(last_error_message)), ZSTR_VAL(PG(last_error_file)), PG(last_error_lineno)); if (!error_buf) { efree(basic_buf); if (message) { diff --git a/sapi/phpdbg/phpdbg_info.c b/sapi/phpdbg/phpdbg_info.c index b5dc4fa4927..c09358ca68a 100644 --- a/sapi/phpdbg/phpdbg_info.c +++ b/sapi/phpdbg/phpdbg_info.c @@ -83,7 +83,7 @@ PHPDBG_INFO(error) /* {{{ */ { if (PG(last_error_message)) { phpdbg_try_access { - phpdbg_writeln("lasterror", "error=\"%s\" file=\"%s\" line=\"%d\"", "Last error: %s at %s line %d", PG(last_error_message), PG(last_error_file), PG(last_error_lineno)); + phpdbg_writeln("lasterror", "error=\"%s\" file=\"%s\" line=\"%d\"", "Last error: %s at %s line %d", PG(last_error_message), ZSTR_VAL(PG(last_error_file)), PG(last_error_lineno)); } phpdbg_catch_access { phpdbg_notice("lasterror", "error=\"\"", "No error found!"); } phpdbg_end_try_access();