Skip to content

Generated arginfo header files: combine preprocessor conditional blocks #15736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading