-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is used to initialize strings in other places too, not just for the attribute values, so I would want to make a change in the initialization macro in a separate patch |
||
} | ||
} elseif ($this->type->isArray()) { | ||
if ($cExpr == '[]') { | ||
|
@@ -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; | ||
|
||
|
@@ -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; | ||
} | ||
|