| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| #include "dsu.h" |
| 7 |
|
| |
| 8 |
|
| #define EXTRACT(sv) \ |
| 9 |
|
| if (!sv_isobject(sv) || !sv_derived_from(sv, "Data::DisjointSet::Shared")) \ |
| 10 |
|
| croak("Expected a Data::DisjointSet::Shared object"); \ |
| 11 |
|
| DsuHandle *h = INT2PTR(DsuHandle*, SvIV(SvRV(sv))); \ |
| 12 |
|
| if (!h) croak("Attempted to use a destroyed Data::DisjointSet::Shared object"); \ |
| 13 |
|
| DsuHandle *h0 = h; PERL_UNUSED_VAR(h0); /* identity anchor for REEXTRACT */ \ |
| 14 |
|
| sv_2mortal(SvREFCNT_inc(SvRV(sv))) |
| 15 |
|
| |
| 16 |
|
| /* Re-read the handle after a call that can run Perl code: overloaded/tied |
| 17 |
|
| * argument magic, av_len on a TIED array (AvFILL -> mg_size -> FETCHSIZE), |
| 18 |
|
| * and element fetches. EXTRACT's sv_2mortal(SvREFCNT_inc(...)) pin only |
| 19 |
|
| * blocks REFCOUNT-driven destruction; an explicit $obj->DESTROY frees the |
| 20 |
|
| * handle regardless and zeroes the IV, so the local `h` would dangle. |
| 21 |
|
| * That same Perl can also REPLACE the invocant ($obj = 42, or $obj = another |
| 22 |
|
| * object) by mutating the ST(0) alias. So we re-check SvROK (else SvRV would |
| 23 |
|
| * run on a non-reference), then compare the re-read handle against the one |
| 24 |
|
| * captured at EXTRACT (h0): a legitimate invocant's handle is immutable across |
| 25 |
|
| * a call, so `h != h0` rejects EVERY replacement (non-ref, foreign ref, or a |
| 26 |
|
| * DIFFERENT same-class object -- which sv_derived_from could not tell apart) |
| 27 |
|
| * and destruction (a freed/DESTROYed handle reads back 0 != h0) in one branch, |
| 28 |
|
| * at the same cost as the old `!h` null check. */ |
| 29 |
|
| #define REEXTRACT(sv) \ |
| 30 |
|
| if (!SvROK(sv)) \ |
| 31 |
|
| croak("Data::DisjointSet::Shared object was replaced during the call"); \ |
| 32 |
|
| h = INT2PTR(DsuHandle*, SvIV(SvRV(sv))); \ |
| 33 |
|
| if (h != h0) croak("Data::DisjointSet::Shared object replaced or destroyed during the call") |
| 34 |
|
| |
| 35 |
|
| #define MAKE_OBJ(class, handle) \ |
| 36 |
|
| SV *obj = newSViv(PTR2IV(handle)); \ |
| 37 |
|
| SV *ref = newRV_noinc(obj); \ |
| 38 |
|
| sv_bless(ref, gv_stashpv(class, GV_ADD)); \ |
| 39 |
|
| RETVAL = ref |
| 40 |
|
| |
| 41 |
|
| MODULE = Data::DisjointSet::Shared PACKAGE = Data::DisjointSet::Shared |
| 42 |
|
| |
| 43 |
|
| PROTOTYPES: DISABLE |
| 44 |
|
| |
| 45 |
|
| SV * |
| 46 |
|
| new(class, path = &PL_sv_undef, n = 0, ...) |
| 47 |
|
| const char *class |
| 48 |
|
| SV *path |
| 49 |
|
| UV n |
| 50 |
|
| PREINIT: |
| 51 |
|
| char errbuf[DSU_ERR_BUFLEN]; |
| 52 |
|
| CODE: |
| 53 |
|
| /* Optional 4th arg: file mode for exclusive create (default 0600, owner-only). |
| 54 |
|
| Resolve BEFORE capturing the path PV: its get-magic could realloc/free it. */ |
| 55 |
30 |
▶ | 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; |
2 |
28 |
30 |
| mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; |
0 |
2 |
2 |
| 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; |
2 |
0 |
2 |
|
| 56 |
44 |
▶ | 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 |
30 |
30 |
| 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 |
16 |
30 |
|
| 57 |
30 |
| DsuHandle *h = dsu_create(p, (uint64_t)n, mode, errbuf); /* validates args into errbuf */ |
| 58 |
30 |
▶ | if (!h) croak("Data::DisjointSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::DisjointSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
5 |
25 |
30 |
| if (!h) croak("Data::DisjointSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
5 |
0 |
5 |
|
| 59 |
25 |
| MAKE_OBJ(class, h); |
| 60 |
|
| OUTPUT: |
| 61 |
|
| RETVAL |
| 62 |
|
| |
| 63 |
|
| SV * |
| 64 |
|
| new_memfd(class, name = &PL_sv_undef, n = 0) |
| 65 |
|
| const char *class |
| 66 |
|
| SV *name |
| 67 |
|
| UV n |
| 68 |
|
| PREINIT: |
| 69 |
|
| char errbuf[DSU_ERR_BUFLEN]; |
| 70 |
|
| CODE: |
| 71 |
7 |
▶ | 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 |
4 |
4 |
| 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 */ |
3 |
1 |
4 |
|
| 72 |
4 |
| DsuHandle *h = dsu_create_memfd(nm, (uint64_t)n, errbuf); /* validates args into errbuf */ |
| 73 |
4 |
▶ | if (!h) croak("Data::DisjointSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::DisjointSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
3 |
4 |
| if (!h) croak("Data::DisjointSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
0 |
1 |
|
| 74 |
3 |
| MAKE_OBJ(class, h); |
| 75 |
|
| OUTPUT: |
| 76 |
|
| RETVAL |
| 77 |
|
| |
| 78 |
|
| SV * |
| 79 |
|
| new_from_fd(class, fd) |
| 80 |
|
| const char *class |
| 81 |
|
| int fd |
| 82 |
|
| PREINIT: |
| 83 |
|
| char errbuf[DSU_ERR_BUFLEN]; |
| 84 |
|
| CODE: |
| 85 |
4 |
| DsuHandle *h = dsu_open_fd(fd, errbuf); |
| 86 |
4 |
▶ | if (!h) croak("Data::DisjointSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::DisjointSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
3 |
4 |
| if (!h) croak("Data::DisjointSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
0 |
1 |
|
| 87 |
3 |
| MAKE_OBJ(class, h); |
| 88 |
|
| OUTPUT: |
| 89 |
|
| RETVAL |
| 90 |
|
| |
| 91 |
|
| void |
| 92 |
|
| DESTROY(self) |
| 93 |
|
| SV *self |
| 94 |
|
| CODE: |
| 95 |
33 |
▶ | if (sv_isobject(self) && sv_derived_from(self, "Data::DisjointSet::Shared")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv_isobject(self) && sv_derived_from(self, "Data::DisjointSet::Shared")) { |
33 |
0 |
33 |
| if (sv_isobject(self) && sv_derived_from(self, "Data::DisjointSet::Shared")) { |
33 |
0 |
33 |
|
| 96 |
33 |
| DsuHandle *h = INT2PTR(DsuHandle*, SvIV(SvRV(self))); |
| 97 |
33 |
▶ | if (h) { sv_setiv(SvRV(self), 0); dsu_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); dsu_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */ |
31 |
2 |
33 |
|
| 98 |
|
| } |
| 99 |
|
| |
| 100 |
|
| UV |
| 101 |
|
| find(self, x) |
| 102 |
|
| SV *self |
| 103 |
|
| UV x |
| 104 |
|
| PREINIT: |
| 105 |
3048 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3048 |
0 |
3048 |
| EXTRACT(self); |
0 |
3048 |
3048 |
| EXTRACT(self); |
1 |
3047 |
3048 |
|
| 106 |
|
| CODE: |
| 107 |
|
| /* Range-check BEFORE locking so a croak holds no lock. */ |
| 108 |
3047 |
▶ | if (x >= h->n) |
Branch: 1 branch
| Branch | True | False | Total |
| if (x >= h->n) |
1 |
3046 |
3047 |
|
| 109 |
1 |
| croak("Data::DisjointSet::Shared->find: index %" UVuf " out of range (n=%u)", |
| 110 |
|
| x, h->n); |
| 111 |
|
| /* find performs path compression -> it MUTATES -> take the write lock. */ |
| 112 |
3046 |
| dsu_rwlock_wrlock(h); |
| 113 |
3046 |
| RETVAL = (UV)dsu_find(h, (uint32_t)x); |
| 114 |
3046 |
| dsu_rwlock_wrunlock(h); |
| 115 |
|
| OUTPUT: |
| 116 |
|
| RETVAL |
| 117 |
|
| |
| 118 |
|
| IV |
| 119 |
|
| union(self, a, b) |
| 120 |
|
| SV *self |
| 121 |
|
| UV a |
| 122 |
|
| UV b |
| 123 |
|
| PREINIT: |
| 124 |
2019 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
2019 |
0 |
2019 |
| EXTRACT(self); |
0 |
2019 |
2019 |
| EXTRACT(self); |
0 |
2019 |
2019 |
|
| 125 |
|
| CODE: |
| 126 |
2019 |
▶ | if (a >= h->n) |
Branch: 1 branch
| Branch | True | False | Total |
| if (a >= h->n) |
1 |
2018 |
2019 |
|
| 127 |
1 |
| croak("Data::DisjointSet::Shared->union: index %" UVuf " out of range (n=%u)", |
| 128 |
|
| a, h->n); |
| 129 |
2018 |
▶ | if (b >= h->n) |
Branch: 1 branch
| Branch | True | False | Total |
| if (b >= h->n) |
1 |
2017 |
2018 |
|
| 130 |
1 |
| croak("Data::DisjointSet::Shared->union: index %" UVuf " out of range (n=%u)", |
| 131 |
|
| b, h->n); |
| 132 |
2017 |
| dsu_rwlock_wrlock(h); |
| 133 |
2017 |
| RETVAL = (IV)dsu_union_locked(h, (uint32_t)a, (uint32_t)b); /* 1 = newly merged, 0 = already together */ |
| 134 |
2017 |
| dsu_rwlock_wrunlock(h); |
| 135 |
|
| OUTPUT: |
| 136 |
|
| RETVAL |
| 137 |
|
| |
| 138 |
|
| bool |
| 139 |
|
| connected(self, a, b) |
| 140 |
|
| SV *self |
| 141 |
|
| UV a |
| 142 |
|
| UV b |
| 143 |
|
| PREINIT: |
| 144 |
5658 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
5658 |
0 |
5658 |
| EXTRACT(self); |
0 |
5658 |
5658 |
| EXTRACT(self); |
0 |
5658 |
5658 |
|
| 145 |
|
| CODE: |
| 146 |
5658 |
▶ | if (a >= h->n) |
Branch: 1 branch
| Branch | True | False | Total |
| if (a >= h->n) |
1 |
5657 |
5658 |
|
| 147 |
1 |
| croak("Data::DisjointSet::Shared->connected: index %" UVuf " out of range (n=%u)", |
| 148 |
|
| a, h->n); |
| 149 |
5657 |
▶ | if (b >= h->n) |
Branch: 1 branch
| Branch | True | False | Total |
| if (b >= h->n) |
1 |
5656 |
5657 |
|
| 150 |
1 |
| croak("Data::DisjointSet::Shared->connected: index %" UVuf " out of range (n=%u)", |
| 151 |
|
| b, h->n); |
| 152 |
|
| /* connected compresses paths via dsu_find -> it MUTATES -> write lock. */ |
| 153 |
5656 |
| dsu_rwlock_wrlock(h); |
| 154 |
5656 |
| RETVAL = dsu_connected_locked(h, (uint32_t)a, (uint32_t)b); |
| 155 |
5656 |
| dsu_rwlock_wrunlock(h); |
| 156 |
|
| OUTPUT: |
| 157 |
|
| RETVAL |
| 158 |
|
| |
| 159 |
|
| UV |
| 160 |
|
| union_many(self, pairs) |
| 161 |
|
| SV *self |
| 162 |
|
| SV *pairs |
| 163 |
|
| PREINIT: |
| 164 |
13 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
13 |
0 |
13 |
| EXTRACT(self); |
0 |
13 |
13 |
| EXTRACT(self); |
0 |
13 |
13 |
|
| 165 |
|
| AV *av; |
| 166 |
|
| IV top; |
| 167 |
|
| CODE: |
| 168 |
13 |
▶ | SvGETMAGIC(pairs); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(pairs); |
0 |
13 |
13 |
| SvGETMAGIC(pairs); |
0 |
0 |
0 |
|
| 169 |
13 |
▶ | if (!SvROK(pairs) || SvTYPE(SvRV(pairs)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(pairs) || SvTYPE(SvRV(pairs)) != SVt_PVAV) |
12 |
1 |
13 |
| if (!SvROK(pairs) || SvTYPE(SvRV(pairs)) != SVt_PVAV) |
0 |
12 |
12 |
|
| 170 |
1 |
| croak("Data::DisjointSet::Shared->union_many: expected an array reference"); |
| 171 |
12 |
| av = (AV *)SvRV(pairs); |
| 172 |
12 |
| sv_2mortal(SvREFCNT_inc((SV *)av)); /* pin the arrayref: a tied element's FETCH below cannot free it mid-loop */ |
| 173 |
12 |
| top = av_len(av); /* last index, -1 if empty */ |
| 174 |
|
| /* SvGETMAGIC(pairs) above, and av_len on a tied array, both run Perl that |
| 175 |
|
| * can have destroyed self -- re-check before the first use of h below. */ |
| 176 |
12 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
12 |
12 |
| REEXTRACT(self); |
0 |
12 |
12 |
|
| 177 |
|
| { |
| 178 |
12 |
▶ | STRLEN cnt = (top >= 0) ? (STRLEN)(top + 1) : 0, i; |
Branch: 1 branch
| Branch | True | False | Total |
| STRLEN cnt = (top >= 0) ? (STRLEN)(top + 1) : 0, i; |
10 |
2 |
12 |
|
| 179 |
|
| STRLEN npairs; |
| 180 |
12 |
| uint32_t *vals = NULL; |
| 181 |
12 |
| UV merged = 0; |
| 182 |
12 |
| uint32_t n = h->n; |
| 183 |
12 |
▶ | if (cnt & 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cnt & 1) |
1 |
11 |
12 |
|
| 184 |
1 |
| croak("Data::DisjointSet::Shared->union_many: expected an even number of elements (flat [a0,b0,a1,b1,...]), got %" UVuf, |
| 185 |
|
| (UV)cnt); |
| 186 |
11 |
| npairs = cnt / 2; |
| 187 |
11 |
▶ | if (cnt) { /* resolve + range-check ALL before locking */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (cnt) { /* resolve + range-check ALL before locking */ |
9 |
2 |
11 |
|
| 188 |
9 |
▶ | Newx(vals, cnt, uint32_t); SAVEFREEPV(vals); /* freed on return OR unwind */ |
Branch: 1 branch
| Branch | True | False | Total |
| Newx(vals, cnt, uint32_t); SAVEFREEPV(vals); /* freed on return OR unwind */ |
0 |
9 |
9 |
|
| 189 |
46 |
▶ | for (i = 0; i < cnt; i++) { /* a croak here holds NO lock; SAVEFREEPV cleans up */ |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < cnt; i++) { /* a croak here holds NO lock; SAVEFREEPV cleans up */ |
40 |
6 |
46 |
|
| 190 |
40 |
| SV **el = av_fetch(av, (SSize_t)i, 0); |
| 191 |
40 |
▶ | UV v = (el && *el) ? SvUV(*el) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| UV v = (el && *el) ? SvUV(*el) : 0; |
40 |
0 |
40 |
| UV v = (el && *el) ? SvUV(*el) : 0; |
40 |
0 |
40 |
|
| 192 |
40 |
▶ | if (v >= n) |
Branch: 1 branch
| Branch | True | False | Total |
| if (v >= n) |
3 |
37 |
40 |
|
| 193 |
3 |
| croak("Data::DisjointSet::Shared->union_many: index %" UVuf " out of range (n=%u)", |
| 194 |
|
| v, n); |
| 195 |
37 |
| vals[i] = (uint32_t)v; |
| 196 |
|
| } |
| 197 |
|
| } |
| 198 |
|
| /* Element get-magic in the resolve loop above can also have destroyed |
| 199 |
|
| * self; re-check before taking the lock (and note `n` may be stale -- |
| 200 |
|
| * a destroyed handle croaks here rather than being used). */ |
| 201 |
8 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
8 |
8 |
| REEXTRACT(self); |
0 |
8 |
8 |
|
| 202 |
8 |
| dsu_rwlock_wrlock(h); /* locked region: NO croak-capable calls */ |
| 203 |
23 |
▶ | for (i = 0; i < npairs; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < npairs; i++) |
15 |
8 |
23 |
|
| 204 |
15 |
| merged += (UV)dsu_union_locked(h, vals[2*i], vals[2*i + 1]); |
| 205 |
8 |
| dsu_rwlock_wrunlock(h); |
| 206 |
8 |
▶ | RETVAL = merged; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = merged; |
0 |
8 |
8 |
|
| 207 |
|
| } |
| 208 |
|
| OUTPUT: |
| 209 |
|
| RETVAL |
| 210 |
|
| |
| 211 |
|
| UV |
| 212 |
|
| set_size(self, x) |
| 213 |
|
| SV *self |
| 214 |
|
| UV x |
| 215 |
|
| PREINIT: |
| 216 |
2134 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
2134 |
0 |
2134 |
| EXTRACT(self); |
0 |
2134 |
2134 |
| EXTRACT(self); |
0 |
2134 |
2134 |
|
| 217 |
|
| CODE: |
| 218 |
2134 |
▶ | if (x >= h->n) |
Branch: 1 branch
| Branch | True | False | Total |
| if (x >= h->n) |
1 |
2133 |
2134 |
|
| 219 |
1 |
| croak("Data::DisjointSet::Shared->set_size: index %" UVuf " out of range (n=%u)", |
| 220 |
|
| x, h->n); |
| 221 |
|
| /* set_size compresses paths via dsu_find -> it MUTATES -> write lock. */ |
| 222 |
2133 |
| dsu_rwlock_wrlock(h); |
| 223 |
2133 |
| RETVAL = (UV)dsu_set_size_locked(h, (uint32_t)x); |
| 224 |
2133 |
| dsu_rwlock_wrunlock(h); |
| 225 |
|
| OUTPUT: |
| 226 |
|
| RETVAL |
| 227 |
|
| |
| 228 |
|
| UV |
| 229 |
|
| num_sets(self) |
| 230 |
|
| SV *self |
| 231 |
|
| PREINIT: |
| 232 |
2020 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
2020 |
0 |
2020 |
| EXTRACT(self); |
0 |
2020 |
2020 |
| EXTRACT(self); |
0 |
2020 |
2020 |
|
| 233 |
|
| CODE: |
| 234 |
2020 |
| dsu_rwlock_rdlock(h); |
| 235 |
2020 |
| RETVAL = (UV)h->hdr->num_sets; |
| 236 |
2020 |
| dsu_rwlock_rdunlock(h); |
| 237 |
|
| OUTPUT: |
| 238 |
|
| RETVAL |
| 239 |
|
| |
| 240 |
|
| UV |
| 241 |
|
| capacity(self) |
| 242 |
|
| SV *self |
| 243 |
|
| PREINIT: |
| 244 |
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 |
|
| 245 |
|
| CODE: |
| 246 |
6 |
▶ | RETVAL = (UV)h->hdr->n; /* immutable after creation -- lock-free */ |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)h->hdr->n; /* immutable after creation -- lock-free */ |
0 |
6 |
6 |
|
| 247 |
|
| OUTPUT: |
| 248 |
|
| RETVAL |
| 249 |
|
| |
| 250 |
|
| void |
| 251 |
|
| reset(self) |
| 252 |
|
| SV *self |
| 253 |
|
| PREINIT: |
| 254 |
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 |
|
| 255 |
|
| CODE: |
| 256 |
3 |
| dsu_rwlock_wrlock(h); |
| 257 |
3 |
| dsu_reset_locked(h); |
| 258 |
3 |
| dsu_rwlock_wrunlock(h); |
| 259 |
|
| |
| 260 |
|
| SV * |
| 261 |
|
| stats(self) |
| 262 |
|
| SV *self |
| 263 |
|
| PREINIT: |
| 264 |
5 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
5 |
0 |
5 |
| EXTRACT(self); |
0 |
5 |
5 |
| EXTRACT(self); |
0 |
5 |
5 |
|
| 265 |
|
| CODE: |
| 266 |
|
| { |
| 267 |
|
| uint32_t n, num_sets; |
| 268 |
|
| uint64_t ops; |
| 269 |
|
| /* Snapshot under the lock; do all (croak-capable) Perl allocation after |
| 270 |
|
| releasing it -- so an OOM in newHV/newSV* can never strand the lock. */ |
| 271 |
5 |
| dsu_rwlock_rdlock(h); |
| 272 |
5 |
| n = h->hdr->n; |
| 273 |
5 |
| num_sets = h->hdr->num_sets; |
| 274 |
5 |
| ops = __atomic_load_n(&h->hdr->stat_ops, __ATOMIC_RELAXED); |
| 275 |
5 |
| dsu_rwlock_rdunlock(h); |
| 276 |
|
| |
| 277 |
5 |
| HV *hv = newHV(); |
| 278 |
5 |
| hv_stores(hv, "capacity", newSVuv((UV)n)); |
| 279 |
5 |
| hv_stores(hv, "sets", newSVuv((UV)num_sets)); |
| 280 |
5 |
| hv_stores(hv, "ops", newSVuv((UV)ops)); |
| 281 |
5 |
| hv_stores(hv, "mmap_size", newSVuv((UV)h->mmap_size)); |
| 282 |
5 |
| RETVAL = newRV_noinc((SV *)hv); |
| 283 |
|
| } |
| 284 |
|
| OUTPUT: |
| 285 |
|
| RETVAL |
| 286 |
|
| |
| 287 |
|
| SV * |
| 288 |
|
| path(self) |
| 289 |
|
| SV *self |
| 290 |
|
| PREINIT: |
| 291 |
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 |
|
| 292 |
|
| CODE: |
| 293 |
3 |
▶ | 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; |
1 |
2 |
3 |
|
| 294 |
|
| OUTPUT: |
| 295 |
|
| RETVAL |
| 296 |
|
| |
| 297 |
|
| int |
| 298 |
|
| memfd(self) |
| 299 |
|
| SV *self |
| 300 |
|
| PREINIT: |
| 301 |
5 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
5 |
0 |
5 |
| EXTRACT(self); |
0 |
5 |
5 |
| EXTRACT(self); |
0 |
5 |
5 |
|
| 302 |
|
| CODE: |
| 303 |
5 |
▶ | RETVAL = h->backing_fd; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->backing_fd; |
0 |
5 |
5 |
|
| 304 |
|
| OUTPUT: |
| 305 |
|
| RETVAL |
| 306 |
|
| |
| 307 |
|
| void |
| 308 |
|
| sync(self) |
| 309 |
|
| SV *self |
| 310 |
|
| PREINIT: |
| 311 |
2 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
2 |
0 |
2 |
| EXTRACT(self); |
0 |
2 |
2 |
| EXTRACT(self); |
0 |
2 |
2 |
|
| 312 |
|
| CODE: |
| 313 |
2 |
▶ | if (dsu_msync(h) != 0) croak("sync: %s", strerror(errno)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (dsu_msync(h) != 0) croak("sync: %s", strerror(errno)); |
0 |
2 |
2 |
|
| 314 |
|
| |
| 315 |
|
| void |
| 316 |
|
| unlink(self, ...) |
| 317 |
|
| SV *self |
| 318 |
|
| CODE: |
| 319 |
3 |
▶ | if (sv_isobject(self) && sv_derived_from(self, "Data::DisjointSet::Shared")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv_isobject(self) && sv_derived_from(self, "Data::DisjointSet::Shared")) { |
1 |
1 |
2 |
| if (sv_isobject(self) && sv_derived_from(self, "Data::DisjointSet::Shared")) { |
1 |
0 |
1 |
|
| 320 |
1 |
| DsuHandle *h = INT2PTR(DsuHandle*, SvIV(SvRV(self))); |
| 321 |
1 |
▶ | if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) |
Branch: 4 branches
| Branch | True | False | Total |
| 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 |
|
| 322 |
0 |
| croak("Data::DisjointSet::Shared->unlink(%s): %s", h->path, strerror(errno)); |
| 323 |
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 |
|
| 324 |
|
| { |
| 325 |
1 |
| const char *up = SvPV_nolen(ST(1)); |
| 326 |
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 |
|
| 327 |
0 |
| croak("Data::DisjointSet::Shared->unlink(%s): %s", up, strerror(errno)); |
| 328 |
|
| } |
| 329 |
|
| } |