Shared.xs

filter: Statementstmt 91.4% 117 / 128 Branchbran 53.7% 145 / 270 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 65.8% 262 / 398 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« fenwick2d.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 "fenwick2d.h"
7  
8 #define EXTRACT(sv) \
9 if (!sv_isobject(sv) || !sv_derived_from(sv, "Data::Fenwick2D::Shared")) \
10 croak("Expected a Data::Fenwick2D::Shared object"); \
11 F2dHandle *h = INT2PTR(F2dHandle*, SvIV(SvRV(sv))); \
12 if (!h) croak("Attempted to use a destroyed Data::Fenwick2D::Shared object"); \
13 F2dHandle *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'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 x/y/delta/value argument is a plain
23 * typemap UV/IV, which xsubpp converts in INPUT, BEFORE PREINIT's EXTRACT runs
24 * (verified against the generated Shared.c). It is defined for the method that
25 * eventually converts an SV, or takes a second object, after extracting. */
26 #define REEXTRACT(sv) \
27 if (!SvROK(sv)) \
28 croak("Data::Fenwick2D::Shared object was replaced during the call"); \
29 h = INT2PTR(F2dHandle*, SvIV(SvRV(sv))); \
30 if (h != h0) croak("Data::Fenwick2D::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 /* 1-based (row, col) bounds check (croaks with a clear message) */
39 #define CHECK_XY(x, y) \
40 do { if ((x) < 1 || (x) > h->rows || (y) < 1 || (y) > h->cols) \
41 croak("Data::Fenwick2D::Shared: cell (%" UVuf ",%" UVuf ") out of range 1..%" UVuf " x 1..%" UVuf, \
42 (UV)(x), (UV)(y), (UV)h->rows, (UV)h->cols); } while (0)
43  
44 MODULE = Data::Fenwick2D::Shared PACKAGE = Data::Fenwick2D::Shared
45  
46 PROTOTYPES: DISABLE
47  
48 SV *
49 new(class, path = &PL_sv_undef, rows = 0, cols = 0, ...)
50 const char *class
51 SV *path
52 UV rows
53 UV cols
54 PREINIT:
55 char errbuf[F2D_ERR_BUFLEN];
56 CODE:
57 24 ▶ if (rows < 1 || cols < 1)
Branch: 2 branches
BranchTrueFalseTotal
if (rows < 1 || cols < 1) 24 0 24
if (rows < 1 || cols < 1) 0 24 24
58 0 croak("Data::Fenwick2D::Shared->new: rows and cols must be >= 1");
59 /* Optional 5th arg: file mode for a newly-created file-backed segment (default 0600). */
60 24 ▶ mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600;
Branch: 4 branches
BranchTrueFalseTotal
mode_t mode = (items > 4 && (SvGETMAGIC(ST(4)), SvOK(ST(4)))) ? (mode_t)SvUV(ST(4)) : 0600; 0 24 24
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
61 /* Capture the path PV last, after all get-magic on the optional args:
62 SvGETMAGIC(ST(4)) above could realloc/free the PV before f2d_create() uses it. */
63 38 ▶ 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 24 24
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 10 24
64 24 F2dHandle *hh = f2d_create(p, (uint64_t)rows, (uint64_t)cols, mode, errbuf);
65 24 ▶ if (!hh) croak("Data::Fenwick2D::Shared->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!hh) croak("Data::Fenwick2D::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); 4 20 24
if (!hh) croak("Data::Fenwick2D::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); 4 0 4
66 /* Re-read the class PV at the point of use: xsubpp captured it in INPUT,
67 * before the argument magic above ran, and that magic can realloc/free
68 * the PV, leaving MAKE_OBJ to bless into a stale (or reused) buffer.
69 * SvPV_nolen, not SvPV_nomg: an overloaded class must re-stringify. */
70 20 class = SvPV_nolen(ST(0));
71 20 MAKE_OBJ(class, hh);
72 OUTPUT:
73 RETVAL
74  
75 SV *
76 new_memfd(class, name = &PL_sv_undef, rows = 0, cols = 0)
77 const char *class
78 SV *name
79 UV rows
80 UV cols
81 PREINIT:
82 char errbuf[F2D_ERR_BUFLEN];
83 CODE:
84 2 ▶ const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; 0 1 1
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; 1 0 1
85 1 ▶ if (rows < 1 || cols < 1)
Branch: 2 branches
BranchTrueFalseTotal
if (rows < 1 || cols < 1) 1 0 1
if (rows < 1 || cols < 1) 0 1 1
86 0 croak("Data::Fenwick2D::Shared->new_memfd: rows and cols must be >= 1");
87 1 F2dHandle *hh = f2d_create_memfd(nm, (uint64_t)rows, (uint64_t)cols, errbuf);
88 1 ▶ if (!hh) croak("Data::Fenwick2D::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!hh) croak("Data::Fenwick2D::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 1 1
if (!hh) croak("Data::Fenwick2D::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
89 /* Re-read the class PV at the point of use (see new() above): the rows/
90 * cols INPUT conversions and the name magic both ran after xsubpp
91 * captured class. */
92 1 class = SvPV_nolen(ST(0));
93 1 MAKE_OBJ(class, hh);
94 OUTPUT:
95 RETVAL
96  
97 SV *
98 new_from_fd(class, fd)
99 const char *class
100 int fd
101 PREINIT:
102 char errbuf[F2D_ERR_BUFLEN];
103 CODE:
104 2 F2dHandle *hh = f2d_open_fd(fd, errbuf);
105 2 ▶ if (!hh) croak("Data::Fenwick2D::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!hh) croak("Data::Fenwick2D::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 1 2
if (!hh) croak("Data::Fenwick2D::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
106 /* Re-read the class PV at the point of use (see new() above): fd's INPUT
107 * conversion ran get-magic after xsubpp captured class. */
108 1 class = SvPV_nolen(ST(0));
109 1 MAKE_OBJ(class, hh);
110 OUTPUT:
111 RETVAL
112  
113 SV *
114 new_readonly(class, path)
115 const char *class
116 SV *path
117 PREINIT:
118 char errbuf[F2D_ERR_BUFLEN];
119 CODE:
120 /* Open a FROZEN (sealed) file read-only: O_RDONLY + PROT_READ, no lock
121 ever. A sealed file is immutable and no read path writes the mapping,
122 so queries take no reader-slot / rwlock traffic and any number of
123 processes can share one PROT_READ mapping (same architecture; the
124 magic rejects a wrong-endian file). */
125 13 ▶ const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 7 7
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 0 0 0
const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; 6 1 7
126 7 ▶ if (!p) croak("Data::Fenwick2D::Shared->new_readonly: path is required");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Data::Fenwick2D::Shared->new_readonly: path is required"); 1 6 7
127 6 F2dHandle *hh = f2d_open_readonly(p, errbuf);
128 6 ▶ if (!hh) croak("Data::Fenwick2D::Shared->new_readonly: %s", errbuf);
Branch: 1 branch
BranchTrueFalseTotal
if (!hh) croak("Data::Fenwick2D::Shared->new_readonly: %s", errbuf); 2 4 6
129 /* Re-read the class PV at the point of use (see new() above): path's
130 * get-magic above could have run Perl code that reallocs/frees it. */
131 4 class = SvPV_nolen(ST(0));
132 4 MAKE_OBJ(class, hh);
133 OUTPUT:
134 RETVAL
135  
136 void
137 DESTROY(self)
138 SV *self
139 CODE:
140 26 ▶ if (sv_isobject(self) && sv_derived_from(self, "Data::Fenwick2D::Shared")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self) && sv_derived_from(self, "Data::Fenwick2D::Shared")) { 26 0 26
if (sv_isobject(self) && sv_derived_from(self, "Data::Fenwick2D::Shared")) { 26 0 26
141 26 F2dHandle *h = INT2PTR(F2dHandle*, SvIV(SvRV(self)));
142 26 ▶ if (h) { sv_setiv(SvRV(self), 0); f2d_destroy(h); }
Branch: 1 branch
BranchTrueFalseTotal
if (h) { sv_setiv(SvRV(self), 0); f2d_destroy(h); } 26 0 26
143 }
144  
145 # ---- mutation ----
146  
147 void
148 update(self, x, y, delta)
149 SV *self
150 UV x
151 UV y
152 IV delta
153 PREINIT:
154 326 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 326 0 326
EXTRACT(self); 0 326 326
EXTRACT(self); 0 326 326
155 CODE:
156 326 ▶ if (h->readonly) croak("Data::Fenwick2D::Shared->update: structure is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::Fenwick2D::Shared->update: structure is frozen (read-only)"); 2 324 326
157 324 ▶ CHECK_XY(x, y);
Branch: 4 branches
BranchTrueFalseTotal
CHECK_XY(x, y); 323 1 324
CHECK_XY(x, y); 322 1 323
CHECK_XY(x, y); 322 0 322
CHECK_XY(x, y); 1 321 322
158 321 f2d_rwlock_wrlock(h);
159 321 ▶ if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_RELAXED)) { f2d_rwlock_wrunlock(h); croak("Data::Fenwick2D::Shared->update: structure is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_RELAXED)) { f2d_rwlock_wrunlock(h); croak("Data::Fenwick2D::Shared->update: structure is frozen (read-only)"); } 1 320 321
160 320 f2d_update_locked(h, (uint64_t)x, (uint64_t)y, (int64_t)delta);
161 320 h->hdr->stat_ops++;
162 320 f2d_rwlock_wrunlock(h);
163  
164 IV
165 set(self, x, y, value)
166 SV *self
167 UV x
168 UV y
169 IV value
170 PREINIT:
171 11 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 11 0 11
EXTRACT(self); 0 11 11
EXTRACT(self); 0 11 11
172 int64_t cur;
173 CODE:
174 11 ▶ if (h->readonly) croak("Data::Fenwick2D::Shared->set: structure is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::Fenwick2D::Shared->set: structure is frozen (read-only)"); 2 9 11
175 9 ▶ CHECK_XY(x, y);
Branch: 4 branches
BranchTrueFalseTotal
CHECK_XY(x, y); 9 0 9
CHECK_XY(x, y); 9 0 9
CHECK_XY(x, y); 9 0 9
CHECK_XY(x, y); 0 9 9
176 9 f2d_rwlock_wrlock(h);
177 9 ▶ if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_RELAXED)) { f2d_rwlock_wrunlock(h); croak("Data::Fenwick2D::Shared->set: structure is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_RELAXED)) { f2d_rwlock_wrunlock(h); croak("Data::Fenwick2D::Shared->set: structure is frozen (read-only)"); } 1 8 9
178 8 cur = f2d_point_locked(h, (uint64_t)x, (uint64_t)y); /* current value at (x,y) */
179 8 f2d_update_locked(h, (uint64_t)x, (uint64_t)y, (int64_t)((uint64_t)value - (uint64_t)cur));
180 8 h->hdr->stat_ops++;
181 8 f2d_rwlock_wrunlock(h);
182 8 ▶ RETVAL = (IV)cur; /* previous value */
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (IV)cur; /* previous value */ 0 8 8
183 OUTPUT:
184 RETVAL
185  
186 void
187 clear(self)
188 SV *self
189 PREINIT:
190 6 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 6 0 6
EXTRACT(self); 0 6 6
EXTRACT(self); 0 6 6
191 CODE:
192 6 ▶ if (h->readonly) croak("Data::Fenwick2D::Shared->clear: structure is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::Fenwick2D::Shared->clear: structure is frozen (read-only)"); 2 4 6
193 4 f2d_rwlock_wrlock(h);
194 4 ▶ if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_RELAXED)) { f2d_rwlock_wrunlock(h); croak("Data::Fenwick2D::Shared->clear: structure is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (__atomic_load_n(&h->hdr->sealed, __ATOMIC_RELAXED)) { f2d_rwlock_wrunlock(h); croak("Data::Fenwick2D::Shared->clear: structure is frozen (read-only)"); } 1 3 4
195 3 f2d_clear_locked(h);
196 3 h->hdr->stat_ops++;
197 3 f2d_rwlock_wrunlock(h);
198  
199 void
200 freeze(self)
201 SV *self
202 PREINIT:
203 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
204 CODE:
205 4 ▶ if (h->readonly) croak("Data::Fenwick2D::Shared->freeze: cannot freeze a read-only handle");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::Fenwick2D::Shared->freeze: cannot freeze a read-only handle"); 2 2 4
206 2 ▶ if (f2d_freeze(h) != 0) croak("Data::Fenwick2D::Shared->freeze: msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (f2d_freeze(h) != 0) croak("Data::Fenwick2D::Shared->freeze: msync: %s", strerror(errno)); 0 2 2
207 2 h->readonly = 1; /* this handle now rejects mutation too (the file is sealed) */
208  
209 UV
210 frozen(self)
211 SV *self
212 PREINIT:
213 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
214 CODE:
215 4 ▶ RETVAL = __atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = __atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0; 0 4 4
216 OUTPUT:
217 RETVAL
218  
219 UV
220 readonly(self)
221 SV *self
222 PREINIT:
223 3 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 3 0 3
EXTRACT(self); 0 3 3
EXTRACT(self); 0 3 3
224 CODE:
225 3 ▶ RETVAL = h->readonly ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->readonly ? 1 : 0; 0 3 3
226 OUTPUT:
227 RETVAL
228  
229 # ---- query ----
230  
231 IV
232 prefix(self, x, y)
233 SV *self
234 UV x
235 UV y
236 PREINIT:
237 429 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 429 0 429
EXTRACT(self); 0 429 429
EXTRACT(self); 0 429 429
238 int64_t s;
239 CODE:
240 429 ▶ if (x > h->rows || y > h->cols)
Branch: 2 branches
BranchTrueFalseTotal
if (x > h->rows || y > h->cols) 429 0 429
if (x > h->rows || y > h->cols) 0 429 429
241 0 croak("Data::Fenwick2D::Shared->prefix: (%" UVuf ",%" UVuf ") out of range 0..%" UVuf " x 0..%" UVuf,
242 (UV)x, (UV)y, (UV)h->rows, (UV)h->cols);
243 429 ▶ if (h->readonly) {
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { 3 426 429
244 3 s = f2d_prefix_locked(h, (uint64_t)x, (uint64_t)y);
245 } else {
246 426 f2d_rwlock_rdlock(h);
247 426 s = f2d_prefix_locked(h, (uint64_t)x, (uint64_t)y);
248 426 f2d_rwlock_rdunlock(h);
249 }
250 429 ▶ RETVAL = (IV)s;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (IV)s; 418 11 429
251 OUTPUT:
252 RETVAL
253  
254 IV
255 rect(self, x1, y1, x2, y2)
256 SV *self
257 UV x1
258 UV y1
259 UV x2
260 UV y2
261 PREINIT:
262 306 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 306 0 306
EXTRACT(self); 0 306 306
EXTRACT(self); 0 306 306
263 int64_t s;
264 CODE:
265 306 ▶ if (x1 < 1 || y1 < 1 || x2 > h->rows || y2 > h->cols || x1 > x2 || y1 > y2)
Branch: 6 branches
BranchTrueFalseTotal
if (x1 < 1 || y1 < 1 || x2 > h->rows || y2 > h->cols || x1 > x2 || y1 > y2) 306 0 306
if (x1 < 1 || y1 < 1 || x2 > h->rows || y2 > h->cols || x1 > x2 || y1 > y2) 306 0 306
if (x1 < 1 || y1 < 1 || x2 > h->rows || y2 > h->cols || x1 > x2 || y1 > y2) 305 1 306
if (x1 < 1 || y1 < 1 || x2 > h->rows || y2 > h->cols || x1 > x2 || y1 > y2) 305 0 305
if (x1 < 1 || y1 < 1 || x2 > h->rows || y2 > h->cols || x1 > x2 || y1 > y2) 304 1 305
if (x1 < 1 || y1 < 1 || x2 > h->rows || y2 > h->cols || x1 > x2 || y1 > y2) 0 304 304
266 2 croak("Data::Fenwick2D::Shared->rect: bad rectangle [%" UVuf ",%" UVuf "]..[%" UVuf ",%" UVuf "] (valid 1..%" UVuf " x 1..%" UVuf ")",
267 (UV)x1, (UV)y1, (UV)x2, (UV)y2, (UV)h->rows, (UV)h->cols);
268 304 ▶ if (h->readonly) {
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { 1 303 304
269 1 s = f2d_rect_locked(h, (uint64_t)x1, (uint64_t)y1, (uint64_t)x2, (uint64_t)y2);
270 } else {
271 303 f2d_rwlock_rdlock(h);
272 303 s = f2d_rect_locked(h, (uint64_t)x1, (uint64_t)y1, (uint64_t)x2, (uint64_t)y2);
273 303 f2d_rwlock_rdunlock(h);
274 }
275 304 ▶ RETVAL = (IV)s;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (IV)s; 299 5 304
276 OUTPUT:
277 RETVAL
278  
279 IV
280 point(self, x, y)
281 SV *self
282 UV x
283 UV y
284 PREINIT:
285 317 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 317 0 317
EXTRACT(self); 0 317 317
EXTRACT(self); 0 317 317
286 int64_t s;
287 CODE:
288 317 ▶ CHECK_XY(x, y);
Branch: 4 branches
BranchTrueFalseTotal
CHECK_XY(x, y); 316 1 317
CHECK_XY(x, y); 316 0 316
CHECK_XY(x, y); 316 0 316
CHECK_XY(x, y); 0 316 316
289 316 ▶ if (h->readonly) {
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { 2 314 316
290 2 s = f2d_point_locked(h, (uint64_t)x, (uint64_t)y);
291 } else {
292 314 f2d_rwlock_rdlock(h);
293 314 s = f2d_point_locked(h, (uint64_t)x, (uint64_t)y);
294 314 f2d_rwlock_rdunlock(h);
295 }
296 316 ▶ RETVAL = (IV)s;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (IV)s; 299 17 316
297 OUTPUT:
298 RETVAL
299  
300 IV
301 total(self)
302 SV *self
303 PREINIT:
304 13 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 13 0 13
EXTRACT(self); 0 13 13
EXTRACT(self); 0 13 13
305 int64_t s;
306 CODE:
307 13 ▶ if (h->readonly) {
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { 2 11 13
308 2 s = f2d_prefix_locked(h, h->rows, h->cols);
309 } else {
310 11 f2d_rwlock_rdlock(h);
311 11 s = f2d_prefix_locked(h, h->rows, h->cols);
312 11 f2d_rwlock_rdunlock(h);
313 }
314 13 ▶ RETVAL = (IV)s;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (IV)s; 0 13 13
315 OUTPUT:
316 RETVAL
317  
318 # ---- introspection ----
319  
320 UV
321 rows(self)
322 SV *self
323 PREINIT:
324 5 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 5 0 5
EXTRACT(self); 0 5 5
EXTRACT(self); 0 5 5
325 CODE:
326 5 ▶ RETVAL = (UV)h->rows;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV)h->rows; 0 5 5
327 OUTPUT:
328 RETVAL
329  
330 UV
331 cols(self)
332 SV *self
333 PREINIT:
334 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
335 CODE:
336 4 ▶ RETVAL = (UV)h->cols;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (UV)h->cols; 0 4 4
337 OUTPUT:
338 RETVAL
339  
340 SV *
341 stats(self)
342 SV *self
343 PREINIT:
344 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
345 CODE:
346 {
347 uint64_t rr, cc, ops, mmap_size;
348 int64_t tot;
349 4 rr = h->rows; cc = h->cols;
350 4 ▶ if (!h->readonly) f2d_rwlock_rdlock(h); /* frozen: immutable grid, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) f2d_rwlock_rdlock(h); /* frozen: immutable grid, no lock */ 3 1 4
351 4 tot = f2d_prefix_locked(h, rr, cc);
352 4 ops = h->hdr->stat_ops;
353 4 ▶ if (!h->readonly) f2d_rwlock_rdunlock(h);
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) f2d_rwlock_rdunlock(h); 3 1 4
354 4 mmap_size = (uint64_t)h->mmap_size;
355  
356 4 HV *hv = newHV();
357 4 hv_stores(hv, "rows", newSVuv((UV)rr));
358 4 hv_stores(hv, "cols", newSVuv((UV)cc));
359 4 hv_stores(hv, "total", newSViv((IV)tot));
360 4 hv_stores(hv, "ops", newSVuv((UV)ops));
361 4 hv_stores(hv, "mmap_size", newSVuv((UV)mmap_size));
362 4 hv_stores(hv, "frozen", newSVuv(__atomic_load_n(&h->hdr->sealed, __ATOMIC_ACQUIRE) ? 1 : 0));
363 4 hv_stores(hv, "readonly", newSVuv(h->readonly ? 1 : 0));
364 4 RETVAL = newRV_noinc((SV *)hv);
365 }
366 OUTPUT:
367 RETVAL
368  
369 SV *
370 path(self)
371 SV *self
372 PREINIT:
373 1 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 1 0 1
EXTRACT(self); 0 1 1
EXTRACT(self); 0 1 1
374 CODE:
375 1 ▶ RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; 1 0 1
376 OUTPUT:
377 RETVAL
378  
379 int
380 memfd(self)
381 SV *self
382 PREINIT:
383 2 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 2 0 2
EXTRACT(self); 0 2 2
EXTRACT(self); 0 2 2
384 CODE:
385 2 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 2 2
386 OUTPUT:
387 RETVAL
388  
389 void
390 sync(self)
391 SV *self
392 PREINIT:
393 2 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 2 0 2
EXTRACT(self); 0 2 2
EXTRACT(self); 0 2 2
394 CODE:
395 2 ▶ if (!h->readonly && f2d_msync(h) != 0) croak("sync: %s", strerror(errno));
Branch: 2 branches
BranchTrueFalseTotal
if (!h->readonly && f2d_msync(h) != 0) croak("sync: %s", strerror(errno)); 1 1 2
if (!h->readonly && f2d_msync(h) != 0) croak("sync: %s", strerror(errno)); 0 1 1
396  
397 void
398 unlink(self, ...)
399 SV *self
400 CODE:
401 0 ▶ if (sv_isobject(self) && sv_derived_from(self, "Data::Fenwick2D::Shared")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self) && sv_derived_from(self, "Data::Fenwick2D::Shared")) { 0 0 0
if (sv_isobject(self) && sv_derived_from(self, "Data::Fenwick2D::Shared")) { 0 0 0
402 0 F2dHandle *h = INT2PTR(F2dHandle*, SvIV(SvRV(self)));
403 0 ▶ if (h && h->path && unlink(h->path) != 0 && errno != ENOENT)
Branch: 4 branches
BranchTrueFalseTotal
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
404 0 croak("Data::Fenwick2D::Shared->unlink(%s): %s", h->path, strerror(errno));
405 0 ▶ } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) {
Branch: 4 branches
BranchTrueFalseTotal
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 0 0 0
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 0 0 0
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 0 0 0
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 0 0 0
406 {
407 0 const char *up = SvPV_nolen(ST(1));
408 0 ▶ if (unlink(up) != 0 && errno != ENOENT)
Branch: 2 branches
BranchTrueFalseTotal
if (unlink(up) != 0 && errno != ENOENT) 0 0 0
if (unlink(up) != 0 && errno != ENOENT) 0 0 0
409 0 croak("Data::Fenwick2D::Shared->unlink(%s): %s", up, strerror(errno));
410 }
411 }
« fenwick2d.h ↑ Summary