From 5bb03158b67e03c9cb7b1cbda537dbb525917645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 19 Mar 2024 08:20:33 +0100 Subject: [PATCH] Add the last few remaining constants to stubs (#13751) Basically all constants are now declared via stubs. The rest of the constants are either deprecated (`SID` or `MHASH_*`) or out of interest (`__COMPILER_HALT_OFFSET__` and `PHP_CLI_PROCESS_TITLE`). --- build/gen_stub.php | 17 ++++++++++++++--- ext/standard/dir.c | 14 +++++--------- ext/standard/dir.stub.php | 11 +++++++++++ ext/standard/dir_arginfo.h | 4 +++- ext/standard/php_dir_int.h | 2 ++ main/main.c | 10 +--------- main/main.stub.php | 12 ++++++++++++ main/main_arginfo.h | 4 +++- 8 files changed, 51 insertions(+), 23 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 489ba66be52..657b630c6bf 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -2526,6 +2526,7 @@ class ConstInfo extends VariableLike public ?string $cond; public ?string $cValue; public bool $isUndocumentable; + public bool $isFileCacheAllowed; /** * @var AttributeInfo[] $attributes @@ -2544,7 +2545,8 @@ class ConstInfo extends VariableLike ?string $link, ?int $phpVersionIdMinimumCompatibility, array $attributes, - ?ExposedDocComment $exposedDocComment + ?ExposedDocComment $exposedDocComment, + bool $isFileCacheAllowed ) { $this->name = $name; $this->value = $value; @@ -2553,6 +2555,7 @@ class ConstInfo extends VariableLike $this->cond = $cond; $this->cValue = $cValue; $this->isUndocumentable = $isUndocumentable; + $this->isFileCacheAllowed = $isFileCacheAllowed; parent::__construct($flags, $type, $phpDocType, $link, $phpVersionIdMinimumCompatibility, $attributes, $exposedDocComment); } @@ -2698,6 +2701,9 @@ class ConstInfo extends VariableLike $cExpr = $value->getCExpr(); $flags = "CONST_PERSISTENT"; + if (!$this->isFileCacheAllowed) { + $flags .= " | CONST_NO_FILE_CACHE"; + } if ($this->phpVersionIdMinimumCompatibility !== null && $this->phpVersionIdMinimumCompatibility < 80000) { $flags .= " | CONST_CS"; } @@ -2725,7 +2731,8 @@ class ConstInfo extends VariableLike return "\tREGISTER_STRING_CONSTANT(\"$constName\", " . ($cExpr ?: '"' . addslashes($constValue) . '"') . ", $flags);\n"; } - throw new Exception("Unimplemented constant type");} + throw new Exception("Unimplemented constant type"); + } /** @param array $allConstInfos */ private function getClassConstDeclaration(EvaluatedValue $value, array $allConstInfos): string @@ -4304,6 +4311,7 @@ function parseConstLike( $deprecated = false; $cValue = null; $link = null; + $isFileCacheAllowed = true; if ($comments) { $tags = parseDocComments($comments); foreach ($tags as $tag) { @@ -4317,6 +4325,8 @@ function parseConstLike( $isUndocumentable = true; } elseif ($tag->name === 'link') { $link = $tag->value; + } elseif ($tag->name === 'no-file-cache') { + $isFileCacheAllowed = false; } } } @@ -4339,7 +4349,8 @@ function parseConstLike( $link, $phpVersionIdMinimumCompatibility, $attributes, - createExposedDocComment($comments) + createExposedDocComment($comments), + $isFileCacheAllowed ); } diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 7426a7360ee..8e5bf1a36c2 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -107,7 +107,11 @@ PHP_RINIT_FUNCTION(dir) PHP_MINIT_FUNCTION(dir) { - static char dirsep_str[2], pathsep_str[2]; + dirsep_str[0] = DEFAULT_SLASH; + dirsep_str[1] = '\0'; + + pathsep_str[0] = ZEND_PATHS_SEPARATOR; + pathsep_str[1] = '\0'; register_dir_symbols(module_number); @@ -117,14 +121,6 @@ PHP_MINIT_FUNCTION(dir) ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL); #endif - dirsep_str[0] = DEFAULT_SLASH; - dirsep_str[1] = '\0'; - REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, CONST_PERSISTENT); - - pathsep_str[0] = ZEND_PATHS_SEPARATOR; - pathsep_str[1] = '\0'; - REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_PERSISTENT); - return SUCCESS; } /* }}} */ diff --git a/ext/standard/dir.stub.php b/ext/standard/dir.stub.php index b0c12e01167..6177d9fb590 100644 --- a/ext/standard/dir.stub.php +++ b/ext/standard/dir.stub.php @@ -2,6 +2,17 @@ /** @generate-class-entries */ +/** + * @var string + * @cvalue dirsep_str + */ +const DIRECTORY_SEPARATOR = UNKNOWN; +/** + * @var string + * @cvalue pathsep_str + */ +const PATH_SEPARATOR = UNKNOWN; + #ifdef HAVE_GLOB #if (defined(GLOB_BRACE) && GLOB_BRACE != 0) /** diff --git a/ext/standard/dir_arginfo.h b/ext/standard/dir_arginfo.h index 6ab700254db..cdf21396bb0 100644 --- a/ext/standard/dir_arginfo.h +++ b/ext/standard/dir_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: f2571fbbcff57095abcb846f148644e10b2db2e8 */ + * Stub hash: 4b0f093770ff9a6cad9db033e0b62b412408b937 */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Directory_close, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() @@ -22,6 +22,8 @@ static const zend_function_entry class_Directory_methods[] = { static void register_dir_symbols(int module_number) { + REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, CONST_PERSISTENT); + REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_PERSISTENT); #if defined(HAVE_GLOB) && (defined(GLOB_BRACE) && GLOB_BRACE != 0) REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_PERSISTENT); #endif diff --git a/ext/standard/php_dir_int.h b/ext/standard/php_dir_int.h index df9a9078ee4..a359cb725d0 100644 --- a/ext/standard/php_dir_int.h +++ b/ext/standard/php_dir_int.h @@ -62,4 +62,6 @@ #endif /* HAVE_GLOB */ +char dirsep_str[2], pathsep_str[2]; + #endif /* PHP_DIR_INT_H */ diff --git a/main/main.c b/main/main.c index 29d8642b8f7..44c2048fe4c 100644 --- a/main/main.c +++ b/main/main.c @@ -2137,16 +2137,8 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0); - register_main_symbols(module_number); - - REGISTER_MAIN_STRINGL_CONSTANT("PHP_SAPI", sapi_module.name, strlen(sapi_module.name), CONST_PERSISTENT | CONST_NO_FILE_CACHE); - php_binary_init(); - if (PG(php_binary)) { - REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", PG(php_binary), strlen(PG(php_binary)), CONST_PERSISTENT | CONST_NO_FILE_CACHE); - } else { - REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_NO_FILE_CACHE); - } + register_main_symbols(module_number); /* this will read in php.ini, set up the configuration parameters, load zend extensions and register php function extensions diff --git a/main/main.stub.php b/main/main.stub.php index 9b0c08c592c..fd8ac28dd8b 100644 --- a/main/main.stub.php +++ b/main/main.stub.php @@ -354,3 +354,15 @@ const UPLOAD_ERR_EXTENSION = UNKNOWN; */ const ZEND_VERIFY_TYPE_INFERENCE = UNKNOWN; #endif +/** + * @var string + * @cvalue sapi_module.name + * @no-file-cache + */ +const PHP_SAPI = UNKNOWN; +/** + * @var string + * @cvalue PG(php_binary) ? PG(php_binary) : "" + * @no-file-cache + */ +const PHP_BINARY = UNKNOWN; diff --git a/main/main_arginfo.h b/main/main_arginfo.h index c19f5420d4f..9c12a065792 100644 --- a/main/main_arginfo.h +++ b/main/main_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 2542736c885829255e4226783b60db1453342b65 */ + * Stub hash: 7ff3d7dc2636153044513390669cb46e9a5b5a0a */ static void register_main_symbols(int module_number) { @@ -97,4 +97,6 @@ static void register_main_symbols(int module_number) #if defined(ZEND_VERIFY_TYPE_INFERENCE) REGISTER_BOOL_CONSTANT("ZEND_VERIFY_TYPE_INFERENCE", ZEND_VERIFY_TYPE_INFERENCE, CONST_PERSISTENT); #endif + REGISTER_STRING_CONSTANT("PHP_SAPI", sapi_module.name, CONST_PERSISTENT | CONST_NO_FILE_CACHE); + REGISTER_STRING_CONSTANT("PHP_BINARY", PG(php_binary) ? PG(php_binary) : "", CONST_PERSISTENT | CONST_NO_FILE_CACHE); }