| 1 |
|
| /* This file is part of the Variable::Magic Perl module. |
| 2 |
|
| * See http://search.cpan.org/dist/Variable-Magic/ */ |
| 3 |
|
| |
| 4 |
|
| #include <stdarg.h> /* <va_list>, va_{start,arg,end}, ... */ |
| 5 |
|
| |
| 6 |
|
| #include <stdio.h> /* sprintf() */ |
| 7 |
|
| |
| 8 |
|
| #define PERL_NO_GET_CONTEXT |
| 9 |
|
| #include "EXTERN.h" |
| 10 |
|
| #include "perl.h" |
| 11 |
|
| #include "XSUB.h" |
| 12 |
|
| |
| 13 |
|
| /* --- XS helpers ---------------------------------------------------------- */ |
| 14 |
|
| |
| 15 |
|
| #define XSH_PACKAGE "Variable::Magic" |
| 16 |
|
| |
| 17 |
|
| #include "xsh/caps.h" |
| 18 |
|
| #include "xsh/util.h" |
| 19 |
|
| |
| 20 |
|
| /* ... Features ............................................................ */ |
| 21 |
|
| |
| 22 |
|
| /* uvar magic and Hash::Util::FieldHash were commited with 28419, but we only |
| 23 |
|
| * enable them on 5.10 */ |
| 24 |
|
| #if XSH_HAS_PERL(5, 10, 0) |
| 25 |
|
| # define VMG_UVAR 1 |
| 26 |
|
| #else |
| 27 |
|
| # define VMG_UVAR 0 |
| 28 |
|
| #endif |
| 29 |
|
| |
| 30 |
|
| #if XSH_HAS_PERL_MAINT(5, 11, 0, 32969) || XSH_HAS_PERL(5, 12, 0) |
| 31 |
|
| # define VMG_COMPAT_SCALAR_LENGTH_NOLEN 1 |
| 32 |
|
| #else |
| 33 |
|
| # define VMG_COMPAT_SCALAR_LENGTH_NOLEN 0 |
| 34 |
|
| #endif |
| 35 |
|
| |
| 36 |
|
| #if XSH_HAS_PERL(5, 17, 4) |
| 37 |
|
| # define VMG_COMPAT_SCALAR_NOLEN 1 |
| 38 |
|
| #else |
| 39 |
|
| # define VMG_COMPAT_SCALAR_NOLEN 0 |
| 40 |
|
| #endif |
| 41 |
|
| |
| 42 |
|
| /* Applied to dev-5.9 as 25854, integrated to maint-5.8 as 28160, partially |
| 43 |
|
| * reverted to dev-5.11 as 9cdcb38b */ |
| 44 |
|
| #if XSH_HAS_PERL_MAINT(5, 8, 9, 28160) || XSH_HAS_PERL_MAINT(5, 9, 3, 25854) || XSH_HAS_PERL(5, 10, 0) |
| 45 |
|
| # ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN |
| 46 |
|
| # if XSH_HAS_PERL(5, 11, 0) |
| 47 |
|
| # define VMG_COMPAT_ARRAY_PUSH_NOLEN 0 |
| 48 |
|
| # else |
| 49 |
|
| # define VMG_COMPAT_ARRAY_PUSH_NOLEN 1 |
| 50 |
|
| # endif |
| 51 |
|
| # endif |
| 52 |
|
| # ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID |
| 53 |
|
| # define VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID 1 |
| 54 |
|
| # endif |
| 55 |
|
| #else |
| 56 |
|
| # ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN |
| 57 |
|
| # define VMG_COMPAT_ARRAY_PUSH_NOLEN 0 |
| 58 |
|
| # endif |
| 59 |
|
| # ifndef VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID |
| 60 |
|
| # define VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID 0 |
| 61 |
|
| # endif |
| 62 |
|
| #endif |
| 63 |
|
| |
| 64 |
|
| /* Applied to dev-5.11 as 34908 */ |
| 65 |
|
| #if XSH_HAS_PERL_MAINT(5, 11, 0, 34908) || XSH_HAS_PERL(5, 12, 0) |
| 66 |
|
| # define VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID 1 |
| 67 |
|
| #else |
| 68 |
|
| # define VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID 0 |
| 69 |
|
| #endif |
| 70 |
|
| |
| 71 |
|
| /* Applied to dev-5.9 as 31473 (see #43357), integrated to maint-5.8 as 32542 */ |
| 72 |
|
| #if XSH_HAS_PERL_MAINT(5, 8, 9, 32542) || XSH_HAS_PERL_MAINT(5, 9, 5, 31473) || XSH_HAS_PERL(5, 10, 0) |
| 73 |
|
| # define VMG_COMPAT_ARRAY_UNDEF_CLEAR 1 |
| 74 |
|
| #else |
| 75 |
|
| # define VMG_COMPAT_ARRAY_UNDEF_CLEAR 0 |
| 76 |
|
| #endif |
| 77 |
|
| |
| 78 |
|
| #define VMG_COMPAT_HASH_DELETE_NOUVAR_VOID 0 |
| 79 |
|
| |
| 80 |
|
| #if XSH_HAS_PERL(5, 17, 0) |
| 81 |
|
| # define VMG_COMPAT_CODE_COPY_CLONE 1 |
| 82 |
|
| #else |
| 83 |
|
| # define VMG_COMPAT_CODE_COPY_CLONE 0 |
| 84 |
|
| #endif |
| 85 |
|
| |
| 86 |
|
| #if XSH_HAS_PERL(5, 13, 2) |
| 87 |
|
| # define VMG_COMPAT_GLOB_GET 1 |
| 88 |
|
| #else |
| 89 |
|
| # define VMG_COMPAT_GLOB_GET 0 |
| 90 |
|
| #endif |
| 91 |
|
| |
| 92 |
|
| /* ... Trampoline ops ...................................................... */ |
| 93 |
|
| |
| 94 |
|
| #define VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE (XSH_HAS_PERL(5, 10, 0) && !XSH_HAS_PERL(5, 10, 1)) |
| 95 |
|
| |
| 96 |
|
| /* NewOp() isn't public in perl 5.8.0. */ |
| 97 |
|
| #define VMG_RESET_RMG_NEEDS_TRAMPOLINE (VMG_UVAR && (XSH_THREADSAFE || !XSH_HAS_PERL(5, 8, 1))) |
| 98 |
|
| |
| 99 |
|
| #define VMG_NEEDS_TRAMPOLINE VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE || VMG_RESET_RMG_NEEDS_TRAMPOLINE |
| 100 |
|
| |
| 101 |
|
| #if VMG_NEEDS_TRAMPOLINE |
| 102 |
|
| |
| 103 |
|
| typedef struct { |
| 104 |
|
| OP temp; |
| 105 |
|
| SVOP target; |
| 106 |
|
| } vmg_trampoline; |
| 107 |
|
| |
| 108 |
|
| static void vmg_trampoline_init(vmg_trampoline *t, OP *(*cb)(pTHX)) { |
| 109 |
|
| t->temp.op_type = OP_STUB; |
| 110 |
|
| t->temp.op_ppaddr = 0; |
| 111 |
|
| t->temp.op_next = (OP *) &t->target; |
| 112 |
|
| t->temp.op_flags = 0; |
| 113 |
|
| t->temp.op_private = 0; |
| 114 |
|
| |
| 115 |
|
| t->target.op_type = OP_STUB; |
| 116 |
|
| t->target.op_ppaddr = cb; |
| 117 |
|
| t->target.op_next = NULL; |
| 118 |
|
| t->target.op_flags = 0; |
| 119 |
|
| t->target.op_private = 0; |
| 120 |
|
| t->target.op_sv = NULL; |
| 121 |
|
| } |
| 122 |
|
| |
| 123 |
|
| static OP *vmg_trampoline_bump(pTHX_ vmg_trampoline *t, SV *sv, OP *o) { |
| 124 |
|
| #define vmg_trampoline_bump(T, S, O) vmg_trampoline_bump(aTHX_ (T), (S), (O)) |
| 125 |
|
| t->temp = *o; |
| 126 |
|
| t->temp.op_next = (OP *) &t->target; |
| 127 |
|
| |
| 128 |
|
| t->target.op_sv = sv; |
| 129 |
|
| t->target.op_next = o->op_next; |
| 130 |
|
| |
| 131 |
|
| return &t->temp; |
| 132 |
|
| } |
| 133 |
|
| |
| 134 |
|
| #endif /* VMG_NEEDS_TRAMPOLINE */ |
| 135 |
|
| |
| 136 |
|
| /* --- Compatibility ------------------------------------------------------- */ |
| 137 |
|
| |
| 138 |
|
| #ifndef Newx |
| 139 |
|
| # define Newx(v, n, c) New(0, v, n, c) |
| 140 |
|
| #endif |
| 141 |
|
| |
| 142 |
|
| #ifndef SvMAGIC_set |
| 143 |
|
| # define SvMAGIC_set(sv, val) (SvMAGIC(sv) = (val)) |
| 144 |
|
| #endif |
| 145 |
|
| |
| 146 |
|
| #ifndef SvRV_const |
| 147 |
|
| # define SvRV_const(sv) SvRV((SV *) sv) |
| 148 |
|
| #endif |
| 149 |
|
| |
| 150 |
|
| #ifndef SvREFCNT_inc_simple_void |
| 151 |
|
| # define SvREFCNT_inc_simple_void(sv) ((void) SvREFCNT_inc(sv)) |
| 152 |
|
| #endif |
| 153 |
|
| |
| 154 |
|
| #ifndef SvREFCNT_dec_NN |
| 155 |
|
| # define SvREFCNT_dec_NN(sv) ((void) SvREFCNT_dec(sv)) |
| 156 |
|
| #endif |
| 157 |
|
| |
| 158 |
|
| #ifndef mPUSHu |
| 159 |
|
| # define mPUSHu(U) PUSHs(sv_2mortal(newSVuv(U))) |
| 160 |
|
| #endif |
| 161 |
|
| |
| 162 |
|
| #ifndef PERL_MAGIC_ext |
| 163 |
|
| # define PERL_MAGIC_ext '~' |
| 164 |
|
| #endif |
| 165 |
|
| |
| 166 |
|
| #ifndef PERL_MAGIC_tied |
| 167 |
|
| # define PERL_MAGIC_tied 'P' |
| 168 |
|
| #endif |
| 169 |
|
| |
| 170 |
|
| #ifndef MGf_LOCAL |
| 171 |
|
| # define MGf_LOCAL 0 |
| 172 |
|
| #endif |
| 173 |
|
| |
| 174 |
|
| #ifndef IN_PERL_COMPILETIME |
| 175 |
|
| # define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling) |
| 176 |
|
| #endif |
| 177 |
|
| |
| 178 |
|
| #ifndef OP_NAME |
| 179 |
|
| # define OP_NAME(O) (PL_op_name[(O)->op_type]) |
| 180 |
|
| #endif |
| 181 |
|
| |
| 182 |
|
| #ifndef OP_CLASS |
| 183 |
|
| # define OP_CLASS(O) (PL_opargs[(O)->op_type] & OA_CLASS_MASK) |
| 184 |
|
| #endif |
| 185 |
|
| |
| 186 |
|
| #define VMG_CAREFUL_SELF_DESTRUCTION XSH_HAS_PERL(5, 25, 3) |
| 187 |
|
| |
| 188 |
|
| /* ... Bug-free mg_magical ................................................. */ |
| 189 |
|
| |
| 190 |
|
| /* See the discussion at http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2008-01/msg00036.html */ |
| 191 |
|
| |
| 192 |
|
| #if XSH_HAS_PERL(5, 11, 3) |
| 193 |
|
| |
| 194 |
|
| #define vmg_mg_magical(S) mg_magical(S) |
| 195 |
|
| |
| 196 |
|
| #else |
| 197 |
|
| |
| 198 |
|
| static void vmg_mg_magical(SV *sv) { |
| 199 |
|
| const MAGIC *mg; |
| 200 |
|
| |
| 201 |
|
| SvMAGICAL_off(sv); |
| 202 |
|
| if ((mg = SvMAGIC(sv))) { |
| 203 |
|
| do { |
| 204 |
|
| const MGVTBL* const vtbl = mg->mg_virtual; |
| 205 |
|
| if (vtbl) { |
| 206 |
|
| if (vtbl->svt_get && !(mg->mg_flags & MGf_GSKIP)) |
| 207 |
|
| SvGMAGICAL_on(sv); |
| 208 |
|
| if (vtbl->svt_set) |
| 209 |
|
| SvSMAGICAL_on(sv); |
| 210 |
|
| if (vtbl->svt_clear) |
| 211 |
|
| SvRMAGICAL_on(sv); |
| 212 |
|
| } |
| 213 |
|
| } while ((mg = mg->mg_moremagic)); |
| 214 |
|
| if (!(SvFLAGS(sv) & (SVs_GMG|SVs_SMG))) |
| 215 |
|
| SvRMAGICAL_on(sv); |
| 216 |
|
| } |
| 217 |
|
| } |
| 218 |
|
| |
| 219 |
|
| #endif |
| 220 |
|
| |
| 221 |
|
| /* ... Cleaner version of sv_magicext() .................................... */ |
| 222 |
|
| |
| 223 |
486 |
| static MAGIC *vmg_sv_magicext(pTHX_ SV *sv, SV *obj, const MGVTBL *vtbl, const void *ptr, I32 len) { |
| 224 |
|
| #define vmg_sv_magicext(S, O, V, P, L) vmg_sv_magicext(aTHX_ (S), (O), (V), (P), (L)) |
| 225 |
|
| MAGIC *mg; |
| 226 |
|
| |
| 227 |
486 |
| mg = sv_magicext(sv, obj, PERL_MAGIC_ext, vtbl, ptr, len); |
| 228 |
486 |
▶ | if (!mg) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mg) |
0 |
486 |
486 |
|
| 229 |
0 |
| return NULL; |
| 230 |
|
| |
| 231 |
486 |
| mg->mg_private = 0; |
| 232 |
|
| |
| 233 |
486 |
▶ | if (vtbl->svt_copy) |
Branch: 1 branch
| Branch | True | False | Total |
| if (vtbl->svt_copy) |
21 |
465 |
486 |
|
| 234 |
21 |
| mg->mg_flags |= MGf_COPY; |
| 235 |
|
| #if MGf_DUP |
| 236 |
486 |
▶ | if (vtbl->svt_dup) |
Branch: 1 branch
| Branch | True | False | Total |
| if (vtbl->svt_dup) |
0 |
486 |
486 |
|
| 237 |
0 |
| mg->mg_flags |= MGf_DUP; |
| 238 |
|
| #endif /* MGf_DUP */ |
| 239 |
|
| #if MGf_LOCAL |
| 240 |
486 |
▶ | if (vtbl->svt_local) |
Branch: 1 branch
| Branch | True | False | Total |
| if (vtbl->svt_local) |
20 |
466 |
486 |
|
| 241 |
20 |
| mg->mg_flags |= MGf_LOCAL; |
| 242 |
|
| #endif /* MGf_LOCAL */ |
| 243 |
|
| |
| 244 |
486 |
▶ | if (mg->mg_flags & MGf_REFCOUNTED) |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg->mg_flags & MGf_REFCOUNTED) |
138 |
348 |
486 |
|
| 245 |
138 |
| SvREFCNT_dec(obj); |
| 246 |
|
| |
| 247 |
486 |
| return mg; |
| 248 |
|
| } |
| 249 |
|
| |
| 250 |
|
| /* ... Safe version of call_sv() ........................................... */ |
| 251 |
|
| |
| 252 |
657 |
| static I32 vmg_call_sv(pTHX_ SV *sv, I32 flags, int (*cleanup)(pTHX_ void *), void *ud) { |
| 253 |
|
| #define vmg_call_sv(S, F, C, U) vmg_call_sv(aTHX_ (S), (F), (C), (U)) |
| 254 |
|
| I32 ret; |
| 255 |
657 |
| SV *old_err = NULL; |
| 256 |
|
| |
| 257 |
657 |
▶ | if (SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { |
657 |
0 |
657 |
| if (SvTRUE(ERRSV)) { |
55 |
602 |
657 |
|
| 258 |
55 |
▶ | old_err = newSVsv(ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| old_err = newSVsv(ERRSV); |
55 |
0 |
55 |
|
| 259 |
55 |
▶ | sv_setsv(ERRSV, &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setsv(ERRSV, &PL_sv_undef); |
55 |
0 |
55 |
|
| 260 |
|
| } |
| 261 |
|
| |
| 262 |
657 |
| ret = call_sv(sv, flags | G_EVAL); |
| 263 |
|
| |
| 264 |
657 |
▶ | if (SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { |
657 |
0 |
657 |
| if (SvTRUE(ERRSV)) { |
116 |
541 |
657 |
|
| 265 |
116 |
| SvREFCNT_dec(old_err); |
| 266 |
|
| |
| 267 |
116 |
▶ | if (IN_PERL_COMPILETIME) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (IN_PERL_COMPILETIME) { |
3 |
113 |
116 |
|
| 268 |
3 |
▶ | if (!PL_in_eval) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!PL_in_eval) { |
2 |
1 |
3 |
|
| 269 |
2 |
▶ | if (PL_errors) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_errors) |
2 |
0 |
2 |
|
| 270 |
2 |
▶ | sv_catsv(PL_errors, ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_catsv(PL_errors, ERRSV); |
2 |
0 |
2 |
|
| 271 |
|
| else |
| 272 |
0 |
▶ | Perl_warn(aTHX_ "%s", SvPV_nolen(ERRSV)); |
Branch: 1 branch
| Branch | True | False | Total |
| Perl_warn(aTHX_ "%s", SvPV_nolen(ERRSV)); |
0 |
0 |
0 |
|
| 273 |
2 |
▶ | SvCUR_set(ERRSV, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| SvCUR_set(ERRSV, 0); |
2 |
0 |
2 |
|
| 274 |
|
| } |
| 275 |
|
| #if XSH_HAS_PERL(5, 10, 0) || defined(PL_parser) |
| 276 |
3 |
▶ | if (PL_parser) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_parser) |
3 |
0 |
3 |
|
| 277 |
3 |
| ++PL_parser->error_count; |
| 278 |
|
| #elif defined(PL_error_count) |
| 279 |
|
| ++PL_error_count; |
| 280 |
|
| #else |
| 281 |
|
| ++PL_Ierror_count; |
| 282 |
|
| #endif |
| 283 |
|
| } else { |
| 284 |
113 |
▶ | if (!cleanup || cleanup(aTHX_ ud)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cleanup || cleanup(aTHX_ ud)) |
70 |
43 |
113 |
| if (!cleanup || cleanup(aTHX_ ud)) |
65 |
5 |
70 |
|
| 285 |
108 |
| croak(NULL); |
| 286 |
|
| } |
| 287 |
|
| } else { |
| 288 |
541 |
▶ | if (old_err) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (old_err) { |
23 |
518 |
541 |
|
| 289 |
23 |
▶ | sv_setsv(ERRSV, old_err); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setsv(ERRSV, old_err); |
23 |
0 |
23 |
|
| 290 |
23 |
| SvREFCNT_dec(old_err); |
| 291 |
|
| } |
| 292 |
|
| } |
| 293 |
|
| |
| 294 |
549 |
| return ret; |
| 295 |
|
| } |
| 296 |
|
| |
| 297 |
|
| /* --- Stolen chunk of B --------------------------------------------------- */ |
| 298 |
|
| |
| 299 |
|
| typedef enum { |
| 300 |
|
| OPc_NULL, |
| 301 |
|
| OPc_BASEOP, |
| 302 |
|
| OPc_UNOP, |
| 303 |
|
| OPc_BINOP, |
| 304 |
|
| OPc_LOGOP, |
| 305 |
|
| OPc_LISTOP, |
| 306 |
|
| OPc_PMOP, |
| 307 |
|
| OPc_SVOP, |
| 308 |
|
| OPc_PADOP, |
| 309 |
|
| OPc_PVOP, |
| 310 |
|
| OPc_LOOP, |
| 311 |
|
| OPc_COP, |
| 312 |
|
| #if XSH_HAS_PERL(5, 21, 5) |
| 313 |
|
| OPc_METHOP, |
| 314 |
|
| #endif |
| 315 |
|
| #if XSH_HAS_PERL(5, 21, 7) |
| 316 |
|
| OPc_UNOP_AUX, |
| 317 |
|
| #endif |
| 318 |
|
| OPc_MAX |
| 319 |
|
| } opclass; |
| 320 |
|
| |
| 321 |
|
| static const char *const vmg_opclassnames[] = { |
| 322 |
|
| "B::NULL", |
| 323 |
|
| "B::OP", |
| 324 |
|
| "B::UNOP", |
| 325 |
|
| "B::BINOP", |
| 326 |
|
| "B::LOGOP", |
| 327 |
|
| "B::LISTOP", |
| 328 |
|
| "B::PMOP", |
| 329 |
|
| "B::SVOP", |
| 330 |
|
| "B::PADOP", |
| 331 |
|
| "B::PVOP", |
| 332 |
|
| "B::LOOP", |
| 333 |
|
| "B::COP", |
| 334 |
|
| #if XSH_HAS_PERL(5, 21, 5) |
| 335 |
|
| "B::METHOP", |
| 336 |
|
| #endif |
| 337 |
|
| #if XSH_HAS_PERL(5, 21, 7) |
| 338 |
|
| "B::UNOP_AUX", |
| 339 |
|
| #endif |
| 340 |
|
| NULL |
| 341 |
|
| }; |
| 342 |
|
| |
| 343 |
20 |
| static opclass vmg_opclass(pTHX_ const OP *o) { |
| 344 |
|
| #define vmg_opclass(O) vmg_opclass(aTHX_ (O)) |
| 345 |
|
| #if 0 |
| 346 |
|
| if (!o) |
| 347 |
|
| return OPc_NULL; |
| 348 |
|
| #endif |
| 349 |
|
| |
| 350 |
20 |
▶ | if (o->op_type == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_type == 0) { |
0 |
20 |
20 |
|
| 351 |
|
| #if XSH_HAS_PERL(5, 21, 7) |
| 352 |
0 |
▶ | if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE) |
Branch: 2 branches
| Branch | True | False | Total |
| if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE) |
0 |
0 |
0 |
| if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE) |
0 |
0 |
0 |
|
| 353 |
0 |
| return OPc_COP; |
| 354 |
|
| #endif |
| 355 |
0 |
▶ | return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP; |
Branch: 1 branch
| Branch | True | False | Total |
| return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP; |
0 |
0 |
0 |
|
| 356 |
|
| } |
| 357 |
|
| |
| 358 |
20 |
▶ | if (o->op_type == OP_SASSIGN) |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_type == OP_SASSIGN) |
0 |
20 |
20 |
|
| 359 |
0 |
▶ | return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP); |
Branch: 1 branch
| Branch | True | False | Total |
| return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP); |
0 |
0 |
0 |
|
| 360 |
|
| |
| 361 |
20 |
▶ | if (o->op_type == OP_AELEMFAST) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_type == OP_AELEMFAST) { |
0 |
20 |
20 |
|
| 362 |
|
| #if PERL_VERSION <= 14 |
| 363 |
|
| if (o->op_flags & OPf_SPECIAL) |
| 364 |
|
| return OPc_BASEOP; |
| 365 |
|
| else |
| 366 |
|
| #endif |
| 367 |
|
| #ifdef USE_ITHREADS |
| 368 |
|
| return OPc_PADOP; |
| 369 |
|
| #else |
| 370 |
0 |
| return OPc_SVOP; |
| 371 |
|
| #endif |
| 372 |
|
| } |
| 373 |
|
| |
| 374 |
|
| #ifdef USE_ITHREADS |
| 375 |
|
| if (o->op_type == OP_GV || o->op_type == OP_GVSV || o->op_type == OP_RCATLINE) |
| 376 |
|
| return OPc_PADOP; |
| 377 |
|
| #endif |
| 378 |
|
| |
| 379 |
20 |
▶ | switch (OP_CLASS(o)) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (OP_CLASS(o)) { |
0 |
20 |
20 |
|
| 380 |
1 |
| case OA_BASEOP: |
| 381 |
1 |
| return OPc_BASEOP; |
| 382 |
4 |
| case OA_UNOP: |
| 383 |
4 |
| return OPc_UNOP; |
| 384 |
1 |
| case OA_BINOP: |
| 385 |
1 |
| return OPc_BINOP; |
| 386 |
1 |
| case OA_LOGOP: |
| 387 |
1 |
| return OPc_LOGOP; |
| 388 |
1 |
| case OA_LISTOP: |
| 389 |
1 |
| return OPc_LISTOP; |
| 390 |
1 |
| case OA_PMOP: |
| 391 |
1 |
| return OPc_PMOP; |
| 392 |
0 |
| case OA_SVOP: |
| 393 |
0 |
| return OPc_SVOP; |
| 394 |
0 |
| case OA_PADOP: |
| 395 |
0 |
| return OPc_PADOP; |
| 396 |
2 |
| case OA_PVOP_OR_SVOP: |
| 397 |
|
| return ( |
| 398 |
|
| #if XSH_HAS_PERL(5, 13, 7) |
| 399 |
4 |
| (o->op_type != OP_CUSTOM) && |
| 400 |
|
| #endif |
| 401 |
2 |
▶ | (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))) |
Branch: 1 branch
| Branch | True | False | Total |
| (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))) |
1 |
1 |
2 |
|
| 402 |
|
| #if defined(USE_ITHREADS) && XSH_HAS_PERL(5, 8, 9) |
| 403 |
|
| ? OPc_PADOP : OPc_PVOP; |
| 404 |
|
| #else |
| 405 |
4 |
▶ | ? OPc_SVOP : OPc_PVOP; |
Branch: 1 branch
| Branch | True | False | Total |
| ? OPc_SVOP : OPc_PVOP; |
2 |
0 |
2 |
|
| 406 |
|
| #endif |
| 407 |
1 |
| case OA_LOOP: |
| 408 |
1 |
| return OPc_LOOP; |
| 409 |
0 |
| case OA_COP: |
| 410 |
0 |
| return OPc_COP; |
| 411 |
1 |
| case OA_BASEOP_OR_UNOP: |
| 412 |
1 |
▶ | return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP; |
Branch: 1 branch
| Branch | True | False | Total |
| return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP; |
1 |
0 |
1 |
|
| 413 |
1 |
| case OA_FILESTATOP: |
| 414 |
1 |
▶ | return ((o->op_flags & OPf_KIDS) ? OPc_UNOP : |
Branch: 1 branch
| Branch | True | False | Total |
| return ((o->op_flags & OPf_KIDS) ? OPc_UNOP : |
0 |
1 |
1 |
|
| 415 |
|
| #ifdef USE_ITHREADS |
| 416 |
|
| (o->op_flags & OPf_REF) ? OPc_PADOP : OPc_BASEOP); |
| 417 |
|
| #else |
| 418 |
0 |
▶ | (o->op_flags & OPf_REF) ? OPc_SVOP : OPc_BASEOP); |
Branch: 1 branch
| Branch | True | False | Total |
| (o->op_flags & OPf_REF) ? OPc_SVOP : OPc_BASEOP); |
0 |
0 |
0 |
|
| 419 |
|
| #endif |
| 420 |
3 |
| case OA_LOOPEXOP: |
| 421 |
3 |
▶ | if (o->op_flags & OPf_STACKED) |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_flags & OPf_STACKED) |
1 |
2 |
3 |
|
| 422 |
1 |
| return OPc_UNOP; |
| 423 |
2 |
▶ | else if (o->op_flags & OPf_SPECIAL) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (o->op_flags & OPf_SPECIAL) |
1 |
1 |
2 |
|
| 424 |
1 |
| return OPc_BASEOP; |
| 425 |
|
| else |
| 426 |
1 |
| return OPc_PVOP; |
| 427 |
|
| #if XSH_HAS_PERL(5, 21, 5) |
| 428 |
1 |
| case OA_METHOP: |
| 429 |
1 |
| return OPc_METHOP; |
| 430 |
|
| #endif |
| 431 |
|
| #if XSH_HAS_PERL(5, 21, 7) |
| 432 |
2 |
| case OA_UNOP_AUX: |
| 433 |
2 |
| return OPc_UNOP_AUX; |
| 434 |
|
| #endif |
| 435 |
|
| } |
| 436 |
|
| |
| 437 |
0 |
| return OPc_BASEOP; |
| 438 |
|
| } |
| 439 |
|
| |
| 440 |
|
| /* --- Error messages ------------------------------------------------------ */ |
| 441 |
|
| |
| 442 |
|
| static const char vmg_invalid_wiz[] = "Invalid wizard object"; |
| 443 |
|
| static const char vmg_wrongargnum[] = "Wrong number of arguments"; |
| 444 |
|
| |
| 445 |
|
| /* --- Thread-local storage ------------------------------------------------ */ |
| 446 |
|
| |
| 447 |
|
| typedef struct { |
| 448 |
|
| HV *b__op_stashes[OPc_MAX]; |
| 449 |
|
| I32 depth; |
| 450 |
|
| MAGIC *freed_tokens; |
| 451 |
|
| #if VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE |
| 452 |
|
| vmg_trampoline propagate_errsv; |
| 453 |
|
| #endif |
| 454 |
|
| #if VMG_RESET_RMG_NEEDS_TRAMPOLINE |
| 455 |
|
| vmg_trampoline reset_rmg; |
| 456 |
|
| #endif |
| 457 |
|
| } xsh_user_cxt_t; |
| 458 |
|
| |
| 459 |
|
| #if XSH_THREADSAFE |
| 460 |
|
| |
| 461 |
|
| static void xsh_user_clone(pTHX_ const xsh_user_cxt_t *old_cxt, xsh_user_cxt_t *new_cxt) { |
| 462 |
|
| int c; |
| 463 |
|
| |
| 464 |
|
| for (c = OPc_NULL; c < OPc_MAX; ++c) { |
| 465 |
|
| new_cxt->b__op_stashes[c] = old_cxt->b__op_stashes[c] |
| 466 |
|
| ? gv_stashpv(vmg_opclassnames[c], 1) |
| 467 |
|
| : NULL; |
| 468 |
|
| } |
| 469 |
|
| |
| 470 |
|
| new_cxt->depth = old_cxt->depth; |
| 471 |
|
| new_cxt->freed_tokens = NULL; |
| 472 |
|
| |
| 473 |
|
| return; |
| 474 |
|
| } |
| 475 |
|
| |
| 476 |
|
| |
| 477 |
|
| #endif /* XSH_THREADSAFE */ |
| 478 |
|
| |
| 479 |
|
| #define XSH_THREADS_NEED_TEARDOWN_LATE 1 |
| 480 |
|
| |
| 481 |
|
| #include "xsh/threads.h" |
| 482 |
|
| |
| 483 |
|
| /* --- <vmg_vtable> structure ---------------------------------------------- */ |
| 484 |
|
| |
| 485 |
|
| #if XSH_THREADSAFE |
| 486 |
|
| |
| 487 |
|
| typedef struct { |
| 488 |
|
| MGVTBL *vtbl; |
| 489 |
|
| U32 refcount; |
| 490 |
|
| } vmg_vtable; |
| 491 |
|
| |
| 492 |
|
| static vmg_vtable *vmg_vtable_alloc(pTHX) { |
| 493 |
|
| #define vmg_vtable_alloc() vmg_vtable_alloc(aTHX) |
| 494 |
|
| vmg_vtable *t; |
| 495 |
|
| |
| 496 |
|
| t = VOID2(vmg_vtable *, PerlMemShared_malloc(sizeof *t)); |
| 497 |
|
| |
| 498 |
|
| t->vtbl = VOID2(MGVTBL *, PerlMemShared_malloc(sizeof *t->vtbl)); |
| 499 |
|
| t->refcount = 1; |
| 500 |
|
| |
| 501 |
|
| return t; |
| 502 |
|
| } |
| 503 |
|
| |
| 504 |
|
| #define vmg_vtable_vtbl(T) (T)->vtbl |
| 505 |
|
| |
| 506 |
|
| static perl_mutex vmg_vtable_refcount_mutex; |
| 507 |
|
| |
| 508 |
|
| static vmg_vtable *vmg_vtable_dup(pTHX_ vmg_vtable *t) { |
| 509 |
|
| #define vmg_vtable_dup(T) vmg_vtable_dup(aTHX_ (T)) |
| 510 |
|
| XSH_LOCK(&vmg_vtable_refcount_mutex); |
| 511 |
|
| ++t->refcount; |
| 512 |
|
| XSH_UNLOCK(&vmg_vtable_refcount_mutex); |
| 513 |
|
| |
| 514 |
|
| return t; |
| 515 |
|
| } |
| 516 |
|
| |
| 517 |
|
| static void vmg_vtable_free(pTHX_ vmg_vtable *t) { |
| 518 |
|
| #define vmg_vtable_free(T) vmg_vtable_free(aTHX_ (T)) |
| 519 |
|
| U32 refcount; |
| 520 |
|
| |
| 521 |
|
| XSH_LOCK(&vmg_vtable_refcount_mutex); |
| 522 |
|
| refcount = --t->refcount; |
| 523 |
|
| XSH_UNLOCK(&vmg_vtable_refcount_mutex); |
| 524 |
|
| |
| 525 |
|
| if (!refcount) { |
| 526 |
|
| PerlMemShared_free(t->vtbl); |
| 527 |
|
| PerlMemShared_free(t); |
| 528 |
|
| } |
| 529 |
|
| } |
| 530 |
|
| |
| 531 |
|
| #else /* XSH_THREADSAFE */ |
| 532 |
|
| |
| 533 |
|
| typedef MGVTBL vmg_vtable; |
| 534 |
|
| |
| 535 |
176 |
| static vmg_vtable *vmg_vtable_alloc(pTHX) { |
| 536 |
|
| #define vmg_vtable_alloc() vmg_vtable_alloc(aTHX) |
| 537 |
|
| vmg_vtable *t; |
| 538 |
|
| |
| 539 |
176 |
| Newx(t, 1, vmg_vtable); |
| 540 |
|
| |
| 541 |
176 |
| return t; |
| 542 |
|
| } |
| 543 |
|
| |
| 544 |
|
| #define vmg_vtable_vtbl(T) ((MGVTBL *) (T)) |
| 545 |
|
| |
| 546 |
|
| #define vmg_vtable_free(T) Safefree(T) |
| 547 |
|
| |
| 548 |
|
| #endif /* !XSH_THREADSAFE */ |
| 549 |
|
| |
| 550 |
|
| /* --- <vmg_wizard> structure ---------------------------------------------- */ |
| 551 |
|
| |
| 552 |
|
| typedef struct { |
| 553 |
|
| vmg_vtable *vtable; |
| 554 |
|
| |
| 555 |
|
| U8 opinfo; |
| 556 |
|
| U8 uvar; |
| 557 |
|
| |
| 558 |
|
| SV *cb_data; |
| 559 |
|
| SV *cb_get, *cb_set, *cb_len, *cb_clear, *cb_free; |
| 560 |
|
| SV *cb_copy; |
| 561 |
|
| SV *cb_dup; |
| 562 |
|
| #if MGf_LOCAL |
| 563 |
|
| SV *cb_local; |
| 564 |
|
| #endif /* MGf_LOCAL */ |
| 565 |
|
| #if VMG_UVAR |
| 566 |
|
| SV *cb_fetch, *cb_store, *cb_exists, *cb_delete; |
| 567 |
|
| #endif /* VMG_UVAR */ |
| 568 |
|
| } vmg_wizard; |
| 569 |
|
| |
| 570 |
|
| static void vmg_op_info_init(pTHX_ unsigned int opinfo); |
| 571 |
|
| |
| 572 |
176 |
| static vmg_wizard *vmg_wizard_alloc(pTHX_ UV opinfo) { |
| 573 |
|
| #define vmg_wizard_alloc(O) vmg_wizard_alloc(aTHX_ (O)) |
| 574 |
|
| vmg_wizard *w; |
| 575 |
|
| |
| 576 |
176 |
| Newx(w, 1, vmg_wizard); |
| 577 |
|
| |
| 578 |
176 |
| w->uvar = 0; |
| 579 |
176 |
▶ | w->opinfo = (U8) ((opinfo < 255) ? opinfo : 255); |
Branch: 1 branch
| Branch | True | False | Total |
| w->opinfo = (U8) ((opinfo < 255) ? opinfo : 255); |
176 |
0 |
176 |
|
| 580 |
176 |
▶ | if (w->opinfo) |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->opinfo) |
41 |
135 |
176 |
|
| 581 |
41 |
| vmg_op_info_init(aTHX_ w->opinfo); |
| 582 |
|
| |
| 583 |
176 |
| w->vtable = vmg_vtable_alloc(); |
| 584 |
|
| |
| 585 |
176 |
| return w; |
| 586 |
|
| } |
| 587 |
|
| |
| 588 |
131 |
| static void vmg_wizard_free(pTHX_ vmg_wizard *w) { |
| 589 |
|
| #define vmg_wizard_free(W) vmg_wizard_free(aTHX_ (W)) |
| 590 |
131 |
▶ | if (!w) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!w) |
0 |
131 |
131 |
|
| 591 |
0 |
| return; |
| 592 |
|
| |
| 593 |
|
| /* During global destruction, any of the callbacks may already have been |
| 594 |
|
| * freed, so we can't rely on still being able to access them. */ |
| 595 |
131 |
▶ | if (!PL_dirty) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!PL_dirty) { |
131 |
0 |
131 |
|
| 596 |
131 |
| SvREFCNT_dec(w->cb_data); |
| 597 |
131 |
| SvREFCNT_dec(w->cb_get); |
| 598 |
131 |
| SvREFCNT_dec(w->cb_set); |
| 599 |
131 |
| SvREFCNT_dec(w->cb_len); |
| 600 |
131 |
| SvREFCNT_dec(w->cb_clear); |
| 601 |
131 |
| SvREFCNT_dec(w->cb_free); |
| 602 |
131 |
| SvREFCNT_dec(w->cb_copy); |
| 603 |
|
| #if 0 |
| 604 |
|
| SvREFCNT_dec(w->cb_dup); |
| 605 |
|
| #endif |
| 606 |
|
| #if MGf_LOCAL |
| 607 |
131 |
| SvREFCNT_dec(w->cb_local); |
| 608 |
|
| #endif /* MGf_LOCAL */ |
| 609 |
|
| #if VMG_UVAR |
| 610 |
131 |
| SvREFCNT_dec(w->cb_fetch); |
| 611 |
131 |
| SvREFCNT_dec(w->cb_store); |
| 612 |
131 |
| SvREFCNT_dec(w->cb_exists); |
| 613 |
131 |
| SvREFCNT_dec(w->cb_delete); |
| 614 |
|
| #endif /* VMG_UVAR */ |
| 615 |
|
| } |
| 616 |
|
| |
| 617 |
|
| /* PerlMemShared_free() and Safefree() are still fine during global |
| 618 |
|
| * destruction though. */ |
| 619 |
131 |
| vmg_vtable_free(w->vtable); |
| 620 |
131 |
| Safefree(w); |
| 621 |
|
| |
| 622 |
131 |
| return; |
| 623 |
|
| } |
| 624 |
|
| |
| 625 |
|
| #if XSH_THREADSAFE |
| 626 |
|
| |
| 627 |
|
| #define VMG_CLONE_CB(N) \ |
| 628 |
|
| z->cb_ ## N = (w->cb_ ## N) ? SvREFCNT_inc(sv_dup(w->cb_ ## N, params)) \ |
| 629 |
|
| : NULL; |
| 630 |
|
| |
| 631 |
|
| static const vmg_wizard *vmg_wizard_dup(pTHX_ const vmg_wizard *w, CLONE_PARAMS *params) { |
| 632 |
|
| #define vmg_wizard_dup(W, P) vmg_wizard_dup(aTHX_ (W), (P)) |
| 633 |
|
| vmg_wizard *z; |
| 634 |
|
| |
| 635 |
|
| if (!w) |
| 636 |
|
| return NULL; |
| 637 |
|
| |
| 638 |
|
| Newx(z, 1, vmg_wizard); |
| 639 |
|
| |
| 640 |
|
| z->vtable = vmg_vtable_dup(w->vtable); |
| 641 |
|
| z->uvar = w->uvar; |
| 642 |
|
| z->opinfo = w->opinfo; |
| 643 |
|
| |
| 644 |
|
| VMG_CLONE_CB(data); |
| 645 |
|
| VMG_CLONE_CB(get); |
| 646 |
|
| VMG_CLONE_CB(set); |
| 647 |
|
| VMG_CLONE_CB(len); |
| 648 |
|
| VMG_CLONE_CB(clear); |
| 649 |
|
| VMG_CLONE_CB(free); |
| 650 |
|
| VMG_CLONE_CB(copy); |
| 651 |
|
| VMG_CLONE_CB(dup); |
| 652 |
|
| #if MGf_LOCAL |
| 653 |
|
| VMG_CLONE_CB(local); |
| 654 |
|
| #endif /* MGf_LOCAL */ |
| 655 |
|
| #if VMG_UVAR |
| 656 |
|
| VMG_CLONE_CB(fetch); |
| 657 |
|
| VMG_CLONE_CB(store); |
| 658 |
|
| VMG_CLONE_CB(exists); |
| 659 |
|
| VMG_CLONE_CB(delete); |
| 660 |
|
| #endif /* VMG_UVAR */ |
| 661 |
|
| |
| 662 |
|
| return z; |
| 663 |
|
| } |
| 664 |
|
| |
| 665 |
|
| #endif /* XSH_THREADSAFE */ |
| 666 |
|
| |
| 667 |
|
| #define vmg_wizard_id(W) PTR2IV(vmg_vtable_vtbl((W)->vtable)) |
| 668 |
|
| |
| 669 |
|
| /* --- Wizard SV objects --------------------------------------------------- */ |
| 670 |
|
| |
| 671 |
131 |
| static int vmg_wizard_sv_free(pTHX_ SV *sv, MAGIC *mg) { |
| 672 |
131 |
| vmg_wizard_free((vmg_wizard *) mg->mg_ptr); |
| 673 |
|
| |
| 674 |
131 |
| return 0; |
| 675 |
|
| } |
| 676 |
|
| |
| 677 |
|
| #if XSH_THREADSAFE |
| 678 |
|
| |
| 679 |
|
| static int vmg_wizard_sv_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *params) { |
| 680 |
|
| mg->mg_ptr = (char *) vmg_wizard_dup((const vmg_wizard *) mg->mg_ptr, params); |
| 681 |
|
| |
| 682 |
|
| return 0; |
| 683 |
|
| } |
| 684 |
|
| |
| 685 |
|
| #endif /* XSH_THREADSAFE */ |
| 686 |
|
| |
| 687 |
|
| static MGVTBL vmg_wizard_sv_vtbl = { |
| 688 |
|
| NULL, /* get */ |
| 689 |
|
| NULL, /* set */ |
| 690 |
|
| NULL, /* len */ |
| 691 |
|
| NULL, /* clear */ |
| 692 |
|
| vmg_wizard_sv_free, /* free */ |
| 693 |
|
| NULL, /* copy */ |
| 694 |
|
| #if XSH_THREADSAFE |
| 695 |
|
| vmg_wizard_sv_dup, /* dup */ |
| 696 |
|
| #else |
| 697 |
|
| NULL, /* dup */ |
| 698 |
|
| #endif |
| 699 |
|
| #if MGf_LOCAL |
| 700 |
|
| NULL, /* local */ |
| 701 |
|
| #endif /* MGf_LOCAL */ |
| 702 |
|
| }; |
| 703 |
|
| |
| 704 |
176 |
| static SV *vmg_wizard_sv_new(pTHX_ const vmg_wizard *w) { |
| 705 |
|
| #define vmg_wizard_sv_new(W) vmg_wizard_sv_new(aTHX_ (W)) |
| 706 |
|
| SV *wiz; |
| 707 |
|
| |
| 708 |
|
| #if XSH_THREADSAFE |
| 709 |
|
| wiz = newSV(0); |
| 710 |
|
| #else |
| 711 |
176 |
| wiz = newSViv(PTR2IV(w)); |
| 712 |
|
| #endif |
| 713 |
|
| |
| 714 |
176 |
| vmg_sv_magicext(wiz, NULL, &vmg_wizard_sv_vtbl, w, 0); |
| 715 |
|
| |
| 716 |
176 |
| SvREADONLY_on(wiz); |
| 717 |
|
| |
| 718 |
176 |
| return wiz; |
| 719 |
|
| } |
| 720 |
|
| |
| 721 |
|
| #if XSH_THREADSAFE |
| 722 |
|
| |
| 723 |
|
| #define vmg_sv_has_wizard_type(S) (SvTYPE(S) >= SVt_PVMG) |
| 724 |
|
| |
| 725 |
|
| static const vmg_wizard *vmg_wizard_from_sv_nocheck(const SV *wiz) { |
| 726 |
|
| MAGIC *mg; |
| 727 |
|
| |
| 728 |
|
| for (mg = SvMAGIC(wiz); mg; mg = mg->mg_moremagic) { |
| 729 |
|
| if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &vmg_wizard_sv_vtbl) |
| 730 |
|
| return (const vmg_wizard *) mg->mg_ptr; |
| 731 |
|
| } |
| 732 |
|
| |
| 733 |
|
| return NULL; |
| 734 |
|
| } |
| 735 |
|
| |
| 736 |
|
| #else /* XSH_THREADSAFE */ |
| 737 |
|
| |
| 738 |
|
| #define vmg_sv_has_wizard_type(S) SvIOK(S) |
| 739 |
|
| |
| 740 |
|
| #define vmg_wizard_from_sv_nocheck(W) INT2PTR(const vmg_wizard *, SvIVX(W)) |
| 741 |
|
| |
| 742 |
|
| #endif /* !XSH_THREADSAFE */ |
| 743 |
|
| |
| 744 |
|
| #define vmg_wizard_from_sv(W) (vmg_sv_has_wizard_type(W) ? vmg_wizard_from_sv_nocheck(W) : NULL) |
| 745 |
|
| |
| 746 |
372 |
| static const vmg_wizard *vmg_wizard_from_mg(const MAGIC *mg) { |
| 747 |
372 |
▶ | if (mg->mg_type == PERL_MAGIC_ext && mg->mg_len == HEf_SVKEY) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (mg->mg_type == PERL_MAGIC_ext && mg->mg_len == HEf_SVKEY) { |
329 |
43 |
372 |
| if (mg->mg_type == PERL_MAGIC_ext && mg->mg_len == HEf_SVKEY) { |
329 |
0 |
329 |
|
| 748 |
329 |
| SV *sv = (SV *) mg->mg_ptr; |
| 749 |
|
| |
| 750 |
329 |
▶ | if (vmg_sv_has_wizard_type(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (vmg_sv_has_wizard_type(sv)) |
329 |
0 |
329 |
|
| 751 |
329 |
| return vmg_wizard_from_sv_nocheck(sv); |
| 752 |
|
| } |
| 753 |
|
| |
| 754 |
43 |
| return NULL; |
| 755 |
|
| } |
| 756 |
|
| |
| 757 |
|
| #define vmg_wizard_from_mg_nocheck(M) vmg_wizard_from_sv_nocheck((const SV *) (M)->mg_ptr) |
| 758 |
|
| |
| 759 |
|
| /* --- User-level functions implementation --------------------------------- */ |
| 760 |
|
| |
| 761 |
381 |
| static const MAGIC *vmg_find(const SV *sv, const vmg_wizard *w) { |
| 762 |
|
| const MAGIC *mg; |
| 763 |
|
| IV wid; |
| 764 |
|
| |
| 765 |
381 |
▶ | if (SvTYPE(sv) < SVt_PVMG) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(sv) < SVt_PVMG) |
159 |
222 |
381 |
|
| 766 |
159 |
| return NULL; |
| 767 |
|
| |
| 768 |
222 |
| wid = vmg_wizard_id(w); |
| 769 |
|
| |
| 770 |
286 |
▶ | for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
113 |
173 |
286 |
|
| 771 |
113 |
| const vmg_wizard *z = vmg_wizard_from_mg(mg); |
| 772 |
|
| |
| 773 |
113 |
▶ | if (z && vmg_wizard_id(z) == wid) |
Branch: 2 branches
| Branch | True | False | Total |
| if (z && vmg_wizard_id(z) == wid) |
90 |
23 |
113 |
| if (z && vmg_wizard_id(z) == wid) |
49 |
41 |
90 |
|
| 774 |
49 |
| return mg; |
| 775 |
|
| } |
| 776 |
|
| |
| 777 |
173 |
| return NULL; |
| 778 |
|
| } |
| 779 |
|
| |
| 780 |
|
| /* ... Construct private data .............................................. */ |
| 781 |
|
| |
| 782 |
143 |
| static SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, SV **args, I32 items) { |
| 783 |
|
| #define vmg_data_new(C, S, A, I) vmg_data_new(aTHX_ (C), (S), (A), (I)) |
| 784 |
|
| I32 i; |
| 785 |
|
| SV *nsv; |
| 786 |
|
| |
| 787 |
143 |
| dSP; |
| 788 |
|
| |
| 789 |
143 |
| ENTER; |
| 790 |
143 |
| SAVETMPS; |
| 791 |
|
| |
| 792 |
143 |
| PUSHSTACKi(PERLSI_MAGIC); |
| 793 |
|
| |
| 794 |
143 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
143 |
143 |
|
| 795 |
143 |
▶ | EXTEND(SP, items + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, items + 1); |
143 |
0 |
143 |
| EXTEND(SP, items + 1); |
0 |
143 |
143 |
|
| 796 |
143 |
| PUSHs(sv_2mortal(newRV_inc(sv))); |
| 797 |
197 |
▶ | for (i = 0; i < items; ++i) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < items; ++i) |
54 |
143 |
197 |
|
| 798 |
54 |
| PUSHs(args[i]); |
| 799 |
143 |
| PUTBACK; |
| 800 |
|
| |
| 801 |
143 |
| vmg_call_sv(ctor, G_SCALAR, 0, NULL); |
| 802 |
|
| |
| 803 |
135 |
| SPAGAIN; |
| 804 |
135 |
| nsv = POPs; |
| 805 |
|
| #if XSH_HAS_PERL(5, 8, 3) |
| 806 |
135 |
▶ | SvREFCNT_inc_simple_void(nsv); /* Or it will be destroyed in FREETMPS */ |
Branch: 1 branch
| Branch | True | False | Total |
| SvREFCNT_inc_simple_void(nsv); /* Or it will be destroyed in FREETMPS */ |
135 |
0 |
135 |
|
| 807 |
|
| #else |
| 808 |
|
| nsv = sv_newref(nsv); /* Workaround some bug in SvREFCNT_inc() */ |
| 809 |
|
| #endif |
| 810 |
135 |
| PUTBACK; |
| 811 |
|
| |
| 812 |
135 |
| POPSTACK; |
| 813 |
|
| |
| 814 |
135 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
135 |
0 |
135 |
|
| 815 |
135 |
| LEAVE; |
| 816 |
|
| |
| 817 |
135 |
| return nsv; |
| 818 |
|
| } |
| 819 |
|
| |
| 820 |
69 |
| static SV *vmg_data_get(pTHX_ SV *sv, const vmg_wizard *w) { |
| 821 |
|
| #define vmg_data_get(S, W) vmg_data_get(aTHX_ (S), (W)) |
| 822 |
69 |
| const MAGIC *mg = vmg_find(sv, w); |
| 823 |
|
| |
| 824 |
69 |
▶ | return mg ? mg->mg_obj : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return mg ? mg->mg_obj : NULL; |
48 |
21 |
69 |
|
| 825 |
|
| } |
| 826 |
|
| |
| 827 |
|
| /* ... Magic cast/dispell .................................................. */ |
| 828 |
|
| |
| 829 |
|
| #if VMG_UVAR |
| 830 |
|
| |
| 831 |
|
| static I32 vmg_svt_val(pTHX_ IV, SV *); |
| 832 |
|
| |
| 833 |
|
| typedef struct { |
| 834 |
|
| struct ufuncs new_uf; |
| 835 |
|
| struct ufuncs old_uf; |
| 836 |
|
| } vmg_uvar_ud; |
| 837 |
|
| |
| 838 |
|
| #endif /* VMG_UVAR */ |
| 839 |
|
| |
| 840 |
128 |
| static void vmg_mg_del(pTHX_ SV *sv, MAGIC *prevmagic, MAGIC *mg, MAGIC *moremagic) { |
| 841 |
|
| #define vmg_mg_del(S, P, M, N) vmg_mg_del(aTHX_ (S), (P), (M), (N)) |
| 842 |
|
| dXSH_CXT; |
| 843 |
|
| |
| 844 |
128 |
▶ | if (prevmagic) |
Branch: 1 branch
| Branch | True | False | Total |
| if (prevmagic) |
23 |
105 |
128 |
|
| 845 |
23 |
| prevmagic->mg_moremagic = moremagic; |
| 846 |
|
| else |
| 847 |
105 |
| SvMAGIC_set(sv, moremagic); |
| 848 |
|
| |
| 849 |
|
| /* Destroy private data */ |
| 850 |
|
| #if VMG_UVAR |
| 851 |
128 |
▶ | if (mg->mg_type == PERL_MAGIC_uvar) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg->mg_type == PERL_MAGIC_uvar) { |
19 |
109 |
128 |
|
| 852 |
19 |
| Safefree(mg->mg_ptr); |
| 853 |
|
| } else { |
| 854 |
|
| #endif /* VMG_UVAR */ |
| 855 |
109 |
▶ | if (mg->mg_obj != sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg->mg_obj != sv) { |
109 |
0 |
109 |
|
| 856 |
109 |
| SvREFCNT_dec(mg->mg_obj); |
| 857 |
109 |
| mg->mg_obj = NULL; |
| 858 |
|
| } |
| 859 |
|
| /* Unreference the wizard */ |
| 860 |
109 |
| SvREFCNT_dec((SV *) mg->mg_ptr); |
| 861 |
109 |
| mg->mg_ptr = NULL; |
| 862 |
|
| #if VMG_UVAR |
| 863 |
|
| } |
| 864 |
|
| #endif /* VMG_UVAR */ |
| 865 |
|
| |
| 866 |
128 |
▶ | if (XSH_CXT.depth) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (XSH_CXT.depth) { |
76 |
52 |
128 |
|
| 867 |
76 |
| mg->mg_moremagic = XSH_CXT.freed_tokens; |
| 868 |
76 |
| XSH_CXT.freed_tokens = mg; |
| 869 |
|
| } else { |
| 870 |
52 |
| mg->mg_moremagic = NULL; |
| 871 |
52 |
| Safefree(mg); |
| 872 |
|
| } |
| 873 |
128 |
| } |
| 874 |
|
| |
| 875 |
68 |
| static int vmg_magic_chain_free(pTHX_ MAGIC *mg, MAGIC *skip) { |
| 876 |
|
| #define vmg_magic_chain_free(M, S) vmg_magic_chain_free(aTHX_ (M), (S)) |
| 877 |
68 |
| int skipped = 0; |
| 878 |
|
| |
| 879 |
144 |
▶ | while (mg) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (mg) { |
76 |
68 |
144 |
|
| 880 |
76 |
| MAGIC *moremagic = mg->mg_moremagic; |
| 881 |
|
| |
| 882 |
76 |
▶ | if (mg == skip) |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg == skip) |
3 |
73 |
76 |
|
| 883 |
3 |
| ++skipped; |
| 884 |
|
| else |
| 885 |
73 |
| Safefree(mg); |
| 886 |
|
| |
| 887 |
76 |
| mg = moremagic; |
| 888 |
|
| } |
| 889 |
|
| |
| 890 |
68 |
| return skipped; |
| 891 |
|
| } |
| 892 |
|
| |
| 893 |
312 |
| static UV vmg_cast(pTHX_ SV *sv, const vmg_wizard *w, const SV *wiz, SV **args, I32 items) { |
| 894 |
|
| #define vmg_cast(S, W, WIZ, A, I) vmg_cast(aTHX_ (S), (W), (WIZ), (A), (I)) |
| 895 |
|
| MAGIC *mg; |
| 896 |
|
| MGVTBL *t; |
| 897 |
|
| SV *data; |
| 898 |
|
| U32 oldgmg; |
| 899 |
|
| |
| 900 |
312 |
▶ | if (vmg_find(sv, w)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (vmg_find(sv, w)) |
1 |
311 |
312 |
|
| 901 |
1 |
| return 1; |
| 902 |
|
| |
| 903 |
311 |
| oldgmg = SvGMAGICAL(sv); |
| 904 |
|
| |
| 905 |
311 |
▶ | data = (w->cb_data) ? vmg_data_new(w->cb_data, sv, args, items) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| data = (w->cb_data) ? vmg_data_new(w->cb_data, sv, args, items) : NULL; |
143 |
168 |
311 |
|
| 906 |
|
| |
| 907 |
303 |
| t = vmg_vtable_vtbl(w->vtable); |
| 908 |
303 |
| mg = vmg_sv_magicext(sv, data, t, wiz, HEf_SVKEY); |
| 909 |
|
| |
| 910 |
303 |
▶ | if (SvTYPE(sv) < SVt_PVHV) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(sv) < SVt_PVHV) |
231 |
72 |
303 |
|
| 911 |
231 |
| goto done; |
| 912 |
|
| |
| 913 |
|
| /* The GMAGICAL flag only says that a hash is tied or has uvar magic - get |
| 914 |
|
| * magic is actually never called for them. If the GMAGICAL flag was off before |
| 915 |
|
| * calling sv_magicext(), the hash isn't tied and has no uvar magic. If it's |
| 916 |
|
| * now on, then this wizard has get magic. Hence we can work around the |
| 917 |
|
| * get/clear shortcoming by turning the GMAGICAL flag off. If the current magic |
| 918 |
|
| * has uvar callbacks, it will be turned back on later. */ |
| 919 |
72 |
▶ | if (!oldgmg && SvGMAGICAL(sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!oldgmg && SvGMAGICAL(sv)) |
60 |
12 |
72 |
| if (!oldgmg && SvGMAGICAL(sv)) |
6 |
54 |
60 |
|
| 920 |
6 |
| SvGMAGICAL_off(sv); |
| 921 |
|
| |
| 922 |
|
| #if VMG_UVAR |
| 923 |
72 |
▶ | if (w->uvar) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->uvar) { |
29 |
43 |
72 |
|
| 924 |
43 |
| MAGIC *prevmagic, *moremagic = NULL; |
| 925 |
|
| vmg_uvar_ud ud; |
| 926 |
|
| |
| 927 |
43 |
| ud.new_uf.uf_val = vmg_svt_val; |
| 928 |
43 |
| ud.new_uf.uf_set = NULL; |
| 929 |
43 |
| ud.new_uf.uf_index = 0; |
| 930 |
43 |
| ud.old_uf.uf_val = NULL; |
| 931 |
43 |
| ud.old_uf.uf_set = NULL; |
| 932 |
43 |
| ud.old_uf.uf_index = 0; |
| 933 |
|
| |
| 934 |
|
| /* One uvar magic in the chain is enough. */ |
| 935 |
88 |
▶ | for (prevmagic = NULL, mg = SvMAGIC(sv); mg; prevmagic = mg, mg = moremagic) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (prevmagic = NULL, mg = SvMAGIC(sv); mg; prevmagic = mg, mg = moremagic) { |
48 |
40 |
88 |
|
| 936 |
48 |
| moremagic = mg->mg_moremagic; |
| 937 |
48 |
▶ | if (mg->mg_type == PERL_MAGIC_uvar) |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg->mg_type == PERL_MAGIC_uvar) |
3 |
45 |
48 |
|
| 938 |
3 |
| break; |
| 939 |
|
| } |
| 940 |
|
| |
| 941 |
43 |
▶ | if (mg) { /* Found another uvar magic. */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg) { /* Found another uvar magic. */ |
3 |
40 |
43 |
|
| 942 |
3 |
| struct ufuncs *uf = (struct ufuncs *) mg->mg_ptr; |
| 943 |
3 |
▶ | if (uf->uf_val == vmg_svt_val) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (uf->uf_val == vmg_svt_val) { |
2 |
1 |
3 |
|
| 944 |
|
| /* It's our uvar magic, nothing to do. oldgmg was true. */ |
| 945 |
2 |
| goto done; |
| 946 |
|
| } else { |
| 947 |
|
| /* It's another uvar magic, backup it and replace it by ours. */ |
| 948 |
1 |
| ud.old_uf = *uf; |
| 949 |
1 |
| vmg_mg_del(sv, prevmagic, mg, moremagic); |
| 950 |
|
| } |
| 951 |
|
| } |
| 952 |
|
| |
| 953 |
41 |
| sv_magic(sv, NULL, PERL_MAGIC_uvar, (const char *) &ud, sizeof(ud)); |
| 954 |
41 |
| vmg_mg_magical(sv); |
| 955 |
|
| /* Our hash now carries uvar magic. The uvar/clear shortcoming has to be |
| 956 |
|
| * handled by our uvar callback. */ |
| 957 |
|
| } |
| 958 |
|
| #endif /* VMG_UVAR */ |
| 959 |
|
| |
| 960 |
29 |
| done: |
| 961 |
303 |
| return 1; |
| 962 |
|
| } |
| 963 |
|
| |
| 964 |
57 |
| static UV vmg_dispell(pTHX_ SV *sv, const vmg_wizard *w) { |
| 965 |
|
| #define vmg_dispell(S, W) vmg_dispell(aTHX_ (S), (W)) |
| 966 |
|
| #if VMG_UVAR |
| 967 |
57 |
| U32 uvars = 0; |
| 968 |
|
| #endif /* VMG_UVAR */ |
| 969 |
57 |
| MAGIC *mg, *prevmagic, *moremagic = NULL; |
| 970 |
57 |
| IV wid = vmg_wizard_id(w); |
| 971 |
|
| |
| 972 |
57 |
▶ | if (SvTYPE(sv) < SVt_PVMG) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(sv) < SVt_PVMG) |
1 |
56 |
57 |
|
| 973 |
1 |
| return 0; |
| 974 |
|
| |
| 975 |
78 |
▶ | for (prevmagic = NULL, mg = SvMAGIC(sv); mg; prevmagic = mg, mg = moremagic) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (prevmagic = NULL, mg = SvMAGIC(sv); mg; prevmagic = mg, mg = moremagic) { |
77 |
1 |
78 |
|
| 976 |
|
| const vmg_wizard *z; |
| 977 |
|
| |
| 978 |
77 |
| moremagic = mg->mg_moremagic; |
| 979 |
|
| |
| 980 |
77 |
| z = vmg_wizard_from_mg(mg); |
| 981 |
77 |
▶ | if (z) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (z) { |
58 |
19 |
77 |
|
| 982 |
58 |
| IV zid = vmg_wizard_id(z); |
| 983 |
|
| |
| 984 |
|
| #if VMG_UVAR |
| 985 |
58 |
▶ | if (zid == wid) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (zid == wid) { |
55 |
3 |
58 |
|
| 986 |
|
| /* If the current has no uvar, short-circuit uvar deletion. */ |
| 987 |
55 |
▶ | uvars = z->uvar ? (uvars + 1) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| uvars = z->uvar ? (uvars + 1) : 0; |
24 |
31 |
55 |
|
| 988 |
55 |
| break; |
| 989 |
3 |
▶ | } else if (z->uvar) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (z->uvar) { |
1 |
2 |
3 |
|
| 990 |
1 |
| ++uvars; |
| 991 |
|
| /* We can't break here since we need to find the ext magic to delete. */ |
| 992 |
|
| } |
| 993 |
|
| #else /* VMG_UVAR */ |
| 994 |
|
| if (zid == wid) |
| 995 |
|
| break; |
| 996 |
|
| #endif /* !VMG_UVAR */ |
| 997 |
|
| } |
| 998 |
|
| } |
| 999 |
56 |
▶ | if (!mg) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!mg) |
1 |
55 |
56 |
|
| 1000 |
1 |
| return 0; |
| 1001 |
|
| |
| 1002 |
55 |
| vmg_mg_del(sv, prevmagic, mg, moremagic); |
| 1003 |
|
| |
| 1004 |
|
| #if VMG_UVAR |
| 1005 |
55 |
▶ | if (uvars == 1 && SvTYPE(sv) >= SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (uvars == 1 && SvTYPE(sv) >= SVt_PVHV) { |
23 |
32 |
55 |
| if (uvars == 1 && SvTYPE(sv) >= SVt_PVHV) { |
20 |
3 |
23 |
|
| 1006 |
|
| /* mg was the first ext magic in the chain that had uvar */ |
| 1007 |
|
| |
| 1008 |
21 |
▶ | for (mg = moremagic; mg; mg = mg->mg_moremagic) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (mg = moremagic; mg; mg = mg->mg_moremagic) { |
2 |
19 |
21 |
|
| 1009 |
2 |
| const vmg_wizard *z = vmg_wizard_from_mg(mg); |
| 1010 |
|
| |
| 1011 |
2 |
▶ | if (z && z->uvar) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (z && z->uvar) { |
1 |
1 |
2 |
| if (z && z->uvar) { |
1 |
0 |
1 |
|
| 1012 |
1 |
| ++uvars; |
| 1013 |
1 |
| break; |
| 1014 |
|
| } |
| 1015 |
|
| } |
| 1016 |
|
| |
| 1017 |
20 |
▶ | if (uvars == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (uvars == 1) { |
19 |
1 |
20 |
|
| 1018 |
|
| vmg_uvar_ud *ud; |
| 1019 |
|
| |
| 1020 |
19 |
▶ | for (prevmagic = NULL, mg = SvMAGIC(sv); mg; prevmagic = mg, mg = moremagic){ |
Branch: 1 branch
| Branch | True | False | Total |
| for (prevmagic = NULL, mg = SvMAGIC(sv); mg; prevmagic = mg, mg = moremagic){ |
19 |
0 |
19 |
|
| 1021 |
19 |
| moremagic = mg->mg_moremagic; |
| 1022 |
19 |
▶ | if (mg->mg_type == PERL_MAGIC_uvar) |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg->mg_type == PERL_MAGIC_uvar) |
19 |
0 |
19 |
|
| 1023 |
19 |
| break; |
| 1024 |
|
| } |
| 1025 |
|
| |
| 1026 |
19 |
| ud = (vmg_uvar_ud *) mg->mg_ptr; |
| 1027 |
19 |
▶ | if (ud->old_uf.uf_val || ud->old_uf.uf_set) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ud->old_uf.uf_val || ud->old_uf.uf_set) { |
18 |
1 |
19 |
| if (ud->old_uf.uf_val || ud->old_uf.uf_set) { |
0 |
18 |
18 |
|
| 1028 |
|
| /* Revert the original uvar magic. */ |
| 1029 |
|
| struct ufuncs *uf; |
| 1030 |
1 |
| Newx(uf, 1, struct ufuncs); |
| 1031 |
1 |
| *uf = ud->old_uf; |
| 1032 |
1 |
| Safefree(ud); |
| 1033 |
1 |
| mg->mg_ptr = (char *) uf; |
| 1034 |
1 |
| mg->mg_len = sizeof(*uf); |
| 1035 |
|
| } else { |
| 1036 |
|
| /* Remove the uvar magic. */ |
| 1037 |
18 |
| vmg_mg_del(sv, prevmagic, mg, moremagic); |
| 1038 |
|
| } |
| 1039 |
|
| } |
| 1040 |
|
| } |
| 1041 |
|
| #endif /* VMG_UVAR */ |
| 1042 |
|
| |
| 1043 |
55 |
| vmg_mg_magical(sv); |
| 1044 |
|
| |
| 1045 |
55 |
| return 1; |
| 1046 |
|
| } |
| 1047 |
|
| |
| 1048 |
|
| /* ... OP info ............................................................. */ |
| 1049 |
|
| |
| 1050 |
|
| #define VMG_OP_INFO_NAME 1 |
| 1051 |
|
| #define VMG_OP_INFO_OBJECT 2 |
| 1052 |
|
| |
| 1053 |
|
| #if XSH_THREADSAFE |
| 1054 |
|
| static perl_mutex vmg_op_name_init_mutex; |
| 1055 |
|
| #endif |
| 1056 |
|
| |
| 1057 |
|
| static U32 vmg_op_name_init = 0; |
| 1058 |
|
| static unsigned char vmg_op_name_len[MAXO] = { 0 }; |
| 1059 |
|
| |
| 1060 |
41 |
| static void vmg_op_info_init(pTHX_ unsigned int opinfo) { |
| 1061 |
|
| #define vmg_op_info_init(W) vmg_op_info_init(aTHX_ (W)) |
| 1062 |
41 |
| switch (opinfo) { |
| 1063 |
20 |
| case VMG_OP_INFO_NAME: |
| 1064 |
|
| XSH_LOCK(&vmg_op_name_init_mutex); |
| 1065 |
20 |
▶ | if (!vmg_op_name_init) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!vmg_op_name_init) { |
2 |
18 |
20 |
|
| 1066 |
|
| OPCODE t; |
| 1067 |
860 |
▶ | for (t = 0; t < OP_max; ++t) |
Branch: 1 branch
| Branch | True | False | Total |
| for (t = 0; t < OP_max; ++t) |
858 |
2 |
860 |
|
| 1068 |
858 |
| vmg_op_name_len[t] = strlen(PL_op_name[t]); |
| 1069 |
2 |
| vmg_op_name_init = 1; |
| 1070 |
|
| } |
| 1071 |
|
| XSH_UNLOCK(&vmg_op_name_init_mutex); |
| 1072 |
20 |
| break; |
| 1073 |
20 |
| case VMG_OP_INFO_OBJECT: { |
| 1074 |
|
| dXSH_CXT; |
| 1075 |
20 |
▶ | if (!XSH_CXT.b__op_stashes[0]) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!XSH_CXT.b__op_stashes[0]) { |
2 |
18 |
20 |
|
| 1076 |
|
| int c; |
| 1077 |
2 |
| require_pv("B.pm"); |
| 1078 |
30 |
▶ | for (c = OPc_NULL; c < OPc_MAX; ++c) |
Branch: 1 branch
| Branch | True | False | Total |
| for (c = OPc_NULL; c < OPc_MAX; ++c) |
28 |
2 |
30 |
|
| 1079 |
28 |
| XSH_CXT.b__op_stashes[c] = gv_stashpv(vmg_opclassnames[c], 1); |
| 1080 |
|
| } |
| 1081 |
20 |
| break; |
| 1082 |
|
| } |
| 1083 |
1 |
| default: |
| 1084 |
1 |
| break; |
| 1085 |
|
| } |
| 1086 |
41 |
| } |
| 1087 |
|
| |
| 1088 |
47 |
| static SV *vmg_op_info(pTHX_ unsigned int opinfo) { |
| 1089 |
|
| #define vmg_op_info(W) vmg_op_info(aTHX_ (W)) |
| 1090 |
47 |
▶ | if (!PL_op) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!PL_op) |
6 |
41 |
47 |
|
| 1091 |
6 |
| return &PL_sv_undef; |
| 1092 |
|
| |
| 1093 |
41 |
| switch (opinfo) { |
| 1094 |
20 |
| case VMG_OP_INFO_NAME: { |
| 1095 |
|
| const char *name; |
| 1096 |
|
| STRLEN name_len; |
| 1097 |
20 |
| OPCODE t = PL_op->op_type; |
| 1098 |
20 |
▶ | name = OP_NAME(PL_op); |
Branch: 1 branch
| Branch | True | False | Total |
| name = OP_NAME(PL_op); |
0 |
20 |
20 |
|
| 1099 |
20 |
▶ | name_len = (t == OP_CUSTOM) ? strlen(name) : vmg_op_name_len[t]; |
Branch: 1 branch
| Branch | True | False | Total |
| name_len = (t == OP_CUSTOM) ? strlen(name) : vmg_op_name_len[t]; |
0 |
20 |
20 |
|
| 1100 |
20 |
| return sv_2mortal(newSVpvn(name, name_len)); |
| 1101 |
|
| } |
| 1102 |
20 |
| case VMG_OP_INFO_OBJECT: { |
| 1103 |
|
| dXSH_CXT; |
| 1104 |
20 |
| return sv_bless(sv_2mortal(newRV_noinc(newSViv(PTR2IV(PL_op)))), |
| 1105 |
|
| XSH_CXT.b__op_stashes[vmg_opclass(PL_op)]); |
| 1106 |
|
| } |
| 1107 |
1 |
| default: |
| 1108 |
1 |
| break; |
| 1109 |
|
| } |
| 1110 |
|
| |
| 1111 |
1 |
| return &PL_sv_undef; |
| 1112 |
|
| } |
| 1113 |
|
| |
| 1114 |
|
| /* --- svt callbacks ------------------------------------------------------- */ |
| 1115 |
|
| |
| 1116 |
|
| #define VMG_CB_CALL_ARGS_MASK 15 |
| 1117 |
|
| #define VMG_CB_CALL_ARGS_SHIFT 4 |
| 1118 |
|
| #define VMG_CB_CALL_OPINFO (VMG_OP_INFO_NAME|VMG_OP_INFO_OBJECT) /* 1|2 */ |
| 1119 |
|
| #define VMG_CB_CALL_GUARD 4 |
| 1120 |
|
| |
| 1121 |
65 |
| static int vmg_dispell_guard_oncroak(pTHX_ void *ud) { |
| 1122 |
|
| dXSH_CXT; |
| 1123 |
|
| |
| 1124 |
65 |
| XSH_CXT.depth--; |
| 1125 |
|
| |
| 1126 |
|
| /* If we're at the upmost magic call and we're about to die, we can just free |
| 1127 |
|
| * the tokens right now, since we will jump past the problematic part of our |
| 1128 |
|
| * caller. */ |
| 1129 |
65 |
▶ | if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) { |
65 |
0 |
65 |
| if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) { |
61 |
4 |
65 |
|
| 1130 |
61 |
| vmg_magic_chain_free(XSH_CXT.freed_tokens, NULL); |
| 1131 |
61 |
| XSH_CXT.freed_tokens = NULL; |
| 1132 |
|
| } |
| 1133 |
|
| |
| 1134 |
65 |
| return 1; |
| 1135 |
|
| } |
| 1136 |
|
| |
| 1137 |
4 |
| static int vmg_dispell_guard_free(pTHX_ SV *sv, MAGIC *mg) { |
| 1138 |
4 |
| vmg_magic_chain_free((MAGIC *) mg->mg_ptr, NULL); |
| 1139 |
|
| |
| 1140 |
4 |
| return 0; |
| 1141 |
|
| } |
| 1142 |
|
| |
| 1143 |
|
| #if XSH_THREADSAFE |
| 1144 |
|
| |
| 1145 |
|
| static int vmg_dispell_guard_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *params) { |
| 1146 |
|
| /* The freed magic tokens aren't cloned by perl because it cannot reach them |
| 1147 |
|
| * (they have been detached from their parent SV when they were enqueued). |
| 1148 |
|
| * Hence there's nothing to purge in the new thread. */ |
| 1149 |
|
| mg->mg_ptr = NULL; |
| 1150 |
|
| |
| 1151 |
|
| return 0; |
| 1152 |
|
| } |
| 1153 |
|
| |
| 1154 |
|
| #endif /* XSH_THREADSAFE */ |
| 1155 |
|
| |
| 1156 |
|
| static MGVTBL vmg_dispell_guard_vtbl = { |
| 1157 |
|
| NULL, /* get */ |
| 1158 |
|
| NULL, /* set */ |
| 1159 |
|
| NULL, /* len */ |
| 1160 |
|
| NULL, /* clear */ |
| 1161 |
|
| vmg_dispell_guard_free, /* free */ |
| 1162 |
|
| NULL, /* copy */ |
| 1163 |
|
| #if XSH_THREADSAFE |
| 1164 |
|
| vmg_dispell_guard_dup, /* dup */ |
| 1165 |
|
| #else |
| 1166 |
|
| NULL, /* dup */ |
| 1167 |
|
| #endif |
| 1168 |
|
| #if MGf_LOCAL |
| 1169 |
|
| NULL, /* local */ |
| 1170 |
|
| #endif /* MGf_LOCAL */ |
| 1171 |
|
| }; |
| 1172 |
|
| |
| 1173 |
4 |
| static SV *vmg_dispell_guard_new(pTHX_ MAGIC *root) { |
| 1174 |
|
| #define vmg_dispell_guard_new(R) vmg_dispell_guard_new(aTHX_ (R)) |
| 1175 |
|
| SV *guard; |
| 1176 |
|
| |
| 1177 |
4 |
| guard = sv_newmortal(); |
| 1178 |
4 |
| vmg_sv_magicext(guard, NULL, &vmg_dispell_guard_vtbl, root, 0); |
| 1179 |
|
| |
| 1180 |
4 |
| return guard; |
| 1181 |
|
| } |
| 1182 |
|
| |
| 1183 |
373 |
| static int vmg_cb_call(pTHX_ SV *cb, unsigned int flags, SV *sv, ...) { |
| 1184 |
|
| va_list ap; |
| 1185 |
373 |
| int ret = 0; |
| 1186 |
|
| unsigned int i, args, opinfo; |
| 1187 |
373 |
| MAGIC **chain = NULL; |
| 1188 |
|
| SV *svr; |
| 1189 |
|
| |
| 1190 |
373 |
| dSP; |
| 1191 |
|
| |
| 1192 |
373 |
| args = flags & VMG_CB_CALL_ARGS_MASK; |
| 1193 |
373 |
| flags >>= VMG_CB_CALL_ARGS_SHIFT; |
| 1194 |
373 |
| opinfo = flags & VMG_CB_CALL_OPINFO; |
| 1195 |
|
| |
| 1196 |
373 |
| ENTER; |
| 1197 |
373 |
| SAVETMPS; |
| 1198 |
|
| |
| 1199 |
373 |
| PUSHSTACKi(PERLSI_MAGIC); |
| 1200 |
|
| |
| 1201 |
373 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
373 |
373 |
|
| 1202 |
373 |
▶ | EXTEND(SP, args + 1); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, args + 1); |
0 |
373 |
373 |
|
| 1203 |
373 |
| PUSHs(sv_2mortal(newRV_inc(sv))); |
| 1204 |
373 |
| va_start(ap, sv); |
| 1205 |
950 |
▶ | for (i = 0; i < args; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < args; ++i) { |
577 |
373 |
950 |
|
| 1206 |
577 |
| SV *sva = va_arg(ap, SV *); |
| 1207 |
577 |
▶ | PUSHs(sva ? sva : &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(sva ? sva : &PL_sv_undef); |
341 |
236 |
577 |
|
| 1208 |
|
| } |
| 1209 |
373 |
| va_end(ap); |
| 1210 |
373 |
▶ | if (opinfo) |
Branch: 1 branch
| Branch | True | False | Total |
| if (opinfo) |
41 |
332 |
373 |
|
| 1211 |
41 |
▶ | XPUSHs(vmg_op_info(opinfo)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(vmg_op_info(opinfo)); |
0 |
41 |
41 |
|
| 1212 |
373 |
| PUTBACK; |
| 1213 |
|
| |
| 1214 |
373 |
▶ | if (flags & VMG_CB_CALL_GUARD) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & VMG_CB_CALL_GUARD) { |
144 |
229 |
373 |
|
| 1215 |
|
| dXSH_CXT; |
| 1216 |
144 |
| XSH_CXT.depth++; |
| 1217 |
144 |
| vmg_call_sv(cb, G_SCALAR, vmg_dispell_guard_oncroak, NULL); |
| 1218 |
136 |
| XSH_CXT.depth--; |
| 1219 |
136 |
▶ | if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) |
Branch: 2 branches
| Branch | True | False | Total |
| if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) |
134 |
2 |
136 |
| if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) |
4 |
130 |
134 |
|
| 1220 |
4 |
| chain = &XSH_CXT.freed_tokens; |
| 1221 |
|
| } else { |
| 1222 |
229 |
| vmg_call_sv(cb, G_SCALAR, 0, NULL); |
| 1223 |
|
| } |
| 1224 |
|
| |
| 1225 |
341 |
| SPAGAIN; |
| 1226 |
341 |
| svr = POPs; |
| 1227 |
341 |
▶ | if (SvOK(svr)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(svr)) |
208 |
133 |
341 |
|
| 1228 |
208 |
| ret = (int) SvIV(svr); |
| 1229 |
341 |
▶ | if (SvROK(svr)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(svr)) |
23 |
318 |
341 |
|
| 1230 |
23 |
| SvREFCNT_inc(svr); |
| 1231 |
|
| else |
| 1232 |
318 |
| svr = NULL; |
| 1233 |
341 |
| PUTBACK; |
| 1234 |
|
| |
| 1235 |
341 |
| POPSTACK; |
| 1236 |
|
| |
| 1237 |
341 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
341 |
0 |
341 |
|
| 1238 |
341 |
| LEAVE; |
| 1239 |
|
| |
| 1240 |
341 |
▶ | if (svr && !SvTEMP(svr)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (svr && !SvTEMP(svr)) |
23 |
318 |
341 |
| if (svr && !SvTEMP(svr)) |
23 |
0 |
23 |
|
| 1241 |
23 |
| sv_2mortal(svr); |
| 1242 |
|
| |
| 1243 |
341 |
▶ | if (chain) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (chain) { |
4 |
337 |
341 |
|
| 1244 |
4 |
| vmg_dispell_guard_new(*chain); |
| 1245 |
4 |
| *chain = NULL; |
| 1246 |
|
| } |
| 1247 |
|
| |
| 1248 |
341 |
| return ret; |
| 1249 |
|
| } |
| 1250 |
|
| |
| 1251 |
|
| #define VMG_CB_FLAGS(OI, A) \ |
| 1252 |
|
| ((((unsigned int) (OI)) << VMG_CB_CALL_ARGS_SHIFT) | (A)) |
| 1253 |
|
| |
| 1254 |
|
| #define vmg_cb_call1(I, OI, S, A1) \ |
| 1255 |
|
| vmg_cb_call(aTHX_ (I), VMG_CB_FLAGS((OI), 1), (S), (A1)) |
| 1256 |
|
| #define vmg_cb_call2(I, OI, S, A1, A2) \ |
| 1257 |
|
| vmg_cb_call(aTHX_ (I), VMG_CB_FLAGS((OI), 2), (S), (A1), (A2)) |
| 1258 |
|
| #define vmg_cb_call3(I, OI, S, A1, A2, A3) \ |
| 1259 |
|
| vmg_cb_call(aTHX_ (I), VMG_CB_FLAGS((OI), 3), (S), (A1), (A2), (A3)) |
| 1260 |
|
| |
| 1261 |
|
| /* ... Default no-op magic callback ........................................ */ |
| 1262 |
|
| |
| 1263 |
7 |
| static int vmg_svt_default_noop(pTHX_ SV *sv, MAGIC *mg) { |
| 1264 |
7 |
| return 0; |
| 1265 |
|
| } |
| 1266 |
|
| |
| 1267 |
|
| /* ... get magic ........................................................... */ |
| 1268 |
|
| |
| 1269 |
82 |
| static int vmg_svt_get(pTHX_ SV *sv, MAGIC *mg) { |
| 1270 |
82 |
| const vmg_wizard *w = vmg_wizard_from_mg_nocheck(mg); |
| 1271 |
|
| |
| 1272 |
82 |
| return vmg_cb_call1(w->cb_get, w->opinfo, sv, mg->mg_obj); |
| 1273 |
|
| } |
| 1274 |
|
| |
| 1275 |
|
| #define vmg_svt_get_noop vmg_svt_default_noop |
| 1276 |
|
| |
| 1277 |
|
| /* ... set magic ........................................................... */ |
| 1278 |
|
| |
| 1279 |
90 |
| static int vmg_svt_set(pTHX_ SV *sv, MAGIC *mg) { |
| 1280 |
90 |
| const vmg_wizard *w = vmg_wizard_from_mg_nocheck(mg); |
| 1281 |
|
| |
| 1282 |
90 |
| return vmg_cb_call1(w->cb_set, w->opinfo, sv, mg->mg_obj); |
| 1283 |
|
| } |
| 1284 |
|
| |
| 1285 |
|
| #define vmg_svt_set_noop vmg_svt_default_noop |
| 1286 |
|
| |
| 1287 |
|
| /* ... len magic ........................................................... */ |
| 1288 |
|
| |
| 1289 |
0 |
| static U32 vmg_sv_len(pTHX_ SV *sv) { |
| 1290 |
|
| #define vmg_sv_len(S) vmg_sv_len(aTHX_ (S)) |
| 1291 |
|
| STRLEN len; |
| 1292 |
|
| #if XSH_HAS_PERL(5, 9, 3) |
| 1293 |
0 |
| const U8 *s = VOID2(const U8 *, VOID2(const void *, SvPV_const(sv, len))); |
| 1294 |
|
| #else |
| 1295 |
|
| U8 *s = SvPV(sv, len); |
| 1296 |
|
| #endif |
| 1297 |
|
| |
| 1298 |
0 |
▶ | return DO_UTF8(sv) ? utf8_length(s, s + len) : len; |
Branch: 2 branches
| Branch | True | False | Total |
| return DO_UTF8(sv) ? utf8_length(s, s + len) : len; |
0 |
0 |
0 |
| return DO_UTF8(sv) ? utf8_length(s, s + len) : len; |
0 |
0 |
0 |
|
| 1299 |
|
| } |
| 1300 |
|
| |
| 1301 |
36 |
| static U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { |
| 1302 |
36 |
| const vmg_wizard *w = vmg_wizard_from_mg_nocheck(mg); |
| 1303 |
36 |
| unsigned int opinfo = w->opinfo; |
| 1304 |
|
| U32 len, ret; |
| 1305 |
|
| SV *svr; |
| 1306 |
36 |
| svtype t = SvTYPE(sv); |
| 1307 |
|
| |
| 1308 |
36 |
| dSP; |
| 1309 |
|
| |
| 1310 |
36 |
| ENTER; |
| 1311 |
36 |
| SAVETMPS; |
| 1312 |
|
| |
| 1313 |
36 |
| PUSHSTACKi(PERLSI_MAGIC); |
| 1314 |
|
| |
| 1315 |
36 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
36 |
36 |
|
| 1316 |
36 |
▶ | EXTEND(SP, 3); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 3); |
0 |
36 |
36 |
|
| 1317 |
36 |
| PUSHs(sv_2mortal(newRV_inc(sv))); |
| 1318 |
36 |
▶ | PUSHs(mg->mg_obj ? mg->mg_obj : &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(mg->mg_obj ? mg->mg_obj : &PL_sv_undef); |
9 |
27 |
36 |
|
| 1319 |
36 |
▶ | if (t < SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (t < SVt_PVAV) { |
0 |
36 |
36 |
|
| 1320 |
0 |
| len = vmg_sv_len(sv); |
| 1321 |
0 |
| mPUSHu(len); |
| 1322 |
36 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
36 |
0 |
36 |
|
| 1323 |
36 |
| len = av_len((AV *) sv) + 1; |
| 1324 |
36 |
| mPUSHu(len); |
| 1325 |
|
| } else { |
| 1326 |
0 |
| len = 0; |
| 1327 |
0 |
| PUSHs(&PL_sv_undef); |
| 1328 |
|
| } |
| 1329 |
36 |
▶ | if (opinfo) |
Branch: 1 branch
| Branch | True | False | Total |
| if (opinfo) |
2 |
34 |
36 |
|
| 1330 |
2 |
▶ | XPUSHs(vmg_op_info(opinfo)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(vmg_op_info(opinfo)); |
0 |
2 |
2 |
|
| 1331 |
36 |
| PUTBACK; |
| 1332 |
|
| |
| 1333 |
36 |
| vmg_call_sv(w->cb_len, G_SCALAR, 0, NULL); |
| 1334 |
|
| |
| 1335 |
25 |
| SPAGAIN; |
| 1336 |
25 |
| svr = POPs; |
| 1337 |
25 |
▶ | ret = SvOK(svr) ? (U32) SvUV(svr) : len; |
Branch: 1 branch
| Branch | True | False | Total |
| ret = SvOK(svr) ? (U32) SvUV(svr) : len; |
19 |
6 |
25 |
|
| 1338 |
25 |
▶ | if (t == SVt_PVAV) |
Branch: 1 branch
| Branch | True | False | Total |
| if (t == SVt_PVAV) |
25 |
0 |
25 |
|
| 1339 |
25 |
| --ret; |
| 1340 |
25 |
| PUTBACK; |
| 1341 |
|
| |
| 1342 |
25 |
| POPSTACK; |
| 1343 |
|
| |
| 1344 |
25 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
25 |
0 |
25 |
|
| 1345 |
25 |
| LEAVE; |
| 1346 |
|
| |
| 1347 |
25 |
| return ret; |
| 1348 |
|
| } |
| 1349 |
|
| |
| 1350 |
1 |
| static U32 vmg_svt_len_noop(pTHX_ SV *sv, MAGIC *mg) { |
| 1351 |
1 |
| U32 len = 0; |
| 1352 |
1 |
| svtype t = SvTYPE(sv); |
| 1353 |
|
| |
| 1354 |
1 |
▶ | if (t < SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (t < SVt_PVAV) { |
0 |
1 |
1 |
|
| 1355 |
0 |
| len = vmg_sv_len(sv); |
| 1356 |
1 |
▶ | } else if (t == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (t == SVt_PVAV) { |
1 |
0 |
1 |
|
| 1357 |
1 |
| len = (U32) av_len((AV *) sv); |
| 1358 |
|
| } |
| 1359 |
|
| |
| 1360 |
1 |
| return len; |
| 1361 |
|
| } |
| 1362 |
|
| |
| 1363 |
|
| /* ... clear magic ......................................................... */ |
| 1364 |
|
| |
| 1365 |
25 |
| static int vmg_svt_clear(pTHX_ SV *sv, MAGIC *mg) { |
| 1366 |
25 |
| const vmg_wizard *w = vmg_wizard_from_mg_nocheck(mg); |
| 1367 |
25 |
| unsigned int flags = w->opinfo; |
| 1368 |
|
| |
| 1369 |
|
| #if !XSH_HAS_PERL(5, 12, 0) |
| 1370 |
|
| flags |= VMG_CB_CALL_GUARD; |
| 1371 |
|
| #endif |
| 1372 |
|
| |
| 1373 |
25 |
| return vmg_cb_call1(w->cb_clear, flags, sv, mg->mg_obj); |
| 1374 |
|
| } |
| 1375 |
|
| |
| 1376 |
|
| #define vmg_svt_clear_noop vmg_svt_default_noop |
| 1377 |
|
| |
| 1378 |
|
| /* ... free magic .......................................................... */ |
| 1379 |
|
| |
| 1380 |
|
| #if VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE |
| 1381 |
|
| |
| 1382 |
|
| static OP *vmg_pp_propagate_errsv(pTHX) { |
| 1383 |
|
| SVOP *o = cSVOPx(PL_op); |
| 1384 |
|
| |
| 1385 |
|
| if (o->op_sv) { |
| 1386 |
|
| sv_setsv(ERRSV, o->op_sv); |
| 1387 |
|
| SvREFCNT_dec(o->op_sv); |
| 1388 |
|
| o->op_sv = NULL; |
| 1389 |
|
| } |
| 1390 |
|
| |
| 1391 |
|
| return NORMAL; |
| 1392 |
|
| } |
| 1393 |
|
| |
| 1394 |
|
| #endif /* VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE */ |
| 1395 |
|
| |
| 1396 |
3 |
| static int vmg_propagate_errsv_free(pTHX_ SV *sv, MAGIC *mg) { |
| 1397 |
3 |
▶ | if (mg->mg_obj) |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg->mg_obj) |
3 |
0 |
3 |
|
| 1398 |
3 |
▶ | sv_setsv(ERRSV, mg->mg_obj); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setsv(ERRSV, mg->mg_obj); |
3 |
0 |
3 |
|
| 1399 |
|
| |
| 1400 |
3 |
| return 0; |
| 1401 |
|
| } |
| 1402 |
|
| |
| 1403 |
|
| /* perl is already kind enough to handle the cloning of the mg_obj member, |
| 1404 |
|
| hence we don't need to define a dup magic callback. */ |
| 1405 |
|
| |
| 1406 |
|
| static MGVTBL vmg_propagate_errsv_vtbl = { |
| 1407 |
|
| 0, /* get */ |
| 1408 |
|
| 0, /* set */ |
| 1409 |
|
| 0, /* len */ |
| 1410 |
|
| 0, /* clear */ |
| 1411 |
|
| vmg_propagate_errsv_free, /* free */ |
| 1412 |
|
| 0, /* copy */ |
| 1413 |
|
| 0, /* dup */ |
| 1414 |
|
| #if MGf_LOCAL |
| 1415 |
|
| 0, /* local */ |
| 1416 |
|
| #endif /* MGf_LOCAL */ |
| 1417 |
|
| }; |
| 1418 |
|
| |
| 1419 |
|
| typedef struct { |
| 1420 |
|
| SV *sv; |
| 1421 |
|
| #if VMG_CAREFUL_SELF_DESTRUCTION |
| 1422 |
|
| SV *rsv; /* The ref to the sv currently being freed, pushed on the stack */ |
| 1423 |
|
| #endif |
| 1424 |
|
| int in_eval; |
| 1425 |
|
| I32 base; |
| 1426 |
|
| } vmg_svt_free_cleanup_ud; |
| 1427 |
|
| |
| 1428 |
62 |
| static int vmg_svt_free_cleanup(pTHX_ void *ud_) { |
| 1429 |
62 |
| vmg_svt_free_cleanup_ud *ud = VOID2(vmg_svt_free_cleanup_ud *, ud_); |
| 1430 |
|
| |
| 1431 |
62 |
▶ | if (ud->in_eval) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ud->in_eval) { |
5 |
57 |
62 |
|
| 1432 |
5 |
▶ | U32 optype = PL_op ? PL_op->op_type : OP_NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| U32 optype = PL_op ? PL_op->op_type : OP_NULL; |
3 |
2 |
5 |
|
| 1433 |
|
| |
| 1434 |
5 |
▶ | if (optype == OP_LEAVETRY || optype == OP_LEAVEEVAL) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (optype == OP_LEAVETRY || optype == OP_LEAVEEVAL) { |
2 |
3 |
5 |
| if (optype == OP_LEAVETRY || optype == OP_LEAVEEVAL) { |
0 |
2 |
2 |
|
| 1435 |
3 |
▶ | SV *errsv = newSVsv(ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| SV *errsv = newSVsv(ERRSV); |
3 |
0 |
3 |
|
| 1436 |
|
| |
| 1437 |
3 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
3 |
0 |
3 |
|
| 1438 |
3 |
▶ | LEAVE_SCOPE(ud->base); |
Branch: 1 branch
| Branch | True | False | Total |
| LEAVE_SCOPE(ud->base); |
3 |
0 |
3 |
|
| 1439 |
|
| |
| 1440 |
|
| #if VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE |
| 1441 |
|
| if (optype == OP_LEAVETRY) { |
| 1442 |
|
| dXSH_CXT; |
| 1443 |
|
| PL_op = vmg_trampoline_bump(&XSH_CXT.propagate_errsv, errsv, PL_op); |
| 1444 |
|
| } else if (optype == OP_LEAVEEVAL) { |
| 1445 |
|
| SV *guard = sv_newmortal(); |
| 1446 |
|
| vmg_sv_magicext(guard, errsv, &vmg_propagate_errsv_vtbl, NULL, 0); |
| 1447 |
|
| } |
| 1448 |
|
| #else /* !VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE */ |
| 1449 |
|
| # if !XSH_HAS_PERL(5, 8, 9) |
| 1450 |
|
| { |
| 1451 |
|
| SV *guard = sv_newmortal(); |
| 1452 |
|
| vmg_sv_magicext(guard, errsv, &vmg_propagate_errsv_vtbl, NULL, 0); |
| 1453 |
|
| } |
| 1454 |
|
| # else |
| 1455 |
3 |
▶ | vmg_sv_magicext(ERRSV, errsv, &vmg_propagate_errsv_vtbl, NULL, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| vmg_sv_magicext(ERRSV, errsv, &vmg_propagate_errsv_vtbl, NULL, 0); |
3 |
0 |
3 |
|
| 1456 |
|
| # endif |
| 1457 |
|
| #endif /* VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE */ |
| 1458 |
|
| |
| 1459 |
3 |
| SAVETMPS; |
| 1460 |
|
| } |
| 1461 |
|
| |
| 1462 |
|
| /* Don't propagate */ |
| 1463 |
5 |
| return 0; |
| 1464 |
|
| } else { |
| 1465 |
57 |
| SV *sv = ud->sv; |
| 1466 |
|
| MAGIC *mg; |
| 1467 |
|
| |
| 1468 |
|
| #if VMG_CAREFUL_SELF_DESTRUCTION |
| 1469 |
|
| /* Silently undo the ref - don't trigger destruction in the referent |
| 1470 |
|
| * for a second time */ |
| 1471 |
57 |
▶ | if (SvROK(ud->rsv) && SvRV(ud->rsv) == sv) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(ud->rsv) && SvRV(ud->rsv) == sv) { |
57 |
0 |
57 |
| if (SvROK(ud->rsv) && SvRV(ud->rsv) == sv) { |
57 |
0 |
57 |
|
| 1472 |
57 |
| SvRV_set(ud->rsv, NULL); |
| 1473 |
57 |
| SvROK_off(ud->rsv); |
| 1474 |
57 |
| --SvREFCNT(sv); /* Silent */ |
| 1475 |
|
| } |
| 1476 |
57 |
| SvREFCNT_dec_NN(ud->rsv); |
| 1477 |
|
| #endif |
| 1478 |
|
| |
| 1479 |
|
| /* We are about to croak() while sv is being destroyed. Try to clean up |
| 1480 |
|
| * things a bit. */ |
| 1481 |
57 |
| mg = SvMAGIC(sv); |
| 1482 |
57 |
▶ | if (mg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mg) { |
54 |
3 |
57 |
|
| 1483 |
54 |
| vmg_mg_del(sv, NULL, mg, mg->mg_moremagic); |
| 1484 |
54 |
| mg_magical(sv); |
| 1485 |
|
| } |
| 1486 |
57 |
| SvREFCNT_dec(sv); /* Re-trigger destruction */ |
| 1487 |
|
| |
| 1488 |
57 |
| vmg_dispell_guard_oncroak(aTHX_ NULL); |
| 1489 |
|
| |
| 1490 |
|
| /* After that, propagate the error upwards. */ |
| 1491 |
57 |
| return 1; |
| 1492 |
|
| } |
| 1493 |
|
| } |
| 1494 |
|
| |
| 1495 |
105 |
| static int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) { |
| 1496 |
|
| vmg_svt_free_cleanup_ud ud; |
| 1497 |
|
| const vmg_wizard *w; |
| 1498 |
105 |
| int ret = 0; |
| 1499 |
|
| SV *svr; |
| 1500 |
|
| |
| 1501 |
105 |
| dSP; |
| 1502 |
|
| |
| 1503 |
|
| /* During global destruction, we cannot be sure that the wizard and its free |
| 1504 |
|
| * callback are still alive. */ |
| 1505 |
105 |
▶ | if (PL_dirty) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_dirty) |
0 |
105 |
105 |
|
| 1506 |
0 |
| return 0; |
| 1507 |
|
| |
| 1508 |
105 |
| w = vmg_wizard_from_mg_nocheck(mg); |
| 1509 |
|
| |
| 1510 |
|
| /* So that it survives the temp cleanup below */ |
| 1511 |
105 |
▶ | SvREFCNT_inc_simple_void(sv); |
Branch: 1 branch
| Branch | True | False | Total |
| SvREFCNT_inc_simple_void(sv); |
105 |
0 |
105 |
|
| 1512 |
|
| |
| 1513 |
|
| #if !(XSH_HAS_PERL_MAINT(5, 11, 0, 32686) || XSH_HAS_PERL(5, 12, 0)) |
| 1514 |
|
| /* The previous magic tokens were freed but the magic chain wasn't updated, so |
| 1515 |
|
| * if you access the sv from the callback the old deleted magics will trigger |
| 1516 |
|
| * and cause memory misreads. Change 32686 solved it that way : */ |
| 1517 |
|
| SvMAGIC_set(sv, mg); |
| 1518 |
|
| #endif |
| 1519 |
|
| |
| 1520 |
105 |
| ud.sv = sv; |
| 1521 |
105 |
▶ | if (cxstack_ix < cxstack_max) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cxstack_ix < cxstack_max) { |
105 |
0 |
105 |
|
| 1522 |
105 |
| ud.in_eval = (CxTYPE(cxstack + cxstack_ix + 1) == CXt_EVAL); |
| 1523 |
105 |
▶ | ud.base = ud.in_eval ? PL_scopestack[PL_scopestack_ix] : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| ud.base = ud.in_eval ? PL_scopestack[PL_scopestack_ix] : 0; |
6 |
99 |
105 |
|
| 1524 |
|
| } else { |
| 1525 |
0 |
| ud.in_eval = 0; |
| 1526 |
0 |
| ud.base = 0; |
| 1527 |
|
| } |
| 1528 |
|
| |
| 1529 |
105 |
| ENTER; |
| 1530 |
105 |
| SAVETMPS; |
| 1531 |
|
| |
| 1532 |
105 |
| PUSHSTACKi(PERLSI_MAGIC); |
| 1533 |
|
| |
| 1534 |
105 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
105 |
105 |
|
| 1535 |
105 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
105 |
105 |
|
| 1536 |
|
| /* This will bump the refcount of sv from 0 to 1 */ |
| 1537 |
|
| #if VMG_CAREFUL_SELF_DESTRUCTION |
| 1538 |
105 |
| ud.rsv = newRV_inc(sv); |
| 1539 |
105 |
| PUSHs(ud.rsv); |
| 1540 |
|
| #else |
| 1541 |
|
| PUSHs(sv_2mortal(newRV_inc(sv))); |
| 1542 |
|
| #endif |
| 1543 |
105 |
▶ | PUSHs(mg->mg_obj ? mg->mg_obj : &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(mg->mg_obj ? mg->mg_obj : &PL_sv_undef); |
35 |
70 |
105 |
|
| 1544 |
105 |
▶ | if (w->opinfo) |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->opinfo) |
4 |
101 |
105 |
|
| 1545 |
4 |
▶ | XPUSHs(vmg_op_info(w->opinfo)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(vmg_op_info(w->opinfo)); |
0 |
4 |
4 |
|
| 1546 |
105 |
| PUTBACK; |
| 1547 |
|
| |
| 1548 |
|
| { |
| 1549 |
|
| dXSH_CXT; |
| 1550 |
105 |
| XSH_CXT.depth++; |
| 1551 |
105 |
| vmg_call_sv(w->cb_free, G_SCALAR, vmg_svt_free_cleanup, &ud); |
| 1552 |
48 |
| XSH_CXT.depth--; |
| 1553 |
48 |
▶ | if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) { |
45 |
3 |
48 |
| if (XSH_CXT.depth == 0 && XSH_CXT.freed_tokens) { |
3 |
42 |
45 |
|
| 1554 |
|
| /* Free all the tokens in the chain but the current one (if it's present). |
| 1555 |
|
| * It will be taken care of by our caller, Perl_mg_free(). */ |
| 1556 |
3 |
| vmg_magic_chain_free(XSH_CXT.freed_tokens, mg); |
| 1557 |
3 |
| XSH_CXT.freed_tokens = NULL; |
| 1558 |
|
| } |
| 1559 |
|
| } |
| 1560 |
|
| |
| 1561 |
48 |
| SPAGAIN; |
| 1562 |
48 |
| svr = POPs; |
| 1563 |
48 |
▶ | if (SvOK(svr)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(svr)) |
11 |
37 |
48 |
|
| 1564 |
11 |
| ret = (int) SvIV(svr); |
| 1565 |
48 |
| PUTBACK; |
| 1566 |
|
| |
| 1567 |
48 |
| POPSTACK; |
| 1568 |
|
| |
| 1569 |
|
| #if VMG_CAREFUL_SELF_DESTRUCTION |
| 1570 |
|
| /* Silently undo the ref - don't trigger destruction in the referent |
| 1571 |
|
| * for a second time */ |
| 1572 |
48 |
▶ | if (SvROK(ud.rsv) && SvRV(ud.rsv) == sv) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(ud.rsv) && SvRV(ud.rsv) == sv) { |
48 |
0 |
48 |
| if (SvROK(ud.rsv) && SvRV(ud.rsv) == sv) { |
48 |
0 |
48 |
|
| 1573 |
48 |
| SvRV_set(ud.rsv, NULL); |
| 1574 |
48 |
| SvROK_off(ud.rsv); |
| 1575 |
48 |
| --SvREFCNT(sv); /* Silent */ |
| 1576 |
|
| } |
| 1577 |
48 |
| SvREFCNT_dec_NN(ud.rsv); |
| 1578 |
|
| #endif |
| 1579 |
|
| |
| 1580 |
48 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
45 |
3 |
48 |
|
| 1581 |
48 |
| LEAVE; |
| 1582 |
|
| |
| 1583 |
|
| /* Calling SvREFCNT_dec() will trigger destructors in an infinite loop, so |
| 1584 |
|
| * we have to rely on SvREFCNT() being a lvalue. Heck, even the core does it */ |
| 1585 |
48 |
| --SvREFCNT(sv); |
| 1586 |
|
| |
| 1587 |
|
| /* Perl_mg_free will get rid of the magic and decrement mg->mg_obj and |
| 1588 |
|
| * mg->mg_ptr reference count */ |
| 1589 |
48 |
| return ret; |
| 1590 |
|
| } |
| 1591 |
|
| |
| 1592 |
|
| #define vmg_svt_free_noop vmg_svt_default_noop |
| 1593 |
|
| |
| 1594 |
|
| #if XSH_HAS_PERL_MAINT(5, 11, 0, 33256) || XSH_HAS_PERL(5, 12, 0) |
| 1595 |
|
| # define VMG_SVT_COPY_KEYLEN_TYPE I32 |
| 1596 |
|
| #else |
| 1597 |
|
| # define VMG_SVT_COPY_KEYLEN_TYPE int |
| 1598 |
|
| #endif |
| 1599 |
|
| |
| 1600 |
|
| /* ... copy magic .......................................................... */ |
| 1601 |
|
| |
| 1602 |
30 |
| static int vmg_svt_copy(pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *key, VMG_SVT_COPY_KEYLEN_TYPE keylen) { |
| 1603 |
30 |
| const vmg_wizard *w = vmg_wizard_from_mg_nocheck(mg); |
| 1604 |
|
| SV *keysv; |
| 1605 |
|
| int ret; |
| 1606 |
|
| |
| 1607 |
30 |
▶ | if (keylen == HEf_SVKEY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (keylen == HEf_SVKEY) { |
20 |
10 |
30 |
|
| 1608 |
20 |
| keysv = (SV *) key; |
| 1609 |
|
| } else { |
| 1610 |
10 |
| keysv = newSVpvn(key, keylen); |
| 1611 |
|
| } |
| 1612 |
|
| |
| 1613 |
30 |
▶ | if (SvTYPE(sv) >= SVt_PVCV) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(sv) >= SVt_PVCV) |
1 |
29 |
30 |
|
| 1614 |
1 |
| nsv = sv_2mortal(newRV_inc(nsv)); |
| 1615 |
|
| |
| 1616 |
30 |
| ret = vmg_cb_call3(w->cb_copy, w->opinfo, sv, mg->mg_obj, keysv, nsv); |
| 1617 |
|
| |
| 1618 |
30 |
▶ | if (keylen != HEf_SVKEY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (keylen != HEf_SVKEY) { |
10 |
20 |
30 |
|
| 1619 |
10 |
| SvREFCNT_dec(keysv); |
| 1620 |
|
| } |
| 1621 |
|
| |
| 1622 |
30 |
| return ret; |
| 1623 |
|
| } |
| 1624 |
|
| |
| 1625 |
0 |
| static int vmg_svt_copy_noop(pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *key, VMG_SVT_COPY_KEYLEN_TYPE keylen) { |
| 1626 |
0 |
| return 0; |
| 1627 |
|
| } |
| 1628 |
|
| |
| 1629 |
|
| /* ... dup magic ........................................................... */ |
| 1630 |
|
| |
| 1631 |
|
| #if 0 |
| 1632 |
|
| static int vmg_svt_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param) { |
| 1633 |
|
| return 0; |
| 1634 |
|
| } |
| 1635 |
|
| #define vmg_svt_dup_noop vmg_svt_dup |
| 1636 |
|
| #endif |
| 1637 |
|
| |
| 1638 |
|
| /* ... local magic ......................................................... */ |
| 1639 |
|
| |
| 1640 |
|
| #if MGf_LOCAL |
| 1641 |
|
| |
| 1642 |
2 |
| static int vmg_svt_local(pTHX_ SV *nsv, MAGIC *mg) { |
| 1643 |
2 |
| const vmg_wizard *w = vmg_wizard_from_mg_nocheck(mg); |
| 1644 |
|
| |
| 1645 |
2 |
| return vmg_cb_call1(w->cb_local, w->opinfo, nsv, mg->mg_obj); |
| 1646 |
|
| } |
| 1647 |
|
| |
| 1648 |
|
| #define vmg_svt_local_noop vmg_svt_default_noop |
| 1649 |
|
| |
| 1650 |
|
| #endif /* MGf_LOCAL */ |
| 1651 |
|
| |
| 1652 |
|
| /* ... uvar magic .......................................................... */ |
| 1653 |
|
| |
| 1654 |
|
| #if VMG_UVAR |
| 1655 |
|
| |
| 1656 |
14 |
| static OP *vmg_pp_reset_rmg(pTHX) { |
| 1657 |
14 |
| SVOP *o = cSVOPx(PL_op); |
| 1658 |
|
| |
| 1659 |
14 |
| SvRMAGICAL_on(o->op_sv); |
| 1660 |
14 |
| o->op_sv = NULL; |
| 1661 |
|
| |
| 1662 |
14 |
| return NORMAL; |
| 1663 |
|
| } |
| 1664 |
|
| |
| 1665 |
168 |
| static I32 vmg_svt_val(pTHX_ IV action, SV *sv) { |
| 1666 |
|
| vmg_uvar_ud *ud; |
| 1667 |
|
| MAGIC *mg, *umg, *moremagic; |
| 1668 |
168 |
| SV *key = NULL, *newkey = NULL; |
| 1669 |
168 |
| int tied = 0; |
| 1670 |
|
| |
| 1671 |
168 |
| umg = mg_find(sv, PERL_MAGIC_uvar); |
| 1672 |
|
| /* umg can't be NULL or we wouldn't be there. */ |
| 1673 |
168 |
| key = umg->mg_obj; |
| 1674 |
168 |
| ud = (vmg_uvar_ud *) umg->mg_ptr; |
| 1675 |
|
| |
| 1676 |
168 |
▶ | if (ud->old_uf.uf_val) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ud->old_uf.uf_val) |
3 |
165 |
168 |
|
| 1677 |
3 |
| ud->old_uf.uf_val(aTHX_ action, sv); |
| 1678 |
168 |
▶ | if (ud->old_uf.uf_set) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ud->old_uf.uf_set) |
0 |
168 |
168 |
|
| 1679 |
0 |
| ud->old_uf.uf_set(aTHX_ action, sv); |
| 1680 |
|
| |
| 1681 |
512 |
▶ | for (mg = SvMAGIC(sv); mg; mg = moremagic) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (mg = SvMAGIC(sv); mg; mg = moremagic) { |
352 |
160 |
512 |
|
| 1682 |
|
| const vmg_wizard *w; |
| 1683 |
|
| |
| 1684 |
|
| /* mg may be freed later by the uvar call, so we need to fetch the next |
| 1685 |
|
| * token before reaching that fateful point. */ |
| 1686 |
352 |
| moremagic = mg->mg_moremagic; |
| 1687 |
|
| |
| 1688 |
352 |
| switch (mg->mg_type) { |
| 1689 |
180 |
| case PERL_MAGIC_ext: |
| 1690 |
180 |
| break; |
| 1691 |
4 |
| case PERL_MAGIC_tied: |
| 1692 |
4 |
| ++tied; |
| 1693 |
4 |
| continue; |
| 1694 |
168 |
| default: |
| 1695 |
168 |
| continue; |
| 1696 |
|
| } |
| 1697 |
|
| |
| 1698 |
180 |
| w = vmg_wizard_from_mg(mg); |
| 1699 |
180 |
▶ | if (!w) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!w) |
0 |
180 |
180 |
|
| 1700 |
0 |
| continue; |
| 1701 |
|
| |
| 1702 |
180 |
| switch (w->uvar) { |
| 1703 |
3 |
| case 0: |
| 1704 |
3 |
| continue; |
| 1705 |
24 |
| case 2: |
| 1706 |
24 |
▶ | if (!newkey) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!newkey) |
24 |
0 |
24 |
|
| 1707 |
24 |
| newkey = key = umg->mg_obj = sv_mortalcopy(umg->mg_obj); |
| 1708 |
|
| } |
| 1709 |
|
| |
| 1710 |
177 |
| switch (action |
| 1711 |
177 |
| & (HV_FETCH_ISSTORE|HV_FETCH_ISEXISTS|HV_FETCH_LVALUE|HV_DELETE)) { |
| 1712 |
72 |
| case 0: |
| 1713 |
72 |
▶ | if (w->cb_fetch) |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->cb_fetch) |
57 |
15 |
72 |
|
| 1714 |
57 |
| vmg_cb_call2(w->cb_fetch, w->opinfo | VMG_CB_CALL_GUARD, sv, |
| 1715 |
|
| mg->mg_obj, key); |
| 1716 |
70 |
| break; |
| 1717 |
59 |
| case HV_FETCH_ISSTORE: |
| 1718 |
|
| case HV_FETCH_LVALUE: |
| 1719 |
|
| case (HV_FETCH_ISSTORE|HV_FETCH_LVALUE): |
| 1720 |
59 |
▶ | if (w->cb_store) |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->cb_store) |
57 |
2 |
59 |
|
| 1721 |
57 |
| vmg_cb_call2(w->cb_store, w->opinfo | VMG_CB_CALL_GUARD, sv, |
| 1722 |
|
| mg->mg_obj, key); |
| 1723 |
57 |
| break; |
| 1724 |
29 |
| case HV_FETCH_ISEXISTS: |
| 1725 |
29 |
▶ | if (w->cb_exists) |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->cb_exists) |
14 |
15 |
29 |
|
| 1726 |
14 |
| vmg_cb_call2(w->cb_exists, w->opinfo | VMG_CB_CALL_GUARD, sv, |
| 1727 |
|
| mg->mg_obj, key); |
| 1728 |
27 |
| break; |
| 1729 |
17 |
| case HV_DELETE: |
| 1730 |
|
| case (HV_DELETE|G_DISCARD): |
| 1731 |
17 |
▶ | if (w->cb_delete) |
Branch: 1 branch
| Branch | True | False | Total |
| if (w->cb_delete) |
16 |
1 |
17 |
|
| 1732 |
16 |
| vmg_cb_call2(w->cb_delete, w->opinfo | VMG_CB_CALL_GUARD, sv, |
| 1733 |
|
| mg->mg_obj, key); |
| 1734 |
15 |
| break; |
| 1735 |
|
| } |
| 1736 |
|
| } |
| 1737 |
|
| |
| 1738 |
160 |
▶ | if (SvRMAGICAL(sv) && !tied && !(action & (HV_FETCH_ISSTORE|HV_DELETE))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (SvRMAGICAL(sv) && !tied && !(action & (HV_FETCH_ISSTORE|HV_DELETE))) { |
27 |
133 |
160 |
| if (SvRMAGICAL(sv) && !tied && !(action & (HV_FETCH_ISSTORE|HV_DELETE))) { |
23 |
4 |
27 |
| if (SvRMAGICAL(sv) && !tied && !(action & (HV_FETCH_ISSTORE|HV_DELETE))) { |
14 |
9 |
23 |
|
| 1739 |
|
| /* Temporarily hide the RMAGICAL flag of the hash so it isn't wrongly |
| 1740 |
|
| * mistaken for a tied hash by the rest of hv_common. It will be reset by |
| 1741 |
|
| * the op_ppaddr of a new fake op injected between the current and the next |
| 1742 |
|
| * one. */ |
| 1743 |
|
| |
| 1744 |
|
| #if VMG_RESET_RMG_NEEDS_TRAMPOLINE |
| 1745 |
|
| |
| 1746 |
|
| dXSH_CXT; |
| 1747 |
|
| |
| 1748 |
|
| PL_op = vmg_trampoline_bump(&XSH_CXT.reset_rmg, sv, PL_op); |
| 1749 |
|
| |
| 1750 |
|
| #else /* !VMG_RESET_RMG_NEEDS_TRAMPOLINE */ |
| 1751 |
|
| |
| 1752 |
14 |
| OP *nop = PL_op->op_next; |
| 1753 |
14 |
| SVOP *svop = NULL; |
| 1754 |
|
| |
| 1755 |
14 |
▶ | if (nop && nop->op_ppaddr == vmg_pp_reset_rmg) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (nop && nop->op_ppaddr == vmg_pp_reset_rmg) { |
14 |
0 |
14 |
| if (nop && nop->op_ppaddr == vmg_pp_reset_rmg) { |
4 |
10 |
14 |
|
| 1756 |
4 |
| svop = (SVOP *) nop; |
| 1757 |
|
| } else { |
| 1758 |
10 |
| NewOp(1101, svop, 1, SVOP); |
| 1759 |
10 |
| svop->op_type = OP_STUB; |
| 1760 |
10 |
| svop->op_ppaddr = vmg_pp_reset_rmg; |
| 1761 |
10 |
| svop->op_next = nop; |
| 1762 |
10 |
| svop->op_flags = 0; |
| 1763 |
10 |
| svop->op_private = 0; |
| 1764 |
|
| |
| 1765 |
10 |
| PL_op->op_next = (OP *) svop; |
| 1766 |
|
| } |
| 1767 |
|
| |
| 1768 |
14 |
| svop->op_sv = sv; |
| 1769 |
|
| |
| 1770 |
|
| #endif /* VMG_RESET_RMG_NEEDS_TRAMPOLINE */ |
| 1771 |
|
| |
| 1772 |
14 |
| SvRMAGICAL_off(sv); |
| 1773 |
|
| } |
| 1774 |
|
| |
| 1775 |
160 |
| return 0; |
| 1776 |
|
| } |
| 1777 |
|
| |
| 1778 |
|
| #endif /* VMG_UVAR */ |
| 1779 |
|
| |
| 1780 |
|
| /* --- Module setup/teardown ----------------------------------------------- */ |
| 1781 |
|
| |
| 1782 |
|
| #if XSH_THREADSAFE |
| 1783 |
|
| |
| 1784 |
|
| static void vmg_global_teardown_late_locked(pTHX_ void *ud) { |
| 1785 |
|
| #define vmg_global_teardown_late_locked(UD) vmg_global_teardown_late_locked(aTHX_ (UD)) |
| 1786 |
|
| MUTEX_DESTROY(&vmg_op_name_init_mutex); |
| 1787 |
|
| MUTEX_DESTROY(&vmg_vtable_refcount_mutex); |
| 1788 |
|
| |
| 1789 |
|
| return; |
| 1790 |
|
| } |
| 1791 |
|
| |
| 1792 |
|
| static signed char vmg_destruct_level(pTHX) { |
| 1793 |
|
| #define vmg_destruct_level() vmg_destruct_level(aTHX) |
| 1794 |
|
| signed char lvl; |
| 1795 |
|
| |
| 1796 |
|
| lvl = PL_perl_destruct_level; |
| 1797 |
|
| |
| 1798 |
|
| #ifdef DEBUGGING |
| 1799 |
|
| { |
| 1800 |
|
| const char *s = PerlEnv_getenv("PERL_DESTRUCT_LEVEL"); |
| 1801 |
|
| if (s) { |
| 1802 |
|
| int i; |
| 1803 |
|
| #if XSH_HAS_PERL(5, 21, 3) |
| 1804 |
|
| if (strEQ(s, "-1")) { |
| 1805 |
|
| i = -1; |
| 1806 |
|
| } else { |
| 1807 |
|
| # if XSH_HAS_PERL(5, 21, 10) |
| 1808 |
|
| UV uv; |
| 1809 |
|
| if (Perl_grok_atoUV(s, &uv, NULL) && uv <= INT_MAX) |
| 1810 |
|
| i = (int) uv; |
| 1811 |
|
| else |
| 1812 |
|
| i = 0; |
| 1813 |
|
| # else /* XSH_HAS_PERL(5, 21, 3) && !XSH_HAS_PERL(5, 21, 10) */ |
| 1814 |
|
| i = Perl_grok_atou(s, NULL); |
| 1815 |
|
| # endif |
| 1816 |
|
| } |
| 1817 |
|
| #else /* !XSH_HAS_PERL(5, 21, 3) */ |
| 1818 |
|
| i = atoi(s); |
| 1819 |
|
| #endif |
| 1820 |
|
| if (lvl < i) |
| 1821 |
|
| lvl = i; |
| 1822 |
|
| } |
| 1823 |
|
| } |
| 1824 |
|
| #endif |
| 1825 |
|
| |
| 1826 |
|
| return lvl; |
| 1827 |
|
| } |
| 1828 |
|
| |
| 1829 |
|
| #endif /* XSH_THREADSAFE */ |
| 1830 |
|
| |
| 1831 |
30 |
| static void xsh_user_global_setup(pTHX) { |
| 1832 |
|
| #if XSH_THREADSAFE |
| 1833 |
|
| MUTEX_INIT(&vmg_vtable_refcount_mutex); |
| 1834 |
|
| MUTEX_INIT(&vmg_op_name_init_mutex); |
| 1835 |
|
| #endif |
| 1836 |
|
| |
| 1837 |
30 |
| return; |
| 1838 |
|
| } |
| 1839 |
|
| |
| 1840 |
30 |
| static void xsh_user_local_setup(pTHX_ xsh_user_cxt_t *cxt) { |
| 1841 |
|
| HV *stash; |
| 1842 |
|
| int c; |
| 1843 |
|
| |
| 1844 |
450 |
▶ | for (c = OPc_NULL; c < OPc_MAX; ++c) |
Branch: 1 branch
| Branch | True | False | Total |
| for (c = OPc_NULL; c < OPc_MAX; ++c) |
420 |
30 |
450 |
|
| 1845 |
420 |
| cxt->b__op_stashes[c] = NULL; |
| 1846 |
|
| |
| 1847 |
30 |
| cxt->depth = 0; |
| 1848 |
30 |
| cxt->freed_tokens = NULL; |
| 1849 |
|
| |
| 1850 |
|
| #if VMG_PROPAGATE_ERRSV_NEEDS_TRAMPOLINE |
| 1851 |
|
| vmg_trampoline_init(&cxt->propagate_errsv, vmg_pp_propagate_errsv); |
| 1852 |
|
| #endif |
| 1853 |
|
| #if VMG_RESET_RMG_NEEDS_TRAMPOLINE |
| 1854 |
|
| vmg_trampoline_init(&cxt->reset_rmg, vmg_pp_reset_rmg); |
| 1855 |
|
| #endif |
| 1856 |
|
| |
| 1857 |
30 |
| stash = gv_stashpv(XSH_PACKAGE, 1); |
| 1858 |
30 |
| newCONSTSUB(stash, "MGf_COPY", newSVuv(MGf_COPY)); |
| 1859 |
30 |
| newCONSTSUB(stash, "MGf_DUP", newSVuv(MGf_DUP)); |
| 1860 |
30 |
| newCONSTSUB(stash, "MGf_LOCAL", newSVuv(MGf_LOCAL)); |
| 1861 |
30 |
| newCONSTSUB(stash, "VMG_UVAR", newSVuv(VMG_UVAR)); |
| 1862 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_SCALAR_LENGTH_NOLEN", |
| 1863 |
|
| newSVuv(VMG_COMPAT_SCALAR_LENGTH_NOLEN)); |
| 1864 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_SCALAR_NOLEN", |
| 1865 |
|
| newSVuv(VMG_COMPAT_SCALAR_NOLEN)); |
| 1866 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_ARRAY_PUSH_NOLEN", |
| 1867 |
|
| newSVuv(VMG_COMPAT_ARRAY_PUSH_NOLEN)); |
| 1868 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID", |
| 1869 |
|
| newSVuv(VMG_COMPAT_ARRAY_PUSH_NOLEN_VOID)); |
| 1870 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID", |
| 1871 |
|
| newSVuv(VMG_COMPAT_ARRAY_UNSHIFT_NOLEN_VOID)); |
| 1872 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_ARRAY_UNDEF_CLEAR", |
| 1873 |
|
| newSVuv(VMG_COMPAT_ARRAY_UNDEF_CLEAR)); |
| 1874 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_HASH_DELETE_NOUVAR_VOID", |
| 1875 |
|
| newSVuv(VMG_COMPAT_HASH_DELETE_NOUVAR_VOID)); |
| 1876 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_CODE_COPY_CLONE", |
| 1877 |
|
| newSVuv(VMG_COMPAT_CODE_COPY_CLONE)); |
| 1878 |
30 |
| newCONSTSUB(stash, "VMG_COMPAT_GLOB_GET", newSVuv(VMG_COMPAT_GLOB_GET)); |
| 1879 |
30 |
| newCONSTSUB(stash, "VMG_PERL_PATCHLEVEL", newSVuv(XSH_PERL_PATCHLEVEL)); |
| 1880 |
30 |
| newCONSTSUB(stash, "VMG_THREADSAFE", newSVuv(XSH_THREADSAFE)); |
| 1881 |
30 |
| newCONSTSUB(stash, "VMG_FORKSAFE", newSVuv(XSH_FORKSAFE)); |
| 1882 |
30 |
| newCONSTSUB(stash, "VMG_OP_INFO_NAME", newSVuv(VMG_OP_INFO_NAME)); |
| 1883 |
30 |
| newCONSTSUB(stash, "VMG_OP_INFO_OBJECT", newSVuv(VMG_OP_INFO_OBJECT)); |
| 1884 |
|
| |
| 1885 |
30 |
| return; |
| 1886 |
|
| } |
| 1887 |
|
| |
| 1888 |
30 |
| static void xsh_user_local_teardown(pTHX_ xsh_user_cxt_t *cxt) { |
| 1889 |
30 |
▶ | if (cxt->depth == 0 && cxt->freed_tokens) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (cxt->depth == 0 && cxt->freed_tokens) { |
30 |
0 |
30 |
| if (cxt->depth == 0 && cxt->freed_tokens) { |
0 |
30 |
30 |
|
| 1890 |
0 |
| vmg_magic_chain_free(cxt->freed_tokens, NULL); |
| 1891 |
0 |
| cxt->freed_tokens = NULL; |
| 1892 |
|
| } |
| 1893 |
|
| |
| 1894 |
30 |
| return; |
| 1895 |
|
| } |
| 1896 |
|
| |
| 1897 |
30 |
| static void xsh_user_global_teardown(pTHX) { |
| 1898 |
|
| #if XSH_THREADSAFE |
| 1899 |
|
| if (vmg_destruct_level() == 0) |
| 1900 |
|
| vmg_global_teardown_late_locked(NULL); |
| 1901 |
|
| else |
| 1902 |
|
| xsh_teardown_late_register(vmg_global_teardown_late_locked, NULL); |
| 1903 |
|
| #endif |
| 1904 |
|
| |
| 1905 |
30 |
| return; |
| 1906 |
|
| } |
| 1907 |
|
| |
| 1908 |
|
| /* --- Macros for the XS section ------------------------------------------- */ |
| 1909 |
|
| |
| 1910 |
|
| #ifdef CvISXSUB |
| 1911 |
|
| # define VMG_CVOK(C) \ |
| 1912 |
|
| ((CvISXSUB(C) ? (void *) CvXSUB(C) : (void *) CvROOT(C)) ? 1 : 0) |
| 1913 |
|
| #else |
| 1914 |
|
| # define VMG_CVOK(C) (CvROOT(C) || CvXSUB(C)) |
| 1915 |
|
| #endif |
| 1916 |
|
| |
| 1917 |
|
| #define VMG_CBOK(S) ((SvTYPE(S) == SVt_PVCV) ? VMG_CVOK(S) : SvOK(S)) |
| 1918 |
|
| |
| 1919 |
|
| #define VMG_SET_CB(S, N) { \ |
| 1920 |
|
| SV *cb = (S); \ |
| 1921 |
|
| if (SvOK(cb) && SvROK(cb)) { \ |
| 1922 |
|
| cb = SvRV(cb); \ |
| 1923 |
|
| if (VMG_CBOK(cb)) \ |
| 1924 |
|
| SvREFCNT_inc_simple_void(cb); \ |
| 1925 |
|
| else \ |
| 1926 |
|
| cb = NULL; \ |
| 1927 |
|
| } else { \ |
| 1928 |
|
| cb = NULL; \ |
| 1929 |
|
| } \ |
| 1930 |
|
| w->cb_ ## N = cb; \ |
| 1931 |
|
| } |
| 1932 |
|
| |
| 1933 |
|
| #define VMG_SET_SVT_CB(S, N) { \ |
| 1934 |
|
| SV *cb = (S); \ |
| 1935 |
|
| if (SvOK(cb) && SvROK(cb)) { \ |
| 1936 |
|
| cb = SvRV(cb); \ |
| 1937 |
|
| if (VMG_CBOK(cb)) { \ |
| 1938 |
|
| t->svt_ ## N = vmg_svt_ ## N; \ |
| 1939 |
|
| SvREFCNT_inc_simple_void(cb); \ |
| 1940 |
|
| } else { \ |
| 1941 |
|
| t->svt_ ## N = vmg_svt_ ## N ## _noop; \ |
| 1942 |
|
| cb = NULL; \ |
| 1943 |
|
| } \ |
| 1944 |
|
| } else { \ |
| 1945 |
|
| t->svt_ ## N = NULL; \ |
| 1946 |
|
| cb = NULL; \ |
| 1947 |
|
| } \ |
| 1948 |
|
| w->cb_ ## N = cb; \ |
| 1949 |
|
| } |
| 1950 |
|
| |
| 1951 |
|
| /* --- XS ------------------------------------------------------------------ */ |
| 1952 |
|
| |
| 1953 |
|
| MODULE = Variable::Magic PACKAGE = Variable::Magic |
| 1954 |
|
| |
| 1955 |
|
| PROTOTYPES: ENABLE |
| 1956 |
|
| |
| 1957 |
|
| BOOT: |
| 1958 |
|
| { |
| 1959 |
30 |
| xsh_setup(); |
| 1960 |
|
| } |
| 1961 |
|
| |
| 1962 |
|
| #if XSH_THREADSAFE |
| 1963 |
|
| |
| 1964 |
|
| void |
| 1965 |
|
| CLONE(...) |
| 1966 |
|
| PROTOTYPE: DISABLE |
| 1967 |
|
| PPCODE: |
| 1968 |
|
| xsh_clone(); |
| 1969 |
|
| XSRETURN(0); |
| 1970 |
|
| |
| 1971 |
|
| #endif /* XSH_THREADSAFE */ |
| 1972 |
|
| |
| 1973 |
|
| SV *_wizard(...) |
| 1974 |
|
| PROTOTYPE: DISABLE |
| 1975 |
|
| PREINIT: |
| 1976 |
|
| vmg_wizard *w; |
| 1977 |
|
| MGVTBL *t; |
| 1978 |
|
| SV *op_info, *copy_key; |
| 1979 |
197 |
| I32 i = 0; |
| 1980 |
|
| CODE: |
| 1981 |
197 |
▶ | if (items != 9 |
Branch: 1 branch
| Branch | True | False | Total |
| if (items != 9 |
20 |
177 |
197 |
|
| 1982 |
|
| #if MGf_LOCAL |
| 1983 |
|
| + 1 |
| 1984 |
|
| #endif /* MGf_LOCAL */ |
| 1985 |
|
| #if VMG_UVAR |
| 1986 |
|
| + 5 |
| 1987 |
|
| #endif /* VMG_UVAR */ |
| 1988 |
20 |
| ) { croak(vmg_wrongargnum); } |
| 1989 |
|
| |
| 1990 |
177 |
| op_info = ST(i++); |
| 1991 |
177 |
▶ | w = vmg_wizard_alloc(SvOK(op_info) ? SvUV(op_info) : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| w = vmg_wizard_alloc(SvOK(op_info) ? SvUV(op_info) : 0); |
42 |
135 |
177 |
|
| 1992 |
176 |
| t = vmg_vtable_vtbl(w->vtable); |
| 1993 |
|
| |
| 1994 |
176 |
▶ | VMG_SET_CB(ST(i++), data); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_CB(ST(i++), data); |
82 |
94 |
176 |
| VMG_SET_CB(ST(i++), data); |
82 |
0 |
82 |
| VMG_SET_CB(ST(i++), data); |
82 |
0 |
82 |
| VMG_SET_CB(ST(i++), data); |
0 |
82 |
82 |
| VMG_SET_CB(ST(i++), data); |
82 |
0 |
82 |
| VMG_SET_CB(ST(i++), data); |
82 |
0 |
82 |
|
| 1995 |
|
| |
| 1996 |
176 |
▶ | VMG_SET_SVT_CB(ST(i++), get); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_SVT_CB(ST(i++), get); |
58 |
118 |
176 |
| VMG_SET_SVT_CB(ST(i++), get); |
58 |
0 |
58 |
| VMG_SET_SVT_CB(ST(i++), get); |
54 |
4 |
58 |
| VMG_SET_SVT_CB(ST(i++), get); |
0 |
54 |
54 |
| VMG_SET_SVT_CB(ST(i++), get); |
56 |
2 |
58 |
| VMG_SET_SVT_CB(ST(i++), get); |
56 |
0 |
56 |
|
| 1997 |
176 |
▶ | VMG_SET_SVT_CB(ST(i++), set); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_SVT_CB(ST(i++), set); |
24 |
152 |
176 |
| VMG_SET_SVT_CB(ST(i++), set); |
24 |
0 |
24 |
| VMG_SET_SVT_CB(ST(i++), set); |
23 |
1 |
24 |
| VMG_SET_SVT_CB(ST(i++), set); |
0 |
23 |
23 |
| VMG_SET_SVT_CB(ST(i++), set); |
23 |
1 |
24 |
| VMG_SET_SVT_CB(ST(i++), set); |
23 |
0 |
23 |
|
| 1998 |
176 |
▶ | VMG_SET_SVT_CB(ST(i++), len); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_SVT_CB(ST(i++), len); |
17 |
159 |
176 |
| VMG_SET_SVT_CB(ST(i++), len); |
17 |
0 |
17 |
| VMG_SET_SVT_CB(ST(i++), len); |
15 |
2 |
17 |
| VMG_SET_SVT_CB(ST(i++), len); |
0 |
15 |
15 |
| VMG_SET_SVT_CB(ST(i++), len); |
15 |
2 |
17 |
| VMG_SET_SVT_CB(ST(i++), len); |
15 |
0 |
15 |
|
| 1999 |
176 |
▶ | VMG_SET_SVT_CB(ST(i++), clear); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_SVT_CB(ST(i++), clear); |
16 |
160 |
176 |
| VMG_SET_SVT_CB(ST(i++), clear); |
16 |
0 |
16 |
| VMG_SET_SVT_CB(ST(i++), clear); |
16 |
0 |
16 |
| VMG_SET_SVT_CB(ST(i++), clear); |
0 |
16 |
16 |
| VMG_SET_SVT_CB(ST(i++), clear); |
16 |
0 |
16 |
| VMG_SET_SVT_CB(ST(i++), clear); |
16 |
0 |
16 |
|
| 2000 |
176 |
▶ | VMG_SET_SVT_CB(ST(i++), free); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_SVT_CB(ST(i++), free); |
37 |
139 |
176 |
| VMG_SET_SVT_CB(ST(i++), free); |
37 |
0 |
37 |
| VMG_SET_SVT_CB(ST(i++), free); |
37 |
0 |
37 |
| VMG_SET_SVT_CB(ST(i++), free); |
0 |
37 |
37 |
| VMG_SET_SVT_CB(ST(i++), free); |
37 |
0 |
37 |
| VMG_SET_SVT_CB(ST(i++), free); |
37 |
0 |
37 |
|
| 2001 |
176 |
▶ | VMG_SET_SVT_CB(ST(i++), copy); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_SVT_CB(ST(i++), copy); |
9 |
167 |
176 |
| VMG_SET_SVT_CB(ST(i++), copy); |
9 |
0 |
9 |
| VMG_SET_SVT_CB(ST(i++), copy); |
9 |
0 |
9 |
| VMG_SET_SVT_CB(ST(i++), copy); |
0 |
9 |
9 |
| VMG_SET_SVT_CB(ST(i++), copy); |
9 |
0 |
9 |
| VMG_SET_SVT_CB(ST(i++), copy); |
9 |
0 |
9 |
|
| 2002 |
|
| /* VMG_SET_SVT_CB(ST(i++), dup); */ |
| 2003 |
176 |
| i++; |
| 2004 |
176 |
| t->svt_dup = NULL; |
| 2005 |
176 |
| w->cb_dup = NULL; |
| 2006 |
|
| #if MGf_LOCAL |
| 2007 |
176 |
▶ | VMG_SET_SVT_CB(ST(i++), local); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_SVT_CB(ST(i++), local); |
8 |
168 |
176 |
| VMG_SET_SVT_CB(ST(i++), local); |
8 |
0 |
8 |
| VMG_SET_SVT_CB(ST(i++), local); |
7 |
1 |
8 |
| VMG_SET_SVT_CB(ST(i++), local); |
0 |
7 |
7 |
| VMG_SET_SVT_CB(ST(i++), local); |
7 |
1 |
8 |
| VMG_SET_SVT_CB(ST(i++), local); |
7 |
0 |
7 |
|
| 2008 |
|
| #endif /* MGf_LOCAL */ |
| 2009 |
|
| #if VMG_UVAR |
| 2010 |
176 |
▶ | VMG_SET_CB(ST(i++), fetch); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_CB(ST(i++), fetch); |
21 |
155 |
176 |
| VMG_SET_CB(ST(i++), fetch); |
21 |
0 |
21 |
| VMG_SET_CB(ST(i++), fetch); |
21 |
0 |
21 |
| VMG_SET_CB(ST(i++), fetch); |
0 |
21 |
21 |
| VMG_SET_CB(ST(i++), fetch); |
21 |
0 |
21 |
| VMG_SET_CB(ST(i++), fetch); |
21 |
0 |
21 |
|
| 2011 |
176 |
▶ | VMG_SET_CB(ST(i++), store); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_CB(ST(i++), store); |
20 |
156 |
176 |
| VMG_SET_CB(ST(i++), store); |
20 |
0 |
20 |
| VMG_SET_CB(ST(i++), store); |
20 |
0 |
20 |
| VMG_SET_CB(ST(i++), store); |
0 |
20 |
20 |
| VMG_SET_CB(ST(i++), store); |
20 |
0 |
20 |
| VMG_SET_CB(ST(i++), store); |
20 |
0 |
20 |
|
| 2012 |
176 |
▶ | VMG_SET_CB(ST(i++), exists); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_CB(ST(i++), exists); |
15 |
161 |
176 |
| VMG_SET_CB(ST(i++), exists); |
15 |
0 |
15 |
| VMG_SET_CB(ST(i++), exists); |
15 |
0 |
15 |
| VMG_SET_CB(ST(i++), exists); |
0 |
15 |
15 |
| VMG_SET_CB(ST(i++), exists); |
15 |
0 |
15 |
| VMG_SET_CB(ST(i++), exists); |
15 |
0 |
15 |
|
| 2013 |
176 |
▶ | VMG_SET_CB(ST(i++), delete); |
Branch: 6 branches
| Branch | True | False | Total |
| VMG_SET_CB(ST(i++), delete); |
15 |
161 |
176 |
| VMG_SET_CB(ST(i++), delete); |
15 |
0 |
15 |
| VMG_SET_CB(ST(i++), delete); |
15 |
0 |
15 |
| VMG_SET_CB(ST(i++), delete); |
0 |
15 |
15 |
| VMG_SET_CB(ST(i++), delete); |
15 |
0 |
15 |
| VMG_SET_CB(ST(i++), delete); |
15 |
0 |
15 |
|
| 2014 |
|
| |
| 2015 |
176 |
| copy_key = ST(i++); |
| 2016 |
176 |
▶ | if (w->cb_fetch || w->cb_store || w->cb_exists || w->cb_delete) |
Branch: 4 branches
| Branch | True | False | Total |
| if (w->cb_fetch || w->cb_store || w->cb_exists || w->cb_delete) |
155 |
21 |
176 |
| if (w->cb_fetch || w->cb_store || w->cb_exists || w->cb_delete) |
148 |
7 |
155 |
| if (w->cb_fetch || w->cb_store || w->cb_exists || w->cb_delete) |
142 |
6 |
148 |
| if (w->cb_fetch || w->cb_store || w->cb_exists || w->cb_delete) |
6 |
136 |
142 |
|
| 2017 |
40 |
▶ | w->uvar = SvTRUE(copy_key) ? 2 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| w->uvar = SvTRUE(copy_key) ? 2 : 1; |
1 |
39 |
40 |
|
| 2018 |
|
| #endif /* VMG_UVAR */ |
| 2019 |
|
| |
| 2020 |
176 |
| RETVAL = newRV_noinc(vmg_wizard_sv_new(w)); |
| 2021 |
|
| OUTPUT: |
| 2022 |
|
| RETVAL |
| 2023 |
|
| |
| 2024 |
|
| SV *cast(SV *sv, SV *wiz, ...) |
| 2025 |
|
| PROTOTYPE: \[$@%&*]$@ |
| 2026 |
|
| PREINIT: |
| 2027 |
313 |
| const vmg_wizard *w = NULL; |
| 2028 |
313 |
| SV **args = NULL; |
| 2029 |
313 |
▶ | I32 i = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| I32 i = 0; |
52 |
261 |
313 |
|
| 2030 |
|
| CODE: |
| 2031 |
313 |
▶ | if (items > 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (items > 2) { |
52 |
261 |
313 |
|
| 2032 |
52 |
| i = items - 2; |
| 2033 |
52 |
| args = &ST(2); |
| 2034 |
|
| } |
| 2035 |
313 |
▶ | if (SvROK(wiz)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(wiz)) { |
312 |
1 |
313 |
|
| 2036 |
312 |
| wiz = SvRV_const(wiz); |
| 2037 |
312 |
▶ | w = vmg_wizard_from_sv(wiz); |
Branch: 1 branch
| Branch | True | False | Total |
| w = vmg_wizard_from_sv(wiz); |
312 |
0 |
312 |
|
| 2038 |
|
| } |
| 2039 |
313 |
▶ | if (!w) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!w) |
1 |
312 |
313 |
|
| 2040 |
1 |
| croak(vmg_invalid_wiz); |
| 2041 |
312 |
| RETVAL = newSVuv(vmg_cast(SvRV(sv), w, wiz, args, i)); |
| 2042 |
|
| OUTPUT: |
| 2043 |
|
| RETVAL |
| 2044 |
|
| |
| 2045 |
|
| void |
| 2046 |
|
| getdata(SV *sv, SV *wiz) |
| 2047 |
|
| PROTOTYPE: \[$@%&*]$ |
| 2048 |
|
| PREINIT: |
| 2049 |
71 |
▶ | const vmg_wizard *w = NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| const vmg_wizard *w = NULL; |
70 |
1 |
71 |
|
| 2050 |
|
| SV *data; |
| 2051 |
|
| PPCODE: |
| 2052 |
71 |
▶ | if (SvROK(wiz)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(wiz)) |
70 |
1 |
71 |
|
| 2053 |
70 |
▶ | w = vmg_wizard_from_sv(SvRV_const(wiz)); |
Branch: 1 branch
| Branch | True | False | Total |
| w = vmg_wizard_from_sv(SvRV_const(wiz)); |
69 |
1 |
70 |
|
| 2054 |
71 |
▶ | if (!w) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!w) |
2 |
69 |
71 |
|
| 2055 |
2 |
| croak(vmg_invalid_wiz); |
| 2056 |
69 |
| data = vmg_data_get(SvRV(sv), w); |
| 2057 |
69 |
▶ | if (!data) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!data) |
22 |
47 |
69 |
|
| 2058 |
22 |
| XSRETURN_EMPTY; |
| 2059 |
47 |
| ST(0) = data; |
| 2060 |
47 |
| XSRETURN(1); |
| 2061 |
|
| |
| 2062 |
|
| SV *dispell(SV *sv, SV *wiz) |
| 2063 |
|
| PROTOTYPE: \[$@%&*]$ |
| 2064 |
|
| PREINIT: |
| 2065 |
59 |
▶ | const vmg_wizard *w = NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| const vmg_wizard *w = NULL; |
58 |
1 |
59 |
|
| 2066 |
|
| CODE: |
| 2067 |
59 |
▶ | if (SvROK(wiz)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(wiz)) |
58 |
1 |
59 |
|
| 2068 |
58 |
▶ | w = vmg_wizard_from_sv(SvRV_const(wiz)); |
Branch: 1 branch
| Branch | True | False | Total |
| w = vmg_wizard_from_sv(SvRV_const(wiz)); |
57 |
1 |
58 |
|
| 2069 |
59 |
▶ | if (!w) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!w) |
2 |
57 |
59 |
|
| 2070 |
2 |
| croak(vmg_invalid_wiz); |
| 2071 |
57 |
| RETVAL = newSVuv(vmg_dispell(SvRV(sv), w)); |
| 2072 |
|
| OUTPUT: |
| 2073 |
|
| RETVAL |