Skip to content

Commit 5dd0575

Browse files
Generated arginfo header files: combine preprocessor conditional blocks (#15736)
When functions' or class methods' availability is based on some preprocessor condition, the generated arginfo header files wrap the declarations in the preprocessor `#if` conditional blocks, one per declaration, even if they are in the same conditional block based on comments in the stub file. Instead of having multiple conditional blocks one after the other with the same condition, combine them into a single conditional block.
1 parent 24d4ae9 commit 5dd0575

19 files changed

+30
-801
lines changed

Zend/Optimizer/zend_func_infos.h

-30
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ static const func_info_t func_infos[] = {
102102
F1("imagecreatetruecolor", MAY_BE_OBJECT|MAY_BE_FALSE),
103103
#if defined(PHP_WIN32)
104104
F1("imagegrabwindow", MAY_BE_OBJECT|MAY_BE_FALSE),
105-
#endif
106-
#if defined(PHP_WIN32)
107105
F1("imagegrabscreen", MAY_BE_OBJECT|MAY_BE_FALSE),
108106
#endif
109107
F1("imagerotate", MAY_BE_OBJECT|MAY_BE_FALSE),
@@ -137,8 +135,6 @@ static const func_info_t func_infos[] = {
137135
F1("imagegetclip", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG),
138136
#if defined(HAVE_GD_FREETYPE)
139137
F1("imageftbbox", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
140-
#endif
141-
#if defined(HAVE_GD_FREETYPE)
142138
F1("imagefttext", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
143139
#endif
144140
F1("imagecrop", MAY_BE_OBJECT|MAY_BE_FALSE),
@@ -182,11 +178,7 @@ static const func_info_t func_infos[] = {
182178
F1("hash_hkdf", MAY_BE_STRING),
183179
#if defined(PHP_MHASH_BC)
184180
F1("mhash_get_hash_name", MAY_BE_STRING|MAY_BE_FALSE),
185-
#endif
186-
#if defined(PHP_MHASH_BC)
187181
F1("mhash_keygen_s2k", MAY_BE_STRING|MAY_BE_FALSE),
188-
#endif
189-
#if defined(PHP_MHASH_BC)
190182
F1("mhash", MAY_BE_STRING|MAY_BE_FALSE),
191183
#endif
192184
F1("iconv_substr", MAY_BE_STRING|MAY_BE_FALSE),
@@ -239,29 +231,13 @@ static const func_info_t func_infos[] = {
239231
F1("mb_get_info", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_STRING|MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_NULL),
240232
#if defined(HAVE_MBREGEX)
241233
F1("mb_regex_encoding", MAY_BE_STRING|MAY_BE_BOOL),
242-
#endif
243-
#if defined(HAVE_MBREGEX)
244234
F1("mb_ereg_replace", MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL),
245-
#endif
246-
#if defined(HAVE_MBREGEX)
247235
F1("mb_eregi_replace", MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL),
248-
#endif
249-
#if defined(HAVE_MBREGEX)
250236
F1("mb_ereg_replace_callback", MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL),
251-
#endif
252-
#if defined(HAVE_MBREGEX)
253237
F1("mb_split", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
254-
#endif
255-
#if defined(HAVE_MBREGEX)
256238
F1("mb_ereg_search_pos", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
257-
#endif
258-
#if defined(HAVE_MBREGEX)
259239
F1("mb_ereg_search_regs", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_FALSE|MAY_BE_FALSE),
260-
#endif
261-
#if defined(HAVE_MBREGEX)
262240
F1("mb_ereg_search_getregs", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_FALSE|MAY_BE_FALSE),
263-
#endif
264-
#if defined(HAVE_MBREGEX)
265241
F1("mb_regex_set_options", MAY_BE_STRING),
266242
#endif
267243
F1("mysqli_affected_rows", MAY_BE_LONG|MAY_BE_STRING),
@@ -402,8 +378,6 @@ static const func_info_t func_infos[] = {
402378
FN("sodium_crypto_kx_server_session_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
403379
#if defined(crypto_secretstream_xchacha20poly1305_ABYTES)
404380
FN("sodium_crypto_secretstream_xchacha20poly1305_init_push", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
405-
#endif
406-
#if defined(crypto_secretstream_xchacha20poly1305_ABYTES)
407381
FN("sodium_crypto_secretstream_xchacha20poly1305_pull", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
408382
#endif
409383
F1("class_implements", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
@@ -596,8 +570,6 @@ static const func_info_t func_infos[] = {
596570
F1("number_format", MAY_BE_STRING),
597571
#if defined(HAVE_GETTIMEOFDAY)
598572
F1("microtime", MAY_BE_STRING|MAY_BE_DOUBLE),
599-
#endif
600-
#if defined(HAVE_GETTIMEOFDAY)
601573
F1("gettimeofday", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_DOUBLE),
602574
#endif
603575
#if defined(HAVE_GETRUSAGE)
@@ -609,8 +581,6 @@ static const func_info_t func_infos[] = {
609581
F1("password_hash", MAY_BE_STRING),
610582
#if defined(PHP_CAN_SUPPORT_PROC_OPEN)
611583
F1("proc_open", MAY_BE_RESOURCE|MAY_BE_FALSE),
612-
#endif
613-
#if defined(PHP_CAN_SUPPORT_PROC_OPEN)
614584
F1("proc_get_status", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_FALSE|MAY_BE_ARRAY_OF_TRUE|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING),
615585
#endif
616586
F1("quoted_printable_decode", MAY_BE_STRING),

build/gen_stub.php

+30-3
Original file line numberDiff line numberDiff line change
@@ -5022,21 +5022,48 @@ function findEquivalentFuncInfo(array $generatedFuncInfos, FuncInfo $funcInfo):
50225022
function generateCodeWithConditions(
50235023
iterable $infos, string $separator, Closure $codeGenerator, ?string $parentCond = null): string {
50245024
$code = "";
5025+
5026+
// For combining the conditional blocks of the infos with the same condition
5027+
$openCondition = null;
50255028
foreach ($infos as $info) {
50265029
$infoCode = $codeGenerator($info);
50275030
if ($infoCode === null) {
50285031
continue;
50295032
}
50305033

5031-
$code .= $separator;
50325034
if ($info->cond && $info->cond !== $parentCond) {
5033-
$code .= "#if {$info->cond}\n";
5035+
if ($openCondition !== null
5036+
&& $info->cond !== $openCondition
5037+
) {
5038+
// Changing condition, end old
5039+
$code .= "#endif\n";
5040+
$code .= $separator;
5041+
$code .= "#if {$info->cond}\n";
5042+
$openCondition = $info->cond;
5043+
} elseif ($openCondition === null) {
5044+
// New condition with no existing one
5045+
$code .= $separator;
5046+
$code .= "#if {$info->cond}\n";
5047+
$openCondition = $info->cond;
5048+
} else {
5049+
// Staying in the same condition
5050+
$code .= $separator;
5051+
}
50345052
$code .= $infoCode;
5035-
$code .= "#endif\n";
50365053
} else {
5054+
if ($openCondition !== null) {
5055+
// Ending the condition
5056+
$code .= "#endif\n";
5057+
$openCondition = null;
5058+
}
5059+
$code .= $separator;
50375060
$code .= $infoCode;
50385061
}
50395062
}
5063+
// The last info might have been in a conditional block
5064+
if ($openCondition !== null) {
5065+
$code .= "#endif\n";
5066+
}
50405067

50415068
return $code;
50425069
}

0 commit comments

Comments
 (0)