1 | #define PERL_NO_GET_CONTEXT |
1 | #define PERL_NO_GET_CONTEXT |
|
|
2 | |
|
|
3 | #include "libcoro/coro.c" |
2 | |
4 | |
3 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
4 | #include "perl.h" |
6 | #include "perl.h" |
5 | #include "XSUB.h" |
7 | #include "XSUB.h" |
6 | |
8 | |
7 | #include "patchlevel.h" |
9 | #include "patchlevel.h" |
8 | |
10 | |
9 | #if PATCHLEVEL < 6 |
11 | #if PERL_VERSION < 6 |
10 | # ifndef PL_ppaddr |
12 | # ifndef PL_ppaddr |
11 | # define PL_ppaddr ppaddr |
13 | # define PL_ppaddr ppaddr |
12 | # endif |
14 | # endif |
13 | # ifndef call_sv |
15 | # ifndef call_sv |
14 | # define call_sv perl_call_sv |
16 | # define call_sv perl_call_sv |
… | |
… | |
24 | # endif |
26 | # endif |
25 | # ifndef IS_PADCONST |
27 | # ifndef IS_PADCONST |
26 | # define IS_PADCONST(v) 0 |
28 | # define IS_PADCONST(v) 0 |
27 | # endif |
29 | # endif |
28 | #endif |
30 | #endif |
29 | |
|
|
30 | #include "libcoro/coro.c" |
|
|
31 | |
31 | |
32 | #include <signal.h> |
32 | #include <signal.h> |
33 | |
33 | |
34 | #ifdef HAVE_MMAP |
34 | #ifdef HAVE_MMAP |
35 | # include <unistd.h> |
35 | # include <unistd.h> |
… | |
… | |
128 | I32 savestack_ix; |
128 | I32 savestack_ix; |
129 | I32 savestack_max; |
129 | I32 savestack_max; |
130 | OP **retstack; |
130 | OP **retstack; |
131 | I32 retstack_ix; |
131 | I32 retstack_ix; |
132 | I32 retstack_max; |
132 | I32 retstack_max; |
|
|
133 | PMOP *curpm; |
133 | COP *curcop; |
134 | COP *curcop; |
134 | JMPENV *top_env; |
135 | JMPENV *top_env; |
135 | |
136 | |
136 | /* data associated with this coroutine (initial args) */ |
137 | /* data associated with this coroutine (initial args) */ |
137 | AV *args; |
138 | AV *args; |
… | |
… | |
347 | PL_savestack_ix = c->savestack_ix; |
348 | PL_savestack_ix = c->savestack_ix; |
348 | PL_savestack_max = c->savestack_max; |
349 | PL_savestack_max = c->savestack_max; |
349 | PL_retstack = c->retstack; |
350 | PL_retstack = c->retstack; |
350 | PL_retstack_ix = c->retstack_ix; |
351 | PL_retstack_ix = c->retstack_ix; |
351 | PL_retstack_max = c->retstack_max; |
352 | PL_retstack_max = c->retstack_max; |
|
|
353 | PL_curpm = c->curpm; |
352 | PL_curcop = c->curcop; |
354 | PL_curcop = c->curcop; |
353 | PL_top_env = c->top_env; |
355 | PL_top_env = c->top_env; |
354 | |
356 | |
355 | if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); |
357 | if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); |
356 | if (c->defsv) REPLACE_SV (DEFSV , c->defsv); |
358 | if (c->defsv) REPLACE_SV (DEFSV , c->defsv); |
… | |
… | |
472 | c->savestack_ix = PL_savestack_ix; |
474 | c->savestack_ix = PL_savestack_ix; |
473 | c->savestack_max = PL_savestack_max; |
475 | c->savestack_max = PL_savestack_max; |
474 | c->retstack = PL_retstack; |
476 | c->retstack = PL_retstack; |
475 | c->retstack_ix = PL_retstack_ix; |
477 | c->retstack_ix = PL_retstack_ix; |
476 | c->retstack_max = PL_retstack_max; |
478 | c->retstack_max = PL_retstack_max; |
|
|
479 | c->curpm = PL_curpm; |
477 | c->curcop = PL_curcop; |
480 | c->curcop = PL_curcop; |
478 | c->top_env = PL_top_env; |
481 | c->top_env = PL_top_env; |
479 | } |
482 | } |
480 | |
483 | |
481 | /* |
484 | /* |
… | |
… | |
1051 | |
1054 | |
1052 | void |
1055 | void |
1053 | yield(...) |
1056 | yield(...) |
1054 | PROTOTYPE: @ |
1057 | PROTOTYPE: @ |
1055 | CODE: |
1058 | CODE: |
1056 | static SV *returnstk; |
1059 | SV *yieldstack; |
1057 | SV *sv; |
1060 | SV *sv; |
1058 | AV *defav = GvAV (PL_defgv); |
1061 | AV *defav = GvAV (PL_defgv); |
1059 | struct coro *prev, *next; |
1062 | struct coro *prev, *next; |
1060 | |
1063 | |
1061 | if (!returnstk) |
1064 | yieldstack = *hv_fetch ( |
1062 | returnstk = SvRV ((SV *)get_sv ("Coro::Cont::return", FALSE)); |
1065 | (HV *)SvRV (GvSV (coro_current)), |
|
|
1066 | "yieldstack", sizeof ("yieldstack") - 1, |
|
|
1067 | 0 |
|
|
1068 | ); |
1063 | |
1069 | |
1064 | /* set up @_ -- ugly */ |
1070 | /* set up @_ -- ugly */ |
1065 | av_clear (defav); |
1071 | av_clear (defav); |
1066 | av_fill (defav, items - 1); |
1072 | av_fill (defav, items - 1); |
1067 | while (items--) |
1073 | while (items--) |
1068 | av_store (defav, items, SvREFCNT_inc (ST(items))); |
1074 | av_store (defav, items, SvREFCNT_inc (ST(items))); |
1069 | |
1075 | |
1070 | SvGETMAGIC (returnstk); /* isn't documentation wrong for mg_get? */ |
|
|
1071 | sv = av_pop ((AV *)SvRV (returnstk)); |
1076 | sv = av_pop ((AV *)SvRV (yieldstack)); |
1072 | prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); |
1077 | prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); |
1073 | next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); |
1078 | next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); |
1074 | SvREFCNT_dec (sv); |
1079 | SvREFCNT_dec (sv); |
1075 | |
1080 | |
1076 | transfer (aTHX_ prev, next, 0); |
1081 | transfer (aTHX_ prev, next, 0); |