Skip to content

Commit 29ed52c

Browse files
committed
chore(agent): remove obsolete PHP 7.0/7.1 ZEND_MODULE_API_NO usage
1 parent f12e255 commit 29ed52c

23 files changed

+22
-621
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
}
@@ -462,41 +404,20 @@ zval* nr_php_get_user_func_arg(size_t requested_arg_index,
462404
return NULL;
463405
}
464406

465-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
466407
(void)arg_count_via_h;
467408

468409
if (requested_arg_index > ZEND_CALL_NUM_ARGS(execute_data)) {
469410
return NULL;
470411
}
471412

472413
arg_via_h = ZEND_CALL_ARG(execute_data, requested_arg_index);
473-
#else
474-
arg_via_h = nr_php_get_user_func_arg_via_h(
475-
requested_arg_index, &arg_count_via_h, NR_EXECUTE_ORIG_ARGS TSRMLS_CC);
476-
#endif /* PHP7+ */
477414

478415
return arg_via_h;
479416
}
480417

481418
size_t nr_php_get_user_func_arg_count(NR_EXECUTE_PROTO TSRMLS_DC) {
482-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
483419
NR_UNUSED_FUNC_RETURN_VALUE;
484420
return (size_t)ZEND_CALL_NUM_ARGS(execute_data);
485-
#else
486-
int arg_count_via_h = -1;
487-
488-
if (NULL
489-
== nr_php_get_user_func_arg_via_h(1, &arg_count_via_h,
490-
NR_EXECUTE_ORIG_ARGS TSRMLS_CC)) {
491-
return 0;
492-
} else if (arg_count_via_h < 0) {
493-
nrl_verbosedebug(NRL_AGENT, "%s: unexpected argument count %d", __func__,
494-
arg_count_via_h);
495-
return 0;
496-
}
497-
498-
return (size_t)arg_count_via_h;
499-
#endif /* PHP7+ */
500421
}
501422

502423
zend_execute_data* nr_php_get_caller_execute_data(NR_EXECUTE_PROTO,
@@ -525,30 +446,18 @@ zend_execute_data* nr_php_get_caller_execute_data(NR_EXECUTE_PROTO,
525446
ced = ced->prev_execute_data;
526447
}
527448

528-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
529449
if ((NULL == ced) || (NULL == ced->opline)) {
530450
return NULL;
531451
}
532-
#else
533-
if ((NULL == ced) || (NULL == ced->op_array)) {
534-
return NULL;
535-
}
536-
#endif /* PHP7+ */
537452

538453
if ((ZEND_DO_FCALL != ced->opline->opcode)
539454
&& (ZEND_DO_FCALL_BY_NAME != ced->opline->opcode)) {
540455
return NULL;
541456
}
542457

543-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
544458
if (NULL == ced->func) {
545459
return NULL;
546460
}
547-
#else
548-
if (0 == ced->function_state.function) {
549-
return NULL;
550-
}
551-
#endif /* PHP7+ */
552461

553462
return ced;
554463
}
@@ -562,17 +471,12 @@ const zend_function* nr_php_get_caller(NR_EXECUTE_PROTO,
562471
return NULL;
563472
}
564473

565-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
566474
return ped->func;
567-
#else
568-
return ped->function_state.function;
569-
#endif /* PHP7+ */
570475
}
571476

572477
zval* nr_php_get_active_php_variable(const char* name TSRMLS_DC) {
573478
HashTable* table;
574479

575-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
576480
table = zend_rebuild_symbol_table();
577481

578482
/*
@@ -586,10 +490,6 @@ zval* nr_php_get_active_php_variable(const char* name TSRMLS_DC) {
586490
* https://nikic.github.io/2015/06/19/Internal-value-representation-in-PHP-7-part-2.html#indirect-zvals
587491
*/
588492
return nr_php_zval_direct(nr_php_zend_hash_find(table, name));
589-
#else
590-
table = EG(active_symbol_table);
591-
return nr_php_zend_hash_find(table, name);
592-
#endif /* PHP7+ */
593493
}
594494

