Skip to content

Commit c5308e4

Browse files
committed
Fixup master compatibility of arg_info
1 parent b7eb412 commit c5308e4

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
@@ -407,7 +407,12 @@ static void dd_log_probe_ensure_payload(dd_log_probe_dyn *dyn, dd_log_probe_def
407407

408408
static void dd_log_probe_capture_snapshot(ddog_DebuggerCapture *capture, dd_log_probe_def *def, zend_execute_data *execute_data) {
409409
const ddog_CaptureConfiguration *capture_config = def->parent.probe.probe.log.capture;
410-
if (ZEND_USER_CODE(EX(func)->type)) {
410+
#if PHP_VERSION_ID < 80600
411+
if (ZEND_USER_CODE(EX(func)->type))
412+
#else
413+
if (ZEND_USER_CODE(EX(func)->type) || EX(func)->internal_function.arg_info)
414+
#endif
415+
{
411416
zend_array *symbol_table = zend_rebuild_symbol_table();
412417
zend_string *symbol;
413418
zval *variable;
@@ -421,6 +426,7 @@ static void dd_log_probe_capture_snapshot(ddog_DebuggerCapture *capture, dd_log_
421426
ddog_snapshot_add_field(capture, type, name_slice, capture_value);
422427
}
423428
} ZEND_HASH_FOREACH_END();
429+
#if PHP_VERSION_ID < 80600
424430
} else if (EX(func)->internal_function.arg_info) {
425431
uint32_t num_args = EX(func)->internal_function.num_args;
426432
for (uintptr_t i = 0; i < num_args; ++i) {
@@ -431,6 +437,7 @@ static void dd_log_probe_capture_snapshot(ddog_DebuggerCapture *capture, dd_log_
431437
ddtrace_create_capture_value(EX_VAR_NUM(i), &capture_value, capture_config, capture_config->max_reference_depth);
432438
ddog_snapshot_add_field(capture, DDOG_FIELD_TYPE_ARG, name_slice, capture_value);
433439
}
440+
#endif
434441
}
435442
if (hasThis()) {
436443
struct ddog_CaptureValue capture_value = {0};
@@ -977,7 +984,18 @@ static const void *dd_eval_fetch_identifier(void *ctx, const ddog_CharSlice *nam
977984
zend_execute_data *execute_data = eval_ctx->frame;
978985

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

0 commit comments

Comments
 (0)