Skip to content

Commit 4a66341

Browse files
committed
Add funcinfo for spl global functions
This assumes that `iterator_*` will now always throw or abort on failure. Also, move #include _arginfo.h directive to the top of the file - virtually all other files put it there, and developers may base code on basic_functions.c.
1 parent 8fb3ef6 commit 4a66341

File tree

5 files changed

+106
-79
lines changed

5 files changed

+106
-79
lines changed

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,12 +1049,9 @@ static const func_info_t func_infos[] = {
10491049
F1("class_implements", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_STRING),
10501050
F1("class_parents", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_STRING),
10511051
F1("class_uses", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_STRING),
1052-
F0("iterator_apply", MAY_BE_NULL | MAY_BE_LONG),
1053-
F0("iterator_count", MAY_BE_FALSE | MAY_BE_LONG),
1054-
F1("iterator_to_array", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_ARRAY_OF_ANY),
1055-
F1("spl_classes", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_STRING),
1056-
F1("spl_object_hash", MAY_BE_NULL | MAY_BE_STRING),
1057-
F0("spl_object_id", MAY_BE_NULL | MAY_BE_LONG),
1052+
F1("iterator_to_array", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_ARRAY_OF_ANY),
1053+
F1("spl_classes", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_STRING),
1054+
F1("spl_object_hash", MAY_BE_STRING),
10581055

10591056
};
10601057

ext/spl/php_spl.c

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "php_main.h"
2424
#include "ext/standard/info.h"
2525
#include "php_spl.h"
26+
#include "php_spl_arginfo.h"
2627
#include "spl_functions.h"
2728
#include "spl_engine.h"
2829
#include "spl_array.h"
@@ -892,76 +893,6 @@ PHP_MINFO_FUNCTION(spl)
892893
}
893894
/* }}} */
894895

