Shared.xs

filter: Statementstmt 96.6% 231 / 239 Branchbran 57.7% 224 / 388 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 72.5% 455 / 627 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« minhash.h ↑ Summary
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5 #include "ppport.h"
6 #include "minhash.h"
7  
8 #define EXTRACT(sv) \
9 if (!sv_isobject(sv) || !sv_derived_from(sv, "Data::MinHash::Shared")) \
10 croak("Expected a Data::MinHash::Shared object"); \
11 MnhHandle *h = INT2PTR(MnhHandle*, SvIV(SvRV(sv))); \
12 if (!h) croak("Attempted to use a destroyed Data::MinHash::Shared object"); \
13 MnhHandle *h0 = h; PERL_UNUSED_VAR(h0); \
14 sv_2mortal(SvREFCNT_inc(SvRV(sv)))
15  
16 /* Re-read the handle after a call that can run Perl code (tied/overloaded
17 * argument magic, tied-array fetches). That code may call $obj->DESTROY
18 * explicitly, which frees the handle and zeroes the IV; EXTRACT's mortal
19 * pins the referent only against refcount-driven destruction, not an
20 * explicit DESTROY, so the local `h` would dangle. Used only where magic
21 * can actually intervene between EXTRACT and the first use of h. */
22 /* The same Perl that can destroy the handle can also REPLACE the invocant
23 * ($obj = 42 from an overload handler mutates ST(0), because Perl passes
24 * aliases), so SvROK must be re-checked before SvRV -- otherwise SvRV would
25 * run on a non-reference. */
26 #define REEXTRACT(sv) \
27 if (!SvROK(sv)) \
28 croak("Data::MinHash::Shared object was replaced during the call"); \
29 h = INT2PTR(MnhHandle*, SvIV(SvRV(sv))); \
30 if (h != h0) croak("Data::MinHash::Shared object replaced or destroyed during the call")
31  
32 #define MAKE_OBJ(class, handle) \
33 SV *obj = newSViv(PTR2IV(handle)); \
34 SV *ref = newRV_noinc(obj); \
35 sv_bless(ref, gv_stashpv(class, GV_ADD)); \
36 RETVAL = ref
37  
38 MODULE = Data::MinHash::Shared PACKAGE = Data::MinHash::Shared
39  
40 PROTOTYPES: DISABLE
41  
42 SV *
43 new(class, path = &PL_sv_undef, k = 0, ...)
44 const char *class
45 SV *path
46 UV k
47 PREINIT:
48 char errbuf[MNH_ERR_BUFLEN];
49 CODE:
50 56 ▶ if (k < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (k < 1) 1 55 56
51 1 croak("Data::MinHash::Shared->new: number of registers must be >= 1");
52 /* Optional 4th arg: file mode for a newly-created file-backed segment
53 * (default 0600, owner-only). Pass e.g. 0660 to opt into cross-user
54 * sharing. Ignored for anonymous segments and existing files. */
55 55 ▶ mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600;
Branch: 4 branches
BranchTrueFalseTotal
mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; 0 55 55
mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; 0 0 0
mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; 0 0 0
mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; 0 0 0
56 /* Capture the path PV LAST, after the get-magic on mode above has run:
57 * that magic can realloc/free path's PV and dangle p before use. */
58 71 ▶ const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 55 55
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 0 0
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 16 39 55
59 55 MnhHandle *h = mnh_create(p, (uint64_t)k, mode, errbuf);
60 55 ▶ if (!h) croak("Data::MinHash::Shared->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::MinHash::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); 5 50 55
if (!h) croak("Data::MinHash::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); 5 0 5
61 /* Re-read the class PV at the point of use: xsubpp captured it in INPUT,
62 * before the k/mode/path magic above, which can realloc/free that PV and
63 * dangle `class` before MAKE_OBJ passes it to gv_stashpv. */
64 50 class = SvPV_nolen(ST(0));
65 50 MAKE_OBJ(class, h);
66 OUTPUT:
67 RETVAL
68  
69 SV *
70 new_memfd(class, name = &PL_sv_undef, k = 0)
71 const char *class
72 SV *name
73 UV k
74 PREINIT:
75 char errbuf[MNH_ERR_BUFLEN];
76 CODE:
77 4 ▶ const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; /* undef -> default label */
Branch: 3 branches
BranchTrueFalseTotal
const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; /* undef -> default label */ 0 2 2
const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; /* undef -> default label */ 0 0 0
const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; /* undef -> default label */ 2 0 2
78 2 ▶ if (k < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (k < 1) 0 2 2
79 0 croak("Data::MinHash::Shared->new_memfd: number of registers must be >= 1");
80 2 MnhHandle *h = mnh_create_memfd(nm, (uint64_t)k, errbuf);
81 2 ▶ if (!h) croak("Data::MinHash::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::MinHash::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 2 2
if (!h) croak("Data::MinHash::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
82 /* Re-read the class PV at the point of use (see new above): the k/name
83 * magic ran after xsubpp captured `class` in INPUT. */
84 2 class = SvPV_nolen(ST(0));
85 2 MAKE_OBJ(class, h);
86 OUTPUT:
87 RETVAL
88  
89 SV *
90 new_from_fd(class, fd)
91 const char *class
92 int fd
93 PREINIT:
94 char errbuf[MNH_ERR_BUFLEN];
95 CODE:
96 2 MnhHandle *h = mnh_open_fd(fd, errbuf);
97 2 ▶ if (!h) croak("Data::MinHash::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::MinHash::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 0 2 2
if (!h) croak("Data::MinHash::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
98 /* Re-read the class PV at the point of use (see new above): the fd
99 * conversion in INPUT ran its magic after `class` was captured. */
100 2 class = SvPV_nolen(ST(0));
101 2 MAKE_OBJ(class, h);
102 OUTPUT:
103 RETVAL
104  
105 SV *
106 new_readonly(class, path)
107 const char *class
108 SV *path
109 PREINIT:
110 char errbuf[MNH_ERR_BUFLEN];
111 CODE:
112 /* Open a FROZEN (sealed) file read-only: O_RDONLY + PROT_READ, no lock
113 ever. A sealed file is immutable and no read path writes the mapping,
114 so queries take no reader-slot / rwlock traffic and any number of
115 processes can share one PROT_READ mapping (same architecture; the
116 magic rejects a wrong-endian file). */
117 13 ▶ const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 7 7
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 0 0
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 6 1 7
118 7 ▶ if (!p) croak("Data::MinHash::Shared->new_readonly: path is required");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Data::MinHash::Shared->new_readonly: path is required"); 1 6 7
119 6 MnhHandle *h = mnh_open_readonly(p, errbuf);
120 6 ▶ if (!h) croak("Data::MinHash::Shared->new_readonly: %s", errbuf);
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Data::MinHash::Shared->new_readonly: %s", errbuf); 2 4 6
121 /* Re-read the class PV at the point of use (see new above): the path
122 * magic above can realloc/free the INPUT-captured PV. */
123 4 class = SvPV_nolen(ST(0));
124 4 MAKE_OBJ(class, h);
125 OUTPUT:
126 RETVAL
127  
128 void
129 DESTROY(self)
130 SV *self
131 CODE:
132 60 ▶ if (sv_isobject(self) && sv_derived_from(self, "Data::MinHash::Shared")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self) && sv_derived_from(self, "Data::MinHash::Shared")) { 60 0 60
if (sv_isobject(self) && sv_derived_from(self, "Data::MinHash::Shared")) { 60 0 60
133 60 MnhHandle *h = INT2PTR(MnhHandle*, SvIV(SvRV(self)));
134 60 ▶ if (h) { sv_setiv(SvRV(self), 0); mnh_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */
Branch: 1 branch
BranchTrueFalseTotal
if (h) { sv_setiv(SvRV(self), 0); mnh_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */ 58 2 60
135 }
136  
137 int
138 add(self, item)
139 SV *self
140 SV *item
141 PREINIT:
142 16418 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 16418 0 16418
EXTRACT(self); 0 16418 16418
EXTRACT(self); 0 16418 16418
143 STRLEN n;
144 const char *s;
145 CODE:
146 16418 ▶ if (h->readonly) croak("Data::MinHash::Shared->add: sketch is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::MinHash::Shared->add: sketch is frozen (read-only)"); 2 16416 16418
147 16415 s = SvPVbyte(item, n); /* may croak (wide char) -- BEFORE the lock */
148 16415 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 16415 16415
REEXTRACT(self); 0 16415 16415
149 16415 mnh_rwlock_wrlock(h);
150 16415 ▶ if (h->hdr->sealed) { mnh_rwlock_wrunlock(h); croak("Data::MinHash::Shared->add: sketch is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { mnh_rwlock_wrunlock(h); croak("Data::MinHash::Shared->add: sketch is frozen (read-only)"); } 1 16414 16415
151 16414 RETVAL = mnh_add_locked(h, s, n);
152 16414 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
153 16414 mnh_rwlock_wrunlock(h);
154 OUTPUT:
155 RETVAL
156  
157 UV
158 add_many(self, items)
159 SV *self
160 SV *items
161 PREINIT:
162 11 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 11 0 11
EXTRACT(self); 0 11 11
EXTRACT(self); 0 11 11
163 AV *av;
164 IV top;
165 11 ▶ UV changed = 0;
Branch: 1 branch
BranchTrueFalseTotal
UV changed = 0; 11 0 11
166 CODE:
167 11 ▶ if (h->readonly) croak("Data::MinHash::Shared->add_many: sketch is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::MinHash::Shared->add_many: sketch is frozen (read-only)"); 2 9 11
168 9 ▶ SvGETMAGIC(items);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(items); 0 9 9
SvGETMAGIC(items); 0 0 0
169 9 ▶ if (!SvROK(items) || SvTYPE(SvRV(items)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(items) || SvTYPE(SvRV(items)) != SVt_PVAV) 8 1 9
if (!SvROK(items) || SvTYPE(SvRV(items)) != SVt_PVAV) 0 8 8
170 1 croak("Data::MinHash::Shared->add_many: expected an array reference");
171 8 av = (AV *)SvRV(items);
172 8 sv_2mortal(SvREFCNT_inc((SV *)av)); /* pin the arrayref: element magic below cannot free it mid-loop */
173 8 top = av_len(av); /* last index, -1 if empty */
174 {
175 8 ▶ STRLEN cnt = (top >= 0) ? (STRLEN)(top + 1) : 0, i;
Branch: 1 branch
BranchTrueFalseTotal
STRLEN cnt = (top >= 0) ? (STRLEN)(top + 1) : 0, i; 8 0 8
176 8 const char **ps = NULL; STRLEN *ls = NULL;
177 8 ▶ if (cnt) { /* resolve all bytes BEFORE locking */
Branch: 1 branch
BranchTrueFalseTotal
if (cnt) { /* resolve all bytes BEFORE locking */ 8 0 8
178 8 ▶ Newx(ps, cnt, const char *); SAVEFREEPV(ps); /* freed on return OR unwind */
Branch: 1 branch
BranchTrueFalseTotal
Newx(ps, cnt, const char *); SAVEFREEPV(ps); /* freed on return OR unwind */ 0 8 8
179 8 ▶ Newx(ls, cnt, STRLEN); SAVEFREEPV(ls);
Branch: 1 branch
BranchTrueFalseTotal
Newx(ls, cnt, STRLEN); SAVEFREEPV(ls); 0 8 8
180 234 ▶ for (i = 0; i < cnt; i++) { /* a croak here holds NO lock; SAVEFREEPV cleans up */
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) { /* a croak here holds NO lock; SAVEFREEPV cleans up */ 226 8 234
181 226 SV **el = av_fetch(av, (SSize_t)i, 0);
182 226 ▶ if (el && *el) {
Branch: 2 branches
BranchTrueFalseTotal
if (el && *el) { 226 0 226
if (el && *el) { 226 0 226
183 STRLEN len;
184 226 const char *src = SvPVbyte(*el, len); /* may run overload/tie/get-magic = arbitrary Perl */
185 /* Copy bytes into a private mortal SV NOW: a LATER element SvPVbyte can
186 * grow/free THIS element PV, dangling src before the locked loop uses it. */
187 226 SV *copy = sv_2mortal(newSVpvn(src, len));
188 226 ps[i] = SvPVX_const(copy);
189 226 ls[i] = len;
190 0 } else { ps[i] = ""; ls[i] = 0; }
191 }
192 }
193 8 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 8 8
REEXTRACT(self); 0 8 8
194 8 mnh_rwlock_wrlock(h); /* locked region: NO croak-capable calls */
195 8 ▶ if (h->hdr->sealed) { mnh_rwlock_wrunlock(h); croak("Data::MinHash::Shared->add_many: sketch is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { mnh_rwlock_wrunlock(h); croak("Data::MinHash::Shared->add_many: sketch is frozen (read-only)"); } 1 7 8
196 232 ▶ for (i = 0; i < cnt; i++) changed += (UV)mnh_add_locked(h, ps[i], ls[i]);
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < cnt; i++) changed += (UV)mnh_add_locked(h, ps[i], ls[i]); 225 7 232
197 7 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); /* a call always counts, even an empty batch */
198 7 mnh_rwlock_wrunlock(h);
199 }
200 7 ▶ RETVAL = changed;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = changed; 2 5 7
201 OUTPUT:
202 RETVAL
203  
204 double
205 similarity(self, other)
206 SV *self
207 SV *other
208 PREINIT:
209 18 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 18 0 18
EXTRACT(self); 0 18 18
EXTRACT(self); 0 18 18
210 CODE:
211 18 ▶ if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared"))
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared")) 17 1 18
if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared")) 0 17 17
212 1 croak("Data::MinHash::Shared->similarity: expected a Data::MinHash::Shared object");
213 17 MnhHandle *o = INT2PTR(MnhHandle*, SvIV(SvRV(other)));
214 17 ▶ if (!o) croak("Attempted to use a destroyed Data::MinHash::Shared object");
Branch: 1 branch
BranchTrueFalseTotal
if (!o) croak("Attempted to use a destroyed Data::MinHash::Shared object"); 0 17 17
215 17 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 17 17
REEXTRACT(self); 0 17 17
216  
217 /* k is immutable after creation -- compare lock-free, croak BEFORE allocating
218 * so a mismatch holds no lock and leaks no buffer. */
219 17 uint64_t ok = o->hdr->k;
220 17 ▶ if (ok != h->hdr->k)
Branch: 1 branch
BranchTrueFalseTotal
if (ok != h->hdr->k) 1 16 17
221 1 croak("Data::MinHash::Shared->similarity: register-count mismatch (k=%llu vs k=%llu)",
222 (unsigned long long)h->hdr->k, (unsigned long long)ok);
223  
224 /* Snapshot the other's registers under its read lock into a temp buffer, then
225 * release before taking self's read lock. Copying to a temp avoids holding
226 * two locks at once (deadlock-free regardless of acquisition order). */
227 16 uint64_t k = ok;
228 16 uint64_t o_max = mnh_reg_max(o); /* Layer B: never read past o's real mapping */
229 16 ▶ if (k > o_max) k = o_max;
Branch: 1 branch
BranchTrueFalseTotal
if (k > o_max) k = o_max; 0 16 16
230 uint64_t *tmp;
231 16 ▶ Newx(tmp, (size_t)(k ? k : 1), uint64_t);
Branch: 3 branches
BranchTrueFalseTotal
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 16 0 16
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 0 16 16
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 16 0 16
232 16 SAVEFREEPV(tmp); /* freed on normal return OR croak unwind */
233 16 ▶ if (o->readonly) { /* frozen other: immutable registers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (o->readonly) { /* frozen other: immutable registers, no lock */ 3 13 16
234 3 memcpy(tmp, mnh_registers(o), (size_t)k * sizeof(uint64_t));
235 } else {
236 13 mnh_rwlock_rdlock(o);
237 13 memcpy(tmp, mnh_registers(o), (size_t)k * sizeof(uint64_t));
238 13 mnh_rwlock_rdunlock(o);
239 }
240  
241 16 uint64_t agree, kk = h->hdr->k;
242 16 ▶ if (h->readonly) { /* frozen self: immutable registers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen self: immutable registers, no lock */ 3 13 16
243 3 agree = mnh_agree_locked(h, tmp, k);
244 } else {
245 13 mnh_rwlock_rdlock(h);
246 13 agree = mnh_agree_locked(h, tmp, k);
247 13 mnh_rwlock_rdunlock(h);
248 }
249 16 ▶ RETVAL = kk ? (double)agree / (double)kk : 0.0;
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = kk ? (double)agree / (double)kk : 0.0; 16 0 16
RETVAL = kk ? (double)agree / (double)kk : 0.0; 3 13 16
250 OUTPUT:
251 RETVAL
252  
253 # ---- b-bit MinHash: estimate Jaccard from only the low b bits of each register ----
254  
255 NV
256 bbit_similarity(self, other, b)
257 SV *self
258 SV *other
259 UV b
260 PREINIT:
261 168 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 168 0 168
EXTRACT(self); 0 168 168
EXTRACT(self); 0 168 168
262 CODE:
263 168 ▶ if (b < 1 || b > 64)
Branch: 2 branches
BranchTrueFalseTotal
if (b < 1 || b > 64) 167 1 168
if (b < 1 || b > 64) 1 166 167
264 2 croak("Data::MinHash::Shared->bbit_similarity: b must be between 1 and 64");
265 166 ▶ if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared"))
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared")) 166 0 166
if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared")) 0 166 166
266 0 croak("Data::MinHash::Shared->bbit_similarity: expected a Data::MinHash::Shared object");
267 166 MnhHandle *o = INT2PTR(MnhHandle*, SvIV(SvRV(other)));
268 166 ▶ if (!o) croak("Attempted to use a destroyed Data::MinHash::Shared object");
Branch: 1 branch
BranchTrueFalseTotal
if (!o) croak("Attempted to use a destroyed Data::MinHash::Shared object"); 0 166 166
269 166 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 166 166
REEXTRACT(self); 0 166 166
270 166 uint64_t ok = o->hdr->k;
271 166 ▶ if (ok != h->hdr->k)
Branch: 1 branch
BranchTrueFalseTotal
if (ok != h->hdr->k) 1 165 166
272 1 croak("Data::MinHash::Shared->bbit_similarity: register-count mismatch (k=%llu vs k=%llu)",
273 (unsigned long long)h->hdr->k, (unsigned long long)ok);
274 {
275 165 uint64_t k = ok, o_max = mnh_reg_max(o); /* Layer B: never read past o's mapping */
276 165 ▶ if (k > o_max) k = o_max;
Branch: 1 branch
BranchTrueFalseTotal
if (k > o_max) k = o_max; 0 165 165
277 uint64_t *tmp;
278 165 ▶ Newx(tmp, (size_t)(k ? k : 1), uint64_t);
Branch: 3 branches
BranchTrueFalseTotal
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 165 0 165
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 0 165 165
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 165 0 165
279 165 SAVEFREEPV(tmp);
280 165 ▶ if (o->readonly) { /* frozen other: immutable registers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (o->readonly) { /* frozen other: immutable registers, no lock */ 4 161 165
281 4 memcpy(tmp, mnh_registers(o), (size_t)k * sizeof(uint64_t));
282 } else {
283 161 mnh_rwlock_rdlock(o);
284 161 memcpy(tmp, mnh_registers(o), (size_t)k * sizeof(uint64_t));
285 161 mnh_rwlock_rdunlock(o);
286 }
287  
288 165 uint64_t mask = mnh_bbit_mask((uint32_t)b), agree, kk = h->hdr->k;
289 165 ▶ if (h->readonly) { /* frozen self: immutable registers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen self: immutable registers, no lock */ 4 161 165
290 4 agree = mnh_bbit_agree_locked(h, tmp, k, mask);
291 } else {
292 161 mnh_rwlock_rdlock(h);
293 161 agree = mnh_bbit_agree_locked(h, tmp, k, mask);
294 161 mnh_rwlock_rdunlock(h);
295 }
296 165 ▶ double f = kk ? (double)agree / (double)kk : 0.0;
Branch: 1 branch
BranchTrueFalseTotal
double f = kk ? (double)agree / (double)kk : 0.0; 165 0 165
297 165 RETVAL = mnh_bbit_correct(f, (uint32_t)b);
298 }
299 OUTPUT:
300 RETVAL
301  
302 SV *
303 bbit_signature(self, b)
304 SV *self
305 UV b
306 PREINIT:
307 275 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 275 0 275
EXTRACT(self); 0 275 275
EXTRACT(self); 0 275 275
308 CODE:
309 275 ▶ if (b < 1 || b > 64)
Branch: 2 branches
BranchTrueFalseTotal
if (b < 1 || b > 64) 274 1 275
if (b < 1 || b > 64) 0 274 274
310 1 croak("Data::MinHash::Shared->bbit_signature: b must be between 1 and 64");
311 {
312 274 uint64_t k = h->hdr->k, kmax = mnh_reg_max(h); /* Layer B */
313 274 ▶ if (k > kmax) k = kmax;
Branch: 1 branch
BranchTrueFalseTotal
if (k > kmax) k = kmax; 0 274 274
314 274 uint64_t nbytes = (k * (uint64_t)b + 7) / 8;
315 uint64_t *regs; uint8_t *out;
316 274 ▶ Newx(regs, (size_t)(k ? k : 1), uint64_t); SAVEFREEPV(regs);
Branch: 3 branches
BranchTrueFalseTotal
Newx(regs, (size_t)(k ? k : 1), uint64_t); SAVEFREEPV(regs); 274 0 274
Newx(regs, (size_t)(k ? k : 1), uint64_t); SAVEFREEPV(regs); 0 274 274
Newx(regs, (size_t)(k ? k : 1), uint64_t); SAVEFREEPV(regs); 274 0 274
317 274 ▶ Newx(out, (size_t)(nbytes ? nbytes : 1), uint8_t); SAVEFREEPV(out);
Branch: 1 branch
BranchTrueFalseTotal
Newx(out, (size_t)(nbytes ? nbytes : 1), uint8_t); SAVEFREEPV(out); 274 0 274
318 274 ▶ if (h->readonly) { /* frozen: immutable registers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable registers, no lock */ 1 273 274
319 1 memcpy(regs, mnh_registers(h), (size_t)k * sizeof(uint64_t));
320 } else {
321 273 mnh_rwlock_rdlock(h);
322 273 memcpy(regs, mnh_registers(h), (size_t)k * sizeof(uint64_t));
323 273 mnh_rwlock_rdunlock(h);
324 }
325 274 mnh_bbit_pack(regs, k, (uint32_t)b, out); /* pack the low b bits, after unlock */
326 274 RETVAL = newSVpvn((char *)out, (STRLEN)nbytes);
327 }
328 OUTPUT:
329 RETVAL
330  
331 NV
332 bbit_similarity_of(class, sig_a, sig_b, k, b)
333 SV *class
334 SV *sig_a
335 SV *sig_b
336 UV k
337 UV b
338 PREINIT:
339 STRLEN la, lb;
340 const unsigned char *a, *bp;
341 CODE:
342 PERL_UNUSED_VAR(class);
343 139 ▶ if (b < 1 || b > 64) croak("Data::MinHash::Shared->bbit_similarity_of: b must be between 1 and 64");
Branch: 2 branches
BranchTrueFalseTotal
if (b < 1 || b > 64) croak("Data::MinHash::Shared->bbit_similarity_of: b must be between 1 and 64"); 139 0 139
if (b < 1 || b > 64) croak("Data::MinHash::Shared->bbit_similarity_of: b must be between 1 and 64"); 0 139 139
344 139 ▶ if (k < 1) croak("Data::MinHash::Shared->bbit_similarity_of: k must be >= 1");
Branch: 1 branch
BranchTrueFalseTotal
if (k < 1) croak("Data::MinHash::Shared->bbit_similarity_of: k must be >= 1"); 1 138 139
345 138 ▶ if (k > MNH_MAX_K) croak("Data::MinHash::Shared->bbit_similarity_of: k must be <= 16777216 (2^24)"); /* bound k*b so `need` cannot overflow */
Branch: 1 branch
BranchTrueFalseTotal
if (k > MNH_MAX_K) croak("Data::MinHash::Shared->bbit_similarity_of: k must be <= 16777216 (2^24)"); /* bound k*b so `need` cannot overflow */ 1 137 138
346 /* Copy sig_a into a private mortal first: SvPVbyte(sig_b) below runs a
347 * tied/overloaded sig_b's magic, which could realloc/free sig_a's PV and
348 * dangle `a`. The copy stays valid for the compare loop. */
349 274 ▶ { SV *ca = sv_2mortal(newSVsv(sig_a)); a = (const unsigned char *)SvPVbyte(ca, la); }
Branch: 1 branch
BranchTrueFalseTotal
{ SV *ca = sv_2mortal(newSVsv(sig_a)); a = (const unsigned char *)SvPVbyte(ca, la); } 137 0 137
350 137 bp = (const unsigned char *)SvPVbyte(sig_b, lb);
351 {
352 137 STRLEN need = (STRLEN)(((uint64_t)k * (uint64_t)b + 7) / 8);
353 137 ▶ if (la < need || lb < need)
Branch: 2 branches
BranchTrueFalseTotal
if (la < need || lb < need) 136 1 137
if (la < need || lb < need) 0 136 136
354 1 croak("Data::MinHash::Shared->bbit_similarity_of: signature too short for k=%llu b=%llu (need %llu bytes)",
355 (unsigned long long)k, (unsigned long long)b, (unsigned long long)need);
356 136 uint64_t agree = 0;
357 8968 ▶ for (uint64_t i = 0; i < (uint64_t)k; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (uint64_t i = 0; i < (uint64_t)k; i++) 8832 136 8968
358 8832 ▶ if (mnh_bbit_get(a, i, (uint32_t)b) == mnh_bbit_get(bp, i, (uint32_t)b)) agree++;
Branch: 1 branch
BranchTrueFalseTotal
if (mnh_bbit_get(a, i, (uint32_t)b) == mnh_bbit_get(bp, i, (uint32_t)b)) agree++; 5214 3618 8832
359 136 double f = (double)agree / (double)k;
360 136 RETVAL = mnh_bbit_correct(f, (uint32_t)b);
361 }
362 OUTPUT:
363 RETVAL
364  
365 void
366 merge(self, other)
367 SV *self
368 SV *other
369 PREINIT:
370 6 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 6 0 6
EXTRACT(self); 0 6 6
EXTRACT(self); 0 6 6
371 CODE:
372 6 ▶ if (h->readonly) croak("Data::MinHash::Shared->merge: sketch is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::MinHash::Shared->merge: sketch is frozen (read-only)"); 2 4 6
373 4 ▶ if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared"))
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared")) 4 0 4
if (!sv_isobject(other) || !sv_derived_from(other, "Data::MinHash::Shared")) 0 4 4
374 0 croak("Data::MinHash::Shared->merge: expected a Data::MinHash::Shared object");
375 4 MnhHandle *o = INT2PTR(MnhHandle*, SvIV(SvRV(other)));
376 4 ▶ if (!o) croak("Attempted to use a destroyed Data::MinHash::Shared object");
Branch: 1 branch
BranchTrueFalseTotal
if (!o) croak("Attempted to use a destroyed Data::MinHash::Shared object"); 0 4 4
377 4 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 4 4
REEXTRACT(self); 0 4 4
378  
379 /* k is immutable after creation -- compare lock-free, croak BEFORE allocating
380 * so a mismatch holds no lock and leaks no buffer. */
381 4 uint64_t ok = o->hdr->k;
382 4 ▶ if (ok != h->hdr->k)
Branch: 1 branch
BranchTrueFalseTotal
if (ok != h->hdr->k) 1 3 4
383 1 croak("Data::MinHash::Shared->merge: register-count mismatch (k=%llu vs k=%llu)",
384 (unsigned long long)h->hdr->k, (unsigned long long)ok);
385  
386 /* Snapshot the other's registers under its read lock into a temp buffer, then
387 * release before taking self's write lock. Copying to a temp avoids holding
388 * two locks at once (deadlock-free regardless of acquisition order between
389 * two processes merging each other). */
390 3 uint64_t k = ok;
391 3 uint64_t o_max = mnh_reg_max(o); /* Layer B: never read past o's real mapping */
392 3 ▶ if (k > o_max) k = o_max;
Branch: 1 branch
BranchTrueFalseTotal
if (k > o_max) k = o_max; 0 3 3
393 uint64_t *tmp;
394 3 ▶ Newx(tmp, (size_t)(k ? k : 1), uint64_t);
Branch: 3 branches
BranchTrueFalseTotal
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 3 0 3
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 0 3 3
Newx(tmp, (size_t)(k ? k : 1), uint64_t); 3 0 3
395 3 SAVEFREEPV(tmp); /* freed on normal return OR croak unwind */
396 3 ▶ if (o->readonly) { /* frozen other: immutable registers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (o->readonly) { /* frozen other: immutable registers, no lock */ 2 1 3
397 2 memcpy(tmp, mnh_registers(o), (size_t)k * sizeof(uint64_t));
398 } else {
399 1 mnh_rwlock_rdlock(o);
400 1 memcpy(tmp, mnh_registers(o), (size_t)k * sizeof(uint64_t));
401 1 mnh_rwlock_rdunlock(o);
402 }
403  
404 3 mnh_rwlock_wrlock(h);
405 3 ▶ if (h->hdr->sealed) { mnh_rwlock_wrunlock(h); croak("Data::MinHash::Shared->merge: sketch is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { mnh_rwlock_wrunlock(h); croak("Data::MinHash::Shared->merge: sketch is frozen (read-only)"); } 1 2 3
406 2 mnh_merge_locked(h, tmp, k);
407 2 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
408 2 mnh_rwlock_wrunlock(h);
409  
410 void
411 registers(self)
412 SV *self
413 PREINIT:
414 20 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 20 0 20
EXTRACT(self); 0 20 20
EXTRACT(self); 0 20 20
415 PPCODE:
416 {
417 20 uint64_t k = h->hdr->k;
418 20 uint64_t kmax = mnh_reg_max(h); /* Layer B: never read past the real mapping */
419 20 ▶ if (k > kmax) k = kmax;
Branch: 1 branch
BranchTrueFalseTotal
if (k > kmax) k = kmax; 0 20 20
420 20 uint64_t *snap = NULL;
421 20 ▶ if (k) { Newx(snap, (size_t)k, uint64_t); SAVEFREEPV(snap); } /* alloc BEFORE the lock */
Branch: 2 branches
BranchTrueFalseTotal
if (k) { Newx(snap, (size_t)k, uint64_t); SAVEFREEPV(snap); } /* alloc BEFORE the lock */ 20 0 20
if (k) { Newx(snap, (size_t)k, uint64_t); SAVEFREEPV(snap); } /* alloc BEFORE the lock */ 0 20 20
422 20 ▶ if (h->readonly) { /* frozen: immutable registers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable registers, no lock */ 4 16 20
423 4 ▶ if (k) memcpy(snap, mnh_registers(h), (size_t)k * sizeof(uint64_t));
Branch: 1 branch
BranchTrueFalseTotal
if (k) memcpy(snap, mnh_registers(h), (size_t)k * sizeof(uint64_t)); 4 0 4
424 } else {
425 16 mnh_rwlock_rdlock(h);
426 16 ▶ if (k) memcpy(snap, mnh_registers(h), (size_t)k * sizeof(uint64_t));
Branch: 1 branch
BranchTrueFalseTotal
if (k) memcpy(snap, mnh_registers(h), (size_t)k * sizeof(uint64_t)); 16 0 16
427 16 mnh_rwlock_rdunlock(h);
428 }
429 20 ▶ EXTEND(SP, (SSize_t)k);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, (SSize_t)k); 20 0 20
EXTEND(SP, (SSize_t)k); 0 20 20
430 3052 ▶ for (uint64_t j = 0; j < k; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (uint64_t j = 0; j < k; j++) 3032 20 3052
431 3032 PUSHs(sv_2mortal(newSVuv((UV)snap[j]))); /* Perl alloc AFTER unlock */
432 }
433  
434 UV
435 filled(self)
436 SV *self
437 PREINIT:
438 12 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 12 0 12
EXTRACT(self); 0 12 12
EXTRACT(self); 1 11 12
439 UV n;
440 CODE:
441 11 ▶ if (h->readonly) { /* frozen: immutable registers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable registers, no lock */ 2 9 11
442 2 n = (UV)mnh_filled_locked(h);
443 } else {
444 9 mnh_rwlock_rdlock(h);
445 9 n = (UV)mnh_filled_locked(h);
446 9 mnh_rwlock_rdunlock(h);
447 }
448 11 ▶ RETVAL = n;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = n; 0 11 11
449 OUTPUT:
450 RETVAL
451  
452 void
453 clear(self)
454 SV *self
455 PREINIT:
456 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
457 CODE:
458 4 ▶ if (h->readonly) croak("Data::MinHash::Shared->clear: sketch is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::MinHash::Shared->clear: sketch is frozen (read-only)"); 2 2 4
459 2 mnh_rwlock_wrlock(h);
460 2 ▶ if (h->hdr->sealed) { mnh_rwlock_wrunlock(h); croak("Data::MinHash::Shared->clear: sketch is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { mnh_rwlock_wrunlock(h); croak("Data::MinHash::Shared->clear: sketch is frozen (read-only)"); } 1 1 2
461 1 mnh_clear_locked(h);
462 1 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
463 1 mnh_rwlock_wrunlock(h);
464  
465 void
466 freeze(self)
467 SV *self
468 PREINIT:
469 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
470 CODE:
471 4 ▶ if (h->readonly) croak("Data::MinHash::Shared->freeze: cannot freeze a read-only handle");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::MinHash::Shared->freeze: cannot freeze a read-only handle"); 2 2 4
472 2 ▶ if (mnh_freeze(h) != 0) croak("Data::MinHash::Shared->freeze: msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (mnh_freeze(h) != 0) croak("Data::MinHash::Shared->freeze: msync: %s", strerror(errno)); 0 2 2
473 2 h->readonly = 1; /* this handle now rejects mutation too (the file is sealed) */
474  
475 UV
476 frozen(self)
477 SV *self
478 PREINIT:
479 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
480 CODE:
481 4 ▶ RETVAL = __atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = __atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0; 0 4 4
482 OUTPUT:
483 RETVAL
484  
485 UV
486 readonly(self)
487 SV *self
488 PREINIT:
489 3 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 3 0 3
EXTRACT(self); 0 3 3
EXTRACT(self); 0 3 3
490 CODE:
491 3 ▶ RETVAL = h->readonly ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->readonly ? 1 : 0; 0 3 3
492 OUTPUT:
493 RETVAL
494  
495 UV
496 size(self)
497 SV *self
498 PREINIT:
499 7 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 7 0 7
EXTRACT(self); 0 7 7
EXTRACT(self); 0 7 7
500 CODE:
501 7 ▶ RETVAL = (UV)h->hdr->k;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV)h->hdr->k; 0 7 7
502 OUTPUT:
503 RETVAL
504  
505 SV *
506 stats(self)
507 SV *self
508 PREINIT:
509 2 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 2 0 2
EXTRACT(self); 0 2 2
EXTRACT(self); 0 2 2
510 CODE:
511 {
512 uint64_t k, filled, ops;
513 /* Snapshot under the lock; do all (croak-capable) Perl allocation after
514 releasing it -- so an OOM in newHV/newSVuv can never strand the lock. */
515 2 ▶ if (!h->readonly) mnh_rwlock_rdlock(h); /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) mnh_rwlock_rdlock(h); /* frozen: immutable, no lock */ 1 1 2
516 2 filled = mnh_filled_locked(h);
517 2 k = h->hdr->k;
518 2 ops = h->hdr->stat_ops;
519 2 ▶ if (!h->readonly) mnh_rwlock_rdunlock(h);
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) mnh_rwlock_rdunlock(h); 1 1 2
520  
521 2 HV *hv = newHV();
522 2 hv_stores(hv, "size", newSVuv((UV)k));
523 2 hv_stores(hv, "filled", newSVuv((UV)filled));
524 2 hv_stores(hv, "ops", newSVuv((UV)ops));
525 2 hv_stores(hv, "mmap_size", newSVuv((UV)h->mmap_size));
526 2 hv_stores(hv, "frozen", newSVuv(__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0));
527 2 hv_stores(hv, "readonly", newSVuv(h->readonly ? 1 : 0));
528 2 RETVAL = newRV_noinc((SV *)hv);
529 }
530 OUTPUT:
531 RETVAL
532  
533 SV *
534 path(self)
535 SV *self
536 PREINIT:
537 2 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 2 0 2
EXTRACT(self); 0 2 2
EXTRACT(self); 0 2 2
538 CODE:
539 2 ▶ RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; 2 0 2
540 OUTPUT:
541 RETVAL
542  
543 int
544 memfd(self)
545 SV *self
546 PREINIT:
547 3 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 3 0 3
EXTRACT(self); 0 3 3
EXTRACT(self); 0 3 3
548 CODE:
549 3 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 3 3
550 OUTPUT:
551 RETVAL
552  
553 void
554 sync(self)
555 SV *self
556 PREINIT:
557 3 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 3 0 3
EXTRACT(self); 0 3 3
EXTRACT(self); 0 3 3
558 CODE:
559 3 ▶ if (!h->readonly && mnh_msync(h) != 0) croak("sync: %s", strerror(errno));
Branch: 2 branches
BranchTrueFalseTotal
if (!h->readonly && mnh_msync(h) != 0) croak("sync: %s", strerror(errno)); 2 1 3
if (!h->readonly && mnh_msync(h) != 0) croak("sync: %s", strerror(errno)); 0 2 2
560  
561 void
562 unlink(self, ...)
563 SV *self
564 CODE:
565 1 ▶ if (sv_isobject(self) && sv_derived_from(self, "Data::MinHash::Shared")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self) && sv_derived_from(self, "Data::MinHash::Shared")) { 0 1 1
if (sv_isobject(self) && sv_derived_from(self, "Data::MinHash::Shared")) { 0 0 0
566 0 MnhHandle *h = INT2PTR(MnhHandle*, SvIV(SvRV(self)));
567 0 ▶ if (h && h->path && unlink(h->path) != 0 && errno != ENOENT)
Branch: 4 branches
BranchTrueFalseTotal
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
568 0 croak("Data::MinHash::Shared->unlink(%s): %s", h->path, strerror(errno));
569 1 ▶ } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) {
Branch: 4 branches
BranchTrueFalseTotal
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 1 0 1
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 0 1 1
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 0 0 0
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 1 0 1
570 {
571 1 const char *up = SvPV_nolen(ST(1));
572 1 ▶ if (unlink(up) != 0 && errno != ENOENT)
Branch: 2 branches
BranchTrueFalseTotal
if (unlink(up) != 0 && errno != ENOENT) 0 1 1
if (unlink(up) != 0 && errno != ENOENT) 0 0 0
573 0 croak("Data::MinHash::Shared->unlink(%s): %s", up, strerror(errno));
574 }
575 }
« minhash.h ↑ Summary