Skip to content

Commit 423e50c

Browse files
authored
zend_object_handler.c: call zend_get_call_trampoline_func() and pass zend_function* directly (#20297)
Abstracting away the bool parameter is not that useful, and doesn't make the code more legible. Moreover, it is not needed if one passes the zend_function* directly, which we always have. This is because it can be derived/copied from the fn_flags.
1 parent 4461e29 commit 423e50c

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

UPGRADING.INTERNALS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ PHP 8.6 INTERNALS UPGRADE NOTES
4141
stored instead.
4242
. The zend_active_function{_ex}() functions now return a const zend_function
4343
pointer.
44+
. The zend_get_call_trampoline_func() API now takes the __call or
45+
__callStatic zend_function* instead of a CE and a boolean argument.
4446

4547
========================
4648
2. Build system changes

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3955,7 +3955,7 @@ static zend_always_inline bool zend_is_callable_check_func(zval *callable, const
39553955
get_function_via_handler:
39563956
if (fcc->object && fcc->calling_scope == ce_org) {
39573957
if (strict_class && ce_org->__call) {
3958-
fcc->function_handler = zend_get_call_trampoline_func(ce_org, mname, 0);
3958+
fcc->function_handler = zend_get_call_trampoline_func(ce_org->__call, mname);
39593959
call_via_handler = 1;
39603960
retval = true;
39613961
} else {

Zend/zend_object_handlers.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,19 +1674,17 @@ ZEND_API bool zend_check_protected(const zend_class_entry *ce, const zend_class_
16741674
}
16751675
/* }}} */
16761676

1677-
ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce, zend_string *method_name, bool is_static) /* {{{ */
1677+
ZEND_API ZEND_ATTRIBUTE_NONNULL zend_function *zend_get_call_trampoline_func(
1678+
const zend_function *fbc, zend_string *method_name) /* {{{ */
16781679
{
16791680
size_t mname_len;
16801681
zend_op_array *func;
1681-
zend_function *fbc = is_static ? ce->__callstatic : ce->__call;
16821682
/* We use non-NULL value to avoid useless run_time_cache allocation.
16831683
* The low bit must be zero, to not be interpreted as a MAP_PTR offset.
16841684
*/
16851685
static const void *dummy = (void*)(intptr_t)2;
16861686
static const zend_arg_info arg_info[1] = {{0}};
16871687

1688-
ZEND_ASSERT(fbc);
1689-
16901688
if (EXPECTED(EG(trampoline).common.function_name == NULL)) {
16911689
func = &EG(trampoline).op_array;
16921690
} else {
@@ -1700,13 +1698,10 @@ ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce
17001698
func->fn_flags = ZEND_ACC_CALL_VIA_TRAMPOLINE
17011699
| ZEND_ACC_PUBLIC
17021700
| ZEND_ACC_VARIADIC
1703-
| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD));
1701+
| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED|ZEND_ACC_NODISCARD|ZEND_ACC_STATIC));
17041702
func->fn_flags2 = 0;
17051703
/* Attributes outlive the trampoline because they are created by the compiler. */
17061704
func->attributes = fbc->common.attributes;
1707-
if (is_static) {
1708-
func->fn_flags |= ZEND_ACC_STATIC;
1709-
}
17101705
func->opcodes = &EG(call_trampoline_op);
17111706
ZEND_MAP_PTR_INIT(func->run_time_cache, (void**)dummy);
17121707
func->scope = fbc->common.scope;
@@ -1828,12 +1823,6 @@ ZEND_API zend_function *zend_get_property_hook_trampoline(
18281823
return func;
18291824
}
18301825

1831-
static zend_always_inline zend_function *zend_get_user_call_function(zend_class_entry *ce, zend_string *method_name) /* {{{ */
1832-
{
1833-
return zend_get_call_trampoline_func(ce, method_name, false);
1834-
}
1835-
/* }}} */
1836-
18371826
ZEND_API ZEND_COLD zend_never_inline void zend_bad_method_call(const zend_function *fbc, const zend_string *method_name, const zend_class_entry *scope) /* {{{ */
18381827
{
18391828
zend_throw_error(NULL, "Call to %s method %s::%s() from %s%s",
@@ -1875,7 +1864,7 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
18751864
ZSTR_ALLOCA_FREE(lc_method_name, use_heap);
18761865
}
18771866
if (zobj->ce->__call) {
1878-
return zend_get_user_call_function(zobj->ce, method_name);
1867+
return zend_get_call_trampoline_func(zobj->ce->__call, method_name);
18791868
} else {
18801869
return NULL;
18811870
}
@@ -1901,7 +1890,7 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
19011890
if (UNEXPECTED(fbc->op_array.fn_flags & ZEND_ACC_PRIVATE)
19021891
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fbc), scope))) {
19031892
if (zobj->ce->__call) {
1904-
fbc = zend_get_user_call_function(zobj->ce, method_name);
1893+
fbc = zend_get_call_trampoline_func(zobj->ce->__call, method_name);
19051894
} else {
19061895
zend_bad_method_call(fbc, method_name, scope);
19071896
fbc = NULL;
@@ -1922,14 +1911,8 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
19221911
}
19231912
/* }}} */
19241913

1925-
static zend_always_inline zend_function *zend_get_user_callstatic_function(zend_class_entry *ce, zend_string *method_name) /* {{{ */
1926-
{
1927-
return zend_get_call_trampoline_func(ce, method_name, true);
1928-
}
1929-
/* }}} */
1930-
19311914
static zend_always_inline zend_function *get_static_method_fallback(
1932-
zend_class_entry *ce, zend_string *function_name)
1915+
const zend_class_entry *ce, zend_string *function_name)
19331916
{
19341917
zend_object *object;
19351918
if (ce->__call &&
@@ -1939,9 +1922,9 @@ static zend_always_inline zend_function *get_static_method_fallback(
19391922
* see: tests/classes/__call_004.phpt */
19401923

19411924
ZEND_ASSERT(object->ce->__call);
1942-
return zend_get_user_call_function(object->ce, function_name);
1925+
return zend_get_call_trampoline_func(object->ce->__call, function_name);
19431926
} else if (ce->__callstatic) {
1944-
return zend_get_user_callstatic_function(ce, function_name);
1927+
return zend_get_call_trampoline_func(ce->__callstatic, function_name);
19451928
} else {
19461929
return NULL;
19471930
}

Zend/zend_object_handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ ZEND_API bool zend_check_protected(const zend_class_entry *ce, const zend_class_
312312

313313
ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_string *prop_info_name, bool is_dynamic);
314314

315-
ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce, zend_string *method_name, bool is_static);
315+
ZEND_API ZEND_ATTRIBUTE_NONNULL zend_function *zend_get_call_trampoline_func(const zend_function *fbc, zend_string *method_name);
316316

317317
ZEND_API uint32_t *zend_get_property_guard(zend_object *zobj, zend_string *member);
318318

0 commit comments

Comments
 (0)