ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/State.xs
(Generate patch)

Comparing Coro/Coro/State.xs (file contents):
Revision 1.471 by root, Fri Jul 14 23:20:07 2017 UTC vs.
Revision 1.477 by root, Sat Feb 29 21:40:22 2020 UTC

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"
1222 myop.op_next = Nullop; 1242 myop.op_next = Nullop;
1223 myop.op_type = OP_ENTERSUB; 1243 myop.op_type = OP_ENTERSUB;
1224 myop.op_flags = OPf_WANT_VOID; 1244 myop.op_flags = OPf_WANT_VOID;
1225 1245
1226 PUSHMARK (SP); 1246 PUSHMARK (SP);
1227 PUSHs ((SV *)coro->startcv); 1247 XPUSHs ((SV *)coro->startcv);
1228 PUTBACK; 1248 PUTBACK;
1229 PL_op = (OP *)&myop; 1249 PL_op = (OP *)&myop;
1230 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); 1250 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
1231 } 1251 }
1232 1252
1380 av_push (av, SvREFCNT_inc_NN (*bot++)); 1400 av_push (av, SvREFCNT_inc_NN (*bot++));
1381 1401
1382 PL_runops = RUNOPS_DEFAULT; 1402 PL_runops = RUNOPS_DEFAULT;
1383 ENTER; 1403 ENTER;
1384 SAVETMPS; 1404 SAVETMPS;
1405 PUSHMARK (SP);
1385 EXTEND (SP, 3); 1406 EXTEND (SP, 3);
1386 PUSHMARK (SP);
1387 PUSHs (&PL_sv_no); 1407 PUSHs (&PL_sv_no);
1388 PUSHs (fullname); 1408 PUSHs (fullname);
1389 PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); 1409 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
1390 PUTBACK; 1410 PUTBACK;
1391 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);
1418 gv_efullname3 (fullname, gv, 0); 1438 gv_efullname3 (fullname, gv, 0);
1419 1439
1420 PL_runops = RUNOPS_DEFAULT; 1440 PL_runops = RUNOPS_DEFAULT;
1421 ENTER; 1441 ENTER;
1422 SAVETMPS; 1442 SAVETMPS;
1443 PUSHMARK (SP);
1423 EXTEND (SP, 3); 1444 EXTEND (SP, 3);
1424 PUSHMARK (SP);
1425 PUSHs (&PL_sv_yes); 1445 PUSHs (&PL_sv_yes);
1426 PUSHs (fullname); 1446 PUSHs (fullname);
1427 PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc (SUB_ARGARRAY)) : &PL_sv_undef); 1447 PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc (SUB_ARGARRAY)) : &PL_sv_undef);
1428 PUTBACK; 1448 PUTBACK;
1429 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);
1442 dSP; 1462 dSP;
1443 1463
1444 PL_runops = RUNOPS_DEFAULT; 1464 PL_runops = RUNOPS_DEFAULT;
1445 ENTER; 1465 ENTER;
1446 SAVETMPS; 1466 SAVETMPS;
1447 EXTEND (SP, 3);
1448 PL_runops = RUNOPS_DEFAULT;
1449 PUSHMARK (SP); 1467 PUSHMARK (SP);
1468 EXTEND (SP, 2);
1450 PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); 1469 PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0)));
1451 PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); 1470 PUSHs (sv_2mortal (newSViv (CopLINE (oldcop))));
1452 PUTBACK; 1471 PUTBACK;
1453 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);
1454 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);
1840 1859
1841static int ecb_cold 1860static int ecb_cold
1842coro_state_dup (pTHX_ MAGIC *mg, CLONE_PARAMS *params) 1861coro_state_dup (pTHX_ MAGIC *mg, CLONE_PARAMS *params)
1843{ 1862{
1844 /* called when perl clones the current process the slow way (windows process emulation) */ 1863 /* called when perl clones the current process the slow way (windows process emulation) */
1845 /* WE SIMply nuke the pointers in the copy, causing perl to croak */ 1864 /* we simply nuke the pointers in the copy, causing perl to croak */
1846 mg->mg_ptr = 0; 1865 mg->mg_ptr = 0;
1847 mg->mg_virtual = 0; 1866 mg->mg_virtual = 0;
1848 1867
1849 return 0; 1868 return 0;
1850} 1869}
2372safe_cancel (pTHX_ struct coro *coro, SV **arg, int items) 2391safe_cancel (pTHX_ struct coro *coro, SV **arg, int items)
2373{ 2392{
2374 if (coro->cctx) 2393 if (coro->cctx)
2375 croak ("coro inside C callback, unable to cancel at this time, caught"); 2394 croak ("coro inside C callback, unable to cancel at this time, caught");
2376 2395
2377 if (coro->flags & CF_NEW) 2396 if (coro->flags & (CF_NEW | CF_ZOMBIE))
2378 { 2397 {
2379 coro_set_status (aTHX_ coro, arg, items); 2398 coro_set_status (aTHX_ coro, arg, items);
2380 coro_state_destroy (aTHX_ coro); 2399 coro_state_destroy (aTHX_ coro);
2381 } 2400 }
2382 else 2401 else
2462 2481
2463 if (ecb_expect_false (coro->cctx) && ecb_expect_false (coro->cctx->flags & CC_TRACE)) 2482 if (ecb_expect_false (coro->cctx) && ecb_expect_false (coro->cctx->flags & CC_TRACE))
2464 api_trace (aTHX_ coro_current, 0); 2483 api_trace (aTHX_ coro_current, 0);
2465 2484
2466 frame->prepare = prepare_schedule; 2485 frame->prepare = prepare_schedule;
2467 av_push (av_async_pool, SvREFCNT_inc (hv)); 2486 av_push (av_async_pool, SvREFCNT_inc_NN (hv));
2468 } 2487 }
2469 } 2488 }
2470 else 2489 else
2471 { 2490 {
2472 /* first iteration, simply fall through */ 2491 /* first iteration, simply fall through */
2486coro_rouse_callback (pTHX_ CV *cv) 2505coro_rouse_callback (pTHX_ CV *cv)
2487{ 2506{
2488 dXSARGS; 2507 dXSARGS;
2489 SV *data = (SV *)S_GENSUB_ARG; 2508 SV *data = (SV *)S_GENSUB_ARG;
2490 2509
2510 /* data starts being the coro, and is replaced by the results when done */
2491 if (SvTYPE (SvRV (data)) != SVt_PVAV) 2511 if (SvTYPE (SvRV (data)) != SVt_PVAV)
2492 { 2512 {
2493 /* first call, set args */ 2513 /* first call, set args */
2494 SV *coro = SvRV (data); 2514 SV *coro = SvRV (data);
2495 AV *av = newAV (); 2515 AV *av = newAV ();
2499 /* better take a full copy of the arguments */ 2519 /* better take a full copy of the arguments */
2500 while (items--) 2520 while (items--)
2501 av_store (av, items, newSVsv (ST (items))); 2521 av_store (av, items, newSVsv (ST (items)));
2502 2522
2503 api_ready (aTHX_ coro); 2523 api_ready (aTHX_ coro);
2504 SvREFCNT_dec (coro); 2524 SvREFCNT_dec_NN (coro);
2505 } 2525 }
2506 2526
2507 XSRETURN_EMPTY; 2527 XSRETURN_EMPTY;
2508} 2528}
2509 2529
2578 struct coro *coro = SvSTATE_hv (hv); 2598 struct coro *coro = SvSTATE_hv (hv);
2579 SV *data = newRV_inc ((SV *)hv); 2599 SV *data = newRV_inc ((SV *)hv);
2580 SV *cb = s_gensub (aTHX_ coro_rouse_callback, (void *)data); 2600 SV *cb = s_gensub (aTHX_ coro_rouse_callback, (void *)data);
2581 2601
2582 sv_magicext (SvRV (cb), data, CORO_MAGIC_type_rouse, 0, 0, 0); 2602 sv_magicext (SvRV (cb), data, CORO_MAGIC_type_rouse, 0, 0, 0);
2583 SvREFCNT_dec (data); /* magicext increases the refcount */ 2603 SvREFCNT_dec_NN (data); /* magicext increases the refcount */
2584 2604
2585 SvREFCNT_dec (coro->rouse_cb); 2605 SvREFCNT_dec (coro->rouse_cb);
2586 coro->rouse_cb = SvREFCNT_inc_NN (cb); 2606 coro->rouse_cb = SvREFCNT_inc_NN (cb);
2587 2607
2588 return cb; 2608 return cb;
3675 rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); 3695 rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV));
3676 rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); 3696 rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV));
3677 3697
3678 coro_state_stash = gv_stashpv ("Coro::State", TRUE); 3698 coro_state_stash = gv_stashpv ("Coro::State", TRUE);
3679 3699
3700 newCONSTSUB (coro_state_stash, "BACKEND", newSVpv (CORO_BACKEND, 0)); /* undocumented */
3701
3680 newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); 3702 newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE));
3681 newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); 3703 newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB));
3682 newCONSTSUB (coro_state_stash, "CC_TRACE_LINE", newSViv (CC_TRACE_LINE)); 3704 newCONSTSUB (coro_state_stash, "CC_TRACE_LINE", newSViv (CC_TRACE_LINE));
3683 newCONSTSUB (coro_state_stash, "CC_TRACE_ALL" , newSViv (CC_TRACE_ALL)); 3705 newCONSTSUB (coro_state_stash, "CC_TRACE_ALL" , newSViv (CC_TRACE_ALL));
3684 3706
3808call (Coro::State coro, SV *coderef) 3830call (Coro::State coro, SV *coderef)
3809 ALIAS: 3831 ALIAS:
3810 eval = 1 3832 eval = 1
3811 CODE: 3833 CODE:
3812{ 3834{
3835 struct coro *current = SvSTATE_current;
3836
3813 if (coro->mainstack && ((coro->flags & CF_RUNNING) || coro->slot)) 3837 if ((coro == current) || (coro->mainstack && ((coro->flags & CF_RUNNING) || coro->slot)))
3814 { 3838 {
3815 struct coro *current = SvSTATE_current;
3816 struct CoroSLF slf_save; 3839 struct CoroSLF slf_save;
3817 3840
3818 if (current != coro) 3841 if (current != coro)
3819 { 3842 {
3820 PUTBACK; 3843 PUTBACK;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines