Skip to content

Commit d50b73e

Browse files
committed
#9: + fix context tests and refcount
1 parent 089f34b commit d50b73e

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

async.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ PHP_FUNCTION(Async_currentContext)
658658
async_context_t *context = async_context_new();
659659
context->scope = scope;
660660
scope->context = &context->base;
661-
RETURN_OBJ(&context->std);
661+
RETURN_OBJ_COPY(&context->std);
662662
}
663663

664664
// Return the existing context from scope

scope.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,10 @@ static void scope_dispose(zend_async_event_t *scope_event)
10881088
zend_async_scope_remove_child(scope->scope.parent_scope, &scope->scope);
10891089
}
10901090

1091-
// Clear weak reference from context to scope
10921091
if (scope->scope.context != NULL) {
10931092
async_context_t *context = (async_context_t *) scope->scope.context;
10941093
context->scope = NULL;
1094+
OBJ_RELEASE(&context->std);
10951095
}
10961096

10971097
if (scope->scope.scope_object != NULL) {

tests/context/002-context_inheritance.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Context inheritance through scope hierarchy
55

66
use function Async\spawn;
77
use function Async\currentContext;
8+
use function Async\await;
89

910
echo "start\n";
1011

@@ -79,6 +80,8 @@ $child_coroutine = $child_scope->spawn(function() {
7980
return "child_done";
8081
});
8182

83+
await($child_coroutine);
84+
8285
$child_coroutine->getResult();
8386

8487
echo "end\n";

0 commit comments

Comments
 (0)