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_history.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 54187 static SV *store_read_once(pTHX_ SV *sv) {
14 54187 SV *c = sv_newmortal();
15 54187 sv_setsv_flags(c, sv, SV_GMAGIC | SV_NOSTEAL);
16 54187 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 154776 static SV *store_call(pTHX_ SV *code, SV **args, I32 nargs, I32 gimme,
37 SV **one, AV *many) {
38 154776 dSP;
39 154776 SV *err = NULL;
40 I32 n, i;
41  
42 154776 ▶ if (one) *one = &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
if (one) *one = &PL_sv_undef; 115500 39276 154776
43 154776 ENTER;
44 154776 save_scalar(PL_errgv);
45 154776 PUSHSTACKi(PERLSI_UNKNOWN);
46 {
47 154776 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 154776 154776
48 154776 ▶ EXTEND(SP, nargs);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, nargs); 154776 0 154776
EXTEND(SP, nargs); 0 154776 154776
49 389442 ▶ for (i = 0; i < nargs; i++) PUSHs(args[i]);
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nargs; i++) PUSHs(args[i]); 234666 154776 389442
50 154776 PUTBACK;
51 154776 n = call_sv(code, gimme | G_EVAL);
52 154776 SPAGAIN;
53 154776 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 154776 0 154776
if (SvTRUE(ERRSV)) { 2029 152747 154776
54 2029 ▶ err = sv_2mortal(newSVsv(ERRSV));
Branch: 1 branch
BranchTrueFalseTotal
err = sv_2mortal(newSVsv(ERRSV)); 2029 0 2029
55 }
56 152747 ▶ else if (gimme == G_SCALAR && one) {
Branch: 2 branches
BranchTrueFalseTotal
else if (gimme == G_SCALAR && one) { 111442 41305 152747
else if (gimme == G_SCALAR && one) { 111442 0 111442
57 111442 ▶ if (n > 0) *one = *SP;
Branch: 1 branch
BranchTrueFalseTotal
if (n > 0) *one = *SP; 111442 0 111442
58 }
59 41305 ▶ else if (gimme == G_LIST && many) {
Branch: 2 branches
BranchTrueFalseTotal
else if (gimme == G_LIST && many) { 3 41302 41305
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 154776 SP -= n;
63 154776 PUTBACK;
64 }
65 154776 POPSTACK;
66 154776 LEAVE;
67 154776 return err;
68 }
69  
70 /* Throw `err` again. */
71 2028 static void store_rethrow(pTHX_ SV *err) {
72 2028 ▶ sv_setsv(ERRSV, err);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, err); 2028 0 2028
73 2028 croak(NULL);
74 }
75  
76 #endif
« include/store/store_abi_impl.h ↑ Summary include/store/store_history.h »