Skip to content

Commit a1c6ee2

Browse files
committed
Convert error filename to zend_string
Error handling functions/callbacks now accept the error filename as a zend_string* instead of a const char*.
1 parent 8c420bd commit a1c6ee2

File tree

9 files changed

+50
-54
lines changed

9 files changed

+50
-54
lines changed

Zend/zend.c

+15-20
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ ZEND_API FILE *(*zend_fopen)(zend_string *filename, zend_string **opened_path);
7777
ZEND_API zend_result (*zend_stream_open_function)(zend_file_handle *handle);
7878
ZEND_API void (*zend_ticks_function)(int ticks);
7979
ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
80-
ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
80+
ZEND_API void (*zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
8181
void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
8282
void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
8383
ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
@@ -1316,7 +1316,7 @@ ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */
13161316
} while (0)
13171317

13181318
static ZEND_COLD void zend_error_impl(
1319-
int orig_type, const char *error_filename, uint32_t error_lineno, zend_string *message)
1319+
int orig_type, zend_string *error_filename, uint32_t error_lineno, zend_string *message)
13201320
{
13211321
zval params[4];
13221322
zval retval;
@@ -1381,7 +1381,7 @@ static ZEND_COLD void zend_error_impl(
13811381
ZVAL_LONG(&params[0], type);
13821382

13831383
if (error_filename) {
1384-
ZVAL_STRING(&params[2], error_filename);
1384+
ZVAL_STR_COPY(&params[2], error_filename);
13851385
} else {
13861386
ZVAL_NULL(&params[2]);
13871387
}
@@ -1449,15 +1449,15 @@ static ZEND_COLD void zend_error_impl(
14491449
/* }}} */
14501450

14511451
static ZEND_COLD void zend_error_va_list(
1452-
int orig_type, const char *error_filename, uint32_t error_lineno,
1452+
int orig_type, zend_string *error_filename, uint32_t error_lineno,
14531453
const char *format, va_list args)
14541454
{
14551455
zend_string *message = zend_vstrpprintf(0, format, args);
14561456
zend_error_impl(orig_type, error_filename, error_lineno, message);
14571457
zend_string_release(message);
14581458
}
14591459

1460-
static ZEND_COLD void get_filename_lineno(int type, const char **filename, uint32_t *lineno) {
1460+
static ZEND_COLD void get_filename_lineno(int type, zend_string **filename, uint32_t *lineno) {
14611461
/* Obtain relevant filename and lineno */
14621462
switch (type) {
14631463
case E_CORE_ERROR:
@@ -1479,16 +1479,11 @@ static ZEND_COLD void get_filename_lineno(int type, const char **filename, uint3
14791479
case E_USER_DEPRECATED:
14801480
case E_RECOVERABLE_ERROR:
14811481
if (zend_is_compiling()) {
1482-
*filename = ZSTR_VAL(zend_get_compiled_filename());
1482+
*filename = zend_get_compiled_filename();
14831483
*lineno = zend_get_compiled_lineno();
14841484
} else if (zend_is_executing()) {
1485-
*filename = zend_get_executed_filename();
1486-
if ((*filename)[0] == '[') { /* [no active file] */
1487-
*filename = NULL;
1488-
*lineno = 0;
1489-
} else {
1490-
*lineno = zend_get_executed_lineno();
1491-
}
1485+
*filename = zend_get_executed_filename_ex();
1486+
*lineno = zend_get_executed_lineno();
14921487
} else {
14931488
*filename = NULL;
14941489
*lineno = 0;
@@ -1500,12 +1495,12 @@ static ZEND_COLD void get_filename_lineno(int type, const char **filename, uint3
15001495
break;
15011496
}
15021497
if (!*filename) {
1503-
*filename = "Unknown";
1498+
*filename = ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED);
15041499
}
15051500
}
15061501

15071502
ZEND_API ZEND_COLD void zend_error_at(
1508-
int type, const char *filename, uint32_t lineno, const char *format, ...) {
1503+
int type, zend_string *filename, uint32_t lineno, const char *format, ...) {
15091504
va_list args;
15101505

15111506
if (!filename) {
@@ -1519,7 +1514,7 @@ ZEND_API ZEND_COLD void zend_error_at(
15191514
}
15201515

15211516
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) {
1522-
const char *filename;
1517+
zend_string *filename;
15231518
uint32_t lineno;
15241519
va_list args;
15251520

@@ -1530,7 +1525,7 @@ ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) {
15301525
}
15311526

15321527
ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...) {
1533-
const char *filename;
1528+
zend_string *filename;
15341529
uint32_t lineno;
15351530
va_list args;
15361531

@@ -1541,7 +1536,7 @@ ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...)
15411536
}
15421537

15431538
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
1544-
int type, const char *filename, uint32_t lineno, const char *format, ...)
1539+
int type, zend_string *filename, uint32_t lineno, const char *format, ...)
15451540
{
15461541
va_list args;
15471542

@@ -1559,7 +1554,7 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
15591554

15601555
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
15611556
{
1562-
const char *filename;
1557+
zend_string *filename;
15631558
uint32_t lineno;
15641559
va_list args;
15651560

@@ -1572,7 +1567,7 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *
15721567
}
15731568

15741569
ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message) {
1575-
const char *filename;
1570+
zend_string *filename;
15761571
uint32_t lineno;
15771572
get_filename_lineno(type, &filename, &lineno);
15781573
zend_error_impl(type, filename, lineno, message);

Zend/zend.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ struct _zend_class_entry {
215215
};
216216

217217
typedef struct _zend_utility_functions {
218-
void (*error_function)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
218+
void (*error_function)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
219219
size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
220220
size_t (*write_function)(const char *str, size_t str_length);
221221
FILE *(*fopen_function)(zend_string *filename, zend_string **opened_path);
@@ -310,7 +310,7 @@ extern ZEND_API zend_write_func_t zend_write;
310310
extern ZEND_API FILE *(*zend_fopen)(zend_string *filename, zend_string **opened_path);
311311
extern ZEND_API void (*zend_ticks_function)(int ticks);
312312
extern ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
313-
extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
313+
extern ZEND_API void (*zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
314314
extern ZEND_API void (*zend_on_timeout)(int seconds);
315315
extern ZEND_API zend_result (*zend_stream_open_function)(zend_file_handle *handle);
316316
extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
@@ -330,8 +330,8 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *
330330
/* For custom format specifiers like H */
331331
ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...);
332332
/* If filename is NULL the default filename is used. */
333-
ZEND_API ZEND_COLD void zend_error_at(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
334-
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
333+
ZEND_API ZEND_COLD void zend_error_at(int type, zend_string *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
334+
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, zend_string *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
335335
ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message);
336336

337337
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);

Zend/zend_exceptions.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ ZEND_API ZEND_COLD zend_object *zend_throw_error_exception(zend_class_entry *exc
872872
}
873873
/* }}} */
874874

875-
static void zend_error_va(int type, const char *file, uint32_t lineno, const char *format, ...) /* {{{ */
875+
static void zend_error_va(int type, zend_string *file, uint32_t lineno, const char *format, ...) /* {{{ */
876876
{
877877
va_list args;
878878
va_start(args, format);
@@ -900,8 +900,8 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
900900
zend_long line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE));
901901
int type = (ce_exception == zend_ce_parse_error ? E_PARSE : E_COMPILE_ERROR) | E_DONT_BAIL;
902902

903-
zend_observer_error_notify(type, ZSTR_VAL(file), line, message);
904-
zend_error_cb(type, ZSTR_VAL(file), line, message);
903+
zend_observer_error_notify(type, file, line, message);
904+
zend_error_cb(type, file, line, message);
905905

906906
zend_string_release_ex(file, 0);
907907
zend_string_release_ex(message, 0);
@@ -930,7 +930,7 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
930930
line = zval_get_long(GET_PROPERTY_SILENT(&zv, ZEND_STR_LINE));
931931
}
932932

933-
zend_error_va(E_WARNING, (file && ZSTR_LEN(file) > 0) ? ZSTR_VAL(file) : NULL, line,
933+
zend_error_va(E_WARNING, (file && ZSTR_LEN(file) > 0) ? file : NULL, line,
934934
"Uncaught %s in exception handling during call to %s::__toString()",
935935
ZSTR_VAL(Z_OBJCE(zv)->name), ZSTR_VAL(ce_exception->name));
936936

@@ -944,7 +944,7 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
944944
line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE));
945945

946946
zend_error_va(severity | E_DONT_BAIL,
947-
(file && ZSTR_LEN(file) > 0) ? ZSTR_VAL(file) : NULL, line,
947+
(file && ZSTR_LEN(file) > 0) ? file : NULL, line,
948948
"Uncaught %s\n thrown", ZSTR_VAL(str));
949949

950950
zend_string_release_ex(str, 0);

Zend/zend_observer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ ZEND_API void zend_observer_error_register(zend_observer_error_cb cb)
245245
zend_llist_add_element(&zend_observer_error_callbacks, &cb);
246246
}
247247

248-
void zend_observer_error_notify(int type, const char *error_filename, uint32_t error_lineno, zend_string *message)
248+
void zend_observer_error_notify(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message)
249249
{
250250
zend_llist_element *element;
251251
zend_observer_error_cb callback;

Zend/zend_observer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ ZEND_API void ZEND_FASTCALL zend_observer_fcall_end(
7272

7373
ZEND_API void zend_observer_fcall_end_all(void);
7474

75-
typedef void (*zend_observer_error_cb)(int type, const char *error_filename, uint32_t error_lineno, zend_string *message);
75+
typedef void (*zend_observer_error_cb)(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message);
7676

7777
ZEND_API void zend_observer_error_register(zend_observer_error_cb callback);
78-
void zend_observer_error_notify(int type, const char *error_filename, uint32_t error_lineno, zend_string *message);
78+
void zend_observer_error_notify(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message);
7979

8080
END_EXTERN_C()
8181

Zend/zend_string.h

+1
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ EMPTY_SWITCH_DEFAULT_CASE()
505505
_(ZEND_STR_PAAMAYIM_NEKUDOTAYIM, "::") \
506506
_(ZEND_STR_ARGS, "args") \
507507
_(ZEND_STR_UNKNOWN, "unknown") \
508+
_(ZEND_STR_UNKNOWN_CAPITALIZED, "Unknown") \
508509
_(ZEND_STR_EVAL, "eval") \
509510
_(ZEND_STR_INCLUDE, "include") \
510511
_(ZEND_STR_REQUIRE, "require") \

ext/opcache/ZendAccelerator.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static zend_class_entry* (*accelerator_orig_inheritance_cache_get)(zend_class_en
122122
static zend_class_entry* (*accelerator_orig_inheritance_cache_add)(zend_class_entry *ce, zend_class_entry *proto, zend_class_entry *parent, zend_class_entry **traits_and_interfaces, HashTable *dependencies);
123123
static zend_result (*accelerator_orig_zend_stream_open_function)(zend_file_handle *handle );
124124
static zend_string *(*accelerator_orig_zend_resolve_path)(zend_string *filename);
125-
static void (*accelerator_orig_zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
125+
static void (*accelerator_orig_zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
126126
static zif_handler orig_chdir = NULL;
127127
static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL;
128128
static zend_result (*orig_post_startup_cb)(void);
@@ -1686,12 +1686,12 @@ static void zend_accel_set_auto_globals(int mask)
16861686
ZCG(auto_globals_mask) |= mask;
16871687
}
16881688

1689-
static void persistent_error_cb(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message) {
1689+
static void persistent_error_cb(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) {
16901690
if (ZCG(record_warnings)) {
16911691
zend_recorded_warning *warning = emalloc(sizeof(zend_recorded_warning));
16921692
warning->type = type;
16931693
warning->error_lineno = error_lineno;
1694-
warning->error_filename = zend_string_init(error_filename, strlen(error_filename), 0);
1694+
warning->error_filename = zend_string_copy(error_filename);
16951695
warning->error_message = zend_string_copy(message);
16961696

16971697
ZCG(num_warnings)++;
@@ -1705,7 +1705,7 @@ static void replay_warnings(zend_persistent_script *script) {
17051705
for (uint32_t i = 0; i < script->num_warnings; i++) {
17061706
zend_recorded_warning *warning = script->warnings[i];
17071707
accelerator_orig_zend_error_cb(
1708-
warning->type, ZSTR_VAL(warning->error_filename), warning->error_lineno,
1708+
warning->type, warning->error_filename, warning->error_lineno,
17091709
warning->error_message);
17101710
}
17111711
}
@@ -4084,13 +4084,13 @@ static void preload_link(void)
40844084
if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS)
40854085
&& zend_hash_exists(EG(class_table), key)) {
40864086
zend_error_at(
4087-
E_WARNING, ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start,
4087+
E_WARNING, ce->info.user.filename, ce->info.user.line_start,
40884088
"Can't preload already declared class %s", ZSTR_VAL(ce->name));
40894089
} else {
40904090
const char *kind, *name;
40914091
get_unlinked_dependency(ce, &kind, &name);
40924092
zend_error_at(
4093-
E_WARNING, ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start,
4093+
E_WARNING, ce->info.user.filename, ce->info.user.line_start,
40944094
"Can't preload unlinked class %s: %s%s",
40954095
ZSTR_VAL(ce->name), kind, name);
40964096
}

ext/soap/soap.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void delete_service(void *service);
6868
static void delete_url(void *handle);
6969
static void delete_hashtable(void *hashtable);
7070

71-
static void soap_error_handler(int error_num, const char *error_filename, const uint32_t error_lineno, zend_string *message);
71+
static void soap_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
7272

7373
#define SOAP_SERVER_BEGIN_CODE() \
7474
bool _old_handler = SOAP_GLOBAL(use_soap_error_handler);\
@@ -164,7 +164,7 @@ zend_class_entry* soap_var_class_entry;
164164

165165
ZEND_DECLARE_MODULE_GLOBALS(soap)
166166

167-
static void (*old_error_handler)(int, const char *, const uint32_t, zend_string *);
167+
static void (*old_error_handler)(int, zend_string *, const uint32_t, zend_string *);
168168

169169
PHP_RINIT_FUNCTION(soap);
170170
PHP_MINIT_FUNCTION(soap);
@@ -1799,7 +1799,7 @@ static ZEND_NORETURN void soap_server_fault(char* code, char* string, char *acto
17991799
}
18001800
/* }}} */
18011801

1802-
static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, const char *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */
1802+
static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */
18031803
{
18041804
bool _old_in_compilation;
18051805
zend_execute_data *_old_current_execute_data;
@@ -1900,7 +1900,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, c
19001900
}
19011901
/* }}} */
19021902

1903-
static void soap_error_handler(int error_num, const char *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */
1903+
static void soap_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */
19041904
{
19051905
if (EXPECTED(!SOAP_GLOBAL(use_soap_error_handler))) {
19061906
old_error_handler(error_num, error_filename, error_lineno, message);

0 commit comments

Comments
 (0)