include/store/store_call.h

filter: Statementstmt 100% 31 / 31 Branchbran 70.0% 21 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 85.2% 52 / 61 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/store/store_abi_impl.h ↑ Summary include/store/store_core.h »
1 #ifndef STORE_CALL_H
2 #define STORE_CALL_H
3  
4 /* G_LIST is perl 5.36's name for what older perls call G_ARRAY. */
5 #ifndef G_LIST
6 # define G_LIST G_ARRAY
7 #endif
8  
9 /* A caller's scalar read once - its magic run once - into a mortal copy
10 * the rest can read as often as it likes. Not sv_mortalcopy: that takes
11 * the string buffer of a temporary it copies, leaving the temporary empty,
12 * and a temporary is what a sub's return value is. NOSTEAL copies it. */
13 41929 static SV *store_read_once(pTHX_ SV *sv) {
14 41929 SV *c = sv_newmortal();
15 41929 sv_setsv_flags(c, sv, SV_GMAGIC | SV_NOSTEAL);
16 41929 return c;
17 }
18  
19 /* Every sub the store calls - a swap's, a watcher, the validator, a
20 * transaction's - is called through here.
21 *
22 * On a stack of its own, as perl's sort calls its comparison. Without that,
23 * `last` or `next` inside the sub finds the caller's loop on the context
24 * stack and jumps to it straight through this library's C, which never
25 * gets control back: a transaction would stay open for ever. On a stack of
26 * its own there is no loop to find, so it is an error like any other, and
27 * the store deals with it as it deals with a die.
28 *
29 * Under G_EVAL, with $@ localised, so that a call that works leaves the
30 * caller's $@ as it was. A die comes back as a copy of the error, mortal,
31 * for the caller to throw again once it has put things right.
32 *
33 * `gimme` is G_VOID, G_SCALAR or G_LIST. A scalar result is put in *one;
34 * list results are pushed onto `many`. Either is a temporary that lives as
35 * long as the caller's temps frame. */
36 154158 static SV *store_call(pTHX_ SV *code, SV **args, I32 nargs, I32 gimme,
37 SV **one, AV *many) {
38 154158 dSP;
39 154158 SV *err = NULL;
40 I32 n, i;
41  
42 154158 ▶ if (one) *one = &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
if (one) *one = &PL_sv_undef; 114882 39276 154158
43 154158 ENTER;
44 154158 save_scalar(PL_errgv);
45 154158 PUSHSTACKi(PERLSI_UNKNOWN);
46 {
47 154158 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 154158 154158
48 154158 ▶ EXTEND(SP, nargs);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, nargs); 154158 0 154158
EXTEND(SP, nargs); 0 154158 154158
49 386972 ▶ for (i = 0; i < nargs; i++) PUSHs(args[i]);
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nargs; i++) PUSHs(args[i]); 232814 154158 386972
50 154158 PUTBACK;
51 154158 n = call_sv(code, gimme | G_EVAL);
52 154158 SPAGAIN;
53 154158 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 154158 0 154158
if (SvTRUE(ERRSV)) { 2028 152130 154158
54 2028 ▶ err = sv_2mortal(newSVsv(ERRSV));
Branch: 1 branch
BranchTrueFalseTotal
err = sv_2mortal(newSVsv(ERRSV)); 2028 0 2028
55 }
56 152130 ▶ else if (gimme == G_SCALAR && one) {
Branch: 2 branches
BranchTrueFalseTotal
else if (gimme == G_SCALAR && one) { 110826 41304 152130
else if (gimme == G_SCALAR && one) { 110826 0 110826
57 110826 ▶ if (n > 0) *one = *SP;
Branch: 1 branch
BranchTrueFalseTotal
if (n > 0) *one = *SP; 110826 0 110826
58 }
59 41304 ▶ else if (gimme == G_LIST && many) {
Branch: 2 branches
BranchTrueFalseTotal
else if (gimme == G_LIST && many) { 3 41301 41304
else if (gimme == G_LIST && many) { 3 0 3
60 8 ▶ for (i = n; i > 0; i--) av_push(many, SvREFCNT_inc_simple_NN(*(SP - i + 1)));
Branch: 1 branch
BranchTrueFalseTotal
for (i = n; i > 0; i--) av_push(many, SvREFCNT_inc_simple_NN(*(SP - i + 1))); 5 3 8
61 }
62 154158 SP -= n;
63 154158 PUTBACK;
64 }
65 154158 POPSTACK;
66 154158 LEAVE;
67 154158 return err;
68 }
69  
70 /* Throw `err` again. */
71 2027 static void store_rethrow(pTHX_ SV *err) {
72 2027 ▶ sv_setsv(ERRSV, err);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, err); 2027 0 2027
73 2027 croak(NULL);
74 }
75  
76 #endif
« include/store/store_abi_impl.h ↑ Summary include/store/store_core.h »