Skip to content

Commit 34b0ae8

Browse files
committed
stream: use wrapper ptr key for logged errors
1 parent bdf9600 commit 34b0ae8

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

main/streams/stream_errors.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
/* StreamException class entry */
2626
static zend_class_entry *php_ce_stream_exception;
2727

28+
#define PHP_STREAM_ERRORS_WRAPPER_NAME(_wrapper) \
29+
(_wrapper && _wrapper->wops && _wrapper->wops->label ? _wrapper->wops->label : "unknown")
30+
2831
static void php_stream_error_entry_dtor(void *error)
2932
{
3033
php_stream_error_entry *entry = *(php_stream_error_entry **) error;
3134
zend_string_release(entry->message);
3235
pefree(entry->wrapper_name, entry->persistent);
3336
pefree(entry->docref, entry->persistent);
34-
// param is not currently supported for streams so cannot be persistent
37+
// param is not currently supported for streams so cannot be persistent
3538
ZEND_ASSERT(!entry->persistent || entry->param == NULL);
3639
efree(entry->param);
3740
pefree(entry, entry->persistent);
@@ -216,8 +219,8 @@ static void php_stream_process_error(php_stream_context *context, const char *wr
216219

217220
/* Helper to create error entry */
218221
static php_stream_error_entry *php_stream_create_error_entry(zend_string *message, int code,
219-
const char *wrapper_name, const char *docref, char *param, int severity,
220-
bool terminal, bool persistent)
222+
const char *wrapper_name, const char *docref, char *param, int severity, bool terminal,
223+
bool persistent)
221224
{
222225
if (persistent) {
223226
message = zend_string_dup(message, true);
@@ -240,8 +243,8 @@ static php_stream_error_entry *php_stream_create_error_entry(zend_string *messag
240243

241244
/* Common storage function*/
242245
static void php_stream_store_error_common(php_stream_context *context, php_stream *stream,
243-
zend_string *message, const char *docref, int code,
244-
const char *wrapper_name, char *param, int severity, bool terminal)
246+
zend_string *message, const char *docref, int code, const char *wrapper_name, char *param,
247+
int severity, bool terminal)
245248
{
246249
int error_mode = php_stream_get_error_mode(context);
247250
int store_mode = php_stream_get_error_store_mode(context, error_mode);
@@ -295,8 +298,8 @@ static void php_stream_wrapper_error_internal_with_name(const char *wrapper_name
295298
{
296299
zend_string *message = vstrpprintf(0, fmt, args);
297300

298-
php_stream_process_error(context, wrapper_name, NULL, docref, code, ZSTR_VAL(message),
299-
param, severity, terminal);
301+
php_stream_process_error(context, wrapper_name, NULL, docref, code, ZSTR_VAL(message), param,
302+
severity, terminal);
300303

301304
php_stream_store_error_common(
302305
context, NULL, message, docref, code, wrapper_name, param, severity, terminal);
@@ -308,10 +311,10 @@ static void php_stream_wrapper_error_internal(php_stream_wrapper *wrapper,
308311
php_stream_context *context, const char *docref, int options, int severity, bool terminal,
309312
int code, char *param, const char *fmt, va_list args)
310313
{
311-
const char *wrapper_name = wrapper ? wrapper->wops->label : "unknown";
314+
const char *wrapper_name = PHP_STREAM_ERRORS_WRAPPER_NAME(wrapper);
312315

313-
php_stream_wrapper_error_internal_with_name(wrapper_name, context, docref, options, severity,
314-
terminal, code, param, fmt, args);
316+
php_stream_wrapper_error_internal_with_name(
317+
wrapper_name, context, docref, options, severity, terminal, code, param, fmt, args);
315318
}
316319

317320
PHPAPI void php_stream_wrapper_error_with_name(const char *wrapper_name,
@@ -347,7 +350,7 @@ PHPAPI void php_stream_wrapper_error_param(php_stream_wrapper *wrapper, php_stre
347350
if (options & REPORT_ERRORS) {
348351
va_list args;
349352
va_start(args, fmt);
350-
char *param_copy = param ? estrdup(param): NULL;
353+
char *param_copy = param ? estrdup(param) : NULL;
351354
php_stream_wrapper_error_internal(
352355
wrapper, context, docref, options, severity, terminal, code, param_copy, fmt, args);
353356
va_end(args);
@@ -364,35 +367,35 @@ PHPAPI void php_stream_wrapper_error_param2(php_stream_wrapper *wrapper,
364367

365368
va_list args;
366369
va_start(args, fmt);
367-
php_stream_wrapper_error_internal(
368-
wrapper, context, docref, options, severity, terminal, code, combined_param, fmt, args);
370+
php_stream_wrapper_error_internal(wrapper, context, docref, options, severity, terminal,
371+
code, combined_param, fmt, args);
369372
va_end(args);
370373
}
371374
}
372375

373376
/* Wrapper error logging - stores in FG(wrapper_logged_errors) */
374377

375-
static void php_stream_wrapper_log_store_error(zend_string *message, int code,
376-
const char *wrapper_name, const char *param, int severity, bool terminal)
378+
static void php_stream_wrapper_log_store_error(const php_stream_wrapper *wrapper,
379+
zend_string *message, int code, const char *param, int severity, bool terminal)
377380
{
378-
char *param_copy = param ? estrdup(param): NULL;
381+
char *param_copy = param ? estrdup(param) : NULL;
379382
php_stream_error_entry *entry = php_stream_create_error_entry(
380-
message, code, wrapper_name, NULL, param_copy, severity, terminal, false);
383+
message, code, NULL, NULL, param_copy, severity, terminal, false);
381384

382385
if (!FG(wrapper_logged_errors)) {
383386
ALLOC_HASHTABLE(FG(wrapper_logged_errors));
384387
zend_hash_init(FG(wrapper_logged_errors), 8, NULL, php_stream_error_list_dtor, 0);
385388
}
386389

387390
zend_llist *list = zend_hash_str_find_ptr(
388-
FG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name));
391+
FG(wrapper_logged_errors), (const char *) &wrapper, sizeof(wrapper));
389392

390393
if (!list) {
391394
zend_llist new_list;
392395
zend_llist_init(
393396
&new_list, sizeof(php_stream_error_entry *), php_stream_error_entry_dtor, 0);
394-
list = zend_hash_str_update_mem(FG(wrapper_logged_errors), wrapper_name,
395-
strlen(wrapper_name), &new_list, sizeof(new_list));
397+
list = zend_hash_str_update_mem(FG(wrapper_logged_errors), (const char *) &wrapper,
398+
sizeof(wrapper), &new_list, sizeof(new_list));
396399
}
397400

398401
zend_llist_add_element(list, &entry);
@@ -403,16 +406,15 @@ static void php_stream_wrapper_log_error_internal(const php_stream_wrapper *wrap
403406
char *param, const char *fmt, va_list args)
404407
{
405408
zend_string *message = vstrpprintf(0, fmt, args);
406-
const char *wrapper_name = wrapper ? wrapper->wops->label : "unknown";
409+
const char *wrapper_name = PHP_STREAM_ERRORS_WRAPPER_NAME(wrapper);
407410

408411
if (options & REPORT_ERRORS) {
409412
/* Report immediately using standard error functions */
410413
php_stream_wrapper_error_internal_with_name(
411414
wrapper_name, context, NULL, options, severity, terminal, code, param, fmt, args);
412415
} else {
413416
/* Store for later display in FG(wrapper_logged_errors) */
414-
php_stream_wrapper_log_store_error(
415-
message, code, wrapper_name, param, severity, terminal);
417+
php_stream_wrapper_log_store_error(wrapper, message, code, param, severity, terminal);
416418
}
417419
zend_string_release(message);
418420
}
@@ -434,24 +436,24 @@ PHPAPI void php_stream_wrapper_log_error_param(const php_stream_wrapper *wrapper
434436
{
435437
va_list args;
436438
va_start(args, fmt);
437-
char *param_copy = param ? estrdup(param): NULL;
439+
char *param_copy = param ? estrdup(param) : NULL;
438440
php_stream_wrapper_log_error_internal(
439441
wrapper, context, options, severity, terminal, code, param_copy, fmt, args);
440442
va_end(args);
441443
}
442444

443-
static zend_llist *php_stream_get_wrapper_errors_list(const char *wrapper_name)
445+
static zend_llist *php_stream_get_wrapper_errors_list(php_stream_wrapper *wrapper)
444446
{
445447
if (!FG(wrapper_logged_errors)) {
446448
return NULL;
447449
} else {
448450
return (zend_llist *) zend_hash_str_find_ptr(
449-
FG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name));
451+
FG(wrapper_logged_errors), (const char *) &wrapper, sizeof(wrapper));
450452
}
451453
}
452454

453-
void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper,
454-
php_stream_context *context, int code, const char *path, const char *caption)
455+
void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, php_stream_context *context,
456+
int code, const char *path, const char *caption)
455457
{
456458
char *msg;
457459
char errstr[256];
@@ -462,10 +464,9 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper,
462464
return;
463465
}
464466

465-
const char *wrapper_name = wrapper ? wrapper->wops->label : "unknown";
466467
char *tmp = estrdup(path);
467468
if (wrapper) {
468-
zend_llist *err_list = php_stream_get_wrapper_errors_list(wrapper_name);
469+
zend_llist *err_list = php_stream_get_wrapper_errors_list(wrapper);
469470
if (err_list) {
470471
size_t l = 0;
471472
int brlen;
@@ -513,8 +514,8 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper,
513514
}
514515

515516
php_strip_url_passwd(tmp);
516-
php_stream_wrapper_warn_param(wrapper, context, REPORT_ERRORS, code, tmp,
517-
"%s: %s", caption, msg);
517+
php_stream_wrapper_warn_param(
518+
wrapper, context, REPORT_ERRORS, code, tmp, "%s: %s", caption, msg);
518519
efree(tmp);
519520
if (free_msg) {
520521
efree(msg);
@@ -524,8 +525,7 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper,
524525
void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper)
525526
{
526527
if (wrapper && FG(wrapper_logged_errors)) {
527-
const char *wrapper_name = wrapper ? wrapper->wops->label : "unknown";
528-
zend_hash_str_del(FG(wrapper_logged_errors), wrapper_name, strlen(wrapper_name));
528+
zend_hash_str_del(FG(wrapper_logged_errors), (const char *) &wrapper, sizeof(wrapper));
529529
}
530530
}
531531

@@ -549,8 +549,8 @@ PHPAPI void php_stream_error(php_stream *stream, const char *docref, int severit
549549
severity, terminal);
550550

551551
/* Store error */
552-
php_stream_store_error_common(context, stream, message, docref, code, wrapper_name, NULL,
553-
severity, terminal);
552+
php_stream_store_error_common(
553+
context, stream, message, docref, code, wrapper_name, NULL, severity, terminal);
554554

555555
zend_string_release(message);
556556
}

0 commit comments

Comments
 (0)