Skip to content

Extract obtaining of fake scope into function #14960

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
Jul 15, 2024
Merged
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
44 changes: 14 additions & 30 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,20 @@ static ZEND_COLD zend_never_inline void zend_readonly_property_unset_error(
ZSTR_VAL(ce->name), ZSTR_VAL(member));
}

static zend_always_inline zend_class_entry *get_fake_or_executed_scope(void)
{
if (UNEXPECTED(EG(fake_scope))) {
return EG(fake_scope);
} else {
return zend_get_executed_scope();
}
}

static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *ce, zend_string *member, int silent, void **cache_slot, const zend_property_info **info_ptr) /* {{{ */
{
zval *zv;
zend_property_info *property_info;
uint32_t flags;
zend_class_entry *scope;
uintptr_t offset;

if (cache_slot && EXPECTED(ce == CACHED_PTR_EX(cache_slot))) {
Expand Down Expand Up @@ -349,11 +357,7 @@ static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *c
flags = property_info->flags;

if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
if (UNEXPECTED(EG(fake_scope))) {
scope = EG(fake_scope);
} else {
scope = zend_get_executed_scope();
}
zend_class_entry *scope = get_fake_or_executed_scope();

if (property_info->ce != scope) {
if (flags & ZEND_ACC_CHANGED) {
Expand Down Expand Up @@ -436,7 +440,6 @@ ZEND_API zend_property_info *zend_get_property_info(const zend_class_entry *ce,
zval *zv;
zend_property_info *property_info;
uint32_t flags;
zend_class_entry *scope;

if (UNEXPECTED(zend_hash_num_elements(&ce->properties_info) == 0)
|| EXPECTED((zv = zend_hash_find(&ce->properties_info, member)) == NULL)) {
Expand All @@ -454,11 +457,7 @@ ZEND_API zend_property_info *zend_get_property_info(const zend_class_entry *ce,
flags = property_info->flags;

if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
if (UNEXPECTED(EG(fake_scope))) {
scope = EG(fake_scope);
} else {
scope = zend_get_executed_scope();
}
zend_class_entry *scope = get_fake_or_executed_scope();
if (property_info->ce != scope) {
if (flags & ZEND_ACC_CHANGED) {
zend_property_info *p = zend_get_parent_private_property(scope, ce, member);
Expand Down Expand Up @@ -917,12 +916,7 @@ static zend_always_inline bool property_uses_strict_types(void) {
static bool verify_readonly_initialization_access(
const zend_property_info *prop_info, const zend_class_entry *ce,
zend_string *name, const char *operation) {
zend_class_entry *scope;
if (UNEXPECTED(EG(fake_scope))) {
scope = EG(fake_scope);
} else {
scope = zend_get_executed_scope();
}
zend_class_entry *scope = get_fake_or_executed_scope();
if (prop_info->ce == scope) {
return true;
}
Expand Down Expand Up @@ -1839,7 +1833,6 @@ ZEND_API void zend_class_init_statics(zend_class_entry *class_type) /* {{{ */
ZEND_API zval *zend_std_get_static_property_with_info(zend_class_entry *ce, zend_string *property_name, int type, zend_property_info **property_info_ptr) /* {{{ */
{
zval *ret;
zend_class_entry *scope;
zend_property_info *property_info = zend_hash_find_ptr(&ce->properties_info, property_name);
*property_info_ptr = property_info;

Expand All @@ -1848,11 +1841,7 @@ ZEND_API zval *zend_std_get_static_property_with_info(zend_class_entry *ce, zend
}

if (!(property_info->flags & ZEND_ACC_PUBLIC)) {
if (UNEXPECTED(EG(fake_scope))) {
scope = EG(fake_scope);
} else {
scope = zend_get_executed_scope();
}
zend_class_entry *scope = get_fake_or_executed_scope();
if (property_info->ce != scope) {
if (UNEXPECTED(property_info->flags & ZEND_ACC_PRIVATE)
|| UNEXPECTED(!is_protected_compatible_scope(property_info->ce, scope))) {
Expand Down Expand Up @@ -1933,15 +1922,10 @@ static ZEND_COLD zend_never_inline void zend_bad_constructor_call(zend_function
ZEND_API zend_function *zend_std_get_constructor(zend_object *zobj) /* {{{ */
{
zend_function *constructor = zobj->ce->constructor;
zend_class_entry *scope;

if (constructor) {
if (UNEXPECTED(!(constructor->op_array.fn_flags & ZEND_ACC_PUBLIC))) {
if (UNEXPECTED(EG(fake_scope))) {
scope = EG(fake_scope);
} else {
scope = zend_get_executed_scope();
}
zend_class_entry *scope = get_fake_or_executed_scope();
if (UNEXPECTED(constructor->common.scope != scope)) {
if (UNEXPECTED(constructor->op_array.fn_flags & ZEND_ACC_PRIVATE)
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(constructor), scope))) {
Expand Down
Loading