Skip to content

Commit 425e7cc

Browse files
Generated arginfo header files: replace sizeof() with strlen()
The coding conventions call for using `strlen()` on constant strings, but not refactoring existing uses of `sizeof()` unless there is existing refactoring taking place. I have recently sent a few patches that refactored/simplified some of the arginfo headers, but this patch touches more of them. The generated headers present a special case - until they are updated to use `strlen()`, new additions will be forced to use `sizeof()`, since that is what the generator script produces. Let's just make the change now.
1 parent f12b231 commit 425e7cc

File tree

67 files changed

+2147
-2147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2147
-2147
lines changed

Zend/zend_attributes_arginfo.h

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Zend/zend_builtin_functions_arginfo.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Zend/zend_exceptions_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/gen_stub.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ protected function getTypeCode(string $variableLikeName, string &$code): string
24452445
foreach ($arginfoType->classTypes as $classType) {
24462446
$escapedClassName = $classType->toEscapedName();
24472447
$varEscapedClassName = $classType->toVarEscapedName();
2448-
$code .= "\tzend_string *{$variableLikeType}_{$variableLikeName}_class_{$varEscapedClassName} = zend_string_init(\"{$escapedClassName}\", sizeof(\"{$escapedClassName}\") - 1, 1);\n";
2448+
$code .= "\tzend_string *{$variableLikeType}_{$variableLikeName}_class_{$varEscapedClassName} = zend_string_init(\"{$escapedClassName}\", strlen(\"{$escapedClassName}\"), 1);\n";
24492449
}
24502450

