Skip to content

Commit 919c36a

Browse files
authored
Fixup master compatibility of arg_info (#3833)
1 parent 9d9fdac commit 919c36a

3 files changed

Lines changed: 43 additions & 18 deletions

File tree

ext/handlers_exception.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,19 @@ void ddtrace_exception_handlers_startup(void) {
510510
.function_name = zend_string_init_interned(ZEND_STRL("ddtrace_exception_handler"), 1),
511511
.num_args = 4,
512512
.required_num_args = 1,
513+
#if PHP_VERSION_ID < 80600
513514
.arg_info = (zend_internal_arg_info *)(arginfo_ddtrace_exception_or_error_handler + 1),
515+
#endif
514516
.handler = &zim_DDTrace_ExceptionOrErrorHandler_execute,
515517
};
518+
#if PHP_VERSION_ID >= 80600
519+
uint32_t num_args = ddtrace_exception_or_error_handler.num_args + 1;
520+
zend_arg_info *new_arg_info = pemalloc(sizeof(zend_arg_info) * num_args, 1);
521+
for (uint32_t i = 0; i < num_args; i++) {
522+
zend_convert_internal_arg_info(&new_arg_info[i], &arginfo_ddtrace_exception_or_error_handler[i], i == 0, true);
523+
}
524+
ddtrace_exception_or_error_handler.arg_info = new_arg_info + 1;
525+
#endif
516526

517527
INIT_NS_CLASS_ENTRY(dd_exception_or_error_handler_ce, "DDTrace", "ExceptionHandler", NULL);
518528
dd_exception_or_error_handler_ce.type = ZEND_INTERNAL_CLASS;
@@ -619,6 +629,9 @@ void ddtrace_exception_handlers_startup(void) {
619629
}
620630

621631
void ddtrace_exception_handlers_shutdown(void) {
632+
#if PHP_VERSION_ID >= 80600
633+
zend_free_internal_arg_info(&ddtrace_exception_or_error_handler, true);
634+
#endif
622635
ddtrace_free_unregistered_class(&dd_exception_or_error_handler_ce);
623636
zend_hash_destroy(&ddtrace_exception_custom_create_object);
624637
}

ext/hook/uhook_otel.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,22 @@ static bool dd_uhook_begin(zend_ulong invocation, zend_execute_data *execute_dat
9191
if (strkey) {
9292
uint32_t num_args = fbc->common.num_args;
9393
// As per zend_handle_named_arg()
94-
if (EXPECTED(fbc->type == ZEND_USER_FUNCTION)
95-
|| EXPECTED(fbc->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) {
94+
#if PHP_VERSION_ID < 80600
95+
if (UNEXPECTED(fbc->type != ZEND_USER_FUNCTION) && EXPECTED((fbc->common.fn_flags & ZEND_ACC_USER_ARG_INFO == 0))) {
9696
for (uint32_t i = 0; i < num_args; i++) {
97-
zend_arg_info *arg_info = &fbc->op_array.arg_info[i];
98-
if (zend_string_equals(strkey, arg_info->name)) {
97+
zend_internal_arg_info *arg_info = &fbc->internal_function.arg_info[i];
98+
size_t len = strlen(arg_info->name);
99+
if (zend_string_equals_cstr(strkey, arg_info->name, len)) {
99100
arg_offset = i;
100101
found = true;
101102
}
102103
}
103-
} else {
104+
} else
105+
#endif
106+
{
104107
for (uint32_t i = 0; i < num_args; i++) {
105-
zend_internal_arg_info *arg_info = &fbc->internal_function.arg_info[i];
106-
size_t len = strlen(arg_info->name);
107-
if (zend_string_equals_cstr(strkey, arg_info->name, len)) {
108+
zend_arg_info *arg_info = &fbc->op_array.arg_info[i];
109+
if (zend_string_equals(strkey, arg_info->name)) {
108110
arg_offset = i;
109111
found = true;
110112
}

ext/live_debugger.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,12 @@ static void dd_log_probe_ensure_payload(dd_log_probe_dyn *dyn, dd_log_probe_def
408408

409409
static void dd_log_probe_capture_snapshot(ddog_DebuggerCapture *capture, dd_log_probe_def *def, zend_execute_data *execute_data) {
410410
const ddog_CaptureConfiguration *capture_config = def->parent.probe.probe.log.capture;
411-
if (ZEND_USER_CODE(EX(func)->type)) {
411+
#if PHP_VERSION_ID < 80600
412+
if (ZEND_USER_CODE(EX(func)->type))
413+
#else
414+
if (ZEND_USER_CODE(EX(func)->type) || EX(func)->internal_function.arg_info)
415+
#endif
416+
{
412417
zend_array *symbol_table = zend_rebuild_symbol_table();
413418
zend_string *symbol;
414419
zval *variable;
@@ -422,6 +427,7 @@ static void dd_log_probe_capture_snapshot(ddog_DebuggerCapture *capture, dd_log_
422427
ddog_snapshot_add_field(capture, type, name_slice, capture_value);
423428
}
424429
} ZEND_HASH_FOREACH_END();
430+
#if PHP_VERSION_ID < 80600
425431
} else if (EX(func)->internal_function.arg_info) {
426432
uint32_t num_args = EX(func)->internal_function.num_args;
427433
for (uintptr_t i = 0; i < num_args; ++i) {
@@ -432,6 +438,7 @@ static void dd_log_probe_capture_snapshot(ddog_DebuggerCapture *capture, dd_log_
432438
ddtrace_create_capture_value(EX_VAR_NUM(i), &capture_value, capture_config, capture_config->max_reference_depth);
433439
ddog_snapshot_add_field(capture, DDOG_FIELD_TYPE_ARG, name_slice, capture_value);
434440
}
441+
#endif
435442
}
436443
if (hasThis()) {
437444
struct ddog_CaptureValue capture_value = {0};
@@ -978,7 +985,18 @@ static const void *dd_eval_fetch_identifier(void *ctx, const ddog_CharSlice *nam
978985
zend_execute_data *execute_data = eval_ctx->frame;
979986

980987
if (EX(func)) {
981-
if (ZEND_USER_CODE(EX(func)->type)) {
988+
#if PHP_VERSION_ID < 80600
989+
if (!ZEND_USER_CODE(EX(func)->type)) {
990+
int call_args = MIN(EX_NUM_ARGS(), EX(func)->common.num_args);
991+
for (int i = 0; i < call_args; ++i) {
992+
const char *argname = EX(func)->internal_function.arg_info[i].name;
993+
if (zend_binary_strcmp(argname, strlen(argname), name->ptr, name->len) == 0) {
994+
return EX_VAR_NUM(i);
995+
}
996+
}
997+
} else
998+
#endif
999+
{
9821000
zend_execute_data *current_execute_data = EG(current_execute_data);
9831001
EG(current_execute_data) = execute_data;
9841002
zend_array *symtable = zend_rebuild_symbol_table();
@@ -990,14 +1008,6 @@ static const void *dd_eval_fetch_identifier(void *ctx, const ddog_CharSlice *nam
9901008
if (zvp) {
9911009
return zvp;
9921010
}
993-
} else {
994-
int call_args = MIN(EX_NUM_ARGS(), EX(func)->common.num_args);
995-
for (int i = 0; i < call_args; ++i) {
996-
const char *argname = EX(func)->internal_function.arg_info[i].name;
997-
if (zend_binary_strcmp(argname, strlen(argname), name->ptr, name->len) == 0) {
998-
return EX_VAR_NUM(i);
999-
}
1000-
}
10011011
}
10021012
}
10031013

0 commit comments

Comments
 (0)