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.465 by root, Sat Jun 25 19:04:04 2016 UTC vs.
Revision 1.466 by root, Sat Jun 25 19:22:33 2016 UTC

1064static MGVTBL coro_sigelem_vtbl; 1064static MGVTBL coro_sigelem_vtbl;
1065 1065
1066static int ecb_cold 1066static int ecb_cold
1067coro_sig_copy (pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *name, I32 namlen) 1067coro_sig_copy (pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *name, I32 namlen)
1068{ 1068{
1069 char *key = SvPV_nolen ((SV *)name);
1070
1071 /* do what mg_copy normally does */
1069 sv_magic (nsv, mg->mg_obj, PERL_MAGIC_sigelem, name, namlen); 1072 sv_magic (nsv, mg->mg_obj, PERL_MAGIC_sigelem, name, namlen);
1070 assert (mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual == &PL_vtbl_sigelem); 1073 assert (mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual == &PL_vtbl_sigelem);
1074
1075 /* patch sigelem vtbl, but only for __WARN__ and __DIE__ */
1076 if (*key == '_'
1077 && (strEQ (key, "__DIE__")
1078 || strEQ (key, "__WARN__")))
1071 mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual = &coro_sigelem_vtbl; 1079 mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual = &coro_sigelem_vtbl;
1080
1072 return 1; 1081 return 1;
1073} 1082}
1074 1083
1075/* perl does not have a %SIG vtbl, we provide one so we can override */ 1084/* perl does not have a %SIG vtbl, we provide one so we can override */
1076/* the cwvtblagic for %SIG members */ 1085/* the magic vtbl for the __DIE__ and __WARN__ members */
1077static const MGVTBL coro_sig_vtbl = { 1086static const MGVTBL coro_sig_vtbl = {
1078 0, 0, 0, 0, 0, 1087 0, 0, 0, 0, 0,
1079 coro_sig_copy 1088 coro_sig_copy
1080}; 1089};
1081 1090
1087 */ 1096 */
1088static int ecb_cold 1097static int ecb_cold
1089coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) 1098coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg)
1090{ 1099{
1091 const char *s = MgPV_nolen_const (mg); 1100 const char *s = MgPV_nolen_const (mg);
1101 /* the key must be either __DIE__ or __WARN__ here */
1102 SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook;
1092 1103
1093 if (*s == '_') 1104 SV *ssv;
1094 {
1095 SV **svp = 0;
1096 1105
1097 if (strEQ (s, "__DIE__" )) svp = &PL_diehook;
1098 if (strEQ (s, "__WARN__")) svp = &PL_warnhook;
1099
1100 if (svp) 1106 if (!*svp)
1101 {
1102 SV *ssv;
1103
1104 if (!*svp)
1105 ssv = &PL_sv_undef; 1107 ssv = &PL_sv_undef;
1106 else if (SvTYPE (*svp) == SVt_PVCV) /* perlio directly stores a CV in warnhook. ugh. */ 1108 else if (SvTYPE (*svp) == SVt_PVCV) /* perlio directly stores a CV in warnhook. ugh. */
1107 ssv = sv_2mortal (newRV_inc (*svp)); 1109 ssv = sv_2mortal (newRV_inc (*svp));
1108 else 1110 else
1109 ssv = *svp; 1111 ssv = *svp;
1110 1112
1111 sv_setsv (sv, ssv); 1113 sv_setsv (sv, ssv);
1112 return 0; 1114 return 0;
1113 }
1114 }
1115
1116 return PL_vtbl_sigelem.svt_get ? PL_vtbl_sigelem.svt_get (aTHX_ sv, mg) : 0;
1117} 1115}
1118 1116
1119static int ecb_cold 1117static int ecb_cold
1120coro_sigelem_clr (pTHX_ SV *sv, MAGIC *mg) 1118coro_sigelem_clr (pTHX_ SV *sv, MAGIC *mg)
1121{ 1119{
1122 const char *s = MgPV_nolen_const (mg); 1120 const char *s = MgPV_nolen_const (mg);
1121 /* the key must be either __DIE__ or __WARN__ here */
1122 SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook;
1123 1123
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; 1124 SV *old = *svp;
1134 *svp = 0; 1125 *svp = 0;
1135 SvREFCNT_dec (old); 1126 SvREFCNT_dec (old);
1136 return 0; 1127 return 0;
1137 }
1138 }
1139
1140 return PL_vtbl_sigelem.svt_clear ? PL_vtbl_sigelem.svt_clear (aTHX_ sv, mg) : 0;
1141} 1128}
1142 1129
1143static int ecb_cold 1130static int ecb_cold
1144coro_sigelem_set (pTHX_ SV *sv, MAGIC *mg) 1131coro_sigelem_set (pTHX_ SV *sv, MAGIC *mg)
1145{ 1132{
1146 const char *s = MgPV_nolen_const (mg); 1133 const char *s = MgPV_nolen_const (mg);
1134 /* the key must be either __DIE__ or __WARN__ here */
1135 SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook;
1147 1136
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; 1137 SV *old = *svp;
1158 *svp = SvOK (sv) ? newSVsv (sv) : 0; 1138 *svp = SvOK (sv) ? newSVsv (sv) : 0;
1159 SvREFCNT_dec (old); 1139 SvREFCNT_dec (old);
1160 return 0; 1140 return 0;
1161 }
1162 }
1163
1164 return PL_vtbl_sigelem.svt_set ? PL_vtbl_sigelem.svt_set (aTHX_ sv, mg) : 0;
1165} 1141}
1166 1142
1167static void 1143static void
1168prepare_nop (pTHX_ struct coro_transfer_args *ta) 1144prepare_nop (pTHX_ struct coro_transfer_args *ta)
1169{ 1145{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines