Skip to content

Commit ebb0a4c

Browse files
committed
Frameless fallback for buildins
1 parent 685e6e4 commit ebb0a4c

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

Zend/zend_builtin_functions.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,21 @@ ZEND_FRAMELESS_FUNCTION(class_exists, 1)
10501050
Z_FLF_PARAM_FREE_STR(1, name_tmp);
10511051
}
10521052

1053+
ZEND_FRAMELESS_FUNCTION(class_exists, 2)
1054+
{
1055+
zval name_tmp;
1056+
zend_string *name;
1057+
bool autoload;
1058+
1059+
Z_FLF_PARAM_STR(1, name, name_tmp);
1060+
Z_FLF_PARAM_BOOL(2, autoload);
1061+
1062+
_class_exists_impl(return_value, name, autoload, ZEND_ACC_LINKED, ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT);
1063+
1064+
flf_clean:
1065+
Z_FLF_PARAM_FREE_STR(1, name_tmp);
1066+
}
1067+
10531068
/* {{{ Checks if the class exists */
10541069
ZEND_FUNCTION(interface_exists)
10551070
{

Zend/zend_builtin_functions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ BEGIN_EXTERN_C()
2828
ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int options, int limit);
2929

3030
extern ZEND_FRAMELESS_FUNCTION(class_exists, 1);
31+
extern ZEND_FRAMELESS_FUNCTION(class_exists, 2);
3132
END_EXTERN_C()
3233

3334
#endif /* ZEND_BUILTIN_FUNCTIONS_H */

Zend/zend_builtin_functions.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function property_exists($object_or_class, string $property): bool {}
7373

7474
/**
7575
* @frameless-function {"arity": 1}
76+
* @frameless-function {"arity": 2}
7677
*/
7778
function class_exists(string $class, bool $autoload = true): bool {}
7879

Zend/zend_builtin_functions_arginfo.h

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

Zend/zend_compile.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4610,22 +4610,8 @@ static zend_result zend_compile_frameless_icall(znode *result, zend_ast_list *ar
46104610
return FAILURE;
46114611
}
46124612

4613-
static zend_result zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args, zend_function *fbc, uint32_t type) /* {{{ */
4613+
static zend_result zend_try_compile_special_func_ex(znode *result, zend_string *lcname, zend_ast_list *args, zend_function *fbc, uint32_t type) /* {{{ */
46144614
{
4615-
if (CG(compiler_options) & ZEND_COMPILE_NO_BUILTINS) {
4616-
return FAILURE;
4617-
}
4618-
4619-
if (fbc->type != ZEND_INTERNAL_FUNCTION) {
4620-
/* If the function is part of disabled_functions, it may be redeclared as a userland
4621-
* function with a different implementation. Don't use the VM builtin in that case. */
4622-
return FAILURE;
4623-
}
4624-
4625-
if (zend_args_contain_unpack_or_named(args)) {
4626-
return FAILURE;
4627-
}
4628-
46294615
if (zend_string_equals_literal(lcname, "strlen")) {
46304616
return zend_compile_func_strlen(result, args);
46314617
} else if (zend_string_equals_literal(lcname, "is_null")) {
@@ -4690,13 +4676,33 @@ static zend_result zend_try_compile_special_func(znode *result, zend_string *lcn
46904676
return zend_compile_func_array_slice(result, args);
46914677
} else if (zend_string_equals_literal(lcname, "array_key_exists")) {
46924678
return zend_compile_func_array_key_exists(result, args);
4693-
} else if (zend_compile_frameless_icall(result, args, fbc, type) == SUCCESS) {
4694-
return SUCCESS;
46954679
} else {
46964680
return FAILURE;
46974681
}
46984682
}
4699-
/* }}} */
4683+
4684+
static zend_result zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args, zend_function *fbc, uint32_t type) /* {{{ */
4685+
{
4686+
if (CG(compiler_options) & ZEND_COMPILE_NO_BUILTINS) {
4687+
return FAILURE;
4688+
}
4689+
4690+
if (fbc->type != ZEND_INTERNAL_FUNCTION) {
4691+
/* If the function is part of disabled_functions, it may be redeclared as a userland
4692+
* function with a different implementation. Don't use the VM builtin in that case. */
4693+
return FAILURE;
4694+
}
4695+
4696+
if (zend_args_contain_unpack_or_named(args)) {
4697+
return FAILURE;
4698+
}
4699+
4700+
if (zend_try_compile_special_func_ex(result, lcname, args, fbc, type) == SUCCESS) {
4701+
return SUCCESS;
4702+
}
4703+
4704+
return zend_compile_frameless_icall(result, args, fbc, type);
4705+
}
47004706

47014707
static void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
47024708
{

0 commit comments

Comments
 (0)