Shared.xs

filter: Statementstmt 96.9% 257 / 265 Branchbran 65.3% 243 / 372 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 78.4% 500 / 637 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« roaring.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 "roaring.h"
7  
8 #define EXTRACT(sv) \
9 if (!sv_isobject(sv) || !sv_derived_from(sv, "Data::RoaringBitmap::Shared")) \
10 croak("Expected a Data::RoaringBitmap::Shared object"); \
11 RbHandle *h = INT2PTR(RbHandle*, SvIV(SvRV(sv))); \
12 if (!h) croak("Attempted to use a destroyed Data::RoaringBitmap::Shared object"); \
13 RbHandle *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 #define REEXTRACT(sv) \
23 if (!SvROK(sv)) \
24 croak("Data::RoaringBitmap::Shared object was replaced during the call"); \
25 h = INT2PTR(RbHandle*, SvIV(SvRV(sv))); \
26 if (h != h0) croak("Data::RoaringBitmap::Shared object replaced or destroyed during the call")
27  
28 #define MAKE_OBJ(class, handle) \
29 SV *obj = newSViv(PTR2IV(handle)); \
30 SV *ref = newRV_noinc(obj); \
31 sv_bless(ref, gv_stashpv(class, GV_ADD)); \
32 RETVAL = ref
33  
34 #define RB_UINT32_MAX_UV ((UV)0xFFFFFFFF)
35  
36 /* Acquire the receiver `a`'s WRITE lock and the other `b`'s READ lock in a
37 * globally-consistent order keyed on each bitmap's shared-memory identity
38 * (hdr->bitmap_id), NOT the process-local handle pointer. Two unrelated
39 * processes mapping the same pair X,Y therefore agree on order, so a
40 * concurrent X.union(Y) / Y.union(X) cannot deadlock. The receiver always
41 * gets the write lock and the other the read lock regardless of which is
42 * acquired first. a and b must refer to DISTINCT underlying bitmaps (the
43 * caller has already ruled out a == b and equal bitmap_id). */
44 12 static void rb_lock_pair(RbHandle *a, RbHandle *b) {
45 12 ▶ if (a->hdr->bitmap_id < b->hdr->bitmap_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (a->hdr->bitmap_id < b->hdr->bitmap_id) { 8 4 12
46 8 rb_rwlock_wrlock(a);
47 8 rb_rwlock_rdlock(b);
48 } else {
49 4 rb_rwlock_rdlock(b);
50 4 rb_rwlock_wrlock(a);
51 }
52 12 }
53 12 static void rb_unlock_pair(RbHandle *a, RbHandle *b) {
54 12 ▶ if (a->hdr->bitmap_id < b->hdr->bitmap_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (a->hdr->bitmap_id < b->hdr->bitmap_id) { 8 4 12
55 8 rb_rwlock_rdunlock(b);
56 8 rb_rwlock_wrunlock(a);
57 } else {
58 4 rb_rwlock_wrunlock(a);
59 4 rb_rwlock_rdunlock(b);
60 }
61 12 }
62  
63 MODULE = Data::RoaringBitmap::Shared PACKAGE = Data::RoaringBitmap::Shared
64  
65 PROTOTYPES: DISABLE
66  
67 SV *
68 new(class, path = &PL_sv_undef, container_capacity = 256, file_mode = 0600)
69 const char *class
70 SV *path
71 UV container_capacity
72 UV file_mode
73 PREINIT:
74 char errbuf[RB_ERR_BUFLEN];
75 CODE:
76 120 ▶ 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 80 80
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; 40 40 80
77 80 RbHandle *h = rb_create(p, (uint64_t)container_capacity, (mode_t)file_mode, errbuf); /* validates args into errbuf */
78 80 ▶ if (!h) croak("Data::RoaringBitmap::Shared->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::RoaringBitmap::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); 7 73 80
if (!h) croak("Data::RoaringBitmap::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); 7 0 7
79 73 MAKE_OBJ(class, h);
80 OUTPUT:
81 RETVAL
82  
83 SV *
84 new_memfd(class, name = &PL_sv_undef, container_capacity = 256)
85 const char *class
86 SV *name
87 UV container_capacity
88 PREINIT:
89 char errbuf[RB_ERR_BUFLEN];
90 CODE:
91 5 ▶ 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 3 3
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 1 3
92 3 RbHandle *h = rb_create_memfd(nm, (uint64_t)container_capacity, errbuf); /* validates args into errbuf */
93 3 ▶ if (!h) croak("Data::RoaringBitmap::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::RoaringBitmap::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 1 2 3
if (!h) croak("Data::RoaringBitmap::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
94 2 MAKE_OBJ(class, h);
95 OUTPUT:
96 RETVAL
97  
98 SV *
99 new_from_fd(class, fd)
100 const char *class
101 int fd
102 PREINIT:
103 char errbuf[RB_ERR_BUFLEN];
104 CODE:
105 2 RbHandle *h = rb_open_fd(fd, errbuf);
106 2 ▶ if (!h) croak("Data::RoaringBitmap::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::RoaringBitmap::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 1 2
if (!h) croak("Data::RoaringBitmap::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
107 1 MAKE_OBJ(class, h);
108 OUTPUT:
109 RETVAL
110  
111 SV *
112 new_readonly(class, path)
113 const char *class
114 SV *path
115 PREINIT:
116 char errbuf[RB_ERR_BUFLEN];
117 CODE:
118 /* Open a FROZEN (sealed) file read-only: O_RDONLY + PROT_READ, no lock
119 ever. A sealed file is immutable and no read path writes the mapping,
120 so queries take no reader-slot / rwlock traffic and any number of
121 processes can share one PROT_READ mapping (same architecture; the
122 magic rejects a wrong-endian file). */
123 15 ▶ 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 8 8
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; 7 1 8
124 8 ▶ if (!p) croak("Data::RoaringBitmap::Shared->new_readonly: path is required");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Data::RoaringBitmap::Shared->new_readonly: path is required"); 1 7 8
125 7 RbHandle *h = rb_open_readonly(p, errbuf);
126 7 ▶ if (!h) croak("Data::RoaringBitmap::Shared->new_readonly: %s", errbuf);
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Data::RoaringBitmap::Shared->new_readonly: %s", errbuf); 2 5 7
127 5 class = SvPV_nolen(ST(0)); /* re-read: path get-magic may have realloced ST(0)'s PV before bless */
128 5 MAKE_OBJ(class, h);
129 OUTPUT:
130 RETVAL
131  
132 void
133 DESTROY(self)
134 SV *self
135 CODE:
136 83 ▶ if (sv_isobject(self) && sv_derived_from(self, "Data::RoaringBitmap::Shared")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self) && sv_derived_from(self, "Data::RoaringBitmap::Shared")) { 83 0 83
if (sv_isobject(self) && sv_derived_from(self, "Data::RoaringBitmap::Shared")) { 83 0 83
137 83 RbHandle *h = INT2PTR(RbHandle*, SvIV(SvRV(self)));
138 83 ▶ if (h) { sv_setiv(SvRV(self), 0); rb_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); rb_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */ 81 2 83
139 }
140  
141 IV
142 add(self, x)
143 SV *self
144 UV x
145 PREINIT:
146 44683 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 44683 0 44683
EXTRACT(self); 0 44683 44683
EXTRACT(self); 0 44683 44683
147 int added;
148 uint32_t hi;
149 CODE:
150 44683 ▶ if (h->readonly) croak("Data::RoaringBitmap::Shared->add: bitmap is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::RoaringBitmap::Shared->add: bitmap is frozen (read-only)"); 3 44680 44683
151 /* Range-check BEFORE locking: a croak must never happen under the lock. */
152 44680 ▶ if (x > RB_UINT32_MAX_UV)
Branch: 1 branch
BranchTrueFalseTotal
if (x > RB_UINT32_MAX_UV) 2 44678 44680
153 2 croak("Data::RoaringBitmap::Shared->add: value %" UVuf " exceeds uint32 (max 4294967295)", x);
154 44678 hi = (uint32_t)(x >> 16);
155 44678 rb_rwlock_wrlock(h);
156 44678 ▶ if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->add: bitmap is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->add: bitmap is frozen (read-only)"); } 0 44678 44678
157 /* Need a free container slot only if this value touches an empty bucket. */
158 44678 ▶ if (rb_buckets(h)[hi].type == RB_TYPE_NONE && rb_avail_slots(h) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (rb_buckets(h)[hi].type == RB_TYPE_NONE && rb_avail_slots(h) == 0) { 174 44504 44678
if (rb_buckets(h)[hi].type == RB_TYPE_NONE && rb_avail_slots(h) == 0) { 12 162 174
159 12 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); /* a call that took the write lock counts (matches add_many) */
160 12 rb_rwlock_wrunlock(h); /* release BEFORE croak */
161 12 croak("Data::RoaringBitmap::Shared->add: container pool exhausted "
162 "(grow container_capacity)");
163 }
164 44666 added = rb_add_locked(h, (uint32_t)x);
165 44666 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
166 44666 rb_rwlock_wrunlock(h);
167 44666 ▶ RETVAL = (IV)added;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (IV)added; 44621 45 44666
168 OUTPUT:
169 RETVAL
170  
171 IV
172 add_many(self, ints)
173 SV *self
174 SV *ints
175 PREINIT:
176 41 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 41 0 41
EXTRACT(self); 0 41 41
EXTRACT(self); 0 41 41
177 AV *av;
178 SSize_t n, i;
179 UV *vals;
180 IV total_added;
181 CODE:
182 41 ▶ if (h->readonly) croak("Data::RoaringBitmap::Shared->add_many: bitmap is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::RoaringBitmap::Shared->add_many: bitmap is frozen (read-only)"); 2 39 41
183 39 ▶ SvGETMAGIC(ints);
Branch: 2 branches
BranchTrueFalseTotal
SvGETMAGIC(ints); 0 39 39
SvGETMAGIC(ints); 0 0 0
184 39 ▶ if (!SvROK(ints) || SvTYPE(SvRV(ints)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ints) || SvTYPE(SvRV(ints)) != SVt_PVAV) 39 0 39
if (!SvROK(ints) || SvTYPE(SvRV(ints)) != SVt_PVAV) 0 39 39
185 0 croak("Data::RoaringBitmap::Shared->add_many: expected an array reference");
186 39 av = (AV *)SvRV(ints);
187 39 sv_2mortal(SvREFCNT_inc((SV *)av)); /* pin the arrayref: element magic below cannot free it mid-loop */
188 39 n = av_len(av) + 1;
189 /* Resolve + range-check every value BEFORE the lock (croak-free section). */
190 39 ▶ Newx(vals, n > 0 ? n : 1, UV);
Branch: 3 branches
BranchTrueFalseTotal
Newx(vals, n > 0 ? n : 1, UV); 39 0 39
Newx(vals, n > 0 ? n : 1, UV); 0 39 39
Newx(vals, n > 0 ? n : 1, UV); 39 0 39
191 39 SAVEFREEPV(vals);
192 69392 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 69354 38 69392
193 69354 SV **e = av_fetch(av, i, 0);
194 69354 ▶ if (e && *e) SvGETMAGIC(*e); /* a tied-array element is a deferred-magic PVLV */
Branch: 4 branches
BranchTrueFalseTotal
if (e && *e) SvGETMAGIC(*e); /* a tied-array element is a deferred-magic PVLV */ 69354 0 69354
if (e && *e) SvGETMAGIC(*e); /* a tied-array element is a deferred-magic PVLV */ 69354 0 69354
if (e && *e) SvGETMAGIC(*e); /* a tied-array element is a deferred-magic PVLV */ 0 69354 69354
if (e && *e) SvGETMAGIC(*e); /* a tied-array element is a deferred-magic PVLV */ 0 0 0
195 69354 ▶ UV v = (e && SvOK(*e)) ? SvUV(*e) : 0;
Branch: 2 branches
BranchTrueFalseTotal
UV v = (e && SvOK(*e)) ? SvUV(*e) : 0; 69354 0 69354
UV v = (e && SvOK(*e)) ? SvUV(*e) : 0; 69354 0 69354
196 69354 ▶ if (v > RB_UINT32_MAX_UV) {
Branch: 1 branch
BranchTrueFalseTotal
if (v > RB_UINT32_MAX_UV) { 1 69353 69354
197 1 croak("Data::RoaringBitmap::Shared->add_many: value %" UVuf
198 " exceeds uint32 (max 4294967295)", v);
199 }
200 69353 vals[i] = v;
201 }
202 38 total_added = 0;
203 38 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 38 38
REEXTRACT(self); 0 38 38
204 38 rb_rwlock_wrlock(h);
205 38 ▶ if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->add_many: bitmap is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->add_many: bitmap is frozen (read-only)"); } 0 38 38
206 69387 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 69350 37 69387
207 69350 uint32_t hi = (uint32_t)(vals[i] >> 16);
208 69350 ▶ if (rb_buckets(h)[hi].type == RB_TYPE_NONE && rb_avail_slots(h) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (rb_buckets(h)[hi].type == RB_TYPE_NONE && rb_avail_slots(h) == 0) { 2403 66947 69350
if (rb_buckets(h)[hi].type == RB_TYPE_NONE && rb_avail_slots(h) == 0) { 1 2402 2403
209 1 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
210 1 rb_rwlock_wrunlock(h); /* release BEFORE croak; partial adds remain (documented non-atomic) */
211 1 croak("Data::RoaringBitmap::Shared->add_many: container pool exhausted "
212 "after adding %" IVdf " element(s) (grow container_capacity)", total_added);
213 }
214 69349 total_added += rb_add_locked(h, (uint32_t)vals[i]);
215 }
216 37 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
217 37 rb_rwlock_wrunlock(h);
218 37 ▶ RETVAL = total_added;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = total_added; 15 22 37
219 OUTPUT:
220 RETVAL
221  
222 bool
223 contains(self, x)
224 SV *self
225 UV x
226 PREINIT:
227 12815 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 12815 0 12815
EXTRACT(self); 0 12815 12815
EXTRACT(self); 1 12814 12815
228 CODE:
229 12814 ▶ if (x > RB_UINT32_MAX_UV) { RETVAL = 0; } /* a value out of range is simply absent */
Branch: 1 branch
BranchTrueFalseTotal
if (x > RB_UINT32_MAX_UV) { RETVAL = 0; } /* a value out of range is simply absent */ 1 12813 12814
230 12813 ▶ else if (h->readonly) { /* frozen: immutable containers, no lock */
Branch: 1 branch
BranchTrueFalseTotal
else if (h->readonly) { /* frozen: immutable containers, no lock */ 17 12796 12813
231 17 RETVAL = rb_contains_locked(h, (uint32_t)x) ? 1 : 0;
232 }
233 else {
234 12796 rb_rwlock_rdlock(h);
235 12796 RETVAL = rb_contains_locked(h, (uint32_t)x) ? 1 : 0;
236 12796 rb_rwlock_rdunlock(h);
237 }
238 OUTPUT:
239 RETVAL
240  
241 IV
242 remove(self, x)
243 SV *self
244 UV x
245 PREINIT:
246 5014 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 5014 0 5014
EXTRACT(self); 0 5014 5014
EXTRACT(self); 0 5014 5014
247 int removed;
248 CODE:
249 5014 ▶ if (h->readonly) croak("Data::RoaringBitmap::Shared->remove: bitmap is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::RoaringBitmap::Shared->remove: bitmap is frozen (read-only)"); 3 5011 5014
250 5011 ▶ if (x > RB_UINT32_MAX_UV) { RETVAL = 0; } /* out of range -> nothing to remove */
Branch: 1 branch
BranchTrueFalseTotal
if (x > RB_UINT32_MAX_UV) { RETVAL = 0; } /* out of range -> nothing to remove */ 1 5010 5011
251 else {
252 5010 rb_rwlock_wrlock(h);
253 5010 ▶ if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->remove: bitmap is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->remove: bitmap is frozen (read-only)"); } 0 5010 5010
254 5010 removed = rb_remove_locked(h, (uint32_t)x);
255 5010 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
256 5010 rb_rwlock_wrunlock(h);
257 5010 RETVAL = (IV)removed;
258 }
259 OUTPUT:
260 RETVAL
261  
262 UV
263 cardinality(self)
264 SV *self
265 PREINIT:
266 56 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 56 0 56
EXTRACT(self); 0 56 56
EXTRACT(self); 0 56 56
267 CODE:
268 56 ▶ if (h->readonly) { /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock */ 4 52 56
269 4 RETVAL = (UV)h->hdr->cardinality;
270 } else {
271 52 rb_rwlock_rdlock(h);
272 52 RETVAL = (UV)h->hdr->cardinality;
273 52 rb_rwlock_rdunlock(h);
274 }
275 OUTPUT:
276 RETVAL
277  
278 bool
279 is_empty(self)
280 SV *self
281 PREINIT:
282 5 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 5 0 5
EXTRACT(self); 0 5 5
EXTRACT(self); 0 5 5
283 CODE:
284 5 ▶ if (h->readonly) { /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock */ 1 4 5
285 1 RETVAL = (h->hdr->cardinality == 0) ? 1 : 0;
286 } else {
287 4 rb_rwlock_rdlock(h);
288 4 RETVAL = (h->hdr->cardinality == 0) ? 1 : 0;
289 4 rb_rwlock_rdunlock(h);
290 }
291 OUTPUT:
292 RETVAL
293  
294 SV *
295 min(self)
296 SV *self
297 PREINIT:
298 15 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 15 0 15
EXTRACT(self); 0 15 15
EXTRACT(self); 0 15 15
299 uint32_t v;
300 int found;
301 CODE:
302 15 ▶ if (h->readonly) { /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock */ 1 14 15
303 1 found = rb_min_locked(h, &v);
304 } else {
305 14 rb_rwlock_rdlock(h);
306 14 found = rb_min_locked(h, &v);
307 14 rb_rwlock_rdunlock(h);
308 }
309 15 ▶ RETVAL = found ? newSVuv((UV)v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = found ? newSVuv((UV)v) : &PL_sv_undef; 14 1 15
310 OUTPUT:
311 RETVAL
312  
313 SV *
314 max(self)
315 SV *self
316 PREINIT:
317 9 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 9 0 9
EXTRACT(self); 0 9 9
EXTRACT(self); 0 9 9
318 uint32_t v;
319 int found;
320 CODE:
321 9 ▶ if (h->readonly) { /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock */ 1 8 9
322 1 found = rb_max_locked(h, &v);
323 } else {
324 8 rb_rwlock_rdlock(h);
325 8 found = rb_max_locked(h, &v);
326 8 rb_rwlock_rdunlock(h);
327 }
328 9 ▶ RETVAL = found ? newSVuv((UV)v) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = found ? newSVuv((UV)v) : &PL_sv_undef; 8 1 9
329 OUTPUT:
330 RETVAL
331  
332 SV *
333 to_array(self)
334 SV *self
335 PREINIT:
336 48 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 48 0 48
EXTRACT(self); 0 48 48
EXTRACT(self); 0 48 48
337 AV *av;
338 UV card;
339 CODE:
340 /* Read the cardinality under a short read lock to size a C snapshot buffer.
341 Allocate it with Newx OUTSIDE any lock (Newx can OOM-longjmp, which under
342 the read lock would strand it), snapshot the set bits under a second read
343 lock, then build the AV AFTER unlocking -- newSVuv/av_store must never run
344 while the lock is held. The cardinality may grow between the read and the
345 fill, but to_array is a best-effort snapshot; we cap the fill at the buffer
346 length so we never write past it. */
347 48 ▶ if (h->readonly) { /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock */ 2 46 48
348 2 card = (UV)h->hdr->cardinality;
349 } else {
350 46 rb_rwlock_rdlock(h);
351 46 card = (UV)h->hdr->cardinality;
352 46 rb_rwlock_rdunlock(h);
353 }
354  
355 {
356 48 uint32_t *buf = NULL;
357 RbBucket *bt;
358 48 UV idx = 0;
359 48 ▶ if (card) { Newx(buf, card, uint32_t); SAVEFREEPV(buf); }
Branch: 2 branches
BranchTrueFalseTotal
if (card) { Newx(buf, card, uint32_t); SAVEFREEPV(buf); } 43 5 48
if (card) { Newx(buf, card, uint32_t); SAVEFREEPV(buf); } 0 43 43
360 48 ▶ if (!h->readonly) rb_rwlock_rdlock(h);
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) rb_rwlock_rdlock(h); 46 2 48
361 48 bt = rb_buckets(h);
362 1525 ▶ for (uint32_t hi = 0; hi < RB_NUM_BUCKETS && idx < card; hi++) {
Branch: 2 branches
BranchTrueFalseTotal
for (uint32_t hi = 0; hi < RB_NUM_BUCKETS && idx < card; hi++) { 1525 0 1525
for (uint32_t hi = 0; hi < RB_NUM_BUCKETS && idx < card; hi++) { 1477 48 1525
363 1477 ▶ if (bt[hi].type == RB_TYPE_NONE) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (bt[hi].type == RB_TYPE_NONE) continue; 27 1450 1477
364 1450 ▶ if (bt[hi].type == RB_TYPE_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (bt[hi].type == RB_TYPE_ARRAY) { 1441 9 1450
365 1441 uint16_t *vals = rb_array(h, bt[hi].container_off);
366 1441 uint32_t ac = rb_array_card(&bt[hi]);
367 18340 ▶ for (uint32_t i = 0; i < ac && idx < card; i++)
Branch: 2 branches
BranchTrueFalseTotal
for (uint32_t i = 0; i < ac && idx < card; i++) 16899 1441 18340
for (uint32_t i = 0; i < ac && idx < card; i++) 16899 0 16899
368 16899 buf[idx++] = ((uint32_t)hi << 16) | vals[i];
369 } else {
370 9 uint64_t *bits = rb_bitmap(h, bt[hi].container_off);
371 6498 ▶ for (uint32_t w = 0; w < 1024 && idx < card; w++) {
Branch: 2 branches
BranchTrueFalseTotal
for (uint32_t w = 0; w < 1024 && idx < card; w++) { 6492 6 6498
for (uint32_t w = 0; w < 1024 && idx < card; w++) { 6489 3 6492
372 6489 uint64_t word = bits[w];
373 54536 ▶ while (word && idx < card) {
Branch: 2 branches
BranchTrueFalseTotal
while (word && idx < card) { 48047 6489 54536
while (word && idx < card) { 48047 0 48047
374 48047 uint32_t lo = (w << 6) + (uint32_t)__builtin_ctzll(word);
375 48047 buf[idx++] = ((uint32_t)hi << 16) | lo;
376 48047 word &= word - 1; /* clear lowest set bit */
377 }
378 }
379 }
380 }
381 48 ▶ if (!h->readonly) rb_rwlock_rdunlock(h);
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) rb_rwlock_rdunlock(h); 46 2 48
382  
383 48 av = newAV();
384 48 ▶ if (idx) {
Branch: 1 branch
BranchTrueFalseTotal
if (idx) { 43 5 48
385 43 av_extend(av, (SSize_t)idx - 1);
386 64989 ▶ for (UV i = 0; i < idx; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (UV i = 0; i < idx; i++) 64946 43 64989
387 64946 av_store(av, (SSize_t)i, newSVuv((UV)buf[i]));
388 }
389 }
390 48 RETVAL = newRV_noinc((SV *)av);
391 OUTPUT:
392 RETVAL
393  
394 SV *
395 union(self, other)
396 SV *self
397 SV *other
398 PREINIT:
399 17 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 17 0 17
EXTRACT(self); 0 17 17
EXTRACT(self); 0 17 17
400 CODE:
401 17 ▶ if (h->readonly) croak("Data::RoaringBitmap::Shared->union: bitmap is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::RoaringBitmap::Shared->union: bitmap is frozen (read-only)"); 2 15 17
402 15 ▶ if (!sv_isobject(other) || !sv_derived_from(other, "Data::RoaringBitmap::Shared"))
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(other) || !sv_derived_from(other, "Data::RoaringBitmap::Shared")) 15 0 15
if (!sv_isobject(other) || !sv_derived_from(other, "Data::RoaringBitmap::Shared")) 0 15 15
403 0 croak("Data::RoaringBitmap::Shared->union: expected a Data::RoaringBitmap::Shared object");
404 {
405 15 RbHandle *o = INT2PTR(RbHandle*, SvIV(SvRV(other)));
406 15 ▶ if (!o) croak("Attempted to use a destroyed Data::RoaringBitmap::Shared object");
Branch: 1 branch
BranchTrueFalseTotal
if (!o) croak("Attempted to use a destroyed Data::RoaringBitmap::Shared object"); 0 15 15
407 /* sv_isobject/sv_derived_from above begin with SvGETMAGIC(other), so a
408 * tied `other` can have destroyed self before h is used below. `o` was
409 * read after that magic and needs no re-read. */
410 15 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 15 15
REEXTRACT(self); 0 15 15
411 /* Same bitmap: a pure no-op, including stats, so freeze cannot race a write. */
412 15 ▶ if (o == h || o->hdr->bitmap_id == h->hdr->bitmap_id) {
Branch: 2 branches
BranchTrueFalseTotal
if (o == h || o->hdr->bitmap_id == h->hdr->bitmap_id) { 12 3 15
if (o == h || o->hdr->bitmap_id == h->hdr->bitmap_id) { 4 8 12
413 7 ▶ if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE))
Branch: 1 branch
BranchTrueFalseTotal
if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) 3 4 7
414 3 croak("Data::RoaringBitmap::Shared->union: bitmap is frozen (read-only)");
415 4 SvREFCNT_inc(self);
416 4 RETVAL = self;
417 8 ▶ } else if (o->readonly) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (o->readonly) { 1 7 8
418 /* Frozen other: its containers are immutable (PROT_READ), so read them
419 * lock-free -- take ONLY the receiver's write lock (a read lock on o's
420 * PROT_READ mapping would SIGSEGV). No lock ordering is needed with
421 * one lock, so no rb_lock_pair. */
422 uint32_t need;
423 1 rb_rwlock_wrlock(h);
424 1 ▶ if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->union: bitmap is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->union: bitmap is frozen (read-only)"); } 0 1 1
425 1 need = rb_union_new_slots_needed(h, o);
426 1 ▶ if (rb_avail_slots(h) < need) {
Branch: 1 branch
BranchTrueFalseTotal
if (rb_avail_slots(h) < need) { 0 1 1
427 0 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
428 0 rb_rwlock_wrunlock(h); /* release BEFORE croak */
429 0 croak("Data::RoaringBitmap::Shared->union: container pool exhausted "
430 "(needs %u more container(s); grow container_capacity)", need);
431 }
432 1 rb_union_locked(h, o);
433 1 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
434 1 rb_rwlock_wrunlock(h);
435 1 SvREFCNT_inc(self);
436 1 RETVAL = self;
437 } else {
438 uint32_t need;
439 7 rb_lock_pair(h, o);
440 7 ▶ if (h->hdr->sealed) { rb_unlock_pair(h, o); croak("Data::RoaringBitmap::Shared->union: bitmap is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { rb_unlock_pair(h, o); croak("Data::RoaringBitmap::Shared->union: bitmap is frozen (read-only)"); } 0 7 7
441 7 need = rb_union_new_slots_needed(h, o);
442 7 ▶ if (rb_avail_slots(h) < need) {
Branch: 1 branch
BranchTrueFalseTotal
if (rb_avail_slots(h) < need) { 1 6 7
443 1 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
444 1 rb_unlock_pair(h, o); /* release BEFORE croak */
445 1 croak("Data::RoaringBitmap::Shared->union: container pool exhausted "
446 "(needs %u more container(s); grow container_capacity)", need);
447 }
448 6 rb_union_locked(h, o);
449 6 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
450 6 rb_unlock_pair(h, o);
451 6 SvREFCNT_inc(self); /* return the receiver for chaining */
452 6 RETVAL = self;
453 }
454 }
455 OUTPUT:
456 RETVAL
457  
458 SV *
459 intersect(self, other)
460 SV *self
461 SV *other
462 PREINIT:
463 14 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 14 0 14
EXTRACT(self); 0 14 14
EXTRACT(self); 0 14 14
464 CODE:
465 14 ▶ if (h->readonly) croak("Data::RoaringBitmap::Shared->intersect: bitmap is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::RoaringBitmap::Shared->intersect: bitmap is frozen (read-only)"); 2 12 14
466 12 ▶ if (!sv_isobject(other) || !sv_derived_from(other, "Data::RoaringBitmap::Shared"))
Branch: 2 branches
BranchTrueFalseTotal
if (!sv_isobject(other) || !sv_derived_from(other, "Data::RoaringBitmap::Shared")) 12 0 12
if (!sv_isobject(other) || !sv_derived_from(other, "Data::RoaringBitmap::Shared")) 0 12 12
467 0 croak("Data::RoaringBitmap::Shared->intersect: expected a Data::RoaringBitmap::Shared object");
468 {
469 12 RbHandle *o = INT2PTR(RbHandle*, SvIV(SvRV(other)));
470 12 ▶ if (!o) croak("Attempted to use a destroyed Data::RoaringBitmap::Shared object");
Branch: 1 branch
BranchTrueFalseTotal
if (!o) croak("Attempted to use a destroyed Data::RoaringBitmap::Shared object"); 0 12 12
471 /* sv_isobject/sv_derived_from above begin with SvGETMAGIC(other), so a
472 * tied `other` can have destroyed self before h is used below. `o` was
473 * read after that magic and needs no re-read. */
474 12 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 12 12
REEXTRACT(self); 0 12 12
475 /* Same bitmap: a pure no-op, including stats, so freeze cannot race a write. */
476 12 ▶ if (o == h || o->hdr->bitmap_id == h->hdr->bitmap_id) {
Branch: 2 branches
BranchTrueFalseTotal
if (o == h || o->hdr->bitmap_id == h->hdr->bitmap_id) { 9 3 12
if (o == h || o->hdr->bitmap_id == h->hdr->bitmap_id) { 3 6 9
477 6 ▶ if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE))
Branch: 1 branch
BranchTrueFalseTotal
if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) 3 3 6
478 3 croak("Data::RoaringBitmap::Shared->intersect: bitmap is frozen (read-only)");
479 3 SvREFCNT_inc(self);
480 3 RETVAL = self;
481 6 ▶ } else if (o->readonly) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (o->readonly) { 1 5 6
482 /* Frozen other: immutable containers, read lock-free -- take ONLY the
483 * receiver's write lock (o is PROT_READ; an rdlock on it would
484 * SIGSEGV). intersect never needs new slots. */
485 1 rb_rwlock_wrlock(h);
486 1 ▶ if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->intersect: bitmap is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->intersect: bitmap is frozen (read-only)"); } 0 1 1
487 1 rb_intersect_locked(h, o);
488 1 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
489 1 rb_rwlock_wrunlock(h);
490 1 SvREFCNT_inc(self);
491 1 RETVAL = self;
492 } else {
493 5 rb_lock_pair(h, o); /* intersect never needs new slots */
494 5 ▶ if (h->hdr->sealed) { rb_unlock_pair(h, o); croak("Data::RoaringBitmap::Shared->intersect: bitmap is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { rb_unlock_pair(h, o); croak("Data::RoaringBitmap::Shared->intersect: bitmap is frozen (read-only)"); } 0 5 5
495 5 rb_intersect_locked(h, o);
496 5 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
497 5 rb_unlock_pair(h, o);
498 5 SvREFCNT_inc(self);
499 5 RETVAL = self;
500 }
501 }
502 OUTPUT:
503 RETVAL
504  
505 void
506 clear(self)
507 SV *self
508 PREINIT:
509 3 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 3 0 3
EXTRACT(self); 0 3 3
EXTRACT(self); 0 3 3
510 CODE:
511 3 ▶ if (h->readonly) croak("Data::RoaringBitmap::Shared->clear: bitmap is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::RoaringBitmap::Shared->clear: bitmap is frozen (read-only)"); 2 1 3
512 1 rb_rwlock_wrlock(h);
513 1 ▶ if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->clear: bitmap is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { rb_rwlock_wrunlock(h); croak("Data::RoaringBitmap::Shared->clear: bitmap is frozen (read-only)"); } 0 1 1
514 1 rb_clear_locked(h);
515 1 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
516 1 rb_rwlock_wrunlock(h);
517  
518 void
519 freeze(self)
520 SV *self
521 PREINIT:
522 5 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 5 0 5
EXTRACT(self); 0 5 5
EXTRACT(self); 0 5 5
523 CODE:
524 5 ▶ if (h->readonly) croak("Data::RoaringBitmap::Shared->freeze: cannot freeze a read-only handle");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::RoaringBitmap::Shared->freeze: cannot freeze a read-only handle"); 2 3 5
525 3 ▶ if (rb_freeze(h) != 0) croak("Data::RoaringBitmap::Shared->freeze: msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (rb_freeze(h) != 0) croak("Data::RoaringBitmap::Shared->freeze: msync: %s", strerror(errno)); 0 3 3
526 3 h->readonly = 1; /* this handle now rejects mutation too (the file is sealed) */
527  
528 UV
529 frozen(self)
530 SV *self
531 PREINIT:
532 3 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 3 0 3
EXTRACT(self); 0 3 3
EXTRACT(self); 0 3 3
533 CODE:
534 3 ▶ 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 3 3
535 OUTPUT:
536 RETVAL
537  
538 UV
539 readonly(self)
540 SV *self
541 PREINIT:
542 3 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 3 0 3
EXTRACT(self); 0 3 3
EXTRACT(self); 0 3 3
543 CODE:
544 3 ▶ RETVAL = h->readonly ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->readonly ? 1 : 0; 0 3 3
545 OUTPUT:
546 RETVAL
547  
548 SV *
549 stats(self)
550 SV *self
551 PREINIT:
552 32 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 32 0 32
EXTRACT(self); 0 32 32
EXTRACT(self); 0 32 32
553 CODE:
554 {
555 uint64_t card, ops;
556 uint32_t cont_used, cont_cap, bkts_used;
557 /* Snapshot under the lock; do all (croak-capable) Perl allocation after
558 releasing it -- so an OOM in newHV/newSV* can never strand the lock. */
559 32 ▶ if (!h->readonly) rb_rwlock_rdlock(h); /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) rb_rwlock_rdlock(h); /* frozen: immutable, no lock */ 29 3 32
560 32 card = h->hdr->cardinality;
561 32 cont_used = h->hdr->container_used;
562 32 cont_cap = h->hdr->container_cap;
563 32 ops = h->hdr->stat_ops;
564 32 bkts_used = rb_buckets_used(h);
565 32 ▶ if (!h->readonly) rb_rwlock_rdunlock(h);
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) rb_rwlock_rdunlock(h); 29 3 32
566  
567 32 HV *hv = newHV();
568 32 hv_stores(hv, "cardinality", newSVuv((UV)card));
569 32 hv_stores(hv, "containers_used", newSVuv((UV)cont_used));
570 32 hv_stores(hv, "containers_capacity", newSVuv((UV)cont_cap));
571 32 hv_stores(hv, "buckets_used", newSVuv((UV)bkts_used));
572 32 hv_stores(hv, "ops", newSVuv((UV)ops));
573 32 hv_stores(hv, "mmap_size", newSVuv((UV)h->mmap_size));
574 32 hv_stores(hv, "frozen", newSVuv(h->hdr->sealed ? 1 : 0));
575 32 hv_stores(hv, "readonly", newSVuv(h->readonly ? 1 : 0));
576 32 RETVAL = newRV_noinc((SV *)hv);
577 }
578 OUTPUT:
579 RETVAL
580  
581 SV *
582 path(self)
583 SV *self
584 PREINIT:
585 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
586 CODE:
587 4 ▶ 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 2 4
588 OUTPUT:
589 RETVAL
590  
591 int
592 memfd(self)
593 SV *self
594 PREINIT:
595 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
596 CODE:
597 4 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 4 4
598 OUTPUT:
599 RETVAL
600  
601 void
602 sync(self)
603 SV *self
604 PREINIT:
605 3 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 3 0 3
EXTRACT(self); 0 3 3
EXTRACT(self); 0 3 3
606 CODE:
607 3 ▶ if (!h->readonly && rb_msync(h) != 0) croak("sync: %s", strerror(errno));
Branch: 2 branches
BranchTrueFalseTotal
if (!h->readonly && rb_msync(h) != 0) croak("sync: %s", strerror(errno)); 2 1 3
if (!h->readonly && rb_msync(h) != 0) croak("sync: %s", strerror(errno)); 0 2 2
608  
609 void
610 unlink(self, ...)
611 SV *self
612 CODE:
613 3 ▶ if (sv_isobject(self) && sv_derived_from(self, "Data::RoaringBitmap::Shared")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self) && sv_derived_from(self, "Data::RoaringBitmap::Shared")) { 1 1 2
if (sv_isobject(self) && sv_derived_from(self, "Data::RoaringBitmap::Shared")) { 1 0 1
614 1 RbHandle *h = INT2PTR(RbHandle*, SvIV(SvRV(self)));
615 1 ▶ if (h && h->path && unlink(h->path) != 0 && errno != ENOENT)
Branch: 4 branches
BranchTrueFalseTotal
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 1 0 1
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 1 0 1
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 1 1
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
616 0 croak("Data::RoaringBitmap::Shared->unlink(%s): %s", h->path, strerror(errno));
617 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
618 {
619 1 const char *up = SvPV_nolen(ST(1));
620 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
621 0 croak("Data::RoaringBitmap::Shared->unlink(%s): %s", up, strerror(errno));
622 }
623 }
« roaring.h ↑ Summary