Skip to content

Commit ec66e78

Browse files
committed
php#56: fix correct destructor test output and handle coroutine context in garbage collection
1 parent 5657dd5 commit ec66e78

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Zend/zend_gc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,11 @@ static zend_always_inline zend_result gc_call_destructors(uint32_t idx, uint32_t
19111911
obj->handlers->dtor_obj(obj);
19121912
GC_TRACE_REF(obj, "returned from destructor");
19131913
GC_DELREF(obj);
1914-
if (UNEXPECTED((fiber != NULL && GC_G(dtor_fiber) != fiber) || coroutine != *current_coroutine_ptr)) {
1914+
if (UNEXPECTED((coroutine == NULL && coroutine != *current_coroutine_ptr))) {
1915+
// special case: called from main coroutine and activate async context
1916+
GC_G(gc_coroutine) = *current_coroutine_ptr;
1917+
}
1918+
if (UNEXPECTED((fiber != NULL && GC_G(dtor_fiber) != fiber) || (coroutine != NULL && coroutine != *current_coroutine_ptr))) {
19151919
/* We resumed after suspension */
19161920
gc_check_possible_root((zend_refcounted*)&obj->gc);
19171921
return FAILURE;
@@ -2397,6 +2401,7 @@ ZEND_API int zend_gc_collect_cycles(void)
23972401
GC_G(gc_active) = 0;
23982402

23992403
GC_G(collector_time) += zend_hrtime() - start_time;
2404+
GC_G(gc_coroutine) = NULL;
24002405
return total_count;
24012406
}
24022407

0 commit comments

Comments
 (0)