Skip to content

Commit

Permalink
fixup! improve code readability
Browse files Browse the repository at this point in the history
Re-use `ZEND_STRING_VALUE` macro, which is already an agent's
compatibilty macro, and with that simplify the code even more
by not defining new type for zend_string.
  • Loading branch information
lavarou committed Aug 8, 2023
1 parent cec08d8 commit 6d24dc2
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions agent/php_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,6 @@ 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,
Expand All @@ -184,7 +174,11 @@ typedef nr_php_compat_zend_string_t zend_string;
*/
nruserfn_t* nr_php_wrap_generic_callable(zval* callable,
nrspecialfn_t callback TSRMLS_DC) {
nr_php_compat_zend_string_t* name = NULL;
#if ZEND_MODULE_API_NO < ZEND_7_0_X_API_NO
char* name = NULL;
#else
zend_string* name = NULL;
#endif
zend_fcall_info_cache fcc;
zend_fcall_info fci;

Expand All @@ -206,8 +200,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(
NR_PHP_COMPAT_ZEND_STRING_VALUE(name), NR_PHP_COMPAT_ZEND_STRING_LEN(name)
callback,
ZEND_STRING_VALUE(name), ZEND_STRING_LEN(name), callback,
NR_WRAPREC_IS_TRANSIENT TSRMLS_CC);
#endif

Expand All @@ -222,8 +215,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(
NR_PHP_COMPAT_ZEND_STRING_VALUE(name), NR_PHP_COMPAT_ZEND_STRING_LEN(name)
callback,
ZEND_STRING_VALUE(name), ZEND_STRING_LEN(name), callback,
NR_WRAPREC_IS_TRANSIENT TSRMLS_CC);
#endif

Expand Down Expand Up @@ -258,7 +250,7 @@ nruserfn_t* nr_php_wrap_generic_callable(zval* callable,
}
if (NULL != name) {
nrl_verbosedebug(NRL_INSTRUMENT, "Failed to wrap callable: %s",
NR_PHP_COMPAT_ZEND_STRING_VALUE(name));
ZEND_STRING_VALUE(name));
} else {
nrl_verbosedebug(NRL_INSTRUMENT,
"Failed to wrap callable with unknown name");
Expand Down

0 comments on commit 6d24dc2

Please sign in to comment.