24512451
$classTypeCount = count($arginfoType->classTypes);
@@ -2468,7 +2468,7 @@ protected function getTypeCode(string $variableLikeName, string &$code): string
24682468
} else {
24692469
$escapedClassName = $arginfoType->classTypes[0]->toEscapedName();
24702470
$varEscapedClassName = $arginfoType->classTypes[0]->toVarEscapedName();
2471-
$code .= "\tzend_string *{$variableLikeType}_{$variableLikeName}_class_{$varEscapedClassName} = zend_string_init(\"{$escapedClassName}\", sizeof(\"{$escapedClassName}\")-1, 1);\n";
2471+
$code .= "\tzend_string *{$variableLikeType}_{$variableLikeName}_class_{$varEscapedClassName} = zend_string_init(\"{$escapedClassName}\", strlen(\"{$escapedClassName}\"), 1);\n";
24722472

24732473
$typeCode = "(zend_type) ZEND_TYPE_INIT_CLASS({$variableLikeType}_{$variableLikeName}_class_{$varEscapedClassName}, 0, " . $arginfoType->toTypeMask() . ")";
24742474
}
@@ -2772,7 +2772,7 @@ private function getClassConstDeclaration(EvaluatedValue $value, array $allConst
27722772

27732773
$code = "\n" . $zvalCode;
27742774

2775-
$code .= "\tzend_string *const_{$constName}_name = zend_string_init_interned(\"$constName\", sizeof(\"$constName\") - 1, 1);\n";
2775+
$code .= "\tzend_string *const_{$constName}_name = zend_string_init_interned(\"$constName\", strlen(\"$constName\"), 1);\n";
27762776
$nameCode = "const_{$constName}_name";
27772777

27782778
if ($this->exposedDocComment) {
@@ -3149,7 +3149,7 @@ private function getString(string $propName): array {
31493149
// Generally strings will not be known
31503150
$nameCode = "property_{$propName}_name";
31513151
$result = [
3152-
"\tzend_string *$nameCode = zend_string_init(\"$propName\", sizeof(\"$propName\") - 1, 1);\n",
3152+
"\tzend_string *$nameCode = zend_string_init(\"$propName\", strlen(\"$propName\"), 1);\n",
31533153
$nameCode,
31543154
"\tzend_string_release($nameCode);\n"
31553155
];
@@ -3297,7 +3297,7 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC
32973297
if (isset($knowns[$escapedAttributeName])) {
32983298
$code .= "\t" . ($this->args ? "zend_attribute *attribute_{$escapedAttributeName}_$nameSuffix = " : "") . "$invocation, ZSTR_KNOWN({$knowns[$escapedAttributeName]}), " . count($this->args) . ");\n";
32993299
} else {
3300-
$code .= "\tzend_string *attribute_name_{$escapedAttributeName}_$nameSuffix = zend_string_init_interned(\"" . addcslashes($this->class, "\\") . "\", sizeof(\"" . addcslashes($this->class, "\\") . "\") - 1, 1);\n";
3300+
$code .= "\tzend_string *attribute_name_{$escapedAttributeName}_$nameSuffix = zend_string_init_interned(\"" . addcslashes($this->class, "\\") . "\", strlen(\"" . addcslashes($this->class, "\\") . "\"), 1);\n";
33013301
$code .= "\t" . ($this->args ? "zend_attribute *attribute_{$escapedAttributeName}_$nameSuffix = " : "") . "$invocation, attribute_name_{$escapedAttributeName}_$nameSuffix, " . count($this->args) . ");\n";
33023302
$code .= "\tzend_string_release(attribute_name_{$escapedAttributeName}_$nameSuffix);\n";
33033303
}
@@ -3310,7 +3310,7 @@ public function generateCode(string $invocation, string $nameSuffix, array $allC
33103310
if (isset($knowns[$arg->name->name])) {
33113311
$code .= "\tattribute_{$escapedAttributeName}_{$nameSuffix}->args[$i].name = ZSTR_KNOWN({$knowns[$arg->name->name]});\n";
33123312
} else {
3313-
$code .= "\tattribute_{$escapedAttributeName}_{$nameSuffix}->args[$i].name = zend_string_init_interned(\"{$arg->name->name}\", sizeof(\"{$arg->name->name}\") - 1, 1);\n";
3313+
$code .= "\tattribute_{$escapedAttributeName}_{$nameSuffix}->args[$i].name = zend_string_init_interned(\"{$arg->name->name}\", strlen(\"{$arg->name->name}\"), 1);\n";
33143314
}
33153315
}
33163316
}
@@ -5382,7 +5382,7 @@ static function (FuncInfo $funcInfo) use ($allConstInfos, $phpVersionIdMinimumCo
53825382

53835383
foreach ($funcInfo->attributes as $key => $attribute) {
53845384
$code .= $attribute->generateCode(
5385-
"zend_add_function_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", sizeof(\"" . $funcInfo->name->getNameForAttributes() . "\") - 1)",
5385+
"zend_add_function_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", strlen(\"" . $funcInfo->name->getNameForAttributes() . "\"))",
53865386
"func_" . $funcInfo->name->getNameForAttributes() . "_$key",
53875387
$allConstInfos,
53885388
$phpVersionIdMinimumCompatibility
@@ -5392,7 +5392,7 @@ static function (FuncInfo $funcInfo) use ($allConstInfos, $phpVersionIdMinimumCo
53925392
foreach ($funcInfo->args as $index => $arg) {
53935393
foreach ($arg->attributes as $key => $attribute) {
53945394
$code .= $attribute->generateCode(
5395-
"zend_add_parameter_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", sizeof(\"" . $funcInfo->name->getNameForAttributes() . "\") - 1), $index",
5395+
"zend_add_parameter_attribute(zend_hash_str_find_ptr($functionTable, \"" . $funcInfo->name->getNameForAttributes() . "\", strlen(\"" . $funcInfo->name->getNameForAttributes() . "\")), $index",
53965396
"func_{$funcInfo->name->getNameForAttributes()}_arg{$index}_$key",
53975397
$allConstInfos,
53985398
$phpVersionIdMinimumCompatibility

ext/bcmath/bcmath_arginfo.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)