Skip to content

Commit ce2f9bb

Browse files
committedAug 24, 2008
- MFH Fix issue with destruction of overloaded objects
1 parent 0edbdd7 commit ce2f9bb

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed
 

‎Zend/zend_gc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ ZEND_API int gc_collect_cycles(TSRMLS_D)
575575
EG(objects_store).object_buckets[Z_OBJ_HANDLE(p->z)].bucket.obj.refcount <= 0) {
576576
EG(objects_store).object_buckets[Z_OBJ_HANDLE(p->z)].bucket.obj.refcount = 1;
577577
Z_TYPE(p->z) = IS_NULL;
578-
zend_objects_store_del_ref_by_handle(Z_OBJ_HANDLE(p->z) TSRMLS_CC);
578+
zend_objects_store_del_ref_by_handle_ex(Z_OBJ_HANDLE(p->z), Z_OBJ_HT(p->z) TSRMLS_CC);
579579
}
580580
} else if (Z_TYPE(p->z) == IS_ARRAY) {
581581
Z_TYPE(p->z) = IS_NULL;

‎Zend/zend_objects.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl
5353

5454
if (destructor) {
5555
zval *obj;
56+
zend_object_store_bucket *obj_bucket;
5657

5758
if (destructor->op_array.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
5859
if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) {
@@ -87,8 +88,11 @@ ZEND_API void zend_objects_destroy_object(zend_object *object, zend_object_handl
8788
MAKE_STD_ZVAL(obj);
8889
Z_TYPE_P(obj) = IS_OBJECT;
8990
Z_OBJ_HANDLE_P(obj) = handle;
90-
/* TODO: We cannot set proper handlers. */
91-
Z_OBJ_HT_P(obj) = &std_object_handlers;
91+
obj_bucket = &EG(objects_store).object_buckets[handle];
92+
if (!obj_bucket->bucket.obj.handlers) {
93+
obj_bucket->bucket.obj.handlers = &std_object_handlers;
94+
}
95+
Z_OBJ_HT_P(obj) = obj_bucket->bucket.obj.handlers;
9296
zval_copy_ctor(obj);
9397

9498
/* Make sure that destructors are protected from previously thrown exceptions.

‎Zend/zend_objects_API.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ ZEND_API zend_object_handle zend_objects_store_put(void *object, zend_objects_st
122122
obj->object = object;
123123
obj->dtor = dtor?dtor:(zend_objects_store_dtor_t)zend_objects_destroy_object;
124124
obj->free_storage = free_storage;
125-
126125
obj->clone = clone;
126+
obj->handlers = NULL;
127127

128128
#if ZEND_DEBUG_OBJECTS
129129
fprintf(stderr, "Allocated object id #%d\n", handle);
@@ -168,7 +168,7 @@ ZEND_API void zend_objects_store_del_ref(zval *zobject TSRMLS_DC)
168168
handle = Z_OBJ_HANDLE_P(zobject);
169169

170170
Z_ADDREF_P(zobject);
171-
zend_objects_store_del_ref_by_handle(handle TSRMLS_CC);
171+
zend_objects_store_del_ref_by_handle_ex(handle, Z_OBJ_HT_P(zobject) TSRMLS_CC);
172172
Z_DELREF_P(zobject);
173173

174174
GC_ZOBJ_CHECK_POSSIBLE_ROOT(zobject);
@@ -177,7 +177,7 @@ ZEND_API void zend_objects_store_del_ref(zval *zobject TSRMLS_DC)
177177
/*
178178
* Delete a reference to an objects store entry given the object handle.
179179
*/
180-
ZEND_API void zend_objects_store_del_ref_by_handle(zend_object_handle handle TSRMLS_DC)
180+
ZEND_API void zend_objects_store_del_ref_by_handle_ex(zend_object_handle handle, const zend_object_handlers *handlers TSRMLS_DC) /* {{{ */
181181
{
182182
struct _store_object *obj;
183183
int failure = 0;
@@ -198,6 +198,9 @@ ZEND_API void zend_objects_store_del_ref_by_handle(zend_object_handle handle TSR
198198
EG(objects_store).object_buckets[handle].destructor_called = 1;
199199

200200
if (obj->dtor) {
201+
if (handlers && !obj->handlers) {
202+
obj->handlers = handlers;
203+
}
201204
zend_try {
202205
obj->dtor(obj->object, handle TSRMLS_CC);
203206
} zend_catch {
@@ -232,6 +235,7 @@ ZEND_API void zend_objects_store_del_ref_by_handle(zend_object_handle handle TSR
232235
zend_bailout();
233236
}
234237
}
238+
/* }}} */
235239

236240
ZEND_API zend_object_value zend_objects_store_clone_obj(zval *zobject TSRMLS_DC)
237241
{
@@ -250,6 +254,7 @@ ZEND_API zend_object_value zend_objects_store_clone_obj(zval *zobject TSRMLS_DC)
250254

251255
retval.handle = zend_objects_store_put(new_object, obj->dtor, obj->free_storage, obj->clone TSRMLS_CC);
252256
retval.handlers = Z_OBJ_HT_P(zobject);
257+
EG(objects_store).object_buckets[handle].bucket.obj.handlers = retval.handlers;
253258

254259
return retval;
255260
}
@@ -288,8 +293,10 @@ ZEND_API void zend_object_store_set_object(zval *zobject, void *object TSRMLS_DC
288293
ZEND_API void zend_object_store_ctor_failed(zval *zobject TSRMLS_DC)
289294
{
290295
zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
291-
292-
EG(objects_store).object_buckets[handle].destructor_called = 1;
296+
zend_object_store_bucket *obj_bucket = &EG(objects_store).object_buckets[handle];
297+
298+
obj_bucket->bucket.obj.handlers = Z_OBJ_HT_P(zobject);;
299+
obj_bucket->destructor_called = 1;
293300
}
294301

295302

‎Zend/zend_objects_API.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct _zend_object_store_bucket {
3737
zend_objects_store_dtor_t dtor;
3838
zend_objects_free_object_storage_t free_storage;
3939
zend_objects_store_clone_t clone;
40+
const zend_object_handlers *handlers;
4041
zend_uint refcount;
4142
gc_root_buffer *buffered;
4243
} obj;
@@ -66,7 +67,10 @@ ZEND_API zend_object_handle zend_objects_store_put(void *object, zend_objects_st
6667
ZEND_API void zend_objects_store_add_ref(zval *object TSRMLS_DC);
6768
ZEND_API void zend_objects_store_del_ref(zval *object TSRMLS_DC);
6869
ZEND_API void zend_objects_store_add_ref_by_handle(zend_object_handle handle TSRMLS_DC);
69-
ZEND_API void zend_objects_store_del_ref_by_handle(zend_object_handle handle TSRMLS_DC);
70+
ZEND_API void zend_objects_store_del_ref_by_handle_ex(zend_object_handle handle, const zend_object_handlers *handlers TSRMLS_DC);
71+
static inline void zend_objects_store_del_ref_by_handle(zend_object_handle handle TSRMLS_DC) {
72+
zend_objects_store_del_ref_by_handle_ex(handle, NULL TSRMLS_CC);
73+
}
7074
ZEND_API zend_uint zend_objects_store_get_refcount(zval *object TSRMLS_DC);
7175
ZEND_API zend_object_value zend_objects_store_clone_obj(zval *object TSRMLS_DC);
7276
ZEND_API void *zend_object_store_get_object(const zval *object TSRMLS_DC);

0 commit comments

Comments
 (0)