From cec08d8da175666c499275d2b4a6a40e40295764 Mon Sep 17 00:00:00 2001 From: Michal Nowacki Date: Tue, 8 Aug 2023 12:02:15 -0400 Subject: [PATCH] improve code readability --- agent/php_wrapper.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/agent/php_wrapper.c b/agent/php_wrapper.c index 225098b5e..30403a194 100644 --- a/agent/php_wrapper.c +++ b/agent/php_wrapper.c @@ -164,6 +164,16 @@ nruserfn_t* nr_php_wrap_callable(zend_function* callable, return wraprec; } +#if ZEND_MODULE_API_NO < ZEND_7_0_X_API_NO +typedef nr_php_compat_zend_string_t char; +#define NR_PHP_COMPAT_ZEND_STRING_VALUE(s) (s) +#define NR_PHP_COMPAT_ZEND_STRING_LEN(s) nr_strlen((s)) +#else +typedef nr_php_compat_zend_string_t zend_string; +#define NR_PHP_COMPAT_ZEND_STRING_VALUE(s) ZEND_STRING_VALUE(name) +#define NR_PHP_COMPAT_ZEND_STRING_LEN(s) ZEND_STRING_LEN(name) +#endif + /* * When wrapping a generic callable, it is currently only desired that a * wraprec's internals be evaluated BEFORE for the callable's. As such, @@ -174,11 +184,7 @@ nruserfn_t* nr_php_wrap_callable(zend_function* callable, */ nruserfn_t* nr_php_wrap_generic_callable(zval* callable, nrspecialfn_t callback TSRMLS_DC) { -#if ZEND_MODULE_API_NO < ZEND_7_0_X_API_NO - char* name = NULL; -#else - zend_string* name = NULL; -#endif + nr_php_compat_zend_string_t* name = NULL; zend_fcall_info_cache fcc; zend_fcall_info fci; @@ -200,11 +206,7 @@ nruserfn_t* nr_php_wrap_generic_callable(zval* callable, NULL, NULL, NR_WRAPREC_IS_TRANSIENT); #else return nr_php_wrap_user_function_with_transience( -#if ZEND_MODULE_API_NO < ZEND_7_0_X_API_NO - name, nr_strlen(name), -#else - ZEND_STRING_VALUE(name), ZEND_STRING_LEN(name), -#endif + NR_PHP_COMPAT_ZEND_STRING_VALUE(name), NR_PHP_COMPAT_ZEND_STRING_LEN(name) callback, NR_WRAPREC_IS_TRANSIENT TSRMLS_CC); #endif @@ -220,11 +222,7 @@ nruserfn_t* nr_php_wrap_generic_callable(zval* callable, NULL, NULL, NR_WRAPREC_IS_TRANSIENT); #else return nr_php_wrap_user_function_with_transience( -#if ZEND_MODULE_API_NO < ZEND_7_0_X_API_NO - name, nr_strlen(name), -#else - ZEND_STRING_VALUE(name), ZEND_STRING_LEN(name), -#endif + NR_PHP_COMPAT_ZEND_STRING_VALUE(name), NR_PHP_COMPAT_ZEND_STRING_LEN(name) callback, NR_WRAPREC_IS_TRANSIENT TSRMLS_CC); #endif @@ -260,11 +258,7 @@ nruserfn_t* nr_php_wrap_generic_callable(zval* callable, } if (NULL != name) { nrl_verbosedebug(NRL_INSTRUMENT, "Failed to wrap callable: %s", -#if ZEND_MODULE_API_NO < ZEND_7_0_X_API_NO - name); -#else - ZEND_STRING_VALUE(name)); -#endif + NR_PHP_COMPAT_ZEND_STRING_VALUE(name)); } else { nrl_verbosedebug(NRL_INSTRUMENT, "Failed to wrap callable with unknown name");