Skip to content

Commit 1ebe77c

Browse files
committed
chore(agent): remove obsolete PHP 7.0/7.1 ZEND_MODULE_API_NO usage
1 parent a333a7d commit 1ebe77c

23 files changed

+22
-622
lines changed

agent/fw_laravel_queue.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,6 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_process) {
620620
if (EG(exception)) {
621621
zval* exception_zval = NULL;
622622

623-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
624623
/*
625624
* On PHP 7, EG(exception) is stored as a zend_object, and is only wrapped
626625
* in a zval when it actually needs to be. Unfortunately, our error handling
@@ -640,12 +639,6 @@ NR_PHP_WRAPPER(nr_laravel_queue_worker_process) {
640639

641640
ZVAL_OBJ(&exception, EG(exception));
642641
exception_zval = &exception;
643-
#else
644-
/*
645-
* On PHP 5, the exception is just a regular old zval.
646-
*/
647-
exception_zval = EG(exception);
648-
#endif /* PHP7+ */
649642

650643
nr_php_error_record_exception(
651644
NRPRG(txn), exception_zval, NR_PHP_ERROR_PRIORITY_UNCAUGHT_EXCEPTION,
@@ -835,13 +828,8 @@ NR_PHP_WRAPPER(nr_laravel_queue_queue_createpayload) {
835828
/*
836829
* Finally, we change the string in the return value to our new JSON.
837830
*/
838-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
839831
zend_string_free(Z_STR_P(*retval_ptr));
840832
Z_STR_P(*retval_ptr) = zend_string_copy(Z_STR_P(json));
841-
#else
842-
efree(Z_STRVAL_PP(retval_ptr));
843-
nr_php_zval_str_len(*retval_ptr, Z_STRVAL_P(json), Z_STRLEN_P(json));
844-
#endif /* PHP7+ */
845833

846834
end:
847835
nr_php_zval_free(&payload);

agent/php_agent.c

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ static zval* nr_php_get_zval_object_property_with_class_internal(
2020
zval* object,
2121
zend_class_entry* ce,
2222
const char* cname TSRMLS_DC) {
23-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
2423
/*
2524
* Although the below notes still apply in principle, PHP 7 additionally broke
2625
* the API for zend_read_property by adding an rv parameter, which is used to
@@ -41,25 +40,6 @@ static zval* nr_php_get_zval_object_property_with_class_internal(
4140
if (&EG(uninitialized_zval) != data) {
4241
return data;
4342
}
44-
#else
45-
/*
46-
* This attempts to read uninitialized (or non existing) properties always
47-
* return uninitialized_zval_ptr, even in the case where we read a property
48-
* during pre-hook time on a constructor.
49-
*/
50-
zend_bool silent = 1; /* forces BP_VAR_IS semantics */
51-
#if ZEND_MODULE_API_NO >= ZEND_5_4_X_API_NO
52-
zval* data = zend_read_property(ce, object, cname, nr_strlen(cname),
53-
silent TSRMLS_CC);
54-
#else
55-
zval* data = zend_read_property(ce, object, (char*)nr_remove_const(cname),
56-
nr_strlen(cname), silent TSRMLS_CC);
57-
#endif /* PHP >= 5.4 */
58-
59-
if (EG(uninitialized_zval_ptr) != data) {
60-
return data;
61-
}
62-
#endif /* PHP7+ */
6343

6444
return NULL;
6545
}
@@ -149,32 +129,12 @@ int nr_php_object_has_method(zval* object, const char* lcname TSRMLS_DC) {
149129
return 0;
150130
} else {
151131
void* func;
152-
153-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
154132
zend_string* name_str = zend_string_init(vname, namelen, 0);
155133

156134
func = (void*)Z_OBJ_HT_P(object)->get_method(&Z_OBJ_P(object), name_str,
157135
NULL TSRMLS_CC);
158136

159137
zend_string_release(name_str);
160-
#elif ZEND_MODULE_API_NO >= ZEND_5_4_X_API_NO
161-
/*
162-
* This can leak if the object has a __call() method, as in that situation
163-
* only, zend_std_get_method() will indirectly allocate a new
164-
* zend_function in zend_get_user_call_function().
165-
*
166-
* We can't easily detect this, and the zend_function() is allocated via
167-
* emalloc(), so we're just going to let this slide and let the Zend
168-
* Engine clean it up at RSHUTDOWN. Note that this needs to be suppressed
169-
* in Valgrind, though.
170-
*/
171-
func = (void*)Z_OBJ_HT_P(object)->get_method(
172-
&object, vname, namelen,
173-
NULL TSRMLS_CC); /* nr_php_object_has_method */
174-
#else /* PHP < 5.4 */
175-
func = (void*)Z_OBJ_HT_P(object)->get_method(
176-
&object, vname, namelen TSRMLS_CC); /* nr_php_object_has_method */
177-
#endif
178138

179139
if (NULL == func) {
180140
return 0;
@@ -214,23 +174,11 @@ zend_function* nr_php_find_function(const char* name TSRMLS_DC) {
214174
* whereas PHP 7 only uses a single level of indirection.
215175
*/
216176
zend_class_entry* nr_php_find_class(const char* name TSRMLS_DC) {
217-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
218177
if (NULL == name) {
219178
return NULL;
220179
}
221180

222181
return (zend_class_entry*)nr_php_zend_hash_find_ptr(EG(class_table), name);
223-
#else
224-
zend_class_entry** ce_ptr = 0;
225-
226-
if (0 == name) {
227-
return 0;
228-
}
229-
230-
ce_ptr = (zend_class_entry**)nr_php_zend_hash_find_ptr(EG(class_table), name);
231-
232-
return ce_ptr ? *ce_ptr : NULL;
233-
#endif /* PHP7+ */
234182
}
235183

236184
zend_function* nr_php_find_class_method(const zend_class_entry* klass,
@@ -286,15 +234,9 @@ zend_function* nr_php_zval_to_function(zval* zv TSRMLS_DC) {
286234
return NULL;
287235
}
288236

289-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
290237
if (zend_is_callable_ex(zv, NULL, 0, NULL, &fcc, NULL)) {
291238
return fcc.function_handler;
292239
}
293-
#else
294-
if (zend_is_callable_ex(zv, NULL, 0, NULL, NULL, &fcc, NULL TSRMLS_CC)) {
295-
return fcc.function_handler;
296-
}
297-
#endif /* PHP7+ */
298240

299241
return NULL;
300242
}
@@ -348,41 +290,20 @@ zval* nr_php_get_user_func_arg(size_t requested_arg_index,
348290
return NULL;
349291
}
350292

351-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
352293
(void)arg_count_via_h;
353294

354295
if (requested_arg_index > ZEND_CALL_NUM_ARGS(execute_data)) {
355296
return NULL;
356297
}
357298

358299
arg_via_h = ZEND_CALL_ARG(execute_data, requested_arg_index);
359-
#else
360-
arg_via_h = nr_php_get_user_func_arg_via_h(
361-
requested_arg_index, &arg_count_via_h, NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
362-
#endif /* PHP7+ */
363300

364301
return arg_via_h;
365302
}
366303

367304
size_t nr_php_get_user_func_arg_count(NR_EXECUTE_PROTO TSRMLS_DC) {
368-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
369305
NR_UNUSED_FUNC_RETURN_VALUE;
370306
return (size_t)ZEND_CALL_NUM_ARGS(execute_data);
371-
#else
372-
int arg_count_via_h = -1;
373-
374-
if (NULL
375-
== nr_php_get_user_func_arg_via_h(1, &arg_count_via_h,
376-
NR_EXECUTE_ORIG_ARGS TSRMLS_CC)) {
377-
return 0;
378-
} else if (arg_count_via_h < 0) {
379-
nrl_verbosedebug(NRL_AGENT, "%s: unexpected argument count %d", __func__,
380-
arg_count_via_h);
381-
return 0;
382-
}
383-
384-
return (size_t)arg_count_via_h;
385-
#endif /* PHP7+ */
386307
}
387308

388309
zend_execute_data* nr_php_get_caller_execute_data(NR_EXECUTE_PROTO,
@@ -411,30 +332,18 @@ zend_execute_data* nr_php_get_caller_execute_data(NR_EXECUTE_PROTO,
411332
ced = ced->prev_execute_data;
412333
}
413334

414-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
415335
if ((NULL == ced) || (NULL == ced->opline)) {
416336
return NULL;
417337
}
418-
#else
419-
if ((NULL == ced) || (NULL == ced->op_array)) {
420-
return NULL;
421-
}
422-
#endif /* PHP7+ */
423338

424339
if ((ZEND_DO_FCALL != ced->opline->opcode)
425340
&& (ZEND_DO_FCALL_BY_NAME != ced->opline->opcode)) {
426341
return NULL;
427342
}
428343

429-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
430344
if (NULL == ced->func) {
431345
return NULL;
432346
}
433-
#else
434-
if (0 == ced->function_state.function) {
435-
return NULL;
436-
}
437-
#endif /* PHP7+ */
438347

439348
return ced;
440349
}
@@ -448,17 +357,12 @@ const zend_function* nr_php_get_caller(NR_EXECUTE_PROTO,
448357
return NULL;
449358
}
450359

451-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
452360
return ped->func;
453-
#else
454-
return ped->function_state.function;
455-
#endif /* PHP7+ */
456361
}
457362

458363
zval* nr_php_get_active_php_variable(const char* name TSRMLS_DC) {
459364
HashTable* table;
460365

461-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
462366
table = zend_rebuild_symbol_table();
463367

464368
/*
@@ -472,10 +376,6 @@ zval* nr_php_get_active_php_variable(const char* name TSRMLS_DC) {
472376
* https://nikic.github.io/2015/06/19/Internal-value-representation-in-PHP-7-part-2.html#indirect-zvals
473377
*/
474378
return nr_php_zval_direct(nr_php_zend_hash_find(table, name));
475-
#else
476-
table = EG(active_symbol_table);
477-
return nr_php_zend_hash_find(table, name);
478-
#endif /* PHP7+ */
479379
}
480380

481381
int nr_php_silence_errors(TSRMLS_D) {
@@ -491,7 +391,6 @@ void nr_php_restore_errors(int error_reporting TSRMLS_DC) {
491391
}
492392

493393
zval* nr_php_get_constant(const char* name TSRMLS_DC) {
494-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
495394
zval* constant;
496395
zval* copy = NULL;
497396
zend_string* name_str;
@@ -515,31 +414,9 @@ zval* nr_php_get_constant(const char* name TSRMLS_DC) {
515414
ZVAL_DUP(copy, constant);
516415

517416
return copy;
518-
#else
519-
nr_string_len_t len;
520-
int rv;
521-
zval* constant = NULL;
522-
523-
if (NULL == name) {
524-
return NULL;
525-
}
526-
527-
len = nr_strlen(name);
528-
constant = nr_php_zval_alloc();
529-
530-
/* zend_get_constant returns 0 and 1 (not SUCCESS or FAILURE) */
531-
rv = zend_get_constant(name, len, constant TSRMLS_CC);
532-
if (0 == rv) {
533-
nr_php_zval_free(&constant);
534-
return NULL;
535-
}
536-
537-
return constant;
538-
#endif /* PHP7+ */
539417
}
540418

541419
zval* nr_php_get_class_constant(const zend_class_entry* ce, const char* name) {
542-
#if ZEND_MODULE_API_NO >= ZEND_7_1_X_API_NO
543420
zend_class_constant* constant = NULL;
544421
zval* copy = NULL;
545422

@@ -555,29 +432,6 @@ zval* nr_php_get_class_constant(const zend_class_entry* ce, const char* name) {
555432
}
556433

557434
return copy;
558-
#else
559-
zval* constant = NULL;
560-
zval* copy = NULL;
561-
562-
if (NULL == ce) {
563-
return NULL;
564-
}
565-
566-
constant = nr_php_zend_hash_find(&(ce->constants_table), name);
567-
568-
if (constant) {
569-
copy = nr_php_zval_alloc();
570-
571-
/*
572-
* PHP 7.0 usually returns an IS_REF. We need to unwrap to ensure that we
573-
* duplicate the concrete value, otherwise the caller will end up freeing a
574-
* value that it doesn't own, and bad things will happen.
575-
*/
576-
ZVAL_DUP(copy, nr_php_zval_real_value(constant));
577-
}
578-
579-
return copy;
580-
#endif
581435
}
582436

583437
char* nr_php_get_object_constant(zval* app, const char* name) {
@@ -649,17 +503,13 @@ int nr_php_is_zval_named_constant(const zval* zv, const char* name TSRMLS_DC) {
649503
}
650504

651505
int nr_php_zend_is_auto_global(const char* name, size_t name_len TSRMLS_DC) {
652-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
653506
zend_bool rv;
654507
zend_string* zs = zend_string_init(name, name_len, 0);
655508

656509
rv = zend_is_auto_global(zs);
657510

658511
zend_string_free(zs);
659512
return rv;
660-
#else
661-
return (int)zend_is_auto_global(name, (int)name_len TSRMLS_CC);
662-
#endif /* PHP7+ */
663513
}
664514

665515
const char* nr_php_use_license(const char* api_license TSRMLS_DC) {
@@ -687,11 +537,7 @@ char* nr_php_get_server_global(const char* name TSRMLS_DC) {
687537
return NULL;
688538
}
689539

690-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
691540
global = &(PG(http_globals)[TRACK_VARS_SERVER]);
692-
#else
693-
global = PG(http_globals)[TRACK_VARS_SERVER];
694-
#endif
695541

696542
if (!nr_php_is_zval_valid_array(global)) {
697543
return NULL;
@@ -1014,11 +860,7 @@ char* nr_php_function_debug_name(const zend_function* func) {
1014860

1015861
if ((ZEND_USER_FUNCTION == func->type)
1016862
&& (func->common.fn_flags & ZEND_ACC_CLOSURE)) {
1017-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
1018863
const char* filename = ZSTR_VAL(func->op_array.filename);
1019-
#else
1020-
const char* filename = func->op_array.filename;
1021-
#endif /* PHP7+ */
1022864
char* orig_name = name;
1023865

1024866
name = nr_formatf("%s declared at %s:%d", orig_name, NRSAFESTR(filename),

0 commit comments

Comments
 (0)