| 1 |
|
| #include "mouse.h" |
| 2 |
|
| #include "xs_version.h" |
| 3 |
|
| |
| 4 |
|
| #define MY_CXT_KEY "Mouse::Util::_guts" XS_VERSION |
| 5 |
|
| typedef struct { |
| 6 |
|
| HV* metas; |
| 7 |
|
| } my_cxt_t; |
| 8 |
|
| START_MY_CXT |
| 9 |
|
| |
| 10 |
|
| #define ISA_CACHE "::LINEALIZED_ISA_CACHE::" |
| 11 |
|
| |
| 12 |
|
| #ifdef no_mro_get_linear_isa |
| 13 |
|
| AV* |
| 14 |
|
| mouse_mro_get_linear_isa(pTHX_ HV* const stash){ |
| 15 |
|
| GV* const cachegv = *(GV**)hv_fetchs(stash, ISA_CACHE, TRUE); |
| 16 |
|
| AV* isa; |
| 17 |
|
| SV* gen; |
| 18 |
|
| CV* get_linear_isa; |
| 19 |
|
| |
| 20 |
|
| if(!isGV(cachegv)) |
| 21 |
|
| gv_init(cachegv, stash, ISA_CACHE, sizeof(ISA_CACHE)-1, TRUE); |
| 22 |
|
| |
| 23 |
|
| isa = GvAVn(cachegv); |
| 24 |
|
| gen = GvSVn(cachegv); |
| 25 |
|
| |
| 26 |
|
| |
| 27 |
|
| if(SvIOK(gen) && SvIVX(gen) == (IV)mro_get_pkg_gen(stash)){ |
| 28 |
|
| return isa; /* returns the cache if available */ |
| 29 |
|
| } |
| 30 |
|
| else{ |
| 31 |
|
| SvREFCNT_dec(isa); |
| 32 |
|
| GvAV(cachegv) = isa = newAV(); |
| 33 |
|
| } |
| 34 |
|
| |
| 35 |
|
| get_linear_isa = get_cv("Mouse::Util::get_linear_isa", TRUE); |
| 36 |
|
| |
| 37 |
|
| { |
| 38 |
|
| SV* avref; |
| 39 |
|
| dSP; |
| 40 |
|
| |
| 41 |
|
| ENTER; |
| 42 |
|
| SAVETMPS; |
| 43 |
|
| |
| 44 |
|
| PUSHMARK(SP); |
| 45 |
|
| mXPUSHp(HvNAME_get(stash), HvNAMELEN_get(stash)); |
| 46 |
|
| PUTBACK; |
| 47 |
|
| |
| 48 |
|
| call_sv((SV*)get_linear_isa, G_SCALAR); |
| 49 |
|
| |
| 50 |
|
| SPAGAIN; |
| 51 |
|
| avref = POPs; |
| 52 |
|
| PUTBACK; |
| 53 |
|
| |
| 54 |
|
| if(IsArrayRef(avref)){ |
| 55 |
|
| AV* const av = (AV*)SvRV(avref); |
| 56 |
|
| I32 const len = AvFILLp(av) + 1; |
| 57 |
|
| I32 i; |
| 58 |
|
| |
| 59 |
|
| for(i = 0; i < len; i++){ |
| 60 |
|
| HV* const stash = gv_stashsv(AvARRAY(av)[i], FALSE); |
| 61 |
|
| if(stash) |
| 62 |
|
| av_push(isa, newSVpv(HvNAME(stash), 0)); |
| 63 |
|
| } |
| 64 |
|
| SvREADONLY_on(isa); |
| 65 |
|
| } |
| 66 |
|
| else{ |
| 67 |
|
| Perl_croak(aTHX_ "Mouse:Util::get_linear_isa() didn't return an ARRAY reference"); |
| 68 |
|
| } |
| 69 |
|
| |
| 70 |
|
| FREETMPS; |
| 71 |
|
| LEAVE; |
| 72 |
|
| } |
| 73 |
|
| |
| 74 |
|
| sv_setiv(gen, (IV)mro_get_pkg_gen(stash)); |
| 75 |
|
| return isa; |
| 76 |
|
| } |
| 77 |
|
| #endif /* !no_mor_get_linear_isa */ |
| 78 |
|
| |
| 79 |
|
| #ifdef DEBUGGING |
| 80 |
|
| SV* |
| 81 |
|
| mouse_av_at_safe(pTHX_ AV* const av, I32 const ix){ |
| 82 |
|
| assert(av); |
| 83 |
|
| assert(SvTYPE(av) == SVt_PVAV); |
| 84 |
|
| assert(AvMAX(av) >= ix); |
| 85 |
|
| return AvARRAY(av)[ix] ? AvARRAY(av)[ix] : &PL_sv_undef; |
| 86 |
|
| } |
| 87 |
|
| #endif |
| 88 |
|
| |
| 89 |
|
| void |
| 90 |
922 |
| mouse_throw_error(SV* const metaobject, SV* const data /* not used */, const char* const fmt, ...){ |
| 91 |
|
| dTHX; |
| 92 |
|
| va_list args; |
| 93 |
|
| SV* message; |
| 94 |
|
| |
| 95 |
|
| assert(metaobject); |
| 96 |
|
| assert(fmt); |
| 97 |
|
| |
| 98 |
922 |
| va_start(args, fmt); |
| 99 |
922 |
| message = vnewSVpvf(fmt, &args); |
| 100 |
922 |
| va_end(args); |
| 101 |
|
| |
| 102 |
|
| { |
| 103 |
922 |
| dSP; |
| 104 |
922 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
922 |
922 |
|
| 105 |
922 |
▶ | EXTEND(SP, 6); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 6); |
0 |
922 |
922 |
|
| 106 |
|
| |
| 107 |
922 |
| PUSHs(metaobject); |
| 108 |
922 |
| mPUSHs(message); |
| 109 |
|
| |
| 110 |
922 |
▶ | if(data){ /* extra arg, might be useful for debugging */ |
Branch: 1 branch
| Branch | True | False | Total |
| if(data){ /* extra arg, might be useful for debugging */ |
839 |
83 |
922 |
|
| 111 |
839 |
| mPUSHs(newSVpvs("data")); |
| 112 |
839 |
| PUSHs(data); |
| 113 |
839 |
| mPUSHs(newSVpvs("depth")); |
| 114 |
839 |
| mPUSHi(-1); |
| 115 |
|
| } |
| 116 |
922 |
| PUTBACK; |
| 117 |
922 |
▶ | if(SvOK(metaobject)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if(SvOK(metaobject)) { |
922 |
0 |
922 |
|
| 118 |
922 |
| call_method("throw_error", G_VOID); |
| 119 |
|
| } |
| 120 |
|
| else { |
| 121 |
0 |
| call_pv("Mouse::Util::throw_error", G_VOID); |
| 122 |
|
| } |
| 123 |
0 |
| croak("throw_error() did not throw the error (%"SVf")", message); |
| 124 |
|
| } |
| 125 |
|
| } |
| 126 |
|
| |
| 127 |
|
| #if PERL_VERSION_LT(5,14,0) |
| 128 |
|
| /* workaround Perl-RT #69939 */ |
| 129 |
|
| I32 |
| 130 |
|
| mouse_call_sv_safe(pTHX_ SV* const sv, I32 const flags) { |
| 131 |
|
| I32 count; |
| 132 |
|
| ENTER; |
| 133 |
|
| /* Don't do SAVETMPS */ |
| 134 |
|
| |
| 135 |
|
| SAVEGENERICSV(ERRSV); /* local $@ */ |
| 136 |
|
| ERRSV = newSV(0); |
| 137 |
|
| |
| 138 |
|
| count = call_sv(aTHX_ sv, flags | G_EVAL); |
| 139 |
|
| |
| 140 |
|
| if(sv_true(ERRSV)){ |
| 141 |
|
| SV* const err = sv_mortalcopy(ERRSV); |
| 142 |
|
| LEAVE; |
| 143 |
|
| sv_setsv(ERRSV, err); |
| 144 |
|
| croak(NULL); /* rethrow */ |
| 145 |
|
| } |
| 146 |
|
| |
| 147 |
|
| LEAVE; |
| 148 |
|
| |
| 149 |
|
| return count; |
| 150 |
|
| } |
| 151 |
|
| #endif |
| 152 |
|
| |
| 153 |
|
| void |
| 154 |
45195 |
| mouse_must_defined(pTHX_ SV* const value, const char* const name) { |
| 155 |
|
| assert(value); |
| 156 |
|
| assert(name); |
| 157 |
|
| |
| 158 |
45195 |
▶ | SvGETMAGIC(value); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(value); |
0 |
45195 |
45195 |
| SvGETMAGIC(value); |
0 |
0 |
0 |
|
| 159 |
45195 |
▶ | if(!SvOK(value)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!SvOK(value)){ |
0 |
45195 |
45195 |
|
| 160 |
0 |
| croak("You must define %s", name); |
| 161 |
|
| } |
| 162 |
45195 |
| } |
| 163 |
|
| |
| 164 |
|
| void |
| 165 |
27450 |
| mouse_must_ref(pTHX_ SV* const value, const char* const name, svtype const t) { |
| 166 |
|
| assert(value); |
| 167 |
|
| assert(name); |
| 168 |
|
| |
| 169 |
27450 |
▶ | SvGETMAGIC(value); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(value); |
0 |
27450 |
27450 |
| SvGETMAGIC(value); |
0 |
0 |
0 |
|
| 170 |
27450 |
▶ | if(!(SvROK(value) && (t == SVt_NULL || SvTYPE(SvRV(value)) == t))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if(!(SvROK(value) && (t == SVt_NULL || SvTYPE(SvRV(value)) == t))) { |
27450 |
0 |
27450 |
| if(!(SvROK(value) && (t == SVt_NULL || SvTYPE(SvRV(value)) == t))) { |
25371 |
2079 |
27450 |
| if(!(SvROK(value) && (t == SVt_NULL || SvTYPE(SvRV(value)) == t))) { |
0 |
25371 |
25371 |
|
| 171 |
0 |
▶ | croak("You must pass %s, not %s", |
Branch: 1 branch
| Branch | True | False | Total |
| croak("You must pass %s, not %s", |
0 |
0 |
0 |
|
| 172 |
|
| name, SvOK(value) ? SvPV_nolen(value) : "undef"); |
| 173 |
|
| } |
| 174 |
27450 |
| } |
| 175 |
|
| |
| 176 |
|
| |
| 177 |
|
| bool |
| 178 |
1453 |
| mouse_is_class_loaded(pTHX_ SV * const klass){ |
| 179 |
|
| HV *stash; |
| 180 |
|
| GV** gvp; |
| 181 |
|
| HE* he; |
| 182 |
|
| |
| 183 |
1453 |
▶ | if (!(SvPOKp(klass) && SvCUR(klass))) { /* XXX: SvPOK does not work with magical scalars */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(SvPOKp(klass) && SvCUR(klass))) { /* XXX: SvPOK does not work with magical scalars */ |
1396 |
57 |
1453 |
| if (!(SvPOKp(klass) && SvCUR(klass))) { /* XXX: SvPOK does not work with magical scalars */ |
6 |
1390 |
1396 |
|
| 184 |
63 |
| return FALSE; |
| 185 |
|
| } |
| 186 |
|
| |
| 187 |
1390 |
| stash = gv_stashsv(klass, FALSE); |
| 188 |
1390 |
▶ | if (!stash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!stash) { |
64 |
1326 |
1390 |
|
| 189 |
64 |
| return FALSE; |
| 190 |
|
| } |
| 191 |
|
| |
| 192 |
1326 |
▶ | if (( gvp = (GV**)hv_fetchs(stash, "VERSION", FALSE) )) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (( gvp = (GV**)hv_fetchs(stash, "VERSION", FALSE) )) { |
11 |
1315 |
1326 |
|
| 193 |
11 |
▶ | if(isGV(*gvp) && GvSV(*gvp) && SvOK(GvSV(*gvp))){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(isGV(*gvp) && GvSV(*gvp) && SvOK(GvSV(*gvp))){ |
11 |
0 |
11 |
| if(isGV(*gvp) && GvSV(*gvp) && SvOK(GvSV(*gvp))){ |
7 |
4 |
11 |
| if(isGV(*gvp) && GvSV(*gvp) && SvOK(GvSV(*gvp))){ |
7 |
0 |
7 |
|
| 194 |
7 |
| return TRUE; |
| 195 |
|
| } |
| 196 |
|
| } |
| 197 |
|
| |
| 198 |
1319 |
▶ | if (( gvp = (GV**)hv_fetchs(stash, "ISA", FALSE) )) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (( gvp = (GV**)hv_fetchs(stash, "ISA", FALSE) )) { |
195 |
1124 |
1319 |
|
| 199 |
195 |
▶ | if(isGV(*gvp) && GvAV(*gvp) && av_len(GvAV(*gvp)) != -1){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(isGV(*gvp) && GvAV(*gvp) && av_len(GvAV(*gvp)) != -1){ |
195 |
0 |
195 |
| if(isGV(*gvp) && GvAV(*gvp) && av_len(GvAV(*gvp)) != -1){ |
195 |
0 |
195 |
| if(isGV(*gvp) && GvAV(*gvp) && av_len(GvAV(*gvp)) != -1){ |
186 |
9 |
195 |
|
| 200 |
186 |
| return TRUE; |
| 201 |
|
| } |
| 202 |
|
| } |
| 203 |
|
| |
| 204 |
1133 |
| hv_iterinit(stash); |
| 205 |
1360 |
▶ | while(( he = hv_iternext(stash) )){ |
Branch: 1 branch
| Branch | True | False | Total |
| while(( he = hv_iternext(stash) )){ |
1340 |
20 |
1360 |
|
| 206 |
1340 |
| GV* const gv = (GV*)HeVAL(he); |
| 207 |
|
| |
| 208 |
1340 |
▶ | if(isGV(gv)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(isGV(gv)){ |
1340 |
0 |
1340 |
|
| 209 |
1340 |
▶ | if(GvCVu(gv)){ /* is GV and has CV */ |
Branch: 2 branches
| Branch | True | False | Total |
| if(GvCVu(gv)){ /* is GV and has CV */ |
1248 |
92 |
1340 |
| if(GvCVu(gv)){ /* is GV and has CV */ |
1113 |
135 |
1248 |
|
| 210 |
1113 |
| hv_iterinit(stash); /* reset */ |
| 211 |
1113 |
| return TRUE; |
| 212 |
|
| } |
| 213 |
|
| } |
| 214 |
0 |
▶ | else if(SvOK(gv)){ /* is a stub or constant */ |
Branch: 1 branch
| Branch | True | False | Total |
| else if(SvOK(gv)){ /* is a stub or constant */ |
0 |
0 |
0 |
|
| 215 |
0 |
| hv_iterinit(stash); /* reset */ |
| 216 |
0 |
| return TRUE; |
| 217 |
|
| } |
| 218 |
|
| } |
| 219 |
20 |
| return FALSE; |
| 220 |
|
| } |
| 221 |
|
| |
| 222 |
|
| |
| 223 |
|
| SV* |
| 224 |
9725 |
| mouse_call0 (pTHX_ SV* const self, SV* const method) { |
| 225 |
9725 |
| dSP; |
| 226 |
|
| SV *ret; |
| 227 |
|
| |
| 228 |
9725 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
9725 |
9725 |
|
| 229 |
9725 |
▶ | XPUSHs(self); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(self); |
0 |
9725 |
9725 |
|
| 230 |
9725 |
| PUTBACK; |
| 231 |
|
| |
| 232 |
9725 |
| call_sv_safe(method, G_SCALAR | G_METHOD); |
| 233 |
|
| |
| 234 |
9723 |
| SPAGAIN; |
| 235 |
9723 |
| ret = POPs; |
| 236 |
9723 |
| PUTBACK; |
| 237 |
|
| |
| 238 |
9723 |
| return ret; |
| 239 |
|
| } |
| 240 |
|
| |
| 241 |
|
| SV* |
| 242 |
1038 |
| mouse_call1 (pTHX_ SV* const self, SV* const method, SV* const arg1) { |
| 243 |
1038 |
| dSP; |
| 244 |
|
| SV *ret; |
| 245 |
|
| |
| 246 |
1038 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
1038 |
1038 |
|
| 247 |
1038 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
1038 |
1038 |
|
| 248 |
1038 |
| PUSHs(self); |
| 249 |
1038 |
| PUSHs(arg1); |
| 250 |
1038 |
| PUTBACK; |
| 251 |
|
| |
| 252 |
1038 |
| call_sv_safe(method, G_SCALAR | G_METHOD); |
| 253 |
|
| |
| 254 |
1036 |
| SPAGAIN; |
| 255 |
1036 |
| ret = POPs; |
| 256 |
1036 |
| PUTBACK; |
| 257 |
|
| |
| 258 |
1036 |
| return ret; |
| 259 |
|
| } |
| 260 |
|
| |
| 261 |
|
| int |
| 262 |
6093 |
| mouse_predicate_call(pTHX_ SV* const self, SV* const method) { |
| 263 |
6093 |
| return sv_true( mcall0(self, method) ); |
| 264 |
|
| } |
| 265 |
|
| |
| 266 |
|
| SV* |
| 267 |
4410 |
| mouse_get_metaclass(pTHX_ SV* metaclass_name){ |
| 268 |
|
| dMY_CXT; |
| 269 |
|
| HE* he; |
| 270 |
|
| |
| 271 |
|
| assert(metaclass_name); |
| 272 |
|
| assert(MY_CXT.metas); |
| 273 |
|
| |
| 274 |
4410 |
▶ | if(IsObject(metaclass_name)){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(IsObject(metaclass_name)){ |
1876 |
2534 |
4410 |
| if(IsObject(metaclass_name)){ |
1876 |
0 |
1876 |
|
| 275 |
1876 |
| HV* const stash = SvSTASH(SvRV(metaclass_name)); |
| 276 |
|
| |
| 277 |
1876 |
▶ | metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
Branch: 12 branches
| Branch | True | False | Total |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
1876 |
0 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
1876 |
0 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
1876 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
0 |
0 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
1876 |
0 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
1876 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
1876 |
0 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
1876 |
0 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
1876 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
0 |
0 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
1876 |
0 |
1876 |
| metaclass_name = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
1876 |
1876 |
|
| 278 |
1876 |
| sv_2mortal(metaclass_name); |
| 279 |
|
| } |
| 280 |
|
| |
| 281 |
4410 |
| he = hv_fetch_ent(MY_CXT.metas, metaclass_name, FALSE, 0U); |
| 282 |
|
| |
| 283 |
4410 |
▶ | return he ? HeVAL(he) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| return he ? HeVAL(he) : &PL_sv_undef; |
3895 |
515 |
4410 |
|
| 284 |
|
| } |
| 285 |
|
| |
| 286 |
|
| MAGIC* |
| 287 |
24725 |
| mouse_mg_find(pTHX_ SV* const sv, const MGVTBL* const vtbl, I32 const flags){ |
| 288 |
|
| MAGIC* mg; |
| 289 |
|
| |
| 290 |
|
| assert(sv != NULL); |
| 291 |
24725 |
▶ | 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){ |
23662 |
1063 |
24725 |
|
| 292 |
23662 |
▶ | if(mg->mg_virtual == vtbl){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(mg->mg_virtual == vtbl){ |
23662 |
0 |
23662 |
|
| 293 |
23662 |
| return mg; |
| 294 |
|
| } |
| 295 |
|
| } |
| 296 |
|
| |
| 297 |
1063 |
▶ | if(flags & MOUSEf_DIE_ON_FAIL){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(flags & MOUSEf_DIE_ON_FAIL){ |
0 |
1063 |
1063 |
|
| 298 |
0 |
| croak("mouse_mg_find: no MAGIC found for %"SVf, sv_2mortal(newRV_inc(sv))); |
| 299 |
|
| } |
| 300 |
1063 |
| return NULL; |
| 301 |
|
| } |
| 302 |
|
| |
| 303 |
|
| GV* |
| 304 |
32265 |
| mouse_stash_fetch(pTHX_ HV* const stash, const char* const name, I32 const namelen, I32 const create) { |
| 305 |
32265 |
▶ | GV** const gvp = (GV**)hv_fetch(stash, name, namelen, create); |
Branch: 1 branch
| Branch | True | False | Total |
| GV** const gvp = (GV**)hv_fetch(stash, name, namelen, create); |
24505 |
7760 |
32265 |
|
| 306 |
|
| |
| 307 |
32265 |
▶ | if(gvp){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(gvp){ |
29596 |
2669 |
32265 |
|
| 308 |
29596 |
▶ | if(!isGV(*gvp)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!isGV(*gvp)){ |
24300 |
5296 |
29596 |
|
| 309 |
24300 |
| gv_init(*gvp, stash, name, namelen, GV_ADDMULTI); |
| 310 |
|
| } |
| 311 |
29596 |
| return *gvp; |
| 312 |
|
| } |
| 313 |
|
| else{ |
| 314 |
2669 |
| return NULL; |
| 315 |
|
| } |
| 316 |
|
| } |
| 317 |
|
| |
| 318 |
|
| void |
| 319 |
26584 |
| mouse_install_sub(pTHX_ GV* const gv, SV* const code_ref) { |
| 320 |
|
| CV* cv; |
| 321 |
|
| |
| 322 |
|
| assert(gv != NULL); |
| 323 |
|
| assert(code_ref != NULL); |
| 324 |
|
| assert(isGV(gv)); |
| 325 |
|
| assert(IsCodeRef(code_ref)); |
| 326 |
|
| |
| 327 |
26584 |
▶ | if(GvCVu(gv)){ /* delete *slot{gv} to work around "redefine" warning */ |
Branch: 2 branches
| Branch | True | False | Total |
| if(GvCVu(gv)){ /* delete *slot{gv} to work around "redefine" warning */ |
26490 |
94 |
26584 |
| if(GvCVu(gv)){ /* delete *slot{gv} to work around "redefine" warning */ |
260 |
26230 |
26490 |
|
| 328 |
260 |
| SvREFCNT_dec(GvCV(gv)); |
| 329 |
260 |
| GvCV_set(gv, NULL); |
| 330 |
|
| } |
| 331 |
|
| |
| 332 |
26584 |
| sv_setsv_mg((SV*)gv, code_ref); /* *gv = $code_ref */ |
| 333 |
|
| |
| 334 |
|
| /* name the CODE ref if it's anonymous */ |
| 335 |
26584 |
| cv = (CV*)SvRV(code_ref); |
| 336 |
26584 |
▶ | if(CvANON(cv) |
Branch: 1 branch
| Branch | True | False | Total |
| if(CvANON(cv) |
3070 |
23514 |
26584 |
|
| 337 |
3070 |
▶ | && CvGV(cv) /* a cv under construction has no gv */ ){ |
Branch: 1 branch
| Branch | True | False | Total |
| && CvGV(cv) /* a cv under construction has no gv */ ){ |
3070 |
0 |
3070 |
|
| 338 |
|
| HV* dbsub; |
| 339 |
|
| |
| 340 |
|
| /* update %DB::sub to make NYTProf happy */ |
| 341 |
3070 |
▶ | if((PL_perldb & (PERLDBf_SUBLINE|PERLDB_NAMEANON)) |
Branch: 1 branch
| Branch | True | False | Total |
| if((PL_perldb & (PERLDBf_SUBLINE|PERLDB_NAMEANON)) |
0 |
3070 |
3070 |
|
| 342 |
0 |
▶ | && PL_DBsub && (dbsub = GvHV(PL_DBsub)) |
Branch: 2 branches
| Branch | True | False | Total |
| && PL_DBsub && (dbsub = GvHV(PL_DBsub)) |
0 |
0 |
0 |
| && PL_DBsub && (dbsub = GvHV(PL_DBsub)) |
0 |
0 |
0 |
|
| 343 |
|
| ){ |
| 344 |
|
| /* see Perl_newATTRSUB() in op.c */ |
| 345 |
0 |
| SV* const subname = sv_newmortal(); |
| 346 |
|
| HE* orig; |
| 347 |
|
| |
| 348 |
0 |
| gv_efullname3(subname, CvGV(cv), NULL); |
| 349 |
0 |
| orig = hv_fetch_ent(dbsub, subname, FALSE, 0U); |
| 350 |
0 |
▶ | if(orig){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(orig){ |
0 |
0 |
0 |
|
| 351 |
0 |
| gv_efullname3(subname, gv, NULL); |
| 352 |
0 |
| (void)hv_store_ent(dbsub, subname, HeVAL(orig), 0U); |
| 353 |
0 |
| SvREFCNT_inc_simple_void_NN(HeVAL(orig)); |
| 354 |
|
| } |
| 355 |
|
| } |
| 356 |
|
| |
| 357 |
3070 |
| CvGV_set(cv, gv); |
| 358 |
3070 |
| CvANON_off(cv); |
| 359 |
|
| } |
| 360 |
26584 |
| } |
| 361 |
|
| |
| 362 |
|
| MODULE = Mouse::Util PACKAGE = Mouse::Util |
| 363 |
|
| |
| 364 |
|
| PROTOTYPES: DISABLE |
| 365 |
|
| VERSIONCHECK: DISABLE |
| 366 |
|
| |
| 367 |
|
| BOOT: |
| 368 |
|
| { |
| 369 |
|
| MY_CXT_INIT; |
| 370 |
286 |
| MY_CXT.metas = NULL; |
| 371 |
|
| } |
| 372 |
|
| |
| 373 |
|
| void |
| 374 |
|
| __register_metaclass_storage(HV* metas, bool cloning) |
| 375 |
|
| CODE: |
| 376 |
|
| { |
| 377 |
286 |
▶ | if(cloning){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(cloning){ |
0 |
286 |
286 |
|
| 378 |
|
| MY_CXT_CLONE; |
| 379 |
0 |
| MY_CXT.metas = NULL; |
| 380 |
|
| } |
| 381 |
|
| { |
| 382 |
|
| dMY_CXT; |
| 383 |
286 |
▶ | if(MY_CXT.metas && ckWARN(WARN_REDEFINE)){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(MY_CXT.metas && ckWARN(WARN_REDEFINE)){ |
0 |
286 |
286 |
| if(MY_CXT.metas && ckWARN(WARN_REDEFINE)){ |
0 |
0 |
0 |
|
| 384 |
0 |
| Perl_warner(aTHX_ packWARN(WARN_REDEFINE), "Metaclass storage more than once"); |
| 385 |
|
| } |
| 386 |
286 |
| MY_CXT.metas = metas; |
| 387 |
286 |
| SvREFCNT_inc_simple_void_NN(metas); |
| 388 |
|
| } |
| 389 |
|
| } |
| 390 |
|
| |
| 391 |
|
| bool |
| 392 |
|
| is_valid_class_name(SV* sv) |
| 393 |
|
| CODE: |
| 394 |
|
| { |
| 395 |
1332 |
▶ | SvGETMAGIC(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(sv); |
0 |
1332 |
1332 |
| SvGETMAGIC(sv); |
0 |
0 |
0 |
|
| 396 |
2660 |
▶ | if(SvPOKp(sv) && SvCUR(sv) > 0){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvPOKp(sv) && SvCUR(sv) > 0){ |
1330 |
2 |
1332 |
| if(SvPOKp(sv) && SvCUR(sv) > 0){ |
1328 |
2 |
1330 |
|
| 397 |
|
| UV i; |
| 398 |
1328 |
| RETVAL = TRUE; |
| 399 |
23228 |
▶ | for(i = 0; i < SvCUR(sv); i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < SvCUR(sv); i++){ |
21902 |
1326 |
23228 |
|
| 400 |
21902 |
| char const c = SvPVX(sv)[i]; |
| 401 |
21902 |
▶ | if(!(isALNUM(c) || c == ':')){ |
Branch: 2 branches
| Branch | True | False | Total |
| if(!(isALNUM(c) || c == ':')){ |
3976 |
17926 |
21902 |
| if(!(isALNUM(c) || c == ':')){ |
2 |
3974 |
3976 |
|
| 402 |
2 |
| RETVAL = FALSE; |
| 403 |
2 |
| break; |
| 404 |
|
| } |
| 405 |
|
| } |
| 406 |
|
| } |
| 407 |
|
| else{ |
| 408 |
4 |
| RETVAL = SvNIOKp(sv) ? TRUE : FALSE; |
| 409 |
|
| } |
| 410 |
|
| } |
| 411 |
|
| OUTPUT: |
| 412 |
|
| RETVAL |
| 413 |
|
| |
| 414 |
|
| bool |
| 415 |
|
| is_class_loaded(SV* sv) |
| 416 |
|
| |
| 417 |
|
| void |
| 418 |
|
| get_code_info(CV* code) |
| 419 |
|
| PREINIT: |
| 420 |
|
| GV* gv; |
| 421 |
|
| HV* stash; |
| 422 |
|
| PPCODE: |
| 423 |
767 |
▶ | if((gv = CvGV(code)) && isGV(gv) && (stash = GvSTASH(gv))){ |
Branch: 3 branches
| Branch | True | False | Total |
| if((gv = CvGV(code)) && isGV(gv) && (stash = GvSTASH(gv))){ |
767 |
0 |
767 |
| if((gv = CvGV(code)) && isGV(gv) && (stash = GvSTASH(gv))){ |
767 |
0 |
767 |
| if((gv = CvGV(code)) && isGV(gv) && (stash = GvSTASH(gv))){ |
767 |
0 |
767 |
|
| 424 |
767 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
767 |
767 |
|
| 425 |
767 |
▶ | mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
Branch: 12 branches
| Branch | True | False | Total |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
767 |
0 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
767 |
0 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
0 |
767 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
0 |
0 |
0 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
767 |
0 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
0 |
767 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
767 |
0 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
767 |
0 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
0 |
767 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
0 |
0 |
0 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
767 |
0 |
767 |
| mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); |
0 |
767 |
767 |
|
| 426 |
767 |
| mPUSHs(newSVpvn_share(GvNAME_get(gv), GvNAMELEN_get(gv), 0U)); |
| 427 |
|
| } |
| 428 |
|
| |
| 429 |
|
| SV* |
| 430 |
|
| get_code_package(CV* code) |
| 431 |
|
| PREINIT: |
| 432 |
|
| HV* stash; |
| 433 |
|
| CODE: |
| 434 |
4456 |
▶ | if(CvGV(code) && isGV(CvGV(code)) && (stash = GvSTASH(CvGV(code)))){ |
Branch: 3 branches
| Branch | True | False | Total |
| if(CvGV(code) && isGV(CvGV(code)) && (stash = GvSTASH(CvGV(code)))){ |
4456 |
0 |
4456 |
| if(CvGV(code) && isGV(CvGV(code)) && (stash = GvSTASH(CvGV(code)))){ |
4456 |
0 |
4456 |
| if(CvGV(code) && isGV(CvGV(code)) && (stash = GvSTASH(CvGV(code)))){ |
4456 |
0 |
4456 |
|
| 435 |
4456 |
▶ | RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
Branch: 12 branches
| Branch | True | False | Total |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
4456 |
0 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
4456 |
0 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
4456 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
0 |
0 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
4456 |
0 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
4456 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
4456 |
0 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
4456 |
0 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
4456 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
0 |
0 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
4456 |
0 |
4456 |
| RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); |
0 |
4456 |
4456 |
|
| 436 |
|
| } |
| 437 |
|
| else{ |
| 438 |
0 |
| RETVAL = &PL_sv_no; |
| 439 |
|
| } |
| 440 |
|
| OUTPUT: |
| 441 |
|
| RETVAL |
| 442 |
|
| |
| 443 |
|
| CV* |
| 444 |
|
| get_code_ref(SV* package, SV* name) |
| 445 |
|
| CODE: |
| 446 |
|
| { |
| 447 |
|
| HV* stash; |
| 448 |
|
| STRLEN name_len; |
| 449 |
|
| const char* name_pv; |
| 450 |
|
| GV* gv; |
| 451 |
|
| |
| 452 |
5382 |
| must_defined(package, "a package name"); |
| 453 |
5382 |
| must_defined(name, "a subroutine name"); |
| 454 |
|
| |
| 455 |
5382 |
| stash = gv_stashsv(package, FALSE); |
| 456 |
5382 |
▶ | if(!stash){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!stash){ |
0 |
5382 |
5382 |
|
| 457 |
926 |
| XSRETURN_UNDEF; |
| 458 |
|
| } |
| 459 |
|
| |
| 460 |
5382 |
| name_pv = SvPV_const(name, name_len); |
| 461 |
5382 |
| gv = stash_fetch(stash, name_pv, name_len, FALSE); |
| 462 |
5382 |
▶ | RETVAL = gv ? GvCVu(gv) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| RETVAL = gv ? GvCVu(gv) : NULL; |
5030 |
352 |
5382 |
| RETVAL = gv ? GvCVu(gv) : NULL; |
4931 |
99 |
5030 |
|
| 463 |
|
| |
| 464 |
5382 |
▶ | if(!RETVAL){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!RETVAL){ |
926 |
4456 |
5382 |
|
| 465 |
926 |
| XSRETURN_UNDEF; |
| 466 |
|
| } |
| 467 |
|
| } |
| 468 |
|
| OUTPUT: |
| 469 |
|
| RETVAL |
| 470 |
|
| |
| 471 |
|
| void |
| 472 |
|
| generate_isa_predicate_for(SV* arg, SV* predicate_name = NULL) |
| 473 |
|
| ALIAS: |
| 474 |
|
| generate_isa_predicate_for = 0 |
| 475 |
|
| generate_can_predicate_for = 1 |
| 476 |
|
| PPCODE: |
| 477 |
|
| { |
| 478 |
1437 |
| const char* name_pv = NULL; |
| 479 |
|
| CV* xsub; |
| 480 |
|
| |
| 481 |
1437 |
▶ | must_defined(arg, ix == 0 ? "a class_name" : "method names"); |
Branch: 1 branch
| Branch | True | False | Total |
| must_defined(arg, ix == 0 ? "a class_name" : "method names"); |
573 |
864 |
1437 |
|
| 482 |
|
| |
| 483 |
1437 |
▶ | if(predicate_name){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(predicate_name){ |
858 |
579 |
1437 |
|
| 484 |
858 |
| must_defined(predicate_name, "a predicate name"); |
| 485 |
858 |
| name_pv = SvPV_nolen_const(predicate_name); |
| 486 |
|
| } |
| 487 |
|
| |
| 488 |
1437 |
▶ | if(ix == 0){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(ix == 0){ |
573 |
864 |
1437 |
|
| 489 |
573 |
| xsub = mouse_generate_isa_predicate_for(aTHX_ arg, name_pv); |
| 490 |
|
| } |
| 491 |
|
| else{ |
| 492 |
864 |
| xsub = mouse_generate_can_predicate_for(aTHX_ arg, name_pv); |
| 493 |
|
| } |
| 494 |
|
| |
| 495 |
1437 |
▶ | if(predicate_name == NULL){ /* anonymous predicate */ |
Branch: 1 branch
| Branch | True | False | Total |
| if(predicate_name == NULL){ /* anonymous predicate */ |
579 |
858 |
1437 |
|
| 496 |
579 |
▶ | mXPUSHs( newRV_inc((SV*)xsub) ); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs( newRV_inc((SV*)xsub) ); |
0 |
579 |
579 |
|
| 497 |
|
| } |
| 498 |
|
| } |
| 499 |
|
| |
| 500 |
|
| # This xsub will redefine &Mouse::Util::install_subroutines() |
| 501 |
|
| void |
| 502 |
|
| install_subroutines(SV* into, ...) |
| 503 |
|
| CODE: |
| 504 |
|
| { |
| 505 |
|
| HV* stash; |
| 506 |
|
| I32 i; |
| 507 |
|
| |
| 508 |
4892 |
| must_defined(into, "a package name"); |
| 509 |
4892 |
| stash = gv_stashsv(into, TRUE); |
| 510 |
|
| |
| 511 |
4892 |
▶ | if( ((items-1) % 2) != 0 ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if( ((items-1) % 2) != 0 ){ |
0 |
4892 |
4892 |
|
| 512 |
0 |
| croak_xs_usage(cv, "into, name => coderef [, other_name, other_coderef ...]"); |
| 513 |
|
| } |
| 514 |
|
| |
| 515 |
29397 |
▶ | for(i = 1; i < items; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 1; i < items; i += 2) { |
24505 |
4892 |
29397 |
|
| 516 |
24505 |
| SV* const name = ST(i); |
| 517 |
24505 |
| SV* const code = ST(i+1); |
| 518 |
|
| STRLEN len; |
| 519 |
|
| const char* pv; |
| 520 |
|
| GV* gv; |
| 521 |
|
| |
| 522 |
24505 |
| must_defined(name, "a subroutine name"); |
| 523 |
24505 |
| must_ref(code, "a CODE reference", SVt_PVCV); |
| 524 |
|
| |
| 525 |
24505 |
| pv = SvPV_const(name, len); |
| 526 |
24505 |
| gv = stash_fetch(stash, pv, len, TRUE); |
| 527 |
|
| |
| 528 |
24505 |
| mouse_install_sub(aTHX_ gv, code); |
| 529 |
|
| } |
| 530 |
|
| } |