Skip to content

Commit d2680ad

Browse files
committed
use op_array extension only for PHPs 8.0+
1 parent fd5c35b commit d2680ad

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

agent/php_execute.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
* conditions wherever possible.
9494
*/
9595

96+
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO
9697
static inline nruserfn_t* nr_php_get_wraprec_from_op_array_extension(const char* fn, zend_function* zf) {
9798
nruserfn_t* wraprec = (nruserfn_t*)ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle));
9899
nrl_verbosedebug(NRL_AGENT, "%s from %s, op_array_extension=%p, wraprec=%p, wraprec->pid=%d", __func__, fn, ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle)), wraprec, wraprec? wraprec->pid : 0);
@@ -102,6 +103,7 @@ static inline nruserfn_t* nr_php_get_wraprec_from_op_array_extension(const char*
102103
}
103104
return wraprec;
104105
}
106+
#endif
105107

106108
static void nr_php_show_exec_return(NR_EXECUTE_PROTO TSRMLS_DC);
107109
static int nr_php_show_exec_indentation(TSRMLS_D);
@@ -608,8 +610,13 @@ static void nr_php_show_exec(NR_EXECUTE_PROTO TSRMLS_DC) {
608610
char argstr[NR_EXECUTE_DEBUG_STRBUFSZ];
609611
const char* filename = nr_php_op_array_file_name(NR_OP_ARRAY);
610612
const char* function_name = nr_php_op_array_function_name(NR_OP_ARRAY);
613+
#if ZEND_MODULE_API_NO >= ZEND_7_4_X_API_NO
614+
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO
611615
nruserfn_t* wr = nr_php_get_wraprec_from_op_array_extension(__func__, execute_data->func);
612-
616+
#else
617+
nruserfn_t* wr = nr_php_get_wraprec(execute_data->func);
618+
#endif
619+
#endif
613620
argstr[0] = '\0';
614621

615622
if (NR_OP_ARRAY->scope) {

agent/php_globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ typedef struct _nrphpglobals_t {
5252
#else
5353
int zend_offset; /* Zend extension offset */
5454
#endif
55+
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
5556
int op_array_extension_handle; /* Zend op_array extension handle to attach agent's data to function */
57+
#endif
5658
int done_instrumentation; /* Set to true if we have installed instrumentation
5759
handlers */
5860
nrtime_t expensive_min; /* newrelic.special.expensive_node_min */

agent/php_minit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,9 @@ PHP_MINIT_FUNCTION(newrelic) {
720720
nr_php_set_opcode_handlers();
721721

722722
nrl_debug(NRL_INIT, "MINIT processing done");
723-
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 7.4+ */
723+
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
724724
NR_PHP_PROCESS_GLOBALS(zend_offset) = zend_get_resource_handle(dummy);
725-
#if ZEND_MODULE_API_NO >= ZEND_8_4_X_API_NO /* PHP 7.4+ */
725+
#if ZEND_MODULE_API_NO >= ZEND_8_4_X_API_NO /* PHP 8.4+ */
726726
NR_PHP_PROCESS_GLOBALS(op_array_extension_handle) = zend_get_internal_function_extension_handle("newrelic");
727727
#else
728728
NR_PHP_PROCESS_GLOBALS(op_array_extension_handle) = zend_get_op_array_extension_handle("newrelic");

agent/php_user_instrument.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static nr_php_wraprec_hashmap_t* user_function_wrappers;
130130
static inline void nr_php_wraprec_lookup_set(nruserfn_t* wr,
131131
zend_function* zf) {
132132
nr_php_wraprec_hashmap_update(user_function_wrappers, zf, wr);
133+
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
133134
// for situation when wraprec is added after first execution of the function
134135
// store the wraprec in the op_array extension for the duration of the request for later lookup
135136
// The op_array extension slot for function may not be initialized yet because it is
@@ -139,7 +140,7 @@ static inline void nr_php_wraprec_lookup_set(nruserfn_t* wr,
139140
if (NULL != RUN_TIME_CACHE(&zf->op_array)) {
140141
ZEND_OP_ARRAY_EXTENSION(&zf->op_array, NR_PHP_PROCESS_GLOBALS(op_array_extension_handle)) = wr;
141142
}
142-
143+
#endif
143144
}
144145
static inline nruserfn_t* nr_php_wraprec_lookup_get(zend_function* zf) {
145146
nruserfn_t* wraprec = NULL;

0 commit comments

Comments
 (0)