Shared.xs

filter: Statementstmt 97.8% 136 / 139 Branchbran 58.1% 150 / 258 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 72.0% 286 / 397 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« intern.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 "intern.h"
7  
8 #define EXTRACT(sv) \
9 if (!sv_isobject(sv) || !sv_derived_from(sv, "Data::Intern::Shared")) \
10 croak("Expected a Data::Intern::Shared object"); \
11 SiHandle *h = INT2PTR(SiHandle*, SvIV(SvRV(sv))); \
12 if (!h) croak("Attempted to use a destroyed Data::Intern::Shared object"); \
13 SiHandle *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::Intern::Shared object was replaced during the call"); \
25 h = INT2PTR(SiHandle*, SvIV(SvRV(sv))); \
26 if (h != h0) croak("Data::Intern::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::Intern::Shared PACKAGE = Data::Intern::Shared
35  
36 PROTOTYPES: DISABLE
37  
38 SV *
39 new(class, path, max_strings, arena_bytes = 0, ...)
40 const char *class
41 SV *path
42 UV max_strings
43 UV arena_bytes
44 PREINIT:
45 char errbuf[SI_ERR_BUFLEN];
46 CODE:
47 /* Resolve the optional trailing mode arg BEFORE capturing the path PV:
48 its get-magic can run Perl code that reallocs/frees path's PV, so the
49 PV must be captured last, immediately before si_create() uses it. */
50 /* Opt-in file mode for cross-user sharing; default 0600 (owner-only). */
51 40 ▶ 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 40 40
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
52 68 ▶ 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 40 40
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; 28 12 40
53 40 ▶ if (max_strings > SI_MAX_STRINGS) croak("Data::Intern::Shared->new: max_strings exceeds 2^30");
Branch: 1 branch
BranchTrueFalseTotal
if (max_strings > SI_MAX_STRINGS) croak("Data::Intern::Shared->new: max_strings exceeds 2^30"); 0 40 40
54 40 ▶ if (arena_bytes > UINT32_MAX) croak("Data::Intern::Shared->new: arena_bytes exceeds 2^32");
Branch: 1 branch
BranchTrueFalseTotal
if (arena_bytes > UINT32_MAX) croak("Data::Intern::Shared->new: arena_bytes exceeds 2^32"); 0 40 40
55 40 SiHandle *h = si_create(p, (uint32_t)max_strings, (uint32_t)arena_bytes, mode, errbuf);
56 40 ▶ if (!h) croak("Data::Intern::Shared->new: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Intern::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); 6 34 40
if (!h) croak("Data::Intern::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); 6 0 6
57 34 MAKE_OBJ(class, h);
58 OUTPUT:
59 RETVAL
60  
61 SV *
62 new_memfd(class, name, max_strings, arena_bytes = 0)
63 const char *class
64 SV *name
65 UV max_strings
66 UV arena_bytes
67 PREINIT:
68 char errbuf[SI_ERR_BUFLEN];
69 CODE:
70 3 ▶ const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; /* undef -> default label */
Branch: 3 branches
BranchTrueFalseTotal
const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; /* undef -> default label */ 0 2 2
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 */ 1 1 2
71 2 ▶ if (max_strings > SI_MAX_STRINGS) croak("Data::Intern::Shared->new_memfd: max_strings exceeds 2^30");
Branch: 1 branch
BranchTrueFalseTotal
if (max_strings > SI_MAX_STRINGS) croak("Data::Intern::Shared->new_memfd: max_strings exceeds 2^30"); 0 2 2
72 2 ▶ if (arena_bytes > UINT32_MAX) croak("Data::Intern::Shared->new_memfd: arena_bytes exceeds 2^32");
Branch: 1 branch
BranchTrueFalseTotal
if (arena_bytes > UINT32_MAX) croak("Data::Intern::Shared->new_memfd: arena_bytes exceeds 2^32"); 0 2 2
73 2 SiHandle *h = si_create_memfd(nm, (uint32_t)max_strings, (uint32_t)arena_bytes, errbuf);
74 2 ▶ if (!h) croak("Data::Intern::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Intern::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 2 2
if (!h) croak("Data::Intern::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); 0 0 0
75 2 MAKE_OBJ(class, h);
76 OUTPUT:
77 RETVAL
78  
79 SV *
80 new_from_fd(class, fd)
81 const char *class
82 int fd
83 PREINIT:
84 char errbuf[SI_ERR_BUFLEN];
85 CODE:
86 2 SiHandle *h = si_open_fd(fd, errbuf);
87 2 ▶ if (!h) croak("Data::Intern::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!h) croak("Data::Intern::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 1 2
if (!h) croak("Data::Intern::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); 1 0 1
88 1 MAKE_OBJ(class, h);
89 OUTPUT:
90 RETVAL
91  
92 SV *
93 new_readonly(class, path)
94 const char *class
95 SV *path
96 PREINIT:
97 char errbuf[SI_ERR_BUFLEN];
98 CODE:
99 /* Open a FROZEN (sealed) file read-only: O_RDONLY + PROT_READ, no lock
100 ever. A sealed file is immutable and no read path writes the mapping,
101 so queries take no reader-slot / rwlock traffic and any number of
102 processes can share one PROT_READ mapping (same architecture; the
103 magic rejects a wrong-endian file). */
104 11 ▶ 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 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
105 6 ▶ if (!p) croak("Data::Intern::Shared->new_readonly: path is required");
Branch: 1 branch
BranchTrueFalseTotal
if (!p) croak("Data::Intern::Shared->new_readonly: path is required"); 1 5 6
106 5 SiHandle *h = si_open_readonly(p, errbuf);
107 5 ▶ if (!h) croak("Data::Intern::Shared->new_readonly: %s", errbuf);
Branch: 1 branch
BranchTrueFalseTotal
if (!h) croak("Data::Intern::Shared->new_readonly: %s", errbuf); 2 3 5
108 3 class = SvPV_nolen(ST(0)); /* re-read after path's magic: a tied/overloaded arg can realloc/free ST(0)'s PV before it is used to bless */
109 3 MAKE_OBJ(class, h);
110 OUTPUT:
111 RETVAL
112  
113 void
114 DESTROY(self)
115 SV *self
116 CODE:
117 41 ▶ if (sv_isobject(self) && sv_derived_from(self, "Data::Intern::Shared")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self) && sv_derived_from(self, "Data::Intern::Shared")) { 41 0 41
if (sv_isobject(self) && sv_derived_from(self, "Data::Intern::Shared")) { 41 0 41
118 41 SiHandle *h = INT2PTR(SiHandle*, SvIV(SvRV(self)));
119 41 ▶ if (h) { sv_setiv(SvRV(self), 0); si_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */
Branch: 1 branch
BranchTrueFalseTotal
if (h) { sv_setiv(SvRV(self), 0); si_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */ 40 1 41
120 }
121  
122 UV
123 count(self)
124 SV *self
125 PREINIT:
126 33 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 33 0 33
EXTRACT(self); 0 33 33
EXTRACT(self); 1 32 33
127 CODE:
128 32 ▶ if (h->readonly) { /* frozen: immutable, no lock needed */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock needed */ 4 28 32
129 4 RETVAL = h->hdr->count;
130 } else {
131 28 si_rwlock_rdlock(h);
132 28 RETVAL = h->hdr->count;
133 28 si_rwlock_rdunlock(h);
134 }
135 OUTPUT:
136 RETVAL
137  
138 UV
139 max_strings(self)
140 SV *self
141 PREINIT:
142 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
143 CODE:
144 4 ▶ RETVAL = h->hdr->max_strings;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->hdr->max_strings; 0 4 4
145 OUTPUT:
146 RETVAL
147  
148 UV
149 arena_bytes(self)
150 SV *self
151 PREINIT:
152 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
153 CODE:
154 4 ▶ RETVAL = h->hdr->arena_bytes;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->hdr->arena_bytes; 0 4 4
155 OUTPUT:
156 RETVAL
157  
158 UV
159 arena_used(self)
160 SV *self
161 PREINIT:
162 8 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 8 0 8
EXTRACT(self); 0 8 8
EXTRACT(self); 0 8 8
163 CODE:
164 8 ▶ if (h->readonly) { /* frozen: immutable, no lock needed */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock needed */ 2 6 8
165 2 RETVAL = h->hdr->arena_used;
166 } else {
167 6 si_rwlock_rdlock(h);
168 6 RETVAL = h->hdr->arena_used;
169 6 si_rwlock_rdunlock(h);
170 }
171 OUTPUT:
172 RETVAL
173  
174 void
175 clear(self)
176 SV *self
177 PREINIT:
178 9 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 9 0 9
EXTRACT(self); 0 9 9
EXTRACT(self); 0 9 9
179 CODE:
180 9 ▶ if (h->readonly) croak("Data::Intern::Shared->clear: table is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::Intern::Shared->clear: table is frozen (read-only)"); 2 7 9
181 7 si_rwlock_wrlock(h);
182 7 ▶ if (h->hdr->sealed) { si_rwlock_wrunlock(h); croak("Data::Intern::Shared->clear: table is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { si_rwlock_wrunlock(h); croak("Data::Intern::Shared->clear: table is frozen (read-only)"); } 1 6 7
183 6 si_clear_locked(h);
184 6 si_rwlock_wrunlock(h);
185  
186 SV *
187 intern(self, str)
188 SV *self
189 SV *str
190 PREINIT:
191 53847 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 53847 0 53847
EXTRACT(self); 0 53847 53847
EXTRACT(self); 0 53847 53847
192 STRLEN n;
193 const char *s;
194 int64_t id;
195 CODE:
196 53847 ▶ if (h->readonly) croak("Data::Intern::Shared->intern: table is frozen (read-only)");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::Intern::Shared->intern: table is frozen (read-only)"); 3 53844 53847
197 53844 s = SvPVbyte(str, n);
198 53844 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 53844 53844
REEXTRACT(self); 0 53844 53844
199 53844 si_rwlock_wrlock(h);
200 53844 ▶ if (h->hdr->sealed) { si_rwlock_wrunlock(h); croak("Data::Intern::Shared->intern: table is frozen (read-only)"); }
Branch: 1 branch
BranchTrueFalseTotal
if (h->hdr->sealed) { si_rwlock_wrunlock(h); croak("Data::Intern::Shared->intern: table is frozen (read-only)"); } 1 53843 53844
201 53843 id = si_intern_locked(h, s, n);
202 53843 __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED);
203 53843 si_rwlock_wrunlock(h);
204 53843 ▶ RETVAL = (id < 0) ? &PL_sv_undef : newSVuv((UV)id);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (id < 0) ? &PL_sv_undef : newSVuv((UV)id); 53839 4 53843
205 OUTPUT:
206 RETVAL
207  
208 void
209 freeze(self)
210 SV *self
211 PREINIT:
212 6 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 6 0 6
EXTRACT(self); 0 6 6
EXTRACT(self); 0 6 6
213 CODE:
214 6 ▶ if (h->readonly) croak("Data::Intern::Shared->freeze: cannot freeze a read-only handle");
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) croak("Data::Intern::Shared->freeze: cannot freeze a read-only handle"); 2 4 6
215 4 ▶ if (si_freeze(h) != 0) croak("Data::Intern::Shared->freeze: msync: %s", strerror(errno));
Branch: 1 branch
BranchTrueFalseTotal
if (si_freeze(h) != 0) croak("Data::Intern::Shared->freeze: msync: %s", strerror(errno)); 0 4 4
216 4 h->readonly = 1; /* this handle now rejects mutation too (the file is sealed) */
217  
218 UV
219 frozen(self)
220 SV *self
221 PREINIT:
222 4 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 4 0 4
EXTRACT(self); 0 4 4
EXTRACT(self); 0 4 4
223 CODE:
224 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
225 OUTPUT:
226 RETVAL
227  
228 UV
229 readonly(self)
230 SV *self
231 PREINIT:
232 5 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 5 0 5
EXTRACT(self); 0 5 5
EXTRACT(self); 0 5 5
233 CODE:
234 5 ▶ RETVAL = h->readonly ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->readonly ? 1 : 0; 0 5 5
235 OUTPUT:
236 RETVAL
237  
238 SV *
239 id_of(self, str)
240 SV *self
241 SV *str
242 PREINIT:
243 42192 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 42192 0 42192
EXTRACT(self); 0 42192 42192
EXTRACT(self); 0 42192 42192
244 STRLEN n;
245 const char *s;
246 uint32_t id;
247 int found;
248 CODE:
249 42192 s = SvPVbyte(str, n);
250 42192 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 42192 42192
REEXTRACT(self); 0 42192 42192
251 42192 ▶ if (h->readonly) { /* frozen: immutable, no lock needed */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock needed */ 58 42134 42192
252 58 found = si_id_of_locked(h, s, n, &id);
253 } else {
254 42134 si_rwlock_rdlock(h);
255 42134 found = si_id_of_locked(h, s, n, &id);
256 42134 si_rwlock_rdunlock(h);
257 }
258 42192 ▶ RETVAL = found ? newSVuv(id) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = found ? newSVuv(id) : &PL_sv_undef; 42189 3 42192
259 OUTPUT:
260 RETVAL
261  
262 SV *
263 string(self, id)
264 SV *self
265 UV id
266 PREINIT:
267 42196 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 42196 0 42196
EXTRACT(self); 0 42196 42196
EXTRACT(self); 0 42196 42196
268 CODE:
269 {
270 42196 char *tmp = NULL; uint32_t tl = 0; int found = 0;
271 42196 ▶ if (!h->readonly) si_rwlock_rdlock(h); /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) si_rwlock_rdlock(h); /* frozen: immutable, no lock */ 42139 57 42196
272 /* id, reverse[id] and the arena length prefix are all file-stored and
273 * attacker-controlled; bound each before dereferencing so a corrupted
274 * segment yields undef instead of an out-of-bounds read/trap. Valid
275 * data always satisfies off+4+len <= arena_used, so behavior is
276 * unchanged in normal use. */
277 /* count/arena_used are mutable peer-writable header words; clamp each to
278 * the cached physical array size before using it as the id / offset
279 * bound, so a corrupted over-large counter cannot admit an OOB index. */
280 42196 uint32_t count = h->hdr->count;
281 42196 ▶ if (count > h->max_strings) count = h->max_strings;
Branch: 1 branch
BranchTrueFalseTotal
if (count > h->max_strings) count = h->max_strings; 0 42196 42196
282 42196 ▶ if (id < count) {
Branch: 1 branch
BranchTrueFalseTotal
if (id < count) { 42192 4 42196
283 42192 uint32_t off = h->reverse[id];
284 42192 uint32_t used = h->hdr->arena_used;
285 42192 ▶ if (used > h->arena_bytes) used = h->arena_bytes;
Branch: 1 branch
BranchTrueFalseTotal
if (used > h->arena_bytes) used = h->arena_bytes; 0 42192 42192
286 42192 ▶ if (off <= used && used - off >= sizeof(uint32_t)) {
Branch: 2 branches
BranchTrueFalseTotal
if (off <= used && used - off >= sizeof(uint32_t)) { 42192 0 42192
if (off <= used && used - off >= sizeof(uint32_t)) { 42192 0 42192
287 uint32_t l;
288 42192 const char *str = si_arena_str(h, off, &l);
289 42192 ▶ if (l <= used - off - (uint32_t)sizeof(uint32_t)) {
Branch: 1 branch
BranchTrueFalseTotal
if (l <= used - off - (uint32_t)sizeof(uint32_t)) { 42192 0 42192
290 42192 found = 1; tl = l;
291 /* Copy out with a non-croaking malloc so the SV can be
292 * built AFTER unlocking: newSVpvn can croak on OOM, and a
293 * croak while holding the rdlock would leak it and wedge
294 * every writer. */
295 42192 ▶ if (l) { tmp = (char *)malloc(l); if (tmp) memcpy(tmp, str, l); }
Branch: 2 branches
BranchTrueFalseTotal
if (l) { tmp = (char *)malloc(l); if (tmp) memcpy(tmp, str, l); } 42189 3 42192
if (l) { tmp = (char *)malloc(l); if (tmp) memcpy(tmp, str, l); } 42189 0 42189
296 }
297 }
298 }
299 42196 ▶ if (!h->readonly) si_rwlock_rdunlock(h);
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) si_rwlock_rdunlock(h); 42139 57 42196
300 42196 ▶ if (!found) RETVAL = &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
if (!found) RETVAL = &PL_sv_undef; 4 42192 42196
301 42192 ▶ else if (tl == 0) RETVAL = newSVpvn("", 0);
Branch: 1 branch
BranchTrueFalseTotal
else if (tl == 0) RETVAL = newSVpvn("", 0); 3 42189 42192
302 42189 ▶ else if (tmp) { RETVAL = newSVpvn(tmp, tl); free(tmp); }
Branch: 1 branch
BranchTrueFalseTotal
else if (tmp) { RETVAL = newSVpvn(tmp, tl); free(tmp); } 42189 0 42189
303 0 else croak("Data::Intern::Shared->string: out of memory");
304 }
305 OUTPUT:
306 RETVAL
307  
308 bool
309 exists(self, str)
310 SV *self
311 SV *str
312 PREINIT:
313 35670 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 35670 0 35670
EXTRACT(self); 0 35670 35670
EXTRACT(self); 0 35670 35670
314 STRLEN n;
315 const char *s;
316 uint32_t id;
317 CODE:
318 35670 s = SvPVbyte(str, n);
319 35670 ▶ REEXTRACT(self);
Branch: 2 branches
BranchTrueFalseTotal
REEXTRACT(self); 0 35670 35670
REEXTRACT(self); 0 35670 35670
320 35670 ▶ if (h->readonly) { /* frozen: immutable, no lock needed */
Branch: 1 branch
BranchTrueFalseTotal
if (h->readonly) { /* frozen: immutable, no lock needed */ 55 35615 35670
321 55 RETVAL = si_id_of_locked(h, s, n, &id);
322 } else {
323 35615 si_rwlock_rdlock(h);
324 35615 RETVAL = si_id_of_locked(h, s, n, &id);
325 35615 si_rwlock_rdunlock(h);
326 }
327 OUTPUT:
328 RETVAL
329  
330 SV *
331 stats(self)
332 SV *self
333 PREINIT:
334 2 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 2 0 2
EXTRACT(self); 0 2 2
EXTRACT(self); 0 2 2
335 CODE:
336 {
337 uint32_t count, max_strings, hash_slots, arena_used, arena_bytes;
338 uint64_t ops;
339 uint8_t sealed;
340 /* Snapshot the header fields under the lock; do all (croak-capable) Perl
341 allocation after releasing it -- an OOM in newHV/newSVuv must never
342 strand the read lock. */
343 2 ▶ if (!h->readonly) si_rwlock_rdlock(h); /* frozen: immutable, no lock */
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) si_rwlock_rdlock(h); /* frozen: immutable, no lock */ 1 1 2
344 2 SiHeader *hd = h->hdr;
345 2 count = hd->count;
346 2 max_strings = hd->max_strings;
347 2 hash_slots = hd->hash_slots;
348 2 arena_used = hd->arena_used;
349 2 arena_bytes = hd->arena_bytes;
350 2 ops = hd->stat_ops;
351 2 sealed = __atomic_load_n(&hd->sealed, __ATOMIC_ACQUIRE);
352 2 ▶ if (!h->readonly) si_rwlock_rdunlock(h);
Branch: 1 branch
BranchTrueFalseTotal
if (!h->readonly) si_rwlock_rdunlock(h); 1 1 2
353  
354 2 HV *hv = newHV();
355 2 hv_stores(hv, "count", newSVuv(count));
356 2 hv_stores(hv, "max_strings", newSVuv(max_strings));
357 2 hv_stores(hv, "hash_slots", newSVuv(hash_slots));
358 2 hv_stores(hv, "hash_load", newSVnv((double)count / (double)hash_slots));
359 2 hv_stores(hv, "arena_used", newSVuv(arena_used));
360 2 hv_stores(hv, "arena_bytes", newSVuv(arena_bytes));
361 2 hv_stores(hv, "arena_load", newSVnv((double)arena_used / (double)arena_bytes));
362 2 hv_stores(hv, "ops", newSVuv(ops));
363 2 hv_stores(hv, "mmap_size", newSVuv((UV)h->mmap_size));
364 2 hv_stores(hv, "frozen", newSVuv(sealed ? 1 : 0));
365 2 hv_stores(hv, "readonly", newSVuv(h->readonly ? 1 : 0));
366 2 RETVAL = newRV_noinc((SV *)hv);
367 }
368 OUTPUT:
369 RETVAL
370  
371 SV *
372 path(self)
373 SV *self
374 PREINIT:
375 5 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 5 0 5
EXTRACT(self); 0 5 5
EXTRACT(self); 0 5 5
376 CODE:
377 5 ▶ RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; 2 3 5
378 OUTPUT:
379 RETVAL
380  
381 int
382 memfd(self)
383 SV *self
384 PREINIT:
385 5 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 5 0 5
EXTRACT(self); 0 5 5
EXTRACT(self); 0 5 5
386 CODE:
387 5 ▶ RETVAL = h->backing_fd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = h->backing_fd; 0 5 5
388 OUTPUT:
389 RETVAL
390  
391 void
392 sync(self)
393 SV *self
394 PREINIT:
395 5 ▶ EXTRACT(self);
Branch: 3 branches
BranchTrueFalseTotal
EXTRACT(self); 5 0 5
EXTRACT(self); 0 5 5
EXTRACT(self); 0 5 5
396 CODE:
397 5 ▶ if (!h->readonly && si_msync(h) != 0) croak("sync: %s", strerror(errno));
Branch: 2 branches
BranchTrueFalseTotal
if (!h->readonly && si_msync(h) != 0) croak("sync: %s", strerror(errno)); 4 1 5
if (!h->readonly && si_msync(h) != 0) croak("sync: %s", strerror(errno)); 0 4 4
398  
399 void
400 unlink(self, ...)
401 SV *self
402 CODE:
403 3 ▶ if (sv_isobject(self) && sv_derived_from(self, "Data::Intern::Shared")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(self) && sv_derived_from(self, "Data::Intern::Shared")) { 1 1 2
if (sv_isobject(self) && sv_derived_from(self, "Data::Intern::Shared")) { 1 0 1
404 1 SiHandle *h = INT2PTR(SiHandle*, SvIV(SvRV(self)));
405 1 ▶ if (h && h->path && unlink(h->path) != 0 && errno != ENOENT)
Branch: 4 branches
BranchTrueFalseTotal
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 1 0 1
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 1 0 1
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 1 1
if (h && h->path && unlink(h->path) != 0 && errno != ENOENT) 0 0 0
406 0 croak("Data::Intern::Shared->unlink(%s): %s", h->path, strerror(errno));
407 1 ▶ } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) {
Branch: 4 branches
BranchTrueFalseTotal
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 1 0 1
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 0 1 1
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 0 0 0
} else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { 1 0 1
408 {
409 1 const char *up = SvPV_nolen(ST(1));
410 1 ▶ if (unlink(up) != 0 && errno != ENOENT)
Branch: 2 branches
BranchTrueFalseTotal
if (unlink(up) != 0 && errno != ENOENT) 0 1 1
if (unlink(up) != 0 && errno != ENOENT) 0 0 0
411 0 croak("Data::Intern::Shared->unlink(%s): %s", up, strerror(errno));
412 }
413 }
« intern.h ↑ Summary