Skip to content

Commit df97c3a

Browse files
committed
Use get_gc instead of hacks of get_properties
1 parent 881416c commit df97c3a

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

ext/date/php_date.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ static zend_object_value date_object_clone_interval(zval *this_ptr TSRMLS_DC);
563563
static zend_object_value date_object_clone_period(zval *this_ptr TSRMLS_DC);
564564

565565
static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC);
566+
static HashTable *date_object_get_gc(zval *object, zval ***table, int *n TSRMLS_DC);
566567
static HashTable *date_object_get_properties(zval *object TSRMLS_DC);
568+
static HashTable *date_object_get_gc_interval(zval *object, zval ***table, int *n TSRMLS_DC);
567569
static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC);
568570

569571
zval *date_interval_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC);
@@ -1887,6 +1889,7 @@ static void date_register_classes(TSRMLS_D)
18871889
date_object_handlers_date.clone_obj = date_object_clone_date;
18881890
date_object_handlers_date.compare_objects = date_object_compare_date;
18891891
date_object_handlers_date.get_properties = date_object_get_properties;
1892+
date_object_handlers_date.get_gc = date_object_get_gc;
18901893

18911894
#define REGISTER_DATE_CLASS_CONST_STRING(const_name, value) \
18921895
zend_declare_class_constant_stringl(date_ce_date, const_name, sizeof(const_name)-1, value, sizeof(value)-1 TSRMLS_CC);
@@ -1937,6 +1940,7 @@ static void date_register_classes(TSRMLS_D)
19371940
date_object_handlers_interval.write_property = date_interval_write_property;
19381941
date_object_handlers_interval.get_properties = date_object_get_properties_interval;
19391942
date_object_handlers_interval.get_property_ptr_ptr = NULL;
1943+
date_object_handlers_interval.get_gc = date_object_get_gc_interval;
19401944

19411945
INIT_CLASS_ENTRY(ce_period, "DatePeriod", date_funcs_period);
19421946
ce_period.create_object = date_object_new_period;
@@ -2023,6 +2027,13 @@ static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC)
20232027
return 1;
20242028
}
20252029

2030+
static HashTable *date_object_get_gc(zval *object, zval ***table, int *n TSRMLS_DC)
2031+
{
2032+
*table = NULL;
2033+
*n = 0;
2034+
return zend_std_get_properties(object TSRMLS_CC);
2035+
}
2036+
20262037
static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
20272038
{
20282039
HashTable *props;
@@ -2034,7 +2045,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
20342045

20352046
props = zend_std_get_properties(object TSRMLS_CC);
20362047

2037-
if (!dateobj->time || GC_G(gc_active)) {
2048+
if (!dateobj->time) {
20382049
return props;
20392050
}
20402051

@@ -2168,6 +2179,14 @@ static zend_object_value date_object_clone_interval(zval *this_ptr TSRMLS_DC)
21682179
return new_ov;
21692180
}
21702181

2182+
static HashTable *date_object_get_gc_interval(zval *object, zval ***table, int *n TSRMLS_DC)
2183+
{
2184+
2185+
*table = NULL;
2186+
*n = 0;
2187+
return zend_std_get_properties(object TSRMLS_CC);
2188+
}
2189+
21712190
static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
21722191
{
21732192
HashTable *props;
@@ -2179,7 +2198,7 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
21792198

21802199
props = zend_std_get_properties(object TSRMLS_CC);
21812200

2182-
if (!intervalobj->initialized || GC_G(gc_active)) {
2201+
if (!intervalobj->initialized) {
21832202
return props;
21842203
}
21852204

ext/simplexml/simplexml.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,15 +1081,9 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
10811081
zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0);
10821082
}
10831083
else if (sxe->properties) {
1084-
if (GC_G(gc_active)) {
1085-
return sxe->properties;
1086-
}
10871084
zend_hash_clean(sxe->properties);
10881085
rv = sxe->properties;
10891086
} else {
1090-
if (GC_G(gc_active)) {
1091-
return NULL;
1092-
}
10931087
ALLOC_HASHTABLE(rv);
10941088
zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0);
10951089
sxe->properties = rv;
@@ -1201,6 +1195,16 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
12011195
}
12021196
/* }}} */
12031197

1198+
static HashTable * sxe_get_gc(zval *object, zval ***table, int *n TSRMLS_DC) /* {{{ */ {
1199+
php_sxe_object *sxe;
1200+
sxe = php_sxe_fetch_object(object TSRMLS_CC);
1201+
1202+
*table = NULL;
1203+
*n = 0;
1204+
return sxe->properties;
1205+
}
1206+
/* }}} */
1207+
12041208
static HashTable * sxe_get_properties(zval *object TSRMLS_DC) /* {{{ */
12051209
{
12061210
return sxe_get_prop_hash(object, 0 TSRMLS_CC);
@@ -1966,7 +1970,9 @@ static zend_object_handlers sxe_object_handlers = { /* {{{ */
19661970
sxe_objects_compare,
19671971
sxe_object_cast,
19681972
sxe_count_elements,
1969-
sxe_get_debug_info
1973+
sxe_get_debug_info,
1974+
NULL,
1975+
sxe_get_gc
19701976
};
19711977
/* }}} */
19721978

ext/spl/spl_observer.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,8 @@ static HashTable* spl_object_storage_debug_info(zval *obj, int *is_temp TSRMLS_D
361361
/* }}} */
362362

363363
/* overriden for garbage collection
364-
* This is very hacky, but unfortunately the garbage collector can only query objects for
365-
* dependencies through get_properties */
366-
static HashTable *spl_object_storage_get_properties(zval *obj TSRMLS_DC) /* {{{ */
364+
* This is very hacky */
365+
static HashTable *spl_object_storage_get_gc(zval *obj, zval ***table, int *n TSRMLS_DC) /* {{{ */
367366
{
368367
spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(obj TSRMLS_CC);
369368
spl_SplObjectStorageElement *element;
@@ -374,14 +373,8 @@ static HashTable *spl_object_storage_get_properties(zval *obj TSRMLS_DC) /* {{{
374373

375374
props = std_object_handlers.get_properties(obj TSRMLS_CC);
376375

377-
if (!GC_G(gc_active)) {
378-
zend_hash_del(props, "\x00gcdata", sizeof("\x00gcdata"));
379-
return props;
380-
}
381-
382-
if (props->nApplyCount > 0) {
383-
return props;
384-
}
376+
*table = NULL;
377+
*n = 0;
385378

386379
/* clean \x00gcdata, as it may be out of date */
387380
if (zend_hash_find(props, "\x00gcdata", sizeof("\x00gcdata"), (void**) &gcdata_arr_pp) == SUCCESS) {
@@ -1316,10 +1309,10 @@ PHP_MINIT_FUNCTION(spl_observer)
13161309
REGISTER_SPL_STD_CLASS_EX(SplObjectStorage, spl_SplObjectStorage_new, spl_funcs_SplObjectStorage);
13171310
memcpy(&spl_handler_SplObjectStorage, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
13181311

1319-
spl_handler_SplObjectStorage.get_properties = spl_object_storage_get_properties;
13201312
spl_handler_SplObjectStorage.get_debug_info = spl_object_storage_debug_info;
13211313
spl_handler_SplObjectStorage.compare_objects = spl_object_storage_compare_objects;
13221314
spl_handler_SplObjectStorage.clone_obj = spl_object_storage_clone;
1315+
spl_handler_SplObjectStorage.get_gc = spl_object_storage_get_gc;
13231316

13241317
REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Countable);
13251318
REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Iterator);

0 commit comments

Comments
 (0)