| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| #include "bitset.h" |
| 7 |
|
| |
| 8 |
|
| #define EXTRACT_BS(sv) \ |
| 9 |
|
| if (!sv_isobject(sv) || !sv_derived_from(sv, "Data::BitSet::Shared")) \ |
| 10 |
|
| croak("Expected a Data::BitSet::Shared object"); \ |
| 11 |
|
| BsHandle *h = INT2PTR(BsHandle*, SvIV(SvRV(sv))); \ |
| 12 |
|
| if (!h) croak("Attempted to use a destroyed Data::BitSet::Shared object"); \ |
| 13 |
|
| BsHandle *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. EXTRACT_BS's |
| 17 |
|
| * sv_2mortal(SvREFCNT_inc(...)) pin only blocks REFCOUNT-driven destruction; |
| 18 |
|
| * an explicit $obj->DESTROY frees the handle regardless and zeroes the IV. |
| 19 |
|
| * The same Perl can also REPLACE the invocant ($obj = 42 mutates ST(0), |
| 20 |
|
| * because Perl passes aliases), hence the SvROK re-check. |
| 21 |
|
| * |
| 22 |
|
| * No instance method needs it today: every index/value argument is a plain |
| 23 |
|
| * typemap UV, which xsubpp converts in INPUT, BEFORE PREINIT's EXTRACT_BS |
| 24 |
|
| * runs. It is defined for the method that eventually converts an SV after |
| 25 |
|
| * extracting the handle. */ |
| 26 |
|
| #define REEXTRACT_BS(sv) \ |
| 27 |
|
| if (!SvROK(sv)) \ |
| 28 |
|
| croak("Data::BitSet::Shared object was replaced during the call"); \ |
| 29 |
|
| h = INT2PTR(BsHandle*, SvIV(SvRV(sv))); \ |
| 30 |
|
| if (h != h0) croak("Data::BitSet::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 |
|
| #define CHECK_BIT(h, bit) \ |
| 39 |
|
| if ((UV)(bit) >= (h)->hdr->capacity) \ |
| 40 |
|
| croak("bit %" UVuf " out of range (capacity %" UVuf ")", (UV)(bit), (UV)(h)->hdr->capacity) |
| 41 |
|
| |
| 42 |
|
| MODULE = Data::BitSet::Shared PACKAGE = Data::BitSet::Shared |
| 43 |
|
| |
| 44 |
|
| PROTOTYPES: DISABLE |
| 45 |
|
| |
| 46 |
|
| SV * |
| 47 |
|
| new(class, path, capacity, ...) |
| 48 |
|
| const char *class |
| 49 |
|
| SV *path |
| 50 |
|
| UV capacity |
| 51 |
|
| PREINIT: |
| 52 |
|
| char errbuf[BS_ERR_BUFLEN]; |
| 53 |
|
| CODE: |
| 54 |
29 |
▶ | mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; |
Branch: 4 branches
| Branch | True | False | Total |
| mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; |
0 |
29 |
29 |
| 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 |
|
| 55 |
43 |
▶ | const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
0 |
29 |
29 |
| 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; |
14 |
15 |
29 |
|
| 56 |
29 |
| BsHandle *h = bs_create(p, capacity, mode, errbuf); |
| 57 |
29 |
▶ | if (!h) croak("Data::BitSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::BitSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
4 |
25 |
29 |
| if (!h) croak("Data::BitSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
4 |
0 |
4 |
|
| 58 |
|
| /* Re-read the class PV at the point of use: xsubpp captured it in INPUT, |
| 59 |
|
| * before the argument magic above ran, and that magic can realloc/free |
| 60 |
|
| * the PV, leaving MAKE_OBJ to bless into a stale (or reused) buffer. |
| 61 |
|
| * SvPV_nolen, not SvPV_nomg: an overloaded class must re-stringify. */ |
| 62 |
25 |
| class = SvPV_nolen(ST(0)); |
| 63 |
25 |
| MAKE_OBJ(class, h); |
| 64 |
|
| OUTPUT: |
| 65 |
|
| RETVAL |
| 66 |
|
| |
| 67 |
|
| SV * |
| 68 |
|
| new_memfd(class, name, capacity) |
| 69 |
|
| const char *class |
| 70 |
|
| SV *name |
| 71 |
|
| UV capacity |
| 72 |
|
| PREINIT: |
| 73 |
|
| char errbuf[BS_ERR_BUFLEN]; |
| 74 |
|
| CODE: |
| 75 |
|
| /* Take the name as SV and capture its PV here, AFTER xsubpp's INPUT |
| 76 |
|
| * conversion of capacity has run: a T_PV name is captured during INPUT, |
| 77 |
|
| * i.e. before SvUV(ST(2)) get-magic, which could realloc/free that PV. */ |
| 78 |
14 |
▶ | const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; |
0 |
7 |
7 |
| const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; |
0 |
0 |
0 |
| const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; |
7 |
0 |
7 |
|
| 79 |
7 |
| BsHandle *h = bs_create_memfd(nm, capacity, errbuf); |
| 80 |
7 |
▶ | if (!h) croak("Data::BitSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::BitSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
0 |
7 |
7 |
| if (!h) croak("Data::BitSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
0 |
0 |
0 |
|
| 81 |
|
| /* Re-read the class PV at the point of use (see new() above): capacity's |
| 82 |
|
| * INPUT conversion and the name magic both ran after xsubpp captured |
| 83 |
|
| * class. */ |
| 84 |
7 |
| class = SvPV_nolen(ST(0)); |
| 85 |
7 |
| 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[BS_ERR_BUFLEN]; |
| 95 |
|
| CODE: |
| 96 |
2 |
| BsHandle *h = bs_open_fd(fd, errbuf); |
| 97 |
2 |
▶ | if (!h) croak("Data::BitSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::BitSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
1 |
2 |
| if (!h) croak("Data::BitSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
0 |
1 |
|
| 98 |
|
| /* Re-read the class PV at the point of use (see new() above): fd's INPUT |
| 99 |
|
| * conversion ran get-magic after xsubpp captured class. */ |
| 100 |
1 |
| class = SvPV_nolen(ST(0)); |
| 101 |
1 |
| 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[BS_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 |
11 |
▶ | const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
0 |
6 |
6 |
| 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; |
5 |
1 |
6 |
|
| 118 |
6 |
▶ | if (!p) croak("Data::BitSet::Shared->new_readonly: path is required"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p) croak("Data::BitSet::Shared->new_readonly: path is required"); |
1 |
5 |
6 |
|
| 119 |
5 |
| BsHandle *h = bs_open_readonly(p, errbuf); |
| 120 |
5 |
▶ | if (!h) croak("Data::BitSet::Shared->new_readonly: %s", errbuf); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h) croak("Data::BitSet::Shared->new_readonly: %s", errbuf); |
2 |
3 |
5 |
|
| 121 |
|
| /* Re-read the class PV at the point of use (see new() above): path's |
| 122 |
|
| * get-magic above could have run Perl code that reallocs/frees it. |
| 123 |
|
| * BitSet has no REREAD_CLASS macro -- inlined here as elsewhere in this file. */ |
| 124 |
3 |
| class = SvPV_nolen(ST(0)); |
| 125 |
3 |
| MAKE_OBJ(class, h); |
| 126 |
|
| OUTPUT: |
| 127 |
|
| RETVAL |
| 128 |
|
| |
| 129 |
|
| void |
| 130 |
|
| DESTROY(self) |
| 131 |
|
| SV *self |
| 132 |
|
| CODE: |
| 133 |
37 |
▶ | if (!sv_isobject(self) || !sv_derived_from(self, "Data::BitSet::Shared")) return; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv_isobject(self) || !sv_derived_from(self, "Data::BitSet::Shared")) return; |
37 |
0 |
37 |
| if (!sv_isobject(self) || !sv_derived_from(self, "Data::BitSet::Shared")) return; |
0 |
37 |
37 |
|
| 134 |
37 |
| BsHandle *h = INT2PTR(BsHandle*, SvIV(SvRV(self))); |
| 135 |
37 |
▶ | if (!h) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h) return; |
1 |
36 |
37 |
|
| 136 |
36 |
| sv_setiv(SvRV(self), 0); |
| 137 |
36 |
| bs_destroy(h); |
| 138 |
|
| |
| 139 |
|
| IV |
| 140 |
|
| test(self, bit) |
| 141 |
|
| SV *self |
| 142 |
|
| UV bit |
| 143 |
|
| PREINIT: |
| 144 |
26 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
26 |
0 |
26 |
| EXTRACT_BS(self); |
0 |
26 |
26 |
| EXTRACT_BS(self); |
0 |
26 |
26 |
|
| 145 |
|
| CODE: |
| 146 |
26 |
▶ | CHECK_BIT(h, bit); |
Branch: 1 branch
| Branch | True | False | Total |
| CHECK_BIT(h, bit); |
1 |
25 |
26 |
|
| 147 |
25 |
▶ | RETVAL = bs_test(h, bit); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bs_test(h, bit); |
4 |
21 |
25 |
|
| 148 |
|
| OUTPUT: |
| 149 |
|
| RETVAL |
| 150 |
|
| |
| 151 |
|
| IV |
| 152 |
|
| set(self, bit) |
| 153 |
|
| SV *self |
| 154 |
|
| UV bit |
| 155 |
|
| PREINIT: |
| 156 |
9703 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
9703 |
0 |
9703 |
| EXTRACT_BS(self); |
0 |
9703 |
9703 |
| EXTRACT_BS(self); |
0 |
9703 |
9703 |
|
| 157 |
|
| CODE: |
| 158 |
9703 |
▶ | if (h->readonly) croak("Data::BitSet::Shared->set: bitset is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::BitSet::Shared->set: bitset is frozen (read-only)"); |
3 |
9700 |
9703 |
|
| 159 |
9700 |
▶ | CHECK_BIT(h, bit); |
Branch: 1 branch
| Branch | True | False | Total |
| CHECK_BIT(h, bit); |
2 |
9698 |
9700 |
|
| 160 |
|
| /* Re-check the live shared header immediately before the CAS: BitSet has no |
| 161 |
|
| * rwlock to serialize against a PEER process calling ->freeze between our |
| 162 |
|
| * readonly check and this write, so this atomic load is the closest |
| 163 |
|
| * available analog to the rest of the family's post-wrlock sealed re-check. */ |
| 164 |
9698 |
▶ | if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
0 |
9698 |
9698 |
|
| 165 |
0 |
| croak("Data::BitSet::Shared->set: bitset is frozen (read-only)"); |
| 166 |
9698 |
▶ | RETVAL = bs_set(h, bit); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bs_set(h, bit); |
9665 |
33 |
9698 |
|
| 167 |
|
| OUTPUT: |
| 168 |
|
| RETVAL |
| 169 |
|
| |
| 170 |
|
| IV |
| 171 |
|
| clear(self, bit) |
| 172 |
|
| SV *self |
| 173 |
|
| UV bit |
| 174 |
|
| PREINIT: |
| 175 |
8 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
8 |
0 |
8 |
| EXTRACT_BS(self); |
0 |
8 |
8 |
| EXTRACT_BS(self); |
0 |
8 |
8 |
|
| 176 |
|
| CODE: |
| 177 |
8 |
▶ | if (h->readonly) croak("Data::BitSet::Shared->clear: bitset is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::BitSet::Shared->clear: bitset is frozen (read-only)"); |
2 |
6 |
8 |
|
| 178 |
6 |
▶ | CHECK_BIT(h, bit); |
Branch: 1 branch
| Branch | True | False | Total |
| CHECK_BIT(h, bit); |
0 |
6 |
6 |
|
| 179 |
6 |
▶ | if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
0 |
6 |
6 |
|
| 180 |
0 |
| croak("Data::BitSet::Shared->clear: bitset is frozen (read-only)"); |
| 181 |
6 |
▶ | RETVAL = bs_clear(h, bit); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bs_clear(h, bit); |
1 |
5 |
6 |
|
| 182 |
|
| OUTPUT: |
| 183 |
|
| RETVAL |
| 184 |
|
| |
| 185 |
|
| IV |
| 186 |
|
| toggle(self, bit) |
| 187 |
|
| SV *self |
| 188 |
|
| UV bit |
| 189 |
|
| PREINIT: |
| 190 |
4 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
4 |
0 |
4 |
| EXTRACT_BS(self); |
0 |
4 |
4 |
| EXTRACT_BS(self); |
0 |
4 |
4 |
|
| 191 |
|
| CODE: |
| 192 |
4 |
▶ | if (h->readonly) croak("Data::BitSet::Shared->toggle: bitset is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::BitSet::Shared->toggle: bitset is frozen (read-only)"); |
2 |
2 |
4 |
|
| 193 |
2 |
▶ | CHECK_BIT(h, bit); |
Branch: 1 branch
| Branch | True | False | Total |
| CHECK_BIT(h, bit); |
0 |
2 |
2 |
|
| 194 |
2 |
▶ | if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
0 |
2 |
2 |
|
| 195 |
0 |
| croak("Data::BitSet::Shared->toggle: bitset is frozen (read-only)"); |
| 196 |
2 |
▶ | RETVAL = bs_toggle(h, bit); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bs_toggle(h, bit); |
0 |
2 |
2 |
|
| 197 |
|
| OUTPUT: |
| 198 |
|
| RETVAL |
| 199 |
|
| |
| 200 |
|
| UV |
| 201 |
|
| count(self) |
| 202 |
|
| SV *self |
| 203 |
|
| PREINIT: |
| 204 |
32 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
32 |
0 |
32 |
| EXTRACT_BS(self); |
0 |
32 |
32 |
| EXTRACT_BS(self); |
0 |
32 |
32 |
|
| 205 |
|
| CODE: |
| 206 |
32 |
| RETVAL = (UV)bs_count(h); |
| 207 |
|
| OUTPUT: |
| 208 |
|
| RETVAL |
| 209 |
|
| |
| 210 |
|
| UV |
| 211 |
|
| capacity(self) |
| 212 |
|
| SV *self |
| 213 |
|
| PREINIT: |
| 214 |
3 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
3 |
0 |
3 |
| EXTRACT_BS(self); |
0 |
3 |
3 |
| EXTRACT_BS(self); |
0 |
3 |
3 |
|
| 215 |
|
| CODE: |
| 216 |
3 |
▶ | RETVAL = (UV)h->hdr->capacity; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)h->hdr->capacity; |
0 |
3 |
3 |
|
| 217 |
|
| OUTPUT: |
| 218 |
|
| RETVAL |
| 219 |
|
| |
| 220 |
|
| IV |
| 221 |
|
| any(self) |
| 222 |
|
| SV *self |
| 223 |
|
| PREINIT: |
| 224 |
6 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
6 |
0 |
6 |
| EXTRACT_BS(self); |
0 |
6 |
6 |
| EXTRACT_BS(self); |
0 |
6 |
6 |
|
| 225 |
|
| CODE: |
| 226 |
6 |
▶ | RETVAL = bs_any(h); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bs_any(h); |
0 |
6 |
6 |
|
| 227 |
|
| OUTPUT: |
| 228 |
|
| RETVAL |
| 229 |
|
| |
| 230 |
|
| IV |
| 231 |
|
| none(self) |
| 232 |
|
| SV *self |
| 233 |
|
| PREINIT: |
| 234 |
5 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
5 |
0 |
5 |
| EXTRACT_BS(self); |
0 |
5 |
5 |
| EXTRACT_BS(self); |
0 |
5 |
5 |
|
| 235 |
|
| CODE: |
| 236 |
5 |
▶ | RETVAL = bs_none(h); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = bs_none(h); |
0 |
5 |
5 |
|
| 237 |
|
| OUTPUT: |
| 238 |
|
| RETVAL |
| 239 |
|
| |
| 240 |
|
| void |
| 241 |
|
| fill(self) |
| 242 |
|
| SV *self |
| 243 |
|
| PREINIT: |
| 244 |
14 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
14 |
0 |
14 |
| EXTRACT_BS(self); |
0 |
14 |
14 |
| EXTRACT_BS(self); |
0 |
14 |
14 |
|
| 245 |
|
| CODE: |
| 246 |
14 |
▶ | if (h->readonly) croak("Data::BitSet::Shared->fill: bitset is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::BitSet::Shared->fill: bitset is frozen (read-only)"); |
2 |
12 |
14 |
|
| 247 |
12 |
▶ | if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
0 |
12 |
12 |
|
| 248 |
0 |
| croak("Data::BitSet::Shared->fill: bitset is frozen (read-only)"); |
| 249 |
12 |
| bs_fill(h); |
| 250 |
|
| |
| 251 |
|
| void |
| 252 |
|
| zero(self) |
| 253 |
|
| SV *self |
| 254 |
|
| PREINIT: |
| 255 |
6 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
6 |
0 |
6 |
| EXTRACT_BS(self); |
0 |
6 |
6 |
| EXTRACT_BS(self); |
0 |
6 |
6 |
|
| 256 |
|
| CODE: |
| 257 |
6 |
▶ | if (h->readonly) croak("Data::BitSet::Shared->zero: bitset is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::BitSet::Shared->zero: bitset is frozen (read-only)"); |
2 |
4 |
6 |
|
| 258 |
4 |
▶ | if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE)) |
0 |
4 |
4 |
|
| 259 |
0 |
| croak("Data::BitSet::Shared->zero: bitset is frozen (read-only)"); |
| 260 |
4 |
| bs_zero(h); |
| 261 |
|
| |
| 262 |
|
| void |
| 263 |
|
| freeze(self) |
| 264 |
|
| SV *self |
| 265 |
|
| PREINIT: |
| 266 |
13 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
13 |
0 |
13 |
| EXTRACT_BS(self); |
0 |
13 |
13 |
| EXTRACT_BS(self); |
0 |
13 |
13 |
|
| 267 |
|
| CODE: |
| 268 |
13 |
▶ | if (h->readonly) croak("Data::BitSet::Shared->freeze: cannot freeze a read-only handle"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::BitSet::Shared->freeze: cannot freeze a read-only handle"); |
2 |
11 |
13 |
|
| 269 |
11 |
▶ | if (bs_freeze(h) != 0) croak("Data::BitSet::Shared->freeze: msync: %s", strerror(errno)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (bs_freeze(h) != 0) croak("Data::BitSet::Shared->freeze: msync: %s", strerror(errno)); |
0 |
11 |
11 |
|
| 270 |
11 |
| h->readonly = 1; /* this handle now rejects mutation too (the file is sealed) */ |
| 271 |
|
| |
| 272 |
|
| UV |
| 273 |
|
| frozen(self) |
| 274 |
|
| SV *self |
| 275 |
|
| PREINIT: |
| 276 |
4 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
4 |
0 |
4 |
| EXTRACT_BS(self); |
0 |
4 |
4 |
| EXTRACT_BS(self); |
0 |
4 |
4 |
|
| 277 |
|
| CODE: |
| 278 |
4 |
▶ | RETVAL = __atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = __atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0; |
0 |
4 |
4 |
|
| 279 |
|
| OUTPUT: |
| 280 |
|
| RETVAL |
| 281 |
|
| |
| 282 |
|
| UV |
| 283 |
|
| readonly(self) |
| 284 |
|
| SV *self |
| 285 |
|
| PREINIT: |
| 286 |
4 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
4 |
0 |
4 |
| EXTRACT_BS(self); |
0 |
4 |
4 |
| EXTRACT_BS(self); |
0 |
4 |
4 |
|
| 287 |
|
| CODE: |
| 288 |
4 |
▶ | RETVAL = h->readonly ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->readonly ? 1 : 0; |
0 |
4 |
4 |
|
| 289 |
|
| OUTPUT: |
| 290 |
|
| RETVAL |
| 291 |
|
| |
| 292 |
|
| SV * |
| 293 |
|
| first_set(self) |
| 294 |
|
| SV *self |
| 295 |
|
| PREINIT: |
| 296 |
5 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
5 |
0 |
5 |
| EXTRACT_BS(self); |
0 |
5 |
5 |
| EXTRACT_BS(self); |
0 |
5 |
5 |
|
| 297 |
|
| CODE: |
| 298 |
5 |
| int64_t r = bs_first_set(h); |
| 299 |
5 |
▶ | RETVAL = (r >= 0) ? newSViv((IV)r) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (r >= 0) ? newSViv((IV)r) : &PL_sv_undef; |
4 |
1 |
5 |
|
| 300 |
|
| OUTPUT: |
| 301 |
|
| RETVAL |
| 302 |
|
| |
| 303 |
|
| SV * |
| 304 |
|
| first_clear(self) |
| 305 |
|
| SV *self |
| 306 |
|
| PREINIT: |
| 307 |
5 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
5 |
0 |
5 |
| EXTRACT_BS(self); |
0 |
5 |
5 |
| EXTRACT_BS(self); |
0 |
5 |
5 |
|
| 308 |
|
| CODE: |
| 309 |
5 |
| int64_t r = bs_first_clear(h); |
| 310 |
5 |
▶ | RETVAL = (r >= 0) ? newSViv((IV)r) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (r >= 0) ? newSViv((IV)r) : &PL_sv_undef; |
3 |
2 |
5 |
|
| 311 |
|
| OUTPUT: |
| 312 |
|
| RETVAL |
| 313 |
|
| |
| 314 |
|
| void |
| 315 |
|
| _set_bits(self, ...) |
| 316 |
|
| SV *self |
| 317 |
|
| PREINIT: |
| 318 |
75 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
75 |
0 |
75 |
| EXTRACT_BS(self); |
0 |
75 |
75 |
| EXTRACT_BS(self); |
1 |
74 |
75 |
|
| 319 |
|
| PPCODE: |
| 320 |
74 |
| I32 context = GIMME_V; |
| 321 |
74 |
| uint32_t nw = h->hdr->num_words; |
| 322 |
74 |
| uint32_t mw = bs_max_words(h); |
| 323 |
74 |
▶ | if (nw > mw) nw = mw; |
Branch: 1 branch
| Branch | True | False | Total |
| if (nw > mw) nw = mw; |
0 |
74 |
74 |
|
| 324 |
74 |
| uint64_t cap = h->hdr->capacity; |
| 325 |
74 |
| UV count = 0; |
| 326 |
8506 |
▶ | for (uint32_t i = 0; i < nw; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (uint32_t i = 0; i < nw; i++) { |
8432 |
74 |
8506 |
|
| 327 |
8432 |
| uint64_t word = __atomic_load_n(&h->data[i], __ATOMIC_ACQUIRE); |
| 328 |
8432 |
▶ | if (i == nw - 1 && cap % 64) |
Branch: 2 branches
| Branch | True | False | Total |
| if (i == nw - 1 && cap % 64) |
74 |
8358 |
8432 |
| if (i == nw - 1 && cap % 64) |
48 |
26 |
74 |
|
| 329 |
48 |
| word &= ((uint64_t)1 << (cap % 64)) - 1; |
| 330 |
8432 |
▶ | if (context == G_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (context == G_ARRAY) { |
4220 |
4212 |
8432 |
|
| 331 |
4220 |
▶ | EXTEND(SP, bs_popcount(word)); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, bs_popcount(word)); |
4220 |
0 |
4220 |
| EXTEND(SP, bs_popcount(word)); |
0 |
4220 |
4220 |
|
| 332 |
148106 |
▶ | while (word) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (word) { |
143886 |
4220 |
148106 |
|
| 333 |
143886 |
| mPUSHu((UV)i * 64 + __builtin_ctzll(word)); |
| 334 |
143886 |
| word &= word - 1; |
| 335 |
|
| } |
| 336 |
|
| } else { |
| 337 |
4212 |
| count += (UV)bs_popcount(word); |
| 338 |
|
| } |
| 339 |
|
| } |
| 340 |
74 |
▶ | if (context == G_SCALAR) mXPUSHu(count); |
Branch: 2 branches
| Branch | True | False | Total |
| if (context == G_SCALAR) mXPUSHu(count); |
27 |
47 |
74 |
| if (context == G_SCALAR) mXPUSHu(count); |
0 |
27 |
27 |
|
| 341 |
|
| |
| 342 |
|
| SV * |
| 343 |
|
| path(self) |
| 344 |
|
| SV *self |
| 345 |
|
| PREINIT: |
| 346 |
2 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
2 |
0 |
2 |
| EXTRACT_BS(self); |
0 |
2 |
2 |
| EXTRACT_BS(self); |
0 |
2 |
2 |
|
| 347 |
|
| CODE: |
| 348 |
2 |
▶ | RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; |
2 |
0 |
2 |
|
| 349 |
|
| OUTPUT: |
| 350 |
|
| RETVAL |
| 351 |
|
| |
| 352 |
|
| IV |
| 353 |
|
| memfd(self) |
| 354 |
|
| SV *self |
| 355 |
|
| PREINIT: |
| 356 |
2 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
2 |
0 |
2 |
| EXTRACT_BS(self); |
0 |
2 |
2 |
| EXTRACT_BS(self); |
0 |
2 |
2 |
|
| 357 |
|
| CODE: |
| 358 |
2 |
▶ | RETVAL = h->backing_fd; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->backing_fd; |
0 |
2 |
2 |
|
| 359 |
|
| OUTPUT: |
| 360 |
|
| RETVAL |
| 361 |
|
| |
| 362 |
|
| void |
| 363 |
|
| sync(self) |
| 364 |
|
| SV *self |
| 365 |
|
| PREINIT: |
| 366 |
1 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
1 |
0 |
1 |
| EXTRACT_BS(self); |
0 |
1 |
1 |
| EXTRACT_BS(self); |
0 |
1 |
1 |
|
| 367 |
|
| CODE: |
| 368 |
1 |
▶ | if (!h->readonly && bs_msync(h) != 0) croak("msync: %s", strerror(errno)); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h->readonly && bs_msync(h) != 0) croak("msync: %s", strerror(errno)); |
0 |
1 |
1 |
| if (!h->readonly && bs_msync(h) != 0) croak("msync: %s", strerror(errno)); |
0 |
0 |
0 |
|
| 369 |
|
| |
| 370 |
|
| void |
| 371 |
|
| unlink(self_or_class, ...) |
| 372 |
|
| SV *self_or_class |
| 373 |
|
| CODE: |
| 374 |
|
| const char *p; |
| 375 |
0 |
▶ | if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::BitSet::Shared")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::BitSet::Shared")) { |
0 |
0 |
0 |
| if (sv_isobject(self_or_class) && sv_derived_from(self_or_class, "Data::BitSet::Shared")) { |
0 |
0 |
0 |
|
| 376 |
0 |
| BsHandle *h = INT2PTR(BsHandle*, SvIV(SvRV(self_or_class))); |
| 377 |
0 |
▶ | if (!h) croak("Attempted to use a destroyed object"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h) croak("Attempted to use a destroyed object"); |
0 |
0 |
0 |
|
| 378 |
0 |
| p = h->path; |
| 379 |
|
| } else { |
| 380 |
0 |
▶ | if (items < 2) croak("Usage: ...->unlink($path)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (items < 2) croak("Usage: ...->unlink($path)"); |
0 |
0 |
0 |
|
| 381 |
0 |
| p = SvPV_nolen(ST(1)); |
| 382 |
|
| } |
| 383 |
0 |
▶ | if (!p) croak("cannot unlink anonymous or memfd object"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p) croak("cannot unlink anonymous or memfd object"); |
0 |
0 |
0 |
|
| 384 |
0 |
▶ | if (unlink(p) != 0 && errno != ENOENT) croak("unlink(%s): %s", p, strerror(errno)); |
Branch: 2 branches
| Branch | True | False | Total |
| if (unlink(p) != 0 && errno != ENOENT) croak("unlink(%s): %s", p, strerror(errno)); |
0 |
0 |
0 |
| if (unlink(p) != 0 && errno != ENOENT) croak("unlink(%s): %s", p, strerror(errno)); |
0 |
0 |
0 |
|
| 385 |
|
| |
| 386 |
|
| SV * |
| 387 |
|
| stats(self) |
| 388 |
|
| SV *self |
| 389 |
|
| PREINIT: |
| 390 |
2 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
2 |
0 |
2 |
| EXTRACT_BS(self); |
0 |
2 |
2 |
| EXTRACT_BS(self); |
0 |
2 |
2 |
|
| 391 |
|
| CODE: |
| 392 |
2 |
| HV *hv = newHV(); |
| 393 |
2 |
| hv_store(hv, "capacity", 8, newSVuv((UV)h->hdr->capacity), 0); |
| 394 |
2 |
| hv_store(hv, "count", 5, newSVuv((UV)bs_count(h)), 0); |
| 395 |
2 |
| hv_store(hv, "sets", 4, newSVuv((UV)__atomic_load_n(&h->hdr->stat_sets, __ATOMIC_RELAXED)), 0); |
| 396 |
2 |
| hv_store(hv, "clears", 6, newSVuv((UV)__atomic_load_n(&h->hdr->stat_clears, __ATOMIC_RELAXED)), 0); |
| 397 |
2 |
| hv_store(hv, "toggles", 7, newSVuv((UV)__atomic_load_n(&h->hdr->stat_toggles, __ATOMIC_RELAXED)), 0); |
| 398 |
2 |
| hv_store(hv, "mmap_size", 9, newSVuv((UV)h->mmap_size), 0); |
| 399 |
2 |
| hv_store(hv, "frozen", 6, newSVuv(__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0), 0); |
| 400 |
2 |
| hv_store(hv, "readonly", 8, newSVuv(h->readonly ? 1 : 0), 0); |
| 401 |
2 |
| RETVAL = newRV_noinc((SV *)hv); |
| 402 |
|
| OUTPUT: |
| 403 |
|
| RETVAL |
| 404 |
|
| |
| 405 |
|
| SV * |
| 406 |
|
| to_string(self, ...) |
| 407 |
|
| SV *self |
| 408 |
|
| PREINIT: |
| 409 |
6 |
▶ | EXTRACT_BS(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT_BS(self); |
6 |
0 |
6 |
| EXTRACT_BS(self); |
0 |
6 |
6 |
| EXTRACT_BS(self); |
0 |
6 |
6 |
|
| 410 |
|
| CODE: |
| 411 |
6 |
| uint32_t mw = bs_max_words(h); |
| 412 |
6 |
| uint64_t cap = h->hdr->capacity; |
| 413 |
6 |
| uint32_t nw = h->hdr->num_words; |
| 414 |
6 |
▶ | if (nw > mw) nw = mw; /* bound word loop against mapping */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (nw > mw) nw = mw; /* bound word loop against mapping */ |
0 |
6 |
6 |
|
| 415 |
6 |
▶ | if (cap > (uint64_t)nw * 64) cap = (uint64_t)nw * 64; /* bound alloc/length against mapping */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (cap > (uint64_t)nw * 64) cap = (uint64_t)nw * 64; /* bound alloc/length against mapping */ |
0 |
6 |
6 |
|
| 416 |
|
| char *buf; |
| 417 |
6 |
| Newx(buf, cap + 1, char); |
| 418 |
6 |
| SAVEFREEPV(buf); /* freed on scope exit, incl. a croak from newSVpvn (OOM) */ |
| 419 |
6 |
| uint64_t idx = 0; |
| 420 |
30 |
▶ | for (uint32_t w = 0; w < nw && idx < cap; w++) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (uint32_t w = 0; w < nw && idx < cap; w++) { |
24 |
6 |
30 |
| for (uint32_t w = 0; w < nw && idx < cap; w++) { |
24 |
0 |
24 |
|
| 421 |
24 |
| uint64_t word = __atomic_load_n(&h->data[w], __ATOMIC_RELAXED); |
| 422 |
1560 |
▶ | for (int b = 0; b < 64 && idx < cap; b++, idx++) |
Branch: 2 branches
| Branch | True | False | Total |
| for (int b = 0; b < 64 && idx < cap; b++, idx++) |
1536 |
24 |
1560 |
| for (int b = 0; b < 64 && idx < cap; b++, idx++) |
1536 |
0 |
1536 |
|
| 423 |
1536 |
▶ | buf[idx] = (word >> b) & 1 ? '1' : '0'; |
Branch: 1 branch
| Branch | True | False | Total |
| buf[idx] = (word >> b) & 1 ? '1' : '0'; |
22 |
1514 |
1536 |
|
| 424 |
|
| } |
| 425 |
6 |
| buf[cap] = '\0'; |
| 426 |
6 |
| RETVAL = newSVpvn(buf, cap); |
| 427 |
|
| OUTPUT: |
| 428 |
|
| RETVAL |