Skip to content

Commit 5342ffa

Browse files
committed
Use zend_std_build_properties() to access zend_object.properties
1 parent 7d99a9c commit 5342ffa

12 files changed

+29
-64
lines changed

Zend/zend_API.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "zend_inheritance.h"
3232
#include "zend_ini.h"
3333
#include "zend_enum.h"
34+
#include "zend_object_handlers.h"
3435
#include "zend_observer.h"
3536

3637
#include <stdarg.h>
@@ -1764,10 +1765,7 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
17641765
ZSTR_VAL(object->ce->name), property_info != ZEND_WRONG_PROPERTY_INFO ? zend_get_unmangled_property_name(key): "");
17651766
}
17661767

1767-
if (!object->properties) {
1768-
rebuild_object_properties(object);
1769-
}
1770-
prop = zend_hash_update(object->properties, key, prop);
1768+
prop = zend_hash_update(zend_std_get_properties(object), key, prop);
17711769
zval_add_ref(prop);
17721770
}
17731771
} else {
@@ -1779,10 +1777,7 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
17791777
ZSTR_VAL(object->ce->name), h);
17801778
}
17811779

1782-
if (!object->properties) {
1783-
rebuild_object_properties(object);
1784-
}
1785-
prop = zend_hash_index_update(object->properties, h, prop);
1780+
prop = zend_hash_index_update(zend_std_get_properties(object), h, prop);
17861781
zval_add_ref(prop);
17871782
}
17881783
} ZEND_HASH_FOREACH_END();

Zend/zend_object_handlers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
called, we cal __call handler.
6363
*/
6464

65-
ZEND_API void rebuild_object_properties(zend_object *zobj) /* {{{ */
65+
static void rebuild_object_properties(zend_object *zobj) /* {{{ */
6666
{
6767
if (!zobj->properties) {
6868
zend_property_info *prop_info;

Zend/zend_object_handlers.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
267267
ZEND_API zend_string *zend_std_get_class_name(const zend_object *zobj);
268268
ZEND_API int zend_std_compare_objects(zval *o1, zval *o2);
269269
ZEND_API zend_result zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only);
270-
ZEND_API void rebuild_object_properties(zend_object *zobj);
271270

272271
ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj);
273272

Zend/zend_vm_def.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,9 +2495,6 @@ ZEND_VM_C_LABEL(fast_assign_obj):
24952495
}
24962496

