[php-src] master: Add the last few remaining constants to stubs (#13751)
| From: | Máté Kocsis via GitHub | Date: | Tue, 19 Mar 2024 07:34:22 +0000 |
| Subject: | [php-src] master: Add the last few remaining constants to stubs (#13751) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127791@lists.php.net to get a copy of this message | ||
Author: Máté Kocsis (kocsismate)
Committer: GitHub (web-flow)
Pusher: kocsismate
Date: 2024-03-19T08:20:33+01:00
Commit: https://github.com/php/php-src/commit/5bb03158b67e03c9cb7b1cbda537dbb525917645
Raw diff: https://github.com/php/php-src/commit/5bb03158b67e03c9cb7b1cbda537dbb525917645.diff
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).
Changed paths:
M build/gen_stub.php
M ext/standard/dir.c
M ext/standard/dir.stub.php
M ext/standard/dir_arginfo.h
M ext/standard/php_dir_int.h
M main/main.c
M main/main.stub.php
M main/main_arginfo.h
Diff:
diff --git a/build/gen_stub.php b/build/gen_stub.php
index 489ba66be52ee..657b630c6bf40 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 @@ public function __construct(
?string $link,
?int $phpVersionIdMinimumCompatibility,
array $attributes,
- ?ExposedDocComment $exposedDocComment
+ ?ExposedDocComment $exposedDocComment,
+ bool $isFileCacheAllowed
) {
$this->name = $name;
$this->value = $value;
@@ -2553,6 +2555,7 @@ public function __construct(
$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 @@ private function getGlobalConstDeclaration(EvaluatedValue $value, array
$allCons
$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 @@ private function getGlobalConstDeclaration(EvaluatedValue $value, array
$allCons
return "\tREGISTER_STRING_CONSTANT(\"$constName\", " . ($cExpr ?:
'"' . addslashes($constValue) . '"') . ", $flags);\n";
}
- throw new Exception("Unimplemented constant type");}
+ throw new Exception("Unimplemented constant type");
+ }
/** @param array<string, ConstInfo> $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 7426a7360eee1..8e5bf1a36c25f 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 b0c12e011674d..6177d9fb590e6 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 6ab700254dbd4..cdf21396bb0ab 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 df9a9078ee4a3..a359cb725d085 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 29d8642b8f713..44c2048fe4cc3 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 9b0c08c592c06..fd8ac28dd8b7f 100644
--- a/main/main.stub.php
+++ b/main/main.stub.php
@@ -354,3 +354,15 @@
*/
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 c19f5420d4f36..9c12a06579290 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);
}