595495
int nr_php_silence_errors(TSRMLS_D) {
@@ -605,7 +505,6 @@ void nr_php_restore_errors(int error_reporting TSRMLS_DC) {
605505
}
606506

607507
zval* nr_php_get_constant(const char* name TSRMLS_DC) {
608-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
609508
zval* constant;
610509
zval* copy = NULL;
611510
zend_string* name_str;
@@ -629,31 +528,9 @@ zval* nr_php_get_constant(const char* name TSRMLS_DC) {
629528
ZVAL_DUP(copy, constant);
630529

631530
return copy;
632-
#else
633-
nr_string_len_t len;
634-
int rv;
635-
zval* constant = NULL;
636-
637-
if (NULL == name) {
638-
return NULL;
639-
}
640-
641-
len = nr_strlen(name);
642-
constant = nr_php_zval_alloc();
643-
644-
/* zend_get_constant returns 0 and 1 (not SUCCESS or FAILURE) */
645-
rv = zend_get_constant(name, len, constant TSRMLS_CC);
646-
if (0 == rv) {
647-
nr_php_zval_free(&constant);
648-
return NULL;
649-
}
650-
651-
return constant;
652-
#endif /* PHP7+ */
653531
}
654532

655533
zval* nr_php_get_class_constant(const zend_class_entry* ce, const char* name) {
656-
#if ZEND_MODULE_API_NO >= ZEND_7_1_X_API_NO
657534
zend_class_constant* constant = NULL;
658535
zval* copy = NULL;
659536

@@ -669,29 +546,6 @@ zval* nr_php_get_class_constant(const zend_class_entry* ce, const char* name) {
669546
}
670547

671548
return copy;
672-
#else
673-
zval* constant = NULL;
674-
zval* copy = NULL;
675-
676-
if (NULL == ce) {
677-
return NULL;
678-
}
679-
680-
constant = nr_php_zend_hash_find(&(ce->constants_table), name);
681-
682-
if (constant) {
683-
copy = nr_php_zval_alloc();
684-
685-
/*
686-
* PHP 7.0 usually returns an IS_REF. We need to unwrap to ensure that we
687-
* duplicate the concrete value, otherwise the caller will end up freeing a
688-
* value that it doesn't own, and bad things will happen.
689-
*/
690-
ZVAL_DUP(copy, nr_php_zval_real_value(constant));
691-
}
692-
693-
return copy;
694-
#endif
695549
}
696550

697551
char* nr_php_get_object_constant(zval* app, const char* name) {
@@ -763,17 +617,13 @@ int nr_php_is_zval_named_constant(const zval* zv, const char* name TSRMLS_DC) {
763617
}
764618

765619
int nr_php_zend_is_auto_global(const char* name, size_t name_len TSRMLS_DC) {
766-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
767620
zend_bool rv;
768621
zend_string* zs = zend_string_init(name, name_len, 0);
769622

770623
rv = zend_is_auto_global(zs);
771624

772625
zend_string_free(zs);
773626
return rv;
774-
#else
775-
return (int)zend_is_auto_global(name, (int)name_len TSRMLS_CC);
776-
#endif /* PHP7+ */
777627
}
778628

779629
const char* nr_php_use_license(const char* api_license TSRMLS_DC) {
@@ -801,11 +651,7 @@ char* nr_php_get_server_global(const char* name TSRMLS_DC) {
801651
return NULL;
802652
}
803653

804-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
805654
global = &(PG(http_globals)[TRACK_VARS_SERVER]);
806-
#else
807-
global = PG(http_globals)[TRACK_VARS_SERVER];
808-
#endif
809655

810656
if (!nr_php_is_zval_valid_array(global)) {
811657
return NULL;
@@ -1128,11 +974,7 @@ char* nr_php_function_debug_name(const zend_function* func) {
1128974

1129975
if ((ZEND_USER_FUNCTION == func->type)
1130976
&& (func->common.fn_flags & ZEND_ACC_CLOSURE)) {
1131-
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
1132977
const char* filename = ZSTR_VAL(func->op_array.filename);
1133-
#else
1134-
const char* filename = func->op_array.filename;
1135-
#endif /* PHP7+ */
1136978
char* orig_name = name;
1137979

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

0 commit comments

Comments
 (0)