xs/abi.xs

filter: Statementstmt 100% 27 / 27 Branchbran 60.0% 18 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 78.9% 45 / 57 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_ratelimit.h ↑ Summary xs/txn.xs »
1 MODULE = Punk PACKAGE = Punk
2  
3 PROTOTYPES: DISABLE
4  
5 # Address of Punk's own C ABI table (pk_abi.h). A consumer XS module fetches
6 # this once at boot, INT2PTRs it to a `const pk_abi *`, and checks
7 # ->abi_version before using it. Not part of the public Perl API.
8 #
9 # Unsigned, not IV: where the loader maps this object decides the sign bit.
10 # A 32-bit perl above 0x7fffffff, or illumos putting shared objects up at
11 # 0xfffffd7f..., would hand back a negative number from PTR2IV.
12 UV
13 _abi_ptr()
14 CODE:
15 1 ▶ RETVAL = PTR2UV(&PK_ABI);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PTR2UV(&PK_ABI); 0 1 1
16 OUTPUT:
17 RETVAL
18  
19 # ---- the self-test consumer -------------------------------------------------
20 #
21 # Exercise the whole pk_abi table the way a C consumer would - register through
22 # the table's own on_request/on_response, then read the request back through
23 # its accessors - so the test suite proves the FUNCTION POINTERS work and not
24 # just the static functions behind them. Open::API's _abi_selftest is the same
25 # idea. Private.
26  
27 # Install the observers, once. Returns 1 when both registered.
28 IV
29 _abi_selftest_install()
30 CODE:
31 {
32 3 const pk_abi *A = INT2PTR(const pk_abi *, PTR2IV(&PK_ABI));
33 3 ▶ # uncoverable branch true
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable branch true 3 0 3
# uncoverable branch true 0 3 3
34 3 ▶ # uncoverable condition left count:1 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:1 class:ignore_covered_err 1 2 3
35 2 # uncoverable condition left count:2 class:ignore_covered_err
36 2 if (!A || A->abi_version != PK_ABI_VERSION) XSRETURN_IV(0);
37 2 ▶ if (PK_SELFTEST_ON) XSRETURN_IV(1); /* idempotent */
Branch: 1 branch
BranchTrueFalseTotal
if (PK_SELFTEST_ON) XSRETURN_IV(1); /* idempotent */ 2 0 2
38 4 ▶ PK_SELFTEST_ON =
Branch: 2 branches
BranchTrueFalseTotal
PK_SELFTEST_ON = 2 0 2
PK_SELFTEST_ON = 2 0 2
39 A->on_request(aTHX_ pk_selftest_req, NULL)
40 2 ▶ && A->on_response(aTHX_ pk_selftest_res, NULL)
Branch: 1 branch
BranchTrueFalseTotal
&& A->on_response(aTHX_ pk_selftest_res, NULL) 0 2 2
41 && A->on_query(aTHX_ pk_selftest_query, pk_selftest_query_done,
42 NULL);
43 RETVAL = PK_SELFTEST_ON;
44 }
45 OUTPUT:
46 RETVAL
47  
48 # Everything the observers recorded since the last call, and reset.
49 # An arrayref of hashrefs; see pk_selftest_event in punk_obs_selftest.h.
50 SV *
51 _abi_selftest_events()
52 CODE:
53 {
54 39 AV *ev = pk_selftest_av(aTHX);
55 39 AV *out = newAV();
56 39 SSize_t i, n = av_len(ev) + 1;
57 79 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 40 39 79
58 40 SV **e = av_fetch(ev, i, 0);
59 40 ▶ # uncoverable branch false
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable branch false 40 0 40
# uncoverable branch false 40 0 40
60 # uncoverable condition right count:1 class:ignore_covered_err
61 39 # uncoverable condition right count:2 class:ignore_covered_err
62 39 if (e && *e) av_push(out, newSVsv(*e));
63 }
64 av_clear(ev);
65 RETVAL = newRV_noinc((SV *)out);
66 }
67 OUTPUT:
68 RETVAL
69  
70 # v5 current_of, read THROUGH the table. Returns the context of the dispatch
71 # frame running right now, or undef.
72 #
73 # A copy of the reference, not the context: the test compares what it addresses
74 # (refaddr) against the $c its handler was given, which is the only check that
75 # tells "the current context" apart from "a current context".
76 SV *
77 _abi_current()
78 CODE:
79 {
80 12 const pk_abi *A = INT2PTR(const pk_abi *, PTR2IV(&PK_ABI));
81 12 ▶ # uncoverable condition right count:1 class:ignore_covered_err
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable condition right count:1 class:ignore_covered_err 12 0 12
# uncoverable condition right count:1 class:ignore_covered_err 12 0 12
82 12 ▶ # uncoverable condition right count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition right count:2 class:ignore_covered_err 7 5 12
83 5 SV *c = (A && A->abi_version >= 5) ? A->current_of(aTHX) : NULL;
84 if (!c) XSRETURN_UNDEF;
85 RETVAL = newSVsv(c);
86 }
87 OUTPUT:
88 RETVAL
89  
90 # v2 on_query: (starts, dones, ok, nbind, sql) since load.
91 void
92 _abi_selftest_queries()
93 PPCODE:
94 26 ▶ EXTEND(SP, 5);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 5); 0 26 26
95 26 mPUSHi(PK_SELFTEST_Q_STARTS);
96 26 mPUSHi(PK_SELFTEST_Q_DONES);
97 26 mPUSHi(PK_SELFTEST_Q_OK);
98 26 mPUSHi(PK_SELFTEST_Q_BIND);
99 26 mPUSHp(PK_SELFTEST_Q_SQL, strlen(PK_SELFTEST_Q_SQL));
« include/punk/punk_ratelimit.h ↑ Summary xs/txn.xs »