Skip to content

Commit 41c7d28

Browse files
committed
Add macro to get ini target address
1 parent ecc6b8c commit 41c7d28

File tree

7 files changed

+28
-152
lines changed

7 files changed

+28
-152
lines changed

Zend/zend.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,9 @@ static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
139139

140140
static ZEND_INI_MH(OnUpdateAssertions) /* {{{ */
141141
{
142-
zend_long *p, val;
143-
#ifndef ZTS
144-
char *base = (char *) mh_arg2;
145-
#else
146-
char *base;
147-
148-
base = (char *) ts_resource(*((int *) mh_arg2));
149-
#endif
150-
151-
p = (zend_long *) (base+(size_t) mh_arg1);
142+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
152143

153-
val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
144+
zend_long val = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
154145

155146
if (stage != ZEND_INI_STAGE_STARTUP &&
156147
stage != ZEND_INI_STAGE_SHUTDOWN &&

Zend/zend_ini.c

Lines changed: 7 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -578,57 +578,28 @@ ZEND_INI_DISP(display_link_numbers) /* {{{ */
578578
/* Standard message handlers */
579579
ZEND_API ZEND_INI_MH(OnUpdateBool) /* {{{ */
580580
{
581-
zend_bool *p;
582-
#ifndef ZTS
583-
char *base = (char *) mh_arg2;
584-
#else
585-
char *base;
586-
587-
base = (char *) ts_resource(*((int *) mh_arg2));
588-
#endif
589-
590-
p = (zend_bool *) (base+(size_t) mh_arg1);
591-
581+
zend_bool *p = (zend_bool *) ZEND_INI_GET_ADDR();
592582
*p = zend_ini_parse_bool(new_value);
593583
return SUCCESS;
594584
}
595585
/* }}} */
596586

597587
ZEND_API ZEND_INI_MH(OnUpdateLong) /* {{{ */
598588
{
599-
zend_long *p;
600-
#ifndef ZTS
601-
char *base = (char *) mh_arg2;
602-
#else
603-
char *base;
604-
605-
base = (char *) ts_resource(*((int *) mh_arg2));
606-
#endif
607-
608-
p = (zend_long *) (base+(size_t) mh_arg1);
609-
589+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
610590
*p = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
611591
return SUCCESS;
612592
}
613593
/* }}} */
614594

615595
ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
616596
{
617-
zend_long *p, tmp;
618-
#ifndef ZTS
619-
char *base = (char *) mh_arg2;
620-
#else
621-
char *base;
622-
623-
base = (char *) ts_resource(*((int *) mh_arg2));
624-
#endif
625-
626-
tmp = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
597+
zend_long tmp = zend_atol(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
627598
if (tmp < 0) {
628599
return FAILURE;
629600
}
630601

631-
p = (zend_long *) (base+(size_t) mh_arg1);
602+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
632603
*p = tmp;
633604

634605
return SUCCESS;
@@ -637,57 +608,27 @@ ZEND_API ZEND_INI_MH(OnUpdateLongGEZero) /* {{{ */
637608

638609
ZEND_API ZEND_INI_MH(OnUpdateReal) /* {{{ */
639610
{
640-
double *p;
641-
#ifndef ZTS
642-
char *base = (char *) mh_arg2;
643-
#else
644-
char *base;
645-
646-
base = (char *) ts_resource(*((int *) mh_arg2));
647-
#endif
648-
649-
p = (double *) (base+(size_t) mh_arg1);
650-
611+
double *p = (double *) ZEND_INI_GET_ADDR();
651612
*p = zend_strtod(ZSTR_VAL(new_value), NULL);
652613
return SUCCESS;
653614
}
654615
/* }}} */
655616

656617
ZEND_API ZEND_INI_MH(OnUpdateString) /* {{{ */
657618
{
658-
char **p;
659-
#ifndef ZTS
660-
char *base = (char *) mh_arg2;
661-
#else
662-
char *base;
663-
664-
base = (char *) ts_resource(*((int *) mh_arg2));
665-
#endif
666-
667-
p = (char **) (base+(size_t) mh_arg1);
668-
619+
char **p = (char **) ZEND_INI_GET_ADDR();
669620
*p = new_value ? ZSTR_VAL(new_value) : NULL;
670621
return SUCCESS;
671622
}
672623
/* }}} */
673624

674625
ZEND_API ZEND_INI_MH(OnUpdateStringUnempty) /* {{{ */
675626
{
676-
char **p;
677-
#ifndef ZTS
678-
char *base = (char *) mh_arg2;
679-
#else
680-
char *base;
681-
682-
base = (char *) ts_resource(*((int *) mh_arg2));
683-
#endif
684-
685627
if (new_value && !ZSTR_VAL(new_value)[0]) {
686628
return FAILURE;
687629
}
688630

689-
p = (char **) (base+(size_t) mh_arg1);
690-
631+
char **p = (char **) ZEND_INI_GET_ADDR();
691632
*p = new_value ? ZSTR_VAL(new_value) : NULL;
692633
return SUCCESS;
693634
}

Zend/zend_ini.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,12 @@ typedef struct _zend_ini_parser_param {
194194
void *arg;
195195
} zend_ini_parser_param;
196196

197+
#ifndef ZTS
198+
# define ZEND_INI_GET_BASE() ((char *) mh_arg2)
199+
#else
200+
# define ZEND_INI_GET_BASE() ((char *) ts_resource(*((int *) mh_arg2)))
201+
#endif
202+
203+
#define ZEND_INI_GET_ADDR() (ZEND_INI_GET_BASE() + (size_t) mh_arg1)
204+
197205
#endif /* ZEND_INI_H */

ext/opcache/zend_accelerator_module.c

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,8 @@ static int validate_api_restriction(void)
6363

6464
static ZEND_INI_MH(OnUpdateMemoryConsumption)
6565
{
66-
zend_long *p;
67-
zend_long memsize;
68-
#ifndef ZTS
69-
char *base = (char *) mh_arg2;
70-
#else
71-
char *base = (char *) ts_resource(*((int *) mh_arg2));
72-
#endif
73-
74-
/* keep the compiler happy */
75-
(void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
76-
77-
p = (zend_long *) (base + (size_t)mh_arg1);
78-
memsize = atoi(ZSTR_VAL(new_value));
66+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
67+
zend_long memsize = atoi(ZSTR_VAL(new_value));
7968
/* sanity check we must use at least 8 MB */
8069
if (memsize < 8) {
8170
const char *new_new_value = "8";
@@ -103,19 +92,8 @@ static ZEND_INI_MH(OnUpdateMemoryConsumption)
10392

10493
static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
10594
{
106-
zend_long *p;
107-
zend_long size;
108-
#ifndef ZTS
109-
char *base = (char *) mh_arg2;
110-
#else
111-
char *base = (char *) ts_resource(*((int *) mh_arg2));
112-
#endif
113-
114-
/* keep the compiler happy */
115-
(void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
116-
117-
p = (zend_long *) (base + (size_t)mh_arg1);
118-
size = atoi(ZSTR_VAL(new_value));
95+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
96+
zend_long size = atoi(ZSTR_VAL(new_value));
11997
/* sanity check we must use a value between MIN_ACCEL_FILES and MAX_ACCEL_FILES */
12098

12199
if (size < MIN_ACCEL_FILES || size > MAX_ACCEL_FILES) {
@@ -147,19 +125,8 @@ static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
147125

148126
static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
149127
{
150-
double *p;
151-
zend_long percentage;
152-
#ifndef ZTS
153-
char *base = (char *) mh_arg2;
154-
#else
155-
char *base = (char *) ts_resource(*((int *) mh_arg2));
156-
#endif
157-
158-
/* keep the compiler happy */
159-
(void)entry; (void)mh_arg2; (void)mh_arg3; (void)stage;
160-
161-
p = (double *) (base + (size_t)mh_arg1);
162-
percentage = atoi(ZSTR_VAL(new_value));
128+
double *p = (double *) ZEND_INI_GET_ADDR();
129+
zend_long percentage = atoi(ZSTR_VAL(new_value));
163130

164131
if (percentage <= 0 || percentage > 50) {
165132
const char *new_new_value = "5";
@@ -187,14 +154,7 @@ static ZEND_INI_MH(OnEnable)
187154
return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
188155
} else {
189156
/* It may be only temporary disabled */
190-
zend_bool *p;
191-
#ifndef ZTS
192-
char *base = (char *) mh_arg2;
193-
#else
194-
char *base = (char *) ts_resource(*((int *) mh_arg2));
195-
#endif
196-
197-
p = (zend_bool *) (base+(size_t) mh_arg1);
157+
zend_bool *p = (zend_bool *) ZEND_INI_GET_ADDR();
198158
if ((ZSTR_LEN(new_value) == 2 && strcasecmp("on", ZSTR_VAL(new_value)) == 0) ||
199159
(ZSTR_LEN(new_value) == 3 && strcasecmp("yes", ZSTR_VAL(new_value)) == 0) ||
200160
(ZSTR_LEN(new_value) == 4 && strcasecmp("true", ZSTR_VAL(new_value)) == 0) ||

ext/soap/soap.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,8 @@ ZEND_GET_MODULE(soap)
211211

212212
ZEND_INI_MH(OnUpdateCacheMode)
213213
{
214-
char *p;
215-
#ifndef ZTS
216-
char *base = (char *) mh_arg2;
217-
#else
218-
char *base = (char *) ts_resource(*((int *) mh_arg2));
219-
#endif
220-
221-
p = (char*) (base+(size_t) mh_arg1);
222-
214+
char *p = (char *) ZEND_INI_GET_ADDR();
223215
*p = (char)atoi(ZSTR_VAL(new_value));
224-
225216
return SUCCESS;
226217
}
227218

ext/zlib/zlib.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,15 +1250,6 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression)
12501250
{
12511251
int int_value;
12521252
char *ini_value;
1253-
zend_long *p;
1254-
#ifndef ZTS
1255-
char *base = (char *) mh_arg2;
1256-
#else
1257-
char *base;
1258-
1259-
base = (char *) ts_resource(*((int *) mh_arg2));
1260-
#endif
1261-
12621253
if (new_value == NULL) {
12631254
return FAILURE;
12641255
}
@@ -1284,7 +1275,7 @@ static PHP_INI_MH(OnUpdate_zlib_output_compression)
12841275
}
12851276
}
12861277

1287-
p = (zend_long *) (base+(size_t) mh_arg1);
1278+
zend_long *p = (zend_long *) ZEND_INI_GET_ADDR();
12881279
*p = int_value;
12891280

12901281
ZLIBG(output_compression) = ZLIBG(output_compression_default);

main/fopen_wrappers.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,8 @@ Allows any change to open_basedir setting in during Startup and Shutdown events,
7373
or a tightening during activation/runtime/deactivation */
7474
PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
7575
{
76-
char **p, *pathbuf, *ptr, *end;
77-
#ifndef ZTS
78-
char *base = (char *) mh_arg2;
79-
#else
80-
char *base = (char *) ts_resource(*((int *) mh_arg2));
81-
#endif
82-
83-
p = (char **) (base + (size_t) mh_arg1);
76+
char **p = (char **) ZEND_INI_GET_ADDR();
77+
char *pathbuf, *ptr, *end;
8478

8579
if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN || stage == PHP_INI_STAGE_ACTIVATE || stage == PHP_INI_STAGE_DEACTIVATE) {
8680
/* We're in a PHP_INI_SYSTEM context, no restrictions */

0 commit comments

Comments
 (0)