Skip to content

Arginfo: avoid using temporary zvals for initializing attribute values #19141

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 7 additions & 21 deletions Zend/zend_attributes_arginfo.h

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

4 changes: 1 addition & 3 deletions Zend/zend_constants_arginfo.h

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

25 changes: 17 additions & 8 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2358,11 +2358,14 @@ private function __construct($value, SimpleType $type, Expr $expr, array $origin
$this->isUnknownConstValue = $isUnknownConstValue;
}

public function initializeZval(string $zvalName): string
public function initializeZval(string $zvalName, bool $alreadyExists = false, string $forStringDef = ''): string
{
$cExpr = $this->getCExpr();

$code = "\tzval $zvalName;\n";
$code = '';
if (!$alreadyExists) {
$code = "\tzval $zvalName;\n";
}

if ($this->type->isNull()) {
$code .= "\tZVAL_NULL(&$zvalName);\n";
Expand All @@ -2382,8 +2385,11 @@ public function initializeZval(string $zvalName): string
if ($cExpr === '""') {
$code .= "\tZVAL_EMPTY_STRING(&$zvalName);\n";
} else {
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($cExpr, strlen($cExpr), 1);\n";
$code .= "\tZVAL_STR(&$zvalName, {$zvalName}_str);\n";
if ($forStringDef === '') {
$forStringDef = "{$zvalName}_str";
}
$code .= "\tzend_string *$forStringDef = zend_string_init($cExpr, strlen($cExpr), 1);\n";
$code .= "\tZVAL_STR(&$zvalName, $forStringDef);\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this can even be ZVAL_NEW_STR as they're not interned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, all strings that are coming from KNOWN_STRINGS can be set via ZVAL_INTERNED_STR

}
} elseif ($this->type->isArray()) {
if ($cExpr == '[]') {
Expand Down Expand Up @@ -2821,7 +2827,8 @@ private function getClassConstDeclaration(EvaluatedValue $value, array $allConst
{
$constName = $this->name->getDeclarationName();

$zvalCode = $value->initializeZval("const_{$constName}_value", $allConstInfos);
// TODO $allConstInfos is unused
$zvalCode = $value->initializeZval("const_{$constName}_value");

$code = "\n" . $zvalCode;

Expand Down Expand Up @@ -3378,9 +3385,11 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC
}
if ($initValue === '') {
$value = EvaluatedValue::createFromExpression($arg->value, null, null, $allConstInfos);
$zvalName = "attribute_{$escapedAttributeName}_{$nameSuffix}_arg$i";
$code .= $value->initializeZval($zvalName);
$code .= "\tZVAL_COPY_VALUE(&attribute_{$escapedAttributeName}_{$nameSuffix}->args[$i].value, &$zvalName);\n";
$code .= $value->initializeZval(
"attribute_{$escapedAttributeName}_{$nameSuffix}->args[$i].value",
true,
"attribute_{$escapedAttributeName}_{$nameSuffix}_arg{$i}_str"
);
} else {
$code .= $initValue;
}
Expand Down
4 changes: 1 addition & 3 deletions ext/curl/curl_arginfo.h

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

Loading