Skip to content

Commit 637f025

Browse files
Add zend_constant_add_attributes() helper
1 parent 18a613c commit 637f025

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

Zend/zend_constants.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "zend.h"
21+
#include "zend_attributes.h"
2122
#include "zend_constants.h"
2223
#include "zend_exceptions.h"
2324
#include "zend_execute.h"
@@ -544,3 +545,21 @@ ZEND_API zend_result zend_register_constant(zend_constant *c)
544545
}
545546
return ret;
546547
}
548+
549+
void zend_constant_add_attributes(zend_constant *c, zval *attributes_ast) {
550+
zend_ast *ast = Z_ASTVAL_P(attributes_ast);
551+
zend_compile_attributes(&c->attributes, ast, 0, ZEND_ATTRIBUTE_TARGET_CONST, 0);
552+
zend_attribute *deprecated_attribute = zend_get_attribute_str(
553+
c->attributes,
554+
"deprecated",
555+
sizeof("deprecated")-1
556+
);
557+
558+
if (deprecated_attribute) {
559+
ZEND_CONSTANT_SET_FLAGS(
560+
c,
561+
ZEND_CONSTANT_FLAGS(c) | CONST_DEPRECATED,
562+
ZEND_CONSTANT_MODULE_NUMBER(c)
563+
);
564+
}
565+
}

Zend/zend_constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ ZEND_API void zend_register_double_constant(const char *name, size_t name_len, d
8787
ZEND_API void zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number);
8888
ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number);
8989
ZEND_API zend_result zend_register_constant(zend_constant *c);
90+
void zend_constant_add_attributes(zend_constant *c, zval *attributes_ast);
9091
#ifdef ZTS
9192
void zend_copy_constants(HashTable *target, HashTable *source);
9293
#endif

Zend/zend_vm_def.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8280,21 +8280,7 @@ ZEND_VM_HANDLER(210, ZEND_DECLARE_ATTRIBUTED_CONST, CONST, CONST)
82808280
zval *attribs = GET_OP_DATA_ZVAL_PTR(BP_VAR_R);
82818281
zend_constant *registered = zend_get_constant_ptr(c.name);
82828282
ZEND_ASSERT(registered != NULL);
8283-
zend_ast *ast = Z_ASTVAL_P(attribs);
8284-
zend_compile_attributes(&registered->attributes, ast, 0, ZEND_ATTRIBUTE_TARGET_CONST, 0);
8285-
zend_attribute *deprecated_attribute = zend_get_attribute_str(
8286-
registered->attributes,
8287-
"deprecated",
8288-
sizeof("deprecated")-1
8289-
);
8290-
8291-
if (deprecated_attribute) {
8292-
ZEND_CONSTANT_SET_FLAGS(
8293-
registered,
8294-
ZEND_CONSTANT_FLAGS(registered) | CONST_DEPRECATED,
8295-
ZEND_CONSTANT_MODULE_NUMBER(registered)
8296-
);
8297-
}
8283+
zend_constant_add_attributes(registered, attribs);
82988284

82998285
FREE_OP1();
83008286
FREE_OP2();

Zend/zend_vm_execute.h

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)