Skip to content

Commit

Permalink
Generated arginfo header files: combine preprocessor conditional bloc…
Browse files Browse the repository at this point in the history
…ks (#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.
  • Loading branch information
DanielEScherzer authored Sep 4, 2024
1 parent 24d4ae9 commit 5dd0575
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 801 deletions.
30 changes: 0 additions & 30 deletions Zend/Optimizer/zend_func_infos.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ static const func_info_t func_infos[] = {
F1("imagecreatetruecolor", MAY_BE_OBJECT|MAY_BE_FALSE),
#if defined(PHP_WIN32)
F1("imagegrabwindow", MAY_BE_OBJECT|MAY_BE_FALSE),
#endif
#if defined(PHP_WIN32)
F1("imagegrabscreen", MAY_BE_OBJECT|MAY_BE_FALSE),
#endif
F1("imagerotate", MAY_BE_OBJECT|MAY_BE_FALSE),
Expand Down Expand Up @@ -137,8 +135,6 @@ static const func_info_t func_infos[] = {
F1("imagegetclip", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG),
#if defined(HAVE_GD_FREETYPE)
F1("imageftbbox", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
#endif
#if defined(HAVE_GD_FREETYPE)
F1("imagefttext", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
#endif
F1("imagecrop", MAY_BE_OBJECT|MAY_BE_FALSE),
Expand Down Expand Up @@ -182,11 +178,7 @@ static const func_info_t func_infos[] = {
F1("hash_hkdf", MAY_BE_STRING),
#if defined(PHP_MHASH_BC)
F1("mhash_get_hash_name", MAY_BE_STRING|MAY_BE_FALSE),
#endif
#if defined(PHP_MHASH_BC)
F1("mhash_keygen_s2k", MAY_BE_STRING|MAY_BE_FALSE),
#endif
#if defined(PHP_MHASH_BC)
F1("mhash", MAY_BE_STRING|MAY_BE_FALSE),
#endif
F1("iconv_substr", MAY_BE_STRING|MAY_BE_FALSE),
Expand Down Expand Up @@ -239,29 +231,13 @@ static const func_info_t func_infos[] = {
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),
#if defined(HAVE_MBREGEX)
F1("mb_regex_encoding", MAY_BE_STRING|MAY_BE_BOOL),
#endif
#if defined(HAVE_MBREGEX)
F1("mb_ereg_replace", MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL),
#endif
#if defined(HAVE_MBREGEX)
F1("mb_eregi_replace", MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL),
#endif
#if defined(HAVE_MBREGEX)
F1("mb_ereg_replace_callback", MAY_BE_STRING|MAY_BE_FALSE|MAY_BE_NULL),
#endif
#if defined(HAVE_MBREGEX)
F1("mb_split", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
#endif
#if defined(HAVE_MBREGEX)
F1("mb_ereg_search_pos", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
#endif
#if defined(HAVE_MBREGEX)
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),
#endif
#if defined(HAVE_MBREGEX)
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),
#endif
#if defined(HAVE_MBREGEX)
F1("mb_regex_set_options", MAY_BE_STRING),
#endif
F1("mysqli_affected_rows", MAY_BE_LONG|MAY_BE_STRING),
Expand Down Expand Up @@ -402,8 +378,6 @@ static const func_info_t func_infos[] = {
FN("sodium_crypto_kx_server_session_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
#if defined(crypto_secretstream_xchacha20poly1305_ABYTES)
FN("sodium_crypto_secretstream_xchacha20poly1305_init_push", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
#endif
#if defined(crypto_secretstream_xchacha20poly1305_ABYTES)
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),
#endif
F1("class_implements", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
Expand Down Expand Up @@ -596,8 +570,6 @@ static const func_info_t func_infos[] = {
F1("number_format", MAY_BE_STRING),
#if defined(HAVE_GETTIMEOFDAY)
F1("microtime", MAY_BE_STRING|MAY_BE_DOUBLE),
#endif
#if defined(HAVE_GETTIMEOFDAY)
F1("gettimeofday", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_DOUBLE),
#endif
#if defined(HAVE_GETRUSAGE)
Expand All @@ -609,8 +581,6 @@ static const func_info_t func_infos[] = {
F1("password_hash", MAY_BE_STRING),
#if defined(PHP_CAN_SUPPORT_PROC_OPEN)
F1("proc_open", MAY_BE_RESOURCE|MAY_BE_FALSE),
#endif
#if defined(PHP_CAN_SUPPORT_PROC_OPEN)
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),
#endif
F1("quoted_printable_decode", MAY_BE_STRING),
Expand Down
33 changes: 30 additions & 3 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -5022,21 +5022,48 @@ function findEquivalentFuncInfo(array $generatedFuncInfos, FuncInfo $funcInfo):
function generateCodeWithConditions(
iterable $infos, string $separator, Closure $codeGenerator, ?string $parentCond = null): string {
$code = "";

// For combining the conditional blocks of the infos with the same condition
$openCondition = null;
foreach ($infos as $info) {
$infoCode = $codeGenerator($info);
if ($infoCode === null) {
continue;
}

$code .= $separator;
if ($info->cond && $info->cond !== $parentCond) {
$code .= "#if {$info->cond}\n";
if ($openCondition !== null
&& $info->cond !== $openCondition
) {
// Changing condition, end old
$code .= "#endif\n";
$code .= $separator;
$code .= "#if {$info->cond}\n";
$openCondition = $info->cond;
} elseif ($openCondition === null) {
// New condition with no existing one
$code .= $separator;
$code .= "#if {$info->cond}\n";
$openCondition = $info->cond;
} else {
// Staying in the same condition
$code .= $separator;
}
$code .= $infoCode;
$code .= "#endif\n";
} else {
if ($openCondition !== null) {
// Ending the condition
$code .= "#endif\n";
$openCondition = null;
}
$code .= $separator;
$code .= $infoCode;
}
}
// The last info might have been in a conditional block
if ($openCondition !== null) {
$code .= "#endif\n";
}

return $code;
}
Expand Down
Loading

0 comments on commit 5dd0575

Please sign in to comment.