| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| #include "radix.h" |
| 7 |
|
| |
| 8 |
|
| #define EXTRACT(sv) \ |
| 9 |
|
| if (!sv_isobject(sv) || !sv_derived_from(sv, "Data::RadixTree::Shared")) \ |
| 10 |
|
| croak("Expected a Data::RadixTree::Shared object"); \ |
| 11 |
|
| RdxHandle *h = INT2PTR(RdxHandle*, SvIV(SvRV(sv))); \ |
| 12 |
|
| if (!h) croak("Attempted to use a destroyed Data::RadixTree::Shared object"); \ |
| 13 |
|
| RdxHandle *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::RadixTree::Shared object was replaced during the call"); \ |
| 25 |
|
| h = INT2PTR(RdxHandle*, SvIV(SvRV(sv))); \ |
| 26 |
|
| if (h != h0) croak("Data::RadixTree::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 |
|
| MODULE = Data::RadixTree::Shared PACKAGE = Data::RadixTree::Shared |
| 35 |
|
| |
| 36 |
|
| PROTOTYPES: DISABLE |
| 37 |
|
| |
| 38 |
|
| SV * |
| 39 |
|
| new(class, path = &PL_sv_undef, node_capacity = 4096, arena_capacity = 65536, ...) |
| 40 |
|
| const char *class |
| 41 |
|
| SV *path |
| 42 |
|
| UV node_capacity |
| 43 |
|
| UV arena_capacity |
| 44 |
|
| PREINIT: |
| 45 |
|
| char errbuf[RDX_ERR_BUFLEN]; |
| 46 |
|
| CODE: |
| 47 |
|
| /* Optional 5th arg: file mode for a newly-created file-backed segment |
| 48 |
|
| * (default 0600, owner-only). Pass e.g. 0660 to opt into cross-user |
| 49 |
|
| * sharing. Ignored for anonymous/existing segments. */ |
| 50 |
39 |
▶ | mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; |
Branch: 4 branches
| Branch | True | False | Total |
| mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; |
0 |
39 |
39 |
| mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; |
0 |
0 |
0 |
| mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; |
0 |
0 |
0 |
| mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; |
0 |
0 |
0 |
|
| 51 |
|
| /* Capture the path PV only AFTER get-magic on the later optional args |
| 52 |
|
| * above has run: SvGETMAGIC(ST(4)) may realloc/free the PV that |
| 53 |
|
| * SvPV_nolen(path) returns, so the capture must stay last. */ |
| 54 |
57 |
▶ | 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 |
39 |
39 |
| 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; |
18 |
21 |
39 |
|
| 55 |
39 |
| RdxHandle *h = rdx_create(p, (uint64_t)node_capacity, (uint64_t)arena_capacity, mode, errbuf); /* validates args into errbuf */ |
| 56 |
39 |
▶ | if (!h) croak("Data::RadixTree::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::RadixTree::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
9 |
30 |
39 |
| if (!h) croak("Data::RadixTree::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
9 |
0 |
9 |
|
| 57 |
30 |
| MAKE_OBJ(class, h); |
| 58 |
|
| OUTPUT: |
| 59 |
|
| RETVAL |
| 60 |
|
| |
| 61 |
|
| SV * |
| 62 |
|
| new_memfd(class, name = &PL_sv_undef, node_capacity = 4096, arena_capacity = 65536) |
| 63 |
|
| const char *class |
| 64 |
|
| SV *name |
| 65 |
|
| UV node_capacity |
| 66 |
|
| UV arena_capacity |
| 67 |
|
| PREINIT: |
| 68 |
|
| char errbuf[RDX_ERR_BUFLEN]; |
| 69 |
|
| CODE: |
| 70 |
5 |
▶ | const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; /* undef -> default label */ |
Branch: 3 branches
| Branch | True | False | Total |
| 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 |
|
| 71 |
3 |
| RdxHandle *h = rdx_create_memfd(nm, (uint64_t)node_capacity, (uint64_t)arena_capacity, errbuf); /* validates args into errbuf */ |
| 72 |
3 |
▶ | if (!h) croak("Data::RadixTree::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::RadixTree::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
2 |
3 |
| if (!h) croak("Data::RadixTree::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
0 |
1 |
|
| 73 |
2 |
| MAKE_OBJ(class, h); |
| 74 |
|
| OUTPUT: |
| 75 |
|
| RETVAL |
| 76 |
|
| |
| 77 |
|
| SV * |
| 78 |
|
| new_from_fd(class, fd) |
| 79 |
|
| const char *class |
| 80 |
|
| int fd |
| 81 |
|
| PREINIT: |
| 82 |
|
| char errbuf[RDX_ERR_BUFLEN]; |
| 83 |
|
| CODE: |
| 84 |
2 |
| RdxHandle *h = rdx_open_fd(fd, errbuf); |
| 85 |
2 |
▶ | if (!h) croak("Data::RadixTree::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::RadixTree::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
1 |
2 |
| if (!h) croak("Data::RadixTree::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
0 |
1 |
|
| 86 |
1 |
| MAKE_OBJ(class, h); |
| 87 |
|
| OUTPUT: |
| 88 |
|
| RETVAL |
| 89 |
|
| |
| 90 |
|
| SV * |
| 91 |
|
| new_readonly(class, path) |
| 92 |
|
| const char *class |
| 93 |
|
| SV *path |
| 94 |
|
| PREINIT: |
| 95 |
|
| char errbuf[RDX_ERR_BUFLEN]; |
| 96 |
|
| CODE: |
| 97 |
|
| /* Open a FROZEN (sealed) file read-only: O_RDONLY + PROT_READ, no lock |
| 98 |
|
| ever. A sealed file is immutable and no read path writes the mapping, |
| 99 |
|
| so queries take no reader-slot / rwlock traffic and any number of |
| 100 |
|
| processes can share one PROT_READ mapping (same architecture; the |
| 101 |
|
| magic rejects a wrong-endian file). */ |
| 102 |
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 |
|
| 103 |
6 |
▶ | if (!p) croak("Data::RadixTree::Shared->new_readonly: path is required"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p) croak("Data::RadixTree::Shared->new_readonly: path is required"); |
1 |
5 |
6 |
|
| 104 |
5 |
| RdxHandle *h = rdx_open_readonly(p, errbuf); |
| 105 |
5 |
▶ | if (!h) croak("Data::RadixTree::Shared->new_readonly: %s", errbuf); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h) croak("Data::RadixTree::Shared->new_readonly: %s", errbuf); |
2 |
3 |
5 |
|
| 106 |
3 |
| class = SvPV_nolen(ST(0)); /* re-read: SvGETMAGIC(path) above can run Perl that reallocs/frees ST(0)'s PV */ |
| 107 |
3 |
| MAKE_OBJ(class, h); |
| 108 |
|
| OUTPUT: |
| 109 |
|
| RETVAL |
| 110 |
|
| |
| 111 |
|
| void |
| 112 |
|
| DESTROY(self) |
| 113 |
|
| SV *self |
| 114 |
|
| CODE: |
| 115 |
38 |
▶ | if (sv_isobject(self) && sv_derived_from(self, "Data::RadixTree::Shared")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv_isobject(self) && sv_derived_from(self, "Data::RadixTree::Shared")) { |
38 |
0 |
38 |
| if (sv_isobject(self) && sv_derived_from(self, "Data::RadixTree::Shared")) { |
38 |
0 |
38 |
|
| 116 |
38 |
| RdxHandle *h = INT2PTR(RdxHandle*, SvIV(SvRV(self))); |
| 117 |
38 |
▶ | if (h) { sv_setiv(SvRV(self), 0); rdx_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (h) { sv_setiv(SvRV(self), 0); rdx_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */ |
36 |
2 |
38 |
|
| 118 |
|
| } |
| 119 |
|
| |
| 120 |
|
| IV |
| 121 |
|
| insert(self, key, value = 1) |
| 122 |
|
| SV *self |
| 123 |
|
| SV *key |
| 124 |
|
| UV value |
| 125 |
|
| PREINIT: |
| 126 |
1110 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
1110 |
0 |
1110 |
| EXTRACT(self); |
0 |
1110 |
1110 |
| EXTRACT(self); |
0 |
1110 |
1110 |
|
| 127 |
|
| STRLEN klen; |
| 128 |
|
| const char *kp; |
| 129 |
|
| int isnew; |
| 130 |
|
| CODE: |
| 131 |
1110 |
▶ | if (h->readonly) croak("Data::RadixTree::Shared->insert: tree is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::RadixTree::Shared->insert: tree is frozen (read-only)"); |
2 |
1108 |
1110 |
|
| 132 |
|
| /* Resolve key bytes BEFORE locking: SvPVbyte croaks on wide chars, and a |
| 133 |
|
| croak must never happen while holding the lock. */ |
| 134 |
1106 |
| kp = SvPVbyte(key, klen); |
| 135 |
1106 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
1106 |
1106 |
| REEXTRACT(self); |
0 |
1106 |
1106 |
|
| 136 |
1106 |
| rdx_rwlock_wrlock(h); |
| 137 |
1106 |
▶ | if (h->hdr->sealed) { rdx_rwlock_wrunlock(h); croak("Data::RadixTree::Shared->insert: tree is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { rdx_rwlock_wrunlock(h); croak("Data::RadixTree::Shared->insert: tree is frozen (read-only)"); } |
0 |
1106 |
1106 |
|
| 138 |
1106 |
▶ | if (!rdx_insert_has_room(h, (uint32_t)klen)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rdx_insert_has_room(h, (uint32_t)klen)) { |
3 |
1103 |
1106 |
|
| 139 |
3 |
| rdx_rwlock_wrunlock(h); /* release BEFORE croak */ |
| 140 |
3 |
| croak("Data::RadixTree::Shared->insert: capacity exhausted " |
| 141 |
|
| "(node pool or label arena full; grow node/arena capacity)"); |
| 142 |
|
| } |
| 143 |
1103 |
| isnew = rdx_insert_locked(h, (const uint8_t *)kp, (uint32_t)klen, (uint64_t)value); |
| 144 |
1103 |
| __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
| 145 |
1103 |
| rdx_rwlock_wrunlock(h); |
| 146 |
1103 |
▶ | RETVAL = (IV)isnew; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (IV)isnew; |
1065 |
38 |
1103 |
|
| 147 |
|
| OUTPUT: |
| 148 |
|
| RETVAL |
| 149 |
|
| |
| 150 |
|
| SV * |
| 151 |
|
| lookup(self, key) |
| 152 |
|
| SV *self |
| 153 |
|
| SV *key |
| 154 |
|
| PREINIT: |
| 155 |
1633 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
1633 |
0 |
1633 |
| EXTRACT(self); |
0 |
1633 |
1633 |
| EXTRACT(self); |
1 |
1632 |
1633 |
|
| 156 |
|
| STRLEN klen; |
| 157 |
|
| const char *kp; |
| 158 |
|
| uint64_t val; |
| 159 |
|
| int found; |
| 160 |
|
| CODE: |
| 161 |
1631 |
| kp = SvPVbyte(key, klen); /* before the lock */ |
| 162 |
1631 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
1631 |
1631 |
| REEXTRACT(self); |
0 |
1631 |
1631 |
|
| 163 |
1631 |
▶ | if (h->readonly) { /* frozen: immutable tree, no lock needed */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) { /* frozen: immutable tree, no lock needed */ |
24 |
1607 |
1631 |
|
| 164 |
24 |
| found = rdx_lookup_locked(h, (const uint8_t *)kp, (uint32_t)klen, &val); |
| 165 |
|
| } else { |
| 166 |
1607 |
| rdx_rwlock_rdlock(h); |
| 167 |
1607 |
| found = rdx_lookup_locked(h, (const uint8_t *)kp, (uint32_t)klen, &val); |
| 168 |
1607 |
| rdx_rwlock_rdunlock(h); |
| 169 |
|
| } |
| 170 |
1631 |
▶ | RETVAL = found ? newSVuv((UV)val) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = found ? newSVuv((UV)val) : &PL_sv_undef; |
1617 |
14 |
1631 |
|
| 171 |
|
| OUTPUT: |
| 172 |
|
| RETVAL |
| 173 |
|
| |
| 174 |
|
| bool |
| 175 |
|
| exists(self, key) |
| 176 |
|
| SV *self |
| 177 |
|
| SV *key |
| 178 |
|
| PREINIT: |
| 179 |
1615 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
1615 |
0 |
1615 |
| EXTRACT(self); |
0 |
1615 |
1615 |
| EXTRACT(self); |
0 |
1615 |
1615 |
|
| 180 |
|
| STRLEN klen; |
| 181 |
|
| const char *kp; |
| 182 |
|
| CODE: |
| 183 |
1614 |
| kp = SvPVbyte(key, klen); /* before the lock */ |
| 184 |
1614 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
1614 |
1614 |
| REEXTRACT(self); |
0 |
1614 |
1614 |
|
| 185 |
1614 |
▶ | if (h->readonly) { /* frozen: immutable tree, no lock needed */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) { /* frozen: immutable tree, no lock needed */ |
23 |
1591 |
1614 |
|
| 186 |
23 |
| RETVAL = rdx_lookup_locked(h, (const uint8_t *)kp, (uint32_t)klen, NULL) ? 1 : 0; |
| 187 |
|
| } else { |
| 188 |
1591 |
| rdx_rwlock_rdlock(h); |
| 189 |
1591 |
| RETVAL = rdx_lookup_locked(h, (const uint8_t *)kp, (uint32_t)klen, NULL) ? 1 : 0; |
| 190 |
1591 |
| rdx_rwlock_rdunlock(h); |
| 191 |
|
| } |
| 192 |
|
| OUTPUT: |
| 193 |
|
| RETVAL |
| 194 |
|
| |
| 195 |
|
| SV * |
| 196 |
|
| longest_prefix(self, key) |
| 197 |
|
| SV *self |
| 198 |
|
| SV *key |
| 199 |
|
| PREINIT: |
| 200 |
52 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
52 |
0 |
52 |
| EXTRACT(self); |
0 |
52 |
52 |
| EXTRACT(self); |
0 |
52 |
52 |
|
| 201 |
|
| STRLEN klen; |
| 202 |
|
| const char *kp; |
| 203 |
|
| uint64_t val; |
| 204 |
|
| int found; |
| 205 |
|
| CODE: |
| 206 |
51 |
| kp = SvPVbyte(key, klen); /* before the lock */ |
| 207 |
51 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
51 |
51 |
| REEXTRACT(self); |
0 |
51 |
51 |
|
| 208 |
51 |
▶ | if (h->readonly) { /* frozen: immutable tree, no lock needed */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) { /* frozen: immutable tree, no lock needed */ |
8 |
43 |
51 |
|
| 209 |
8 |
| found = rdx_longest_prefix_locked(h, (const uint8_t *)kp, (uint32_t)klen, &val); |
| 210 |
|
| } else { |
| 211 |
43 |
| rdx_rwlock_rdlock(h); |
| 212 |
43 |
| found = rdx_longest_prefix_locked(h, (const uint8_t *)kp, (uint32_t)klen, &val); |
| 213 |
43 |
| rdx_rwlock_rdunlock(h); |
| 214 |
|
| } |
| 215 |
51 |
▶ | RETVAL = found ? newSVuv((UV)val) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = found ? newSVuv((UV)val) : &PL_sv_undef; |
34 |
17 |
51 |
|
| 216 |
|
| OUTPUT: |
| 217 |
|
| RETVAL |
| 218 |
|
| |
| 219 |
|
| IV |
| 220 |
|
| delete(self, key) |
| 221 |
|
| SV *self |
| 222 |
|
| SV *key |
| 223 |
|
| PREINIT: |
| 224 |
527 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
527 |
0 |
527 |
| EXTRACT(self); |
0 |
527 |
527 |
| EXTRACT(self); |
0 |
527 |
527 |
|
| 225 |
|
| STRLEN klen; |
| 226 |
|
| const char *kp; |
| 227 |
|
| int removed; |
| 228 |
|
| CODE: |
| 229 |
527 |
▶ | if (h->readonly) croak("Data::RadixTree::Shared->delete: tree is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::RadixTree::Shared->delete: tree is frozen (read-only)"); |
2 |
525 |
527 |
|
| 230 |
524 |
| kp = SvPVbyte(key, klen); /* before the lock */ |
| 231 |
524 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
524 |
524 |
| REEXTRACT(self); |
0 |
524 |
524 |
|
| 232 |
524 |
| rdx_rwlock_wrlock(h); |
| 233 |
524 |
▶ | if (h->hdr->sealed) { rdx_rwlock_wrunlock(h); croak("Data::RadixTree::Shared->delete: tree is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { rdx_rwlock_wrunlock(h); croak("Data::RadixTree::Shared->delete: tree is frozen (read-only)"); } |
0 |
524 |
524 |
|
| 234 |
524 |
| removed = rdx_delete_locked(h, (const uint8_t *)kp, (uint32_t)klen); |
| 235 |
524 |
| __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
| 236 |
524 |
| rdx_rwlock_wrunlock(h); |
| 237 |
524 |
▶ | RETVAL = (IV)removed; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (IV)removed; |
518 |
6 |
524 |
|
| 238 |
|
| OUTPUT: |
| 239 |
|
| RETVAL |
| 240 |
|
| |
| 241 |
|
| void |
| 242 |
|
| clear(self) |
| 243 |
|
| SV *self |
| 244 |
|
| PREINIT: |
| 245 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 246 |
|
| CODE: |
| 247 |
3 |
▶ | if (h->readonly) croak("Data::RadixTree::Shared->clear: tree is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::RadixTree::Shared->clear: tree is frozen (read-only)"); |
2 |
1 |
3 |
|
| 248 |
1 |
| rdx_rwlock_wrlock(h); |
| 249 |
1 |
▶ | if (h->hdr->sealed) { rdx_rwlock_wrunlock(h); croak("Data::RadixTree::Shared->clear: tree is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { rdx_rwlock_wrunlock(h); croak("Data::RadixTree::Shared->clear: tree is frozen (read-only)"); } |
0 |
1 |
1 |
|
| 250 |
1 |
| rdx_clear_locked(h); |
| 251 |
1 |
| __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
| 252 |
1 |
| rdx_rwlock_wrunlock(h); |
| 253 |
|
| |
| 254 |
|
| void |
| 255 |
|
| freeze(self) |
| 256 |
|
| SV *self |
| 257 |
|
| PREINIT: |
| 258 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 259 |
|
| CODE: |
| 260 |
3 |
▶ | if (h->readonly) croak("Data::RadixTree::Shared->freeze: cannot freeze a read-only handle"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::RadixTree::Shared->freeze: cannot freeze a read-only handle"); |
2 |
1 |
3 |
|
| 261 |
1 |
▶ | if (rdx_freeze(h) != 0) croak("Data::RadixTree::Shared->freeze: msync: %s", strerror(errno)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rdx_freeze(h) != 0) croak("Data::RadixTree::Shared->freeze: msync: %s", strerror(errno)); |
0 |
1 |
1 |
|
| 262 |
1 |
| h->readonly = 1; /* this handle now rejects mutation too (the file is sealed) */ |
| 263 |
|
| |
| 264 |
|
| UV |
| 265 |
|
| frozen(self) |
| 266 |
|
| SV *self |
| 267 |
|
| PREINIT: |
| 268 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 269 |
|
| CODE: |
| 270 |
3 |
▶ | RETVAL = h->hdr->sealed ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->hdr->sealed ? 1 : 0; |
0 |
3 |
3 |
|
| 271 |
|
| OUTPUT: |
| 272 |
|
| RETVAL |
| 273 |
|
| |
| 274 |
|
| UV |
| 275 |
|
| readonly(self) |
| 276 |
|
| SV *self |
| 277 |
|
| PREINIT: |
| 278 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 279 |
|
| CODE: |
| 280 |
3 |
▶ | RETVAL = h->readonly ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->readonly ? 1 : 0; |
0 |
3 |
3 |
|
| 281 |
|
| OUTPUT: |
| 282 |
|
| RETVAL |
| 283 |
|
| |
| 284 |
|
| UV |
| 285 |
|
| count(self) |
| 286 |
|
| SV *self |
| 287 |
|
| PREINIT: |
| 288 |
33 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
33 |
0 |
33 |
| EXTRACT(self); |
0 |
33 |
33 |
| EXTRACT(self); |
0 |
33 |
33 |
|
| 289 |
|
| CODE: |
| 290 |
33 |
▶ | if (h->readonly) { /* frozen: immutable tree, no lock needed */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) { /* frozen: immutable tree, no lock needed */ |
4 |
29 |
33 |
|
| 291 |
4 |
| RETVAL = (UV)h->hdr->keys; |
| 292 |
|
| } else { |
| 293 |
29 |
| rdx_rwlock_rdlock(h); |
| 294 |
29 |
| RETVAL = (UV)h->hdr->keys; |
| 295 |
29 |
| rdx_rwlock_rdunlock(h); |
| 296 |
|
| } |
| 297 |
|
| OUTPUT: |
| 298 |
|
| RETVAL |
| 299 |
|
| |
| 300 |
|
| SV * |
| 301 |
|
| stats(self) |
| 302 |
|
| SV *self |
| 303 |
|
| PREINIT: |
| 304 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 305 |
|
| CODE: |
| 306 |
|
| { |
| 307 |
|
| uint64_t keys, ops; |
| 308 |
|
| uint32_t node_used, node_cap, arena_used, arena_cap; |
| 309 |
|
| /* Snapshot under the lock; do all (croak-capable) Perl allocation after |
| 310 |
|
| releasing it -- so an OOM in newHV/newSV* can never strand the lock. */ |
| 311 |
3 |
▶ | if (!h->readonly) rdx_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) rdx_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
2 |
1 |
3 |
|
| 312 |
3 |
| keys = h->hdr->keys; |
| 313 |
3 |
| node_used = h->hdr->node_used; |
| 314 |
3 |
| node_cap = h->hdr->node_cap; |
| 315 |
3 |
| arena_used = h->hdr->arena_used; |
| 316 |
3 |
| arena_cap = h->hdr->arena_cap; |
| 317 |
3 |
| ops = h->hdr->stat_ops; |
| 318 |
3 |
▶ | if (!h->readonly) rdx_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) rdx_rwlock_rdunlock(h); |
2 |
1 |
3 |
|
| 319 |
|
| |
| 320 |
3 |
| HV *hv = newHV(); |
| 321 |
3 |
| hv_stores(hv, "keys", newSVuv((UV)keys)); |
| 322 |
3 |
| hv_stores(hv, "nodes_used", newSVuv((UV)node_used)); |
| 323 |
3 |
| hv_stores(hv, "nodes_capacity", newSVuv((UV)node_cap)); |
| 324 |
3 |
| hv_stores(hv, "arena_used", newSVuv((UV)arena_used)); |
| 325 |
3 |
| hv_stores(hv, "arena_capacity", newSVuv((UV)arena_cap)); |
| 326 |
3 |
| hv_stores(hv, "ops", newSVuv((UV)ops)); |
| 327 |
3 |
| hv_stores(hv, "mmap_size", newSVuv((UV)h->mmap_size)); |
| 328 |
3 |
| hv_stores(hv, "frozen", newSVuv(h->hdr->sealed ? 1 : 0)); |
| 329 |
3 |
| hv_stores(hv, "readonly", newSVuv(h->readonly ? 1 : 0)); |
| 330 |
3 |
| RETVAL = newRV_noinc((SV *)hv); |
| 331 |
|
| } |
| 332 |
|
| OUTPUT: |
| 333 |
|
| RETVAL |
| 334 |
|
| |
| 335 |
|
| SV * |
| 336 |
|
| path(self) |
| 337 |
|
| SV *self |
| 338 |
|
| PREINIT: |
| 339 |
6 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
6 |
0 |
6 |
| EXTRACT(self); |
0 |
6 |
6 |
| EXTRACT(self); |
0 |
6 |
6 |
|
| 340 |
|
| CODE: |
| 341 |
6 |
▶ | 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; |
4 |
2 |
6 |
|
| 342 |
|
| OUTPUT: |
| 343 |
|
| RETVAL |
| 344 |
|
| |
| 345 |
|
| int |
| 346 |
|
| memfd(self) |
| 347 |
|
| SV *self |
| 348 |
|
| PREINIT: |
| 349 |
4 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
4 |
0 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
|
| 350 |
|
| CODE: |
| 351 |
4 |
▶ | RETVAL = h->backing_fd; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->backing_fd; |
0 |
4 |
4 |
|
| 352 |
|
| OUTPUT: |
| 353 |
|
| RETVAL |
| 354 |
|
| |
| 355 |
|
| void |
| 356 |
|
| sync(self) |
| 357 |
|
| SV *self |
| 358 |
|
| PREINIT: |
| 359 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 360 |
|
| CODE: |
| 361 |
3 |
▶ | if (!h->readonly && rdx_msync(h) != 0) croak("sync: %s", strerror(errno)); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h->readonly && rdx_msync(h) != 0) croak("sync: %s", strerror(errno)); |
2 |
1 |
3 |
| if (!h->readonly && rdx_msync(h) != 0) croak("sync: %s", strerror(errno)); |
0 |
2 |
2 |
|
| 362 |
|
| |
| 363 |
|
| void |
| 364 |
|
| unlink(self, ...) |
| 365 |
|
| SV *self |
| 366 |
|
| CODE: |
| 367 |
11 |
▶ | if (sv_isobject(self) && sv_derived_from(self, "Data::RadixTree::Shared")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv_isobject(self) && sv_derived_from(self, "Data::RadixTree::Shared")) { |
5 |
1 |
6 |
| if (sv_isobject(self) && sv_derived_from(self, "Data::RadixTree::Shared")) { |
5 |
0 |
5 |
|
| 368 |
5 |
| RdxHandle *h = INT2PTR(RdxHandle*, SvIV(SvRV(self))); |
| 369 |
5 |
▶ | if (h && h->path) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (h && h->path) { |
5 |
0 |
5 |
| if (h && h->path) { |
5 |
0 |
5 |
|
| 370 |
5 |
▶ | const char *up = h->unlink_path ? h->unlink_path : h->path; |
Branch: 1 branch
| Branch | True | False | Total |
| const char *up = h->unlink_path ? h->unlink_path : h->path; |
4 |
1 |
5 |
|
| 371 |
5 |
▶ | if (unlink(up) != 0 && errno != ENOENT) |
Branch: 2 branches
| Branch | True | False | Total |
| if (unlink(up) != 0 && errno != ENOENT) |
2 |
3 |
5 |
| if (unlink(up) != 0 && errno != ENOENT) |
0 |
2 |
2 |
|
| 372 |
0 |
| croak("Data::RadixTree::Shared->unlink(%s): %s", h->path, strerror(errno)); |
| 373 |
|
| } |
| 374 |
1 |
▶ | } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { |
Branch: 4 branches
| Branch | True | False | Total |
| } 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 |
|
| 375 |
|
| { |
| 376 |
1 |
| const char *up = SvPV_nolen(ST(1)); |
| 377 |
1 |
▶ | if (unlink(up) != 0 && errno != ENOENT) |
Branch: 2 branches
| Branch | True | False | Total |
| if (unlink(up) != 0 && errno != ENOENT) |
0 |
1 |
1 |
| if (unlink(up) != 0 && errno != ENOENT) |
0 |
0 |
0 |
|
| 378 |
0 |
| croak("Data::RadixTree::Shared->unlink(%s): %s", up, strerror(errno)); |
| 379 |
|
| } |
| 380 |
|
| } |