From: Nikita Popov Date: Mon, 27 Apr 2020 08:21:26 +0000 (+0200) Subject: Add macro to get ini target address X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41c7d28c113d1c8e9c98cc834e8479f8567e5e3a;p=php Add macro to get ini target address --- diff --git a/Zend/zend.c b/Zend/zend.c index 555483a7be..40dd8991a1 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -139,18 +139,9 @@ static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */ static ZEND_INI_MH(OnUpdateAssertions) /* {{{ */ { - zend_long *p, val; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (zend_long *) (base+(size_t) mh_arg1); + zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); - val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); + zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); if (stage != ZEND_INI_STAGE_STARTUP && stage != ZEND_INI_STAGE_SHUTDOWN && diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index a2344653bc..279dcae03c 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -578,17 +578,7 @@ ZEND_INI_DISP(display_link_numbers) /* {{{ */ /* Standard message handlers */ ZEND_API ZEND_INI_MH(OnUpdateBool) /* {{{ */ { - zend_bool *p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (zend_bool *) (base+(size_t) mh_arg1); - + zend_bool *p = (zend_bool *) ZEND_INI_GET_ADDR(); *p = zend_ini_parse_bool(new_value); return SUCCESS; } @@ -596,17 +586,7 @@ ZEND_API ZEND_INI_MH(OnUpdateBool) /* {{{ */ ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */ { - zend_long *p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (zend_long *) (base+(size_t) mh_arg1); - + zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); *p = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); return SUCCESS; } @@ -614,21 +594,12 @@ ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */ ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */ { - zend_long *p, tmp; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - tmp = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); + zend_long tmp = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value)); if (tmp < 0) { return FAILURE; } - p = (zend_long *) (base+(size_t) mh_arg1); + zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); *p = tmp; return SUCCESS; @@ -637,17 +608,7 @@ ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */ ZEND_API ZEND_INI_MH(OnUpdateReal) /* {{{ */ { - double *p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (double *) (base+(size_t) mh_arg1); - + double *p = (double *) ZEND_INI_GET_ADDR(); *p = zend_strtod(ZSTR_VAL(new_value), NULL); return SUCCESS; } @@ -655,17 +616,7 @@ ZEND_API ZEND_INI_MH(OnUpdateReal) /* {{{ */ ZEND_API ZEND_INI_MH(OnUpdateString) /* {{{ */ { - char **p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (char **) (base+(size_t) mh_arg1); - + char **p = (char **) ZEND_INI_GET_ADDR(); *p = new_value ? ZSTR_VAL(new_value) : NULL; return SUCCESS; } @@ -673,21 +624,11 @@ ZEND_API ZEND_INI_MH(OnUpdateString) /* {{{ */ ZEND_API ZEND_INI_MH(OnUpdateStringUnempty) /* {{{ */ { - char **p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - if (new_value && !ZSTR_VAL(new_value)[0]) { return FAILURE; } - p = (char **) (base+(size_t) mh_arg1); - + char **p = (char **) ZEND_INI_GET_ADDR(); *p = new_value ? ZSTR_VAL(new_value) : NULL; return SUCCESS; } diff --git a/Zend/zend_ini.h b/Zend/zend_ini.h index 3759ca3196..0289b322be 100644 --- a/Zend/zend_ini.h +++ b/Zend/zend_ini.h @@ -194,4 +194,12 @@ typedef struct _zend_ini_parser_param { void *arg; } zend_ini_parser_param; +#ifndef ZTS +# define ZEND_INI_GET_BASE() ((char *) mh_arg2) +#else +# define ZEND_INI_GET_BASE() ((char *) ts_resource(*((int *) mh_arg2))) +#endif + +#define ZEND_INI_GET_ADDR() (ZEND_INI_GET_BASE() + (size_t) mh_arg1) + #endif /* ZEND_INI_H */ diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c index ef3cb5cc5c..da9806db7f 100644 --- a/ext/opcache/zend_accelerator_module.c +++ b/ext/opcache/zend_accelerator_module.c @@ -63,19 +63,8 @@ static int validate_api_restriction(void) static ZEND_INI_MH(OnUpdateMemoryConsumption) { - zend_long *p; - zend_long memsize; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - /* keep the compiler happy */ - (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage; - - p = (zend_long *) (base + (size_t)mh_arg1); - memsize = atoi(ZSTR_VAL(new_value)); + zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); + zend_long memsize = atoi(ZSTR_VAL(new_value)); /* sanity check we must use at least 8 MB */ if (memsize < 8) { const char *new_new_value = "8"; @@ -103,19 +92,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption) static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles) { - zend_long *p; - zend_long size; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - /* keep the compiler happy */ - (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage; - - p = (zend_long *) (base + (size_t)mh_arg1); - size = atoi(ZSTR_VAL(new_value)); + zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); + zend_long size = atoi(ZSTR_VAL(new_value)); /* sanity check we must use a value between MIN_ACCEL_FILES and MAX_ACCEL_FILES */ if (size < MIN_ACCEL_FILES || size > MAX_ACCEL_FILES) { @@ -147,19 +125,8 @@ static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles) static ZEND_INI_MH(OnUpdateMaxWastedPercentage) { - double *p; - zend_long percentage; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - /* keep the compiler happy */ - (void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage; - - p = (double *) (base + (size_t)mh_arg1); - percentage = atoi(ZSTR_VAL(new_value)); + double *p = (double *) ZEND_INI_GET_ADDR(); + zend_long percentage = atoi(ZSTR_VAL(new_value)); if (percentage <= 0 || percentage > 50) { const char *new_new_value = "5"; @@ -187,14 +154,7 @@ static ZEND_INI_MH(OnEnable) return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); } else { /* It may be only temporary disabled */ - zend_bool *p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (zend_bool *) (base+(size_t) mh_arg1); + zend_bool *p = (zend_bool *) ZEND_INI_GET_ADDR(); if ((ZSTR_LEN(new_value) == 2 && strcasecmp("on", ZSTR_VAL(new_value)) == 0) || (ZSTR_LEN(new_value) == 3 && strcasecmp("yes", ZSTR_VAL(new_value)) == 0) || (ZSTR_LEN(new_value) == 4 && strcasecmp("true", ZSTR_VAL(new_value)) == 0) || diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 2c82ac3919..a93813e9d1 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -211,17 +211,8 @@ ZEND_GET_MODULE(soap) ZEND_INI_MH(OnUpdateCacheMode) { - char *p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (char*) (base+(size_t) mh_arg1); - + char *p = (char *) ZEND_INI_GET_ADDR(); *p = (char)atoi(ZSTR_VAL(new_value)); - return SUCCESS; } diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 99a1f14b2b..6951c155ad 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1250,15 +1250,6 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression) { int int_value; char *ini_value; - zend_long *p; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base; - - base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - if (new_value == NULL) { return FAILURE; } @@ -1284,7 +1275,7 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression) } } - p = (zend_long *) (base+(size_t) mh_arg1); + zend_long *p = (zend_long *) ZEND_INI_GET_ADDR(); *p = int_value; ZLIBG(output_compression) = ZLIBG(output_compression_default); diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index b2d698e7b0..d61a7c6893 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -73,14 +73,8 @@ Allows any change to open_basedir setting in during Startup and Shutdown events, or a tightening during activation/runtime/deactivation */ PHPAPI ZEND_INI_MH(OnUpdateBaseDir) { - char **p, *pathbuf, *ptr, *end; -#ifndef ZTS - char *base = (char *) mh_arg2; -#else - char *base = (char *) ts_resource(*((int *) mh_arg2)); -#endif - - p = (char **) (base + (size_t) mh_arg1); + char **p = (char **) ZEND_INI_GET_ADDR(); + char *pathbuf, *ptr, *end; if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN || stage == PHP_INI_STAGE_ACTIVATE || stage == PHP_INI_STAGE_DEACTIVATE) { /* We're in a PHP_INI_SYSTEM context, no restrictions */