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