Skip to content

Commit a993e63

Browse files
gen_stub: ZEND_ACC_NODISCARD is for PHP 8.5+
1 parent 26dbcb7 commit a993e63

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

build/gen_stub.php

+29-6
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,13 @@ public function getFunctionEntry(): string {
13901390
$name = "zim_" . $this->name->getDeclarationClassName() . "_" . $this->name->methodName;
13911391

13921392
if ($isVanillaEntry) {
1393-
$functionEntryCode = "\tZEND_ME(" . $this->name->getDeclarationClassName() . ", " . $this->name->methodName . ", $argInfoName, " . implode("|", reset($flagsByPhpVersions)) . ")";
1393+
$template = "\tZEND_ME(" . $this->name->getDeclarationClassName() . ", " . $this->name->methodName . ", $argInfoName, %s)\n";
1394+
$flagsCode = generateVersionDependentFlagCode(
1395+
$template,
1396+
$flagsByPhpVersions,
1397+
$this->minimumPhpVersionIdCompatibility
1398+
);
1399+
$functionEntryCode = rtrim( implode("", $flagsCode) );
13941400
}
13951401
}
13961402
}
@@ -1406,7 +1412,15 @@ public function getFunctionEntry(): string {
14061412
$zendName = '"' . $functionName . '"';
14071413
$name = "zif_$declarationName";
14081414

1409-
if ($isVanillaEntry && reset($flagsByPhpVersions) === ["0"]) {
1415+
// Can only use ZEND_FE() if we have no flags for *all* versions
1416+
$hasFlags = false;
1417+
foreach ($flagsByPhpVersions as $flags) {
1418+
if ($flags !== ['0']) {
1419+
$hasFlags = true;
1420+
break;
1421+
}
1422+
}
1423+
if ($isVanillaEntry && !$hasFlags) {
14101424
$functionEntryCode = "\tZEND_FE($declarationName, $argInfoName)";
14111425
}
14121426
}
@@ -1523,9 +1537,6 @@ private function getArginfoFlagsByPhpVersions(): array
15231537
case "Deprecated":
15241538
$flags[] = "ZEND_ACC_DEPRECATED";
15251539
break;
1526-
case "NoDiscard":
1527-
$flags[] = "ZEND_ACC_NODISCARD";
1528-
break;
15291540
}
15301541
}
15311542

@@ -1534,12 +1545,24 @@ private function getArginfoFlagsByPhpVersions(): array
15341545
$php82AndAboveFlags[] = "ZEND_ACC_COMPILE_TIME_EVAL";
15351546
}
15361547

1548+
$php85AndAboveFlags = $php82AndAboveFlags;
1549+
foreach ($this->attributes as $attr) {
1550+
switch ($attr->class) {
1551+
case "NoDiscard":
1552+
$php85AndAboveFlags[] = "ZEND_ACC_NODISCARD";
1553+
break;
1554+
}
1555+
}
1556+
15371557
if (empty($flags)) {
15381558
$flags[] = "0";
15391559
}
15401560
if (empty($php82AndAboveFlags)) {
15411561
$php82AndAboveFlags[] = "0";
15421562
}
1563+
if (empty($php85AndAboveFlags)) {
1564+
$php85AndAboveFlags[] = "0";
1565+
}
15431566

15441567
return [
15451568
PHP_70_VERSION_ID => $flags,
@@ -1548,7 +1571,7 @@ private function getArginfoFlagsByPhpVersions(): array
15481571
PHP_82_VERSION_ID => $php82AndAboveFlags,
15491572
PHP_83_VERSION_ID => $php82AndAboveFlags,
15501573
PHP_84_VERSION_ID => $php82AndAboveFlags,
1551-
PHP_85_VERSION_ID => $php82AndAboveFlags,
1574+
PHP_85_VERSION_ID => $php85AndAboveFlags,
15521575
];
15531576
}
15541577

ext/zend_test/test_arginfo.h

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)