@@ -83,10 +83,7 @@ nruserfn_t* nr_php_wrap_callable_before_after(
83
83
zend_function * callable ,
84
84
nrspecialfn_t before_callback ,
85
85
nrspecialfn_t after_callback ) {
86
- char * name = NULL ;
87
- #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
88
- zend_observer_fcall_begin_handler * begin_handler ;
89
- #endif
86
+ char * name = NULL ;
90
87
91
88
/* creates a transient wraprec */
92
89
nruserfn_t * wraprec = nr_php_add_custom_tracer_callable (callable TSRMLS_CC );
@@ -104,33 +101,7 @@ nruserfn_t* nr_php_wrap_callable_before_after(
104
101
nr_free (name );
105
102
}
106
103
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
107
- if (callable ) {
108
- // Before messing with our handlers, we must ensure that the observer fields of the function are initialized
109
- begin_handler = (zend_observer_fcall_begin_handler * )& ZEND_OP_ARRAY_EXTENSION ((& (callable )-> common ), zend_observer_fcall_op_array_extension );
110
- // begin_handler will be NULL if the observer hasn't been installed yet.
111
- // *begin_Handler will be NULL if the function has not yet been called.
112
- if (begin_handler && * begin_handler ) {
113
- name = nr_php_function_debug_name (callable );
114
- php_printf ("AHHHHHHH %s\n" , name );
115
- nr_free (name );
116
- // It is okay to attempt to remove a handler that doesn't exist
117
- // TODO this could remove nr_php_observer_fcall_begin/end and then re-add it :)
118
- if (zend_observer_remove_begin_handler (callable , NRINI (tt_detail ) ?
119
- nr_php_observer_fcall_begin :
120
- nr_php_observer_empty_fcall_begin )) {
121
- zend_observer_add_begin_handler (callable , wraprec -> special_instrumentation_before ?
122
- (zend_observer_fcall_begin_handler )wraprec -> special_instrumentation_before :
123
- nr_php_observer_fcall_begin );
124
- }
125
- if (zend_observer_remove_end_handler (callable , NRINI (tt_detail ) ?
126
- nr_php_observer_fcall_end :
127
- nr_php_observer_empty_fcall_end )) {
128
- zend_observer_add_end_handler (callable , wraprec -> special_instrumentation ?
129
- (zend_observer_fcall_end_handler )wraprec -> special_instrumentation :
130
- nr_php_observer_fcall_end );
131
- }
132
- }
133
- }
104
+ nr_php_observer_overwrite_handlers (callable , wraprec );
134
105
#endif
135
106
136
107
return wraprec ;
@@ -172,9 +143,6 @@ nruserfn_t* nr_php_wrap_callable(zend_function* callable,
172
143
nrspecialfn_t callback TSRMLS_DC ) {
173
144
/* creates a transient wraprec */
174
145
nruserfn_t * wraprec = nr_php_add_custom_tracer_callable (callable TSRMLS_CC );
175
- #if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
176
- zend_observer_fcall_begin_handler * begin_handler ;
177
- #endif
178
146
179
147
if (wraprec && callback ) {
180
148
if ((NULL != wraprec -> special_instrumentation )
@@ -186,30 +154,7 @@ nruserfn_t* nr_php_wrap_callable(zend_function* callable,
186
154
} else {
187
155
wraprec -> special_instrumentation = callback ;
188
156
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
189
- if (callable ) {
190
- // Before messing with our handlers, we must ensure that the observer fields of the function are initialized
191
- begin_handler = (zend_observer_fcall_begin_handler * )& ZEND_OP_ARRAY_EXTENSION ((& (callable )-> common ), zend_observer_fcall_op_array_extension );
192
- // begin_handler will be NULL if the observer hasn't been installed yet.
193
- // *begin_Handler will be NULL if the function has not yet been called.
194
- if (begin_handler && * begin_handler ) {
195
- // It is okay to attempt to remove a handler that doesn't exist
196
- // TODO this could remove nr_php_observer_fcall_begin/end and then re-add it :)
197
- if (zend_observer_remove_begin_handler (callable , NRINI (tt_detail ) ?
198
- nr_php_observer_fcall_begin :
199
- nr_php_observer_empty_fcall_begin )) {
200
- zend_observer_add_begin_handler (callable , wraprec -> special_instrumentation_before ?
201
- (zend_observer_fcall_begin_handler )wraprec -> special_instrumentation_before :
202
- nr_php_observer_fcall_begin );
203
- }
204
- if (zend_observer_remove_end_handler (callable , NRINI (tt_detail ) ?
205
- nr_php_observer_fcall_end :
206
- nr_php_observer_empty_fcall_end )) {
207
- zend_observer_add_end_handler (callable , wraprec -> special_instrumentation ?
208
- (zend_observer_fcall_end_handler )wraprec -> special_instrumentation :
209
- nr_php_observer_fcall_end );
210
- }
211
- }
212
- }
157
+ nr_php_observer_overwrite_handlers (callable , wraprec );
213
158
#endif
214
159
}
215
160
}
0 commit comments