-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Zend: Add zend_check_method_accessible()
to DRY method visibility checks
#18995
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -137,5 +137,16 @@ static inline zend_property_info *zend_get_typed_property_info_for_slot(zend_obj | |||||||||||||||||
return NULL; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
static zend_always_inline bool zend_check_method_accessible(const zend_function *fn, const zend_class_entry *scope) | ||||||||||||||||||
{ | ||||||||||||||||||
if (!(fn->common.fn_flags & ZEND_ACC_PUBLIC) | ||||||||||||||||||
&& fn->common.scope != scope | ||||||||||||||||||
&& (UNEXPECTED(fn->common.fn_flags & ZEND_ACC_PRIVATE) | ||||||||||||||||||
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(fn), scope)))) { | ||||||||||||||||||
Comment on lines
+142
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typically the style is to indent subconditions with spaces. One space for every sublevel. I.e.
Suggested change
|
||||||||||||||||||
return false; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
return true; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
#endif /* ZEND_OBJECTS_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6043,14 +6043,12 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY) | |
|
||
if (clone && !(clone->common.fn_flags & ZEND_ACC_PUBLIC)) { | ||
scope = EX(func)->op_array.scope; | ||
if (clone->common.scope != scope) { | ||
if (UNEXPECTED(clone->common.fn_flags & ZEND_ACC_PRIVATE) | ||
|| UNEXPECTED(!zend_check_protected(zend_get_function_root_class(clone), scope))) { | ||
zend_bad_method_call(clone, clone->common.function_name, scope); | ||
FREE_OP1(); | ||
ZVAL_UNDEF(EX_VAR(opline->result.var)); | ||
HANDLE_EXCEPTION(); | ||
} | ||
ZEND_ASSERT(!(clone->common.fn_flags & ZEND_ACC_PUBLIC)); | ||
if (!zend_check_method_accessible(clone, scope)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If inlining is not guaranteed then the extra check on the public flag is not eliminated. always inlining might be better. |
||
zend_bad_method_call(clone, clone->common.function_name, scope); | ||
FREE_OP1(); | ||
ZVAL_UNDEF(EX_VAR(opline->result.var)); | ||
HANDLE_EXCEPTION(); | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To solve the fn_flags reload problem, just insert an ZEND_ASSERT/ZEND_ASSUME here, right before the call to
zend_check_method_accessible
(preferably an assertion).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good idea. That would keep
zend_check_method_accessible()
easy to use compared to asserting withinzend_check_method_accessible()
itself. I'll check this tomorrow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now done. The CI Benchmark still sees a 0.01% increase, which now might actually be noise then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't check now. You didn't specify always_inline though. I also see 0.02 on symfony
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always inline didn't change anything for the non-JIT runs (and my local tests also indicated that the inlining happened).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned:
This doesn't seem to be better in that regard. An assert can at least remind you that you didn't check for
ZEND_ACC_PUBLIC
. Anyway, just my opinion, proceed as you like.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is that the manual checking for public just exists to improve performance when the scope is not yet available. If a scope is already available, then
zend_check_method_accessible()
can just be used directly.Ideally, #18998 would work and we wouldn't need the assert at all.