… | |
… | |
116 | # define CORO_CLOCK_MONOTONIC 1 |
116 | # define CORO_CLOCK_MONOTONIC 1 |
117 | # define CORO_CLOCK_THREAD_CPUTIME_ID 3 |
117 | # define CORO_CLOCK_THREAD_CPUTIME_ID 3 |
118 | # endif |
118 | # endif |
119 | #endif |
119 | #endif |
120 | |
120 | |
|
|
121 | /* one off bugfix for perl 5.22 */ |
|
|
122 | #if PERL_VERSION_ATLEAST(5,22,0) && !PERL_VERSION_ATLEAST(5,24,0) |
|
|
123 | # undef PadlistNAMES |
|
|
124 | # define PadlistNAMES(pl) *((PADNAMELIST **)PadlistARRAY (pl)) |
|
|
125 | #endif |
|
|
126 | |
|
|
127 | #if PERL_VERSION_ATLEAST(5,24,0) |
|
|
128 | # define SUB_ARGARRAY PL_curpad[0] |
|
|
129 | #else |
|
|
130 | # define SUB_ARGARRAY (SV *)cx->blk_sub.argarray |
|
|
131 | #endif |
|
|
132 | |
121 | /* perl usually suppressed asserts. for debugging, we sometimes force it to be on */ |
133 | /* perl usually suppresses asserts. for debugging, we sometimes force it to be on */ |
122 | #if 0 |
134 | #if 0 |
123 | # undef NDEBUG |
135 | # undef NDEBUG |
124 | # include <assert.h> |
136 | # include <assert.h> |
125 | #endif |
137 | #endif |
126 | |
138 | |
… | |
… | |
969 | #endif |
981 | #endif |
970 | |
982 | |
971 | New(54,PL_savestack,24,ANY); |
983 | New(54,PL_savestack,24,ANY); |
972 | PL_savestack_ix = 0; |
984 | PL_savestack_ix = 0; |
973 | PL_savestack_max = 24; |
985 | PL_savestack_max = 24; |
974 | #if !PERL_VERSION_ATLEAST (5,24,0) |
986 | #if PERL_VERSION_ATLEAST (5,24,0) |
975 | /* perl 5.24 moves SS_MAXPUSH optimisation from */ |
987 | /* perl 5.24 moves SS_MAXPUSH optimisation from */ |
976 | /* the header macros to PL_savestack_max */ |
988 | /* the header macros to PL_savestack_max */ |
977 | PL_savestack_max -= SS_MAXPUSH; |
989 | PL_savestack_max -= SS_MAXPUSH; |
978 | #endif |
990 | #endif |
979 | |
991 | |
… | |
… | |
1064 | static MGVTBL coro_sigelem_vtbl; |
1076 | static MGVTBL coro_sigelem_vtbl; |
1065 | |
1077 | |
1066 | static int ecb_cold |
1078 | static int ecb_cold |
1067 | coro_sig_copy (pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *name, I32 namlen) |
1079 | coro_sig_copy (pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *name, I32 namlen) |
1068 | { |
1080 | { |
|
|
1081 | char *key = SvPV_nolen ((SV *)name); |
|
|
1082 | |
|
|
1083 | /* do what mg_copy normally does */ |
1069 | sv_magic (nsv, mg->mg_obj, PERL_MAGIC_sigelem, name, namlen); |
1084 | sv_magic (nsv, mg->mg_obj, PERL_MAGIC_sigelem, name, namlen); |
1070 | assert (mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual == &PL_vtbl_sigelem); |
1085 | assert (mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual == &PL_vtbl_sigelem); |
|
|
1086 | |
|
|
1087 | /* patch sigelem vtbl, but only for __WARN__ and __DIE__ */ |
|
|
1088 | if (*key == '_' |
|
|
1089 | && (strEQ (key, "__DIE__") |
|
|
1090 | || strEQ (key, "__WARN__"))) |
1071 | mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual = &coro_sigelem_vtbl; |
1091 | mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual = &coro_sigelem_vtbl; |
|
|
1092 | |
1072 | return 1; |
1093 | return 1; |
1073 | } |
1094 | } |
1074 | |
1095 | |
1075 | /* perl does not have a %SIG vtbl, we provide one so we can override */ |
1096 | /* perl does not have a %SIG vtbl, we provide one so we can override */ |
1076 | /* the cwvtblagic for %SIG members */ |
1097 | /* the magic vtbl for the __DIE__ and __WARN__ members */ |
1077 | static const MGVTBL coro_sig_vtbl = { |
1098 | static const MGVTBL coro_sig_vtbl = { |
1078 | 0, 0, 0, 0, 0, |
1099 | 0, 0, 0, 0, 0, |
1079 | coro_sig_copy |
1100 | coro_sig_copy |
1080 | }; |
1101 | }; |
1081 | |
1102 | |
… | |
… | |
1087 | */ |
1108 | */ |
1088 | static int ecb_cold |
1109 | static int ecb_cold |
1089 | coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) |
1110 | coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) |
1090 | { |
1111 | { |
1091 | const char *s = MgPV_nolen_const (mg); |
1112 | const char *s = MgPV_nolen_const (mg); |
|
|
1113 | /* the key must be either __DIE__ or __WARN__ here */ |
|
|
1114 | SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook; |
1092 | |
1115 | |
1093 | if (*s == '_') |
1116 | SV *ssv; |
1094 | { |
|
|
1095 | SV **svp = 0; |
|
|
1096 | |
1117 | |
1097 | if (strEQ (s, "__DIE__" )) svp = &PL_diehook; |
|
|
1098 | if (strEQ (s, "__WARN__")) svp = &PL_warnhook; |
|
|
1099 | |
|
|
1100 | if (svp) |
1118 | if (!*svp) |
1101 | { |
|
|
1102 | SV *ssv; |
|
|
1103 | |
|
|
1104 | if (!*svp) |
|
|
1105 | ssv = &PL_sv_undef; |
1119 | ssv = &PL_sv_undef; |
1106 | else if (SvTYPE (*svp) == SVt_PVCV) /* perlio directly stores a CV in warnhook. ugh. */ |
1120 | else if (SvTYPE (*svp) == SVt_PVCV) /* perlio directly stores a CV in warnhook. ugh. */ |
1107 | ssv = sv_2mortal (newRV_inc (*svp)); |
1121 | ssv = sv_2mortal (newRV_inc (*svp)); |
1108 | else |
1122 | else |
1109 | ssv = *svp; |
1123 | ssv = *svp; |
1110 | |
1124 | |
1111 | sv_setsv (sv, ssv); |
1125 | sv_setsv (sv, ssv); |
1112 | return 0; |
1126 | return 0; |
1113 | } |
|
|
1114 | } |
|
|
1115 | |
|
|
1116 | return PL_vtbl_sigelem.svt_get ? PL_vtbl_sigelem.svt_get (aTHX_ sv, mg) : 0; |
|
|
1117 | } |
1127 | } |
1118 | |
1128 | |
1119 | static int ecb_cold |
1129 | static int ecb_cold |
1120 | coro_sigelem_clr (pTHX_ SV *sv, MAGIC *mg) |
1130 | coro_sigelem_clr (pTHX_ SV *sv, MAGIC *mg) |
1121 | { |
1131 | { |
1122 | const char *s = MgPV_nolen_const (mg); |
1132 | const char *s = MgPV_nolen_const (mg); |
|
|
1133 | /* the key must be either __DIE__ or __WARN__ here */ |
|
|
1134 | SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook; |
1123 | |
1135 | |
1124 | if (*s == '_') |
|
|
1125 | { |
|
|
1126 | SV **svp = 0; |
|
|
1127 | |
|
|
1128 | if (strEQ (s, "__DIE__" )) svp = &PL_diehook; |
|
|
1129 | if (strEQ (s, "__WARN__")) svp = &PL_warnhook; |
|
|
1130 | |
|
|
1131 | if (svp) |
|
|
1132 | { |
|
|
1133 | SV *old = *svp; |
1136 | SV *old = *svp; |
1134 | *svp = 0; |
1137 | *svp = 0; |
1135 | SvREFCNT_dec (old); |
1138 | SvREFCNT_dec (old); |
1136 | return 0; |
1139 | return 0; |
1137 | } |
|
|
1138 | } |
|
|
1139 | |
|
|
1140 | return PL_vtbl_sigelem.svt_clear ? PL_vtbl_sigelem.svt_clear (aTHX_ sv, mg) : 0; |
|
|
1141 | } |
1140 | } |
1142 | |
1141 | |
1143 | static int ecb_cold |
1142 | static int ecb_cold |
1144 | coro_sigelem_set (pTHX_ SV *sv, MAGIC *mg) |
1143 | coro_sigelem_set (pTHX_ SV *sv, MAGIC *mg) |
1145 | { |
1144 | { |
1146 | const char *s = MgPV_nolen_const (mg); |
1145 | const char *s = MgPV_nolen_const (mg); |
|
|
1146 | /* the key must be either __DIE__ or __WARN__ here */ |
|
|
1147 | SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook; |
1147 | |
1148 | |
1148 | if (*s == '_') |
|
|
1149 | { |
|
|
1150 | SV **svp = 0; |
|
|
1151 | |
|
|
1152 | if (strEQ (s, "__DIE__" )) svp = &PL_diehook; |
|
|
1153 | if (strEQ (s, "__WARN__")) svp = &PL_warnhook; |
|
|
1154 | |
|
|
1155 | if (svp) |
|
|
1156 | { |
|
|
1157 | SV *old = *svp; |
1149 | SV *old = *svp; |
1158 | *svp = SvOK (sv) ? newSVsv (sv) : 0; |
1150 | *svp = SvOK (sv) ? newSVsv (sv) : 0; |
1159 | SvREFCNT_dec (old); |
1151 | SvREFCNT_dec (old); |
1160 | return 0; |
1152 | return 0; |
1161 | } |
|
|
1162 | } |
|
|
1163 | |
|
|
1164 | return PL_vtbl_sigelem.svt_set ? PL_vtbl_sigelem.svt_set (aTHX_ sv, mg) : 0; |
|
|
1165 | } |
1153 | } |
1166 | |
1154 | |
1167 | static void |
1155 | static void |
1168 | prepare_nop (pTHX_ struct coro_transfer_args *ta) |
1156 | prepare_nop (pTHX_ struct coro_transfer_args *ta) |
1169 | { |
1157 | { |
… | |
… | |
1234 | myop.op_next = Nullop; |
1222 | myop.op_next = Nullop; |
1235 | myop.op_type = OP_ENTERSUB; |
1223 | myop.op_type = OP_ENTERSUB; |
1236 | myop.op_flags = OPf_WANT_VOID; |
1224 | myop.op_flags = OPf_WANT_VOID; |
1237 | |
1225 | |
1238 | PUSHMARK (SP); |
1226 | PUSHMARK (SP); |
1239 | PUSHs ((SV *)coro->startcv); |
1227 | XPUSHs ((SV *)coro->startcv); |
1240 | PUTBACK; |
1228 | PUTBACK; |
1241 | PL_op = (OP *)&myop; |
1229 | PL_op = (OP *)&myop; |
1242 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
1230 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
1243 | } |
1231 | } |
1244 | |
1232 | |
… | |
… | |
1392 | av_push (av, SvREFCNT_inc_NN (*bot++)); |
1380 | av_push (av, SvREFCNT_inc_NN (*bot++)); |
1393 | |
1381 | |
1394 | PL_runops = RUNOPS_DEFAULT; |
1382 | PL_runops = RUNOPS_DEFAULT; |
1395 | ENTER; |
1383 | ENTER; |
1396 | SAVETMPS; |
1384 | SAVETMPS; |
|
|
1385 | PUSHMARK (SP); |
1397 | EXTEND (SP, 3); |
1386 | EXTEND (SP, 3); |
1398 | PUSHMARK (SP); |
|
|
1399 | PUSHs (&PL_sv_no); |
1387 | PUSHs (&PL_sv_no); |
1400 | PUSHs (fullname); |
1388 | PUSHs (fullname); |
1401 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1389 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1402 | PUTBACK; |
1390 | PUTBACK; |
1403 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1391 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
… | |
… | |
1430 | gv_efullname3 (fullname, gv, 0); |
1418 | gv_efullname3 (fullname, gv, 0); |
1431 | |
1419 | |
1432 | PL_runops = RUNOPS_DEFAULT; |
1420 | PL_runops = RUNOPS_DEFAULT; |
1433 | ENTER; |
1421 | ENTER; |
1434 | SAVETMPS; |
1422 | SAVETMPS; |
|
|
1423 | PUSHMARK (SP); |
1435 | EXTEND (SP, 3); |
1424 | EXTEND (SP, 3); |
1436 | PUSHMARK (SP); |
|
|
1437 | PUSHs (&PL_sv_yes); |
1425 | PUSHs (&PL_sv_yes); |
1438 | PUSHs (fullname); |
1426 | PUSHs (fullname); |
1439 | PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); |
1427 | PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc (SUB_ARGARRAY)) : &PL_sv_undef); |
1440 | PUTBACK; |
1428 | PUTBACK; |
1441 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1429 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1442 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1430 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1443 | SPAGAIN; |
1431 | SPAGAIN; |
1444 | FREETMPS; |
1432 | FREETMPS; |
… | |
… | |
1454 | dSP; |
1442 | dSP; |
1455 | |
1443 | |
1456 | PL_runops = RUNOPS_DEFAULT; |
1444 | PL_runops = RUNOPS_DEFAULT; |
1457 | ENTER; |
1445 | ENTER; |
1458 | SAVETMPS; |
1446 | SAVETMPS; |
1459 | EXTEND (SP, 3); |
|
|
1460 | PL_runops = RUNOPS_DEFAULT; |
|
|
1461 | PUSHMARK (SP); |
1447 | PUSHMARK (SP); |
|
|
1448 | EXTEND (SP, 2); |
1462 | PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); |
1449 | PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); |
1463 | PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); |
1450 | PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); |
1464 | PUTBACK; |
1451 | PUTBACK; |
1465 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); |
1452 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); |
1466 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1453 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
… | |
… | |
2384 | safe_cancel (pTHX_ struct coro *coro, SV **arg, int items) |
2371 | safe_cancel (pTHX_ struct coro *coro, SV **arg, int items) |
2385 | { |
2372 | { |
2386 | if (coro->cctx) |
2373 | if (coro->cctx) |
2387 | croak ("coro inside C callback, unable to cancel at this time, caught"); |
2374 | croak ("coro inside C callback, unable to cancel at this time, caught"); |
2388 | |
2375 | |
2389 | if (coro->flags & CF_NEW) |
2376 | if (coro->flags & (CF_NEW | CF_ZOMBIE)) |
2390 | { |
2377 | { |
2391 | coro_set_status (aTHX_ coro, arg, items); |
2378 | coro_set_status (aTHX_ coro, arg, items); |
2392 | coro_state_destroy (aTHX_ coro); |
2379 | coro_state_destroy (aTHX_ coro); |
2393 | } |
2380 | } |
2394 | else |
2381 | else |
… | |
… | |
2463 | av_clear (GvAV (PL_defgv)); |
2450 | av_clear (GvAV (PL_defgv)); |
2464 | hv_store (hv, "desc", sizeof ("desc") - 1, SvREFCNT_inc_NN (sv_async_pool_idle), 0); |
2451 | hv_store (hv, "desc", sizeof ("desc") - 1, SvREFCNT_inc_NN (sv_async_pool_idle), 0); |
2465 | |
2452 | |
2466 | if (ecb_expect_false (coro->swap_sv)) |
2453 | if (ecb_expect_false (coro->swap_sv)) |
2467 | { |
2454 | { |
2468 | swap_svs_leave (coro); |
2455 | SWAP_SVS_LEAVE (coro); |
2469 | SvREFCNT_dec_NN (coro->swap_sv); |
2456 | SvREFCNT_dec_NN (coro->swap_sv); |
2470 | coro->swap_sv = 0; |
2457 | coro->swap_sv = 0; |
2471 | } |
2458 | } |
2472 | |
2459 | |
2473 | coro->prio = 0; |
2460 | coro->prio = 0; |
… | |
… | |
3609 | |
3596 | |
3610 | map_len = load_len + save_len + 16; |
3597 | map_len = load_len + save_len + 16; |
3611 | |
3598 | |
3612 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
3599 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
3613 | |
3600 | |
|
|
3601 | if (map_base == (char *)MAP_FAILED) |
|
|
3602 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
|
|
3603 | |
3614 | assert (("Coro: unable to mmap jit code page, cannot continue.", map_base != (char *)MAP_FAILED)); |
3604 | assert (("Coro: unable to mmap jit code page, cannot continue.", map_base != (char *)MAP_FAILED)); |
3615 | |
3605 | |
3616 | load_perl_slots = (load_save_perl_slots_type)map_base; |
3606 | load_perl_slots = (load_save_perl_slots_type)map_base; |
3617 | memcpy (map_base, load_ptr, load_len); |
3607 | memcpy (map_base, load_ptr, load_len); |
3618 | |
3608 | |
… | |
… | |
4088 | coroapi.enterleave_hook = api_enterleave_hook; |
4078 | coroapi.enterleave_hook = api_enterleave_hook; |
4089 | coroapi.enterleave_unhook = api_enterleave_unhook; |
4079 | coroapi.enterleave_unhook = api_enterleave_unhook; |
4090 | coroapi.enterleave_scope_hook = api_enterleave_scope_hook; |
4080 | coroapi.enterleave_scope_hook = api_enterleave_scope_hook; |
4091 | |
4081 | |
4092 | /*GCoroAPI = &coroapi;*/ |
4082 | /*GCoroAPI = &coroapi;*/ |
4093 | sv_setiv (sv, (IV)&coroapi); |
4083 | sv_setiv (sv, PTR2IV (&coroapi)); |
4094 | SvREADONLY_on (sv); |
4084 | SvREADONLY_on (sv); |
4095 | } |
4085 | } |
4096 | } |
4086 | } |
4097 | |
4087 | |
4098 | SV * |
4088 | SV * |