Skip to content

Commit 2199ff7

Browse files
committed
Get rid of accessor_info
Instead add a `zend_function **accs` to property_info
1 parent 2019467 commit 2199ff7

File tree

6 files changed

+56
-67
lines changed

6 files changed

+56
-67
lines changed

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3401,7 +3401,7 @@ ZEND_API int zend_declare_property_ex(zend_class_entry *ce, const char *name, in
34013401
property_info.doc_comment_len = doc_comment_len;
34023402

34033403
property_info.ce = ce;
3404-
property_info.ai = NULL;
3404+
property_info.accs = NULL;
34053405

34063406
zend_hash_quick_update(&ce->properties_info, name, name_length+1, h, &property_info, sizeof(zend_property_info), NULL);
34073407

Zend/zend_compile.c

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static const char *zend_get_property_name(const zend_property_info *property_inf
129129

130130
static void zend_duplicate_property_info(zend_property_info *property_info) /* {{{ */
131131
{
132-
zend_accessor_info *parent_ai = property_info->ai;
132+
zend_function **orig_accs = property_info->accs;
133133

134134
if (!IS_INTERNED(property_info->name)) {
135135
property_info->name = estrndup(property_info->name, property_info->name_length);
@@ -138,14 +138,13 @@ static void zend_duplicate_property_info(zend_property_info *property_info) /* {
138138
property_info->doc_comment = estrndup(property_info->doc_comment, property_info->doc_comment_len);
139139
}
140140

141-
if (parent_ai) {
141+
if (orig_accs) {
142142
int i;
143143

144-
property_info->ai = ecalloc(1, sizeof(zend_accessor_info));
145-
144+
property_info->accs = ecalloc(ZEND_ACCESSOR_COUNT, sizeof(zend_function *));
146145
for (i = 0; i < ZEND_ACCESSOR_COUNT; ++i) {
147-
if (parent_ai->fn[i]) {
148-
property_info->ai->fn[i] = duplicate_accessor_function(parent_ai->fn[i]);
146+
if (orig_accs[i]) {
147+
property_info->accs[i] = duplicate_accessor_function(orig_accs[i]);
149148
}
150149
}
151150
}
@@ -167,19 +166,18 @@ static void zend_destroy_property_info(zend_property_info *property_info) /* {{{
167166
efree((char*)property_info->doc_comment);
168167
}
169168

170-
if (property_info->ai) {
171-
zend_accessor_info *ai = property_info->ai;
169+
if (property_info->accs) {
170+
zend_function **accs = property_info->accs;
172171
int i;
173-
174-
TSRMLS_FETCH(); /* Need to check how to avoid this tsrm fetch */
172+
TSRMLS_FETCH();
175173

176174
for (i = 0; i < ZEND_ACCESSOR_COUNT; ++i) {
177-
if (ai->fn[i]) {
178-
destroy_op_array((zend_op_array *) ai->fn[i] TSRMLS_CC);
175+
if (accs[i]) {
176+
destroy_op_array((zend_op_array *) accs[i] TSRMLS_CC);
179177
}
180178
}
181179

182-
efree(ai);
180+
efree(accs);
183181
}
184182
}
185183
/* }}} */
@@ -1591,14 +1589,9 @@ void zend_declare_accessor(znode *var_name TSRMLS_DC) { /* {{{ */
15911589
CG(active_class_entry)->ce_flags = orig_ce_flags;
15921590

15931591
if (zend_hash_find(&CG(active_class_entry)->properties_info, property_name, property_name_len + 1, (void **) &property_info)==SUCCESS) {
1594-
if (property_info->ai != NULL) {
1595-
zend_error_noreturn(E_COMPILE_ERROR, "property_info for %s::$%s already has accessor_info created, should not happen in zend_declare_accessor()", CG(active_class_entry)->name, property_name);
1596-
}
1597-
1598-
property_info->ai = ecalloc(1, sizeof(zend_accessor_info));
1599-
16001592
/* Add back final/abstract flags that were skipped previously */
16011593
property_info->flags |= CG(access_type);
1594+
property_info->accs = ecalloc(ZEND_ACCESSOR_COUNT, sizeof(zend_function *));
16021595

16031596
CG(current_property_info) = property_info;
16041597
efree(property_name);
@@ -1643,7 +1636,7 @@ void zend_do_begin_accessor_declaration(znode *function_token, znode *modifiers,
16431636

16441637
/* Declare Function */
16451638
zend_do_begin_function_declaration(function_token, function_token, 1, return_reference, modifiers TSRMLS_CC);
1646-
property_info->ai->fn[ZEND_ACCESSOR_GET] = (zend_function *) CG(active_op_array);
1639+
property_info->accs[ZEND_ACCESSOR_GET] = (zend_function *) CG(active_op_array);
16471640
} else if (Z_TYPE(function_token->u.constant) == IS_STRING && strcasecmp("set", Z_STRVAL(function_token->u.constant)) == 0) {
16481641
znode unused_node, unused_node2, value_node;
16491642

@@ -1655,7 +1648,7 @@ void zend_do_begin_accessor_declaration(znode *function_token, znode *modifiers,
16551648
}
16561649
/* Declare Function */
16571650
zend_do_begin_function_declaration(function_token, function_token, 1, ZEND_RETURN_VAL, modifiers TSRMLS_CC);
1658-
property_info->ai->fn[ZEND_ACCESSOR_SET] = (zend_function *) CG(active_op_array);
1651+
property_info->accs[ZEND_ACCESSOR_SET] = (zend_function *) CG(active_op_array);
16591652

16601653
if (!has_params) {
16611654
/* Add $value parameter to __setHours() */
@@ -1675,7 +1668,7 @@ void zend_do_begin_accessor_declaration(znode *function_token, znode *modifiers,
16751668

16761669
/* Declare Function */
16771670
zend_do_begin_function_declaration(function_token, function_token, 1, ZEND_RETURN_VAL, modifiers TSRMLS_CC);
1678-
property_info->ai->fn[ZEND_ACCESSOR_ISSET] = (zend_function *) CG(active_op_array);
1671+
property_info->accs[ZEND_ACCESSOR_ISSET] = (zend_function *) CG(active_op_array);
16791672
} else if (Z_TYPE(function_token->u.constant) == IS_LONG && Z_LVAL(function_token->u.constant) == T_UNSET) {
16801673
ZVAL_STRING(&function_token->u.constant, create_accessor_function_name(property_name, "unset"), 0);
16811674

@@ -1685,7 +1678,7 @@ void zend_do_begin_accessor_declaration(znode *function_token, znode *modifiers,
16851678

16861679
/* Declare Function */
16871680
zend_do_begin_function_declaration(function_token, function_token, 1, ZEND_RETURN_VAL, modifiers TSRMLS_CC);
1688-
property_info->ai->fn[ZEND_ACCESSOR_UNSET] = (zend_function *) CG(active_op_array);
1681+
property_info->accs[ZEND_ACCESSOR_UNSET] = (zend_function *) CG(active_op_array);
16891682
} else {
16901683
zend_error(E_COMPILE_ERROR, "Unknown accessor '%s', expecting get or set for variable $%s", Z_STRVAL(function_token->u.constant), property_name);
16911684
}
@@ -1708,7 +1701,7 @@ void zend_do_end_accessor_declaration(znode *function_token, const znode *body T
17081701
* ->fn slot it is in */
17091702
zend_uchar acc;
17101703
for (acc = 0; acc < ZEND_ACCESSOR_COUNT; ++acc) {
1711-
if (property_info->ai->fn[acc] == (zend_function *) CG(active_op_array)) {
1704+
if (property_info->accs[acc] == (zend_function *) CG(active_op_array)) {
17121705
break;
17131706
}
17141707
}
@@ -1774,7 +1767,7 @@ void zend_do_end_accessor_declaration(znode *function_token, const znode *body T
17741767
void zend_finalize_accessor(TSRMLS_D) { /* {{{ */
17751768
zend_property_info *property_info = CG(current_property_info);
17761769

1777-
if (!property_info->ai->fn[ZEND_ACCESSOR_ISSET] && property_info->ai->fn[ZEND_ACCESSOR_GET]) {
1770+
if (!property_info->accs[ZEND_ACCESSOR_ISSET] && property_info->accs[ZEND_ACCESSOR_GET]) {
17781771
znode zn_fntoken, zn_modifiers, zn_body;
17791772
INIT_ZNODE(zn_fntoken);
17801773
ZVAL_LONG(&zn_fntoken.u.constant, T_ISSET);
@@ -1788,7 +1781,7 @@ void zend_finalize_accessor(TSRMLS_D) { /* {{{ */
17881781
zend_do_begin_accessor_declaration(&zn_fntoken, &zn_modifiers, 0, 0 TSRMLS_CC);
17891782
zend_do_end_accessor_declaration(&zn_fntoken, &zn_body TSRMLS_CC);
17901783
}
1791-
if (!property_info->ai->fn[ZEND_ACCESSOR_UNSET] && property_info->ai->fn[ZEND_ACCESSOR_SET]) {
1784+
if (!property_info->accs[ZEND_ACCESSOR_UNSET] && property_info->accs[ZEND_ACCESSOR_SET]) {
17921785
znode zn_fntoken, zn_modifiers, zn_body;
17931786
INIT_ZNODE(zn_fntoken);
17941787
ZVAL_LONG(&zn_fntoken.u.constant, T_UNSET);
@@ -3789,23 +3782,23 @@ static zend_bool do_inherit_property_access_check(HashTable *target_ht, zend_pro
37893782
ce->default_properties_table[child_info->offset] = NULL;
37903783
child_info->offset = parent_info->offset;
37913784

3792-
if (parent_info->ai && child_info->ai) {
3785+
if (parent_info->accs && child_info->accs) {
37933786
int i;
37943787
TSRMLS_FETCH();
37953788

37963789
for (i = 0; i < ZEND_ACCESSOR_COUNT; ++i) {
3797-
do_inherit_accessor(&child_info->ai->fn[i], parent_info->ai->fn[i], ce TSRMLS_CC);
3790+
do_inherit_accessor(&child_info->accs[i], parent_info->accs[i], ce TSRMLS_CC);
37983791
}
37993792
}
38003793
}
38013794
return 0; /* Don't copy from parent */
38023795
} else {
38033796
/* Make sure that when we copy abstract accessors the class is marked
38043797
* abstract too */
3805-
if (parent_info->ai) {
3798+
if (parent_info->accs) {
38063799
int i;
38073800
for (i = 0; i < ZEND_ACCESSOR_COUNT; ++i) {
3808-
zend_function *fn = parent_info->ai->fn[i];
3801+
zend_function *fn = parent_info->accs[i];
38093802
if (fn && (fn->common.fn_flags & ZEND_ACC_ABSTRACT)) {
38103803
ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
38113804
}
@@ -4640,14 +4633,14 @@ static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {
46404633
zend_declare_property_ex(ce, prop_name, prop_name_length,
46414634
prop_value, flags,
46424635
doc_comment, property_info->doc_comment_len TSRMLS_CC);
4643-
if (property_info->ai) {
4636+
if (property_info->accs) {
46444637
zend_property_info *created_property_info;
46454638
if (zend_hash_find(&ce->properties_info, prop_name, prop_name_length+1, (void**) &created_property_info) == SUCCESS) {
46464639
int j;
4647-
created_property_info->ai = ecalloc(1, sizeof(zend_accessor_info));
4640+
created_property_info->accs = ecalloc(ZEND_ACCESSOR_COUNT, sizeof(zend_function *));
46484641

46494642
for (j = 0; j < ZEND_ACCESSOR_COUNT; ++j) {
4650-
zend_do_trait_inherit_accessor(&created_property_info->ai->fn[j], property_info->ai->fn[j], ce, ce->traits[i], &overridden TSRMLS_CC);
4643+
zend_do_trait_inherit_accessor(&created_property_info->accs[j], property_info->accs[j], ce, ce->traits[i], &overridden TSRMLS_CC);
46514644
}
46524645
}
46534646
}

Zend/zend_compile.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ typedef struct _zend_try_catch_element {
236236
/* Declares that the function is an accessor zend_function.fn_flags */
237237
#define ZEND_ACC_ACCESSOR 0x10000000
238238

239-
/* Offsets into zend_accessor_info->fn */
239+
/* Offsets into zend_property_info->accs */
240240
#define ZEND_ACCESSOR_GET 0
241241
#define ZEND_ACCESSOR_SET 1
242242
#define ZEND_ACCESSOR_ISSET 2
@@ -252,7 +252,7 @@ typedef struct _zend_property_info {
252252
const char *doc_comment;
253253
int doc_comment_len;
254254
zend_class_entry *ce;
255-
struct _zend_accessor_info *ai;
255+
union _zend_function **accs;
256256
} zend_property_info;
257257

258258

@@ -379,10 +379,6 @@ typedef union _zend_function {
379379
zend_internal_function internal_function;
380380
} zend_function;
381381

382-
typedef struct _zend_accessor_info {
383-
zend_function *fn[4];
384-
} zend_accessor_info;
385-
386382
typedef struct _zend_function_state {
387383
zend_function *function;
388384
void **arguments;

Zend/zend_execute_API.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,11 +1642,11 @@ static int zend_verify_abstract_class_function(zend_function *fn, zend_abstract_
16421642

16431643
static int zend_verify_abstract_class_property(zend_property_info *prop, zend_abstract_info *ai TSRMLS_DC) /* {{{ */
16441644
{
1645-
if (prop->ai) {
1645+
if (prop->accs) {
16461646
int i;
16471647
for (i = 0; i < ZEND_ACCESSOR_COUNT; ++i) {
1648-
if (prop->ai->fn[i]) {
1649-
zend_verify_abstract_class_function(prop->ai->fn[i], ai TSRMLS_CC);
1648+
if (prop->accs[i]) {
1649+
zend_verify_abstract_class_function(prop->accs[i], ai TSRMLS_CC);
16501650
}
16511651
}
16521652
}

Zend/zend_object_handlers.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,13 @@ static zend_function *zend_get_accessor_from_ce(zend_class_entry *ce, const char
340340
return NULL;
341341
}
342342

343-
return prop->ai ? prop->ai->fn[acc] : NULL;
343+
return prop->accs ? prop->accs[acc] : NULL;
344344
}
345345
/* }}} */
346346

347347
static zend_function *zend_get_accessor(zend_property_info *prop, zend_class_entry *ce, zend_uchar acc TSRMLS_DC) /* {{{ */
348348
{
349-
zend_function *fbc = prop->ai->fn[acc];
349+
zend_function *fbc = prop->accs[acc];
350350

351351
if (fbc->common.fn_flags & ZEND_ACC_PRIVATE) {
352352
if (fbc->common.scope == ce && EG(scope) == ce) {
@@ -444,7 +444,7 @@ zend_always_inline struct _zend_property_info *zend_get_property_info_quick(zend
444444
}
445445
return scope_property_info;
446446
} else if (property_info) {
447-
if (!property_info->ai && UNEXPECTED(denied_access != 0)) {
447+
if (!property_info->accs && UNEXPECTED(denied_access != 0)) {
448448
/* Information was available, but we were denied access. Error out. */
449449
if (!silent) {
450450
zend_error_noreturn(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), ce->name, Z_STRVAL_P(member));
@@ -462,7 +462,7 @@ zend_always_inline struct _zend_property_info *zend_get_property_info_quick(zend
462462
EG(std_property_info).name_length = Z_STRLEN_P(member);
463463
EG(std_property_info).h = h;
464464
EG(std_property_info).ce = ce;
465-
EG(std_property_info).ai = NULL;
465+
EG(std_property_info).accs = NULL;
466466
EG(std_property_info).offset = -1;
467467
property_info = &EG(std_property_info);
468468
}
@@ -577,10 +577,10 @@ zval *zend_std_read_property(zval *object, zval *member, int type, const zend_li
577577
property_info = zend_get_property_info_quick(zobj->ce, member, (zobj->ce->__get != NULL), key TSRMLS_CC);
578578

579579
/* Getter shadows property unless in guard */
580-
if(property_info && property_info->ai) {
580+
if(property_info && property_info->accs) {
581581
zend_guard *guard = NULL;
582582

583-
if(!property_info->ai->fn[ZEND_ACCESSOR_GET]) {
583+
if(!property_info->accs[ZEND_ACCESSOR_GET]) {
584584
if(!silent) {
585585
zend_error(E_WARNING, "Cannot get property %s::$%s, no getter defined", zobj->ce->name, Z_STRVAL_P(member));
586586
}
@@ -662,10 +662,10 @@ ZEND_API void zend_std_write_property(zval *object, zval *member, zval *value, c
662662
property_info = zend_get_property_info_quick(zobj->ce, member, (zobj->ce->__set != NULL), key TSRMLS_CC);
663663

664664
/* Setter shadows property unless in guard */
665-
if(property_info && property_info->ai) {
665+
if(property_info && property_info->accs) {
666666
zend_guard *guard = NULL;
667667

668-
if(!property_info->ai->fn[ZEND_ACCESSOR_SET]) {
668+
if(!property_info->accs[ZEND_ACCESSOR_SET]) {
669669
zend_error(E_WARNING, "Cannot set property %s::$%s, no setter defined", zobj->ce->name, Z_STRVAL_P(member));
670670
handled = 1;
671671
} else if(zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS) {
@@ -867,10 +867,10 @@ static zval **zend_std_get_property_ptr_ptr(zval *object, zval *member, const ze
867867
property_info = zend_get_property_info_quick(zobj->ce, member, (zobj->ce->__get != NULL), key TSRMLS_CC);
868868

869869
/* Getter shadows property unless in guard */
870-
if(property_info && property_info->ai) {
870+
if(property_info && property_info->accs) {
871871
zend_guard *guard = NULL;
872872

873-
if(!property_info->ai->fn[ZEND_ACCESSOR_GET]) {
873+
if(!property_info->accs[ZEND_ACCESSOR_GET]) {
874874
zend_error(E_WARNING, "Cannot get property %s::$%s, no getter defined", zobj->ce->name, Z_STRVAL_P(member));
875875
return &EG(uninitialized_zval_ptr);
876876
}
@@ -946,10 +946,10 @@ static void zend_std_unset_property(zval *object, zval *member, const zend_liter
946946
property_info = zend_get_property_info_quick(zobj->ce, member, (zobj->ce->__unset != NULL), key TSRMLS_CC);
947947

948948
/* Unsetter shadows property unless in guard */
949-
if(property_info && property_info->ai) {
949+
if(property_info && property_info->accs) {
950950
zend_guard *guard = NULL;
951951

952-
if(!property_info->ai->fn[ZEND_ACCESSOR_UNSET]) {
952+
if(!property_info->accs[ZEND_ACCESSOR_UNSET]) {
953953
/* Have property but no unsetter, just return and do not throw error */
954954
zend_error(E_WARNING, "Cannot unset guarded property %s::$%s, no unset defined.", zobj->ce->name, Z_STRVAL_P(member));
955955
handled = 1;
@@ -1560,10 +1560,10 @@ static int zend_std_has_property(zval *object, zval *member, int has_set_exists,
15601560
property_info = zend_get_property_info_quick(zobj->ce, member, 1, key TSRMLS_CC);
15611561

15621562
/* Issetter shadows property unless in guard */
1563-
if(property_info && property_info->ai) {
1563+
if(property_info && property_info->accs) {
15641564
zend_guard *guard = NULL;
15651565

1566-
if(!property_info->ai->fn[ZEND_ACCESSOR_ISSET]) {
1566+
if(!property_info->accs[ZEND_ACCESSOR_ISSET]) {
15671567
/* Have property but no issetter, just return and do not throw error */
15681568
result = has_set_exists == 2;
15691569
} else if(zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS) {

0 commit comments

Comments
 (0)