include/ap_abi_impl.h

filter: Statementstmt 100% 37 / 37 Branchbran 100% 26 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 63 / 63 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Apophis.pm ↑ Summary
1 #ifndef AP_ABI_IMPL_H
2 #define AP_ABI_IMPL_H
3  
4 /* Apophis-side implementation of the shared C ABI (ap_abi.h). Included by
5 * Apophis.xs AFTER the static core it wraps - apophis_derive_namespace,
6 * apophis_identify_content, apophis_identify_stream, apophis_build_path,
7 * apophis_ensure_parent_dir and apophis_atomic_write - and after horus.h, so
8 * horus_format_uuid and HORUS_FMT_STR are in scope.
9 *
10 * Everything here is private to Apophis's translation unit; consumers reach
11 * it only through the AP_ABI table returned by Apophis::_abi_ptr. */
12  
13 #include "ap_abi.h"
14  
15 /* Unlike apophis_get_ns / apophis_get_store_dir, this must not croak: the
16 * whole point is that a consumer can hand it any SV and find out. */
17 38 static int ap_abi_store_of(pTHX_ SV *self, const unsigned char **ns_out,
18 const char **dir_out, STRLEN *dirlen_out) {
19 HV *hv;
20 SV **svp;
21 STRLEN nslen;
22  
23 38 ▶ if (!self || !sv_isobject(self)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !sv_isobject(self)) return 0; 33 5 38
if (!self || !sv_isobject(self)) return 0; 6 27 33
24 27 hv = (HV *)SvRV(self);
25 27 ▶ if (SvTYPE((SV *)hv) != SVt_PVHV) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE((SV *)hv) != SVt_PVHV) return 0; 1 26 27
26  
27 26 svp = hv_fetchs(hv, "_ns_bytes", 0);
28 26 ▶ if (!svp || !SvOK(*svp)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) return 0; 25 1 26
if (!svp || !SvOK(*svp)) return 0; 1 24 25
29 24 ▶ if (ns_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (ns_out) { 14 10 24
30 14 *ns_out = (const unsigned char *)SvPV(*svp, nslen);
31 14 ▶ if (nslen != 16) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (nslen != 16) return 0; 1 13 14
32 }
33  
34 23 svp = hv_fetchs(hv, "store_dir", 0);
35 23 ▶ if (!svp || !SvOK(*svp)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) return 0; 22 1 23
if (!svp || !SvOK(*svp)) return 0; 1 21 22
36 21 ▶ if (dir_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (dir_out) { 11 10 21
37 STRLEN dl;
38 11 *dir_out = SvPV(*svp, dl);
39 11 ▶ if (dirlen_out) *dirlen_out = dl;
Branch: 1 branch
BranchTrueFalseTotal
if (dirlen_out) *dirlen_out = dl; 6 5 11
40 }
41 10 ▶ else if (dirlen_out) {
Branch: 1 branch
BranchTrueFalseTotal
else if (dirlen_out) { 5 5 10
42 5 (void)SvPV(*svp, *dirlen_out);
43 }
44  
45 21 return 1;
46 }
47  
48 5 static void ap_abi_derive_ns(unsigned char *ns_out,
49 const char *name, STRLEN len) {
50 5 apophis_derive_namespace(ns_out, name, len);
51 5 }
52  
53 5 static void ap_abi_identify(unsigned char *id_out, const unsigned char *ns,
54 const char *content, STRLEN len) {
55 5 apophis_identify_content(id_out, ns, content, len);
56 5 }
57  
58 4 static void ap_abi_identify_fh(pTHX_ unsigned char *id_out,
59 const unsigned char *ns, PerlIO *fh) {
60 4 apophis_identify_stream(aTHX_ id_out, ns, fh);
61 4 }
62  
63 14 static void ap_abi_format_id(char *buf, const unsigned char *id) {
64 14 horus_format_uuid(buf, id, HORUS_FMT_STR);
65 14 buf[HORUS_FMT_STR_LEN] = '\0';
66 14 }
67  
68 10 static int ap_abi_build_path(char *out, size_t out_size,
69 const char *dir, STRLEN dirlen,
70 const char *id, STRLEN id_len) {
71 10 ▶ if (id_len < 5) return -1; /* the XSUB croaks; the ABI reports */
Branch: 1 branch
BranchTrueFalseTotal
if (id_len < 5) return -1; /* the XSUB croaks; the ABI reports */ 5 5 10
72 5 return apophis_build_path(out, out_size, dir, dirlen, id, id_len);
73 }
74  
75 9 static void ap_abi_write_atomic(pTHX_ const char *path,
76 const char *content, STRLEN len) {
77 9 apophis_ensure_parent_dir(path);
78 8 apophis_atomic_write(aTHX_ path, content, len);
79 7 }
80  
81 static const ap_abi AP_ABI = {
82 AP_ABI_VERSION,
83 ap_abi_store_of,
84 ap_abi_derive_ns,
85 ap_abi_identify,
86 ap_abi_identify_fh,
87 ap_abi_format_id,
88 ap_abi_build_path,
89 ap_abi_write_atomic
90 };
91  
92 #endif /* AP_ABI_IMPL_H */
« blib/lib/Apophis.pm ↑ Summary