| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| |
| 6 |
|
| /* Each XSUB either completes the call exactly as its _pp_NAME in |
| 7 |
|
| lib/Data/Shared.pm would, or hands that sub its untouched arguments |
| 8 |
|
| before pushing anything. */ |
| 9 |
|
| |
| 10 |
|
| /* Data::Shared::Adapter::Keyed::FAST_* */ |
| 11 |
|
| #define FAST_KEY_INT 1 |
| 12 |
|
| #define FAST_ABSENT 2 |
| 13 |
|
| #define FAST_INCR 4 |
| 14 |
|
| |
| 15 |
|
| #define V_GET 0 |
| 16 |
|
| #define V_SET 1 |
| 17 |
|
| #define V_DELETE 2 |
| 18 |
|
| #define V_EXISTS 3 |
| 19 |
|
| #define V_INCR 4 |
| 20 |
|
| #define V_CALL 5 |
| 21 |
|
| #define MUTATING(v) ((v) == V_SET || (v) == V_DELETE || (v) == V_INCR) |
| 22 |
|
| |
| 23 |
|
| #define T_STRING 0 |
| 24 |
|
| #define T_ARRAY 1 |
| 25 |
|
| #define T_COMPILED 2 |
| 26 |
|
| |
| 27 |
|
| #define MAX_CALL_COMPONENTS 16 |
| 28 |
|
| |
| 29 |
|
| /* What a call borrows from a mount record or binding is held until the |
| 30 |
|
| caller's statement ends: the callee may unmount the very mount it runs on. */ |
| 31 |
|
| #define HOLD(sv) sv_2mortal(SvREFCNT_inc_simple_NN((SV *)(sv))) |
| 32 |
|
| |
| 33 |
|
| static const char *const VERB_NAME[] = { "get", "set", "delete", "exists", "incr" }; |
| 34 |
|
| static const I32 VERB_LEN[] = { 3, 3, 6, 6, 4 }; |
| 35 |
|
| |
| 36 |
|
| static const char *const SLOW[3][6] = { |
| 37 |
|
| { "Data::Shared::_pp_shared_get", "Data::Shared::_pp_shared_set", |
| 38 |
|
| "Data::Shared::_pp_shared_delete", "Data::Shared::_pp_shared_exists", |
| 39 |
|
| "Data::Shared::_pp_shared_incr", "Data::Shared::_pp_shared_call" }, |
| 40 |
|
| { "Data::Shared::_pp_shareda_get", "Data::Shared::_pp_shareda_set", |
| 41 |
|
| "Data::Shared::_pp_shareda_delete", "Data::Shared::_pp_shareda_exists", |
| 42 |
|
| "Data::Shared::_pp_shareda_incr", "Data::Shared::_pp_shareda_call" }, |
| 43 |
|
| { "Data::Shared::_pp_sharedc_get", "Data::Shared::_pp_sharedc_set", |
| 44 |
|
| "Data::Shared::_pp_sharedc_delete", "Data::Shared::_pp_sharedc_exists", |
| 45 |
|
| "Data::Shared::_pp_sharedc_incr", "Data::Shared::_pp_sharedc_call" }, |
| 46 |
|
| }; |
| 47 |
|
| |
| 48 |
|
| /* Calls the Perl implementation with this XSUB's own arguments, in the |
| 49 |
|
| caller's context; its results land where this XSUB's arguments were. */ |
| 50 |
2907 |
| static I32 slow_path(pTHX_ int tier, int verb, I32 ax, I32 items, I32 gimme) |
| 51 |
|
| { |
| 52 |
2907 |
| SV **sp = PL_stack_base + ax - 1; |
| 53 |
2907 |
| CV *slow = get_cv(SLOW[tier][verb], 0); |
| 54 |
2907 |
▶ | if (!slow) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!slow) |
0 |
2907 |
2907 |
|
| 55 |
0 |
| croak("Data::Shared: %s is missing", SLOW[tier][verb]); |
| 56 |
2907 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
2907 |
2907 |
|
| 57 |
2907 |
| sp += items; |
| 58 |
2907 |
| PUTBACK; |
| 59 |
2907 |
| return call_sv((SV *)slow, gimme); |
| 60 |
|
| } |
| 61 |
|
| |
| 62 |
4687 |
| static HV *hv_of(SV *sv) |
| 63 |
|
| { |
| 64 |
4687 |
▶ | return sv && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV ? (HV *)SvRV(sv) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return sv && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV ? (HV *)SvRV(sv) : NULL; |
3859 |
828 |
4687 |
| return sv && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV ? (HV *)SvRV(sv) : NULL; |
3859 |
0 |
3859 |
| return sv && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVHV ? (HV *)SvRV(sv) : NULL; |
3859 |
0 |
3859 |
|
| 65 |
|
| } |
| 66 |
|
| |
| 67 |
|
| /* Not SvRMAGICAL alone: a weak reference to a container gives it backref |
| 68 |
|
| magic, and the compiled bindings hold exactly such references. */ |
| 69 |
|
| #define TIED(sv) (SvRMAGICAL(sv) && mg_find((SV *)(sv), PERL_MAGIC_tied)) |
| 70 |
|
| |
| 71 |
1438 |
| static AV *av_of(pTHX_ SV *sv) |
| 72 |
|
| { |
| 73 |
|
| AV *av; |
| 74 |
1438 |
▶ | if (!sv || SvGMAGICAL(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!sv || SvGMAGICAL(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) |
999 |
439 |
1438 |
| if (!sv || SvGMAGICAL(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) |
998 |
1 |
999 |
| if (!sv || SvGMAGICAL(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) |
963 |
35 |
998 |
| if (!sv || SvGMAGICAL(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) |
0 |
963 |
963 |
|
| 75 |
475 |
| return NULL; |
| 76 |
963 |
| av = (AV *)SvRV(sv); |
| 77 |
963 |
▶ | return TIED(av) ? NULL : av; |
Branch: 2 branches
| Branch | True | False | Total |
| return TIED(av) ? NULL : av; |
175 |
788 |
963 |
| return TIED(av) ? NULL : av; |
175 |
0 |
175 |
|
| 78 |
|
| } |
| 79 |
|
| |
| 80 |
869 |
| static CV *cv_of(SV *sv) |
| 81 |
|
| { |
| 82 |
869 |
▶ | return sv && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV ? (CV *)SvRV(sv) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return sv && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV ? (CV *)SvRV(sv) : NULL; |
846 |
23 |
869 |
| return sv && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV ? (CV *)SvRV(sv) : NULL; |
506 |
340 |
846 |
| return sv && SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV ? (CV *)SvRV(sv) : NULL; |
506 |
0 |
506 |
|
| 83 |
|
| } |
| 84 |
|
| |
| 85 |
3954 |
| static HV *object_hv(pTHX_ SV *sv, const char *class, STRLEN len) |
| 86 |
|
| { |
| 87 |
|
| SV *obj; |
| 88 |
|
| HEK *name; |
| 89 |
3954 |
▶ | if (SvGMAGICAL(sv) || !SvROK(sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvGMAGICAL(sv) || !SvROK(sv)) |
3952 |
2 |
3954 |
| if (SvGMAGICAL(sv) || !SvROK(sv)) |
5 |
3947 |
3952 |
|
| 90 |
7 |
| return NULL; |
| 91 |
3947 |
| obj = SvRV(sv); |
| 92 |
3947 |
▶ | if (SvTYPE(obj) != SVt_PVHV || !SvOBJECT(obj) || TIED(obj)) |
Branch: 4 branches
| Branch | True | False | Total |
| if (SvTYPE(obj) != SVt_PVHV || !SvOBJECT(obj) || TIED(obj)) |
3947 |
0 |
3947 |
| if (SvTYPE(obj) != SVt_PVHV || !SvOBJECT(obj) || TIED(obj)) |
3946 |
1 |
3947 |
| if (SvTYPE(obj) != SVt_PVHV || !SvOBJECT(obj) || TIED(obj)) |
0 |
3946 |
3946 |
| if (SvTYPE(obj) != SVt_PVHV || !SvOBJECT(obj) || TIED(obj)) |
0 |
0 |
0 |
|
| 93 |
1 |
| return NULL; |
| 94 |
3946 |
▶ | name = SvSTASH(obj) ? HvNAME_HEK(SvSTASH(obj)) : NULL; |
Branch: 4 branches
| Branch | True | False | Total |
| name = SvSTASH(obj) ? HvNAME_HEK(SvSTASH(obj)) : NULL; |
3946 |
0 |
3946 |
| name = SvSTASH(obj) ? HvNAME_HEK(SvSTASH(obj)) : NULL; |
3946 |
0 |
3946 |
| name = SvSTASH(obj) ? HvNAME_HEK(SvSTASH(obj)) : NULL; |
3946 |
0 |
3946 |
| name = SvSTASH(obj) ? HvNAME_HEK(SvSTASH(obj)) : NULL; |
0 |
3946 |
3946 |
|
| 95 |
3946 |
▶ | if (!name || (STRLEN)HEK_LEN(name) != len || memNE(HEK_KEY(name), class, len)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!name || (STRLEN)HEK_LEN(name) != len || memNE(HEK_KEY(name), class, len)) |
3946 |
0 |
3946 |
| if (!name || (STRLEN)HEK_LEN(name) != len || memNE(HEK_KEY(name), class, len)) |
3944 |
2 |
3946 |
| if (!name || (STRLEN)HEK_LEN(name) != len || memNE(HEK_KEY(name), class, len)) |
0 |
3944 |
3944 |
|
| 96 |
2 |
| return NULL; |
| 97 |
3944 |
| return (HV *)obj; |
| 98 |
|
| } |
| 99 |
|
| |
| 100 |
|
| #define root_hv(sv) object_hv(aTHX_ (sv), "Data::Shared", 12) |
| 101 |
|
| #define compiled_hv(sv) object_hv(aTHX_ (sv), "Data::Shared::Compiled", 22) |
| 102 |
|
| |
| 103 |
9130 |
| static SV *fetch(pTHX_ HV *hv, const char *key, I32 klen) |
| 104 |
|
| { |
| 105 |
9130 |
| SV **svp = hv_fetch(hv, key, klen, 0); |
| 106 |
9130 |
▶ | return svp ? *svp : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return svp ? *svp : NULL; |
7840 |
1290 |
9130 |
|
| 107 |
|
| } |
| 108 |
|
| |
| 109 |
3397 |
| static int truthy(pTHX_ SV *sv) |
| 110 |
|
| { |
| 111 |
3397 |
▶ | return sv && SvTRUE(sv); |
Branch: 2 branches
| Branch | True | False | Total |
| return sv && SvTRUE(sv); |
3397 |
0 |
3397 |
| return sv && SvTRUE(sv); |
130 |
3267 |
3397 |
|
| 112 |
|
| } |
| 113 |
|
| |
| 114 |
2955 |
| static int plain_string(SV *sv) |
| 115 |
|
| { |
| 116 |
2955 |
▶ | return sv && SvPOK(sv) && !SvGMAGICAL(sv); |
Branch: 3 branches
| Branch | True | False | Total |
| return sv && SvPOK(sv) && !SvGMAGICAL(sv); |
2955 |
0 |
2955 |
| return sv && SvPOK(sv) && !SvGMAGICAL(sv); |
2912 |
43 |
2955 |
| return sv && SvPOK(sv) && !SvGMAGICAL(sv); |
2911 |
1 |
2912 |
|
| 117 |
|
| } |
| 118 |
|
| |
| 119 |
|
| /* _parse_string_path: the maximal runs of non-'/' bytes. -1 past max. */ |
| 120 |
2317 |
| static int split_path(const char *p, STRLEN len, const char **at, STRLEN *size, int max) |
| 121 |
|
| { |
| 122 |
2317 |
| const char *end = p + len; |
| 123 |
2317 |
| int n = 0; |
| 124 |
6651 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
5488 |
1163 |
6651 |
|
| 125 |
|
| const char *s; |
| 126 |
10999 |
▶ | while (p < end && *p == '/') |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p == '/') |
10940 |
59 |
10999 |
| while (p < end && *p == '/') |
5511 |
5429 |
10940 |
|
| 127 |
5511 |
| p++; |
| 128 |
5488 |
▶ | if (p >= end) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p >= end) |
59 |
5429 |
5488 |
|
| 129 |
59 |
| break; |
| 130 |
5429 |
| s = p; |
| 131 |
44048 |
▶ | while (p < end && *p != '/') |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != '/') |
41854 |
2194 |
44048 |
| while (p < end && *p != '/') |
38619 |
3235 |
41854 |
|
| 132 |
38619 |
| p++; |
| 133 |
5429 |
▶ | if (n == max) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n == max) |
1095 |
4334 |
5429 |
|
| 134 |
1095 |
| return -1; |
| 135 |
4334 |
| at[n] = s; |
| 136 |
4334 |
| size[n] = (STRLEN)(p - s); |
| 137 |
4334 |
| n++; |
| 138 |
|
| } |
| 139 |
1222 |
| return n; |
| 140 |
|
| } |
| 141 |
|
| |
| 142 |
|
| /* Registry's \A-?[0-9]+\z on the value Perl would match: 1 or 0, or -1 when |
| 143 |
|
| only Perl can tell (a float, a reference, magic). */ |
| 144 |
225 |
| static int index_shape(pTHX_ SV *sv) |
| 145 |
|
| { |
| 146 |
225 |
▶ | if (SvGMAGICAL(sv) || SvROK(sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvGMAGICAL(sv) || SvROK(sv)) |
225 |
0 |
225 |
| if (SvGMAGICAL(sv) || SvROK(sv)) |
0 |
225 |
225 |
|
| 147 |
0 |
| return -1; |
| 148 |
225 |
▶ | if (SvPOK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvPOK(sv)) { |
192 |
33 |
225 |
|
| 149 |
192 |
| STRLEN len, i = 0; |
| 150 |
192 |
| const char *p = SvPVX_const(sv); |
| 151 |
192 |
| len = SvCUR(sv); |
| 152 |
192 |
▶ | if (len && p[0] == '-') |
Branch: 2 branches
| Branch | True | False | Total |
| if (len && p[0] == '-') |
192 |
0 |
192 |
| if (len && p[0] == '-') |
6 |
186 |
192 |
|
| 153 |
6 |
| i = 1; |
| 154 |
192 |
▶ | if (i >= len) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i >= len) |
3 |
189 |
192 |
|
| 155 |
3 |
| return 0; |
| 156 |
392 |
▶ | for (; i < len; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (; i < len; i++) |
232 |
160 |
392 |
|
| 157 |
232 |
▶ | if (p[i] < '0' || p[i] > '9') |
Branch: 2 branches
| Branch | True | False | Total |
| if (p[i] < '0' || p[i] > '9') |
226 |
6 |
232 |
| if (p[i] < '0' || p[i] > '9') |
23 |
203 |
226 |
|
| 158 |
29 |
| return 0; |
| 159 |
160 |
| return 1; |
| 160 |
|
| } |
| 161 |
33 |
▶ | if (SvIOK(sv) && !SvNOK(sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvIOK(sv) && !SvNOK(sv)) |
27 |
6 |
33 |
| if (SvIOK(sv) && !SvNOK(sv)) |
27 |
0 |
27 |
|
| 162 |
27 |
| return 1; |
| 163 |
6 |
| return -1; |
| 164 |
|
| } |
| 165 |
|
| |
| 166 |
480 |
| static int args_plain(pTHX_ I32 ax, I32 from, I32 items) |
| 167 |
|
| { |
| 168 |
|
| I32 i; |
| 169 |
717 |
▶ | for (i = from; i < items; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = from; i < items; i++) |
243 |
474 |
717 |
|
| 170 |
243 |
▶ | if (SvGMAGICAL(ST(i))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvGMAGICAL(ST(i))) |
6 |
237 |
243 |
|
| 171 |
6 |
| return 0; |
| 172 |
474 |
| return 1; |
| 173 |
|
| } |
| 174 |
|
| |
| 175 |
1351 |
| static HV *flat_mount(pTHX_ HV *root, const char *name, STRLEN len, int utf8, int mutating) |
| 176 |
|
| { |
| 177 |
|
| HV *mounts, *m; |
| 178 |
1351 |
▶ | if (mutating && truthy(aTHX_ fetch(aTHX_ root, "readonly", 8))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (mutating && truthy(aTHX_ fetch(aTHX_ root, "readonly", 8))) |
653 |
698 |
1351 |
| if (mutating && truthy(aTHX_ fetch(aTHX_ root, "readonly", 8))) |
14 |
639 |
653 |
|
| 179 |
14 |
| return NULL; |
| 180 |
1337 |
▶ | if (truthy(aTHX_ fetch(aTHX_ root, "_nest_depth", 11))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (truthy(aTHX_ fetch(aTHX_ root, "_nest_depth", 11))) |
7 |
1330 |
1337 |
|
| 181 |
7 |
| return NULL; |
| 182 |
1330 |
▶ | if (!(mounts = hv_of(fetch(aTHX_ root, "mounts", 6)))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(mounts = hv_of(fetch(aTHX_ root, "mounts", 6)))) |
0 |
1330 |
1330 |
|
| 183 |
0 |
| return NULL; |
| 184 |
1330 |
▶ | m = hv_of(fetch(aTHX_ mounts, name, utf8 ? -(I32)len : (I32)len)); |
Branch: 1 branch
| Branch | True | False | Total |
| m = hv_of(fetch(aTHX_ mounts, name, utf8 ? -(I32)len : (I32)len)); |
10 |
1320 |
1330 |
|
| 185 |
1330 |
▶ | if (!m || truthy(aTHX_ fetch(aTHX_ m, "composite", 9))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!m || truthy(aTHX_ fetch(aTHX_ m, "composite", 9))) |
1296 |
34 |
1330 |
| if (!m || truthy(aTHX_ fetch(aTHX_ m, "composite", 9))) |
109 |
1187 |
1296 |
|
| 186 |
143 |
| return NULL; |
| 187 |
1187 |
| return m; |
| 188 |
|
| } |
| 189 |
|
| |
| 190 |
|
| /* Moves count results from the top of the stack to ST(0), copying any the |
| 191 |
|
| callee still owns, as returning through a Perl sub would. */ |
| 192 |
319 |
| static I32 settle(pTHX_ I32 ax, I32 count) |
| 193 |
|
| { |
| 194 |
|
| /* An index, not a pointer: a copy's get-magic may grow the stack. */ |
| 195 |
319 |
| I32 from = (I32)(PL_stack_sp - PL_stack_base) - count + 1, i; |
| 196 |
614 |
▶ | for (i = 0; i < count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < count; i++) { |
295 |
319 |
614 |
|
| 197 |
295 |
| SV *r = PL_stack_base[from + i]; |
| 198 |
295 |
▶ | if (!SvTEMP(r) && !SvIMMORTAL(r)) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!SvTEMP(r) && !SvIMMORTAL(r)) |
116 |
179 |
295 |
| if (!SvTEMP(r) && !SvIMMORTAL(r)) |
116 |
0 |
116 |
| if (!SvTEMP(r) && !SvIMMORTAL(r)) |
0 |
116 |
116 |
| if (!SvTEMP(r) && !SvIMMORTAL(r)) |
0 |
0 |
0 |
|
| 199 |
0 |
| r = sv_mortalcopy(r); |
| 200 |
295 |
| ST(i) = r; |
| 201 |
|
| } |
| 202 |
319 |
| return count; |
| 203 |
|
| } |
| 204 |
|
| |
| 205 |
71 |
| static I32 settle_bool(pTHX_ I32 ax, I32 count) |
| 206 |
|
| { |
| 207 |
71 |
▶ | SV *r = count ? *PL_stack_sp : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *r = count ? *PL_stack_sp : &PL_sv_undef; |
71 |
0 |
71 |
|
| 208 |
71 |
| ST(0) = sv_2mortal(newSViv(SvTRUE(r) ? 1 : 0)); |
| 209 |
71 |
| return 1; |
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
|
| /* Keyed::make_verb's closure for one key, from a fast_verb descriptor |
| 213 |
|
| [handle, code, by, flags]: the result count at ST(0), or -1 before |
| 214 |
|
| anything was pushed when the Perl path has to decide. */ |
| 215 |
375 |
| static I32 run_desc(pTHX_ AV *desc, SV *key, int verb, I32 ax, I32 from, I32 items, I32 gimme) |
| 216 |
|
| { |
| 217 |
|
| SV **d, *handle; |
| 218 |
|
| CV *code, *by; |
| 219 |
|
| IV flags; |
| 220 |
375 |
| I32 nargs = items - from, i, count; |
| 221 |
375 |
▶ | if (AvFILLp(desc) < 3 || !args_plain(aTHX_ ax, from, items)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (AvFILLp(desc) < 3 || !args_plain(aTHX_ ax, from, items)) |
375 |
0 |
375 |
| if (AvFILLp(desc) < 3 || !args_plain(aTHX_ ax, from, items)) |
4 |
371 |
375 |
|
| 222 |
4 |
| return -1; |
| 223 |
371 |
| d = AvARRAY(desc); |
| 224 |
371 |
| handle = d[0]; |
| 225 |
371 |
| code = cv_of(d[1]); |
| 226 |
371 |
| by = cv_of(d[2]); |
| 227 |
371 |
▶ | flags = d[3] ? SvIV(d[3]) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| flags = d[3] ? SvIV(d[3]) : 0; |
371 |
0 |
371 |
|
| 228 |
371 |
▶ | if (!handle || !code) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!handle || !code) |
371 |
0 |
371 |
| if (!handle || !code) |
0 |
371 |
371 |
|
| 229 |
0 |
| return -1; |
| 230 |
371 |
▶ | if ((flags & FAST_KEY_INT) && (verb != V_EXISTS || (flags & FAST_ABSENT))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if ((flags & FAST_KEY_INT) && (verb != V_EXISTS || (flags & FAST_ABSENT))) { |
254 |
117 |
371 |
| if ((flags & FAST_KEY_INT) && (verb != V_EXISTS || (flags & FAST_ABSENT))) { |
58 |
196 |
254 |
| if ((flags & FAST_KEY_INT) && (verb != V_EXISTS || (flags & FAST_ABSENT))) { |
29 |
29 |
58 |
|
| 231 |
225 |
| int shape = index_shape(aTHX_ key); |
| 232 |
225 |
▶ | if (shape < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (shape < 0) |
6 |
219 |
225 |
|
| 233 |
6 |
| return -1; |
| 234 |
219 |
▶ | if (!shape) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!shape) { |
32 |
187 |
219 |
|
| 235 |
32 |
▶ | if (verb != V_EXISTS) |
Branch: 1 branch
| Branch | True | False | Total |
| if (verb != V_EXISTS) |
23 |
9 |
32 |
|
| 236 |
23 |
| return -1; |
| 237 |
9 |
| ST(0) = sv_2mortal(newSViv(0)); |
| 238 |
9 |
| return 1; |
| 239 |
|
| } |
| 240 |
|
| } |
| 241 |
333 |
▶ | if ((flags & FAST_INCR) && nargs > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((flags & FAST_INCR) && nargs > 0) { |
48 |
285 |
333 |
| if ((flags & FAST_INCR) && nargs > 0) { |
32 |
16 |
48 |
|
| 242 |
32 |
▶ | if (!SvOK(ST(from))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(ST(from))) |
5 |
27 |
32 |
|
| 243 |
5 |
| return -1; |
| 244 |
27 |
▶ | if (by) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (by) { |
15 |
12 |
27 |
|
| 245 |
15 |
| code = by; |
| 246 |
15 |
| nargs = 1; |
| 247 |
|
| } |
| 248 |
|
| } |
| 249 |
328 |
| HOLD(code); |
| 250 |
|
| { |
| 251 |
328 |
| dSP; |
| 252 |
328 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
328 |
328 |
|
| 253 |
328 |
▶ | EXTEND(SP, 2 + nargs); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, 2 + nargs); |
328 |
0 |
328 |
| EXTEND(SP, 2 + nargs); |
0 |
328 |
328 |
|
| 254 |
328 |
| PUSHs(HOLD(handle)); |
| 255 |
328 |
| PUSHs(HOLD(key)); |
| 256 |
461 |
▶ | for (i = 0; i < nargs; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < nargs; i++) |
133 |
328 |
461 |
|
| 257 |
133 |
| PUSHs(sv_mortalcopy(ST(from + i))); |
| 258 |
328 |
| PUTBACK; |
| 259 |
|
| } |
| 260 |
328 |
▶ | if (verb == V_EXISTS) |
Branch: 1 branch
| Branch | True | False | Total |
| if (verb == V_EXISTS) |
67 |
261 |
328 |
|
| 261 |
67 |
| return settle_bool(aTHX_ ax, call_sv((SV *)code, G_SCALAR)); |
| 262 |
261 |
| count = call_sv((SV *)code, gimme); |
| 263 |
250 |
| return settle(aTHX_ ax, count); |
| 264 |
|
| } |
| 265 |
|
| |
| 266 |
78 |
| static I32 call_with(pTHX_ CV *code, I32 ax, I32 from, I32 items, I32 gimme, int boolean) |
| 267 |
|
| { |
| 268 |
|
| I32 i; |
| 269 |
78 |
| dSP; |
| 270 |
78 |
| HOLD(code); |
| 271 |
78 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
78 |
78 |
|
| 272 |
78 |
▶ | EXTEND(SP, items - from); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, items - from); |
78 |
0 |
78 |
| EXTEND(SP, items - from); |
0 |
78 |
78 |
|
| 273 |
116 |
▶ | for (i = from; i < items; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = from; i < items; i++) |
38 |
78 |
116 |
|
| 274 |
38 |
| PUSHs(ST(i)); |
| 275 |
78 |
| PUTBACK; |
| 276 |
78 |
▶ | if (boolean) |
Branch: 1 branch
| Branch | True | False | Total |
| if (boolean) |
7 |
71 |
78 |
|
| 277 |
7 |
| return settle_bool(aTHX_ ax, call_sv((SV *)code, G_SCALAR)); |
| 278 |
71 |
| return settle(aTHX_ ax, call_sv((SV *)code, gimme)); |
| 279 |
|
| } |
| 280 |
|
| |
| 281 |
1018 |
| static AV *fast_desc(pTHX_ HV *m, int verb) |
| 282 |
|
| { |
| 283 |
1018 |
| HV *fast = hv_of(fetch(aTHX_ m, "fast", 4)); |
| 284 |
1018 |
▶ | return fast ? av_of(aTHX_ fetch(aTHX_ fast, VERB_NAME[verb], VERB_LEN[verb])) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return fast ? av_of(aTHX_ fetch(aTHX_ fast, VERB_NAME[verb], VERB_LEN[verb])) : NULL; |
674 |
344 |
1018 |
|
| 285 |
|
| } |
| 286 |
|
| |
| 287 |
|
| /* A compiled binding [gen, bound, root, desc, key] still live for root. */ |
| 288 |
610 |
| static AV *live_binding(pTHX_ SV *rootref, SV *cpref, const char *key, I32 klen) |
| 289 |
|
| { |
| 290 |
|
| HV *cp, *bc, *root; |
| 291 |
|
| AV *entry; |
| 292 |
|
| SV **e, *gen; |
| 293 |
610 |
▶ | if (!SvROK(rootref) || !(cp = compiled_hv(cpref))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(rootref) || !(cp = compiled_hv(cpref))) |
610 |
0 |
610 |
| if (!SvROK(rootref) || !(cp = compiled_hv(cpref))) |
6 |
604 |
610 |
|
| 294 |
6 |
| return NULL; |
| 295 |
604 |
▶ | if (!(bc = hv_of(fetch(aTHX_ cp, "_bc", 3)))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bc = hv_of(fetch(aTHX_ cp, "_bc", 3)))) |
330 |
274 |
604 |
|
| 296 |
330 |
| return NULL; |
| 297 |
274 |
▶ | if (!(entry = av_of(aTHX_ fetch(aTHX_ bc, key, klen))) || AvFILLp(entry) < 2) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(entry = av_of(aTHX_ fetch(aTHX_ bc, key, klen))) || AvFILLp(entry) < 2) |
255 |
19 |
274 |
| if (!(entry = av_of(aTHX_ fetch(aTHX_ bc, key, klen))) || AvFILLp(entry) < 2) |
0 |
255 |
255 |
|
| 298 |
19 |
| return NULL; |
| 299 |
255 |
| e = AvARRAY(entry); |
| 300 |
255 |
▶ | if (!e[2] || !SvROK(e[2]) || SvRV(e[2]) != SvRV(rootref)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!e[2] || !SvROK(e[2]) || SvRV(e[2]) != SvRV(rootref)) |
255 |
0 |
255 |
| if (!e[2] || !SvROK(e[2]) || SvRV(e[2]) != SvRV(rootref)) |
253 |
2 |
255 |
| if (!e[2] || !SvROK(e[2]) || SvRV(e[2]) != SvRV(rootref)) |
17 |
236 |
253 |
|
| 301 |
19 |
| return NULL; |
| 302 |
236 |
▶ | if (!(root = hv_of(rootref)) || TIED(root)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(root = hv_of(rootref)) || TIED(root)) |
236 |
0 |
236 |
| if (!(root = hv_of(rootref)) || TIED(root)) |
0 |
236 |
236 |
| if (!(root = hv_of(rootref)) || TIED(root)) |
0 |
0 |
0 |
|
| 303 |
0 |
| return NULL; |
| 304 |
236 |
| gen = fetch(aTHX_ root, "gen", 3); |
| 305 |
236 |
▶ | if (!gen || !e[0] || SvGMAGICAL(gen) || SvIV(gen) != SvIV(e[0])) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!gen || !e[0] || SvGMAGICAL(gen) || SvIV(gen) != SvIV(e[0])) |
236 |
0 |
236 |
| if (!gen || !e[0] || SvGMAGICAL(gen) || SvIV(gen) != SvIV(e[0])) |
236 |
0 |
236 |
| if (!gen || !e[0] || SvGMAGICAL(gen) || SvIV(gen) != SvIV(e[0])) |
236 |
0 |
236 |
| if (!gen || !e[0] || SvGMAGICAL(gen) || SvIV(gen) != SvIV(e[0])) |
3 |
233 |
236 |
|
| 306 |
3 |
| return NULL; |
| 307 |
233 |
| return entry; |
| 308 |
|
| } |
| 309 |
|
| |
| 310 |
2152 |
| XS(xs_string_verb) |
| 311 |
|
| { |
| 312 |
2152 |
| dXSARGS; |
| 313 |
2152 |
| dXSI32; |
| 314 |
2152 |
| int verb = ix; |
| 315 |
2152 |
| I32 gimme = GIMME_V; |
| 316 |
|
| HV *root, *m; |
| 317 |
|
| AV *desc; |
| 318 |
|
| SV *path, *key; |
| 319 |
|
| const char *at[2]; |
| 320 |
|
| STRLEN size[2]; |
| 321 |
|
| I32 n; |
| 322 |
2152 |
▶ | if (items < 2 || !(root = root_hv(ST(0)))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (items < 2 || !(root = root_hv(ST(0)))) |
2149 |
3 |
2152 |
| if (items < 2 || !(root = root_hv(ST(0)))) |
2 |
2147 |
2149 |
|
| 323 |
5 |
| goto slow; |
| 324 |
2147 |
| path = ST(1); |
| 325 |
2147 |
▶ | if (!plain_string(path)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!plain_string(path)) |
13 |
2134 |
2147 |
|
| 326 |
13 |
| goto slow; |
| 327 |
2134 |
▶ | if (split_path(SvPVX_const(path), SvCUR(path), at, size, 2) != 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (split_path(SvPVX_const(path), SvCUR(path), at, size, 2) != 2) |
1185 |
949 |
2134 |
|
| 328 |
1185 |
| goto slow; |
| 329 |
949 |
▶ | m = flat_mount(aTHX_ root, at[0], size[0], SvUTF8(path), MUTATING(verb)); |
Branch: 3 branches
| Branch | True | False | Total |
| m = flat_mount(aTHX_ root, at[0], size[0], SvUTF8(path), MUTATING(verb)); |
652 |
297 |
949 |
| m = flat_mount(aTHX_ root, at[0], size[0], SvUTF8(path), MUTATING(verb)); |
568 |
84 |
652 |
| m = flat_mount(aTHX_ root, at[0], size[0], SvUTF8(path), MUTATING(verb)); |
158 |
410 |
568 |
|
| 330 |
949 |
▶ | if (!m || !(desc = fast_desc(aTHX_ m, verb))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!m || !(desc = fast_desc(aTHX_ m, verb))) |
843 |
106 |
949 |
| if (!m || !(desc = fast_desc(aTHX_ m, verb))) |
666 |
177 |
843 |
|
| 331 |
772 |
| goto slow; |
| 332 |
177 |
| key = newSVpvn_flags(at[1], size[1], SVs_TEMP | (SvUTF8(path) ? SVf_UTF8 : 0)); |
| 333 |
177 |
| n = run_desc(aTHX_ desc, key, verb, ax, 2, items, G_SCALAR); |
| 334 |
169 |
▶ | if (n >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n >= 0) |
145 |
24 |
169 |
|
| 335 |
145 |
| XSRETURN(n); |
| 336 |
24 |
| slow: |
| 337 |
1999 |
| XSRETURN(slow_path(aTHX_ T_STRING, verb, ax, items, gimme)); |
| 338 |
|
| } |
| 339 |
|
| |
| 340 |
301 |
| XS(xs_array_verb) |
| 341 |
|
| { |
| 342 |
301 |
| dXSARGS; |
| 343 |
301 |
| dXSI32; |
| 344 |
301 |
| int verb = ix; |
| 345 |
301 |
| I32 gimme = GIMME_V; |
| 346 |
|
| HV *root, *m; |
| 347 |
|
| AV *path, *desc; |
| 348 |
|
| SV *c0, *c1; |
| 349 |
|
| I32 n; |
| 350 |
301 |
▶ | if (items < 2 || !(root = root_hv(ST(0)))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (items < 2 || !(root = root_hv(ST(0)))) |
301 |
0 |
301 |
| if (items < 2 || !(root = root_hv(ST(0)))) |
0 |
301 |
301 |
|
| 351 |
0 |
| goto slow; |
| 352 |
301 |
▶ | if (!(path = av_of(aTHX_ ST(1))) || SvOBJECT(path) || AvFILLp(path) != 1) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(path = av_of(aTHX_ ST(1))) || SvOBJECT(path) || AvFILLp(path) != 1) |
299 |
2 |
301 |
| if (!(path = av_of(aTHX_ ST(1))) || SvOBJECT(path) || AvFILLp(path) != 1) |
296 |
3 |
299 |
| if (!(path = av_of(aTHX_ ST(1))) || SvOBJECT(path) || AvFILLp(path) != 1) |
61 |
235 |
296 |
|
| 353 |
66 |
| goto slow; |
| 354 |
235 |
| c0 = AvARRAY(path)[0]; |
| 355 |
235 |
| c1 = AvARRAY(path)[1]; |
| 356 |
235 |
▶ | if (!plain_string(c0) || !c1 || SvGMAGICAL(c1) || SvROK(c1) || !SvOK(c1)) |
Branch: 5 branches
| Branch | True | False | Total |
| if (!plain_string(c0) || !c1 || SvGMAGICAL(c1) || SvROK(c1) || !SvOK(c1)) |
220 |
15 |
235 |
| if (!plain_string(c0) || !c1 || SvGMAGICAL(c1) || SvROK(c1) || !SvOK(c1)) |
220 |
0 |
220 |
| if (!plain_string(c0) || !c1 || SvGMAGICAL(c1) || SvROK(c1) || !SvOK(c1)) |
218 |
2 |
220 |
| if (!plain_string(c0) || !c1 || SvGMAGICAL(c1) || SvROK(c1) || !SvOK(c1)) |
211 |
7 |
218 |
| if (!plain_string(c0) || !c1 || SvGMAGICAL(c1) || SvROK(c1) || !SvOK(c1)) |
17 |
194 |
211 |
|
| 357 |
41 |
| goto slow; |
| 358 |
194 |
▶ | m = flat_mount(aTHX_ root, SvPVX_const(c0), SvCUR(c0), SvUTF8(c0), MUTATING(verb)); |
Branch: 3 branches
| Branch | True | False | Total |
| m = flat_mount(aTHX_ root, SvPVX_const(c0), SvCUR(c0), SvUTF8(c0), MUTATING(verb)); |
149 |
45 |
194 |
| m = flat_mount(aTHX_ root, SvPVX_const(c0), SvCUR(c0), SvUTF8(c0), MUTATING(verb)); |
115 |
34 |
149 |
| m = flat_mount(aTHX_ root, SvPVX_const(c0), SvCUR(c0), SvUTF8(c0), MUTATING(verb)); |
35 |
80 |
115 |
|
| 359 |
194 |
▶ | if (!m || !(desc = fast_desc(aTHX_ m, verb))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!m || !(desc = fast_desc(aTHX_ m, verb))) |
175 |
19 |
194 |
| if (!m || !(desc = fast_desc(aTHX_ m, verb))) |
132 |
43 |
175 |
|
| 360 |
151 |
| goto slow; |
| 361 |
43 |
| n = run_desc(aTHX_ desc, sv_mortalcopy(c1), verb, ax, 2, items, G_SCALAR); |
| 362 |
43 |
▶ | if (n >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n >= 0) |
33 |
10 |
43 |
|
| 363 |
33 |
| XSRETURN(n); |
| 364 |
10 |
| slow: |
| 365 |
268 |
| XSRETURN(slow_path(aTHX_ T_ARRAY, verb, ax, items, gimme)); |
| 366 |
|
| } |
| 367 |
|
| |
| 368 |
534 |
| XS(xs_compiled_verb) |
| 369 |
|
| { |
| 370 |
534 |
| dXSARGS; |
| 371 |
534 |
| dXSI32; |
| 372 |
534 |
| int verb = ix; |
| 373 |
534 |
| I32 gimme = GIMME_V; |
| 374 |
|
| AV *entry, *desc; |
| 375 |
|
| SV **e; |
| 376 |
|
| CV *bound; |
| 377 |
|
| I32 n; |
| 378 |
|
| /* A subclass root goes to Perl, whose binding check compares with ==. */ |
| 379 |
534 |
▶ | if (items < 2 || !root_hv(ST(0))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (items < 2 || !root_hv(ST(0))) |
534 |
0 |
534 |
| if (items < 2 || !root_hv(ST(0))) |
2 |
532 |
534 |
|
| 380 |
2 |
| goto slow; |
| 381 |
532 |
▶ | if (!(entry = live_binding(aTHX_ ST(0), ST(1), VERB_NAME[verb], VERB_LEN[verb]))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(entry = live_binding(aTHX_ ST(0), ST(1), VERB_NAME[verb], VERB_LEN[verb]))) |
329 |
203 |
532 |
|
| 382 |
329 |
| goto slow; |
| 383 |
203 |
▶ | if (MUTATING(verb) && truthy(aTHX_ fetch(aTHX_ (HV *)SvRV(ST(0)), "readonly", 8))) |
Branch: 4 branches
| Branch | True | False | Total |
| if (MUTATING(verb) && truthy(aTHX_ fetch(aTHX_ (HV *)SvRV(ST(0)), "readonly", 8))) |
171 |
32 |
203 |
| if (MUTATING(verb) && truthy(aTHX_ fetch(aTHX_ (HV *)SvRV(ST(0)), "readonly", 8))) |
146 |
25 |
171 |
| if (MUTATING(verb) && truthy(aTHX_ fetch(aTHX_ (HV *)SvRV(ST(0)), "readonly", 8))) |
54 |
92 |
146 |
| if (MUTATING(verb) && truthy(aTHX_ fetch(aTHX_ (HV *)SvRV(ST(0)), "readonly", 8))) |
0 |
111 |
111 |
|
| 384 |
0 |
| goto slow; |
| 385 |
203 |
| e = AvARRAY(entry); |
| 386 |
203 |
▶ | if (AvFILLp(entry) >= 4 && (desc = av_of(aTHX_ e[3])) && e[4]) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (AvFILLp(entry) >= 4 && (desc = av_of(aTHX_ e[3])) && e[4]) { |
155 |
48 |
203 |
| if (AvFILLp(entry) >= 4 && (desc = av_of(aTHX_ e[3])) && e[4]) { |
155 |
0 |
155 |
| if (AvFILLp(entry) >= 4 && (desc = av_of(aTHX_ e[3])) && e[4]) { |
155 |
0 |
155 |
|
| 387 |
155 |
| n = run_desc(aTHX_ desc, e[4], verb, ax, 2, items, gimme); |
| 388 |
149 |
▶ | if (n >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n >= 0) |
145 |
4 |
149 |
|
| 389 |
145 |
| XSRETURN(n); |
| 390 |
4 |
| goto slow; |
| 391 |
|
| } |
| 392 |
48 |
▶ | if (!(bound = cv_of(e[1]))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bound = cv_of(e[1]))) |
0 |
48 |
48 |
|
| 393 |
0 |
| goto slow; |
| 394 |
48 |
| XSRETURN(call_with(aTHX_ bound, ax, 2, items, gimme, verb == V_EXISTS)); |
| 395 |
335 |
| slow: |
| 396 |
335 |
| XSRETURN(slow_path(aTHX_ T_COMPILED, verb, ax, items, gimme)); |
| 397 |
|
| } |
| 398 |
|
| |
| 399 |
|
| /* A method name the Perl path would pass straight through to can(). */ |
| 400 |
360 |
| static int plain_method(pTHX_ SV *m) |
| 401 |
|
| { |
| 402 |
|
| const char *p; |
| 403 |
|
| STRLEN len; |
| 404 |
360 |
▶ | if (!plain_string(m) || !SvCUR(m)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!plain_string(m) || !SvCUR(m)) |
344 |
16 |
360 |
| if (!plain_string(m) || !SvCUR(m)) |
12 |
332 |
344 |
|
| 405 |
28 |
| return 0; |
| 406 |
332 |
| p = SvPVX_const(m); |
| 407 |
332 |
| len = SvCUR(m); |
| 408 |
332 |
▶ | if (memchr(p, ':', len)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (memchr(p, ':', len)) |
18 |
314 |
332 |
|
| 409 |
18 |
| return 0; |
| 410 |
314 |
▶ | return !(len == 6 && memEQ(p, "unlink", 6)) && !(len == 7 && memEQ(p, "destroy", 7)) |
Branch: 3 branches
| Branch | True | False | Total |
| return !(len == 6 && memEQ(p, "unlink", 6)) && !(len == 7 && memEQ(p, "destroy", 7)) |
16 |
12 |
28 |
| return !(len == 6 && memEQ(p, "unlink", 6)) && !(len == 7 && memEQ(p, "destroy", 7)) |
11 |
291 |
302 |
| return !(len == 6 && memEQ(p, "unlink", 6)) && !(len == 7 && memEQ(p, "destroy", 7)) |
6 |
5 |
11 |
|
| 411 |
628 |
▶ | && !(len == 6 && memEQ(p, "freeze", 6)); |
Branch: 3 branches
| Branch | True | False | Total |
| && !(len == 6 && memEQ(p, "freeze", 6)); |
28 |
286 |
314 |
| && !(len == 6 && memEQ(p, "freeze", 6)); |
16 |
281 |
297 |
| && !(len == 6 && memEQ(p, "freeze", 6)); |
15 |
1 |
16 |
|
| 412 |
|
| } |
| 413 |
|
| |
| 414 |
|
| /* _dispatch_record_call: handle->method(@rest, @args) through the can() cache. */ |
| 415 |
169 |
| static I32 call_mount(pTHX_ HV *m, SV *method, SV **rest, I32 nrest, I32 ax, I32 items, I32 gimme) |
| 416 |
|
| { |
| 417 |
|
| HV *can; |
| 418 |
|
| CV *code; |
| 419 |
|
| SV *handle; |
| 420 |
|
| I32 i; |
| 421 |
169 |
▶ | if (!(can = hv_of(fetch(aTHX_ m, "can", 3)))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(can = hv_of(fetch(aTHX_ m, "can", 3)))) |
120 |
49 |
169 |
|
| 422 |
120 |
| return -1; |
| 423 |
49 |
| code = cv_of(fetch(aTHX_ can, SvPVX_const(method), |
| 424 |
49 |
▶ | SvUTF8(method) ? -(I32)SvCUR(method) : (I32)SvCUR(method))); |
Branch: 1 branch
| Branch | True | False | Total |
| SvUTF8(method) ? -(I32)SvCUR(method) : (I32)SvCUR(method))); |
0 |
49 |
49 |
|
| 425 |
49 |
| handle = fetch(aTHX_ m, "handle", 6); |
| 426 |
49 |
▶ | if (!code || !handle || !args_plain(aTHX_ ax, 3, items)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!code || !handle || !args_plain(aTHX_ ax, 3, items)) |
26 |
23 |
49 |
| if (!code || !handle || !args_plain(aTHX_ ax, 3, items)) |
26 |
0 |
26 |
| if (!code || !handle || !args_plain(aTHX_ ax, 3, items)) |
1 |
25 |
26 |
|
| 427 |
24 |
| return -1; |
| 428 |
25 |
| HOLD(code); |
| 429 |
|
| { |
| 430 |
25 |
| dSP; |
| 431 |
25 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
25 |
25 |
|
| 432 |
25 |
▶ | EXTEND(SP, 1 + nrest + items - 3); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, 1 + nrest + items - 3); |
25 |
0 |
25 |
| EXTEND(SP, 1 + nrest + items - 3); |
0 |
25 |
25 |
|
| 433 |
|
| /* A copy, as Perl's lexical $handle is: the invocant must not alias |
| 434 |
|
| the mount record's slot. */ |
| 435 |
25 |
| PUSHs(sv_mortalcopy(handle)); |
| 436 |
25 |
▶ | for (i = 0; i < nrest; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < nrest; i++) |
0 |
25 |
25 |
|
| 437 |
0 |
| PUSHs(rest[i]); |
| 438 |
48 |
▶ | for (i = 3; i < items; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 3; i < items; i++) |
23 |
25 |
48 |
|
| 439 |
23 |
| PUSHs(sv_mortalcopy(ST(i))); |
| 440 |
25 |
| PUTBACK; |
| 441 |
|
| } |
| 442 |
25 |
| return settle(aTHX_ ax, call_sv((SV *)code, gimme)); |
| 443 |
|
| } |
| 444 |
|
| |
| 445 |
215 |
| XS(xs_string_call) |
| 446 |
|
| { |
| 447 |
215 |
| dXSARGS; |
| 448 |
215 |
| I32 gimme = GIMME_V; |
| 449 |
|
| HV *root, *m; |
| 450 |
|
| SV *path, *rest[MAX_CALL_COMPONENTS]; |
| 451 |
|
| const char *at[MAX_CALL_COMPONENTS + 1]; |
| 452 |
|
| STRLEN size[MAX_CALL_COMPONENTS + 1]; |
| 453 |
|
| int n, i, utf8; |
| 454 |
|
| I32 r; |
| 455 |
215 |
▶ | if (items < 3 || !(root = root_hv(ST(0))) || !plain_method(aTHX_ ST(2))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (items < 3 || !(root = root_hv(ST(0))) || !plain_method(aTHX_ ST(2))) |
215 |
0 |
215 |
| if (items < 3 || !(root = root_hv(ST(0))) || !plain_method(aTHX_ ST(2))) |
215 |
0 |
215 |
| if (items < 3 || !(root = root_hv(ST(0))) || !plain_method(aTHX_ ST(2))) |
32 |
183 |
215 |
|
| 456 |
32 |
| goto slow; |
| 457 |
183 |
| path = ST(1); |
| 458 |
183 |
▶ | if (!plain_string(path)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!plain_string(path)) |
0 |
183 |
183 |
|
| 459 |
0 |
| goto slow; |
| 460 |
183 |
| n = split_path(SvPVX_const(path), SvCUR(path), at, size, MAX_CALL_COMPONENTS + 1); |
| 461 |
183 |
▶ | if (n < 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n < 1) |
5 |
178 |
183 |
|
| 462 |
5 |
| goto slow; |
| 463 |
178 |
| utf8 = SvUTF8(path) ? 1 : 0; |
| 464 |
178 |
▶ | if (!(m = flat_mount(aTHX_ root, at[0], size[0], utf8, 0))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(m = flat_mount(aTHX_ root, at[0], size[0], utf8, 0))) |
36 |
142 |
178 |
|
| 465 |
36 |
| goto slow; |
| 466 |
145 |
▶ | for (i = 1; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < n; i++) |
3 |
142 |
145 |
|
| 467 |
3 |
▶ | rest[i - 1] = newSVpvn_flags(at[i], size[i], SVs_TEMP | (utf8 ? SVf_UTF8 : 0)); |
Branch: 1 branch
| Branch | True | False | Total |
| rest[i - 1] = newSVpvn_flags(at[i], size[i], SVs_TEMP | (utf8 ? SVf_UTF8 : 0)); |
0 |
3 |
3 |
|
| 468 |
142 |
| r = call_mount(aTHX_ m, ST(2), rest, n - 1, ax, items, gimme); |
| 469 |
142 |
▶ | if (r >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r >= 0) |
21 |
121 |
142 |
|
| 470 |
21 |
| XSRETURN(r); |
| 471 |
121 |
| slow: |
| 472 |
194 |
| XSRETURN(slow_path(aTHX_ T_STRING, V_CALL, ax, items, gimme)); |
| 473 |
|
| } |
| 474 |
|
| |
| 475 |
45 |
| XS(xs_array_call) |
| 476 |
|
| { |
| 477 |
45 |
| dXSARGS; |
| 478 |
45 |
| I32 gimme = GIMME_V; |
| 479 |
|
| HV *root, *m; |
| 480 |
|
| AV *path; |
| 481 |
|
| SV *c0, *rest[MAX_CALL_COMPONENTS]; |
| 482 |
|
| I32 n, i, r; |
| 483 |
45 |
▶ | if (items < 3 || !(root = root_hv(ST(0))) || !plain_method(aTHX_ ST(2))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (items < 3 || !(root = root_hv(ST(0))) || !plain_method(aTHX_ ST(2))) |
45 |
0 |
45 |
| if (items < 3 || !(root = root_hv(ST(0))) || !plain_method(aTHX_ ST(2))) |
45 |
0 |
45 |
| if (items < 3 || !(root = root_hv(ST(0))) || !plain_method(aTHX_ ST(2))) |
11 |
34 |
45 |
|
| 484 |
11 |
| goto slow; |
| 485 |
34 |
▶ | if (!(path = av_of(aTHX_ ST(1))) || SvOBJECT(path)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(path = av_of(aTHX_ ST(1))) || SvOBJECT(path)) |
34 |
0 |
34 |
| if (!(path = av_of(aTHX_ ST(1))) || SvOBJECT(path)) |
0 |
34 |
34 |
|
| 486 |
0 |
| goto slow; |
| 487 |
34 |
| n = AvFILLp(path) + 1; |
| 488 |
34 |
▶ | if (n < 1 || n > MAX_CALL_COMPONENTS + 1) |
Branch: 2 branches
| Branch | True | False | Total |
| if (n < 1 || n > MAX_CALL_COMPONENTS + 1) |
30 |
4 |
34 |
| if (n < 1 || n > MAX_CALL_COMPONENTS + 1) |
0 |
30 |
30 |
|
| 489 |
4 |
| goto slow; |
| 490 |
30 |
| c0 = AvARRAY(path)[0]; |
| 491 |
30 |
▶ | if (!plain_string(c0)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!plain_string(c0)) |
0 |
30 |
30 |
|
| 492 |
0 |
| goto slow; |
| 493 |
33 |
▶ | for (i = 1; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < n; i++) { |
3 |
30 |
33 |
|
| 494 |
3 |
| SV *c = AvARRAY(path)[i]; |
| 495 |
3 |
▶ | if (!c || SvGMAGICAL(c) || SvROK(c) || !SvOK(c)) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!c || SvGMAGICAL(c) || SvROK(c) || !SvOK(c)) |
3 |
0 |
3 |
| if (!c || SvGMAGICAL(c) || SvROK(c) || !SvOK(c)) |
3 |
0 |
3 |
| if (!c || SvGMAGICAL(c) || SvROK(c) || !SvOK(c)) |
3 |
0 |
3 |
| if (!c || SvGMAGICAL(c) || SvROK(c) || !SvOK(c)) |
0 |
3 |
3 |
|
| 496 |
0 |
| goto slow; |
| 497 |
|
| } |
| 498 |
30 |
▶ | if (!(m = flat_mount(aTHX_ root, SvPVX_const(c0), SvCUR(c0), SvUTF8(c0), 0))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(m = flat_mount(aTHX_ root, SvPVX_const(c0), SvCUR(c0), SvUTF8(c0), 0))) |
3 |
27 |
30 |
|
| 499 |
3 |
| goto slow; |
| 500 |
30 |
▶ | for (i = 1; i < n; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < n; i++) |
3 |
27 |
30 |
|
| 501 |
3 |
| rest[i - 1] = sv_mortalcopy(AvARRAY(path)[i]); |
| 502 |
27 |
| r = call_mount(aTHX_ m, ST(2), rest, n - 1, ax, items, gimme); |
| 503 |
27 |
▶ | if (r >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r >= 0) |
4 |
23 |
27 |
|
| 504 |
4 |
| XSRETURN(r); |
| 505 |
23 |
| slow: |
| 506 |
41 |
| XSRETURN(slow_path(aTHX_ T_ARRAY, V_CALL, ax, items, gimme)); |
| 507 |
|
| } |
| 508 |
|
| |
| 509 |
100 |
| XS(xs_compiled_call) |
| 510 |
|
| { |
| 511 |
100 |
| dXSARGS; |
| 512 |
100 |
| I32 gimme = GIMME_V; |
| 513 |
|
| AV *entry; |
| 514 |
|
| CV *bound; |
| 515 |
|
| SV *m; |
| 516 |
|
| char key[256]; |
| 517 |
|
| STRLEN len; |
| 518 |
|
| /* Perl copies the arguments before it picks the binding; a tied one may |
| 519 |
|
| retire that binding when fetched. */ |
| 520 |
100 |
▶ | if (items < 3 || !root_hv(ST(0)) || !plain_method(aTHX_ (m = ST(2))) |
Branch: 3 branches
| Branch | True | False | Total |
| if (items < 3 || !root_hv(ST(0)) || !plain_method(aTHX_ (m = ST(2))) |
100 |
0 |
100 |
| if (items < 3 || !root_hv(ST(0)) || !plain_method(aTHX_ (m = ST(2))) |
100 |
0 |
100 |
| if (items < 3 || !root_hv(ST(0)) || !plain_method(aTHX_ (m = ST(2))) |
79 |
21 |
100 |
|
| 521 |
79 |
▶ | || !args_plain(aTHX_ ax, 3, items)) |
Branch: 1 branch
| Branch | True | False | Total |
| || !args_plain(aTHX_ ax, 3, items)) |
1 |
78 |
79 |
|
| 522 |
22 |
| goto slow; |
| 523 |
78 |
| len = SvCUR(m); |
| 524 |
78 |
▶ | if (len > sizeof key - 5) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > sizeof key - 5) |
0 |
78 |
78 |
|
| 525 |
0 |
| goto slow; |
| 526 |
78 |
| memcpy(key, "call:", 5); |
| 527 |
78 |
| memcpy(key + 5, SvPVX_const(m), len); |
| 528 |
78 |
▶ | if (!(entry = live_binding(aTHX_ ST(0), ST(1), key, |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(entry = live_binding(aTHX_ ST(0), ST(1), key, |
48 |
30 |
78 |
|
| 529 |
78 |
▶ | SvUTF8(m) ? -(I32)(len + 5) : (I32)(len + 5)))) |
Branch: 1 branch
| Branch | True | False | Total |
| SvUTF8(m) ? -(I32)(len + 5) : (I32)(len + 5)))) |
0 |
78 |
78 |
|
| 530 |
48 |
| goto slow; |
| 531 |
30 |
▶ | if (!(bound = cv_of(AvARRAY(entry)[1]))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(bound = cv_of(AvARRAY(entry)[1]))) |
0 |
30 |
30 |
|
| 532 |
0 |
| goto slow; |
| 533 |
30 |
| XSRETURN(call_with(aTHX_ bound, ax, 3, items, gimme, 0)); |
| 534 |
70 |
| slow: |
| 535 |
70 |
| XSRETURN(slow_path(aTHX_ T_COMPILED, V_CALL, ax, items, gimme)); |
| 536 |
|
| } |
| 537 |
|
| |
| 538 |
|
| MODULE = Data::Shared PACKAGE = Data::Shared |
| 539 |
|
| |
| 540 |
|
| PROTOTYPES: DISABLE |
| 541 |
|
| |
| 542 |
|
| BOOT: |
| 543 |
|
| { |
| 544 |
|
| static const char *const names[3][5] = { |
| 545 |
|
| { "Data::Shared::shared_get", "Data::Shared::shared_set", "Data::Shared::shared_delete", |
| 546 |
|
| "Data::Shared::shared_exists", "Data::Shared::shared_incr" }, |
| 547 |
|
| { "Data::Shared::shareda_get", "Data::Shared::shareda_set", "Data::Shared::shareda_delete", |
| 548 |
|
| "Data::Shared::shareda_exists", "Data::Shared::shareda_incr" }, |
| 549 |
|
| { "Data::Shared::sharedc_get", "Data::Shared::sharedc_set", "Data::Shared::sharedc_delete", |
| 550 |
|
| "Data::Shared::sharedc_exists", "Data::Shared::sharedc_incr" }, |
| 551 |
|
| }; |
| 552 |
39 |
| XSUBADDR_t verb_xs[3] = { xs_string_verb, xs_array_verb, xs_compiled_verb }; |
| 553 |
|
| int t, v; |
| 554 |
156 |
▶ | for (t = 0; t < 3; t++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (t = 0; t < 3; t++) |
117 |
39 |
156 |
|
| 555 |
702 |
▶ | for (v = 0; v < 5; v++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (v = 0; v < 5; v++) |
585 |
117 |
702 |
|
| 556 |
585 |
| CvXSUBANY(newXS(names[t][v], verb_xs[t], __FILE__)).any_i32 = v; |
| 557 |
39 |
| newXS("Data::Shared::shared_call", xs_string_call, __FILE__); |
| 558 |
39 |
| newXS("Data::Shared::shareda_call", xs_array_call, __FILE__); |
| 559 |
39 |
| newXS("Data::Shared::sharedc_call", xs_compiled_call, __FILE__); |
| 560 |
|
| } |