24972497
if (!zobj->ce->__set && (zobj->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) {
2498-
if (EXPECTED(zobj->properties == NULL)) {
2499-
rebuild_object_properties(zobj);
2500-
}
25012498
if (OP_DATA_TYPE == IS_CONST) {
25022499
if (UNEXPECTED(Z_OPT_REFCOUNTED_P(value))) {
25032500
Z_ADDREF_P(value);
@@ -2521,8 +2518,8 @@ ZEND_VM_C_LABEL(fast_assign_obj):
25212518
} else if (OP_DATA_TYPE == IS_CV) {
25222519
Z_TRY_ADDREF_P(value);
25232520
}
2524-
}
2525-
zend_hash_add_new(zobj->properties, name, value);
2521+
}
2522+
zend_hash_add_new(zend_std_get_properties(zobj), name, value);
25262523
if (UNEXPECTED(RETURN_VALUE_USED(opline))) {
25272524
ZVAL_COPY(EX_VAR(opline->result.var), value);
25282525
}

ext/date/php_date.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,7 @@ static void initialize_date_period_properties(php_period_obj *period_obj)
15151515
{
15161516
zval zv;
15171517

1518-
if (UNEXPECTED(!period_obj->std.properties)) {
1519-
rebuild_object_properties(&period_obj->std);
1520-
}
1518+
zend_std_get_properties(&period_obj->std);
15211519

15221520
create_date_period_datetime(period_obj->start, period_obj->start_ce, &zv);
15231521
write_date_period_property(&period_obj->std, "start", sizeof("start") - 1, &zv);
@@ -1652,9 +1650,7 @@ static void date_period_it_move_forward(zend_object_iterator *iter)
16521650

16531651
date_period_advance(it_time, object->interval);
16541652

1655-
if (UNEXPECTED(!object->std.properties)) {
1656-
rebuild_object_properties(&object->std);
1657-
}
1653+
zend_std_get_properties(&object->std);
16581654

16591655
create_date_period_datetime(object->current, object->start_ce, &current_zv);
16601656
zend_string *property_name = ZSTR_INIT_LITERAL("current", 0);

ext/pdo/pdo_dbh.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,8 @@ zend_object *pdo_dbh_new(zend_class_entry *ce)
15051505
dbh = zend_object_alloc(sizeof(pdo_dbh_object_t), ce);
15061506
zend_object_std_init(&dbh->std, ce);
15071507
object_properties_init(&dbh->std, ce);
1508-
rebuild_object_properties(&dbh->std);
1508+
/* rebuild properties */
1509+
zend_std_get_properties(&dbh->std);
15091510
dbh->inner = ecalloc(1, sizeof(pdo_dbh_t));
15101511
dbh->inner->def_stmt_ce = pdo_dbstmt_ce;
15111512

ext/pdo/pdo_stmt.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,10 +2426,7 @@ static HashTable *row_get_properties_for(zend_object *object, zend_prop_purpose
24262426
return zend_std_get_properties_for(object, purpose);
24272427
}
24282428

2429-
if (!stmt->std.properties) {
2430-
rebuild_object_properties(&stmt->std);
2431-
}
2432-
props = zend_array_dup(stmt->std.properties);
2429+
props = zend_array_dup(zend_std_get_properties(&stmt->std));
24332430
for (i = 0; i < stmt->column_count; i++) {
24342431
if (zend_string_equals_literal(stmt->columns[i].name, "queryString")) {
24352432
continue;

ext/random/engine_mt19937.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,7 @@ PHP_METHOD(Random_Engine_Mt19937, __debugInfo)
388388

389389
ZEND_PARSE_PARAMETERS_NONE();
390390

391-
if (!engine->std.properties) {
392-
rebuild_object_properties(&engine->std);
393-
}
394-
ZVAL_ARR(return_value, zend_array_dup(engine->std.properties));
391+
ZVAL_ARR(return_value, zend_array_dup(zend_std_get_properties(&engine->std)));
395392

396393
if (engine->engine.algo->serialize) {
397394
array_init(&t);

ext/spl/spl_array.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ static inline spl_array_object *spl_array_from_obj(zend_object *obj) /* {{{ */ {
6464
static inline HashTable **spl_array_get_hash_table_ptr(spl_array_object* intern) { /* {{{ */
6565
//??? TODO: Delay duplication for arrays; only duplicate for write operations
6666
if (intern->ar_flags & SPL_ARRAY_IS_SELF) {
67-
if (!intern->std.properties) {
68-
rebuild_object_properties(&intern->std);
69-
}
67+
/* rebuild properties */
68+
zend_std_get_properties(&intern->std);
7069
return &intern->std.properties;
7170
} else if (intern->ar_flags & SPL_ARRAY_USE_OTHER) {
7271
spl_array_object *other = Z_SPLARRAY_P(&intern->array);
@@ -75,9 +74,9 @@ static inline HashTable **spl_array_get_hash_table_ptr(spl_array_object* intern)
7574
return &Z_ARRVAL(intern->array);
7675
} else {
7776
zend_object *obj = Z_OBJ(intern->array);
78-
if (!obj->properties) {
79-
rebuild_object_properties(obj);
80-
} else if (GC_REFCOUNT(obj->properties) > 1) {
77+
/* rebuild properties */
78+
zend_std_get_properties(obj);
79+
if (GC_REFCOUNT(obj->properties) > 1) {
8180
if (EXPECTED(!(GC_FLAGS(obj->properties) & IS_ARRAY_IMMUTABLE))) {
8281
GC_DELREF(obj->properties);
8382
}
@@ -770,18 +769,15 @@ static HashTable *spl_array_get_properties_for(zend_object *object, zend_prop_pu
770769
static inline HashTable* spl_array_get_debug_info(zend_object *obj) /* {{{ */
771770
{
772771
spl_array_object *intern = spl_array_from_obj(obj);
773-
774-
if (!intern->std.properties) {
775-
rebuild_object_properties(&intern->std);
776-
}
772+
HashTable *properties = zend_std_get_properties(&intern->std);
777773

778774
if (intern->ar_flags & SPL_ARRAY_IS_SELF) {
779-
return zend_array_dup(intern->std.properties);
775+
return zend_array_dup(properties);
780776
} else {
781777
HashTable *debug_info;
782778

783-
debug_info = zend_new_array(zend_hash_num_elements(intern->std.properties) + 1);
784-
zend_hash_copy(debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref);
779+
debug_info = zend_new_array(zend_hash_num_elements(properties) + 1);
780+
zend_hash_copy(debug_info, properties, (copy_ctor_func_t) zval_add_ref);
785781

786782
zval *storage = &intern->array;
787783
Z_TRY_ADDREF_P(storage);
@@ -1266,11 +1262,8 @@ PHP_METHOD(ArrayObject, serialize)
12661262

12671263
/* members */
12681264
smart_str_appendl(&buf, "m:", 2);
1269-
if (!intern->std.properties) {
1270-
rebuild_object_properties(&intern->std);
1271-
}
12721265

1273-
ZVAL_ARR(&members, intern->std.properties);
1266+
ZVAL_ARR(&members, zend_std_get_properties(&intern->std));
12741267

12751268
php_var_serialize(&buf, &members, &var_hash); /* finishes the string */
12761269

ext/spl/spl_directory.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,8 @@ static inline HashTable *spl_filesystem_object_get_debug_info(zend_object *objec
601601
HashTable *debug_info;
602602
zend_string *path_name;
603603

604-
if (!intern->std.properties) {
605-
rebuild_object_properties(&intern->std);
606-
}
607-
608604
// TODO Do zend_new_array() + zend_hash_copy() trick?
609-
debug_info = zend_array_dup(intern->std.properties);
605+
debug_info = zend_array_dup(zend_std_get_properties(&intern->std));
610606

611607
path_name = spl_filesystem_object_get_pathname(intern);
612608
if (path_name) {

ext/spl/spl_dllist.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,11 @@ static inline HashTable* spl_dllist_object_get_debug_info(zend_object *obj) /* {
427427
spl_ptr_llist_element *current = intern->llist->head;
428428
zval tmp, dllist_array;
429429
HashTable *debug_info;
430-
431-
if (!intern->std.properties) {
432-
rebuild_object_properties(&intern->std);
433-
}
430+
HashTable *properties = zend_std_get_properties(&intern->std);
434431

435432
/* +2 As we are adding 2 additional key-entries */
436-
debug_info = zend_new_array(zend_hash_num_elements(intern->std.properties) + 2);
437-
zend_hash_copy(debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref);
433+
debug_info = zend_new_array(zend_hash_num_elements(properties) + 2);
434+
zend_hash_copy(debug_info, properties, (copy_ctor_func_t) zval_add_ref);
438435

439436
ZVAL_LONG(&tmp, intern->flags);
440437
spl_set_private_debug_info_property(spl_ce_SplDoublyLinkedList, "flags", strlen("flags"), debug_info, &tmp);

ext/spl/spl_heap.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,11 @@ static inline HashTable* spl_heap_object_get_debug_info(const zend_class_entry *
507507
spl_heap_object *intern = spl_heap_from_obj(obj);
508508
zval tmp, heap_array;
509509
HashTable *debug_info;
510-
511-
if (!intern->std.properties) {
512-
rebuild_object_properties(&intern->std);
513-
}
510+
HashTable *properties = zend_std_get_properties(&intern->std);
514511

515512
/* +3 As we are adding 3 additional key-entries */
516-
debug_info = zend_new_array(zend_hash_num_elements(intern->std.properties) + 3);
517-
zend_hash_copy(debug_info, intern->std.properties, (copy_ctor_func_t) zval_add_ref);
513+
debug_info = zend_new_array(zend_hash_num_elements(properties) + 3);
514+
zend_hash_copy(debug_info, properties, (copy_ctor_func_t) zval_add_ref);
518515

519516
ZVAL_LONG(&tmp, intern->flags);
520517
spl_set_private_debug_info_property(ce, "flags", strlen("flags"), debug_info, &tmp);

0 commit comments

Comments
 (0)