Skip to content

Declare the last few remaining constants via stubs #13751

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
Mar 19, 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
17 changes: 14 additions & 3 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,7 @@ class ConstInfo extends VariableLike
public ?string $cond;
public ?string $cValue;
public bool $isUndocumentable;
public bool $isFileCacheAllowed;

/**
* @var AttributeInfo[] $attributes
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4304,6 +4311,7 @@ function parseConstLike(
$deprecated = false;
$cValue = null;
$link = null;
$isFileCacheAllowed = true;
if ($comments) {
$tags = parseDocComments($comments);
foreach ($tags as $tag) {
Expand All @@ -4317,6 +4325,8 @@ function parseConstLike(
$isUndocumentable = true;
} elseif ($tag->name === 'link') {
$link = $tag->value;
} elseif ($tag->name === 'no-file-cache') {
$isFileCacheAllowed = false;
}
}
}
Expand All @@ -4339,7 +4349,8 @@ function parseConstLike(
$link,
$phpVersionIdMinimumCompatibility,
$attributes,
createExposedDocComment($comments)
createExposedDocComment($comments),
$isFileCacheAllowed
);
}

Expand Down
14 changes: 5 additions & 9 deletions ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
/* }}} */
Expand Down
11 changes: 11 additions & 0 deletions ext/standard/dir.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
/**
Expand Down
4 changes: 3 additions & 1 deletion ext/standard/dir_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ext/standard/php_dir_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@

#endif /* HAVE_GLOB */

char dirsep_str[2], pathsep_str[2];

#endif /* PHP_DIR_INT_H */
10 changes: 1 addition & 9 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions main/main.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 3 additions & 1 deletion main/main_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.