Skip to content

Commit

Permalink
Compatibility with newest arginfo gen_stub from PHP 8.4 (#2973)
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Weinand <[email protected]>
  • Loading branch information
bwoebi authored Nov 23, 2024
1 parent d123740 commit 6280989
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 76 deletions.
81 changes: 53 additions & 28 deletions ext/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
18 changes: 13 additions & 5 deletions ext/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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();

Expand Down
48 changes: 14 additions & 34 deletions ext/ddtrace_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions ext/hook/uhook_arginfo.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ext/hook/uhook_attributes.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <php.h>
#include <Zend/zend_attributes.h>
#include <Zend/zend_smart_str.h>
#include "uhook_attributes_arginfo.h"
#include "../ddtrace.h"
#include "../configuration.h"
#include "uhook_attributes_arginfo.h"
#include "uhook.h"

#include <hook/hook.h>
Expand Down
5 changes: 2 additions & 3 deletions ext/hook/uhook_attributes_arginfo.h
Original file line number Diff line number Diff line change
@@ -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, "\"\"")
Expand All @@ -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);
Expand Down

0 comments on commit 6280989

Please sign in to comment.