Skip to content

Commit

Permalink
coro: fix dead state with and without autoreset
Browse files Browse the repository at this point in the history
we do not error when the coro returns from return/returncc.
we rather error when a dead coro is called, new yield state 2.
  • Loading branch information
Reini Urban committed Oct 21, 2014
1 parent 80289ca commit 73d47d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/pmc/coroutine.pmc
Expand Up @@ -56,7 +56,7 @@ static void print_sub_name(PARROT_INTERP, ARGIN(PMC *sub_pmc))
# define TRACE_CORO_1(s, arg) \
if (Interp_trace_TEST(interp, PARROT_TRACE_CORO_STATE_FLAG)) \
fprintf(stderr, (s), (arg))
# define TRACE_CORO_d(s, arg) TRACE_CORO_1(s, arg)
# define TRACE_CORO_d(s, arg) /* TRACE_CORO_1(s, arg) */
#endif


Expand Down Expand Up @@ -298,13 +298,20 @@ yields are exhausted and the coro is dead.
else if (!(PObj_get_FLAGS(SELF) & SUB_FLAG_CORO_FF)) {
PackFile_ByteCode *seg;
PMC *ccont;
INTVAL yield;

GET_ATTR_ctx(INTERP, SELF, ctx);
ccont = Parrot_pcc_get_continuation(INTERP, ctx);
TRACE_CORO("# - coro: !ff\n");
GET_ATTR_yield(INTERP, SELF, yield);
TRACE_CORO_1("# - coro: !ff (yield=%ld)\n", yield);
TRACE_CORO_d("# - coro: cont %p\n", ccont);
TRACE_CORO_d("# - coro: ctx %p\n", caller_ctx);
TRACE_CORO_d("# - coro: to_ctx %p\n", ctx);

if (yield == 2) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot resume dead coroutine.");
}
PObj_get_FLAGS(SELF) |= SUB_FLAG_CORO_FF;

GET_ATTR_seg(INTERP, SELF, seg);
Expand All @@ -328,11 +335,8 @@ yields are exhausted and the coro is dead.
GET_ATTR_yield(INTERP, SELF, yield);
TRACE_CORO_1("# - coro: ff (yield=%ld)\n", yield);

if (!yield) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot resume dead coroutine.");
}
SET_ATTR_yield(INTERP, SELF, 0);
if (yield != 2)
SET_ATTR_yield(INTERP, SELF, 0);
GET_ATTR_ctx(INTERP, SELF, ctx);
ccont = Parrot_pcc_get_continuation(INTERP, ctx);

Expand Down
6 changes: 3 additions & 3 deletions t/pmc/coroutine.t
Expand Up @@ -457,17 +457,17 @@ pir_output_is(<<'CODE', <<'OUTPUT', "Resume dead coroutine w/o autoreset");
$I0 = MyCoro() # 3. !ff y=>1
print $I0
$I0 = MyCoro() # 5. !ff y=>1
print $I0
say $I0
push_eh ehandler
$I0 = MyCoro() # 7. ff (y=0) => Cannot resume dead coroutine
say $I0
print $I0
ehandler:
pop_eh
.end
CODE
1240
124
OUTPUT

# Note: TT #1710/GH #585 argued that if one clone is dead the other are also dead.
Expand Down

0 comments on commit 73d47d5

Please sign in to comment.