From 628098978c1574cc6bd8ce3b9233046adba81ece Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Sat, 23 Nov 2024 01:10:31 +0100 Subject: [PATCH] Compatibility with newest arginfo gen_stub from PHP 8.4 (#2973) Signed-off-by: Bob Weinand --- ext/compatibility.h | 81 +++++++++++++++++++---------- ext/ddtrace.c | 18 +++++-- ext/ddtrace_arginfo.h | 48 +++++------------ ext/hook/uhook_arginfo.h | 8 ++- ext/hook/uhook_attributes.c | 2 +- ext/hook/uhook_attributes_arginfo.h | 5 +- 6 files changed, 86 insertions(+), 76 deletions(-) diff --git a/ext/compatibility.h b/ext/compatibility.h index f85d747ea3..351a9043d6 100644 --- a/ext/compatibility.h +++ b/ext/compatibility.h @@ -95,31 +95,6 @@ static inline zend_long zval_get_long(zval *op) { #define PHP_DOUBLE_MAX_LENGTH 1080 #endif -enum { - ZEND_STR_TRACE, - ZEND_STR_LINE, - ZEND_STR_FILE, - ZEND_STR_MESSAGE, - ZEND_STR_CODE, - ZEND_STR_TYPE, - ZEND_STR_FUNCTION, - ZEND_STR_OBJECT, - ZEND_STR_CLASS, - ZEND_STR_OBJECT_OPERATOR, - ZEND_STR_PAAMAYIM_NEKUDOTAYIM, - ZEND_STR_ARGS, - ZEND_STR_UNKNOWN, - ZEND_STR_EVAL, - ZEND_STR_INCLUDE, - ZEND_STR_REQUIRE, - ZEND_STR_INCLUDE_ONCE, - ZEND_STR_REQUIRE_ONCE, - ZEND_STR_PREVIOUS, - ZEND_STR__LAST -}; -extern zend_string *ddtrace_known_strings[ZEND_STR__LAST]; -#define ZSTR_KNOWN(idx) ddtrace_known_strings[idx] - #define zend_declare_class_constant_ex(ce, name, value, access_type, doc_comment) zend_declare_class_constant(ce, ZSTR_VAL(name), ZSTR_LEN(name), value) // copied from PHP-7.0 source, but converting zend_long * to uint32_t * - assuming little endian @@ -210,14 +185,58 @@ static inline zend_string *php_base64_encode_str(const zend_string *str) { _key = _p->key; \ _val = _z; -#if PHP_VERSION_ID >= 70100 -#define ZSTR_KNOWN(idx) CG(known_strings)[idx] -#endif #else #define DD_PARAM_PROLOGUE Z_PARAM_PROLOGUE #endif #if PHP_VERSION_ID < 70300 +enum { +#if PHP_VERSION_ID < 70300 + ZEND_STR_NAME, +#if PHP_VERSION_ID >= 70100 +#define ZEND_STR_NAME (-1 - ZEND_STR_NAME) +#endif +#endif +#if PHP_VERSION_ID < 70200 + ZEND_STR_RESOURCE, +#if PHP_VERSION_ID >= 70100 +#define ZEND_STR_RESOURCE (-1 - ZEND_STR_RESOURCE) +#endif +#endif +#if PHP_VERSION_ID < 70100 + ZEND_STR_TRACE, + ZEND_STR_LINE, + ZEND_STR_FILE, + ZEND_STR_MESSAGE, + ZEND_STR_CODE, + ZEND_STR_TYPE, + ZEND_STR_FUNCTION, + ZEND_STR_OBJECT, + ZEND_STR_CLASS, + ZEND_STR_OBJECT_OPERATOR, + ZEND_STR_PAAMAYIM_NEKUDOTAYIM, + ZEND_STR_ARGS, + ZEND_STR_UNKNOWN, + ZEND_STR_EVAL, + ZEND_STR_INCLUDE, + ZEND_STR_REQUIRE, + ZEND_STR_INCLUDE_ONCE, + ZEND_STR_REQUIRE_ONCE, + ZEND_STR_PREVIOUS, +#endif + ZEND_STR__LAST +}; +extern zend_string *ddtrace_known_strings[ZEND_STR__LAST]; + +#undef ZSTR_KNOWN +#if PHP_VERSION_ID >= 70200 +#define ZSTR_KNOWN(idx) (idx < 0 ? ddtrace_known_strings[-1 - idx] : zend_known_strings[idx]) +#elif PHP_VERSION_ID >= 70100 +#define ZSTR_KNOWN(idx) (idx < 0 ? ddtrace_known_strings[-1 - idx] : CG(known_strings)[idx]) +#else +#define ZSTR_KNOWN(idx) ddtrace_known_strings[idx] +#endif + #define GC_ADDREF(x) (++GC_REFCOUNT(x)) #define GC_DELREF(x) (--GC_REFCOUNT(x)) #define GC_SET_REFCOUNT(x, rc) (GC_REFCOUNT(x) = rc) @@ -625,6 +644,12 @@ static zend_always_inline zend_result zend_call_function_with_return_value(zend_ #else #define hasThis() (Z_TYPE_P(ZEND_THIS) == IS_OBJECT) #endif + +static inline zend_class_entry *zend_register_internal_class_with_flags(zend_class_entry *class_entry, zend_class_entry *parent_ce, uint32_t ce_flags) { + zend_class_entry *register_class = zend_register_internal_class_ex(class_entry, parent_ce); + register_class->ce_flags |= ce_flags; + return register_class; +} #endif #endif // DD_COMPATIBILITY_H diff --git a/ext/ddtrace.c b/ext/ddtrace.c index 3e54a71422..6fe166d009 100644 --- a/ext/ddtrace.c +++ b/ext/ddtrace.c @@ -1300,9 +1300,16 @@ static void dd_disable_if_incompatible_sapi_detected(void) { } } -#if PHP_VERSION_ID < 70100 +#if PHP_VERSION_ID < 70300 zend_string *ddtrace_known_strings[ZEND_STR__LAST]; void ddtrace_init_known_strings(void) { +#undef ZEND_STR_NAME + ddtrace_known_strings[ZEND_STR_NAME] = zend_string_init_interned(ZEND_STRL("name"), 1); +#if PHP_VERSION_ID < 70200 +#undef ZEND_STR_RESOURCE + ddtrace_known_strings[ZEND_STR_RESOURCE] = zend_string_init_interned(ZEND_STRL("resource"), 1); +#endif +#if PHP_VERSION_ID < 70100 ddtrace_known_strings[ZEND_STR_TRACE] = zend_string_init_interned(ZEND_STRL("trace"), 1); ddtrace_known_strings[ZEND_STR_LINE] = zend_string_init_interned(ZEND_STRL("line"), 1); ddtrace_known_strings[ZEND_STR_FILE] = zend_string_init_interned(ZEND_STRL("file"), 1); @@ -1322,6 +1329,7 @@ void ddtrace_init_known_strings(void) { ddtrace_known_strings[ZEND_STR_INCLUDE_ONCE] = zend_string_init_interned(ZEND_STRL("include_once"), 1); ddtrace_known_strings[ZEND_STR_REQUIRE_ONCE] = zend_string_init_interned(ZEND_STRL("require_once"), 1); ddtrace_known_strings[ZEND_STR_PREVIOUS] = zend_string_init_interned(ZEND_STRL("previous"), 1); +#endif } #endif @@ -1342,6 +1350,10 @@ static PHP_MINIT_FUNCTION(ddtrace) { // Reset on every minit for `apachectl graceful`. dd_activate_once_control = (pthread_once_t)PTHREAD_ONCE_INIT; +#if PHP_VERSION_ID < 70300 + ddtrace_init_known_strings(); +#endif + zai_hook_minit(); zai_uhook_minit(module_number); #if PHP_VERSION_ID >= 80000 @@ -1355,10 +1367,6 @@ static PHP_MINIT_FUNCTION(ddtrace) { ddtrace_startup_hrtime(); #endif -#if PHP_VERSION_ID < 70100 - ddtrace_init_known_strings(); -#endif - register_ddtrace_symbols(module_number); REGISTER_INI_ENTRIES(); diff --git a/ext/ddtrace_arginfo.h b/ext/ddtrace_arginfo.h index a68293da30..8766e5292e 100644 --- a/ext/ddtrace_arginfo.h +++ b/ext/ddtrace_arginfo.h @@ -477,10 +477,6 @@ static const zend_function_entry class_DDTrace_SpanLink_methods[] = { ZEND_FE_END }; -static const zend_function_entry class_DDTrace_GitMetadata_methods[] = { - ZEND_FE_END -}; - static const zend_function_entry class_DDTrace_SpanData_methods[] = { ZEND_ME(DDTrace_SpanData, getDuration, arginfo_class_DDTrace_SpanData_getDuration, ZEND_ACC_PUBLIC) ZEND_ME(DDTrace_SpanData, getStartTime, arginfo_class_DDTrace_SpanData_getStartTime, ZEND_ACC_PUBLIC) @@ -489,14 +485,6 @@ static const zend_function_entry class_DDTrace_SpanData_methods[] = { ZEND_FE_END }; -static const zend_function_entry class_DDTrace_RootSpanData_methods[] = { - ZEND_FE_END -}; - -static const zend_function_entry class_DDTrace_SpanStack_methods[] = { - ZEND_FE_END -}; - static const zend_function_entry class_DDTrace_Integration_methods[] = { ZEND_RAW_FENTRY("init", NULL, arginfo_class_DDTrace_Integration_init, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT, NULL, NULL) ZEND_FE_END @@ -523,14 +511,12 @@ static zend_class_entry *register_class_DDTrace_SpanEvent(zend_class_entry *clas zend_class_entry ce, *class_entry; INIT_NS_CLASS_ENTRY(ce, "DDTrace", "SpanEvent", class_DDTrace_SpanEvent_methods); - class_entry = zend_register_internal_class_ex(&ce, NULL); + class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0); zend_class_implements(class_entry, 1, class_entry_JsonSerializable); zval property_name_default_value; ZVAL_UNDEF(&property_name_default_value); - zend_string *property_name_name = zend_string_init("name", sizeof("name") - 1, 1); - zend_declare_typed_property(class_entry, property_name_name, &property_name_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING)); - zend_string_release(property_name_name); + zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_NAME), &property_name_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING)); zval property_attributes_default_value; ZVAL_UNDEF(&property_attributes_default_value); @@ -552,7 +538,7 @@ static zend_class_entry *register_class_DDTrace_ExceptionSpanEvent(zend_class_en zend_class_entry ce, *class_entry; INIT_NS_CLASS_ENTRY(ce, "DDTrace", "ExceptionSpanEvent", class_DDTrace_ExceptionSpanEvent_methods); - class_entry = zend_register_internal_class_ex(&ce, class_entry_DDTrace_SpanEvent); + class_entry = zend_register_internal_class_with_flags(&ce, class_entry_DDTrace_SpanEvent, 0); zval property_exception_default_value; ZVAL_UNDEF(&property_exception_default_value); @@ -569,7 +555,7 @@ static zend_class_entry *register_class_DDTrace_SpanLink(zend_class_entry *class zend_class_entry ce, *class_entry; INIT_NS_CLASS_ENTRY(ce, "DDTrace", "SpanLink", class_DDTrace_SpanLink_methods); - class_entry = zend_register_internal_class_ex(&ce, NULL); + class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0); zend_class_implements(class_entry, 1, class_entry_JsonSerializable); zval property_traceId_default_value; @@ -609,8 +595,8 @@ static zend_class_entry *register_class_DDTrace_GitMetadata(void) { zend_class_entry ce, *class_entry; - INIT_NS_CLASS_ENTRY(ce, "DDTrace", "GitMetadata", class_DDTrace_GitMetadata_methods); - class_entry = zend_register_internal_class_ex(&ce, NULL); + INIT_NS_CLASS_ENTRY(ce, "DDTrace", "GitMetadata", NULL); + class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0); zval property_commitSha_default_value; ZVAL_EMPTY_STRING(&property_commitSha_default_value); @@ -632,19 +618,15 @@ static zend_class_entry *register_class_DDTrace_SpanData(void) zend_class_entry ce, *class_entry; INIT_NS_CLASS_ENTRY(ce, "DDTrace", "SpanData", class_DDTrace_SpanData_methods); - class_entry = zend_register_internal_class_ex(&ce, NULL); + class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0); zval property_name_default_value; ZVAL_EMPTY_STRING(&property_name_default_value); - zend_string *property_name_name = zend_string_init("name", sizeof("name") - 1, 1); - zend_declare_typed_property(class_entry, property_name_name, &property_name_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); - zend_string_release(property_name_name); + zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_NAME), &property_name_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); zval property_resource_default_value; ZVAL_EMPTY_STRING(&property_resource_default_value); - zend_string *property_resource_name = zend_string_init("resource", sizeof("resource") - 1, 1); - zend_declare_typed_property(class_entry, property_resource_name, &property_resource_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); - zend_string_release(property_resource_name); + zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_RESOURCE), &property_resource_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); zval property_service_default_value; ZVAL_EMPTY_STRING(&property_service_default_value); @@ -672,9 +654,7 @@ static zend_class_entry *register_class_DDTrace_SpanData(void) zval property_type_default_value; ZVAL_EMPTY_STRING(&property_type_default_value); - zend_string *property_type_name = zend_string_init("type", sizeof("type") - 1, 1); - zend_declare_typed_property(class_entry, property_type_name, &property_type_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); - zend_string_release(property_type_name); + zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_TYPE), &property_type_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL)); zval property_meta_default_value; ZVAL_EMPTY_ARRAY(&property_meta_default_value); @@ -740,8 +720,8 @@ static zend_class_entry *register_class_DDTrace_RootSpanData(zend_class_entry *c { zend_class_entry ce, *class_entry; - INIT_NS_CLASS_ENTRY(ce, "DDTrace", "RootSpanData", class_DDTrace_RootSpanData_methods); - class_entry = zend_register_internal_class_ex(&ce, class_entry_DDTrace_SpanData); + INIT_NS_CLASS_ENTRY(ce, "DDTrace", "RootSpanData", NULL); + class_entry = zend_register_internal_class_with_flags(&ce, class_entry_DDTrace_SpanData, 0); zval property_origin_default_value; ZVAL_UNDEF(&property_origin_default_value); @@ -805,8 +785,8 @@ static zend_class_entry *register_class_DDTrace_SpanStack(void) { zend_class_entry ce, *class_entry; - INIT_NS_CLASS_ENTRY(ce, "DDTrace", "SpanStack", class_DDTrace_SpanStack_methods); - class_entry = zend_register_internal_class_ex(&ce, NULL); + INIT_NS_CLASS_ENTRY(ce, "DDTrace", "SpanStack", NULL); + class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0); zval property_parent_default_value; ZVAL_UNDEF(&property_parent_default_value); diff --git a/ext/hook/uhook_arginfo.h b/ext/hook/uhook_arginfo.h index e0af7e161e..ddbf22a0fa 100644 --- a/ext/hook/uhook_arginfo.h +++ b/ext/hook/uhook_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 4b2f667462bc9e7bed94b2c9a479b85f3086b521 */ + * Stub hash: 74ab08e7f09c564fabb646706cb9ba0371026875 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_DDTrace_install_hook, 0, 1, IS_LONG, 0) ZEND_ARG_OBJ_TYPE_MASK(0, target, Closure|Generator, MAY_BE_STRING|MAY_BE_CALLABLE, NULL) @@ -83,7 +83,7 @@ static zend_class_entry *register_class_DDTrace_HookData(void) zend_class_entry ce, *class_entry; INIT_NS_CLASS_ENTRY(ce, "DDTrace", "HookData", class_DDTrace_HookData_methods); - class_entry = zend_register_internal_class_ex(&ce, NULL); + class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0); zval property_data_default_value; ZVAL_UNDEF(&property_data_default_value); @@ -99,9 +99,7 @@ static zend_class_entry *register_class_DDTrace_HookData(void) zval property_args_default_value; ZVAL_UNDEF(&property_args_default_value); - zend_string *property_args_name = zend_string_init("args", sizeof("args") - 1, 1); - zend_declare_typed_property(class_entry, property_args_name, &property_args_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY)); - zend_string_release(property_args_name); + zend_declare_typed_property(class_entry, ZSTR_KNOWN(ZEND_STR_ARGS), &property_args_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ARRAY)); zval property_returned_default_value; ZVAL_UNDEF(&property_returned_default_value); diff --git a/ext/hook/uhook_attributes.c b/ext/hook/uhook_attributes.c index fd2d51f3cd..e4ff5e5296 100644 --- a/ext/hook/uhook_attributes.c +++ b/ext/hook/uhook_attributes.c @@ -1,9 +1,9 @@ #include #include #include -#include "uhook_attributes_arginfo.h" #include "../ddtrace.h" #include "../configuration.h" +#include "uhook_attributes_arginfo.h" #include "uhook.h" #include diff --git a/ext/hook/uhook_attributes_arginfo.h b/ext/hook/uhook_attributes_arginfo.h index 4c64d765a8..fb6596cb00 100644 --- a/ext/hook/uhook_attributes_arginfo.h +++ b/ext/hook/uhook_attributes_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 90919c9c350e86acd6fe3c8d06753918d5e0572b */ + * Stub hash: 39cf4bf2cf4b4ec1c18f3ff8643b3ba7b4ad69a1 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DDTrace_Trace___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 0, "\"\"") @@ -23,8 +23,7 @@ static zend_class_entry *register_class_DDTrace_Trace(void) zend_class_entry ce, *class_entry; INIT_NS_CLASS_ENTRY(ce, "DDTrace", "Trace", class_DDTrace_Trace_methods); - class_entry = zend_register_internal_class_ex(&ce, NULL); - class_entry->ce_flags |= ZEND_ACC_FINAL; + class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_FINAL); zend_string *attribute_name_Attribute_class_DDTrace_Trace_0 = zend_string_init_interned("Attribute", sizeof("Attribute") - 1, 1); zend_attribute *attribute_Attribute_class_DDTrace_Trace_0 = zend_add_class_attribute(class_entry, attribute_name_Attribute_class_DDTrace_Trace_0, 1);