895-
/* {{{ arginfo */
896-
ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_to_array, 0, 0, 1)
897-
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
898-
ZEND_ARG_INFO(0, use_keys)
899-
ZEND_END_ARG_INFO();
900-
901-
ZEND_BEGIN_ARG_INFO(arginfo_iterator, 0)
902-
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
903-
ZEND_END_ARG_INFO();
904-
905-
ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_apply, 0, 0, 2)
906-
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
907-
ZEND_ARG_INFO(0, function)
908-
ZEND_ARG_ARRAY_INFO(0, args, 1)
909-
ZEND_END_ARG_INFO();
910-
911-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_parents, 0, 0, 1)
912-
ZEND_ARG_INFO(0, instance)
913-
ZEND_ARG_INFO(0, autoload)
914-
ZEND_END_ARG_INFO()
915-
916-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_implements, 0, 0, 1)
917-
ZEND_ARG_INFO(0, what)
918-
ZEND_ARG_INFO(0, autoload)
919-
ZEND_END_ARG_INFO()
920-
921-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_uses, 0, 0, 1)
922-
ZEND_ARG_INFO(0, what)
923-
ZEND_ARG_INFO(0, autoload)
924-
ZEND_END_ARG_INFO()
925-
926-
927-
ZEND_BEGIN_ARG_INFO(arginfo_spl_classes, 0)
928-
ZEND_END_ARG_INFO()
929-
930-
ZEND_BEGIN_ARG_INFO(arginfo_spl_autoload_functions, 0)
931-
ZEND_END_ARG_INFO()
932-
933-
ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload, 0, 0, 1)
934-
ZEND_ARG_INFO(0, class_name)
935-
ZEND_ARG_INFO(0, file_extensions)
936-
ZEND_END_ARG_INFO()
937-
938-
ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_extensions, 0, 0, 0)
939-
ZEND_ARG_INFO(0, file_extensions)
940-
ZEND_END_ARG_INFO()
941-
942-
ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_call, 0, 0, 1)
943-
ZEND_ARG_INFO(0, class_name)
944-
ZEND_END_ARG_INFO()
945-
946-
ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_register, 0, 0, 0)
947-
ZEND_ARG_INFO(0, autoload_function)
948-
ZEND_ARG_INFO(0, throw)
949-
ZEND_ARG_INFO(0, prepend)
950-
ZEND_END_ARG_INFO()
951-
952-
ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_autoload_unregister, 0, 0, 1)
953-
ZEND_ARG_INFO(0, autoload_function)
954-
ZEND_END_ARG_INFO()
955-
956-
ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_hash, 0, 0, 1)
957-
ZEND_ARG_INFO(0, obj)
958-
ZEND_END_ARG_INFO()
959-
960-
ZEND_BEGIN_ARG_INFO_EX(arginfo_spl_object_id, 0, 0, 1)
961-
ZEND_ARG_INFO(0, obj)
962-
ZEND_END_ARG_INFO()
963-
/* }}} */
964-
965896
/* {{{ spl_functions
966897
*/
967898
static const zend_function_entry spl_functions[] = {
@@ -978,7 +909,7 @@ static const zend_function_entry spl_functions[] = {
978909
PHP_FE(spl_object_hash, arginfo_spl_object_hash)
979910
PHP_FE(spl_object_id, arginfo_spl_object_id)
980911
PHP_FE(iterator_to_array, arginfo_iterator_to_array)
981-
PHP_FE(iterator_count, arginfo_iterator)
912+
PHP_FE(iterator_count, arginfo_iterator_count)
982913
PHP_FE(iterator_apply, arginfo_iterator_apply)
983914
PHP_FE_END
984915
};

ext/spl/php_spl.stub.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/* ext/spl/php_spl.c */
4+
5+
function class_implements($what, bool $autoload = true) : array|false { }
6+
7+
function class_parents($instance, bool $autoload = true) : array|false {}
8+
9+
function class_uses($what, bool $autoload = true) : array|false {}
10+
11+
function spl_autoload(string $class_name, string $file_extensions = '.inc,.php') : void {}
12+
13+
// This silently ignores non-string class names
14+
function spl_autoload_call($class_name) : void {}
15+
16+
function spl_autoload_extensions(string $file_extensions = '') : string {}
17+
18+
function spl_autoload_functions() : array|false {}
19+
20+
function spl_autoload_register($autoload_function = null, bool $throw = true, bool $prepend = false) : bool {}
21+
22+
function spl_autoload_unregister($autoload_function) : bool {}
23+
24+
function spl_classes() : array {}
25+
26+
function spl_object_hash(object $obj) : string {}
27+
28+
function spl_object_id(object $obj) : int {}
29+
30+
/* ext/spl/spl_iterators.c */
31+
function iterator_apply(Traversable $iterator, $function, ?array $args = null) : int {}
32+
33+
function iterator_count(Traversable $iterator) : int {}
34+
35+
function iterator_to_array(Traversable $iterator, bool $use_keys = true) : array { }

ext/spl/php_spl_arginfo.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* This is a generated file, edit the .stub.php file instead. */
2+
3+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_implements, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
4+
ZEND_ARG_INFO(0, what)
5+
ZEND_ARG_TYPE_INFO(0, autoload, _IS_BOOL, 0)
6+
ZEND_END_ARG_INFO()
7+
8+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_parents, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
9+
ZEND_ARG_INFO(0, instance)
10+
ZEND_ARG_TYPE_INFO(0, autoload, _IS_BOOL, 0)
11+
ZEND_END_ARG_INFO()
12+
13+
#define arginfo_class_uses arginfo_class_implements
14+
15+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload, 0, 1, IS_VOID, 0)
16+
ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 0)
17+
ZEND_ARG_TYPE_INFO(0, file_extensions, IS_STRING, 0)
18+
ZEND_END_ARG_INFO()
19+
20+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_call, 0, 1, IS_VOID, 0)
21+
ZEND_ARG_INFO(0, class_name)
22+
ZEND_END_ARG_INFO()
23+
24+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_extensions, 0, 0, IS_STRING, 0)
25+
ZEND_ARG_TYPE_INFO(0, file_extensions, IS_STRING, 0)
26+
ZEND_END_ARG_INFO()
27+
28+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_spl_autoload_functions, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
29+
ZEND_END_ARG_INFO()
30+
31+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_register, 0, 0, _IS_BOOL, 0)
32+
ZEND_ARG_INFO(0, autoload_function)
33+
ZEND_ARG_TYPE_INFO(0, throw, _IS_BOOL, 0)
34+
ZEND_ARG_TYPE_INFO(0, prepend, _IS_BOOL, 0)
35+
ZEND_END_ARG_INFO()
36+
37+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_unregister, 0, 1, _IS_BOOL, 0)
38+
ZEND_ARG_INFO(0, autoload_function)
39+
ZEND_END_ARG_INFO()
40+
41+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_classes, 0, 0, IS_ARRAY, 0)
42+
ZEND_END_ARG_INFO()
43+
44+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_object_hash, 0, 1, IS_STRING, 0)
45+
ZEND_ARG_TYPE_INFO(0, obj, IS_OBJECT, 0)
46+
ZEND_END_ARG_INFO()
47+
48+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_object_id, 0, 1, IS_LONG, 0)
49+
ZEND_ARG_TYPE_INFO(0, obj, IS_OBJECT, 0)
50+
ZEND_END_ARG_INFO()
51+
52+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iterator_apply, 0, 2, IS_LONG, 0)
53+
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
54+
ZEND_ARG_INFO(0, function)
55+
ZEND_ARG_TYPE_INFO(0, args, IS_ARRAY, 1)
56+
ZEND_END_ARG_INFO()
57+
58+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iterator_count, 0, 1, IS_LONG, 0)
59+
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
60+
ZEND_END_ARG_INFO()
61+
62+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iterator_to_array, 0, 1, IS_ARRAY, 0)
63+
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
64+
ZEND_ARG_TYPE_INFO(0, use_keys, _IS_BOOL, 0)
65+
ZEND_END_ARG_INFO()

ext/standard/basic_functions.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "ext/standard/php_dns.h"
3434
#include "ext/standard/php_uuencode.h"
3535
#include "ext/standard/php_mt_rand.h"
36+
#include "basic_functions_arginfo.h"
3637

3738
#ifdef PHP_WIN32
3839
#include "win32/php_win32_globals.h"
@@ -525,8 +526,6 @@ ZEND_END_ARG_INFO()
525526
/* }}} */
526527
/* }}} */
527528

528-
#include "basic_functions_arginfo.h"
529-
530529
static const zend_function_entry basic_functions[] = { /* {{{ */
531530
PHP_FE(constant, arginfo_constant)
532531
PHP_FE(bin2hex, arginfo_bin2hex)

0 commit comments

Comments
 (0)