… | |
… | |
2 | #define USE_NO_MINGW_SETJMP_TWO_ARGS |
2 | #define USE_NO_MINGW_SETJMP_TWO_ARGS |
3 | |
3 | |
4 | #define NDEBUG 1 /* perl usually disables NDEBUG later */ |
4 | #define NDEBUG 1 /* perl usually disables NDEBUG later */ |
5 | |
5 | |
6 | #include "libcoro/coro.c" |
6 | #include "libcoro/coro.c" |
|
|
7 | |
|
|
8 | #if CORO_UCONTEXT |
|
|
9 | #define CORO_BACKEND "ucontext" |
|
|
10 | #elif CORO_SJLJ |
|
|
11 | #define CORO_BACKEND "sjlj" |
|
|
12 | #elif CORO_LINUX |
|
|
13 | #define CORO_BACKEND "linux" |
|
|
14 | #elif CORO_LOSER |
|
|
15 | #define CORO_BACKEND "loser" |
|
|
16 | #elif CORO_FIBER |
|
|
17 | #define CORO_BACKEND "fiber" |
|
|
18 | #elif CORO_IRIX |
|
|
19 | #define CORO_BACKEND "irix" |
|
|
20 | #elif CORO_ASM |
|
|
21 | #define CORO_BACKEND "asm" |
|
|
22 | #elif CORO_PTHREAD |
|
|
23 | #define CORO_BACKEND "pthread" |
|
|
24 | #else |
|
|
25 | #define CORO_BACKEND "unknown" |
|
|
26 | #endif |
7 | |
27 | |
8 | #define PERL_NO_GET_CONTEXT |
28 | #define PERL_NO_GET_CONTEXT |
9 | #define PERL_EXT |
29 | #define PERL_EXT |
10 | |
30 | |
11 | #include "EXTERN.h" |
31 | #include "EXTERN.h" |
… | |
… | |
116 | # define CORO_CLOCK_MONOTONIC 1 |
136 | # define CORO_CLOCK_MONOTONIC 1 |
117 | # define CORO_CLOCK_THREAD_CPUTIME_ID 3 |
137 | # define CORO_CLOCK_THREAD_CPUTIME_ID 3 |
118 | # endif |
138 | # endif |
119 | #endif |
139 | #endif |
120 | |
140 | |
|
|
141 | /* one off bugfix for perl 5.22 */ |
|
|
142 | #if PERL_VERSION_ATLEAST(5,22,0) && !PERL_VERSION_ATLEAST(5,24,0) |
|
|
143 | # undef PadlistNAMES |
|
|
144 | # define PadlistNAMES(pl) *((PADNAMELIST **)PadlistARRAY (pl)) |
|
|
145 | #endif |
|
|
146 | |
|
|
147 | #if PERL_VERSION_ATLEAST(5,24,0) |
|
|
148 | # define SUB_ARGARRAY PL_curpad[0] |
|
|
149 | #else |
|
|
150 | # define SUB_ARGARRAY (SV *)cx->blk_sub.argarray |
|
|
151 | #endif |
|
|
152 | |
121 | /* perl usually suppressed asserts. for debugging, we sometimes force it to be on */ |
153 | /* perl usually suppresses asserts. for debugging, we sometimes force it to be on */ |
122 | #if 0 |
154 | #if 0 |
123 | # undef NDEBUG |
155 | # undef NDEBUG |
124 | # include <assert.h> |
156 | # include <assert.h> |
125 | #endif |
157 | #endif |
126 | |
158 | |
… | |
… | |
251 | int usecount; /* number of transfers to this coro */ |
283 | int usecount; /* number of transfers to this coro */ |
252 | |
284 | |
253 | /* coro process data */ |
285 | /* coro process data */ |
254 | int prio; |
286 | int prio; |
255 | SV *except; /* exception to be thrown */ |
287 | SV *except; /* exception to be thrown */ |
256 | SV *rouse_cb; /* last rouse callback */ |
288 | SV *rouse_cb; /* most recently created rouse callback */ |
257 | AV *on_destroy; /* callbacks or coros to notify on destroy */ |
289 | AV *on_destroy; /* callbacks or coros to notify on destroy */ |
258 | AV *status; /* the exit status list */ |
290 | AV *status; /* the exit status list */ |
259 | |
291 | |
260 | /* async_pool */ |
292 | /* async_pool */ |
261 | SV *saved_deffh; |
293 | SV *saved_deffh; |
… | |
… | |
1210 | myop.op_next = Nullop; |
1242 | myop.op_next = Nullop; |
1211 | myop.op_type = OP_ENTERSUB; |
1243 | myop.op_type = OP_ENTERSUB; |
1212 | myop.op_flags = OPf_WANT_VOID; |
1244 | myop.op_flags = OPf_WANT_VOID; |
1213 | |
1245 | |
1214 | PUSHMARK (SP); |
1246 | PUSHMARK (SP); |
1215 | PUSHs ((SV *)coro->startcv); |
1247 | XPUSHs ((SV *)coro->startcv); |
1216 | PUTBACK; |
1248 | PUTBACK; |
1217 | PL_op = (OP *)&myop; |
1249 | PL_op = (OP *)&myop; |
1218 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
1250 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
1219 | } |
1251 | } |
1220 | |
1252 | |
… | |
… | |
1277 | |
1309 | |
1278 | assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack)); |
1310 | assert (("FATAL: tried to destroy currently running coroutine", coro->mainstack != PL_mainstack)); |
1279 | |
1311 | |
1280 | save_perl (aTHX_ current); |
1312 | save_perl (aTHX_ current); |
1281 | |
1313 | |
1282 | /* this will cause transfer_check to croak on block*/ |
1314 | /* this will cause transfer_check to croak on block */ |
1283 | SvRV_set (coro_current, (SV *)coro->hv); |
1315 | SvRV_set (coro_current, (SV *)coro->hv); |
1284 | |
1316 | |
1285 | load_perl (aTHX_ coro); |
1317 | load_perl (aTHX_ coro); |
1286 | |
1318 | |
1287 | /* restore swapped sv's */ |
1319 | /* restore swapped sv's */ |
… | |
… | |
1368 | av_push (av, SvREFCNT_inc_NN (*bot++)); |
1400 | av_push (av, SvREFCNT_inc_NN (*bot++)); |
1369 | |
1401 | |
1370 | PL_runops = RUNOPS_DEFAULT; |
1402 | PL_runops = RUNOPS_DEFAULT; |
1371 | ENTER; |
1403 | ENTER; |
1372 | SAVETMPS; |
1404 | SAVETMPS; |
|
|
1405 | PUSHMARK (SP); |
1373 | EXTEND (SP, 3); |
1406 | EXTEND (SP, 3); |
1374 | PUSHMARK (SP); |
|
|
1375 | PUSHs (&PL_sv_no); |
1407 | PUSHs (&PL_sv_no); |
1376 | PUSHs (fullname); |
1408 | PUSHs (fullname); |
1377 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1409 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1378 | PUTBACK; |
1410 | PUTBACK; |
1379 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1411 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
… | |
… | |
1406 | gv_efullname3 (fullname, gv, 0); |
1438 | gv_efullname3 (fullname, gv, 0); |
1407 | |
1439 | |
1408 | PL_runops = RUNOPS_DEFAULT; |
1440 | PL_runops = RUNOPS_DEFAULT; |
1409 | ENTER; |
1441 | ENTER; |
1410 | SAVETMPS; |
1442 | SAVETMPS; |
|
|
1443 | PUSHMARK (SP); |
1411 | EXTEND (SP, 3); |
1444 | EXTEND (SP, 3); |
1412 | PUSHMARK (SP); |
|
|
1413 | PUSHs (&PL_sv_yes); |
1445 | PUSHs (&PL_sv_yes); |
1414 | PUSHs (fullname); |
1446 | PUSHs (fullname); |
1415 | PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); |
1447 | PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc (SUB_ARGARRAY)) : &PL_sv_undef); |
1416 | PUTBACK; |
1448 | PUTBACK; |
1417 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1449 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1418 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1450 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1419 | SPAGAIN; |
1451 | SPAGAIN; |
1420 | FREETMPS; |
1452 | FREETMPS; |
… | |
… | |
1430 | dSP; |
1462 | dSP; |
1431 | |
1463 | |
1432 | PL_runops = RUNOPS_DEFAULT; |
1464 | PL_runops = RUNOPS_DEFAULT; |
1433 | ENTER; |
1465 | ENTER; |
1434 | SAVETMPS; |
1466 | SAVETMPS; |
1435 | EXTEND (SP, 3); |
|
|
1436 | PL_runops = RUNOPS_DEFAULT; |
|
|
1437 | PUSHMARK (SP); |
1467 | PUSHMARK (SP); |
|
|
1468 | EXTEND (SP, 2); |
1438 | PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); |
1469 | PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); |
1439 | PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); |
1470 | PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); |
1440 | PUTBACK; |
1471 | PUTBACK; |
1441 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); |
1472 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); |
1442 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1473 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
… | |
… | |
1813 | |
1844 | |
1814 | static int |
1845 | static int |
1815 | coro_state_free (pTHX_ SV *sv, MAGIC *mg) |
1846 | coro_state_free (pTHX_ SV *sv, MAGIC *mg) |
1816 | { |
1847 | { |
1817 | struct coro *coro = (struct coro *)mg->mg_ptr; |
1848 | struct coro *coro = (struct coro *)mg->mg_ptr; |
|
|
1849 | |
|
|
1850 | coro_state_destroy (aTHX_ coro); |
1818 | mg->mg_ptr = 0; |
1851 | mg->mg_ptr = 0; |
1819 | |
1852 | |
1820 | coro_state_destroy (aTHX_ coro); |
|
|
1821 | SvREFCNT_dec (coro->on_destroy); |
1853 | SvREFCNT_dec (coro->on_destroy); |
1822 | SvREFCNT_dec (coro->status); |
1854 | SvREFCNT_dec (coro->status); |
1823 | |
1855 | |
1824 | Safefree (coro); |
1856 | Safefree (coro); |
1825 | |
1857 | |
… | |
… | |
1828 | |
1860 | |
1829 | static int ecb_cold |
1861 | static int ecb_cold |
1830 | coro_state_dup (pTHX_ MAGIC *mg, CLONE_PARAMS *params) |
1862 | coro_state_dup (pTHX_ MAGIC *mg, CLONE_PARAMS *params) |
1831 | { |
1863 | { |
1832 | /* called when perl clones the current process the slow way (windows process emulation) */ |
1864 | /* called when perl clones the current process the slow way (windows process emulation) */ |
1833 | /* WE SIMply nuke the pointers in the copy, causing perl to croak */ |
1865 | /* we simply nuke the pointers in the copy, causing perl to croak */ |
1834 | mg->mg_ptr = 0; |
1866 | mg->mg_ptr = 0; |
1835 | mg->mg_virtual = 0; |
1867 | mg->mg_virtual = 0; |
1836 | |
1868 | |
1837 | return 0; |
1869 | return 0; |
1838 | } |
1870 | } |
… | |
… | |
2360 | safe_cancel (pTHX_ struct coro *coro, SV **arg, int items) |
2392 | safe_cancel (pTHX_ struct coro *coro, SV **arg, int items) |
2361 | { |
2393 | { |
2362 | if (coro->cctx) |
2394 | if (coro->cctx) |
2363 | croak ("coro inside C callback, unable to cancel at this time, caught"); |
2395 | croak ("coro inside C callback, unable to cancel at this time, caught"); |
2364 | |
2396 | |
2365 | if (coro->flags & CF_NEW) |
2397 | if (coro->flags & (CF_NEW | CF_ZOMBIE)) |
2366 | { |
2398 | { |
2367 | coro_set_status (aTHX_ coro, arg, items); |
2399 | coro_set_status (aTHX_ coro, arg, items); |
2368 | coro_state_destroy (aTHX_ coro); |
2400 | coro_state_destroy (aTHX_ coro); |
2369 | } |
2401 | } |
2370 | else |
2402 | else |
… | |
… | |
2450 | |
2482 | |
2451 | if (ecb_expect_false (coro->cctx) && ecb_expect_false (coro->cctx->flags & CC_TRACE)) |
2483 | if (ecb_expect_false (coro->cctx) && ecb_expect_false (coro->cctx->flags & CC_TRACE)) |
2452 | api_trace (aTHX_ coro_current, 0); |
2484 | api_trace (aTHX_ coro_current, 0); |
2453 | |
2485 | |
2454 | frame->prepare = prepare_schedule; |
2486 | frame->prepare = prepare_schedule; |
2455 | av_push (av_async_pool, SvREFCNT_inc (hv)); |
2487 | av_push (av_async_pool, SvREFCNT_inc_NN (hv)); |
2456 | } |
2488 | } |
2457 | } |
2489 | } |
2458 | else |
2490 | else |
2459 | { |
2491 | { |
2460 | /* first iteration, simply fall through */ |
2492 | /* first iteration, simply fall through */ |
… | |
… | |
2473 | static void |
2505 | static void |
2474 | coro_rouse_callback (pTHX_ CV *cv) |
2506 | coro_rouse_callback (pTHX_ CV *cv) |
2475 | { |
2507 | { |
2476 | dXSARGS; |
2508 | dXSARGS; |
2477 | SV *data = (SV *)S_GENSUB_ARG; |
2509 | SV *data = (SV *)S_GENSUB_ARG; |
|
|
2510 | SV *coro = SvRV (data); |
2478 | |
2511 | |
|
|
2512 | /* data starts being either undef or a coro, and is replaced by the results when done */ |
2479 | if (SvTYPE (SvRV (data)) != SVt_PVAV) |
2513 | if (SvTYPE (coro) != SVt_PVAV) |
2480 | { |
2514 | { |
2481 | /* first call, set args */ |
2515 | /* first call, set args */ |
2482 | SV *coro = SvRV (data); |
|
|
2483 | AV *av = newAV (); |
|
|
2484 | |
2516 | |
2485 | SvRV_set (data, (SV *)av); |
2517 | assert (&ST (0) < &ST (1)); /* ensure the stack is in the order we expect it to be */ |
|
|
2518 | SvRV_set (data, (SV *)av_make (items, &ST (0))); /* av_make copies the SVs */ |
2486 | |
2519 | |
2487 | /* better take a full copy of the arguments */ |
2520 | if (coro != &PL_sv_undef) |
2488 | while (items--) |
2521 | { |
2489 | av_store (av, items, newSVsv (ST (items))); |
|
|
2490 | |
|
|
2491 | api_ready (aTHX_ coro); |
2522 | api_ready (aTHX_ coro); |
2492 | SvREFCNT_dec (coro); |
2523 | SvREFCNT_dec_NN (coro); |
|
|
2524 | } |
2493 | } |
2525 | } |
2494 | |
2526 | |
2495 | XSRETURN_EMPTY; |
2527 | XSRETURN_EMPTY; |
2496 | } |
2528 | } |
2497 | |
2529 | |
… | |
… | |
2514 | |
2546 | |
2515 | EXTEND (SP, AvFILLp (av) + 1); |
2547 | EXTEND (SP, AvFILLp (av) + 1); |
2516 | for (i = 0; i <= AvFILLp (av); ++i) |
2548 | for (i = 0; i <= AvFILLp (av); ++i) |
2517 | PUSHs (sv_2mortal (AvARRAY (av)[i])); |
2549 | PUSHs (sv_2mortal (AvARRAY (av)[i])); |
2518 | |
2550 | |
2519 | /* we have stolen the elements, so set length to zero and free */ |
2551 | /* we have stolen the elements, make it unreal and free */ |
2520 | AvFILLp (av) = -1; |
2552 | AvREAL_off (av); |
2521 | av_undef (av); |
2553 | av_undef (av); |
2522 | |
2554 | |
2523 | PUTBACK; |
2555 | PUTBACK; |
2524 | } |
2556 | } |
2525 | |
2557 | |
… | |
… | |
2550 | croak ("Coro::rouse_wait called with illegal callback argument,"); |
2582 | croak ("Coro::rouse_wait called with illegal callback argument,"); |
2551 | |
2583 | |
2552 | { |
2584 | { |
2553 | CV *cv = (CV *)SvRV (cb); /* for S_GENSUB_ARG */ |
2585 | CV *cv = (CV *)SvRV (cb); /* for S_GENSUB_ARG */ |
2554 | SV *data = (SV *)S_GENSUB_ARG; |
2586 | SV *data = (SV *)S_GENSUB_ARG; |
|
|
2587 | int data_ready = SvTYPE (SvRV (data)) == SVt_PVAV; |
|
|
2588 | |
|
|
2589 | /* if there is no data, we need to store the current coro in the reference so we can be woken up */ |
|
|
2590 | if (!data_ready) |
|
|
2591 | if (SvRV (data) != &PL_sv_undef) |
|
|
2592 | croak ("Coro::rouse_wait was called on a calback that is already being waited for - only one thread can wait for a rouse callback, caught"); |
|
|
2593 | else |
|
|
2594 | SvRV_set (data, SvREFCNT_inc_NN (SvRV (coro_current))); |
2555 | |
2595 | |
2556 | frame->data = (void *)data; |
2596 | frame->data = (void *)data; |
2557 | frame->prepare = SvTYPE (SvRV (data)) == SVt_PVAV ? prepare_nop : prepare_schedule; |
2597 | frame->prepare = data_ready ? prepare_nop : prepare_schedule; |
2558 | frame->check = slf_check_rouse_wait; |
2598 | frame->check = slf_check_rouse_wait; |
2559 | } |
2599 | } |
2560 | } |
2600 | } |
2561 | |
2601 | |
2562 | static SV * |
2602 | static SV * |
2563 | coro_new_rouse_cb (pTHX) |
2603 | coro_new_rouse_cb (pTHX) |
2564 | { |
2604 | { |
2565 | HV *hv = (HV *)SvRV (coro_current); |
2605 | HV *hv = (HV *)SvRV (coro_current); |
2566 | struct coro *coro = SvSTATE_hv (hv); |
2606 | struct coro *coro = SvSTATE_hv (hv); |
2567 | SV *data = newRV_inc ((SV *)hv); |
2607 | SV *data = newRV_noinc (&PL_sv_undef); |
2568 | SV *cb = s_gensub (aTHX_ coro_rouse_callback, (void *)data); |
2608 | SV *cb = s_gensub (aTHX_ coro_rouse_callback, (void *)data); |
2569 | |
2609 | |
2570 | sv_magicext (SvRV (cb), data, CORO_MAGIC_type_rouse, 0, 0, 0); |
2610 | sv_magicext (SvRV (cb), data, CORO_MAGIC_type_rouse, 0, 0, 0); |
2571 | SvREFCNT_dec (data); /* magicext increases the refcount */ |
2611 | SvREFCNT_dec_NN (data); /* magicext increases the refcount */ |
2572 | |
2612 | |
2573 | SvREFCNT_dec (coro->rouse_cb); |
2613 | SvREFCNT_dec (coro->rouse_cb); |
2574 | coro->rouse_cb = SvREFCNT_inc_NN (cb); |
2614 | coro->rouse_cb = SvREFCNT_inc_NN (cb); |
2575 | |
2615 | |
2576 | return cb; |
2616 | return cb; |
… | |
… | |
3583 | save = POPs; save_ptr = SvPVbyte (save, save_len); |
3623 | save = POPs; save_ptr = SvPVbyte (save, save_len); |
3584 | load = POPs; load_ptr = SvPVbyte (load, load_len); |
3624 | load = POPs; load_ptr = SvPVbyte (load, load_len); |
3585 | |
3625 | |
3586 | map_len = load_len + save_len + 16; |
3626 | map_len = load_len + save_len + 16; |
3587 | |
3627 | |
3588 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
|
|
3589 | |
|
|
3590 | if (map_base == (char *)MAP_FAILED) |
|
|
3591 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
3628 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
3592 | |
3629 | |
3593 | assert (("Coro: unable to mmap jit code page, cannot continue.", map_base != (char *)MAP_FAILED)); |
3630 | assert (("Coro: unable to mmap jit code page, cannot continue.", map_base != (char *)MAP_FAILED)); |
3594 | |
3631 | |
3595 | load_perl_slots = (load_save_perl_slots_type)map_base; |
3632 | load_perl_slots = (load_save_perl_slots_type)map_base; |
3596 | memcpy (map_base, load_ptr, load_len); |
3633 | memcpy (load_perl_slots, load_ptr, load_len); |
3597 | |
3634 | |
3598 | map_base += (load_len + 15) & ~15; |
|
|
3599 | |
|
|
3600 | save_perl_slots = (load_save_perl_slots_type)map_base; |
3635 | save_perl_slots = (load_save_perl_slots_type)(map_base + ((load_len + 15) & ~15)); |
3601 | memcpy (map_base, save_ptr, save_len); |
3636 | memcpy (save_perl_slots, save_ptr, save_len); |
3602 | |
3637 | |
3603 | /* we are good citizens and try to make the page read-only, so the evil evil */ |
3638 | /* we are good citizens and try to make the page read-only, so the evil evil */ |
3604 | /* hackers might have it a bit more difficult */ |
3639 | /* hackers might have it a bit more difficult */ |
|
|
3640 | /* we do this in two steps, to potentially appease some security frameworks */ |
|
|
3641 | mprotect (map_base, map_len, PROT_READ); |
3605 | mprotect (map_base, map_len, PROT_READ | PROT_EXEC); |
3642 | mprotect (map_base, map_len, PROT_READ | PROT_EXEC); |
3606 | |
3643 | |
3607 | PUTBACK; |
3644 | PUTBACK; |
3608 | eval_pv ("undef &Coro::State::_jit", 1); |
3645 | eval_pv ("undef &Coro::State::_jit", 1); |
3609 | } |
3646 | } |
… | |
… | |
3663 | rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); |
3700 | rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); |
3664 | rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); |
3701 | rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); |
3665 | |
3702 | |
3666 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
3703 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
3667 | |
3704 | |
|
|
3705 | newCONSTSUB (coro_state_stash, "BACKEND", newSVpv (CORO_BACKEND, 0)); /* undocumented */ |
|
|
3706 | |
3668 | newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); |
3707 | newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); |
3669 | newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); |
3708 | newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); |
3670 | newCONSTSUB (coro_state_stash, "CC_TRACE_LINE", newSViv (CC_TRACE_LINE)); |
3709 | newCONSTSUB (coro_state_stash, "CC_TRACE_LINE", newSViv (CC_TRACE_LINE)); |
3671 | newCONSTSUB (coro_state_stash, "CC_TRACE_ALL" , newSViv (CC_TRACE_ALL)); |
3710 | newCONSTSUB (coro_state_stash, "CC_TRACE_ALL" , newSViv (CC_TRACE_ALL)); |
3672 | |
3711 | |
… | |
… | |
3796 | call (Coro::State coro, SV *coderef) |
3835 | call (Coro::State coro, SV *coderef) |
3797 | ALIAS: |
3836 | ALIAS: |
3798 | eval = 1 |
3837 | eval = 1 |
3799 | CODE: |
3838 | CODE: |
3800 | { |
3839 | { |
|
|
3840 | struct coro *current = SvSTATE_current; |
|
|
3841 | |
3801 | if (coro->mainstack && ((coro->flags & CF_RUNNING) || coro->slot)) |
3842 | if ((coro == current) || (coro->mainstack && ((coro->flags & CF_RUNNING) || coro->slot))) |
3802 | { |
3843 | { |
3803 | struct coro *current = SvSTATE_current; |
|
|
3804 | struct CoroSLF slf_save; |
3844 | struct CoroSLF slf_save; |
3805 | |
3845 | |
3806 | if (current != coro) |
3846 | if (current != coro) |
3807 | { |
3847 | { |
3808 | PUTBACK; |
3848 | PUTBACK; |
… | |
… | |
4067 | coroapi.enterleave_hook = api_enterleave_hook; |
4107 | coroapi.enterleave_hook = api_enterleave_hook; |
4068 | coroapi.enterleave_unhook = api_enterleave_unhook; |
4108 | coroapi.enterleave_unhook = api_enterleave_unhook; |
4069 | coroapi.enterleave_scope_hook = api_enterleave_scope_hook; |
4109 | coroapi.enterleave_scope_hook = api_enterleave_scope_hook; |
4070 | |
4110 | |
4071 | /*GCoroAPI = &coroapi;*/ |
4111 | /*GCoroAPI = &coroapi;*/ |
4072 | sv_setiv (sv, (IV)&coroapi); |
4112 | sv_setiv (sv, PTR2IV (&coroapi)); |
4073 | SvREADONLY_on (sv); |
4113 | SvREADONLY_on (sv); |
4074 | } |
4114 | } |
4075 | } |
4115 | } |
4076 | |
4116 | |
4077 | SV * |
4117 | SV * |