include/psaml/psaml_compat.h

filter: Statementstmt 100% 5 / 5 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 76.9% 10 / 13 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/psaml/psaml_flow.h ↑ Summary include/psaml/psaml_time.h »
1 #ifndef PSAML_COMPAT_H
2 #define PSAML_COMPAT_H
3  
4 /* Perl-version portability shims, so the dist builds on every perl it
5 * claims (5.10.0+). Include after EXTERN.h / perl.h / XSUB.h / ppport.h
6 * and before any psaml/ header, so the definitions are in scope
7 * everywhere below. Each shim is the standard definition of the thing it
8 * stands in for; on a perl new enough to have the real one, none of it is
9 * compiled. ppport.h already covers av_count, mPUSHs and newSVpvn_flags.
10 *
11 * An XS floor is a claim until an old perl compiles it. Phase 11 has the
12 * proof; nothing here is believed until then. */
13  
14 /* XS_INTERNAL / XS_EXTERNAL (and XSPROTO) arrived in XSUB.h at 5.16. */
15 #ifndef XSPROTO
16 # define XSPROTO(name) void name(pTHX_ CV *cv)
17 #endif
18 #ifndef XS_INTERNAL
19 # define XS_INTERNAL(name) STATIC XSPROTO(name)
20 #endif
21 #ifndef XS_EXTERNAL
22 # define XS_EXTERNAL(name) XSPROTO(name)
23 #endif
24  
25 /* G_LIST is the 5.36 spelling of G_ARRAY. Unguarded it is not a test
26 * failure, it is a build failure, which is worse: nothing runs to
27 * report it. */
28 #ifndef G_LIST
29 # define G_LIST G_ARRAY
30 #endif
31  
32 #ifndef PERL_STATIC_INLINE
33 # define PERL_STATIC_INLINE static
34 #endif
35  
36 /* mg_findext arrived at 5.14. The fallback walks the chain itself and
37 * matches on the type AND the vtable, which is the whole point of the
38 * ext variant: two extensions can both use PERL_MAGIC_ext on one SV and
39 * each must find only its own. */
40 #if (PERL_REVISION == 5 && PERL_VERSION < 14)
41 PERL_STATIC_INLINE MAGIC *
42 psaml_mg_findext(SV *sv, int type, const MGVTBL *vtbl) {
43 MAGIC *mg;
44 if (!sv || !SvMAGICAL(sv)) return NULL;
45 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
46 if (mg->mg_type == type && mg->mg_virtual == vtbl) return mg;
47 return NULL;
48 }
49 # define mg_findext(sv, type, vtbl) psaml_mg_findext(sv, type, vtbl)
50 #endif
51  
52 /* croak_sv is 5.13.1 and later, and this dist needs it on every perl:
53 * every check in phase 6 throws a blessed Punk::SAML::Error rather than
54 * a string, and a flattened exception has no `code` to assert on.
55 *
56 * This is ppport's shim, and it is TWO branches. Every dist in this
57 * family hand-rolled it once and each got a different half wrong:
58 *
59 * - `croak(NULL)` raises ERRSV verbatim, which is exactly right for a
60 * blessed error and keeps it blessed. Written as the only branch it
61 * drops the " at FILE line N.\n" from plain strings, and it does so
62 * only on the old perls that actually select the shim, so it passes
63 * everywhere you can test and fails on a smoker.
64 * - `croak("%" SVf, ...)` lets croak append the location, which is
65 * right for a string. Written as the only branch it FLATTENS a
66 * blessed exception to its stringification on perl < 5.14, which is
67 * the half that would break this dist specifically.
68 *
69 * psaml_croak_sv is compiled unconditionally and named separately from
70 * the macro, so the shim body is exercised on every perl through
71 * Punk::SAML::_croak_sv_selftest rather than shipping unrun. Be honest
72 * about what that buys: it catches crashes, wrong types and
73 * ref-flattening anywhere, but it cannot catch the location-dropping
74 * half, because on a modern perl the wrong shim passes those assertions
75 * too. That half is only ever provable on a smoker. */
76 PERL_STATIC_INLINE void
77 2 psaml_croak_sv(pTHX_ SV *sv) {
78 2 ▶ if (sv && SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvROK(sv)) { 2 0 2
if (sv && SvROK(sv)) { 1 1 2
79 1 ▶ sv_setsv(ERRSV, sv);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, sv); 1 0 1
80 1 Perl_croak(aTHX_ NULL);
81 }
82 1 ▶ Perl_croak(aTHX_ "%" SVf, SVfARG(sv ? sv : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
Perl_croak(aTHX_ "%" SVf, SVfARG(sv ? sv : &PL_sv_undef)); 1 0 1
83 }
84  
85 #ifndef croak_sv
86 # define croak_sv(sv) psaml_croak_sv(aTHX_ (sv))
87 #endif
88  
89 /* PERL_UNUSED_ARG(my_perl) is a build error, not a warning: under a
90 * threaded perl my_perl is not an ordinary identifier and the expansion
91 * is not an expression. The spelling for an unused interpreter context
92 * is PERL_UNUSED_CONTEXT, written out here because this family has got
93 * it wrong before. */
94 #ifndef PERL_UNUSED_CONTEXT
95 # define PERL_UNUSED_CONTEXT
96 #endif
97  
98 /* The owner string, here rather than in psaml_reg.h because every header
99 * below croaks with it and the include order should not decide who can. */
100 #define PSAML_WHO "Punk::Plugin::SAML"
101  
102 #endif /* PSAML_COMPAT_H */
« include/psaml/psaml_flow.h ↑ Summary include/psaml/psaml_time.h »