include/pq_compat.h

filter: Statementstmt 66.6% 8 / 12 Branchbran 35.7% 5 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 50.0% 13 / 26 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/backend.xs ↑ Summary include/pq_worker.h »
1 #ifndef PQ_COMPAT_H
2 #define PQ_COMPAT_H
3  
4 /* Perl-version portability shims for the C core, so Punk::Queue builds on
5 * every perl it claims (5.10.0+). Include after EXTERN.h / perl.h / XSUB.h
6 * and before any other pq_ header, so the definitions are in scope
7 * everywhere below.
8 *
9 * Each shim is the standard definition of the thing it stands in for; on a
10 * perl new enough to have the real one, none of this is compiled. */
11  
12 /* XS_INTERNAL / XS_EXTERNAL (and XSPROTO) arrived in perl's XSUB.h at 5.16. */
13 #ifndef XSPROTO
14 # define XSPROTO(name) void name(pTHX_ CV *cv)
15 #endif
16 #ifndef XS_INTERNAL
17 # define XS_INTERNAL(name) STATIC XSPROTO(name)
18 #endif
19 #ifndef XS_EXTERNAL
20 # define XS_EXTERNAL(name) XSPROTO(name)
21 #endif
22  
23 /* croak_sv is 5.13.1. */
24 #if PERL_REVISION == 5 && PERL_VERSION < 14
25 # define croak_sv(sv) Perl_croak(aTHX_ "%" SVf, SVfARG(sv))
26 #endif
27  
28 /* isWORDCHAR is the 5.14 spelling of what older perls call isALNUM. Both
29 * mean [0-9A-Za-z_] here: every caller is testing a single ASCII byte. */
30 #ifndef isWORDCHAR
31 # define isWORDCHAR(c) isALNUM(c)
32 #endif
33  
34 /* mPUSHs / mXPUSHs are 5.10.1, one point release above the floor. */
35 #ifndef mPUSHs
36 # define mPUSHs(s) PUSHs(sv_2mortal(s))
37 #endif
38 #ifndef mXPUSHs
39 # define mXPUSHs(s) XPUSHs(sv_2mortal(s))
40 #endif
41  
42 /* The dist version, recorded on worker rows so `punk-queue workers` can
43 * spot a mixed-version fleet. Kept in step with $Punk::Queue::VERSION. */
44 #define PQ_VERSION_STRING "0.01"
45  
46 /* ---- allocation ------------------------------------------------------- *
47 * Everything in include/ and xs/ allocates through these, never through
48 * raw malloc/calloc/realloc: they croak (noreturn) on exhaustion rather
49 * than handing back NULL for a caller to forget to check. This is
50 * Hyperman's hm_xmalloc convention, and it is also what keeps cppcheck's
51 * nullPointerOutOfMemory clean.
52 *
53 * The set is deliberately complete even where phase 1 uses only part of
54 * it: a missing pq_xcalloc is an invitation to reach for a raw calloc, and
55 * the whole value of the convention is that there is nothing to decide.
56 * Hence the unused marker rather than three fewer functions. */
57  
58 4037 static void *pq_xmalloc(pTHX_ size_t n) {
59 4037 ▶ void *p = safemalloc(n ? n : 1);
Branch: 1 branch
BranchTrueFalseTotal
void *p = safemalloc(n ? n : 1); 4037 0 4037
60 4037 ▶ if (!p) croak("Punk::Queue: out of memory allocating %lu bytes",
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Punk::Queue: out of memory allocating %lu bytes", 0 4037 4037
61 (unsigned long)n);
62 4037 return p;
63 }
64  
65 static void *pq_xcalloc(pTHX_ size_t n, size_t sz) PERL_UNUSED_DECL;
66 15 static void *pq_xcalloc(pTHX_ size_t n, size_t sz) {
67 15 ▶ void *p = safecalloc(n ? n : 1, sz ? sz : 1);
Branch: 2 branches
BranchTrueFalseTotal
void *p = safecalloc(n ? n : 1, sz ? sz : 1); 15 0 15
void *p = safecalloc(n ? n : 1, sz ? sz : 1); 15 0 15
68 15 ▶ if (!p) croak("Punk::Queue: out of memory allocating %lu bytes",
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Punk::Queue: out of memory allocating %lu bytes", 0 15 15
69 (unsigned long)(n * sz));
70 15 return p;
71 }
72  
73 static void *pq_xrealloc(pTHX_ void *old, size_t n) PERL_UNUSED_DECL;
74 0 static void *pq_xrealloc(pTHX_ void *old, size_t n) {
75 0 ▶ void *p = saferealloc(old, n ? n : 1);
Branch: 1 branch
BranchTrueFalseTotal
void *p = saferealloc(old, n ? n : 1); 0 0 0
76 0 ▶ if (!p) croak("Punk::Queue: out of memory reallocating %lu bytes",
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Punk::Queue: out of memory reallocating %lu bytes", 0 0 0
77 (unsigned long)n);
78 0 return p;
79 }
80  
81 #endif /* PQ_COMPAT_H */
« xs/backend.xs ↑ Summary include/pq_worker.h »