… | |
… | |
25 | |
25 | |
26 | /* The next macro should declare a variable stacklevel that contains and approximation |
26 | /* The next macro should declare a variable stacklevel that contains and approximation |
27 | * to the current C stack pointer. Its property is that it changes with each call |
27 | * to the current C stack pointer. Its property is that it changes with each call |
28 | * and should be unique. */ |
28 | * and should be unique. */ |
29 | #define dSTACKLEVEL void *stacklevel = &stacklevel |
29 | #define dSTACKLEVEL void *stacklevel = &stacklevel |
|
|
30 | |
|
|
31 | #define IN_DESTRUCT (PL_main_cv == Nullcv) |
30 | |
32 | |
31 | #define labs(l) ((l) >= 0 ? (l) : -(l)) |
33 | #define labs(l) ((l) >= 0 ? (l) : -(l)) |
32 | |
34 | |
33 | #include "CoroAPI.h" |
35 | #include "CoroAPI.h" |
34 | |
36 | |
… | |
… | |
487 | * still there is a memleak of 128 bytes... |
489 | * still there is a memleak of 128 bytes... |
488 | */ |
490 | */ |
489 | STATIC void |
491 | STATIC void |
490 | destroy_stacks(pTHX) |
492 | destroy_stacks(pTHX) |
491 | { |
493 | { |
492 | int destruct = PL_main_cv != Nullcv; |
494 | if (!IN_DESTRUCT) |
493 | |
|
|
494 | if (destruct) |
|
|
495 | { |
495 | { |
496 | /* is this ugly, I ask? */ |
496 | /* is this ugly, I ask? */ |
497 | while (PL_scopestack_ix) |
497 | while (PL_scopestack_ix) |
498 | LEAVE; |
498 | LEAVE; |
499 | |
499 | |
… | |
… | |
513 | dSP; |
513 | dSP; |
514 | SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); |
514 | SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); |
515 | PUTBACK; /* possibly superfluous */ |
515 | PUTBACK; /* possibly superfluous */ |
516 | } |
516 | } |
517 | |
517 | |
518 | if (destruct) |
518 | if (!IN_DESTRUCT) |
519 | { |
519 | { |
520 | dounwind(-1); |
520 | dounwind(-1); |
521 | SvREFCNT_dec(PL_curstackinfo->si_stack); |
521 | SvREFCNT_dec(PL_curstackinfo->si_stack); |
522 | } |
522 | } |
523 | |
523 | |
… | |
… | |
744 | } |
744 | } |
745 | } |
745 | } |
746 | else |
746 | else |
747 | setup_coro (next); |
747 | setup_coro (next); |
748 | } |
748 | } |
749 | } |
|
|
750 | |
749 | |
751 | /* |
750 | /* |
752 | * xnext is now either prev or next, depending on wether |
751 | * xnext is now either prev or next, depending on wether |
753 | * we switched the c stack or not. that's why i use a global |
752 | * we switched the c stack or not. that's why i use a global |
754 | * variable, that should become thread-specific at one point. |
753 | * variable, that should become thread-specific at one point. |
755 | */ |
754 | */ |
756 | xnext->cursp = stacklevel; |
755 | xnext->cursp = stacklevel; |
|
|
756 | } |
757 | } |
757 | } |
758 | |
758 | |
759 | static struct coro * |
759 | static struct coro * |
760 | sv_to_coro (SV *arg, const char *funcname, const char *varname) |
760 | sv_to_coro (SV *arg, const char *funcname, const char *varname) |
761 | { |
761 | { |