include/punk/punk_frozen.h

filter: Statementstmt 95.8% 23 / 24 Branchbran 79.1% 14 / 24 (5 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 87.5% 37 / 48 (5 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_session.h ↑ Summary include/punk/punk_log.h »
1 #ifndef PUNK_FROZEN_H
2 #define PUNK_FROZEN_H
3  
4 /* Frozen's C ABI, resolved once at first use.
5 *
6 * Frozen holds an immutable block of nested data addressed by offset and
7 * read without touching a reference count. Punk's catalogues live in one,
8 * and the read path goes through this table rather than through Frozen's
9 * Perl surface: a Perl frame per lookup is the cost punk_i18n.h exists to
10 * avoid, so reaching Frozen by method call would make i18n slower rather
11 * than faster.
12 *
13 * Its own header documents a different resolution idiom - eval_pv in a
14 * BOOT: block. Punk does not do that anywhere, and the reason is not
15 * style: Perl_eval_sv leaks immortal refcounts on perls up to 5.20, which
16 * t/0012-immortal-refcount.t catches, so every provider here goes through
17 * pk_require_once instead. A reader comparing the two headers would
18 * otherwise assume this one had it wrong.
19 *
20 * Separate from punk_i18n.h so a later consumer - a frozen config, a
21 * frozen routing table - can reuse it without dragging i18n in.
22 */
23  
24 #include "fz_abi.h" /* Frozen's public ABI, via ExtUtils::Depends */
25  
26 static const fz_abi *PUNK_FZ = NULL;
27 static int PUNK_FZ_TRIED = 0;
28  
29 /* Resolve (once) Frozen's ABI table, or NULL. PUNK_FAKE_FZ_BAD simulates a
30 * version mismatch for the guard test. */
31 160 static const fz_abi *punk_fz_try(pTHX) {
32 160 ▶ if (!PUNK_FZ_TRIED) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PUNK_FZ_TRIED) { 20 140 160
33 20 dSP; int count; UV p = 0;
34 20 PUNK_FZ_TRIED = 1;
35 /*
36 # uncoverable branch false
37 # uncoverable condition right count:1 class:ignore_covered_err */
38 20 ▶ if (pk_require_once(aTHX_ "Frozen", FALSE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pk_require_once(aTHX_ "Frozen", FALSE)) { 20 0 20
39 20 SPAGAIN; /* the require may have reallocated the value stack */
40 20 ▶ ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; 0 20 20
41 20 count = call_pv("Frozen::_abi_ptr", G_SCALAR | G_EVAL);
42 20 SPAGAIN;
43 /* SvUV, not SvIV: Frozen::_abi_ptr returns a UV deliberately,
44 * because where the loader maps the object decides the sign
45 * bit and a 32-bit perl above 0x7fffffff hands back a negative
46 * from PTR2IV.
47 *
48 * And popped ONCE, into an SV*, because SvUV is a macro that
49 * mentions its argument more than once: SvUV(POPs) pops twice
50 * and reads the address off the wrong slot. punk_blob.h:77-89
51 * carries the same warning and the release it cost. */
52 /*
53 # uncoverable branch false
54 # uncoverable condition right count:1 class:ignore_covered_err */
55 20 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 20 0 20
56 20 SV *sv = POPs;
57 /*
58 # uncoverable branch false
59 # uncoverable condition right count:1 class:ignore_covered_err
60 # uncoverable condition right count:2 class:ignore_covered_err */
61 20 ▶ if (!SvTRUE(ERRSV)) p = SvUV(sv);
Branch: 2 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV)) p = SvUV(sv); 20 0 20
if (!SvTRUE(ERRSV)) p = SvUV(sv); 20 0 20
62 }
63 20 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 20 0 20
64 /*
65 # uncoverable branch false
66 # uncoverable condition right count:1 class:ignore_covered_err */
67 20 ▶ if (p) {
Branch: 1 branch
BranchTrueFalseTotal
if (p) { 20 0 20
68 20 const fz_abi *a = INT2PTR(const fz_abi *, p);
69 /* >= and never ==: the table is append-only, so a later
70 * one is a superset whose prefix stays valid. Equality
71 * would make every Frozen release break Punk, which is
72 * what Reverse::Proxy 0.04 did against Fetch. */
73 /*
74 # uncoverable condition right count:1 class:ignore_covered_err
75 # uncoverable condition right count:3 class:ignore_covered_err */
76 20 ▶ if (a && !getenv("PUNK_FAKE_FZ_BAD")
Branch: 2 branches
BranchTrueFalseTotal
if (a && !getenv("PUNK_FAKE_FZ_BAD") 20 0 20
if (a && !getenv("PUNK_FAKE_FZ_BAD") 19 1 20
77 19 ▶ && a->abi_version >= FZ_ABI_VERSION)
Branch: 1 branch
BranchTrueFalseTotal
&& a->abi_version >= FZ_ABI_VERSION) 19 0 19
78 19 PUNK_FZ = a;
79 }
80 }
81 }
82 160 return PUNK_FZ;
83 }
84  
85 /* The table, croaking if it is missing or too old.
86 *
87 * Frozen is a HARD dependency: there is no arena to fall back to, because
88 * the block IS the arena. Called from the plugin's register, so this is a
89 * boot-environment error rather than a surprise mid-request. */
90 152 static const fz_abi *punk_fz(pTHX) {
91 152 const fz_abi *a = punk_fz_try(aTHX);
92 /*
93 # uncoverable branch true
94 # uncoverable condition left count:1 class:ignore_covered_err */
95 152 ▶ if (!a)
Branch: 1 branch
BranchTrueFalseTotal
if (!a) 0 152 152
96 0 croak("Punk::Plugin::I18n needs Frozen with a compatible C ABI " /* # uncoverable statement */
97 "(FZ_ABI_VERSION %d); upgrade Frozen to 0.06+", FZ_ABI_VERSION);
98 152 return a;
99 }
100  
101 #endif /* PUNK_FROZEN_H */
« include/punk/punk_session.h ↑ Summary include/punk/punk_log.h »