-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify agent to conform with new PHP 8.0 internal API changes #49
Conversation
… of zval* and zend_string* instead of zval* for property names. Modified agent to toggle between zval and zend_object depending on PHP8 or not.
…on is never allowed. If you wish to pass (or allow passing) arguments by reference, explicitly create those arguments as references using ZEND_MAKE_REF. This function is passed as a pointer in the agent here. This removal also affects call_user_function_ex() (example in agent), which should be replaced by call_user_function().
…nged. The current changes do not register a callback.
…_function`) has been removed `zend_API.c.`. In PHP 8, a disabled function is indistinguishable from a function that does not exist.
…he recommended function; however, it no longer gracefully handled the case of the 2nd parameter being passed in as NULL. We no longer assume graceful handling, and now we check for NULL before calling the function.
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */ | ||
#define PHP7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We updated our usages of PHP7
to use the more complex ifdef
in order to make it clear we were referring to PHP version 7.0 or greater. This define doesn't allow for us to target things just to PHP 7 (and not 8 or 5). Should we update this definition to exclude PHP 8?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if we are sure we've replaced all PHP7 ifdef
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still a bunch of PHP7
ifdefs left. I filed issue #56 to track the need to clean up our ifdef usage so it doesn't block this PR.
ok jenkins |
@@ -1,4 +1,4 @@ | |||
#!/bin/bash | |||
make -j $(nproc) all | |||
make -j $(nproc) run_tests | |||
make -j run_tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I never knew about -j
without any flags 🧠
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes two of us! That was a typo, but apparently -j
without flags is a thing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I thought it was intentional for maximum test pedal to the metal 😆
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */ | ||
/* PHP 8 expects zend_object not zval */ | ||
#define ZVAL_OR_ZEND_OBJECT(x) Z_OBJ(*x) | ||
#else | ||
#define ZVAL_OR_ZEND_OBJECT(x) x | ||
#endif /* PHP8+ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
/* | ||
* The TSRMLS_* functions included below have actually been voided out since PHP | ||
* 7.0. They were formally removed in PHP 8.0 but we still support in our code, | ||
* so we need to add the voided out macros here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect solution!
#ifdef PHP8 | ||
add_assoc_zval(arr, key, ©); | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context in case anyone else was confused by this
…ound definition of `newrelic_arginfo_void` since all usages of this were also wrapped in PHP 8 `if` statements which would then result in an used arg error/warning on some builds.
ok jenkins |
1 similar comment
ok jenkins |
…ic#49) Fixes newrelic#46 * Added defines for PHP8. * Added `TSRMLS` macros. * The Object Handlers API was changed to receive zend_object* instead of zval* and zend_string* instead of zval* for property names. Modified agent to toggle between zval and zend_object depending on PHP8 or not. * The zend_fcall_info no_separation flag has been removed, and separation is never allowed. If you wish to pass (or allow passing) arguments by reference, explicitly create those arguments as references using ZEND_MAKE_REF. This function is passed as a pointer in the agent here. This removal also affects call_user_function_ex() (example in agent), which should be replaced by call_user_function(). * Error notifications have a new API and the callback signature has changed. The current changes do not register a callback. * `display_disabled_function` (and therefore also `zif_display_disabled_function`) has been removed `zend_API.c.`. In PHP 8, a disabled function is indistinguishable from a function that does not exist. * Added `newrelic_arginfo_void` as `PHP_FE` no longer allows `0` as an argument. * Modified unit tests to work with PHP8. * `call_user_function_ex` was removed and `call_user_function` became the recommended function; however, it no longer gracefully handled the case of the 2nd parameter being passed in as NULL. We no longer assume graceful handling, and now we check for NULL before calling the function. * Take into account new `libphp.so` and `libphp.a` naming scheme. * `zend_get_resource_handle` now takes a different type parameter. * Added `#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */` around definition of `newrelic_arginfo_void` since all usages of this were also wrapped in PHP 8 `if` statements which would then result in an used arg error/warning on some builds. * Update opcode inspection to properly detect calls to `call_user_func_array`. On PHP 8.0, there's an additional opcode added when the function is compiled. Co-authored-by: Joshua Benuck <[email protected]>
Fixes #46 * Added defines for PHP8. * Added `TSRMLS` macros. * The Object Handlers API was changed to receive zend_object* instead of zval* and zend_string* instead of zval* for property names. Modified agent to toggle between zval and zend_object depending on PHP8 or not. * The zend_fcall_info no_separation flag has been removed, and separation is never allowed. If you wish to pass (or allow passing) arguments by reference, explicitly create those arguments as references using ZEND_MAKE_REF. This function is passed as a pointer in the agent here. This removal also affects call_user_function_ex() (example in agent), which should be replaced by call_user_function(). * Error notifications have a new API and the callback signature has changed. The current changes do not register a callback. * `display_disabled_function` (and therefore also `zif_display_disabled_function`) has been removed `zend_API.c.`. In PHP 8, a disabled function is indistinguishable from a function that does not exist. * Added `newrelic_arginfo_void` as `PHP_FE` no longer allows `0` as an argument. * Modified unit tests to work with PHP8. * `call_user_function_ex` was removed and `call_user_function` became the recommended function; however, it no longer gracefully handled the case of the 2nd parameter being passed in as NULL. We no longer assume graceful handling, and now we check for NULL before calling the function. * Take into account new `libphp.so` and `libphp.a` naming scheme. * `zend_get_resource_handle` now takes a different type parameter. * Added `#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */` around definition of `newrelic_arginfo_void` since all usages of this were also wrapped in PHP 8 `if` statements which would then result in an used arg error/warning on some builds. * Update opcode inspection to properly detect calls to `call_user_func_array`. On PHP 8.0, there's an additional opcode added when the function is compiled. Co-authored-by: Joshua Benuck <[email protected]>
Fixes #46 * Added defines for PHP8. * Added `TSRMLS` macros. * The Object Handlers API was changed to receive zend_object* instead of zval* and zend_string* instead of zval* for property names. Modified agent to toggle between zval and zend_object depending on PHP8 or not. * The zend_fcall_info no_separation flag has been removed, and separation is never allowed. If you wish to pass (or allow passing) arguments by reference, explicitly create those arguments as references using ZEND_MAKE_REF. This function is passed as a pointer in the agent here. This removal also affects call_user_function_ex() (example in agent), which should be replaced by call_user_function(). * Error notifications have a new API and the callback signature has changed. The current changes do not register a callback. * `display_disabled_function` (and therefore also `zif_display_disabled_function`) has been removed `zend_API.c.`. In PHP 8, a disabled function is indistinguishable from a function that does not exist. * Added `newrelic_arginfo_void` as `PHP_FE` no longer allows `0` as an argument. * Modified unit tests to work with PHP8. * `call_user_function_ex` was removed and `call_user_function` became the recommended function; however, it no longer gracefully handled the case of the 2nd parameter being passed in as NULL. We no longer assume graceful handling, and now we check for NULL before calling the function. * Take into account new `libphp.so` and `libphp.a` naming scheme. * `zend_get_resource_handle` now takes a different type parameter. * Added `#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */` around definition of `newrelic_arginfo_void` since all usages of this were also wrapped in PHP 8 `if` statements which would then result in an used arg error/warning on some builds. * Update opcode inspection to properly detect calls to `call_user_func_array`. On PHP 8.0, there's an additional opcode added when the function is compiled. Co-authored-by: Joshua Benuck <[email protected]>
…ic#49) Fixes newrelic#46 * Added defines for PHP8. * Added `TSRMLS` macros. * The Object Handlers API was changed to receive zend_object* instead of zval* and zend_string* instead of zval* for property names. Modified agent to toggle between zval and zend_object depending on PHP8 or not. * The zend_fcall_info no_separation flag has been removed, and separation is never allowed. If you wish to pass (or allow passing) arguments by reference, explicitly create those arguments as references using ZEND_MAKE_REF. This function is passed as a pointer in the agent here. This removal also affects call_user_function_ex() (example in agent), which should be replaced by call_user_function(). * Error notifications have a new API and the callback signature has changed. The current changes do not register a callback. * `display_disabled_function` (and therefore also `zif_display_disabled_function`) has been removed `zend_API.c.`. In PHP 8, a disabled function is indistinguishable from a function that does not exist. * Added `newrelic_arginfo_void` as `PHP_FE` no longer allows `0` as an argument. * Modified unit tests to work with PHP8. * `call_user_function_ex` was removed and `call_user_function` became the recommended function; however, it no longer gracefully handled the case of the 2nd parameter being passed in as NULL. We no longer assume graceful handling, and now we check for NULL before calling the function. * Take into account new `libphp.so` and `libphp.a` naming scheme. * `zend_get_resource_handle` now takes a different type parameter. * Added `#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */` around definition of `newrelic_arginfo_void` since all usages of this were also wrapped in PHP 8 `if` statements which would then result in an used arg error/warning on some builds. * Update opcode inspection to properly detect calls to `call_user_func_array`. On PHP 8.0, there's an additional opcode added when the function is compiled. Co-authored-by: Joshua Benuck <[email protected]>
Items addressed:
php-src
since PHP7.0, but were officially removed in PHP8.0)display_disabled_function
has been removed from (and thereforezif_display_disabled_function
)zend_API.c.
. In PHP 8, a disabled function is indistinguishable from a function that does not exist.newrelic_arginfo_void
asPHP_FE
no longer allows0
as an argument.libphp.so
andlibphp.a
naming scheme.call_user_function_ex
was removed andcall_user_function
call_user_function
willzend_get_resource_handle
now takes a different type parameter.Remaining items:
call_user_function_ex
call to thecall_user_function
call in the agent functionnr_php_call_user_func
:With
call_user_function_ex
, we used to use theno_separation flag = 0
, which meant PHP itself would internally manipulate ours args appropriately.With
call_user_function
the logic has changed here:https://github.com/php/php-src/blob/master/Zend/zend_execute_API.c#L770
Currently any UNIT TEST call to
nr_php_call
or a direct call tonr_php_call_user_func
that has parameters will choke because the internal handling no longer wraps them as proper zval refs.Before we pass the params to PHP function
call_user_function
, we probably need to do something like:This code could either be placed directly in the
nr_php_call_user_func
function or be an inline function declared inphp_zval.h
like:Additionally, calls to call_user_func_array have changed (as evidenced by this https://www.drupal.org/project/drupal/issues/3174022 discussion), and we still need to ensure any tests and/or wrappers handle it accordingly.
The API internals ticket still has a few allocated days left for someone to pick up.
The unit tests will need to be updated to take into account the changes.
Fixes #46