Skip to content

Commit 6ce5c27

Browse files
committed
Enable external linkage. Fixed comments.
1 parent 55e6e75 commit 6ce5c27

File tree

4 files changed

+56
-37
lines changed

4 files changed

+56
-37
lines changed

Zend/zend_attributes.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#include "zend_API.h"
33
#include "zend_attributes.h"
44

5+
ZEND_API zend_class_entry *zend_ce_php_attribute;
6+
ZEND_API zend_class_entry *zend_ce_php_compiler_attribute;
7+
8+
static HashTable internal_validators;
9+
510
void zend_attribute_validate_phpattribute(zend_attribute *attr, int target)
611
{
712
if (target != ZEND_ATTRIBUTE_TARGET_CLASS) {
@@ -14,9 +19,9 @@ void zend_attribute_validate_phpcompilerattribute(zend_attribute *attr, int targ
1419
zend_error(E_COMPILE_ERROR, "The PhpCompilerAttribute can only be used by internal classes, use PhpAttribute instead");
1520
}
1621

17-
void zend_register_attribute_ce(void)
22+
ZEND_API void zend_register_attribute_ce(void)
1823
{
19-
zend_hash_init(&zend_attributes_internal_validators, 8, NULL, NULL, 1);
24+
zend_hash_init(&internal_validators, 8, NULL, NULL, 1);
2025

2126
zend_class_entry ce;
2227

@@ -33,11 +38,15 @@ void zend_register_attribute_ce(void)
3338
zend_compiler_attribute_register(zend_ce_php_compiler_attribute, zend_attribute_validate_phpcompilerattribute);
3439
}
3540

36-
void zend_compiler_attribute_register(zend_class_entry *ce, zend_attributes_internal_validator validator)
41+
ZEND_API zend_attributes_internal_validator zend_attribute_get_validator(zend_string *lcname)
3742
{
38-
zend_string *attribute_name = zend_string_tolower_ex(ce->name, 1);
43+
return zend_hash_find_ptr(&internal_validators, lcname);
44+
}
3945

40-
zend_hash_update_ptr(&zend_attributes_internal_validators, attribute_name, validator);
46+
ZEND_API void zend_compiler_attribute_register(zend_class_entry *ce, zend_attributes_internal_validator validator)
47+
{
48+
zend_string *lcname = zend_string_tolower_ex(ce->name, 1);
4149

42-
zend_string_release(attribute_name);
50+
zend_hash_update_ptr(&internal_validators, lcname, validator);
51+
zend_string_release(lcname);
4352
}

Zend/zend_attributes.h

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
#define ZEND_ATTRIBUTE_TARGET_PARAMETER 32
1010
#define ZEND_ATTRIBUTE_TARGET_ALL 63
1111

12-
zend_class_entry *zend_ce_php_attribute;
13-
zend_class_entry *zend_ce_php_compiler_attribute;
14-
1512
#define ZEND_ATTRIBUTE_SIZE(argc) (sizeof(zend_attribute) + sizeof(zval) * (argc) - sizeof(zval))
1613

14+
BEGIN_EXTERN_C()
15+
16+
extern ZEND_API zend_class_entry *zend_ce_php_attribute;
17+
extern ZEND_API zend_class_entry *zend_ce_php_compiler_attribute;
18+
1719
typedef struct _zend_attribute {
1820
zend_string *name;
1921
zend_string *lcname;
@@ -22,7 +24,9 @@ typedef struct _zend_attribute {
2224
zval argv[1];
2325
} zend_attribute;
2426

25-
static zend_always_inline void zend_attribute_release(zend_attribute *attr)
27+
typedef void (*zend_attributes_internal_validator)(zend_attribute *attr, int target);
28+
29+
static zend_always_inline void zend_attribute_free(zend_attribute *attr)
2630
{
2731
uint32_t i;
2832

@@ -36,37 +40,42 @@ static zend_always_inline void zend_attribute_release(zend_attribute *attr)
3640
efree(attr);
3741
}
3842

39-
static zend_always_inline zend_bool zend_has_attribute(HashTable *attributes, zend_string *name, uint32_t offset)
43+
static zend_always_inline zend_attribute *zend_get_attribute(HashTable *attributes, zend_string *name, uint32_t offset)
4044
{
4145
if (attributes) {
4246
zend_attribute *attr;
4347

4448
ZEND_HASH_FOREACH_PTR(attributes, attr) {
4549
if (attr->offset == offset && zend_string_equals(attr->lcname, name)) {
46-
return 1;
50+
return attr;
4751
}
4852
} ZEND_HASH_FOREACH_END();
4953
}
5054

51-
return 0;
55+
return NULL;
5256
}
5357

54-
static zend_always_inline zend_bool zend_has_attribute_str(HashTable *attributes, const char *str, size_t len, uint32_t offset)
58+
static zend_always_inline zend_attribute *zend_get_attribute_str(HashTable *attributes, const char *str, size_t len, uint32_t offset)
5559
{
56-
zend_bool result = 0;
57-
5860
if (attributes) {
59-
zend_string *name = zend_string_init(str, len, 0);
60-
result = zend_has_attribute(attributes, name, offset);
61-
zend_string_release(name);
61+
zend_attribute *attr;
62+
63+
ZEND_HASH_FOREACH_PTR(attributes, attr) {
64+
if (attr->offset == offset && ZSTR_LEN(attr->lcname) == len) {
65+
if (0 == memcmp(ZSTR_VAL(attr->lcname), str, len)) {
66+
return attr;
67+
}
68+
}
69+
} ZEND_HASH_FOREACH_END();
6270
}
6371

64-
return result;
72+
return NULL;
6573
}
6674

67-
typedef void (*zend_attributes_internal_validator)(zend_attribute *attr, int target);
68-
HashTable zend_attributes_internal_validators;
75+
ZEND_API void zend_compiler_attribute_register(zend_class_entry *ce, zend_attributes_internal_validator validator);
76+
ZEND_API zend_attributes_internal_validator zend_attribute_get_validator(zend_string *lcname);
77+
ZEND_API void zend_register_attribute_ce(void);
78+
79+
END_EXTERN_C()
6980

70-
void zend_compiler_attribute_register(zend_class_entry *ce, zend_attributes_internal_validator validator);
71-
void zend_register_attribute_ce(void);
7281
#endif

Zend/zend_compile.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5743,10 +5743,11 @@ static zend_attribute *zend_compile_attribute(zend_ast *ast, uint32_t offset) /*
57435743
}
57445744
/* }}} */
57455745

5746-
static void attribute_ptr_dtor(zval *v)
5746+
static void attribute_ptr_dtor(zval *v) /* {{{ */
57475747
{
5748-
zend_attribute_release((zend_attribute *) Z_PTR_P(v));
5748+
zend_attribute_free((zend_attribute *) Z_PTR_P(v));
57495749
}
5750+
/* }}} */
57505751

57515752
static zend_always_inline HashTable *create_attribute_array(uint32_t size) /* {{{ */
57525753
{
@@ -5772,7 +5773,7 @@ static void zend_compile_attributes(HashTable *attributes, zend_ast *ast, uint32
57725773
zend_attribute *attr = zend_compile_attribute(list->child[i], offset);
57735774

57745775
// Validate internal attribute
5775-
zend_attributes_internal_validator validator = zend_hash_find_ptr(&zend_attributes_internal_validators, attr->lcname);
5776+
zend_attributes_internal_validator validator = zend_attribute_get_validator(attr->lcname);
57765777

57775778
if (validator != NULL) {
57785779
validator(attr, target);

ext/reflection/php_reflection.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getDocComment)
17651765
}
17661766
/* }}} */
17671767

1768-
/* {{{ proto public array ReflectionFunction::getAttributes()
1768+
/* {{{ proto public array ReflectionFunction::getAttributes([ string name, int flags ])
17691769
Returns the attributes of this function */
17701770
ZEND_METHOD(ReflectionFunctionAbstract, getAttributes)
17711771
{
@@ -2711,7 +2711,7 @@ ZEND_METHOD(ReflectionParameter, canBePassedByValue)
27112711
}
27122712
/* }}} */
27132713

2714-
/* {{{ proto public bool ReflectionParameter::getAttributes(?string $name = null)
2714+
/* {{{ proto public array ReflectionParameter::getAttributes([ string name, int flags ])
27152715
Get parameter attributes. */
27162716
ZEND_METHOD(ReflectionParameter, getAttributes)
27172717
{
@@ -2731,7 +2731,7 @@ ZEND_METHOD(ReflectionParameter, getAttributes)
27312731
reflect_attributes(INTERNAL_FUNCTION_PARAM_PASSTHRU, attributes, param->offset + 1, scope);
27322732
}
27332733

2734-
/* {{{ proto public bool ReflectionParameter::getPosition()
2734+
/* {{{ proto public int ReflectionParameter::getPosition()
27352735
Returns whether this parameter is an optional parameter */
27362736
ZEND_METHOD(ReflectionParameter, getPosition)
27372737
{
@@ -3786,7 +3786,7 @@ ZEND_METHOD(ReflectionClassConstant, getDocComment)
37863786
}
37873787
/* }}} */
37883788

3789-
/* {{{ proto public array ReflectionClassConstant::getAttributes()
3789+
/* {{{ proto public array ReflectionClassConstant::getAttributes([ string name, int flags ])
37903790
Returns the attributes of this constant */
37913791
ZEND_METHOD(ReflectionClassConstant, getAttributes)
37923792
{
@@ -4174,7 +4174,7 @@ ZEND_METHOD(ReflectionClass, getDocComment)
41744174
}
41754175
/* }}} */
41764176

4177-
/* {{{ proto public array ReflectionClass::getAttributes()
4177+
/* {{{ proto public array ReflectionClass::getAttributes([ string name, int flags ])
41784178
Returns the attributes for this class */
41794179
ZEND_METHOD(ReflectionClass, getAttributes)
41804180
{
@@ -5695,7 +5695,7 @@ ZEND_METHOD(ReflectionProperty, getDocComment)
56955695
}
56965696
/* }}} */
56975697

5698-
/* {{{ proto public array ReflectionProperty::getAttributes()
5698+
/* {{{ proto public array ReflectionProperty::getAttributes([ string name, int flags ])
56995699
Returns the attributes of this property */
57005700
ZEND_METHOD(ReflectionProperty, getAttributes)
57015701
{
@@ -6467,7 +6467,7 @@ static zend_always_inline int import_attribute_value(zval *ret, zval *val, zend_
64676467
}
64686468
/* }}} */
64696469

6470-
/* {{{ proto public string ReflectionAttribute::getArguments()
6470+
/* {{{ proto public array ReflectionAttribute::getArguments()
64716471
* Returns the arguments passed to the attribute */
64726472
ZEND_METHOD(ReflectionAttribute, getArguments)
64736473
{
@@ -6562,7 +6562,7 @@ static void attribute_ctor_cleanup(zval *obj, zval *args, uint32_t argc) /* {{{
65626562
}
65636563
/* }}} */
65646564

6565-
/* {{{ proto public string ReflectionAttribute::newInstance()
6565+
/* {{{ proto public object ReflectionAttribute::newInstance()
65666566
* Returns the attribute as an object */
65676567
ZEND_METHOD(ReflectionAttribute, newInstance)
65686568
{
@@ -6587,10 +6587,10 @@ ZEND_METHOD(ReflectionAttribute, newInstance)
65876587
RETURN_THROWS();
65886588
}
65896589

6590-
if (ce->type == ZEND_USER_CLASS && !zend_has_attribute_str(ce->info.user.attributes, ZEND_STRL("phpattribute"), 0)) {
6590+
if (ce->type == ZEND_USER_CLASS && !zend_get_attribute_str(ce->info.user.attributes, ZEND_STRL("phpattribute"), 0)) {
65916591
zend_throw_error(NULL, "Attempting to use class '%s' as attribute that does not have <<PhpAttribute>>.", ZSTR_VAL(attr->data->name));
65926592
RETURN_THROWS();
6593-
} else if (ce->type == ZEND_INTERNAL_CLASS && zend_hash_exists(&zend_attributes_internal_validators, attr->data->lcname) == 0) {
6593+
} else if (ce->type == ZEND_INTERNAL_CLASS && !zend_attribute_get_validator(attr->data->lcname)) {
65946594
zend_throw_error(NULL, "Attempting to use internal class '%s' as attribute that does not have <<PhpCompilerAttribute>>.", ZSTR_VAL(attr->data->name));
65956595
RETURN_THROWS();
65966596
}

0 commit comments

Comments
 (0)