-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Use attribute validator for assigning flags #19465
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
Open
iluuu1994
wants to merge
2
commits into
php:master
Choose a base branch
from
iluuu1994:expand-attribute-validator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+82
−95
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -70,7 +70,7 @@ uint32_t zend_attribute_attribute_get_flags(zend_attribute *attr, zend_class_ent | |||||
} | ||||||
|
||||||
static void validate_allow_dynamic_properties( | ||||||
zend_attribute *attr, uint32_t target, zend_class_entry *scope) | ||||||
zend_attribute *attr, uint32_t target_type, zend_class_entry *scope, void *target, uint32_t offset) | ||||||
{ | ||||||
if (scope->ce_flags & ZEND_ACC_TRAIT) { | ||||||
zend_error_noreturn(E_ERROR, "Cannot apply #[\\AllowDynamicProperties] to trait %s", | ||||||
|
@@ -96,7 +96,7 @@ static void validate_allow_dynamic_properties( | |||||
} | ||||||
|
||||||
static void validate_attribute( | ||||||
zend_attribute *attr, uint32_t target, zend_class_entry *scope) | ||||||
zend_attribute *attr, uint32_t target_type, zend_class_entry *scope, void *target, uint32_t offset) | ||||||
{ | ||||||
const char *msg = NULL; | ||||||
if (scope->ce_flags & ZEND_ACC_TRAIT) { | ||||||
|
@@ -113,6 +113,51 @@ static void validate_attribute( | |||||
} | ||||||
} | ||||||
|
||||||
static void validate_override( | ||||||
zend_attribute *attr, uint32_t target_type, zend_class_entry *scope, void *target, uint32_t offset) | ||||||
{ | ||||||
if (target_type & ZEND_ATTRIBUTE_TARGET_METHOD) { | ||||||
zend_op_array *op_array = target; | ||||||
op_array->fn_flags |= ZEND_ACC_OVERRIDE; | ||||||
} else { | ||||||
ZEND_ASSERT(target_type & ZEND_ATTRIBUTE_TARGET_PROPERTY); | ||||||
zend_property_info *prop_info = target; | ||||||
prop_info->flags |= ZEND_ACC_OVERRIDE; | ||||||
} | ||||||
} | ||||||
|
||||||
static void validate_deprecated( | ||||||
zend_attribute *attr, uint32_t target_type, zend_class_entry *scope, void *target, uint32_t offset) | ||||||
{ | ||||||
if (target_type & (ZEND_ATTRIBUTE_TARGET_FUNCTION|ZEND_ATTRIBUTE_TARGET_METHOD)) { | ||||||
zend_op_array *op_array = target; | ||||||
op_array->fn_flags |= ZEND_ACC_DEPRECATED; | ||||||
} else if (target_type & (ZEND_ATTRIBUTE_TARGET_CLASS_CONST)) { | ||||||
zend_class_constant *c = target; | ||||||
ZEND_CLASS_CONST_FLAGS(c) |= ZEND_ACC_DEPRECATED; | ||||||
/* For deprecated constants, we need to flag the zval for recursion | ||||||
* detection. Make sure the zval is separated out of shm. */ | ||||||
scope->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS; | ||||||
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. after removing the separate
Suggested change
and similar for the removal of ZEND_ACC_CONSTANTS_UPDATED |
||||||
scope->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED; | ||||||
} else { | ||||||
ZEND_ASSERT(target_type & ZEND_ATTRIBUTE_TARGET_CONST); | ||||||
zend_constant *c = target; | ||||||
ZEND_CONSTANT_SET_FLAGS( | ||||||
c, | ||||||
ZEND_CONSTANT_FLAGS(c) | CONST_DEPRECATED, | ||||||
ZEND_CONSTANT_MODULE_NUMBER(c) | ||||||
); | ||||||
} | ||||||
} | ||||||
|
||||||
static void validate_no_discard( | ||||||
zend_attribute *attr, uint32_t target_type, zend_class_entry *scope, void *target, uint32_t offset) | ||||||
{ | ||||||
ZEND_ASSERT(target_type & (ZEND_ATTRIBUTE_TARGET_FUNCTION|ZEND_ATTRIBUTE_TARGET_METHOD)); | ||||||
zend_op_array *op_array = target; | ||||||
op_array->fn_flags |= ZEND_ACC_NODISCARD; | ||||||
} | ||||||
|
||||||
ZEND_METHOD(Attribute, __construct) | ||||||
{ | ||||||
zend_long flags = ZEND_ATTRIBUTE_TARGET_ALL; | ||||||
|
@@ -560,13 +605,16 @@ void zend_register_attribute_ce(void) | |||||
zend_ce_sensitive_parameter_value->default_object_handlers = &attributes_object_handlers_sensitive_parameter_value; | ||||||
|
||||||
zend_ce_override = register_class_Override(); | ||||||
zend_mark_internal_attribute(zend_ce_override); | ||||||
attr = zend_mark_internal_attribute(zend_ce_override); | ||||||
attr->validator = validate_override; | ||||||
|
||||||
zend_ce_deprecated = register_class_Deprecated(); | ||||||
attr = zend_mark_internal_attribute(zend_ce_deprecated); | ||||||
attr->validator = validate_deprecated; | ||||||
|
||||||
zend_ce_nodiscard = register_class_NoDiscard(); | ||||||
attr = zend_mark_internal_attribute(zend_ce_nodiscard); | ||||||
attr->validator = validate_no_discard; | ||||||
} | ||||||
|
||||||
void zend_attributes_shutdown(void) | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,8 @@ typedef struct _zend_attribute { | |
typedef struct _zend_internal_attribute { | ||
zend_class_entry *ce; | ||
uint32_t flags; | ||
void (*validator)(zend_attribute *attr, uint32_t target, zend_class_entry *scope); | ||
/* Parameter offsets start at 1, everything else uses 0. */ | ||
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. we shouldn't need both |
||
void (*validator)(zend_attribute *attr, uint32_t target_type, zend_class_entry *scope, void *target, uint32_t offset); | ||
} zend_internal_attribute; | ||
|
||
ZEND_API zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *lcname); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.