Browse files

Use get_gc instead of hacks of get_properties

  • Loading branch information...
1 parent 881416c commit df97c3aa0d331be668bd5d8f27fff96d4e3ac1d7 @dstogov dstogov committed Dec 5, 2012
Showing with 39 additions and 21 deletions.
  1. +21 −2 ext/date/php_date.c
  2. +13 −7 ext/simplexml/simplexml.c
  3. +5 −12 ext/spl/spl_observer.c
View
23 ext/date/php_date.c
@@ -563,7 +563,9 @@ static zend_object_value date_object_clone_interval(zval *this_ptr TSRMLS_DC);
static zend_object_value date_object_clone_period(zval *this_ptr TSRMLS_DC);
static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC);
+static HashTable *date_object_get_gc(zval *object, zval ***table, int *n TSRMLS_DC);
static HashTable *date_object_get_properties(zval *object TSRMLS_DC);
+static HashTable *date_object_get_gc_interval(zval *object, zval ***table, int *n TSRMLS_DC);
static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC);
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)
date_object_handlers_date.clone_obj = date_object_clone_date;
date_object_handlers_date.compare_objects = date_object_compare_date;
date_object_handlers_date.get_properties = date_object_get_properties;
+ date_object_handlers_date.get_gc = date_object_get_gc;
#define REGISTER_DATE_CLASS_CONST_STRING(const_name, value) \
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)
date_object_handlers_interval.write_property = date_interval_write_property;
date_object_handlers_interval.get_properties = date_object_get_properties_interval;
date_object_handlers_interval.get_property_ptr_ptr = NULL;
+ date_object_handlers_interval.get_gc = date_object_get_gc_interval;
INIT_CLASS_ENTRY(ce_period, "DatePeriod", date_funcs_period);
ce_period.create_object = date_object_new_period;
@@ -2023,6 +2027,13 @@ static int date_object_compare_date(zval *d1, zval *d2 TSRMLS_DC)
return 1;
}
+static HashTable *date_object_get_gc(zval *object, zval ***table, int *n TSRMLS_DC)
+{
+ *table = NULL;
+ *n = 0;
+ return zend_std_get_properties(object TSRMLS_CC);
+}
+
static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
{
HashTable *props;
@@ -2034,7 +2045,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC)
props = zend_std_get_properties(object TSRMLS_CC);
- if (!dateobj->time || GC_G(gc_active)) {
+ if (!dateobj->time) {
return props;
}
@@ -2168,6 +2179,14 @@ static zend_object_value date_object_clone_interval(zval *this_ptr TSRMLS_DC)
return new_ov;
}
+static HashTable *date_object_get_gc_interval(zval *object, zval ***table, int *n TSRMLS_DC)
+{
+
+ *table = NULL;
+ *n = 0;
+ return zend_std_get_properties(object TSRMLS_CC);
+}
+
static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
{
HashTable *props;
@@ -2179,7 +2198,7 @@ static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC)
props = zend_std_get_properties(object TSRMLS_CC);
- if (!intervalobj->initialized || GC_G(gc_active)) {
+ if (!intervalobj->initialized) {
return props;
}
View
20 ext/simplexml/simplexml.c
@@ -1081,15 +1081,9 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0);
}
else if (sxe->properties) {
- if (GC_G(gc_active)) {
- return sxe->properties;
- }
zend_hash_clean(sxe->properties);
rv = sxe->properties;
} else {
- if (GC_G(gc_active)) {
- return NULL;
- }
ALLOC_HASHTABLE(rv);
zend_hash_init(rv, 0, NULL, ZVAL_PTR_DTOR, 0);
sxe->properties = rv;
@@ -1201,6 +1195,16 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
}
/* }}} */
+static HashTable * sxe_get_gc(zval *object, zval ***table, int *n TSRMLS_DC) /* {{{ */ {
+ php_sxe_object *sxe;
+ sxe = php_sxe_fetch_object(object TSRMLS_CC);
+
+ *table = NULL;
+ *n = 0;
+ return sxe->properties;
+}
+/* }}} */
+
static HashTable * sxe_get_properties(zval *object TSRMLS_DC) /* {{{ */
{
return sxe_get_prop_hash(object, 0 TSRMLS_CC);
@@ -1966,7 +1970,9 @@ static zend_object_handlers sxe_object_handlers = { /* {{{ */
sxe_objects_compare,
sxe_object_cast,
sxe_count_elements,
- sxe_get_debug_info
+ sxe_get_debug_info,
+ NULL,
+ sxe_get_gc
};
/* }}} */
View
17 ext/spl/spl_observer.c
@@ -361,9 +361,8 @@ static HashTable* spl_object_storage_debug_info(zval *obj, int *is_temp TSRMLS_D
/* }}} */
/* overriden for garbage collection
- * This is very hacky, but unfortunately the garbage collector can only query objects for
- * dependencies through get_properties */
-static HashTable *spl_object_storage_get_properties(zval *obj TSRMLS_DC) /* {{{ */
+ * This is very hacky */
+static HashTable *spl_object_storage_get_gc(zval *obj, zval ***table, int *n TSRMLS_DC) /* {{{ */
{
spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(obj TSRMLS_CC);
spl_SplObjectStorageElement *element;
@@ -374,14 +373,8 @@ static HashTable *spl_object_storage_get_properties(zval *obj TSRMLS_DC) /* {{{
props = std_object_handlers.get_properties(obj TSRMLS_CC);
- if (!GC_G(gc_active)) {
- zend_hash_del(props, "\x00gcdata", sizeof("\x00gcdata"));
- return props;
- }
-
- if (props->nApplyCount > 0) {
- return props;
- }
+ *table = NULL;
+ *n = 0;
/* clean \x00gcdata, as it may be out of date */
if (zend_hash_find(props, "\x00gcdata", sizeof("\x00gcdata"), (void**) &gcdata_arr_pp) == SUCCESS) {
@@ -1316,10 +1309,10 @@ PHP_MINIT_FUNCTION(spl_observer)
REGISTER_SPL_STD_CLASS_EX(SplObjectStorage, spl_SplObjectStorage_new, spl_funcs_SplObjectStorage);
memcpy(&spl_handler_SplObjectStorage, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- spl_handler_SplObjectStorage.get_properties = spl_object_storage_get_properties;
spl_handler_SplObjectStorage.get_debug_info = spl_object_storage_debug_info;
spl_handler_SplObjectStorage.compare_objects = spl_object_storage_compare_objects;
spl_handler_SplObjectStorage.clone_obj = spl_object_storage_clone;
+ spl_handler_SplObjectStorage.get_gc = spl_object_storage_get_gc;
REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Countable);
REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Iterator);

0 comments on commit df97c3a

Please sign in to comment.