Streamer.xs

filter: Statementstmt 40.9% 138 / 337 Branchbran 36.8% 90 / 244 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 39.2% 228 / 581 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Data/Dump/Streamer.pm ↑ Summary dds_api.c »
1 /*
2 * Streamer.xs
3 *
4 * Code from Array::RefElem
5 * Copyright (c) 1997-2000 Graham Barr <gbarr@pobox.com>. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the same terms as Perl itself.
8 *
9 * Code From Scalar::Util
10 * Copyright 2000 Gisle Aas.
11 * This library is free software; you can redistribute it and/or
12 * modify it under the same terms as Perl itself.
13 * A good chunk of the XS is morphed or taken directly from this module.
14 * Thanks Gisle.
15 *
16 * alias_ref is from Lexical::Alias by Jeff Pinyan which
17 * was borrowed/modified from Devel::LexAlias by Richard Clamp
18 *
19 *
20 * Additional Code and Modifications
21 * Copyright 2003 Yves Orton.
22 * This library is free software; you can redistribute it and/or
23 * modify it under the same terms as Perl itself.
24 *
25 */
26  
27 #define PERL_NO_GET_CONTEXT
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 #include "EXTERN.h"
32 #include "perl.h"
33 #include "XSUB.h"
34 #include "dds_engine.h"
35 #ifdef __cplusplus
36 }
37 #endif
38  
39 #ifndef PERL_VERSION
40 #include <patchlevel.h>
41 #if !(defined(PERL_VERSION) || (PERL_SUBVERSION > 0 && defined(PATCHLEVEL)))
42 #include <could_not_find_Perl_patchlevel.h>
43 #endif
44 #define PERL_REVISION 5
45 #define PERL_VERSION PATCHLEVEL
46 #define PERL_SUBVERSION PERL_SUBVERSION
47 #endif
48 #if PERL_VERSION < 8
49 #define PERL_MAGIC_qr 'r' /* precompiled qr// regex */
50 #define BFD_Svs_SMG_OR_RMG SVs_RMG
51 #elif ((PERL_VERSION == 8) && (PERL_SUBVERSION >= 1) || (PERL_VERSION > 8))
52 #define BFD_Svs_SMG_OR_RMG SVs_SMG
53 #define MY_PLACEHOLDER PL_sv_placeholder
54 #else
55 #define BFD_Svs_SMG_OR_RMG SVs_RMG
56 #define MY_PLACEHOLDER PL_sv_undef
57 #endif
58 #if (((PERL_VERSION == 9) && (PERL_SUBVERSION >= 4)) || (PERL_VERSION > 9))
59 #define NEW_REGEX_ENGINE 1
60 #endif
61 #if (((PERL_VERSION == 8) && (PERL_SUBVERSION >= 1)) || (PERL_VERSION > 8))
62 #define MY_CAN_FIND_PLACEHOLDERS
63 #define HAS_SV2OBJ
64 #endif
65  
66 #ifdef SvWEAKREF
67  
68 #ifndef PERL_MAGIC_backref
69 #define PERL_MAGIC_backref '<'
70 #endif
71  
72 #define ADD_WEAK_REFCOUNT RETVAL += dds_weak_count(aTHX_ sv)
73 #else
74 #define ADD_WEAK_REFCOUNT
75 #endif
76  
77 #if PERL_VERSION < 7
78 /* Not in 5.6.1. */
79 #define SvUOK(sv) SvIOK_UV(sv)
80 #ifdef cxinc
81 #undef cxinc
82 #endif
83 #define cxinc() my_cxinc(aTHX)
84 /* Grow the legacy interpreter context stack and return its next slot. */
85 static I32 my_cxinc(pTHX)
86 {
87 cxstack_max = cxstack_max * 3 / 2;
88 Renew(cxstack, cxstack_max + 1, struct context); /* XXX should fix CXINC macro */
89 return cxstack_ix + 1;
90 }
91 #endif
92  
93 #if PERL_VERSION < 6
94 #define NV double
95 #endif
96  
97 #if PERL_VERSION < 8
98 #define MY_XS_AMAGIC
99 #endif
100 #if ((PERL_VERSION == 8) && (PERL_SUBVERSION <= 8))
101 #define MY_XS_AMAGIC
102 #endif
103  
104 /*
105 the following two subs are outright stolen from Data::Dumper ( Dumper.xs )
106 from the 5.6.1 distribution of Perl. Probably Gurusamy Sarathy's work.
107 As is much of the code in _globname and globname
108 */
109  
110 /* Test whether a glob name needs quoting rather than bareword syntax. */
111 0 static I32 needs_q(register char *s)
112 {
113 0 TOP:
114 0 ▶ if (s[0] == ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (s[0] == ':') { 0 0 0
115 0 ▶ if (*++s) {
Branch: 1 branch
BranchTrueFalseTotal
if (*++s) { 0 0 0
116 0 ▶ if (*s++ != ':')
Branch: 1 branch
BranchTrueFalseTotal
if (*s++ != ':') 0 0 0
117 0 return 1;
118 } else
119 0 return 1;
120 }
121 0 ▶ if (isIDFIRST(*s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isIDFIRST(*s)) { 0 0 0
122 0 ▶ while (*++s)
Branch: 1 branch
BranchTrueFalseTotal
while (*++s) 0 0 0
123 0 ▶ if (!isALNUM(*s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!isALNUM(*s)) { 0 0 0
124 0 ▶ if (*s == ':')
Branch: 1 branch
BranchTrueFalseTotal
if (*s == ':') 0 0 0
125 0 goto TOP;
126 else
127 0 return 1;
128 }
129 } else
130 0 return 1;
131 0 return 0;
132 }
133  
134 /* Copy slen bytes with single-quote/backslash escaping and return the
135 * number of inserted bytes; the caller provides sufficient destination space. */
136 0 static I32 esc_q(register char *d, register char *s, register STRLEN slen)
137 {
138 0 register I32 ret = 0;
139  
140 0 ▶ while (slen > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (slen > 0) { 0 0 0
141 0 ▶ switch (*s) {
Branch: 1 branch
BranchTrueFalseTotal
switch (*s) { 0 0 0
142 0 case '\'':
143 case '\\':
144 0 *d = '\\';
145 0 ++d;
146 0 ++ret;
147 0 default:
148 0 *d = *s;
149 0 ++d;
150 0 ++s;
151 0 --slen;
152 0 break;
153 }
154 }
155 0 return ret;
156 }
157  
158 XS(XS_Data__Dump__Streamer_SvREADONLY);
159 /* Inspect or directly change the readonly flag of a supplied reference's
160 * referent.
161 */
162 0 XS(XS_Data__Dump__Streamer_SvREADONLY) /* This is dangerous stuff. */
163 {
164 0 dXSARGS;
165 0 SV *sv = SvRV(ST(0));
166  
167 0 ▶ if (items == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) { 0 0 0
168 0 ▶ if (SvREADONLY(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(sv)) 0 0 0
169 0 XSRETURN_YES;
170 else
171 0 XSRETURN_NO;
172 0 ▶ } else if (items == 2) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (items == 2) { 0 0 0
173 0 ▶ if (SvTRUE(ST(1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(ST(1))) { 0 0 0
174 0 SvREADONLY_on(sv);
175 0 XSRETURN_YES;
176 } else {
177 /* I hope you really know what you are doing. */
178 0 SvREADONLY_off(sv);
179 0 XSRETURN_NO;
180 }
181 }
182 0 XSRETURN_UNDEF; /* Can't happen. */
183 }
184  
185 XS(XS_Data__Dump__Streamer_SvREFCNT);
186 /* Inspect or directly replace a referent's raw strong count; the getter
187 * discounts the argument reference.
188 */
189 0 XS(XS_Data__Dump__Streamer_SvREFCNT) /* This is dangerous stuff. */
190 {
191 0 dXSARGS;
192 0 SV *sv = SvRV(ST(0));
193  
194 0 ▶ if (items == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) 0 0 0
195 0 XSRETURN_IV(SvREFCNT(sv) - 1); /* Minus the ref created for us. */
196 0 ▶ else if (items == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (items == 2) { 0 0 0
197 /* I hope you really know what you are doing. */
198 0 SvREFCNT(sv) = SvIV(ST(1));
199 0 XSRETURN_IV(SvREFCNT(sv));
200 }
201 0 XSRETURN_UNDEF; /* Can't happen. */
202 }
203  
204 /* this is from B is perl 5.9.2 */
205 typedef SV *B__SV;
206  
207 MODULE = B PACKAGE = B::SV
208  
209 #ifndef HAS_SV2OBJ
210  
211 #define object_2svref(sv) sv
212 #define SVREF SV *
213  
214 # Recover a Perl reference from a B::SV wrapper on interpreters lacking the
215 # core method.
216 SVREF
217 object_2svref(sv)
218 B::SV sv
219  
220 #endif
221  
222 MODULE = Data::Dump::Streamer PACKAGE = Data::Dump::Streamer
223  
224 # Return a diagnostic snapshot of native traversal counts, queue usage and
225 # retained callback values.
226 SV *
227 _xs_stats(self)
228 SV *self
229 CODE:
230 {
231 3 dds_ctx *ctx = dds_context(aTHX_ self);
232 3 HV *stats = newHV();
233  
234 3 hv_stores(stats, "visits", newSVuv(ctx->visits));
235 3 hv_stores(stats, "lookups", newSVuv(ctx->lookups));
236 3 hv_stores(stats, "candidates", newSVuv(ctx->candidates));
237 3 hv_stores(stats, "repeats", newSVuv(ctx->repeats));
238 3 hv_stores(stats, "queue_peak", newSVuv(ctx->queue_peak));
239 3 hv_stores(stats, "keepalive", newSViv(av_len(ctx->keepalive) + 1));
240 3 hv_stores(stats, "fixes", newSVuv(ctx->fixes));
241 3 RETVAL = newRV_noinc((SV *)stats);
242 }
243 OUTPUT:
244 RETVAL
245  
246 # Return copied diagnostic rows for scalar-slot and referent roles without
247 # dereferencing catalogue address keys.
248 SV *
249 _xs_catalogue(self)
250 SV *self
251 CODE:
252 {
253 3 dds_ctx *ctx = dds_context(aTHX_ self);
254 3 HV *view = newHV();
255 3 AV *slots = newAV(), *references = newAV();
256 UV i;
257  
258 3 hv_stores(view, "slots", newRV_noinc((SV *)slots));
259 3 hv_stores(view, "references", newRV_noinc((SV *)references));
260 3 ▶ if (ctx->table.buckets)
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->table.buckets) 3 0 3
261 99 ▶ for (i = 0; i <= ctx->table.mask; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= ctx->table.mask; i++) { 96 3 99
262 dds_node *node;
263  
264 102 ▶ for (node = ctx->table.buckets[i]; node; node = node->next) {
Branch: 1 branch
BranchTrueFalseTotal
for (node = ctx->table.buckets[i]; node; node = node->next) { 6 96 102
265 int r;
266  
267 18 ▶ for (r = 0; r < 2; r++) {
Branch: 1 branch
BranchTrueFalseTotal
for (r = 0; r < 2; r++) { 12 6 18
268 12 ▶ dds_role *role = r ? &node->ref : &node->slot;
Branch: 1 branch
BranchTrueFalseTotal
dds_role *role = r ? &node->ref : &node->slot; 6 6 12
269 HV *row;
270  
271 12 ▶ if (!role->present)
Branch: 1 branch
BranchTrueFalseTotal
if (!role->present) 6 6 12
272 6 continue;
273 6 row = newHV();
274 6 hv_stores(row, "address", newSVuv(node->address));
275 6 hv_stores(row, "name", newSVsv(role->name));
276 6 hv_stores(row, "depth", newSVuv(role->depth));
277 6 hv_stores(row, "count", newSVuv(role->count));
278 6 hv_stores(row, "encounters", newSVuv(role->encounters));
279 6 hv_stores(row, "readonly", newSViv(role->readonly));
280 6 hv_stores(row, "weak", newSViv(role->weak));
281 6 ▶ hv_stores(row, "done", newSViv(role->done && role->done->ready));
Branch: 2 branches
BranchTrueFalseTotal
hv_stores(row, "done", newSViv(role->done && role->done->ready)); 2 4 6
hv_stores(row, "done", newSViv(role->done && role->done->ready)); 2 0 2
282 6 ▶ av_push(r ? references : slots, newRV_noinc((SV *)row));
Branch: 1 branch
BranchTrueFalseTotal
av_push(r ? references : slots, newRV_noinc((SV *)row)); 3 3 6
283 }
284 }
285 }
286  
287 3 RETVAL = newRV_noinc((SV *)view);
288 }
289 OUTPUT:
290 RETVAL
291  
292 # Return references to a closure's captured pad values, indexed by both
293 # lexical name and pad offset for the deparser.
294 SV *
295 _xs_get_lexicals(rv)
296 SV *rv
297 CODE:
298 {
299 102 HV *values = newHV();
300 CV *cv;
301  
302 102 ▶ if (!SvROK(rv) || SvTYPE(SvRV(rv)) != SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(rv) || SvTYPE(SvRV(rv)) != SVt_PVCV) 102 0 102
if (!SvROK(rv) || SvTYPE(SvRV(rv)) != SVt_PVCV) 0 102 102
303 0 croak("Expected a code reference");
304 102 cv = (CV *)SvRV(rv);
305 102 ▶ if (!CvISXSUB(cv) && CvPADLIST(cv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!CvISXSUB(cv) && CvPADLIST(cv)) { 102 0 102
if (!CvISXSUB(cv) && CvPADLIST(cv)) { 101 1 102
306 #if PERL_VERSION >= 18
307 101 PADLIST *padlist = CvPADLIST(cv);
308 101 PADNAMELIST *names = PadlistNAMES(padlist);
309 101 ▶ PAD *pad = PadlistARRAY(padlist)[CvDEPTH(cv) ? CvDEPTH(cv) : 1];
Branch: 1 branch
BranchTrueFalseTotal
PAD *pad = PadlistARRAY(padlist)[CvDEPTH(cv) ? CvDEPTH(cv) : 1]; 0 101 101
310 #else
311 AV *padlist = (AV *)CvPADLIST(cv);
312 AV *names = (AV *)AvARRAY(padlist)[0];
313 AV *pad = (AV *)AvARRAY(padlist)[CvDEPTH(cv) ? CvDEPTH(cv) : 1];
314 #endif
315 SSize_t i;
316 #if PERL_VERSION >= 18
317 329 ▶ for (i = PadnamelistMAX(names); i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = PadnamelistMAX(names); i >= 0; i--) { 228 101 329
318 228 PADNAME *name = PadnamelistARRAY(names)[i];
319 #else
320 for (i = av_len(names); i >= 0; i--) {
321 SV *name = AvARRAY(names)[i];
322 #endif
323 #if PERL_VERSION >= 18
324 228 ▶ if (name && PadnamePV(name) && PadnameOUTER(name) && !PadnameIsOUR(name)) {
Branch: 4 branches
BranchTrueFalseTotal
if (name && PadnamePV(name) && PadnameOUTER(name) && !PadnameIsOUR(name)) { 228 0 228
if (name && PadnamePV(name) && PadnameOUTER(name) && !PadnameIsOUR(name)) { 99 129 228
if (name && PadnamePV(name) && PadnameOUTER(name) && !PadnameIsOUR(name)) { 85 14 99
if (name && PadnamePV(name) && PadnameOUTER(name) && !PadnameIsOUR(name)) { 81 4 85
325 #else
326 if (name && SvPOK(name) && SvFAKE(name) && !SvPAD_OUR(name)) {
327 #endif
328 81 SV **value = av_fetch(pad, i, 0);
329  
330 81 ▶ if (value && *value) {
Branch: 2 branches
BranchTrueFalseTotal
if (value && *value) { 81 0 81
if (value && *value) { 81 0 81
331 81 SV *index = sv_2mortal(newSViv(i));
332 81 SV *ref = sv_2mortal(newRV_inc(*value));
333 #if PERL_VERSION >= 18
334 81 hv_store(values, PadnamePV(name),
335 PadnameUTF8(name) ? -(I32)PadnameLEN(name) : (I32)PadnameLEN(name),
336 newSVsv(ref), 0);
337 #else
338 hv_store_ent(values, name, newSVsv(ref), 0);
339 #endif
340 81 hv_store_ent(values, index, newSVsv(ref), 0);
341 }
342 }
343 }
344 }
345  
346 102 RETVAL = newRV_noinc((SV *)values);
347 }
348 OUTPUT:
349 RETVAL
350  
351 # Construct a scalar with independently supplied numeric and string values,
352 # preserving the string UTF-8 flag and input taint.
353 void
354 dualvar(num,str)
355 SV *num
356 SV *str
357 PROTOTYPE: $$
358 CODE:
359 {
360 STRLEN len;
361 10 char *ptr = SvPV(str, len);
362  
363 10 ST(0) = sv_newmortal();
364 10 ▶ (void)SvUPGRADE(ST(0), SVt_PVNV);
Branch: 1 branch
BranchTrueFalseTotal
(void)SvUPGRADE(ST(0), SVt_PVNV); 10 0 10
365 10 sv_setpvn(ST(0), ptr, len);
366 10 ▶ if (SvUTF8(str))
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(str)) 1 9 10
367 1 SvUTF8_on(ST(0));
368  
369 10 ▶ if (SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) {
Branch: 3 branches
BranchTrueFalseTotal
if (SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) { 10 0 10
if (SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) { 10 0 10
if (SvNOK(num) || SvPOK(num) || SvMAGICAL(num)) { 0 10 10
370 0 SvNVX(ST(0)) = SvNV(num);
371 0 SvNOK_on(ST(0));
372 }
373 #ifdef SVf_IVisUV
374 10 ▶ else if (SvUOK(num)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvUOK(num)) { 2 8 10
375 2 SvUVX(ST(0)) = SvUV(num);
376 2 SvIOK_on(ST(0));
377 2 SvIsUV_on(ST(0));
378 }
379 #endif
380 else {
381 8 SvIVX(ST(0)) = SvIV(num);
382 8 SvIOK_on(ST(0));
383 }
384  
385 10 ▶ if (PL_tainting && (SvTAINTED(num) || SvTAINTED(str)))
Branch: 5 branches
BranchTrueFalseTotal
if (PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 10 10
if (PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
if (PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
if (PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
if (PL_tainting && (SvTAINTED(num) || SvTAINTED(str))) 0 0 0
386 0 ▶ SvTAINTED_on(ST(0));
Branch: 1 branch
BranchTrueFalseTotal
SvTAINTED_on(ST(0)); 0 0 0
387 10 XSRETURN(1);
388 }
389  
390 # Test whether a scalar currently has both numeric and string value flags; the
391 # values may still represent the same text.
392 bool
393 _could_be_dualvar(sv)
394 SV *sv
395 PROTOTYPE: $
396 CODE:
397 {
398 0 ▶ RETVAL = ((SvNIOK(sv)) && (SvPOK(sv))) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
RETVAL = ((SvNIOK(sv)) && (SvPOK(sv))) ? 1 : 0; 0 0 0
RETVAL = ((SvNIOK(sv)) && (SvPOK(sv))) ? 1 : 0; 0 0 0
RETVAL = ((SvNIOK(sv)) && (SvPOK(sv))) ? 1 : 0; 0 0 0
399 }
400 OUTPUT:
401 RETVAL
402  
403 # Replace an array element with the supplied scalar itself, preserving alias
404 # identity and transferring a retained reference to the array.
405 int
406 alias_av(avref, key, val)
407 SV *avref
408 I32 key
409 SV *val
410 PROTOTYPE: \@$$
411 PREINIT:
412 AV *av;
413 CODE:
414 {
415 559 ▶ if (!SvROK(avref) || SvTYPE(SvRV(avref)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(avref) || SvTYPE(SvRV(avref)) != SVt_PVAV) 559 0 559
if (!SvROK(avref) || SvTYPE(SvRV(avref)) != SVt_PVAV) 0 559 559
416 0 croak("First argument to alias_av() must be an array reference");
417 559 av = (AV *)SvRV(avref);
418 559 SvREFCNT_inc(val);
419 559 ▶ if (!av_store(av, key, val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!av_store(av, key, val)) { 0 559 559
420 0 SvREFCNT_dec(val);
421 0 RETVAL = 0;
422 } else {
423 559 RETVAL = 1;
424 }
425 }
426 OUTPUT:
427 RETVAL
428  
429 # Append the supplied scalar itself to an array, retaining the same SV instead
430 # of copying its value.
431 void
432 push_alias(avref, val)
433 SV *avref
434 SV *val
435 PROTOTYPE: \@$
436 PREINIT:
437 AV *av;
438 CODE:
439 1 ▶ if (!SvROK(avref) || SvTYPE(SvRV(avref)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(avref) || SvTYPE(SvRV(avref)) != SVt_PVAV) 1 0 1
if (!SvROK(avref) || SvTYPE(SvRV(avref)) != SVt_PVAV) 0 1 1
440 0 croak("First argument to push_alias() must be an array reference");
441 1 av = (AV *)SvRV(avref);
442 1 SvREFCNT_inc(val);
443 1 av_push(av, val);
444  
445 # Replace a hash value with the supplied scalar itself, preserving alias
446 # identity and retaining it for the hash.
447 int
448 alias_hv(hvref, key, val)
449 SV *hvref
450 SV *key
451 SV *val
452 PROTOTYPE: \%$$
453 PREINIT:
454 HV *hv;
455 CODE:
456 {
457 27 ▶ if (!SvROK(hvref) || SvTYPE(SvRV(hvref)) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(hvref) || SvTYPE(SvRV(hvref)) != SVt_PVHV) 27 0 27
if (!SvROK(hvref) || SvTYPE(SvRV(hvref)) != SVt_PVHV) 0 27 27
458 0 croak("First argument to alias_hv() must be a hash reference");
459 27 hv = (HV *)SvRV(hvref);
460 27 SvREFCNT_inc(val);
461 27 ▶ if (!hv_store_ent(hv, key, val, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_store_ent(hv, key, val, 0)) { 0 27 27
462 0 SvREFCNT_dec(val);
463 0 RETVAL = 0;
464 } else {
465 27 RETVAL = 1;
466 }
467 }
468 OUTPUT:
469 RETVAL
470  
471 # Fetch magic and return the class name of an object reference, or undef when
472 # the value is not an object.
473 char *
474 blessed(sv)
475 SV *sv
476 PROTOTYPE: $
477 CODE:
478 {
479 7 ▶ if (SvMAGICAL(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvMAGICAL(sv)) 0 7 7
480 0 mg_get(sv);
481 7 ▶ if (!sv_isobject(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(sv)) { 5 2 7
482 5 XSRETURN_UNDEF;
483 }
484 2 RETVAL = (char *)sv_reftype(SvRV(sv), TRUE);
485 }
486 OUTPUT:
487 RETVAL
488  
489 # Return the referent address of a reference, or zero for a nonreference.
490 UV
491 refaddr(sv)
492 SV *sv
493 PROTOTYPE: $
494 CODE:
495 {
496 319 ▶ if (!SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(sv)) { 3 316 319
497 3 RETVAL = 0;
498 } else {
499 316 RETVAL = PTR2UV(SvRV(sv));
500 }
501 }
502 OUTPUT:
503 RETVAL
504  
505 # Turn the supplied reference into a weak reference in place.
506 void
507 weaken(sv)
508 SV *sv
509 PROTOTYPE: $
510 CODE:
511 #ifdef SvWEAKREF
512 755 sv_rvweaken(sv);
513 755 XSRETURN_YES;
514 #else
515 croak("weak references are not implemented in this release of perl");
516 #endif
517  
518 # Report whether the supplied scalar currently holds a weak reference.
519 void
520 isweak(sv)
521 SV *sv
522 PROTOTYPE: $
523 CODE:
524 #ifdef SvWEAKREF
525 1 ▶ ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
Branch: 2 branches
BranchTrueFalseTotal
ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv)); 1 0 1
ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv)); 1 0 1
526 1 XSRETURN(1);
527 #else
528 XSRETURN_NO;
529 #endif
530  
531 # Count weak references pointing at the supplied scalar itself, without
532 # dereferencing it.
533 IV
534 weak_refcount(sv)
535 SV *sv
536 PROTOTYPE: $
537 CODE:
538 {
539 1 RETVAL = 0;
540 1 ▶ ADD_WEAK_REFCOUNT;
Branch: 1 branch
BranchTrueFalseTotal
ADD_WEAK_REFCOUNT; 0 1 1
541 }
542 OUTPUT:
543 RETVAL
544  
545 # Return the supplied scalar's strong reference count plus its weak-reference
546 # count.
547 IV
548 sv_refcount(sv)
549 SV *sv
550 PROTOTYPE: $
551 CODE:
552 {
553 3 RETVAL = SvREFCNT(sv);
554 3 ▶ ADD_WEAK_REFCOUNT;
Branch: 1 branch
BranchTrueFalseTotal
ADD_WEAK_REFCOUNT; 0 3 3
555 }
556 OUTPUT:
557 RETVAL
558  
559 # Return a reference's referent count including weak edges, or zero for a
560 # nonreference.
561 IV
562 refcount(sv)
563 SV *sv
564 PROTOTYPE: $
565 CODE:
566 {
567 5 ▶ if (!SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(sv)) { 0 5 5
568 0 RETVAL = 0;
569 } else {
570 5 sv = (SV *)SvRV(sv);
571 5 RETVAL = SvREFCNT(sv);
572 5 ADD_WEAK_REFCOUNT;
573 }
574 }
575 OUTPUT:
576 RETVAL
577  
578 # Report whether a scalar already has a numeric value flag without coercing
579 # its string value.
580 bool
581 is_numeric(sv)
582 SV *sv
583 PROTOTYPE: $
584 CODE:
585 {
586 7 ▶ RETVAL = (SvNIOK(sv)) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (SvNIOK(sv)) ? 1 : 0; 3 4 7
587 }
588 OUTPUT:
589 RETVAL
590  
591 # Set the supplied scalar's readonly flag and return the flag operation's
592 # result.
593 int
594 _make_ro(sv)
595 SV *sv
596 PROTOTYPE: $
597 CODE:
598 0 ▶RETVAL = SvREADONLY_on(sv);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvREADONLY_on(sv); 0 0 0
599 OUTPUT:
600 RETVAL
601  
602 # Mark the supplied scalar readonly and return that same retained SV for use
603 # in generated expressions.
604 SV *
605 make_ro(sv)
606 SV *sv
607 PROTOTYPE: $
608 CODE:
609 8 SvREADONLY_on(sv);
610 8 SvREFCNT_inc(sv);
611 8 RETVAL = sv;
612 OUTPUT:
613 RETVAL
614  
615 # Set or clear the supplied scalar's readonly flag according to the second
616 # argument.
617 int
618 readonly_set(sv,set)
619 SV *sv
620 SV *set
621 PROTOTYPE: $
622 CODE:
623 0 ▶if (SvTRUE(set)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(set)) { 0 0 0
624 0 RETVAL = SvREADONLY_on(sv);
625 } else {
626 0 RETVAL = SvREADONLY_off(sv);
627 }
628 OUTPUT:
629 RETVAL
630  
631 # Return the supplied scalar's readonly flag without changing it.
632 int
633 readonly(sv)
634 SV *sv
635 PROTOTYPE: $
636 CODE:
637 14 ▶RETVAL = SvREADONLY(sv);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvREADONLY(sv); 0 14 14
638 OUTPUT:
639 RETVAL
640  
641 # Expose Perl's numeric-string recognition for the supplied scalar.
642 int
643 looks_like_number(sv)
644 SV *sv
645 PROTOTYPE: $
646 CODE:
647 0 RETVAL = looks_like_number(sv);
648 OUTPUT:
649 RETVAL
650  
651 # Replace matching slots in the current lexical pad with the source referent,
652 # retaining it and requiring compatible destination/source types.
653 int
654 alias_ref (dst,src)
655 SV *dst
656 SV *src
657 CODE:
658 {
659 31 AV *padv = PL_comppad;
660 int dt, st;
661 31 int ok = 0;
662 I32 i;
663  
664 31 ▶ if (!SvROK(src) || !SvROK(dst))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(src) || !SvROK(dst)) 31 0 31
if (!SvROK(src) || !SvROK(dst)) 0 31 31
665 0 croak("destination and source must be references");
666  
667 31 dt = SvTYPE(SvRV(dst));
668 31 st = SvTYPE(SvRV(src));
669  
670 31 ▶ if (!((dt < SVt_PVAV && st < SVt_PVAV) || (dt == st && dt <= SVt_PVHV)))
Branch: 4 branches
BranchTrueFalseTotal
if (!((dt < SVt_PVAV && st < SVt_PVAV) || (dt == st && dt <= SVt_PVHV))) 31 0 31
if (!((dt < SVt_PVAV && st < SVt_PVAV) || (dt == st && dt <= SVt_PVHV))) 0 31 31
if (!((dt < SVt_PVAV && st < SVt_PVAV) || (dt == st && dt <= SVt_PVHV))) 0 0 0
if (!((dt < SVt_PVAV && st < SVt_PVAV) || (dt == st && dt <= SVt_PVHV))) 0 0 0
671 0 croak("destination and source must be same type (%d != %d)", dt, st);
672  
673 1621 ▶ for (i = 0; i <= av_len(padv); ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(padv); ++i) { 1590 31 1621
674 1590 SV **myvar_ptr = av_fetch(padv, i, 0);
675  
676 1590 ▶ if (myvar_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if (myvar_ptr) { 1559 31 1590
677 1559 ▶ if (SvRV(dst) == *myvar_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvRV(dst) == *myvar_ptr) { 31 1528 1559
678 31 av_store(padv, i, SvRV(src));
679 31 SvREFCNT_inc(SvRV(src));
680 31 ok = 1;
681 }
682 }
683 }
684 31 ▶ if (!ok)
Branch: 1 branch
BranchTrueFalseTotal
if (!ok) 0 31 31
685 0 croak("Failed to created alias");
686 31 ▶ RETVAL = ok;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ok; 0 31 31
687 }
688 OUTPUT:
689 RETVAL
690  
691 # Fetch magic and return the underlying referent type without its blessing, or
692 # false for a nonreference.
693 char *
694 reftype(sv)
695 SV *sv
696 PROTOTYPE: $
697 CODE:
698 {
699 36 ▶ if (SvMAGICAL(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvMAGICAL(sv)) 0 36 36
700 0 mg_get(sv);
701 36 ▶ if (!SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(sv)) { 8 28 36
702 8 XSRETURN_NO;
703 } else {
704 28 RETVAL = (char *)sv_reftype(SvRV(sv), FALSE);
705 }
706 }
707 OUTPUT:
708 RETVAL
709  
710 # Fetch magic and return a directly supplied glob's string name, or false for
711 # a reference or another scalar type.
712 char *
713 _globname(sv)
714 SV *sv
715 PROTOTYPE: $
716 CODE:
717 {
718 0 ▶ if (SvMAGICAL(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvMAGICAL(sv)) 0 0 0
719 0 mg_get(sv);
720 0 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 0 0 0
721 0 XSRETURN_NO;
722 } else {
723 U32 realtype;
724  
725 0 realtype = SvTYPE(sv);
726 0 ▶ if (realtype == SVt_PVGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (realtype == SVt_PVGV) { 0 0 0
727 STRLEN i;
728  
729 0 RETVAL = SvPV(sv, i);
730 } else {
731 0 XSRETURN_NO;
732 }
733 }
734 }
735 OUTPUT:
736 RETVAL
737  
738 # Return an unblessed reference type or a quoted glob expression for a
739 # directly supplied glob; return false for other values.
740 SV *
741 reftype_or_glob(sv)
742 SV *sv
743 PROTOTYPE: $
744 CODE:
745 {
746 0 ▶ if (SvMAGICAL(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvMAGICAL(sv)) 0 0 0
747 0 mg_get(sv);
748 0 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 0 0 0
749 0 RETVAL = newSVpv(sv_reftype(SvRV(sv), FALSE), 0);
750 } else {
751 U32 realtype;
752  
753 0 realtype = SvTYPE(sv);
754 0 ▶ if (realtype == SVt_PVGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (realtype == SVt_PVGV) { 0 0 0
755 char *c, *r;
756 STRLEN i;
757  
758 0 RETVAL = newSVpvn("", 0);
759  
760 0 c = SvPV(sv, i);
761  
762 0 ++c;
763 0 --i; /* Skip the leading glob sigil. */
764 0 ▶ if (i >= 6 && strncmp(c, "main::", 6) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (i >= 6 && strncmp(c, "main::", 6) == 0) { 0 0 0
if (i >= 6 && strncmp(c, "main::", 6) == 0) { 0 0 0
765 0 c += 4;
766 0 i -= 4;
767 }
768  
769 0 ▶ if (needs_q(c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (needs_q(c)) { 0 0 0
770 0 sv_grow(RETVAL, 6 + 2 * i);
771 0 r = SvPVX(RETVAL);
772 0 r[0] = '*';
773 0 r[1] = '{';
774 0 r[2] = '\'';
775 0 i += esc_q(r + 3, c, i);
776 0 i += 3;
777 0 r[i++] = '\'';
778 0 r[i++] = '}';
779 0 r[i] = '\0';
780 } else {
781 0 sv_grow(RETVAL, i + 2);
782 0 r = SvPVX(RETVAL);
783 0 r[0] = '*';
784 0 strcpy(r + 1, c);
785 0 i++;
786 }
787  
788 0 SvCUR_set(RETVAL, i);
789 } else {
790 0 XSRETURN_NO;
791 }
792 }
793 }
794 OUTPUT:
795 RETVAL
796  
797 # Return a referent address or a quoted glob expression for a directly
798 # supplied glob; return false for other values.
799 SV *
800 refaddr_or_glob(sv)
801 SV *sv
802 PROTOTYPE: $
803 CODE:
804 {
805 0 ▶ if (SvMAGICAL(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvMAGICAL(sv)) 0 0 0
806 0 mg_get(sv);
807 0 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 0 0 0
808 UV uv;
809  
810 0 uv = PTR2UV(SvRV(sv));
811 0 RETVAL = newSVuv(uv);
812 } else {
813 U32 realtype;
814  
815 0 realtype = SvTYPE(sv);
816 0 ▶ if (realtype == SVt_PVGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (realtype == SVt_PVGV) { 0 0 0
817 char *c, *r;
818 STRLEN i;
819  
820 0 RETVAL = newSVpvn("", 0);
821  
822 0 c = SvPV(sv, i);
823  
824 0 ++c;
825 0 --i; /* Skip the leading glob sigil. */
826 0 ▶ if (i >= 6 && strncmp(c, "main::", 6) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (i >= 6 && strncmp(c, "main::", 6) == 0) { 0 0 0
if (i >= 6 && strncmp(c, "main::", 6) == 0) { 0 0 0
827 0 c += 4;
828 0 i -= 4;
829 }
830  
831 0 ▶ if (needs_q(c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (needs_q(c)) { 0 0 0
832 0 sv_grow(RETVAL, 6 + 2 * i);
833 0 r = SvPVX(RETVAL);
834 0 r[0] = '*';
835 0 r[1] = '{';
836 0 r[2] = '\'';
837 0 i += esc_q(r + 3, c, i);
838 0 i += 3;
839 0 r[i++] = '\'';
840 0 r[i++] = '}';
841 0 r[i] = '\0';
842 } else {
843 0 sv_grow(RETVAL, i + 2);
844 0 r = SvPVX(RETVAL);
845 0 r[0] = '*';
846 0 strcpy(r + 1, c);
847 0 i++;
848 }
849  
850 0 SvCUR_set(RETVAL, i);
851 } else {
852 0 XSRETURN_NO;
853 }
854 }
855 }
856 OUTPUT:
857 RETVAL
858  
859 # Build a Perl glob expression for a directly supplied glob, shortening main-
860 # package names and escaping quoted names.
861 SV *
862 globname(sv)
863 SV *sv
864 PROTOTYPE: $
865 CODE:
866 {
867 0 ▶ if (SvMAGICAL(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvMAGICAL(sv)) 0 0 0
868 0 mg_get(sv);
869 0 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 0 0 0
870 0 XSRETURN_NO;
871 } else {
872 U32 realtype;
873  
874 0 realtype = SvTYPE(sv);
875 0 ▶ if (realtype == SVt_PVGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (realtype == SVt_PVGV) { 0 0 0
876 char *c, *r;
877 STRLEN i;
878  
879 0 RETVAL = newSVpvn("", 0);
880  
881 0 c = SvPV(sv, i);
882  
883 0 ++c;
884 0 --i; /* Skip the leading glob sigil. */
885 0 ▶ if (i >= 6 && strncmp(c, "main::", 6) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (i >= 6 && strncmp(c, "main::", 6) == 0) { 0 0 0
if (i >= 6 && strncmp(c, "main::", 6) == 0) { 0 0 0
886 0 c += 4;
887 0 i -= 4;
888 }
889  
890 0 ▶ if (needs_q(c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (needs_q(c)) { 0 0 0
891 0 sv_grow(RETVAL, 6 + 2 * i);
892 0 r = SvPVX(RETVAL);
893 0 r[0] = '*';
894 0 r[1] = '{';
895 0 r[2] = '\'';
896 0 i += esc_q(r + 3, c, i);
897 0 i += 3;
898 0 r[i++] = '\'';
899 0 r[i++] = '}';
900 0 r[i] = '\0';
901 } else {
902 0 sv_grow(RETVAL, i + 2);
903 0 r = SvPVX(RETVAL);
904 0 r[0] = '*';
905 0 strcpy(r + 1, c);
906 0 i++;
907 }
908  
909 0 SvCUR_set(RETVAL, i);
910 } else {
911 0 XSRETURN_NO;
912 }
913 }
914 }
915 OUTPUT:
916 RETVAL
917  
918 #ifdef MY_XS_AMAGIC
919  
920 # Clear overload dispatch on the supplied SV for legacy interpreter
921 # compatibility.
922 void
923 SvAMAGIC_off(sv)
924 SV *sv
925 PROTOTYPE: $
926 CODE:
927 SvAMAGIC_off(sv);
928  
929 # Provide the legacy overload compatibility entry point; the retained
930 # implementation clears the overload flag.
931 void
932 SvAMAGIC_on(sv,klass)
933 SV *sv
934 SV *klass
935 PROTOTYPE: $$
936 CODE:
937 SvAMAGIC_off(sv);
938  
939 #endif
940  
941 #ifndef NEW_REGEX_ENGINE
942  
943 # Inspect a legacy regexp, returning pattern and modifiers in list context or
944 # its stringified form in scalar context; return undef otherwise.
945 void
946 regex(sv)
947 SV *sv
948 PROTOTYPE: $
949 PREINIT:
950 STRLEN patlen;
951 char reflags[6];
952 int left;
953 PPCODE:
954 {
955 /*
956 Checks if a reference is a regex or not. If the parameter is
957 not a ref, or is not the result of a qr// then returns undef.
958 Otherwise in list context it returns the pattern and the
959 modifiers, in scalar context it returns the pattern just as it
960 would if the qr// was blessed into the package Regexp and
961 stringified normally.
962 */
963  
964 if (SvMAGICAL(sv)) { /* is this if needed??? Why?*/
965 mg_get(sv);
966 }
967 if (!SvROK(sv)) { /* bail if we dont have a ref. */
968 XSRETURN_UNDEF;
969 }
970 patlen = 0;
971 left = 0;
972 if (SvTHINKFIRST(sv)) {
973 sv = (SV *)SvRV(sv);
974 if (sv) {
975 MAGIC *mg;
976 if (SvTYPE(sv) == SVt_PVMG) {
977 if (((SvFLAGS(sv) & (SVs_OBJECT | SVf_OK | SVs_GMG | SVs_SMG | SVs_RMG)) ==
978 (SVs_OBJECT | BFD_Svs_SMG_OR_RMG)) &&
979 (mg = mg_find(sv, PERL_MAGIC_qr))) {
980 /* Housten, we have a regex! */
981 SV *pattern;
982  
983 regexp *re = (regexp *)mg->mg_obj;
984 I32 gimme = GIMME_V;
985  
986 if (gimme == G_ARRAY) {
987 /*
988 we are in list/array context so stringify
989 the modifiers that apply. We ignore "negative
990 modifiers" in this scenario. Also we dont cache
991 the modifiers. AFAICT there isnt anywhere for
992 them to go. :-(
993 */
994  
995 char *fptr = "msix";
996 char ch;
997  
998 U16 reganch = (U16)((re->reganch & PMf_COMPILETIME) >> 12);
999  
1000 while ((ch = *fptr++)) {
1001 if (reganch & 1) {
1002 reflags[left++] = ch;
1003 }
1004 reganch >>= 1;
1005 }
1006  
1007 pattern = sv_2mortal(newSVpvn(re->precomp, re->prelen));
1008 if (re->reganch & ROPT_UTF8)
1009 SvUTF8_on(pattern);
1010  
1011 /* return the pattern and the modifiers */
1012 XPUSHs(pattern);
1013 XPUSHs(sv_2mortal(newSVpvn(reflags, left)));
1014 XSRETURN(2);
1015 } else {
1016 /*
1017 Non array/list context. So we build up the
1018 stringified form just as PL_sv_2pv does,
1019 and like it we also cache the result. The
1020 entire content of the if() is directly taken
1021 from PL_sv_2pv
1022 */
1023  
1024 if (!mg->mg_ptr) {
1025 char *fptr = "msix";
1026 char ch;
1027 int right = 4;
1028 char need_newline = 0;
1029  
1030 U16 reganch = (U16)((re->reganch & PMf_COMPILETIME) >> 12);
1031  
1032 while ((ch = *fptr++)) {
1033 if (reganch & 1) {
1034 reflags[left++] = ch;
1035 } else {
1036 reflags[right--] = ch;
1037 }
1038 reganch >>= 1;
1039 }
1040 if (left != 4) {
1041 reflags[left] = '-';
1042 left = 5;
1043 }
1044 mg->mg_len = re->prelen + 4 + left;
1045 /*
1046 * If /x was used, we have to worry about a regex
1047 * ending with a comment later being embedded
1048 * within another regex. If so, we don't want this
1049 * regex's "commentization" to leak out to the
1050 * right part of the enclosing regex, we must cap
1051 * it with a newline.
1052 *
1053 * So, if /x was used, we scan backwards from the
1054 * end of the regex. If we find a '#' before we
1055 * find a newline, we need to add a newline
1056 * ourself. If we find a '\n' first (or if we
1057 * don't find '#' or '\n'), we don't need to add
1058 * anything. -jfriedl
1059 */
1060 if (PMf_EXTENDED & re->reganch) {
1061 char *endptr = re->precomp + re->prelen;
1062  
1063 while (endptr >= re->precomp) {
1064 char c = *(endptr--);
1065  
1066 if (c == '\n')
1067 break; /* don't need another */
1068 if (c == '#') {
1069 /* we end while in a comment, so we
1070 need a newline */
1071 mg->mg_len++; /* save space for it */
1072 need_newline = 1; /* note to add it */
1073 break;
1074 }
1075 }
1076 }
1077 /**/
1078 New(616, mg->mg_ptr, mg->mg_len + 1 + left, char);
1079 Copy("(?", mg->mg_ptr, 2, char);
1080 Copy(reflags, mg->mg_ptr + 2, left, char);
1081 Copy(":", mg->mg_ptr + left + 2, 1, char);
1082 Copy(re->precomp, mg->mg_ptr + 3 + left, re->prelen, char);
1083 if (need_newline)
1084 mg->mg_ptr[mg->mg_len - 2] = '\n';
1085 mg->mg_ptr[mg->mg_len - 1] = ')';
1086 mg->mg_ptr[mg->mg_len] = 0;
1087 }
1088 /* return the pattern in (?msix:..) format */
1089 pattern = sv_2mortal(newSVpvn(mg->mg_ptr, mg->mg_len));
1090 if (re->reganch & ROPT_UTF8)
1091 SvUTF8_on(pattern);
1092 XPUSHs(pattern);
1093 XSRETURN(1);
1094 }
1095 }
1096 }
1097 }
1098 }
1099 /* 'twould appear it aint a regex, so return undef/empty list */
1100 XSRETURN_UNDEF;
1101 }
1102  
1103 #endif
1104  
1105 #ifdef MY_CAN_FIND_PLACEHOLDERS
1106  
1107 # Replace two caller-provided arrays with the hash's visible and placeholder
1108 # keys, advancing its hash iterator.
1109 void
1110 all_keys(hash,keys,placeholder)
1111 SV *hash
1112 SV *keys
1113 SV *placeholder
1114 PROTOTYPE: \%\@\@
1115 PREINIT:
1116 AV *av_k;
1117 AV *av_p;
1118 HV *hv;
1119 SV *key;
1120 HE *he;
1121 CODE:
1122 0 ▶ if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV) 0 0 0
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV) 0 0 0
1123 0 croak("First argument to all_keys() must be an HASH reference");
1124 0 ▶ if (!SvROK(keys) || SvTYPE(SvRV(keys)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(keys) || SvTYPE(SvRV(keys)) != SVt_PVAV) 0 0 0
if (!SvROK(keys) || SvTYPE(SvRV(keys)) != SVt_PVAV) 0 0 0
1125 0 croak("Second argument to all_keys() must be an ARRAY reference");
1126 0 ▶ if (!SvROK(placeholder) || SvTYPE(SvRV(placeholder)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(placeholder) || SvTYPE(SvRV(placeholder)) != SVt_PVAV) 0 0 0
if (!SvROK(placeholder) || SvTYPE(SvRV(placeholder)) != SVt_PVAV) 0 0 0
1127 0 croak("Third argument to all_keys() must be an ARRAY reference");
1128  
1129 0 hv = (HV *)SvRV(hash);
1130 0 av_k = (AV *)SvRV(keys);
1131 0 av_p = (AV *)SvRV(placeholder);
1132  
1133 0 av_clear(av_k);
1134 0 av_clear(av_p);
1135  
1136 0 (void)hv_iterinit(hv);
1137 0 ▶ while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 0 0 0
1138 0 key = hv_iterkeysv(he);
1139 0 ▶ if (HeVAL(he) == &MY_PLACEHOLDER) {
Branch: 1 branch
BranchTrueFalseTotal
if (HeVAL(he) == &MY_PLACEHOLDER) { 0 0 0
1140 0 SvREFCNT_inc(key);
1141 0 av_push(av_p, key);
1142 } else {
1143 0 SvREFCNT_inc(key);
1144 0 av_push(av_k, key);
1145 }
1146 }
1147  
1148 # Return restricted-hash placeholder keys as a list, advancing the hash
1149 # iterator.
1150 void
1151 hidden_keys(hash)
1152 SV *hash
1153 PROTOTYPE: \%
1154 PREINIT:
1155 HV *hv;
1156 SV *key;
1157 HE *he;
1158 PPCODE:
1159 6 ▶ if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV) 6 0 6
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV) 0 6 6
1160 0 croak("First argument to hidden_keys() must be an HASH reference");
1161  
1162 6 hv = (HV *)SvRV(hash);
1163 6 (void)hv_iterinit(hv);
1164 66 ▶ while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 54 6 60
1165 54 key = hv_iterkeysv(he);
1166 54 ▶ if (HeVAL(he) == &MY_PLACEHOLDER) {
Branch: 1 branch
BranchTrueFalseTotal
if (HeVAL(he) == &MY_PLACEHOLDER) { 28 26 54
1167 28 ▶ XPUSHs(key);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(key); 0 28 28
1168 }
1169 }
1170  
1171 # Return all legal restricted-hash keys, including placeholders, advancing the
1172 # hash iterator.
1173 void
1174 legal_keys(hash)
1175 SV *hash
1176 PROTOTYPE: \%
1177 PREINIT:
1178 HV *hv;
1179 SV *key;
1180 HE *he;
1181 PPCODE:
1182 6 ▶ if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV) 6 0 6
if (!SvROK(hash) || SvTYPE(SvRV(hash)) != SVt_PVHV) 0 6 6
1183 0 croak("First argument to legal_keys() must be an HASH reference");
1184  
1185 6 hv = (HV *)SvRV(hash);
1186  
1187 6 (void)hv_iterinit(hv);
1188 60 ▶ while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 54 6 60
1189 54 key = hv_iterkeysv(he);
1190 54 ▶ XPUSHs(key);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(key); 0 54 54
1191 }
1192  
1193 #endif
1194  
1195 BOOT:
1196 46 dds_api_boot(aTHX);
1197 46 newXSproto("Data::Dump::Streamer::SvREADONLY_ref",
1198 XS_Data__Dump__Streamer_SvREADONLY, file, "$;$");
1199 46 newXSproto("Data::Dump::Streamer::SvREFCNT_ref",
1200 XS_Data__Dump__Streamer_SvREFCNT, file, "$;$");
« blib/lib/Data/Dump/Streamer.pm ↑ Summary dds_api.c »