| 1 |
|
| /* pmcp_compat.h - what the 5.10 floor costs. |
| 2 |
|
| * |
| 3 |
|
| * Needs: the perl headers. Include before everything else under pmcp/. |
| 4 |
|
| * |
| 5 |
|
| * Every shim here is dead code on a modern perl, which is the problem with |
| 6 |
|
| * shims: they are compiled only on the machines nobody develops on, and they |
| 7 |
|
| * rot silently in between. Where one can be compiled unconditionally it is |
| 8 |
|
| * (pmcp_croak_sv), and t/02 drives it. |
| 9 |
|
| * |
| 10 |
|
| * The floor is 5.010, which is 5.10.0, not 5.10.1. HeUTF8 and mPUSHs/mXPUSHs |
| 11 |
|
| * are 5.10.1 macros and the docker 5.10 images are 5.10.1, so nothing local |
| 12 |
|
| * catches their absence (memory: the 5010 floor is 5.10.0). |
| 13 |
|
| */ |
| 14 |
|
| |
| 15 |
|
| #ifndef PMCP_COMPAT_H |
| 16 |
|
| #define PMCP_COMPAT_H |
| 17 |
|
| |
| 18 |
|
| /* G_LIST is the 5.36 name for G_ARRAY. */ |
| 19 |
|
| #ifndef G_LIST |
| 20 |
|
| # define G_LIST G_ARRAY |
| 21 |
|
| #endif |
| 22 |
|
| |
| 23 |
|
| /* XS_INTERNAL is 5.16+. */ |
| 24 |
|
| #ifndef XS_INTERNAL |
| 25 |
|
| # define XS_INTERNAL(name) static void name(pTHX_ CV *cv) |
| 26 |
|
| #endif |
| 27 |
|
| |
| 28 |
|
| #ifndef HeUTF8 |
| 29 |
|
| # define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) \ |
| 30 |
|
| ? SvUTF8(HeKEY_sv(he)) : (U32)HeKUTF8(he)) |
| 31 |
|
| #endif |
| 32 |
|
| #ifndef mPUSHs |
| 33 |
|
| # define mPUSHs(s) PUSHs(sv_2mortal(s)) |
| 34 |
|
| #endif |
| 35 |
|
| #ifndef mXPUSHs |
| 36 |
|
| # define mXPUSHs(s) XPUSHs(sv_2mortal(s)) |
| 37 |
|
| #endif |
| 38 |
|
| |
| 39 |
|
| /* mg_findext is 5.14+, and the closures in pmcp_clos.h are built on it. The |
| 40 |
|
| * dist calls this one on every perl rather than the native one where it |
| 41 |
|
| * exists, so the code that ships is the code that is tested. */ |
| 42 |
|
| static MAGIC * |
| 43 |
1893 |
| pmcp_mg_findext(pTHX_ const SV *sv, int type, const MGVTBL *vtbl) |
| 44 |
|
| { |
| 45 |
|
| PERL_UNUSED_CONTEXT; |
| 46 |
1893 |
▶ | if (sv && SvTYPE(sv) >= SVt_PVMG) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv && SvTYPE(sv) >= SVt_PVMG) { |
1893 |
0 |
1893 |
| if (sv && SvTYPE(sv) >= SVt_PVMG) { |
1893 |
0 |
1893 |
|
| 47 |
|
| MAGIC *mg; |
| 48 |
1893 |
▶ | for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { |
1893 |
0 |
1893 |
|
| 49 |
1893 |
▶ | if (mg->mg_type == type && mg->mg_virtual == vtbl) |
Branch: 2 branches
| Branch | True | False | Total |
| if (mg->mg_type == type && mg->mg_virtual == vtbl) |
1893 |
0 |
1893 |
| if (mg->mg_type == type && mg->mg_virtual == vtbl) |
1893 |
0 |
1893 |
|
| 50 |
1893 |
| return mg; |
| 51 |
|
| } |
| 52 |
|
| } |
| 53 |
0 |
| return NULL; |
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
|
| /* foldEQ is 5.13.2. ASCII folding is all its callers need (a method name, a |
| 57 |
|
| * media type), and it stops at the first byte that differs, so a shorter |
| 58 |
|
| * string ends on its NUL the way foldEQ's does. Called on every perl. */ |
| 59 |
|
| static int |
| 60 |
780 |
| pmcp_foldEQ(const char *a, const char *b, I32 len) |
| 61 |
|
| { |
| 62 |
9124 |
▶ | while (len-- > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len-- > 0) { |
8512 |
612 |
9124 |
|
| 63 |
8512 |
▶ | if (toLOWER((U8)*a) != toLOWER((U8)*b)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (toLOWER((U8)*a) != toLOWER((U8)*b)) |
15 |
8497 |
8512 |
| if (toLOWER((U8)*a) != toLOWER((U8)*b)) |
0 |
8512 |
8512 |
| if (toLOWER((U8)*a) != toLOWER((U8)*b)) |
168 |
8344 |
8512 |
|
| 64 |
168 |
| return 0; |
| 65 |
8344 |
| a++; |
| 66 |
8344 |
| b++; |
| 67 |
|
| } |
| 68 |
612 |
| return 1; |
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
|
| /* croak_sv is 5.14+. ppport's two branches, both needed: a reference goes out |
| 72 |
|
| * through ERRSV so a blessed exception stays blessed, and a string goes through |
| 73 |
|
| * croak's format so it gains " at FILE line N." the way croak_sv would add it. |
| 74 |
|
| * One branch alone passes every test on a modern perl and is wrong on the old |
| 75 |
|
| * ones (memory: croak_sv shims). Called on every perl, as above, and t/02 |
| 76 |
|
| * drives both branches. */ |
| 77 |
|
| static void |
| 78 |
4 |
| pmcp_croak_sv(pTHX_ SV *sv) |
| 79 |
|
| { |
| 80 |
4 |
▶ | if (SvROK(sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(sv)) { |
1 |
3 |
4 |
|
| 81 |
1 |
▶ | sv_setsv(ERRSV, sv); |
Branch: 1 branch
| Branch | True | False | Total |
| sv_setsv(ERRSV, sv); |
1 |
0 |
1 |
|
| 82 |
1 |
| croak(NULL); |
| 83 |
|
| } |
| 84 |
3 |
| croak("%" SVf, SVfARG(sv)); |
| 85 |
|
| } |
| 86 |
|
| |
| 87 |
|
| #endif /* PMCP_COMPAT_H */ |