include/punk/punk_frozen.h

filter: Statementstmt 95.8% 23 / 24 Branchbran 58.3% 14 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 77.0% 37 / 48 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/request.xs ↑ Summary include/punk/punk_stencil.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 158 static const fz_abi *punk_fz_try(pTHX) {
32 158 ▶ if (!PUNK_FZ_TRIED) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PUNK_FZ_TRIED) { 18 140 158
33 18 dSP; int count; UV p = 0;
34 18 PUNK_FZ_TRIED = 1;
35 18 ▶ if (pk_require_once(aTHX_ "Frozen", FALSE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pk_require_once(aTHX_ "Frozen", FALSE)) { 18 0 18
36 18 SPAGAIN; /* the require may have reallocated the value stack */
37 18 ▶ ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; 0 18 18
38 18 count = call_pv("Frozen::_abi_ptr", G_SCALAR | G_EVAL);
39 18 SPAGAIN;
40 /* SvUV, not SvIV: Frozen::_abi_ptr returns a UV deliberately,
41 * because where the loader maps the object decides the sign
42 * bit and a 32-bit perl above 0x7fffffff hands back a negative
43 * from PTR2IV.
44 *
45 * And popped ONCE, into an SV*, because SvUV is a macro that
46 * mentions its argument more than once: SvUV(POPs) pops twice
47 * and reads the address off the wrong slot. punk_blob.h:77-89
48 * carries the same warning and the release it cost. */
49 18 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 18 0 18
50 18 SV *sv = POPs;
51 18 ▶ if (!SvTRUE(ERRSV)) p = SvUV(sv);
Branch: 2 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV)) p = SvUV(sv); 18 0 18
if (!SvTRUE(ERRSV)) p = SvUV(sv); 18 0 18
52 }
53 18 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 18 0 18
54 18 ▶ if (p) {
Branch: 1 branch
BranchTrueFalseTotal
if (p) { 18 0 18
55 18 const fz_abi *a = INT2PTR(const fz_abi *, p);
56 /* >= and never ==: the table is append-only, so a later
57 * one is a superset whose prefix stays valid. Equality
58 * would make every Frozen release break Punk, which is
59 * what Reverse::Proxy 0.04 did against Fetch. */
60 18 ▶ if (a && !getenv("PUNK_FAKE_FZ_BAD")
Branch: 2 branches
BranchTrueFalseTotal
if (a && !getenv("PUNK_FAKE_FZ_BAD") 18 0 18
if (a && !getenv("PUNK_FAKE_FZ_BAD") 17 1 18
61 17 ▶ && a->abi_version >= FZ_ABI_VERSION)
Branch: 1 branch
BranchTrueFalseTotal
&& a->abi_version >= FZ_ABI_VERSION) 17 0 17
62 17 PUNK_FZ = a;
63 }
64 }
65 }
66 158 return PUNK_FZ;
67 }
68  
69 /* The table, croaking if it is missing or too old.
70 *
71 * Frozen is a HARD dependency: there is no arena to fall back to, because
72 * the block IS the arena. Called from the plugin's register, so this is a
73 * boot-environment error rather than a surprise mid-request. */
74 151 static const fz_abi *punk_fz(pTHX) {
75 151 const fz_abi *a = punk_fz_try(aTHX);
76 151 ▶ if (!a)
Branch: 1 branch
BranchTrueFalseTotal
if (!a) 0 151 151
77 0 croak("Punk::Plugin::I18n needs Frozen with a compatible C ABI "
78 "(FZ_ABI_VERSION %d); upgrade Frozen to 0.06+", FZ_ABI_VERSION);
79 151 return a;
80 }
81  
82 #endif /* PUNK_FROZEN_H */
« xs/request.xs ↑ Summary include/punk/punk_stencil.h »