Skip to content

Commit 958c216

Browse files
committed
Add zend_error_notify_callback infrastructure and call in zend_error_va_list.
1 parent e2f1586 commit 958c216

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Zend/zend.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,8 @@ static ZEND_COLD void zend_error_va_list(
13231323
}
13241324
#endif /* HAVE_DTRACE */
13251325

1326+
zend_error_notify_all_callbacks(type, error_filename, error_lineno, format, args);
1327+
13261328
/* if we don't have a user defined error handler */
13271329
if (Z_TYPE(EG(user_error_handler)) == IS_UNDEF
13281330
|| !(EG(user_error_handler_error_reporting) & type)
@@ -1767,3 +1769,40 @@ ZEND_API void zend_map_ptr_extend(size_t last)
17671769
CG(map_ptr_last) = last;
17681770
}
17691771
}
1772+
1773+
static void zend_error_notify_callback_dtor(zend_error_notify_callback *callback)
1774+
{
1775+
}
1776+
1777+
int zend_startup_error_notify_callbacks()
1778+
{
1779+
zend_llist_init(&zend_error_notify_callbacks, sizeof(zend_error_notify_callback), (void (*)(void *)) zend_error_notify_callback_dtor, 1);
1780+
1781+
return SUCCESS;
1782+
}
1783+
1784+
int zend_shutdown_error_notify_callbacks()
1785+
{
1786+
zend_llist_destroy(&zend_error_notify_callbacks);
1787+
1788+
return SUCCESS;
1789+
}
1790+
1791+
void zend_register_error_notify_callback(const char *name, zend_error_notify_cb cb)
1792+
{
1793+
zend_error_notify_callback callback;
1794+
callback.name = name;
1795+
callback.notify_callback = cb;
1796+
1797+
zend_llist_add_element(&zend_error_notify_callbacks, &callback);
1798+
}
1799+
1800+
static void zend_error_notify_single_callback(zend_error_notify_callback *callback, int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args)
1801+
{
1802+
callback->notify_callback(type, error_filename, error_lineno, format, args);
1803+
}
1804+
1805+
void zend_error_notify_all_callbacks(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args)
1806+
{
1807+
zend_llist_apply_with_arguments(&zend_error_notify_callbacks, (llist_apply_with_args_func_t) zend_error_notify_single_callback, 5, type, error_filename, error_lineno, format, args);
1808+
}

Zend/zend.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ ZEND_API void zend_save_error_handling(zend_error_handling *current);
349349
ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current);
350350
ZEND_API void zend_restore_error_handling(zend_error_handling *saved);
351351

352+
typedef void (*zend_error_notify_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args);
353+
354+
typedef struct {
355+
const char *name;
356+
zend_error_notify_cb notify_callback;
357+
} zend_error_notify_callback;
358+
359+
ZEND_API zend_llist zend_error_notify_callbacks;
360+
void zend_register_error_notify_callback(const char *name, zend_error_notify_cb callback);
361+
int zend_startup_error_notify_callbacks();
362+
int zend_shutdown_error_notify_callbacks();
363+
void zend_error_notify_all_callbacks(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args);
364+
352365
#define DEBUG_BACKTRACE_PROVIDE_OBJECT (1<<0)
353366
#define DEBUG_BACKTRACE_IGNORE_ARGS (1<<1)
354367

0 commit comments

Comments
 (0)