Skip to content

Improve string class constant code generation #9577

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 2 commits into from
Sep 26, 2022
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
2 changes: 1 addition & 1 deletion build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ public function initializeZval(string $zvalName, iterable $allConstInfos): strin
$code .= "\tZVAL_EMPTY_STRING(&$zvalName);\n";
} else {
$constValue = $cConstValue ?: '"' . addslashes($this->value) . '"';
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, sizeof($constValue) - 1, 1);\n";
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, strlen($constValue), 1);\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, strlen($constValue), 1);\n";
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, strlen($constValue), true);\n";

Copy link
Contributor

@mvorisek mvorisek Sep 26, 2022

Choose a reason for hiding this comment

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

@kocsismate why is 1 preferred over true?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mvorisek I wouldn't say at all that 1 is preferred, but TBH I don't really care which value is used.

$code .= "\tZVAL_STR(&$zvalName, {$zvalName}_str);\n";
}
} elseif ($this->type->isArray()) {
Expand Down
28 changes: 14 additions & 14 deletions ext/date/php_date_arginfo.h

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

14 changes: 7 additions & 7 deletions ext/intl/locale/locale_arginfo.h

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

2 changes: 1 addition & 1 deletion ext/intl/uchar/uchar_arginfo.h

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

2 changes: 1 addition & 1 deletion ext/mysqli/mysqli_arginfo.h

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

2 changes: 1 addition & 1 deletion ext/pdo/pdo_dbh_arginfo.h

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

8 changes: 4 additions & 4 deletions ext/zend_test/test_arginfo.h

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

6 changes: 0 additions & 6 deletions ext/zip/php_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -3110,12 +3110,6 @@ static PHP_MINIT_FUNCTION(zip)
php_zip_register_prop_handler(&zip_prop_handlers, "filename", NULL, php_zipobj_get_filename, IS_STRING);
php_zip_register_prop_handler(&zip_prop_handlers, "comment", NULL, php_zipobj_get_zip_comment, IS_STRING);

#ifdef HAVE_LIBZIP_VERSION
zend_declare_class_constant_string(zip_class_entry, "LIBZIP_VERSION", sizeof("LIBZIP_VERSION")-1, zip_libzip_version());
#else
zend_declare_class_constant_string(zip_class_entry, "LIBZIP_VERSION", sizeof("LIBZIP_VERSION")-1, LIBZIP_VERSION);
#endif

php_register_url_stream_wrapper("zip", &php_stream_zip_wrapper);

le_zip_dir = zend_register_list_destructors_ex(php_zip_free_dir, NULL, le_zip_dir_name, module_number);
Expand Down
6 changes: 6 additions & 0 deletions ext/zip/php_zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ extern zend_module_entry zip_module_entry;

#define PHP_ZIP_VERSION "1.21.1"

#ifdef HAVE_LIBZIP_VERSION
#define LIBZIP_VERSION_STR zip_libzip_version()
#else
#define LIBZIP_VERSION_STR LIBZIP_VERSION
#endif

#define ZIP_OPENBASEDIR_CHECKPATH(filename) php_check_open_basedir(filename)

typedef struct _ze_zip_rsrc {
Expand Down
6 changes: 6 additions & 0 deletions ext/zip/php_zip.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,12 @@ class ZipArchive implements Countable
*/
public const EM_UNKNOWN = UNKNOWN;

/**
* @var string
* @cvalue LIBZIP_VERSION_STR
*/
public const LIBZIP_VERSION = UNKNOWN;

/** @readonly */
public int $lastId;
/** @readonly */
Expand Down
9 changes: 8 additions & 1 deletion ext/zip/php_zip_arginfo.h

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