com php-src: Assert that symbol table is available in compact(): ext/standard/array.c ext/standard/basic_functions.stub.ph p
ext/standard/basic_functions_arginfo.h
| From: | Nikita Popov | Date: | Mon, 26 Aug 2019 12:25:48 +0000 |
| Subject: | com php-src: Assert that symbol table is available in compact(): ext/standard/array.c ext/standard/basic_functions.stub.ph p ext/standard/basic_functions_arginfo.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-108061@lists.php.net to get a copy of this message | ||
Commit: a47f170a7562d40d2f675600c641c616c2ebc592
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 26 Aug 2019 14:24:31 +0200
Parents: 99c57b33cf55f6299450aab24d6d2e73228be261
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a47f170a7562d40d2f675600c641c616c2ebc592
Log:
Assert that symbol table is available in compact()
I believe NULL here is no longer possible due to the dynamic call
check. A similar assumption already exists in the extract()
implementation.
Changed paths:
M ext/standard/array.c
M ext/standard/basic_functions.stub.php
M ext/standard/basic_functions_arginfo.h
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index fcb0f21..84f19c4 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2469,6 +2469,7 @@ PHP_FUNCTION(extract)
}
symbol_table = zend_rebuild_symbol_table();
+ ZEND_ASSERT(symbol_table && "A symbol table should always be available here");
if (extract_refs) {
switch (extract_type) {
@@ -2566,7 +2567,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval
*return_valu
}
/* }}} */
-/* {{{ proto array|null compact(mixed var_names [, mixed ...])
+/* {{{ proto array compact(mixed var_names [, mixed ...])
Creates a hash containing variables and their values */
PHP_FUNCTION(compact)
{
@@ -2583,9 +2584,7 @@ PHP_FUNCTION(compact)
}
symbol_table = zend_rebuild_symbol_table();
- if (UNEXPECTED(symbol_table == NULL)) {
- return;
- }
+ ZEND_ASSERT(symbol_table && "A symbol table should always be available here");
/* compact() is probably most used with a single array of var_names
or multiple string names, rather than a combination of both.
diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php
index 146e14d..ea1d99f 100644
--- a/ext/standard/basic_functions.stub.php
+++ b/ext/standard/basic_functions.stub.php
@@ -141,7 +141,7 @@ function array_search($needle, array $haystack, bool $strict = false) {}
/** @prefer-ref $arg */
function extract(array &$arg, int $extract_type = EXTR_OVERWRITE, string $prefix =
""): ?int {}
-function compact($var_name, ...$var_names): ?array {}
+function compact($var_name, ...$var_names): array {}
/** @return array|false */
function array_fill(int $start_key, int $num, $val) {}
diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h
index 19ebcc1..4ca84cf 100644
--- a/ext/standard/basic_functions_arginfo.h
+++ b/ext/standard/basic_functions_arginfo.h
@@ -156,7 +156,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_extract, 0, 1, IS_LONG, 1)
ZEND_ARG_TYPE_INFO(0, prefix, IS_STRING, 0)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_compact, 0, 1, IS_ARRAY, 1)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_compact, 0, 1, IS_ARRAY, 0)
ZEND_ARG_INFO(0, var_name)
ZEND_ARG_VARIADIC_INFO(0, var_names)
ZEND_END_ARG_INFO()