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 |
… | |
… | |
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 | |
31 | |
30 | #include "libcoro/coro.c" |
|
|
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> |
36 | # include <sys/mman.h> |
36 | # include <sys/mman.h> |
… | |
… | |
109 | AV *mainstack; |
109 | AV *mainstack; |
110 | SV **stack_sp; |
110 | SV **stack_sp; |
111 | OP *op; |
111 | OP *op; |
112 | SV **curpad; |
112 | SV **curpad; |
113 | AV *comppad; |
113 | AV *comppad; |
|
|
114 | CV *compcv; |
114 | SV **stack_base; |
115 | SV **stack_base; |
115 | SV **stack_max; |
116 | SV **stack_max; |
116 | SV **tmps_stack; |
117 | SV **tmps_stack; |
117 | I32 tmps_floor; |
118 | I32 tmps_floor; |
118 | I32 tmps_ix; |
119 | I32 tmps_ix; |
… | |
… | |
270 | AV *av = (AV *)mg->mg_obj; |
271 | AV *av = (AV *)mg->mg_obj; |
271 | |
272 | |
272 | /* casting is fun. */ |
273 | /* casting is fun. */ |
273 | while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av))) |
274 | while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av))) |
274 | free_padlist (aTHX_ padlist); |
275 | free_padlist (aTHX_ padlist); |
|
|
276 | |
|
|
277 | SvREFCNT_dec (av); |
275 | } |
278 | } |
276 | |
279 | |
277 | #define PERL_MAGIC_coro PERL_MAGIC_ext |
280 | #define PERL_MAGIC_coro PERL_MAGIC_ext |
278 | |
281 | |
279 | static MGVTBL vtbl_coro = {0, 0, 0, 0, coro_cv_free}; |
282 | static MGVTBL vtbl_coro = {0, 0, 0, 0, coro_cv_free}; |
… | |
… | |
325 | PL_mainstack = c->mainstack; |
328 | PL_mainstack = c->mainstack; |
326 | PL_stack_sp = c->stack_sp; |
329 | PL_stack_sp = c->stack_sp; |
327 | PL_op = c->op; |
330 | PL_op = c->op; |
328 | PL_curpad = c->curpad; |
331 | PL_curpad = c->curpad; |
329 | PL_comppad = c->comppad; |
332 | PL_comppad = c->comppad; |
|
|
333 | PL_compcv = c->compcv; |
330 | PL_stack_base = c->stack_base; |
334 | PL_stack_base = c->stack_base; |
331 | PL_stack_max = c->stack_max; |
335 | PL_stack_max = c->stack_max; |
332 | PL_tmps_stack = c->tmps_stack; |
336 | PL_tmps_stack = c->tmps_stack; |
333 | PL_tmps_floor = c->tmps_floor; |
337 | PL_tmps_floor = c->tmps_floor; |
334 | PL_tmps_ix = c->tmps_ix; |
338 | PL_tmps_ix = c->tmps_ix; |
… | |
… | |
449 | c->mainstack = PL_mainstack; |
453 | c->mainstack = PL_mainstack; |
450 | c->stack_sp = PL_stack_sp; |
454 | c->stack_sp = PL_stack_sp; |
451 | c->op = PL_op; |
455 | c->op = PL_op; |
452 | c->curpad = PL_curpad; |
456 | c->curpad = PL_curpad; |
453 | c->comppad = PL_comppad; |
457 | c->comppad = PL_comppad; |
|
|
458 | c->compcv = PL_compcv; |
454 | c->stack_base = PL_stack_base; |
459 | c->stack_base = PL_stack_base; |
455 | c->stack_max = PL_stack_max; |
460 | c->stack_max = PL_stack_max; |
456 | c->tmps_stack = PL_tmps_stack; |
461 | c->tmps_stack = PL_tmps_stack; |
457 | c->tmps_floor = PL_tmps_floor; |
462 | c->tmps_floor = PL_tmps_floor; |
458 | c->tmps_ix = PL_tmps_ix; |
463 | c->tmps_ix = PL_tmps_ix; |
… | |
… | |
1015 | if (coro->mainstack && coro->mainstack != main_mainstack) |
1020 | if (coro->mainstack && coro->mainstack != main_mainstack) |
1016 | { |
1021 | { |
1017 | struct coro temp; |
1022 | struct coro temp; |
1018 | |
1023 | |
1019 | PUTBACK; |
1024 | PUTBACK; |
1020 | SAVE(aTHX_ (&temp), TRANSFER_SAVE_ALL); |
1025 | SAVE (aTHX_ (&temp), TRANSFER_SAVE_ALL); |
1021 | LOAD(aTHX_ coro); |
1026 | LOAD (aTHX_ coro); |
1022 | SPAGAIN; |
1027 | SPAGAIN; |
1023 | |
1028 | |
1024 | destroy_stacks (aTHX); |
1029 | destroy_stacks (aTHX); |
1025 | |
1030 | |
1026 | LOAD((&temp)); /* this will get rid of defsv etc.. */ |
1031 | LOAD ((&temp)); /* this will get rid of defsv etc.. */ |
1027 | SPAGAIN; |
1032 | SPAGAIN; |
1028 | |
1033 | |
1029 | coro->mainstack = 0; |
1034 | coro->mainstack = 0; |
1030 | } |
1035 | } |
1031 | |
1036 | |
… | |
… | |
1046 | |
1051 | |
1047 | void |
1052 | void |
1048 | yield(...) |
1053 | yield(...) |
1049 | PROTOTYPE: @ |
1054 | PROTOTYPE: @ |
1050 | CODE: |
1055 | CODE: |
1051 | static SV *returnstk; |
1056 | SV *yieldstack; |
1052 | SV *sv; |
1057 | SV *sv; |
1053 | AV *defav = GvAV (PL_defgv); |
1058 | AV *defav = GvAV (PL_defgv); |
1054 | struct coro *prev, *next; |
1059 | struct coro *prev, *next; |
1055 | |
1060 | |
1056 | if (!returnstk) |
1061 | yieldstack = *hv_fetch ( |
1057 | returnstk = SvRV ((SV *)get_sv ("Coro::Cont::return", FALSE)); |
1062 | (HV *)SvRV (GvSV (coro_current)), |
|
|
1063 | "yieldstack", sizeof ("yieldstack") - 1, |
|
|
1064 | 0 |
|
|
1065 | ); |
1058 | |
1066 | |
1059 | /* set up @_ -- ugly */ |
1067 | /* set up @_ -- ugly */ |
1060 | av_clear (defav); |
1068 | av_clear (defav); |
1061 | av_fill (defav, items - 1); |
1069 | av_fill (defav, items - 1); |
1062 | while (items--) |
1070 | while (items--) |
1063 | av_store (defav, items, SvREFCNT_inc (ST(items))); |
1071 | av_store (defav, items, SvREFCNT_inc (ST(items))); |
1064 | |
1072 | |
1065 | mg_get (returnstk); /* isn't documentation wrong for mg_get? */ |
|
|
1066 | sv = av_pop ((AV *)SvRV (returnstk)); |
1073 | sv = av_pop ((AV *)SvRV (yieldstack)); |
1067 | prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); |
1074 | prev = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 0, 0))); |
1068 | next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); |
1075 | next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); |
1069 | SvREFCNT_dec (sv); |
1076 | SvREFCNT_dec (sv); |
1070 | |
1077 | |
1071 | transfer(aTHX_ prev, next, 0); |
1078 | transfer (aTHX_ prev, next, 0); |
1072 | |
1079 | |
1073 | MODULE = Coro::State PACKAGE = Coro |
1080 | MODULE = Coro::State PACKAGE = Coro |
1074 | |
1081 | |
1075 | # this is slightly dirty (should expose a c-level api) |
1082 | # this is slightly dirty (should expose a c-level api) |
1076 | |
1083 | |