| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #define NEED_my_snprintf |
| 6 |
|
| #define NEED_my_sprintf |
| 7 |
|
| #define NEED_sv_2pv_flags |
| 8 |
|
| #define NEED_utf8_to_uvchr_buf |
| 9 |
|
| #define NEED_sv_vstring_get |
| 10 |
|
| #include "ppport.h" |
| 11 |
|
| |
| 12 |
|
| #ifndef strlcpy |
| 13 |
|
| # ifdef my_strlcpy |
| 14 |
|
| # define strlcpy(d,s,l) my_strlcpy(d,s,l) |
| 15 |
|
| # else |
| 16 |
|
| # define strlcpy(d,s,l) strcpy(d,s) |
| 17 |
|
| # endif |
| 18 |
|
| #endif |
| 19 |
|
| |
| 20 |
|
| /* These definitions are ASCII only. But the pure-perl .pm avoids |
| 21 |
|
| * calling this .xs file for releases where they aren't defined */ |
| 22 |
|
| |
| 23 |
|
| #ifndef ESC_NATIVE /* \e */ |
| 24 |
|
| # define ESC_NATIVE LATIN1_TO_NATIVE(27) |
| 25 |
|
| #endif |
| 26 |
|
| |
| 27 |
|
| /* SvPVCLEAR only from perl 5.25.6 */ |
| 28 |
|
| #ifndef SvPVCLEAR |
| 29 |
|
| # define SvPVCLEAR(sv) sv_setpvs((sv), "") |
| 30 |
|
| #endif |
| 31 |
|
| |
| 32 |
|
| #ifndef memBEGINs |
| 33 |
|
| # define memBEGINs(s1, l, s2) \ |
| 34 |
|
| ( (l) >= sizeof(s2) - 1 \ |
| 35 |
|
| && memEQ(s1, "" s2 "", sizeof(s2)-1)) |
| 36 |
|
| #endif |
| 37 |
|
| |
| 38 |
|
| /* This struct contains almost all the user's desired configuration, and it |
| 39 |
|
| * is treated as mostly constant (except for maxrecursed) by the recursive |
| 40 |
|
| * function. This arrangement has the advantage of needing less memory |
| 41 |
|
| * than passing all of them on the stack all the time (as was the case in |
| 42 |
|
| * an earlier implementation). */ |
| 43 |
|
| typedef struct { |
| 44 |
|
| SV *pad; |
| 45 |
|
| SV *xpad; |
| 46 |
|
| SV *sep; |
| 47 |
|
| SV *pair; |
| 48 |
|
| SV *sortkeys; |
| 49 |
|
| SV *freezer; |
| 50 |
|
| SV *toaster; |
| 51 |
|
| SV *bless; |
| 52 |
|
| IV maxrecurse; |
| 53 |
|
| bool maxrecursed; /* at some point we exceeded the maximum recursion level */ |
| 54 |
|
| I32 indent; |
| 55 |
|
| I32 purity; |
| 56 |
|
| I32 deepcopy; |
| 57 |
|
| I32 quotekeys; |
| 58 |
|
| I32 maxdepth; |
| 59 |
|
| I32 useqq; |
| 60 |
|
| int use_sparse_seen_hash; |
| 61 |
|
| int trailingcomma; |
| 62 |
|
| int deparse; |
| 63 |
|
| } Style; |
| 64 |
|
| |
| 65 |
|
| static STRLEN num_q (const char *s, STRLEN slen); |
| 66 |
|
| static STRLEN esc_q (char *dest, const char *src, STRLEN slen); |
| 67 |
|
| static STRLEN esc_q_utf8 (pTHX_ SV *sv, const char *src, STRLEN slen, I32 do_utf8, I32 useqq); |
| 68 |
|
| static bool globname_needs_quote(const char *s, STRLEN len); |
| 69 |
|
| #ifndef GvNAMEUTF8 |
| 70 |
|
| static bool globname_supra_ascii(const char *s, STRLEN len); |
| 71 |
|
| #endif |
| 72 |
|
| static bool key_needs_quote(const char *s, STRLEN len); |
| 73 |
|
| static bool safe_decimal_number(const char *p, STRLEN len); |
| 74 |
|
| static SV *sv_x (pTHX_ SV *sv, const char *str, STRLEN len, I32 n); |
| 75 |
|
| static I32 DD_dump (pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, |
| 76 |
|
| HV *seenhv, AV *postav, const I32 level, SV *apad, |
| 77 |
|
| Style *style); |
| 78 |
|
| |
| 79 |
|
| #define DD_is_integer(sv) SvIOK(sv) |
| 80 |
|
| |
| 81 |
|
| /* does a glob name need to be protected? */ |
| 82 |
|
| static bool |
| 83 |
75 |
| globname_needs_quote(const char *ss, STRLEN len) |
| 84 |
|
| { |
| 85 |
75 |
| const U8 *s = (const U8 *) ss; |
| 86 |
75 |
| const U8 *send = s+len; |
| 87 |
97 |
| TOP: |
| 88 |
97 |
▶ | if (s[0] == ':') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (s[0] == ':') { |
75 |
22 |
97 |
|
| 89 |
75 |
▶ | if (++s<send) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (++s<send) { |
74 |
1 |
75 |
|
| 90 |
74 |
▶ | if (*s++ != ':') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s++ != ':') |
0 |
74 |
74 |
|
| 91 |
0 |
| return TRUE; |
| 92 |
|
| } |
| 93 |
|
| else |
| 94 |
1 |
| return TRUE; |
| 95 |
|
| } |
| 96 |
96 |
▶ | if (isIDFIRST(*s)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isIDFIRST(*s)) { |
86 |
10 |
96 |
|
| 97 |
198 |
▶ | while (++s<send) |
Branch: 1 branch
| Branch | True | False | Total |
| while (++s<send) |
167 |
31 |
198 |
|
| 98 |
167 |
▶ | if (!isWORDCHAR(*s)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!isWORDCHAR(*s)) { |
55 |
112 |
167 |
|
| 99 |
55 |
▶ | if (*s == ':') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*s == ':') |
22 |
33 |
55 |
|
| 100 |
22 |
| goto TOP; |
| 101 |
|
| else |
| 102 |
33 |
| return TRUE; |
| 103 |
|
| } |
| 104 |
|
| } |
| 105 |
|
| else |
| 106 |
10 |
| return TRUE; |
| 107 |
|
| |
| 108 |
31 |
| return FALSE; |
| 109 |
|
| } |
| 110 |
|
| |
| 111 |
|
| #ifndef GvNAMEUTF8 |
| 112 |
|
| /* does a glob name contain supra-ASCII characters? */ |
| 113 |
|
| static bool |
| 114 |
|
| globname_supra_ascii(const char *ss, STRLEN len) |
| 115 |
|
| { |
| 116 |
|
| const U8 *s = (const U8 *) ss; |
| 117 |
|
| const U8 *send = s+len; |
| 118 |
|
| while (s < send) { |
| 119 |
|
| if (!isASCII(*s)) |
| 120 |
|
| return TRUE; |
| 121 |
|
| s++; |
| 122 |
|
| } |
| 123 |
|
| return FALSE; |
| 124 |
|
| } |
| 125 |
|
| #endif |
| 126 |
|
| |
| 127 |
|
| /* does a hash key need to be quoted (to the left of => ). |
| 128 |
|
| Previously this used (globname_)needs_quote() which accepted strings |
| 129 |
|
| like '::foo', but these aren't safe as unquoted keys under strict. |
| 130 |
|
| */ |
| 131 |
|
| static bool |
| 132 |
158 |
| key_needs_quote(const char *s, STRLEN len) { |
| 133 |
158 |
| const char *send = s+len; |
| 134 |
|
| |
| 135 |
158 |
▶ | if (safe_decimal_number(s, len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (safe_decimal_number(s, len)) { |
10 |
148 |
158 |
|
| 136 |
10 |
| return FALSE; |
| 137 |
|
| } |
| 138 |
148 |
▶ | else if (isIDFIRST(*s)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (isIDFIRST(*s)) { |
136 |
12 |
148 |
|
| 139 |
358 |
▶ | while (++s<send) |
Branch: 1 branch
| Branch | True | False | Total |
| while (++s<send) |
224 |
134 |
358 |
|
| 140 |
224 |
▶ | if (!isWORDCHAR(*s)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!isWORDCHAR(*s)) |
2 |
222 |
224 |
|
| 141 |
2 |
| return TRUE; |
| 142 |
|
| } |
| 143 |
|
| else |
| 144 |
12 |
| return TRUE; |
| 145 |
|
| |
| 146 |
134 |
| return FALSE; |
| 147 |
|
| } |
| 148 |
|
| |
| 149 |
|
| /* Check that the SV can be represented as a simple decimal integer. |
| 150 |
|
| * |
| 151 |
|
| * The perl code does this by matching against /^(?:0|-?[1-9]\d{0,8})\z/ |
| 152 |
|
| */ |
| 153 |
|
| static bool |
| 154 |
2286 |
| safe_decimal_number(const char *p, STRLEN len) { |
| 155 |
2286 |
▶ | if (len == 1 && *p == '0') |
Branch: 2 branches
| Branch | True | False | Total |
| if (len == 1 && *p == '0') |
97 |
2189 |
2286 |
| if (len == 1 && *p == '0') |
2 |
95 |
97 |
|
| 156 |
2 |
| return TRUE; |
| 157 |
|
| |
| 158 |
2284 |
▶ | if (len && *p == '-') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (len && *p == '-') { |
2234 |
50 |
2284 |
| if (len && *p == '-') { |
0 |
2234 |
2234 |
|
| 159 |
0 |
| ++p; |
| 160 |
0 |
| --len; |
| 161 |
|
| } |
| 162 |
|
| |
| 163 |
2284 |
▶ | if (len == 0 || *p < '1' || *p > '9') |
Branch: 3 branches
| Branch | True | False | Total |
| if (len == 0 || *p < '1' || *p > '9') |
2234 |
50 |
2284 |
| if (len == 0 || *p < '1' || *p > '9') |
2188 |
46 |
2234 |
| if (len == 0 || *p < '1' || *p > '9') |
2021 |
167 |
2188 |
|
| 164 |
2117 |
| return FALSE; |
| 165 |
|
| |
| 166 |
167 |
| ++p; |
| 167 |
167 |
| --len; |
| 168 |
|
| |
| 169 |
167 |
▶ | if (len > 8) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 8) |
4 |
163 |
167 |
|
| 170 |
4 |
| return FALSE; |
| 171 |
|
| |
| 172 |
201 |
▶ | while (len > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len > 0) { |
191 |
10 |
201 |
|
| 173 |
|
| /* the perl code checks /\d/ but we don't want unicode digits here */ |
| 174 |
191 |
▶ | if (*p < '0' || *p > '9') |
Branch: 2 branches
| Branch | True | False | Total |
| if (*p < '0' || *p > '9') |
38 |
153 |
191 |
| if (*p < '0' || *p > '9') |
0 |
38 |
38 |
|
| 175 |
153 |
| return FALSE; |
| 176 |
38 |
| ++p; |
| 177 |
38 |
| --len; |
| 178 |
|
| } |
| 179 |
10 |
| return TRUE; |
| 180 |
|
| } |
| 181 |
|
| |
| 182 |
|
| /* count the number of "'"s and "\"s in string */ |
| 183 |
|
| static STRLEN |
| 184 |
509 |
| num_q(const char *s, STRLEN slen) |
| 185 |
|
| { |
| 186 |
509 |
| STRLEN ret = 0; |
| 187 |
|
| |
| 188 |
2758 |
▶ | while (slen > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (slen > 0) { |
2249 |
509 |
2758 |
|
| 189 |
2249 |
▶ | if (*s == '\'' || *s == '\\') |
Branch: 2 branches
| Branch | True | False | Total |
| if (*s == '\'' || *s == '\\') |
2248 |
1 |
2249 |
| if (*s == '\'' || *s == '\\') |
1 |
2247 |
2248 |
|
| 190 |
2 |
| ++ret; |
| 191 |
2249 |
| ++s; |
| 192 |
2249 |
| --slen; |
| 193 |
|
| } |
| 194 |
509 |
| return ret; |
| 195 |
|
| } |
| 196 |
|
| |
| 197 |
|
| |
| 198 |
|
| /* returns number of chars added to escape "'"s and "\"s in s */ |
| 199 |
|
| /* slen number of characters in s will be escaped */ |
| 200 |
|
| /* destination must be long enough for additional chars */ |
| 201 |
|
| static STRLEN |
| 202 |
748 |
| esc_q(char *d, const char *s, STRLEN slen) |
| 203 |
|
| { |
| 204 |
748 |
| STRLEN ret = 0; |
| 205 |
|
| |
| 206 |
3638 |
▶ | while (slen > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (slen > 0) { |
2890 |
748 |
3638 |
|
| 207 |
2890 |
▶ | switch (*s) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (*s) { |
5 |
2885 |
2890 |
|
| 208 |
5 |
| case '\'': |
| 209 |
|
| case '\\': |
| 210 |
5 |
| *d = '\\'; |
| 211 |
5 |
| ++d; ++ret; |
| 212 |
|
| /* FALLTHROUGH */ |
| 213 |
2890 |
| default: |
| 214 |
2890 |
| *d = *s; |
| 215 |
2890 |
| ++d; ++s; --slen; |
| 216 |
2890 |
| break; |
| 217 |
|
| } |
| 218 |
|
| } |
| 219 |
748 |
| return ret; |
| 220 |
|
| } |
| 221 |
|
| |
| 222 |
|
| /* this function is also misused for implementing $Useqq */ |
| 223 |
|
| static STRLEN |
| 224 |
2224 |
| esc_q_utf8(pTHX_ SV* sv, const char *src, STRLEN slen, I32 do_utf8, I32 useqq) |
| 225 |
|
| { |
| 226 |
|
| char *r, *rstart; |
| 227 |
2224 |
| const char *s = src; |
| 228 |
2224 |
| const char * const send = src + slen; |
| 229 |
2224 |
| STRLEN j, cur = SvCUR(sv); |
| 230 |
|
| /* Could count 128-255 and 256+ in two variables, if we want to |
| 231 |
|
| be like &qquote and make a distinction. */ |
| 232 |
2224 |
| STRLEN grow = 0; /* bytes needed to represent chars 128+ */ |
| 233 |
|
| /* STRLEN topbit_grow = 0; bytes needed to represent chars 128-255 */ |
| 234 |
2224 |
| STRLEN backslashes = 0; |
| 235 |
2224 |
| STRLEN single_quotes = 0; |
| 236 |
2224 |
| STRLEN qq_escapables = 0; /* " $ @ will need a \ in "" strings. */ |
| 237 |
2224 |
| STRLEN normal = 0; |
| 238 |
|
| int increment; |
| 239 |
|
| |
| 240 |
17827 |
▶ | for (s = src; s < send; s += increment) { /* Sizing pass */ |
Branch: 1 branch
| Branch | True | False | Total |
| for (s = src; s < send; s += increment) { /* Sizing pass */ |
15603 |
2224 |
17827 |
|
| 241 |
15603 |
| UV k = *(U8*)s; |
| 242 |
|
| |
| 243 |
15603 |
| increment = 1; /* Will override if necessary for utf-8 */ |
| 244 |
|
| |
| 245 |
15603 |
▶ | if (isPRINT(k)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isPRINT(k)) { |
14813 |
790 |
15603 |
|
| 246 |
14813 |
▶ | if (k == '\\') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (k == '\\') { |
6 |
14807 |
14813 |
|
| 247 |
6 |
| backslashes++; |
| 248 |
14807 |
▶ | } else if (k == '\'') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (k == '\'') { |
58 |
14749 |
14807 |
|
| 249 |
58 |
| single_quotes++; |
| 250 |
14749 |
▶ | } else if (k == '"' || k == '$' || k == '@') { |
Branch: 3 branches
| Branch | True | False | Total |
| } else if (k == '"' || k == '$' || k == '@') { |
14741 |
8 |
14749 |
| } else if (k == '"' || k == '$' || k == '@') { |
14732 |
9 |
14741 |
| } else if (k == '"' || k == '$' || k == '@') { |
6 |
14726 |
14732 |
|
| 251 |
23 |
| qq_escapables++; |
| 252 |
|
| } else { |
| 253 |
14726 |
| normal++; |
| 254 |
|
| } |
| 255 |
|
| } |
| 256 |
790 |
▶ | else if (! UTF8_IS_INVARIANT(k)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (! UTF8_IS_INVARIANT(k)) { |
634 |
156 |
790 |
|
| 257 |
|
| /* We treat as low ordinal any code point whose representation is |
| 258 |
|
| * the same under UTF-8 as not. Thus, this is a high ordinal code |
| 259 |
|
| * point. |
| 260 |
|
| * |
| 261 |
|
| * If UTF-8, output as hex, regardless of useqq. This means there |
| 262 |
|
| * is an overhead of 4 chars '\x{}'. Then count the number of hex |
| 263 |
|
| * digits. */ |
| 264 |
634 |
▶ | if (do_utf8) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (do_utf8) { |
370 |
264 |
634 |
|
| 265 |
370 |
| k = utf8_to_uvchr_buf((U8*)s, (U8*) send, NULL); |
| 266 |
|
| |
| 267 |
|
| /* treat invalid utf8 byte by byte. This loop iteration gets the |
| 268 |
|
| * first byte */ |
| 269 |
370 |
▶ | increment = (k == 0 && *s != '\0') ? 1 : UTF8SKIP(s); |
Branch: 2 branches
| Branch | True | False | Total |
| increment = (k == 0 && *s != '\0') ? 1 : UTF8SKIP(s); |
50 |
320 |
370 |
| increment = (k == 0 && *s != '\0') ? 1 : UTF8SKIP(s); |
0 |
50 |
50 |
|
| 270 |
|
| |
| 271 |
370 |
| grow += 6; /* Smallest we do is "\x{FF}" */ |
| 272 |
370 |
| k >>= 4; |
| 273 |
478 |
▶ | while ((k >>= 4) != 0) { /* Add space for each nibble */ |
Branch: 1 branch
| Branch | True | False | Total |
| while ((k >>= 4) != 0) { /* Add space for each nibble */ |
108 |
370 |
478 |
|
| 274 |
108 |
| grow++; |
| 275 |
|
| } |
| 276 |
|
| } |
| 277 |
264 |
▶ | else if (useqq) { /* Not utf8, must be <= 0xFF, hence 2 hex |
Branch: 1 branch
| Branch | True | False | Total |
| else if (useqq) { /* Not utf8, must be <= 0xFF, hence 2 hex |
264 |
0 |
264 |
|
| 278 |
|
| * digits. */ |
| 279 |
264 |
| grow += 4 + 2; |
| 280 |
|
| } |
| 281 |
|
| else { /* Non-qq generates 3 octal digits plus backslash */ |
| 282 |
0 |
| grow += 4; |
| 283 |
|
| } |
| 284 |
|
| } /* End of high-ordinal non-printable */ |
| 285 |
156 |
▶ | else if (! useqq) { /* Low ordinal, non-printable, non-qq just |
Branch: 1 branch
| Branch | True | False | Total |
| else if (! useqq) { /* Low ordinal, non-printable, non-qq just |
2 |
154 |
156 |
|
| 286 |
|
| * outputs the raw char */ |
| 287 |
2 |
| normal++; |
| 288 |
|
| } |
| 289 |
|
| else { /* Is qq, non-printable. Output escape sequences */ |
| 290 |
154 |
▶ | if ( k == '\a' || k == '\b' || k == '\t' || k == '\n' || k == '\r' |
Branch: 5 branches
| Branch | True | False | Total |
| if ( k == '\a' || k == '\b' || k == '\t' || k == '\n' || k == '\r' |
150 |
4 |
154 |
| if ( k == '\a' || k == '\b' || k == '\t' || k == '\n' || k == '\r' |
146 |
4 |
150 |
| if ( k == '\a' || k == '\b' || k == '\t' || k == '\n' || k == '\r' |
142 |
4 |
146 |
| if ( k == '\a' || k == '\b' || k == '\t' || k == '\n' || k == '\r' |
136 |
6 |
142 |
| if ( k == '\a' || k == '\b' || k == '\t' || k == '\n' || k == '\r' |
132 |
4 |
136 |
|
| 291 |
132 |
▶ | || k == '\f' || k == ESC_NATIVE) |
Branch: 2 branches
| Branch | True | False | Total |
| || k == '\f' || k == ESC_NATIVE) |
128 |
4 |
132 |
| || k == '\f' || k == ESC_NATIVE) |
6 |
122 |
128 |
|
| 292 |
|
| { |
| 293 |
32 |
| grow += 2; /* 1 char plus backslash */ |
| 294 |
|
| } |
| 295 |
|
| else /* The other non-printable controls are output as an octal escape |
| 296 |
|
| * sequence */ |
| 297 |
122 |
▶ | if (s + 1 >= send || isDIGIT(*(s+1))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (s + 1 >= send || isDIGIT(*(s+1))) { |
120 |
2 |
122 |
| if (s + 1 >= send || isDIGIT(*(s+1))) { |
4 |
116 |
120 |
|
| 298 |
|
| /* When the following character is a digit, use 3 octal digits |
| 299 |
|
| * plus backslash, as using fewer digits would concatenate the |
| 300 |
|
| * following char into this one */ |
| 301 |
6 |
| grow += 4; |
| 302 |
|
| } |
| 303 |
116 |
▶ | else if (k <= 7) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (k <= 7) { |
40 |
76 |
116 |
|
| 304 |
40 |
| grow += 2; /* 1 octal digit, plus backslash */ |
| 305 |
|
| } |
| 306 |
76 |
▶ | else if (k <= 077) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (k <= 077) { |
72 |
4 |
76 |
|
| 307 |
72 |
| grow += 3; /* 2 octal digits plus backslash */ |
| 308 |
|
| } |
| 309 |
|
| else { |
| 310 |
4 |
| grow += 4; /* 3 octal digits plus backslash */ |
| 311 |
|
| } |
| 312 |
|
| } |
| 313 |
|
| } /* End of size-calculating loop */ |
| 314 |
|
| |
| 315 |
2224 |
▶ | if (grow || useqq) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (grow || useqq) { |
2145 |
79 |
2224 |
| if (grow || useqq) { |
2133 |
12 |
2145 |
|
| 316 |
|
| /* We have something needing hex. 3 is ""\0 */ |
| 317 |
2212 |
| sv_grow(sv, cur + 3 + grow + 2*backslashes + single_quotes |
| 318 |
|
| + 2*qq_escapables + normal); |
| 319 |
2212 |
| rstart = r = SvPVX(sv) + cur; |
| 320 |
|
| |
| 321 |
2212 |
| *r++ = '"'; |
| 322 |
|
| |
| 323 |
17750 |
▶ | for (s = src; s < send; s += increment) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (s = src; s < send; s += increment) { |
15538 |
2212 |
17750 |
|
| 324 |
15538 |
| U8 c0 = *(U8 *)s; |
| 325 |
|
| UV k; |
| 326 |
|
| |
| 327 |
15538 |
▶ | if (do_utf8 && ! UTF8_IS_INVARIANT(c0)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (do_utf8 && ! UTF8_IS_INVARIANT(c0)) { |
829 |
14709 |
15538 |
| if (do_utf8 && ! UTF8_IS_INVARIANT(c0)) { |
370 |
459 |
829 |
|
| 328 |
|
| |
| 329 |
|
| /* In UTF-8, we output as \x{} all chars that require more than |
| 330 |
|
| * a single byte in UTF-8 to represent. */ |
| 331 |
370 |
| k = utf8_to_uvchr_buf((U8*)s, (U8*) send, NULL); |
| 332 |
|
| |
| 333 |
|
| /* treat invalid utf8 byte by byte. This loop iteration gets the |
| 334 |
|
| * first byte */ |
| 335 |
370 |
▶ | increment = (k == 0 && *s != '\0') ? 1 : UTF8SKIP(s); |
Branch: 2 branches
| Branch | True | False | Total |
| increment = (k == 0 && *s != '\0') ? 1 : UTF8SKIP(s); |
50 |
320 |
370 |
| increment = (k == 0 && *s != '\0') ? 1 : UTF8SKIP(s); |
0 |
50 |
50 |
|
| 336 |
|
| |
| 337 |
370 |
| r = r + my_sprintf(r, "\\x{%" UVxf "}", k); |
| 338 |
370 |
| continue; |
| 339 |
|
| } |
| 340 |
|
| |
| 341 |
|
| /* Here 1) isn't UTF-8; or |
| 342 |
|
| * 2) the current character is represented as the same single |
| 343 |
|
| * byte regardless of the string's UTF-8ness |
| 344 |
|
| * In each case the character occupies just one byte */ |
| 345 |
15168 |
| k = *(U8*)s; |
| 346 |
15168 |
| increment = 1; |
| 347 |
|
| |
| 348 |
15168 |
▶ | if (isPRINT(k)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (isPRINT(k)) { |
14749 |
419 |
15168 |
|
| 349 |
|
| /* These need a backslash escape */ |
| 350 |
14749 |
▶ | if (k == '"' || k == '\\' || k == '$' || k == '@') { |
Branch: 4 branches
| Branch | True | False | Total |
| if (k == '"' || k == '\\' || k == '$' || k == '@') { |
14743 |
6 |
14749 |
| if (k == '"' || k == '\\' || k == '$' || k == '@') { |
14737 |
6 |
14743 |
| if (k == '"' || k == '\\' || k == '$' || k == '@') { |
14730 |
7 |
14737 |
| if (k == '"' || k == '\\' || k == '$' || k == '@') { |
6 |
14724 |
14730 |
|
| 351 |
25 |
| *r++ = '\\'; |
| 352 |
|
| } |
| 353 |
|
| |
| 354 |
14749 |
| *r++ = (char)k; |
| 355 |
|
| } |
| 356 |
419 |
▶ | else if (! useqq) { /* non-qq, non-printable, low-ordinal is |
Branch: 1 branch
| Branch | True | False | Total |
| else if (! useqq) { /* non-qq, non-printable, low-ordinal is |
1 |
418 |
419 |
|
| 357 |
|
| * output raw */ |
| 358 |
1 |
| *r++ = (char)k; |
| 359 |
|
| } |
| 360 |
|
| else { /* Is qq means use escape sequences */ |
| 361 |
|
| bool next_is_digit; |
| 362 |
|
| |
| 363 |
418 |
| *r++ = '\\'; |
| 364 |
418 |
| switch (k) { |
| 365 |
4 |
| case '\a': *r++ = 'a'; break; |
| 366 |
4 |
| case '\b': *r++ = 'b'; break; |
| 367 |
4 |
| case '\t': *r++ = 't'; break; |
| 368 |
6 |
| case '\n': *r++ = 'n'; break; |
| 369 |
4 |
| case '\f': *r++ = 'f'; break; |
| 370 |
4 |
| case '\r': *r++ = 'r'; break; |
| 371 |
6 |
| case ESC_NATIVE: *r++ = 'e'; break; |
| 372 |
386 |
| default: |
| 373 |
|
| |
| 374 |
|
| /* only ASCII digits matter here, which are invariant, |
| 375 |
|
| * since we only encode characters \377 and under, or |
| 376 |
|
| * \x177 and under for a unicode string |
| 377 |
|
| */ |
| 378 |
386 |
▶ | next_is_digit = (s + 1 < send && isDIGIT(*(s+1))); |
Branch: 2 branches
| Branch | True | False | Total |
| next_is_digit = (s + 1 < send && isDIGIT(*(s+1))); |
382 |
4 |
386 |
| next_is_digit = (s + 1 < send && isDIGIT(*(s+1))); |
4 |
378 |
382 |
|
| 379 |
|
| |
| 380 |
|
| /* faster than |
| 381 |
|
| * r = r + my_sprintf(r, "%o", k); |
| 382 |
|
| */ |
| 383 |
386 |
▶ | if (k <= 7 && !next_is_digit) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (k <= 7 && !next_is_digit) { |
46 |
340 |
386 |
| if (k <= 7 && !next_is_digit) { |
42 |
4 |
46 |
|
| 384 |
42 |
| *r++ = (char)k + '0'; |
| 385 |
344 |
▶ | } else if (k <= 63 && !next_is_digit) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if (k <= 63 && !next_is_digit) { |
76 |
268 |
344 |
| } else if (k <= 63 && !next_is_digit) { |
72 |
4 |
76 |
|
| 386 |
72 |
| *r++ = (char)(k>>3) + '0'; |
| 387 |
72 |
| *r++ = (char)(k&7) + '0'; |
| 388 |
|
| } else { |
| 389 |
272 |
| *r++ = (char)(k>>6) + '0'; |
| 390 |
272 |
| *r++ = (char)((k&63)>>3) + '0'; |
| 391 |
272 |
| *r++ = (char)(k&7) + '0'; |
| 392 |
|
| } |
| 393 |
|
| } |
| 394 |
|
| } |
| 395 |
|
| } |
| 396 |
2212 |
| *r++ = '"'; |
| 397 |
|
| } else { |
| 398 |
|
| /* Single quotes. */ |
| 399 |
12 |
| sv_grow(sv, cur + 3 + 2*backslashes + 2*single_quotes |
| 400 |
|
| + qq_escapables + normal); |
| 401 |
12 |
| rstart = r = SvPVX(sv) + cur; |
| 402 |
12 |
| *r++ = '\''; |
| 403 |
77 |
▶ | for (s = src; s < send; s ++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (s = src; s < send; s ++) { |
65 |
12 |
77 |
|
| 404 |
65 |
| const char k = *s; |
| 405 |
65 |
▶ | if (k == '\'' || k == '\\') |
Branch: 2 branches
| Branch | True | False | Total |
| if (k == '\'' || k == '\\') |
63 |
2 |
65 |
| if (k == '\'' || k == '\\') |
0 |
63 |
63 |
|
| 406 |
2 |
| *r++ = '\\'; |
| 407 |
65 |
| *r++ = k; |
| 408 |
|
| } |
| 409 |
12 |
| *r++ = '\''; |
| 410 |
|
| } |
| 411 |
2224 |
| *r = '\0'; |
| 412 |
2224 |
| j = r - rstart; |
| 413 |
2224 |
| SvCUR_set(sv, cur + j); |
| 414 |
|
| |
| 415 |
2224 |
| return j; |
| 416 |
|
| } |
| 417 |
|
| |
| 418 |
|
| /* append a repeated string to an SV */ |
| 419 |
|
| static SV * |
| 420 |
1454 |
| sv_x(pTHX_ SV *sv, const char *str, STRLEN len, I32 n) |
| 421 |
|
| { |
| 422 |
1454 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
1433 |
21 |
1454 |
|
| 423 |
1433 |
| sv = newSVpvs(""); |
| 424 |
|
| #ifdef DEBUGGING |
| 425 |
|
| else |
| 426 |
|
| assert(SvTYPE(sv) >= SVt_PV); |
| 427 |
|
| #endif |
| 428 |
|
| |
| 429 |
1454 |
▶ | if (n > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > 0) { |
1206 |
248 |
1454 |
|
| 430 |
1206 |
▶ | SvGROW(sv, len*n + SvCUR(sv) + 1); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGROW(sv, len*n + SvCUR(sv) + 1); |
1206 |
0 |
1206 |
| SvGROW(sv, len*n + SvCUR(sv) + 1); |
4 |
1202 |
1206 |
|
| 431 |
1206 |
▶ | if (len == 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 1) { |
287 |
919 |
1206 |
|
| 432 |
287 |
| char * const start = SvPVX(sv) + SvCUR(sv); |
| 433 |
287 |
| SvCUR_set(sv, SvCUR(sv) + n); |
| 434 |
287 |
| start[n] = '\0'; |
| 435 |
2295 |
▶ | while (n > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| while (n > 0) |
2008 |
287 |
2295 |
|
| 436 |
2008 |
| start[--n] = str[0]; |
| 437 |
|
| } |
| 438 |
|
| else |
| 439 |
2595 |
▶ | while (n > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (n > 0) { |
1676 |
919 |
2595 |
|
| 440 |
1676 |
| sv_catpvn(sv, str, len); |
| 441 |
1676 |
| --n; |
| 442 |
|
| } |
| 443 |
|
| } |
| 444 |
1454 |
| return sv; |
| 445 |
|
| } |
| 446 |
|
| |
| 447 |
|
| static SV * |
| 448 |
5 |
| deparsed_output(pTHX_ SV *val) |
| 449 |
|
| { |
| 450 |
|
| SV *text; |
| 451 |
|
| int n; |
| 452 |
5 |
| dSP; |
| 453 |
|
| |
| 454 |
|
| /* This is passed to load_module(), which decrements its ref count and |
| 455 |
|
| * modifies it (so we also can't reuse it below) */ |
| 456 |
5 |
| SV *pkg = newSVpvs("B::Deparse"); |
| 457 |
|
| |
| 458 |
|
| /* Commit ebdc88085efa6fca8a1b0afaa388f0491bdccd5a (first released as part |
| 459 |
|
| * of 5.19.7) changed core S_process_special_blocks() to use a new stack |
| 460 |
|
| * for anything using a BEGIN block, on the grounds that doing so "avoids |
| 461 |
|
| * the stack moving underneath anything that directly or indirectly calls |
| 462 |
|
| * Perl_load_module()". If we're in an older Perl, we can't rely on that |
| 463 |
|
| * stack, and must create a fresh sacrificial stack of our own. */ |
| 464 |
|
| #if PERL_VERSION_LT(5,20,0) |
| 465 |
|
| PUSHSTACKi(PERLSI_REQUIRE); |
| 466 |
|
| #endif |
| 467 |
|
| |
| 468 |
5 |
| load_module(PERL_LOADMOD_NOIMPORT, pkg, 0); |
| 469 |
|
| |
| 470 |
|
| #if PERL_VERSION_LT(5,20,0) |
| 471 |
|
| POPSTACK; |
| 472 |
|
| SPAGAIN; |
| 473 |
|
| #endif |
| 474 |
|
| |
| 475 |
5 |
| SAVETMPS; |
| 476 |
|
| |
| 477 |
5 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
5 |
5 |
|
| 478 |
5 |
▶ | mXPUSHs(newSVpvs("B::Deparse")); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newSVpvs("B::Deparse")); |
0 |
5 |
5 |
|
| 479 |
5 |
| PUTBACK; |
| 480 |
|
| |
| 481 |
5 |
| n = call_method("new", G_SCALAR); |
| 482 |
5 |
| SPAGAIN; |
| 483 |
|
| |
| 484 |
5 |
▶ | if (n != 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n != 1) { |
0 |
5 |
5 |
|
| 485 |
0 |
| croak("B::Deparse->new returned %d items, but expected exactly 1", n); |
| 486 |
|
| } |
| 487 |
|
| |
| 488 |
5 |
▶ | PUSHMARK(SP - n); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP - n); |
0 |
5 |
5 |
|
| 489 |
5 |
▶ | XPUSHs(val); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(val); |
0 |
5 |
5 |
|
| 490 |
5 |
| PUTBACK; |
| 491 |
|
| |
| 492 |
5 |
| n = call_method("coderef2text", G_SCALAR); |
| 493 |
5 |
| SPAGAIN; |
| 494 |
|
| |
| 495 |
5 |
▶ | if (n != 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (n != 1) { |
0 |
5 |
5 |
|
| 496 |
0 |
| croak("$b_deparse->coderef2text returned %d items, but expected exactly 1", n); |
| 497 |
|
| } |
| 498 |
|
| |
| 499 |
5 |
| text = POPs; |
| 500 |
5 |
| SvREFCNT_inc(text); /* the caller will mortalise this */ |
| 501 |
|
| |
| 502 |
5 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
5 |
0 |
5 |
|
| 503 |
|
| |
| 504 |
5 |
| PUTBACK; |
| 505 |
|
| |
| 506 |
5 |
| return text; |
| 507 |
|
| } |
| 508 |
|
| |
| 509 |
|
| static void |
| 510 |
100 |
| dump_regexp(pTHX_ SV *retval, SV *val) |
| 511 |
|
| { |
| 512 |
|
| STRLEN rlen; |
| 513 |
100 |
| SV *sv_pattern = NULL; |
| 514 |
100 |
| SV *sv_flags = NULL; |
| 515 |
|
| const char *rval; |
| 516 |
|
| const U8 *rend; |
| 517 |
|
| U8 *p; |
| 518 |
100 |
| CV *re_pattern_cv = get_cv("re::regexp_pattern", 0); |
| 519 |
|
| int do_utf8; |
| 520 |
|
| |
| 521 |
100 |
▶ | if (!re_pattern_cv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!re_pattern_cv) { |
0 |
100 |
100 |
|
| 522 |
0 |
| sv_pattern = val; |
| 523 |
|
| } |
| 524 |
|
| else { |
| 525 |
100 |
| dSP; |
| 526 |
|
| I32 count; |
| 527 |
100 |
| ENTER; |
| 528 |
100 |
| SAVETMPS; |
| 529 |
100 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
100 |
100 |
|
| 530 |
100 |
▶ | XPUSHs(val); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(val); |
0 |
100 |
100 |
|
| 531 |
100 |
| PUTBACK; |
| 532 |
100 |
| count = call_sv((SV*)re_pattern_cv, G_ARRAY); |
| 533 |
100 |
| SPAGAIN; |
| 534 |
100 |
▶ | if (count >= 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count >= 2) { |
100 |
0 |
100 |
|
| 535 |
100 |
| sv_flags = POPs; |
| 536 |
100 |
| sv_pattern = POPs; |
| 537 |
100 |
| SvREFCNT_inc(sv_flags); |
| 538 |
100 |
| SvREFCNT_inc(sv_pattern); |
| 539 |
|
| } |
| 540 |
100 |
| PUTBACK; |
| 541 |
100 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
100 |
0 |
100 |
|
| 542 |
100 |
| LEAVE; |
| 543 |
100 |
▶ | if (sv_pattern) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_pattern) { |
100 |
0 |
100 |
|
| 544 |
100 |
| sv_2mortal(sv_pattern); |
| 545 |
100 |
| sv_2mortal(sv_flags); |
| 546 |
|
| } |
| 547 |
|
| } |
| 548 |
|
| |
| 549 |
|
| assert(sv_pattern); |
| 550 |
|
| |
| 551 |
100 |
| sv_catpvs(retval, "qr/"); |
| 552 |
|
| |
| 553 |
|
| /* The strategy here is from commit 7894fbab1e479c2c (in June 1999) with a |
| 554 |
|
| * bug fix in Feb 2012 (commit de5ef703c7d8db65). |
| 555 |
|
| * We need to ensure that / is escaped as \/ |
| 556 |
|
| * To be efficient, we want to avoid copying byte-for-byte, so we scan the |
| 557 |
|
| * string looking for "things we need to escape", and each time we find |
| 558 |
|
| * something, we copy over the verbatim section, before writing out the |
| 559 |
|
| * escaped part. At the end, if there's some verbatim section left, we copy |
| 560 |
|
| * that over to finish. |
| 561 |
|
| * The complication (perl #58608) is that we must not convert \/ to \\/ |
| 562 |
|
| * (as that would be a syntax error), so we need to walk the string looking |
| 563 |
|
| * for either |
| 564 |
|
| * \ and the character immediately after (together) |
| 565 |
|
| * a character |
| 566 |
|
| * and only for the latter, do we need to escape / |
| 567 |
|
| * |
| 568 |
|
| * Of course, to add to the fun, we also need to escape Unicode characters |
| 569 |
|
| * to \x{...} notation (whether they are "escaped" by \ or stand alone). |
| 570 |
|
| * |
| 571 |
|
| * which means we need to output qr// notation |
| 572 |
|
| * even if the input was expressed as q'' (eg q'$foo') |
| 573 |
|
| * |
| 574 |
|
| * We can do all this in one pass if we are careful... |
| 575 |
|
| */ |
| 576 |
|
| |
| 577 |
100 |
| rval = SvPV(sv_pattern, rlen); |
| 578 |
100 |
| p = (U8 *)rval; |
| 579 |
100 |
| rend = p + rlen; |
| 580 |
100 |
▶ | do_utf8 = DO_UTF8(sv_pattern); |
Branch: 2 branches
| Branch | True | False | Total |
| do_utf8 = DO_UTF8(sv_pattern); |
24 |
76 |
100 |
| do_utf8 = DO_UTF8(sv_pattern); |
24 |
0 |
24 |
|
| 581 |
|
| |
| 582 |
|
| /* Escape the pattern to make sure it is processed properly if the output |
| 583 |
|
| * is evalled. This includes handling things like escaping / characters |
| 584 |
|
| * as we output it as a qr/.../, along with sigils or other entities which |
| 585 |
|
| * might be misinterpreted. |
| 586 |
|
| * Note 1: Try to keep the $ anchor exceptions in sync with S_scan_const() |
| 587 |
|
| * in toke.c and the regex parser logic in regcomp.c |
| 588 |
|
| * Note 2: The exceptions are not required and this code should still DTRT |
| 589 |
|
| * but produce uglier output if the '$' exception rule were removed. |
| 590 |
|
| * Note 3: This escaping looks weird, but allows us to avoid concerns |
| 591 |
|
| * about whether we have misparsed the pattern or not. When the |
| 592 |
|
| * pattern is interpolated it comes back just as it was before, without |
| 593 |
|
| * us worrying if we misidentified something. The exception list is |
| 594 |
|
| * purely to make the output more readable in common cases where we |
| 595 |
|
| * are confident we won't misparse a $. */ |
| 596 |
582 |
▶ | while (p < rend) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < rend) { |
482 |
100 |
582 |
|
| 597 |
482 |
| UV k = *p; |
| 598 |
482 |
| int saw_backslash = k == '\\'; |
| 599 |
|
| |
| 600 |
482 |
▶ | if (saw_backslash) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (saw_backslash) { |
71 |
411 |
482 |
|
| 601 |
71 |
▶ | if (++p == rend) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (++p == rend) { |
0 |
71 |
71 |
|
| 602 |
|
| /* Oh my, \ at the end. Is this possible? */ |
| 603 |
0 |
| break; |
| 604 |
|
| } |
| 605 |
|
| /* Otherwise we look at the next octet */ |
| 606 |
71 |
| k = *p; |
| 607 |
|
| } |
| 608 |
|
| |
| 609 |
482 |
▶ | if (/* / that was not backslashed */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (/* / that was not backslashed */ |
23 |
459 |
482 |
|
| 610 |
23 |
▶ | (k == '/' && !saw_backslash) |
Branch: 1 branch
| Branch | True | False | Total |
| (k == '/' && !saw_backslash) |
1 |
22 |
23 |
|
| 611 |
|
| /* Unescaped sigils can interpolate when the dump is evaluated. */ |
| 612 |
460 |
▶ | || (k == '@' && !saw_backslash) |
Branch: 2 branches
| Branch | True | False | Total |
| || (k == '@' && !saw_backslash) |
18 |
442 |
460 |
| || (k == '@' && !saw_backslash) |
4 |
14 |
18 |
|
| 613 |
|
| /* Match the $ anchor exceptions in S_scan_const() in toke.c. */ |
| 614 |
446 |
▶ | || (k == '$' && !saw_backslash |
Branch: 2 branches
| Branch | True | False | Total |
| || (k == '$' && !saw_backslash |
51 |
395 |
446 |
| || (k == '$' && !saw_backslash |
43 |
8 |
51 |
|
| 615 |
43 |
▶ | && (p + 1 != rend && p[1] != ' ' |
Branch: 2 branches
| Branch | True | False | Total |
| && (p + 1 != rend && p[1] != ' ' |
38 |
5 |
43 |
| && (p + 1 != rend && p[1] != ' ' |
31 |
7 |
38 |
|
| 616 |
31 |
▶ | && p[1] != '(' && p[1] != ')' && p[1] != '|' |
Branch: 3 branches
| Branch | True | False | Total |
| && p[1] != '(' && p[1] != ')' && p[1] != '|' |
30 |
1 |
31 |
| && p[1] != '(' && p[1] != ')' && p[1] != '|' |
27 |
3 |
30 |
| && p[1] != '(' && p[1] != ')' && p[1] != '|' |
24 |
3 |
27 |
|
| 617 |
24 |
▶ | && p[1] != '\\' |
Branch: 1 branch
| Branch | True | False | Total |
| && p[1] != '\\' |
22 |
2 |
24 |
|
| 618 |
22 |
▶ | && p[1] != '\t' && p[1] != '\r' && p[1] != '\n')) |
Branch: 3 branches
| Branch | True | False | Total |
| && p[1] != '\t' && p[1] != '\r' && p[1] != '\n')) |
22 |
0 |
22 |
| && p[1] != '\t' && p[1] != '\r' && p[1] != '\n')) |
22 |
0 |
22 |
| && p[1] != '\t' && p[1] != '\r' && p[1] != '\n')) |
0 |
22 |
22 |
|
| 619 |
|
| /* or need to use \x{} notation. */ |
| 620 |
424 |
▶ | || (do_utf8 && ! UTF8_IS_INVARIANT(k))) |
Branch: 2 branches
| Branch | True | False | Total |
| || (do_utf8 && ! UTF8_IS_INVARIANT(k))) |
88 |
336 |
424 |
| || (do_utf8 && ! UTF8_IS_INVARIANT(k))) |
24 |
64 |
88 |
|
| 621 |
82 |
| { |
| 622 |
82 |
| STRLEN to_copy = p - (U8 *) rval; |
| 623 |
82 |
▶ | if (to_copy) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (to_copy) { |
51 |
31 |
82 |
|
| 624 |
|
| /* If saw_backslash is true, this will copy the \ for us too. */ |
| 625 |
51 |
| sv_catpvn(retval, rval, to_copy); |
| 626 |
|
| } |
| 627 |
82 |
▶ | if (k == '/') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (k == '/') { |
22 |
60 |
82 |
|
| 628 |
22 |
| sv_catpvs(retval, "\\/"); |
| 629 |
22 |
| ++p; |
| 630 |
|
| } |
| 631 |
96 |
▶ | else if (k == '@' || k == '$') { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (k == '@' || k == '$') { |
46 |
14 |
60 |
| else if (k == '@' || k == '$') { |
22 |
24 |
46 |
|
| 632 |
36 |
| const U8 *start = p; |
| 633 |
36 |
| ++p; |
| 634 |
69 |
▶ | while (p < rend && (*p == '{' || *p == '[')) |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < rend && (*p == '{' || *p == '[')) |
69 |
0 |
69 |
| while (p < rend && (*p == '{' || *p == '[')) |
20 |
49 |
69 |
| while (p < rend && (*p == '{' || *p == '[')) |
13 |
36 |
49 |
|
| 635 |
33 |
| ++p; |
| 636 |
36 |
| sv_catpvs(retval, "${\\q("); |
| 637 |
36 |
| sv_catpvn(retval, (const char *) start, p - start); |
| 638 |
36 |
| sv_catpvs(retval, ")}"); |
| 639 |
|
| } |
| 640 |
|
| else { |
| 641 |
|
| /* If there was a \, we have copied it already, so all that is |
| 642 |
|
| * left to do here is the \x{...} escaping. |
| 643 |
|
| * |
| 644 |
|
| * Since this is a pattern, presumably created by perl, we can |
| 645 |
|
| * assume it is well-formed */ |
| 646 |
24 |
| k = utf8_to_uvchr_buf(p, rend, NULL); |
| 647 |
24 |
| sv_catpvf(retval, "\\x{%" UVxf "}", k); |
| 648 |
24 |
| p += UTF8SKIP(p); |
| 649 |
|
| } |
| 650 |
82 |
| rval = (const char *) p; |
| 651 |
|
| } |
| 652 |
|
| else { |
| 653 |
400 |
| ++p; |
| 654 |
|
| } |
| 655 |
|
| } |
| 656 |
|
| |
| 657 |
100 |
| rlen = rend - (U8 *) rval; |
| 658 |
100 |
▶ | if (rlen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rlen) { |
93 |
7 |
100 |
|
| 659 |
93 |
| sv_catpvn(retval, rval, rlen); |
| 660 |
|
| } |
| 661 |
100 |
| sv_catpvs(retval, "/"); |
| 662 |
|
| |
| 663 |
100 |
▶ | if (sv_flags) |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_flags) |
100 |
0 |
100 |
|
| 664 |
100 |
| sv_catsv(retval, sv_flags); |
| 665 |
100 |
| } |
| 666 |
|
| |
| 667 |
|
| /* |
| 668 |
|
| * This ought to be split into smaller functions. (it is one long function since |
| 669 |
|
| * it exactly parallels the perl version, which was one long thing for |
| 670 |
|
| * efficiency raisins.) Ugggh! |
| 671 |
|
| */ |
| 672 |
|
| static I32 |
| 673 |
4983 |
| DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, |
| 674 |
|
| AV *postav, const I32 level, SV *apad, Style *style) |
| 675 |
|
| { |
| 676 |
|
| char tmpbuf[128]; |
| 677 |
|
| Size_t i; |
| 678 |
|
| char *c, *r, *realpack; |
| 679 |
|
| UV id_buffer; |
| 680 |
4983 |
| char *const id = (char *)&id_buffer; |
| 681 |
|
| SV **svp; |
| 682 |
|
| SV *sv, *ipad, *ival; |
| 683 |
4983 |
| SV *blesspad = Nullsv; |
| 684 |
4983 |
| AV *seenentry = NULL; |
| 685 |
|
| char *iname; |
| 686 |
4983 |
| STRLEN inamelen, idlen = 0; |
| 687 |
|
| U32 realtype; |
| 688 |
4983 |
| bool no_bless = 0; /* when a qr// is blessed into Regexp we dont want to bless it. |
| 689 |
|
| in later perls we should actually check the classname of the |
| 690 |
|
| engine. this gets tricky as it involves lexical issues that arent so |
| 691 |
|
| easy to resolve */ |
| 692 |
4983 |
| bool is_regex = 0; /* we are dumping a regex, we need to know this before we bless */ |
| 693 |
|
| |
| 694 |
4983 |
▶ | if (!val) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!val) |
0 |
4983 |
4983 |
|
| 695 |
0 |
| return 0; |
| 696 |
|
| |
| 697 |
4983 |
▶ | if (style->maxrecursed) |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->maxrecursed) |
1 |
4982 |
4983 |
|
| 698 |
1 |
| return 0; |
| 699 |
|
| |
| 700 |
|
| /* If the output buffer has less than some arbitrary amount of space |
| 701 |
|
| remaining, then enlarge it. For the test case (25M of output), |
| 702 |
|
| *1.1 was slower, *2.0 was the same, so the first guess of 1.5 is |
| 703 |
|
| deemed to be good enough. */ |
| 704 |
4982 |
▶ | if (SvTYPE(retval) >= SVt_PV && (SvLEN(retval) - SvCUR(retval)) < 42) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTYPE(retval) >= SVt_PV && (SvLEN(retval) - SvCUR(retval)) < 42) { |
4982 |
0 |
4982 |
| if (SvTYPE(retval) >= SVt_PV && (SvLEN(retval) - SvCUR(retval)) < 42) { |
4651 |
331 |
4982 |
|
| 705 |
4651 |
| sv_grow(retval, SvCUR(retval) * 3 / 2); |
| 706 |
|
| } |
| 707 |
|
| |
| 708 |
4982 |
| realtype = SvTYPE(val); |
| 709 |
|
| |
| 710 |
4982 |
▶ | if (SvGMAGICAL(val)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvGMAGICAL(val)) |
0 |
4982 |
4982 |
|
| 711 |
0 |
| mg_get(val); |
| 712 |
4982 |
▶ | if (SvROK(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(val)) { |
1098 |
3884 |
4982 |
|
| 713 |
|
| |
| 714 |
|
| /* If a freeze method is provided and the object has it, call |
| 715 |
|
| it. Warn on errors. */ |
| 716 |
1098 |
▶ | if (SvOBJECT(SvRV(val)) && style->freezer && |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvOBJECT(SvRV(val)) && style->freezer && |
116 |
982 |
1098 |
| if (SvOBJECT(SvRV(val)) && style->freezer && |
116 |
0 |
116 |
|
| 717 |
123 |
▶ | SvPOK(style->freezer) && SvCUR(style->freezer) && |
Branch: 1 branch
| Branch | True | False | Total |
| SvPOK(style->freezer) && SvCUR(style->freezer) && |
114 |
2 |
116 |
|
| 718 |
7 |
| gv_fetchmeth(SvSTASH(SvRV(val)), SvPVX_const(style->freezer), |
| 719 |
|
| SvCUR(style->freezer), -1) != NULL) |
| 720 |
|
| { |
| 721 |
6 |
▶ | dSP; ENTER; SAVETMPS; PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| dSP; ENTER; SAVETMPS; PUSHMARK(sp); |
0 |
6 |
6 |
|
| 722 |
6 |
▶ | XPUSHs(val); PUTBACK; |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(val); PUTBACK; |
0 |
6 |
6 |
|
| 723 |
6 |
| i = perl_call_method(SvPVX_const(style->freezer), G_EVAL|G_VOID|G_DISCARD); |
| 724 |
6 |
| SPAGAIN; |
| 725 |
6 |
▶ | if (SvTRUE(ERRSV)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) |
6 |
0 |
6 |
| if (SvTRUE(ERRSV)) |
1 |
5 |
6 |
|
| 726 |
1 |
▶ | warn("WARNING(Freezer method call failed): %" SVf, ERRSV); |
Branch: 1 branch
| Branch | True | False | Total |
| warn("WARNING(Freezer method call failed): %" SVf, ERRSV); |
1 |
0 |
1 |
|
| 727 |
6 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
6 |
0 |
6 |
|
| 728 |
|
| } |
| 729 |
|
| |
| 730 |
1098 |
| ival = SvRV(val); |
| 731 |
1098 |
| realtype = SvTYPE(ival); |
| 732 |
1098 |
| id_buffer = PTR2UV(ival); |
| 733 |
1098 |
| idlen = sizeof(id_buffer); |
| 734 |
1098 |
▶ | if (SvOBJECT(ival)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOBJECT(ival)) |
116 |
982 |
1098 |
|
| 735 |
116 |
▶ | realpack = HvNAME_get(SvSTASH(ival)); |
Branch: 6 branches
| Branch | True | False | Total |
| realpack = HvNAME_get(SvSTASH(ival)); |
116 |
0 |
116 |
| realpack = HvNAME_get(SvSTASH(ival)); |
116 |
0 |
116 |
| realpack = HvNAME_get(SvSTASH(ival)); |
0 |
116 |
116 |
| realpack = HvNAME_get(SvSTASH(ival)); |
0 |
0 |
0 |
| realpack = HvNAME_get(SvSTASH(ival)); |
116 |
0 |
116 |
| realpack = HvNAME_get(SvSTASH(ival)); |
0 |
116 |
116 |
|
| 736 |
|
| else |
| 737 |
982 |
| realpack = NULL; |
| 738 |
|
| |
| 739 |
|
| /* if it has a name, we need to either look it up, or keep a tab |
| 740 |
|
| * on it so we know when we hit it later |
| 741 |
|
| */ |
| 742 |
1098 |
▶ | if (namelen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (namelen) { |
1098 |
0 |
1098 |
|
| 743 |
1098 |
▶ | if ((svp = hv_fetch(seenhv, id, idlen, FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetch(seenhv, id, idlen, FALSE)) |
323 |
775 |
1098 |
|
| 744 |
323 |
▶ | && (sv = *svp) && SvROK(sv) && (seenentry = (AV*)SvRV(sv))) |
Branch: 3 branches
| Branch | True | False | Total |
| && (sv = *svp) && SvROK(sv) && (seenentry = (AV*)SvRV(sv))) |
323 |
0 |
323 |
| && (sv = *svp) && SvROK(sv) && (seenentry = (AV*)SvRV(sv))) |
323 |
0 |
323 |
| && (sv = *svp) && SvROK(sv) && (seenentry = (AV*)SvRV(sv))) |
323 |
0 |
323 |
|
| 745 |
|
| { |
| 746 |
|
| SV *othername; |
| 747 |
323 |
▶ | if ((svp = av_fetch(seenentry, 0, FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = av_fetch(seenentry, 0, FALSE)) |
323 |
0 |
323 |
|
| 748 |
323 |
▶ | && (othername = *svp)) |
Branch: 1 branch
| Branch | True | False | Total |
| && (othername = *svp)) |
323 |
0 |
323 |
|
| 749 |
|
| { |
| 750 |
411 |
▶ | if (style->purity && level > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (style->purity && level > 0) { |
140 |
183 |
323 |
| if (style->purity && level > 0) { |
88 |
52 |
140 |
|
| 751 |
|
| SV *postentry; |
| 752 |
|
| |
| 753 |
88 |
▶ | if (realtype == SVt_PVHV) |
Branch: 1 branch
| Branch | True | False | Total |
| if (realtype == SVt_PVHV) |
28 |
60 |
88 |
|
| 754 |
28 |
| sv_catpvs(retval, "{}"); |
| 755 |
60 |
▶ | else if (realtype == SVt_PVAV) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (realtype == SVt_PVAV) |
38 |
22 |
60 |
|
| 756 |
38 |
| sv_catpvs(retval, "[]"); |
| 757 |
|
| else |
| 758 |
22 |
| sv_catpvs(retval, "do{my $o}"); |
| 759 |
88 |
| postentry = newSVpvn(name, namelen); |
| 760 |
88 |
| sv_catpvs(postentry, " = "); |
| 761 |
88 |
| sv_catsv(postentry, othername); |
| 762 |
88 |
| av_push(postav, postentry); |
| 763 |
|
| } |
| 764 |
|
| else { |
| 765 |
235 |
▶ | if (name[0] == '@' || name[0] == '%') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (name[0] == '@' || name[0] == '%') { |
231 |
4 |
235 |
| if (name[0] == '@' || name[0] == '%') { |
26 |
205 |
231 |
|
| 766 |
30 |
▶ | if ((SvPVX_const(othername))[0] == '\\' && |
Branch: 1 branch
| Branch | True | False | Total |
| if ((SvPVX_const(othername))[0] == '\\' && |
10 |
20 |
30 |
|
| 767 |
10 |
▶ | (SvPVX_const(othername))[1] == name[0]) { |
Branch: 1 branch
| Branch | True | False | Total |
| (SvPVX_const(othername))[1] == name[0]) { |
10 |
0 |
10 |
|
| 768 |
10 |
| sv_catpvn(retval, SvPVX_const(othername)+1, |
| 769 |
|
| SvCUR(othername)-1); |
| 770 |
|
| } |
| 771 |
|
| else { |
| 772 |
20 |
| sv_catpvn(retval, name, 1); |
| 773 |
20 |
| sv_catpvs(retval, "{"); |
| 774 |
20 |
| sv_catsv(retval, othername); |
| 775 |
20 |
| sv_catpvs(retval, "}"); |
| 776 |
|
| } |
| 777 |
|
| } |
| 778 |
|
| else |
| 779 |
205 |
| sv_catsv(retval, othername); |
| 780 |
|
| } |
| 781 |
323 |
| return 1; |
| 782 |
|
| } |
| 783 |
|
| else { |
| 784 |
0 |
| warn("ref name not found for 0x%" UVxf, PTR2UV(ival)); |
| 785 |
0 |
| return 0; |
| 786 |
|
| } |
| 787 |
|
| } |
| 788 |
|
| else { /* store our name and continue */ |
| 789 |
|
| SV *namesv; |
| 790 |
775 |
▶ | if (name[0] == '@' || name[0] == '%') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (name[0] == '@' || name[0] == '%') { |
753 |
22 |
775 |
| if (name[0] == '@' || name[0] == '%') { |
9 |
744 |
753 |
|
| 791 |
31 |
| namesv = newSVpvs("\\"); |
| 792 |
31 |
| sv_catpvn(namesv, name, namelen); |
| 793 |
|
| } |
| 794 |
744 |
▶ | else if (realtype == SVt_PVCV && name[0] == '*') { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (realtype == SVt_PVCV && name[0] == '*') { |
11 |
733 |
744 |
| else if (realtype == SVt_PVCV && name[0] == '*') { |
2 |
9 |
11 |
|
| 795 |
2 |
| namesv = newSVpvs("\\"); |
| 796 |
2 |
| sv_catpvn(namesv, name, namelen); |
| 797 |
2 |
| (SvPVX(namesv))[1] = '&'; |
| 798 |
|
| } |
| 799 |
|
| else |
| 800 |
742 |
| namesv = newSVpvn(name, namelen); |
| 801 |
775 |
| seenentry = newAV(); |
| 802 |
775 |
| av_push(seenentry, namesv); |
| 803 |
775 |
| (void)SvREFCNT_inc(val); |
| 804 |
775 |
| av_push(seenentry, val); |
| 805 |
775 |
| (void)hv_store(seenhv, id, idlen, |
| 806 |
|
| newRV_inc((SV*)seenentry), 0); |
| 807 |
775 |
| SvREFCNT_dec(seenentry); |
| 808 |
|
| } |
| 809 |
|
| } |
| 810 |
|
| /* regexps dont have to be blessed into package "Regexp" |
| 811 |
|
| * they can be blessed into any package. |
| 812 |
|
| */ |
| 813 |
|
| #if PERL_VERSION_LT(5,11,0) |
| 814 |
|
| if (realpack && realtype == SVt_PVMG && mg_find(ival, PERL_MAGIC_qr)) |
| 815 |
|
| #else |
| 816 |
775 |
▶ | if (realpack && realtype == SVt_REGEXP) |
Branch: 2 branches
| Branch | True | False | Total |
| if (realpack && realtype == SVt_REGEXP) |
116 |
659 |
775 |
| if (realpack && realtype == SVt_REGEXP) |
100 |
16 |
116 |
|
| 817 |
|
| #endif |
| 818 |
|
| { |
| 819 |
100 |
| is_regex = 1; |
| 820 |
100 |
▶ | if (strEQ(realpack, "Regexp")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(realpack, "Regexp")) |
99 |
1 |
100 |
|
| 821 |
99 |
| no_bless = 1; |
| 822 |
|
| else |
| 823 |
1 |
| no_bless = 0; |
| 824 |
|
| } |
| 825 |
|
| |
| 826 |
|
| /* If purity is not set and maxdepth is set, then check depth: |
| 827 |
|
| * if we have reached maximum depth, return the string |
| 828 |
|
| * representation of the thing we are currently examining |
| 829 |
|
| * at this depth (i.e., 'Foo=ARRAY(0xdeadbeef)'). |
| 830 |
|
| */ |
| 831 |
775 |
▶ | if (!style->purity && style->maxdepth > 0 && level >= style->maxdepth) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!style->purity && style->maxdepth > 0 && level >= style->maxdepth) { |
582 |
193 |
775 |
| if (!style->purity && style->maxdepth > 0 && level >= style->maxdepth) { |
18 |
564 |
582 |
| if (!style->purity && style->maxdepth > 0 && level >= style->maxdepth) { |
6 |
12 |
18 |
|
| 832 |
|
| STRLEN vallen; |
| 833 |
6 |
| const char * const valstr = SvPV(val,vallen); |
| 834 |
6 |
| sv_catpvs(retval, "'"); |
| 835 |
6 |
| sv_catpvn(retval, valstr, vallen); |
| 836 |
6 |
| sv_catpvs(retval, "'"); |
| 837 |
6 |
| return 1; |
| 838 |
|
| } |
| 839 |
|
| |
| 840 |
769 |
▶ | if (style->maxrecurse > 0 && level >= style->maxrecurse) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (style->maxrecurse > 0 && level >= style->maxrecurse) { |
764 |
5 |
769 |
| if (style->maxrecurse > 0 && level >= style->maxrecurse) { |
4 |
760 |
764 |
|
| 841 |
4 |
| style->maxrecursed = TRUE; |
| 842 |
|
| } |
| 843 |
|
| |
| 844 |
769 |
▶ | if (realpack && !no_bless) { /* we have a blessed ref */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (realpack && !no_bless) { /* we have a blessed ref */ |
116 |
653 |
769 |
| if (realpack && !no_bless) { /* we have a blessed ref */ |
17 |
99 |
116 |
|
| 845 |
|
| STRLEN blesslen; |
| 846 |
17 |
| const char * const blessstr = SvPV(style->bless, blesslen); |
| 847 |
17 |
| sv_catpvn(retval, blessstr, blesslen); |
| 848 |
17 |
| sv_catpvs(retval, "( "); |
| 849 |
17 |
▶ | if (style->indent >= 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->indent >= 2) { |
15 |
2 |
17 |
|
| 850 |
15 |
| blesspad = apad; |
| 851 |
15 |
| apad = sv_2mortal(newSVsv(apad)); |
| 852 |
15 |
| sv_x(aTHX_ apad, " ", 1, blesslen+2); |
| 853 |
|
| } |
| 854 |
|
| } |
| 855 |
|
| |
| 856 |
769 |
| ipad = sv_x(aTHX_ Nullsv, SvPVX_const(style->xpad), SvCUR(style->xpad), level+1); |
| 857 |
769 |
| sv_2mortal(ipad); |
| 858 |
|
| |
| 859 |
769 |
▶ | if (is_regex) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_regex) { |
100 |
669 |
769 |
|
| 860 |
100 |
| dump_regexp(aTHX_ retval, val); |
| 861 |
|
| } |
| 862 |
669 |
▶ | else if ( |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( |
79 |
590 |
669 |
|
| 863 |
|
| #if PERL_VERSION_LT(5,9,0) |
| 864 |
|
| realtype <= SVt_PVBM |
| 865 |
|
| #else |
| 866 |
|
| realtype <= SVt_PVMG |
| 867 |
|
| #endif |
| 868 |
|
| ) { /* scalar ref */ |
| 869 |
79 |
| SV * const namesv = sv_2mortal(newSVpvs("${")); |
| 870 |
79 |
| sv_catpvn(namesv, name, namelen); |
| 871 |
79 |
| sv_catpvs(namesv, "}"); |
| 872 |
79 |
▶ | if (realpack) { /* blessed */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (realpack) { /* blessed */ |
0 |
79 |
79 |
|
| 873 |
0 |
| sv_catpvs(retval, "do{\\(my $o = "); |
| 874 |
0 |
| DD_dump(aTHX_ ival, SvPVX_const(namesv), SvCUR(namesv), retval, seenhv, |
| 875 |
|
| postav, level+1, apad, style); |
| 876 |
0 |
| sv_catpvs(retval, ")}"); |
| 877 |
|
| } /* plain */ |
| 878 |
|
| else { |
| 879 |
79 |
| sv_catpvs(retval, "\\"); |
| 880 |
79 |
| DD_dump(aTHX_ ival, SvPVX_const(namesv), SvCUR(namesv), retval, seenhv, |
| 881 |
|
| postav, level+1, apad, style); |
| 882 |
|
| } |
| 883 |
|
| } |
| 884 |
590 |
▶ | else if (realtype == SVt_PVGV) { /* glob ref */ |
Branch: 1 branch
| Branch | True | False | Total |
| else if (realtype == SVt_PVGV) { /* glob ref */ |
54 |
536 |
590 |
|
| 885 |
54 |
| SV * const namesv = newSVpvs("*{"); |
| 886 |
54 |
| sv_catpvn(namesv, name, namelen); |
| 887 |
54 |
| sv_catpvs(namesv, "}"); |
| 888 |
54 |
| sv_catpvs(retval, "\\"); |
| 889 |
54 |
| DD_dump(aTHX_ ival, SvPVX_const(namesv), SvCUR(namesv), retval, seenhv, |
| 890 |
|
| postav, level+1, apad, style); |
| 891 |
54 |
| SvREFCNT_dec(namesv); |
| 892 |
|
| } |
| 893 |
536 |
▶ | else if (realtype == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (realtype == SVt_PVAV) { |
296 |
240 |
536 |
|
| 894 |
|
| SV *totpad; |
| 895 |
296 |
| SSize_t ix = 0; |
| 896 |
296 |
| const SSize_t ixmax = av_len((AV *)ival); |
| 897 |
|
| |
| 898 |
296 |
| SV * const ixsv = sv_2mortal(newSViv(0)); |
| 899 |
|
| /* allowing for a 24 char wide array index */ |
| 900 |
296 |
| New(0, iname, namelen+28, char); |
| 901 |
296 |
| SAVEFREEPV(iname); |
| 902 |
296 |
| (void) strlcpy(iname, name, namelen+28); |
| 903 |
296 |
| inamelen = namelen; |
| 904 |
296 |
▶ | if (name[0] == '@') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (name[0] == '@') { |
22 |
274 |
296 |
|
| 905 |
22 |
| sv_catpvs(retval, "("); |
| 906 |
22 |
| iname[0] = '$'; |
| 907 |
|
| } |
| 908 |
|
| else { |
| 909 |
274 |
| sv_catpvs(retval, "["); |
| 910 |
|
| /* omit "->" in $foo{bar}->[0], but not in ${$foo}->[0] */ |
| 911 |
|
| /*if (namelen > 0 |
| 912 |
|
| && name[namelen-1] != ']' && name[namelen-1] != '}' |
| 913 |
|
| && (namelen < 4 || (name[1] != '{' && name[2] != '{')))*/ |
| 914 |
274 |
▶ | if ((namelen > 0 |
Branch: 1 branch
| Branch | True | False | Total |
| if ((namelen > 0 |
274 |
0 |
274 |
|
| 915 |
274 |
▶ | && name[namelen-1] != ']' && name[namelen-1] != '}') |
Branch: 2 branches
| Branch | True | False | Total |
| && name[namelen-1] != ']' && name[namelen-1] != '}') |
253 |
21 |
274 |
| && name[namelen-1] != ']' && name[namelen-1] != '}') |
161 |
92 |
253 |
|
| 916 |
182 |
▶ | || (namelen > 4 |
Branch: 1 branch
| Branch | True | False | Total |
| || (namelen > 4 |
182 |
0 |
182 |
|
| 917 |
182 |
▶ | && (name[1] == '{' |
Branch: 1 branch
| Branch | True | False | Total |
| && (name[1] == '{' |
178 |
4 |
182 |
|
| 918 |
178 |
▶ | || (name[0] == '\\' && name[2] == '{')))) |
Branch: 2 branches
| Branch | True | False | Total |
| || (name[0] == '\\' && name[2] == '{')))) |
0 |
178 |
178 |
| || (name[0] == '\\' && name[2] == '{')))) |
0 |
0 |
0 |
|
| 919 |
|
| { |
| 920 |
96 |
| iname[inamelen++] = '-'; iname[inamelen++] = '>'; |
| 921 |
96 |
| iname[inamelen] = '\0'; |
| 922 |
|
| } |
| 923 |
|
| } |
| 924 |
296 |
▶ | if (iname[0] == '*' && iname[inamelen-1] == '}' && inamelen >= 8 && |
Branch: 3 branches
| Branch | True | False | Total |
| if (iname[0] == '*' && iname[inamelen-1] == '}' && inamelen >= 8 && |
4 |
292 |
296 |
| if (iname[0] == '*' && iname[inamelen-1] == '}' && inamelen >= 8 && |
4 |
0 |
4 |
| if (iname[0] == '*' && iname[inamelen-1] == '}' && inamelen >= 8 && |
4 |
0 |
4 |
|
| 925 |
4 |
▶ | (instr(iname+inamelen-8, "{SCALAR}") || |
Branch: 1 branch
| Branch | True | False | Total |
| (instr(iname+inamelen-8, "{SCALAR}") || |
4 |
0 |
4 |
|
| 926 |
4 |
▶ | instr(iname+inamelen-7, "{ARRAY}") || |
Branch: 1 branch
| Branch | True | False | Total |
| instr(iname+inamelen-7, "{ARRAY}") || |
0 |
4 |
4 |
|
| 927 |
0 |
▶ | instr(iname+inamelen-6, "{HASH}"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| instr(iname+inamelen-6, "{HASH}"))) { |
0 |
0 |
0 |
|
| 928 |
4 |
| iname[inamelen++] = '-'; iname[inamelen++] = '>'; |
| 929 |
|
| } |
| 930 |
296 |
| iname[inamelen++] = '['; iname[inamelen] = '\0'; |
| 931 |
296 |
| totpad = sv_2mortal(newSVsv(style->sep)); |
| 932 |
296 |
| sv_catsv(totpad, style->pad); |
| 933 |
296 |
| sv_catsv(totpad, apad); |
| 934 |
|
| |
| 935 |
716 |
▶ | for (ix = 0; ix <= ixmax; ++ix) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ix = 0; ix <= ixmax; ++ix) { |
420 |
296 |
716 |
|
| 936 |
|
| STRLEN ilen; |
| 937 |
|
| SV *elem; |
| 938 |
420 |
| svp = av_fetch((AV*)ival, ix, FALSE); |
| 939 |
420 |
▶ | if (svp) |
Branch: 1 branch
| Branch | True | False | Total |
| if (svp) |
420 |
0 |
420 |
|
| 940 |
420 |
| elem = *svp; |
| 941 |
|
| else |
| 942 |
0 |
| elem = &PL_sv_undef; |
| 943 |
|
| |
| 944 |
420 |
| ilen = inamelen; |
| 945 |
420 |
| sv_setiv(ixsv, ix); |
| 946 |
420 |
| ilen = ilen + my_sprintf(iname+ilen, "%" IVdf, (IV)ix); |
| 947 |
420 |
| iname[ilen++] = ']'; iname[ilen] = '\0'; |
| 948 |
420 |
▶ | if (style->indent >= 3) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->indent >= 3) { |
16 |
404 |
420 |
|
| 949 |
16 |
| sv_catsv(retval, totpad); |
| 950 |
16 |
| sv_catsv(retval, ipad); |
| 951 |
16 |
| sv_catpvs(retval, "#"); |
| 952 |
16 |
| sv_catsv(retval, ixsv); |
| 953 |
|
| } |
| 954 |
420 |
| sv_catsv(retval, totpad); |
| 955 |
420 |
| sv_catsv(retval, ipad); |
| 956 |
420 |
| ENTER; |
| 957 |
420 |
| SAVETMPS; |
| 958 |
420 |
| DD_dump(aTHX_ elem, iname, ilen, retval, seenhv, postav, |
| 959 |
|
| level+1, apad, style); |
| 960 |
420 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
185 |
235 |
420 |
|
| 961 |
420 |
| LEAVE; |
| 962 |
420 |
▶ | if (ix < ixmax || (style->trailingcomma && style->indent >= 1)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (ix < ixmax || (style->trailingcomma && style->indent >= 1)) |
181 |
239 |
420 |
| if (ix < ixmax || (style->trailingcomma && style->indent >= 1)) |
6 |
175 |
181 |
| if (ix < ixmax || (style->trailingcomma && style->indent >= 1)) |
4 |
2 |
6 |
|
| 963 |
243 |
| sv_catpvs(retval, ","); |
| 964 |
|
| } |
| 965 |
296 |
▶ | if (ixmax >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ixmax >= 0) { |
181 |
115 |
296 |
|
| 966 |
181 |
| SV * const opad = sv_x(aTHX_ Nullsv, SvPVX_const(style->xpad), SvCUR(style->xpad), level); |
| 967 |
181 |
| sv_catsv(retval, totpad); |
| 968 |
181 |
| sv_catsv(retval, opad); |
| 969 |
181 |
| SvREFCNT_dec(opad); |
| 970 |
|
| } |
| 971 |
296 |
▶ | if (name[0] == '@') |
Branch: 1 branch
| Branch | True | False | Total |
| if (name[0] == '@') |
22 |
274 |
296 |
|
| 972 |
22 |
| sv_catpvs(retval, ")"); |
| 973 |
|
| else |
| 974 |
274 |
| sv_catpvs(retval, "]"); |
| 975 |
|
| } |
| 976 |
240 |
▶ | else if (realtype == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (realtype == SVt_PVHV) { |
229 |
11 |
240 |
|
| 977 |
|
| SV *totpad, *newapad; |
| 978 |
|
| SV *sname; |
| 979 |
229 |
| HE *entry = NULL; |
| 980 |
|
| char *key; |
| 981 |
|
| SV *hval; |
| 982 |
229 |
| AV *keys = NULL; |
| 983 |
|
| |
| 984 |
229 |
| SV * const iname = newSVpvn_flags(name, namelen, SVs_TEMP); |
| 985 |
229 |
▶ | if (name[0] == '%') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (name[0] == '%') { |
9 |
220 |
229 |
|
| 986 |
9 |
| sv_catpvs(retval, "("); |
| 987 |
9 |
| (SvPVX(iname))[0] = '$'; |
| 988 |
|
| } |
| 989 |
|
| else { |
| 990 |
220 |
| sv_catpvs(retval, "{"); |
| 991 |
|
| /* omit "->" in $foo[0]->{bar}, but not in ${$foo}->{bar} */ |
| 992 |
220 |
▶ | if ((namelen > 0 |
Branch: 1 branch
| Branch | True | False | Total |
| if ((namelen > 0 |
220 |
0 |
220 |
|
| 993 |
220 |
▶ | && name[namelen-1] != ']' && name[namelen-1] != '}') |
Branch: 2 branches
| Branch | True | False | Total |
| && name[namelen-1] != ']' && name[namelen-1] != '}') |
154 |
66 |
220 |
| && name[namelen-1] != ']' && name[namelen-1] != '}') |
38 |
116 |
154 |
|
| 994 |
104 |
▶ | || (namelen > 4 |
Branch: 1 branch
| Branch | True | False | Total |
| || (namelen > 4 |
104 |
0 |
104 |
|
| 995 |
104 |
▶ | && (name[1] == '{' |
Branch: 1 branch
| Branch | True | False | Total |
| && (name[1] == '{' |
88 |
16 |
104 |
|
| 996 |
88 |
▶ | || (name[0] == '\\' && name[2] == '{')))) |
Branch: 2 branches
| Branch | True | False | Total |
| || (name[0] == '\\' && name[2] == '{')))) |
0 |
88 |
88 |
| || (name[0] == '\\' && name[2] == '{')))) |
0 |
0 |
0 |
|
| 997 |
|
| { |
| 998 |
132 |
| sv_catpvs(iname, "->"); |
| 999 |
|
| } |
| 1000 |
|
| } |
| 1001 |
229 |
▶ | if (name[0] == '*' && name[namelen-1] == '}' && namelen >= 8 && |
Branch: 3 branches
| Branch | True | False | Total |
| if (name[0] == '*' && name[namelen-1] == '}' && namelen >= 8 && |
24 |
205 |
229 |
| if (name[0] == '*' && name[namelen-1] == '}' && namelen >= 8 && |
20 |
4 |
24 |
| if (name[0] == '*' && name[namelen-1] == '}' && namelen >= 8 && |
20 |
0 |
20 |
|
| 1002 |
20 |
▶ | (instr(name+namelen-8, "{SCALAR}") || |
Branch: 1 branch
| Branch | True | False | Total |
| (instr(name+namelen-8, "{SCALAR}") || |
20 |
0 |
20 |
|
| 1003 |
20 |
▶ | instr(name+namelen-7, "{ARRAY}") || |
Branch: 1 branch
| Branch | True | False | Total |
| instr(name+namelen-7, "{ARRAY}") || |
20 |
0 |
20 |
|
| 1004 |
20 |
▶ | instr(name+namelen-6, "{HASH}"))) { |
Branch: 1 branch
| Branch | True | False | Total |
| instr(name+namelen-6, "{HASH}"))) { |
20 |
0 |
20 |
|
| 1005 |
20 |
| sv_catpvs(iname, "->"); |
| 1006 |
|
| } |
| 1007 |
229 |
| sv_catpvs(iname, "{"); |
| 1008 |
229 |
| totpad = sv_2mortal(newSVsv(style->sep)); |
| 1009 |
229 |
| sv_catsv(totpad, style->pad); |
| 1010 |
229 |
| sv_catsv(totpad, apad); |
| 1011 |
|
| |
| 1012 |
|
| /* If requested, get a sorted/filtered array of hash keys */ |
| 1013 |
229 |
▶ | if (style->sortkeys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->sortkeys) { |
118 |
111 |
229 |
|
| 1014 |
118 |
▶ | if (style->sortkeys == &PL_sv_yes) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->sortkeys == &PL_sv_yes) { |
103 |
15 |
118 |
|
| 1015 |
103 |
| keys = newAV(); |
| 1016 |
103 |
| (void)hv_iterinit((HV*)ival); |
| 1017 |
389 |
▶ | while ((entry = hv_iternext((HV*)ival))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((entry = hv_iternext((HV*)ival))) { |
286 |
103 |
389 |
|
| 1018 |
286 |
| sv = hv_iterkeysv(entry); |
| 1019 |
286 |
| (void)SvREFCNT_inc(sv); |
| 1020 |
286 |
| av_push(keys, sv); |
| 1021 |
|
| } |
| 1022 |
|
| #ifdef USE_LOCALE_COLLATE |
| 1023 |
|
| # ifdef IN_LC /* Use this if available */ |
| 1024 |
103 |
▶ | if (IN_LC(LC_COLLATE)) |
Branch: 15 branches
| Branch | True | False | Total |
| if (IN_LC(LC_COLLATE)) |
0 |
103 |
103 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
| if (IN_LC(LC_COLLATE)) |
0 |
103 |
103 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
| if (IN_LC(LC_COLLATE)) |
103 |
0 |
103 |
| if (IN_LC(LC_COLLATE)) |
0 |
103 |
103 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
| if (IN_LC(LC_COLLATE)) |
103 |
0 |
103 |
| if (IN_LC(LC_COLLATE)) |
0 |
103 |
103 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
| if (IN_LC(LC_COLLATE)) |
0 |
0 |
0 |
|
| 1025 |
|
| # else |
| 1026 |
|
| if (IN_LOCALE) |
| 1027 |
|
| # endif |
| 1028 |
|
| { |
| 1029 |
0 |
| sortsv(AvARRAY(keys), |
| 1030 |
|
| av_len(keys)+1, |
| 1031 |
|
| Perl_sv_cmp_locale); |
| 1032 |
|
| } |
| 1033 |
|
| else |
| 1034 |
|
| #endif |
| 1035 |
|
| { |
| 1036 |
103 |
| sortsv(AvARRAY(keys), |
| 1037 |
|
| av_len(keys)+1, |
| 1038 |
|
| Perl_sv_cmp); |
| 1039 |
|
| } |
| 1040 |
|
| } |
| 1041 |
|
| else |
| 1042 |
|
| { |
| 1043 |
15 |
▶ | dSP; ENTER; SAVETMPS; PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| dSP; ENTER; SAVETMPS; PUSHMARK(sp); |
0 |
15 |
15 |
|
| 1044 |
15 |
▶ | XPUSHs(sv_2mortal(newRV_inc(ival))); PUTBACK; |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newRV_inc(ival))); PUTBACK; |
0 |
15 |
15 |
|
| 1045 |
15 |
| i = perl_call_sv(style->sortkeys, G_SCALAR | G_EVAL); |
| 1046 |
15 |
| SPAGAIN; |
| 1047 |
15 |
▶ | if (i) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (i) { |
15 |
0 |
15 |
|
| 1048 |
15 |
| sv = POPs; |
| 1049 |
15 |
▶ | if (SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVAV)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVAV)) |
15 |
0 |
15 |
| if (SvROK(sv) && (SvTYPE(SvRV(sv)) == SVt_PVAV)) |
14 |
1 |
15 |
|
| 1050 |
14 |
| keys = (AV*)SvREFCNT_inc(SvRV(sv)); |
| 1051 |
|
| } |
| 1052 |
15 |
▶ | if (! keys) |
Branch: 1 branch
| Branch | True | False | Total |
| if (! keys) |
1 |
14 |
15 |
|
| 1053 |
1 |
| warn("Sortkeys subroutine did not return ARRAYREF\n"); |
| 1054 |
15 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
15 |
0 |
15 |
|
| 1055 |
|
| } |
| 1056 |
118 |
▶ | if (keys) |
Branch: 1 branch
| Branch | True | False | Total |
| if (keys) |
117 |
1 |
118 |
|
| 1057 |
117 |
| sv_2mortal((SV*)keys); |
| 1058 |
|
| } |
| 1059 |
|
| else |
| 1060 |
111 |
| (void)hv_iterinit((HV*)ival); |
| 1061 |
|
| |
| 1062 |
|
| /* foreach (keys %hash) */ |
| 1063 |
898 |
| for (i = 0; 1; i++) { |
| 1064 |
|
| char *nkey; |
| 1065 |
898 |
| char *nkey_buffer = NULL; |
| 1066 |
898 |
| STRLEN nticks = 0; |
| 1067 |
|
| SV* keysv; |
| 1068 |
|
| STRLEN klen; |
| 1069 |
|
| STRLEN keylen; |
| 1070 |
|
| STRLEN nlen; |
| 1071 |
898 |
| bool do_utf8 = FALSE; |
| 1072 |
|
| |
| 1073 |
898 |
▶ | if (style->sortkeys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->sortkeys) { |
535 |
363 |
898 |
|
| 1074 |
535 |
▶ | if (!(keys && (SSize_t)i <= av_len(keys))) break; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(keys && (SSize_t)i <= av_len(keys))) break; |
534 |
1 |
535 |
| if (!(keys && (SSize_t)i <= av_len(keys))) break; |
417 |
117 |
534 |
|
| 1075 |
|
| } else { |
| 1076 |
363 |
▶ | if (!(entry = hv_iternext((HV *)ival))) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(entry = hv_iternext((HV *)ival))) break; |
111 |
252 |
363 |
|
| 1077 |
|
| } |
| 1078 |
|
| |
| 1079 |
669 |
▶ | if (i) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i) |
452 |
217 |
669 |
|
| 1080 |
452 |
| sv_catpvs(retval, ","); |
| 1081 |
|
| |
| 1082 |
669 |
▶ | if (style->sortkeys) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->sortkeys) { |
417 |
252 |
669 |
|
| 1083 |
|
| char *key; |
| 1084 |
417 |
| svp = av_fetch(keys, i, FALSE); |
| 1085 |
417 |
▶ | keysv = svp ? *svp : sv_newmortal(); |
Branch: 1 branch
| Branch | True | False | Total |
| keysv = svp ? *svp : sv_newmortal(); |
417 |
0 |
417 |
|
| 1086 |
417 |
| key = SvPV(keysv, keylen); |
| 1087 |
417 |
▶ | svp = hv_fetch((HV*)ival, key, |
Branch: 1 branch
| Branch | True | False | Total |
| svp = hv_fetch((HV*)ival, key, |
8 |
409 |
417 |
|
| 1088 |
|
| SvUTF8(keysv) ? -(I32)keylen : (I32)keylen, 0); |
| 1089 |
417 |
▶ | hval = svp ? *svp : sv_newmortal(); |
Branch: 1 branch
| Branch | True | False | Total |
| hval = svp ? *svp : sv_newmortal(); |
417 |
0 |
417 |
|
| 1090 |
|
| } |
| 1091 |
|
| else { |
| 1092 |
252 |
| keysv = hv_iterkeysv(entry); |
| 1093 |
252 |
| hval = hv_iterval((HV*)ival, entry); |
| 1094 |
|
| } |
| 1095 |
|
| |
| 1096 |
669 |
| key = SvPV(keysv, keylen); |
| 1097 |
669 |
▶ | do_utf8 = DO_UTF8(keysv); |
Branch: 2 branches
| Branch | True | False | Total |
| do_utf8 = DO_UTF8(keysv); |
14 |
655 |
669 |
| do_utf8 = DO_UTF8(keysv); |
14 |
0 |
14 |
|
| 1098 |
669 |
| klen = keylen; |
| 1099 |
|
| |
| 1100 |
669 |
| sv_catsv(retval, totpad); |
| 1101 |
669 |
| sv_catsv(retval, ipad); |
| 1102 |
|
| |
| 1103 |
669 |
| ENTER; |
| 1104 |
669 |
| SAVETMPS; |
| 1105 |
|
| |
| 1106 |
|
| /* The (very) |
| 1107 |
|
| old logic was first to check utf8 flag, and if utf8 always |
| 1108 |
|
| call esc_q_utf8. This caused test to break under -Mutf8, |
| 1109 |
|
| because there even strings like 'c' have utf8 flag on. |
| 1110 |
|
| Hence with quotekeys == 0 the XS code would still '' quote |
| 1111 |
|
| them based on flags, whereas the perl code would not, |
| 1112 |
|
| based on regexps. |
| 1113 |
|
| |
| 1114 |
|
| The old logic checked that the string was a valid |
| 1115 |
|
| perl glob name (foo::bar), which isn't safe under |
| 1116 |
|
| strict, and differs from the perl code which only |
| 1117 |
|
| accepts simple identifiers. |
| 1118 |
|
| |
| 1119 |
|
| With the fix for [perl #120384] I chose to make |
| 1120 |
|
| their handling of key quoting compatible between XS |
| 1121 |
|
| and perl. |
| 1122 |
|
| */ |
| 1123 |
669 |
▶ | if (style->quotekeys || key_needs_quote(key,keylen)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (style->quotekeys || key_needs_quote(key,keylen)) { |
158 |
511 |
669 |
| if (style->quotekeys || key_needs_quote(key,keylen)) { |
14 |
144 |
158 |
|
| 1124 |
525 |
▶ | if (do_utf8 || style->useqq) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (do_utf8 || style->useqq) { |
513 |
12 |
525 |
| if (do_utf8 || style->useqq) { |
21 |
492 |
513 |
|
| 1125 |
33 |
| STRLEN ocur = SvCUR(retval); |
| 1126 |
33 |
| klen = nlen = esc_q_utf8(aTHX_ retval, key, klen, do_utf8, style->useqq); |
| 1127 |
33 |
| nkey = SvPVX(retval) + ocur; |
| 1128 |
|
| } |
| 1129 |
|
| else { |
| 1130 |
492 |
| nticks = num_q(key, klen); |
| 1131 |
492 |
| New(0, nkey_buffer, klen+nticks+3, char); |
| 1132 |
492 |
| SAVEFREEPV(nkey_buffer); |
| 1133 |
492 |
| nkey = nkey_buffer; |
| 1134 |
492 |
| nkey[0] = '\''; |
| 1135 |
492 |
▶ | if (nticks) |
Branch: 1 branch
| Branch | True | False | Total |
| if (nticks) |
0 |
492 |
492 |
|
| 1136 |
0 |
| klen += esc_q(nkey+1, key, klen); |
| 1137 |
|
| else |
| 1138 |
492 |
| (void)Copy(key, nkey+1, klen, char); |
| 1139 |
492 |
| nkey[++klen] = '\''; |
| 1140 |
492 |
| nkey[++klen] = '\0'; |
| 1141 |
492 |
| nlen = klen; |
| 1142 |
492 |
| sv_catpvn(retval, nkey, klen); |
| 1143 |
|
| } |
| 1144 |
|
| } |
| 1145 |
|
| else { |
| 1146 |
144 |
| nkey = key; |
| 1147 |
144 |
| nlen = klen; |
| 1148 |
144 |
| sv_catpvn(retval, nkey, klen); |
| 1149 |
|
| } |
| 1150 |
|
| |
| 1151 |
669 |
| sname = sv_2mortal(newSVsv(iname)); |
| 1152 |
669 |
| sv_catpvn(sname, nkey, nlen); |
| 1153 |
669 |
| sv_catpvs(sname, "}"); |
| 1154 |
|
| |
| 1155 |
669 |
| sv_catsv(retval, style->pair); |
| 1156 |
669 |
▶ | if (style->indent >= 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->indent >= 2) { |
348 |
321 |
669 |
|
| 1157 |
|
| char *extra; |
| 1158 |
348 |
| STRLEN elen = 0; |
| 1159 |
348 |
| newapad = sv_2mortal(newSVsv(apad)); |
| 1160 |
348 |
| New(0, extra, klen+4+1, char); |
| 1161 |
3796 |
▶ | while (elen < (klen+4)) |
Branch: 1 branch
| Branch | True | False | Total |
| while (elen < (klen+4)) |
3448 |
348 |
3796 |
|
| 1162 |
3448 |
| extra[elen++] = ' '; |
| 1163 |
348 |
| extra[elen] = '\0'; |
| 1164 |
348 |
| sv_catpvn(newapad, extra, elen); |
| 1165 |
348 |
| Safefree(extra); |
| 1166 |
|
| } |
| 1167 |
|
| else |
| 1168 |
321 |
| newapad = apad; |
| 1169 |
|
| |
| 1170 |
669 |
| DD_dump(aTHX_ hval, SvPVX_const(sname), SvCUR(sname), retval, seenhv, |
| 1171 |
|
| postav, level+1, newapad, style); |
| 1172 |
|
| |
| 1173 |
669 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
669 |
0 |
669 |
|
| 1174 |
669 |
| LEAVE; |
| 1175 |
|
| } |
| 1176 |
229 |
▶ | if (i) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (i) { |
217 |
12 |
229 |
|
| 1177 |
217 |
| SV *opad = sv_x(aTHX_ Nullsv, SvPVX_const(style->xpad), |
| 1178 |
217 |
| SvCUR(style->xpad), level); |
| 1179 |
217 |
▶ | if (style->trailingcomma && style->indent >= 1) |
Branch: 2 branches
| Branch | True | False | Total |
| if (style->trailingcomma && style->indent >= 1) |
6 |
211 |
217 |
| if (style->trailingcomma && style->indent >= 1) |
4 |
2 |
6 |
|
| 1180 |
4 |
| sv_catpvs(retval, ","); |
| 1181 |
217 |
| sv_catsv(retval, totpad); |
| 1182 |
217 |
| sv_catsv(retval, opad); |
| 1183 |
217 |
| SvREFCNT_dec(opad); |
| 1184 |
|
| } |
| 1185 |
229 |
▶ | if (name[0] == '%') |
Branch: 1 branch
| Branch | True | False | Total |
| if (name[0] == '%') |
9 |
220 |
229 |
|
| 1186 |
9 |
| sv_catpvs(retval, ")"); |
| 1187 |
|
| else |
| 1188 |
220 |
| sv_catpvs(retval, "}"); |
| 1189 |
|
| } |
| 1190 |
11 |
▶ | else if (realtype == SVt_PVCV) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (realtype == SVt_PVCV) { |
11 |
0 |
11 |
|
| 1191 |
11 |
▶ | if (style->deparse) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->deparse) { |
5 |
6 |
11 |
|
| 1192 |
5 |
| SV *deparsed = sv_2mortal(deparsed_output(aTHX_ val)); |
| 1193 |
5 |
| SV *fullpad = sv_2mortal(newSVsv(style->sep)); |
| 1194 |
|
| const char *p; |
| 1195 |
|
| STRLEN plen; |
| 1196 |
|
| I32 i; |
| 1197 |
|
| |
| 1198 |
5 |
| sv_catsv(fullpad, style->pad); |
| 1199 |
5 |
| sv_catsv(fullpad, apad); |
| 1200 |
9 |
▶ | for (i = 0; i < level; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < level; i++) { |
4 |
5 |
9 |
|
| 1201 |
4 |
| sv_catsv(fullpad, style->xpad); |
| 1202 |
|
| } |
| 1203 |
|
| |
| 1204 |
5 |
| sv_catpvs(retval, "sub "); |
| 1205 |
5 |
| p = SvPV(deparsed, plen); |
| 1206 |
23 |
▶ | while (plen > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (plen > 0) { |
23 |
0 |
23 |
|
| 1207 |
23 |
| const char *nl = (const char *) memchr(p, '\n', plen); |
| 1208 |
23 |
▶ | if (!nl) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!nl) { |
5 |
18 |
23 |
|
| 1209 |
5 |
| sv_catpvn(retval, p, plen); |
| 1210 |
5 |
| break; |
| 1211 |
|
| } |
| 1212 |
|
| else { |
| 1213 |
18 |
| size_t n = nl - p; |
| 1214 |
18 |
| sv_catpvn(retval, p, n); |
| 1215 |
18 |
| sv_catsv(retval, fullpad); |
| 1216 |
18 |
| p += n + 1; |
| 1217 |
18 |
| plen -= n + 1; |
| 1218 |
|
| } |
| 1219 |
|
| } |
| 1220 |
|
| } |
| 1221 |
|
| else { |
| 1222 |
6 |
| sv_catpvs(retval, "sub { \"DUMMY\" }"); |
| 1223 |
6 |
▶ | if (style->purity) |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->purity) |
0 |
6 |
6 |
|
| 1224 |
0 |
| warn("Encountered CODE ref, using dummy placeholder"); |
| 1225 |
|
| } |
| 1226 |
|
| } |
| 1227 |
|
| else { |
| 1228 |
0 |
| warn("cannot handle ref type %d", (int)realtype); |
| 1229 |
|
| } |
| 1230 |
|
| |
| 1231 |
769 |
▶ | if (realpack && !no_bless) { /* free blessed allocs */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (realpack && !no_bless) { /* free blessed allocs */ |
116 |
653 |
769 |
| if (realpack && !no_bless) { /* free blessed allocs */ |
17 |
99 |
116 |
|
| 1232 |
|
| STRLEN plen, pticks; |
| 1233 |
|
| |
| 1234 |
17 |
▶ | if (style->indent >= 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->indent >= 2) { |
15 |
2 |
17 |
|
| 1235 |
15 |
| apad = blesspad; |
| 1236 |
|
| } |
| 1237 |
17 |
| sv_catpvs(retval, ", '"); |
| 1238 |
|
| |
| 1239 |
17 |
| plen = strlen(realpack); |
| 1240 |
17 |
| pticks = num_q(realpack, plen); |
| 1241 |
17 |
▶ | if (pticks) { /* needs escaping */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (pticks) { /* needs escaping */ |
2 |
15 |
17 |
|
| 1242 |
|
| char *npack; |
| 1243 |
2 |
| char *npack_buffer = NULL; |
| 1244 |
|
| |
| 1245 |
2 |
| New(0, npack_buffer, plen+pticks+1, char); |
| 1246 |
2 |
| npack = npack_buffer; |
| 1247 |
2 |
| plen += esc_q(npack, realpack, plen); |
| 1248 |
2 |
| npack[plen] = '\0'; |
| 1249 |
|
| |
| 1250 |
2 |
| sv_catpvn(retval, npack, plen); |
| 1251 |
2 |
| Safefree(npack_buffer); |
| 1252 |
|
| } |
| 1253 |
|
| else { |
| 1254 |
15 |
| sv_catpvn(retval, realpack, strlen(realpack)); |
| 1255 |
|
| } |
| 1256 |
17 |
| sv_catpvs(retval, "' )"); |
| 1257 |
17 |
▶ | if (style->toaster && SvPOK(style->toaster) && SvCUR(style->toaster)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (style->toaster && SvPOK(style->toaster) && SvCUR(style->toaster)) { |
17 |
0 |
17 |
| if (style->toaster && SvPOK(style->toaster) && SvCUR(style->toaster)) { |
17 |
0 |
17 |
| if (style->toaster && SvPOK(style->toaster) && SvCUR(style->toaster)) { |
0 |
17 |
17 |
|
| 1258 |
0 |
| sv_catpvs(retval, "->"); |
| 1259 |
0 |
| sv_catsv(retval, style->toaster); |
| 1260 |
0 |
| sv_catpvs(retval, "()"); |
| 1261 |
|
| } |
| 1262 |
|
| } |
| 1263 |
|
| } |
| 1264 |
|
| else { |
| 1265 |
|
| STRLEN i; |
| 1266 |
|
| STRLEN vstr_len; |
| 1267 |
|
| const char *vstr_pv; |
| 1268 |
|
| |
| 1269 |
3884 |
▶ | if (namelen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (namelen) { |
3884 |
0 |
3884 |
|
| 1270 |
3884 |
| id_buffer = PTR2UV(val); |
| 1271 |
3884 |
| idlen = sizeof(id_buffer); |
| 1272 |
3884 |
▶ | if ((svp = hv_fetch(seenhv, id, idlen, FALSE)) && |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetch(seenhv, id, idlen, FALSE)) && |
110 |
3774 |
3884 |
|
| 1273 |
110 |
▶ | (sv = *svp) && SvROK(sv) && |
Branch: 2 branches
| Branch | True | False | Total |
| (sv = *svp) && SvROK(sv) && |
110 |
0 |
110 |
| (sv = *svp) && SvROK(sv) && |
110 |
0 |
110 |
|
| 1274 |
110 |
▶ | (seenentry = (AV*)SvRV(sv))) |
Branch: 1 branch
| Branch | True | False | Total |
| (seenentry = (AV*)SvRV(sv))) |
110 |
0 |
110 |
|
| 1275 |
102 |
| { |
| 1276 |
|
| SV *othername; |
| 1277 |
110 |
▶ | if ((svp = av_fetch(seenentry, 0, FALSE)) && (othername = *svp) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((svp = av_fetch(seenentry, 0, FALSE)) && (othername = *svp) |
110 |
0 |
110 |
| if ((svp = av_fetch(seenentry, 0, FALSE)) && (othername = *svp) |
110 |
0 |
110 |
|
| 1278 |
110 |
▶ | && (svp = av_fetch(seenentry, 2, FALSE)) && *svp && SvIV(*svp) > 0) |
Branch: 3 branches
| Branch | True | False | Total |
| && (svp = av_fetch(seenentry, 2, FALSE)) && *svp && SvIV(*svp) > 0) |
8 |
102 |
110 |
| && (svp = av_fetch(seenentry, 2, FALSE)) && *svp && SvIV(*svp) > 0) |
8 |
0 |
8 |
| && (svp = av_fetch(seenentry, 2, FALSE)) && *svp && SvIV(*svp) > 0) |
8 |
0 |
8 |
|
| 1279 |
|
| { |
| 1280 |
8 |
| sv_catpvs(retval, "${"); |
| 1281 |
8 |
| sv_catsv(retval, othername); |
| 1282 |
8 |
| sv_catpvs(retval, "}"); |
| 1283 |
8 |
| return 1; |
| 1284 |
|
| } |
| 1285 |
|
| } |
| 1286 |
|
| /* If we're allowed to keep only a sparse "seen" hash |
| 1287 |
|
| * (IOW, the user does not expect it to contain everything |
| 1288 |
|
| * after the dump, then only store in seen hash if the SV |
| 1289 |
|
| * ref count is larger than 1. If it's 1, then we know that |
| 1290 |
|
| * there is no other reference, duh. This is an optimization. |
| 1291 |
|
| * Note that we'd have to check for weak-refs, too, but this is |
| 1292 |
|
| * already the branch for non-refs only. */ |
| 1293 |
3774 |
▶ | else if (val != &PL_sv_undef && (!style->use_sparse_seen_hash || SvREFCNT(val) > 1)) { |
Branch: 3 branches
| Branch | True | False | Total |
| else if (val != &PL_sv_undef && (!style->use_sparse_seen_hash || SvREFCNT(val) > 1)) { |
3774 |
0 |
3774 |
| else if (val != &PL_sv_undef && (!style->use_sparse_seen_hash || SvREFCNT(val) > 1)) { |
16 |
3758 |
3774 |
| else if (val != &PL_sv_undef && (!style->use_sparse_seen_hash || SvREFCNT(val) > 1)) { |
0 |
16 |
16 |
|
| 1294 |
3758 |
| SV * const namesv = newSVpvs("\\"); |
| 1295 |
3758 |
| sv_catpvn(namesv, name, namelen); |
| 1296 |
3758 |
| seenentry = newAV(); |
| 1297 |
3758 |
| av_push(seenentry, namesv); |
| 1298 |
3758 |
| av_push(seenentry, newRV_inc(val)); |
| 1299 |
3758 |
| (void)hv_store(seenhv, id, idlen, newRV_inc((SV*)seenentry), 0); |
| 1300 |
3758 |
| SvREFCNT_dec(seenentry); |
| 1301 |
|
| } |
| 1302 |
|
| } |
| 1303 |
|
| |
| 1304 |
|
| #ifdef SvIsBOOL |
| 1305 |
3876 |
▶ | if (SvIsBOOL(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvIsBOOL(val)) { |
4 |
3872 |
3876 |
|
| 1306 |
4 |
▶ | if (SvTRUE(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(val)) { |
2 |
2 |
4 |
|
| 1307 |
2 |
| sv_catpvs(retval, "!!1"); |
| 1308 |
|
| } |
| 1309 |
|
| else { |
| 1310 |
2 |
| sv_catpvs(retval, "!!0"); |
| 1311 |
|
| } |
| 1312 |
|
| } |
| 1313 |
|
| else |
| 1314 |
|
| #endif |
| 1315 |
3872 |
▶ | if (DD_is_integer(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (DD_is_integer(val)) { |
920 |
2952 |
3872 |
|
| 1316 |
|
| STRLEN len; |
| 1317 |
920 |
▶ | if (SvIsUV(val)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvIsUV(val)) |
0 |
920 |
920 |
|
| 1318 |
0 |
| len = my_snprintf(tmpbuf, sizeof(tmpbuf), "%" UVuf, SvUV(val)); |
| 1319 |
|
| else |
| 1320 |
920 |
| len = my_snprintf(tmpbuf, sizeof(tmpbuf), "%" IVdf, SvIV(val)); |
| 1321 |
920 |
▶ | if (SvPOK(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvPOK(val)) { |
48 |
872 |
920 |
|
| 1322 |
|
| /* Need to check to see if this is a string such as " 0". |
| 1323 |
|
| I'm assuming from sprintf isn't going to clash with utf8. */ |
| 1324 |
|
| STRLEN pvlen; |
| 1325 |
48 |
| const char * const pv = SvPV(val, pvlen); |
| 1326 |
48 |
▶ | if (pvlen != len || memNE(pv, tmpbuf, len)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (pvlen != len || memNE(pv, tmpbuf, len)) |
16 |
32 |
48 |
| if (pvlen != len || memNE(pv, tmpbuf, len)) |
0 |
16 |
16 |
|
| 1327 |
32 |
| goto integer_came_from_string; |
| 1328 |
|
| } |
| 1329 |
888 |
▶ | if (len > 10) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > 10) { |
12 |
876 |
888 |
|
| 1330 |
|
| /* Looks like we're on a 64 bit system. Make it a string so that |
| 1331 |
|
| if a 32 bit system reads the number it will cope better. */ |
| 1332 |
12 |
| sv_catpvf(retval, "'%s'", tmpbuf); |
| 1333 |
|
| } else |
| 1334 |
876 |
| sv_catpvn(retval, tmpbuf, len); |
| 1335 |
|
| } |
| 1336 |
2952 |
▶ | else if (realtype == SVt_PVGV) {/* GLOBs can end up with scribbly names */ |
Branch: 1 branch
| Branch | True | False | Total |
| else if (realtype == SVt_PVGV) {/* GLOBs can end up with scribbly names */ |
75 |
2877 |
2952 |
|
| 1337 |
75 |
| c = SvPV(val, i); |
| 1338 |
75 |
▶ | if(i) ++c, --i; /* just get the name */ |
Branch: 1 branch
| Branch | True | False | Total |
| if(i) ++c, --i; /* just get the name */ |
75 |
0 |
75 |
|
| 1339 |
75 |
▶ | if (memBEGINs(c, i, "main::")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (memBEGINs(c, i, "main::")) { |
75 |
0 |
75 |
| if (memBEGINs(c, i, "main::")) { |
53 |
22 |
75 |
|
| 1340 |
53 |
| c += 4; |
| 1341 |
53 |
▶ | if (i == 6) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i == 6) |
1 |
52 |
53 |
|
| 1342 |
53 |
| i = 0; else i -= 4; |
| 1343 |
|
| } |
| 1344 |
75 |
▶ | if (globname_needs_quote(c,i)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (globname_needs_quote(c,i)) { |
44 |
31 |
75 |
|
| 1345 |
44 |
| sv_grow(retval, SvCUR(retval)+3); |
| 1346 |
44 |
| r = SvPVX(retval)+SvCUR(retval); |
| 1347 |
44 |
| r[0] = '*'; r[1] = '{'; r[2] = 0; |
| 1348 |
44 |
| SvCUR_set(retval, SvCUR(retval)+2); |
| 1349 |
88 |
| i = 3 + esc_q_utf8(aTHX_ retval, c, i, |
| 1350 |
|
| #ifdef GvNAMEUTF8 |
| 1351 |
44 |
| cBOOL(GvNAMEUTF8(val)), style->useqq |
| 1352 |
|
| #else |
| 1353 |
|
| 0, style->useqq || globname_supra_ascii(c, i) |
| 1354 |
|
| #endif |
| 1355 |
|
| ); |
| 1356 |
44 |
| sv_grow(retval, SvCUR(retval)+2); |
| 1357 |
44 |
| r = SvPVX(retval)+SvCUR(retval); |
| 1358 |
44 |
| r[0] = '}'; r[1] = '\0'; |
| 1359 |
44 |
| SvCUR_set(retval, SvCUR(retval)+1); |
| 1360 |
44 |
| r = r+1 - i; |
| 1361 |
|
| } |
| 1362 |
|
| else { |
| 1363 |
31 |
| sv_grow(retval, SvCUR(retval)+i+2); |
| 1364 |
31 |
| r = SvPVX(retval)+SvCUR(retval); |
| 1365 |
31 |
| r[0] = '*'; strlcpy(r+1, c, SvLEN(retval)); |
| 1366 |
31 |
| i++; |
| 1367 |
31 |
| SvCUR_set(retval, SvCUR(retval)+i); |
| 1368 |
|
| } |
| 1369 |
|
| |
| 1370 |
75 |
▶ | if (style->purity) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->purity) { |
24 |
51 |
75 |
|
| 1371 |
|
| static const char* const entries[] = { "{SCALAR}", "{ARRAY}", "{HASH}" }; |
| 1372 |
|
| static const STRLEN sizes[] = { 8, 7, 6 }; |
| 1373 |
|
| SV *e; |
| 1374 |
24 |
| SV * const nname = newSVpvs(""); |
| 1375 |
24 |
| SV * const newapad = newSVpvs(""); |
| 1376 |
24 |
| GV * const gv = (GV*)val; |
| 1377 |
|
| I32 j; |
| 1378 |
|
| |
| 1379 |
96 |
▶ | for (j=0; j<3; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j=0; j<3; j++) { |
72 |
24 |
96 |
|
| 1380 |
72 |
▶ | e = ((j == 0) ? GvSV(gv) : (j == 1) ? (SV*)GvAV(gv) : (SV*)GvHV(gv)); |
Branch: 2 branches
| Branch | True | False | Total |
| e = ((j == 0) ? GvSV(gv) : (j == 1) ? (SV*)GvAV(gv) : (SV*)GvHV(gv)); |
24 |
48 |
72 |
| e = ((j == 0) ? GvSV(gv) : (j == 1) ? (SV*)GvAV(gv) : (SV*)GvHV(gv)); |
24 |
24 |
48 |
|
| 1381 |
72 |
▶ | if (!e) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!e) |
16 |
56 |
72 |
|
| 1382 |
16 |
| continue; |
| 1383 |
56 |
▶ | if (j == 0 && !SvOK(e)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (j == 0 && !SvOK(e)) |
24 |
32 |
56 |
| if (j == 0 && !SvOK(e)) |
12 |
12 |
24 |
|
| 1384 |
12 |
| continue; |
| 1385 |
|
| |
| 1386 |
|
| { |
| 1387 |
44 |
| SV *postentry = newSVpvn(r,i); |
| 1388 |
|
| |
| 1389 |
44 |
| sv_setsv(nname, postentry); |
| 1390 |
44 |
| sv_catpvn(nname, entries[j], sizes[j]); |
| 1391 |
44 |
| sv_catpvs(postentry, " = "); |
| 1392 |
44 |
| av_push(postav, postentry); |
| 1393 |
44 |
| e = newRV_inc(e); |
| 1394 |
|
| |
| 1395 |
44 |
| SvCUR_set(newapad, 0); |
| 1396 |
44 |
▶ | if (style->indent >= 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->indent >= 2) |
6 |
38 |
44 |
|
| 1397 |
6 |
| (void)sv_x(aTHX_ newapad, " ", 1, SvCUR(postentry)); |
| 1398 |
|
| |
| 1399 |
44 |
| DD_dump(aTHX_ e, SvPVX_const(nname), SvCUR(nname), postentry, |
| 1400 |
|
| seenhv, postav, 0, newapad, style); |
| 1401 |
44 |
| SvREFCNT_dec(e); |
| 1402 |
|
| } |
| 1403 |
|
| } |
| 1404 |
|
| |
| 1405 |
24 |
| SvREFCNT_dec(newapad); |
| 1406 |
24 |
| SvREFCNT_dec(nname); |
| 1407 |
|
| } |
| 1408 |
|
| } |
| 1409 |
2877 |
▶ | else if (val == &PL_sv_undef || !SvOK(val)) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (val == &PL_sv_undef || !SvOK(val)) { |
2877 |
0 |
2877 |
| else if (val == &PL_sv_undef || !SvOK(val)) { |
8 |
2869 |
2877 |
|
| 1410 |
8 |
| sv_catpvs(retval, "undef"); |
| 1411 |
|
| } |
| 1412 |
|
| #ifdef SvVOK |
| 1413 |
2869 |
▶ | else if (SvVOK(val) && (vstr_pv = SvVSTRING(val, vstr_len))) { |
Branch: 3 branches
| Branch | True | False | Total |
| else if (SvVOK(val) && (vstr_pv = SvVSTRING(val, vstr_len))) { |
39 |
2830 |
2869 |
| else if (SvVOK(val) && (vstr_pv = SvVSTRING(val, vstr_len))) { |
33 |
6 |
39 |
| else if (SvVOK(val) && (vstr_pv = SvVSTRING(val, vstr_len))) { |
0 |
6 |
6 |
|
| 1414 |
|
| # if !defined(PL_vtbl_vstring) && PERL_VERSION_LT(5,17,0) |
| 1415 |
|
| SV * const vecsv = sv_newmortal(); |
| 1416 |
|
| # if PERL_VERSION_LT(5,10,0) |
| 1417 |
|
| scan_vstring(vstr_pv, vecsv); |
| 1418 |
|
| # else |
| 1419 |
|
| scan_vstring(vstr_pv, vstr_pv + vstr_len, vecsv); |
| 1420 |
|
| # endif |
| 1421 |
|
| if (!sv_eq(vecsv, val)) goto integer_came_from_string; |
| 1422 |
|
| # endif |
| 1423 |
6 |
| sv_catpvn(retval, vstr_pv, vstr_len); |
| 1424 |
|
| } |
| 1425 |
|
| #endif |
| 1426 |
|
| |
| 1427 |
|
| else { |
| 1428 |
2895 |
| integer_came_from_string: |
| 1429 |
2895 |
| c = SvPV(val, i); |
| 1430 |
|
| /* the pure perl and XS non-qq outputs have historically been |
| 1431 |
|
| * different in this case, but for useqq, let's try to match |
| 1432 |
|
| * the pure perl code. |
| 1433 |
|
| * see [perl #74798] |
| 1434 |
|
| */ |
| 1435 |
2895 |
▶ | if (style->useqq && safe_decimal_number(c, i)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (style->useqq && safe_decimal_number(c, i)) { |
2128 |
767 |
2895 |
| if (style->useqq && safe_decimal_number(c, i)) { |
2 |
2126 |
2128 |
|
| 1436 |
2 |
| sv_catsv(retval, val); |
| 1437 |
|
| } |
| 1438 |
2893 |
▶ | else if (DO_UTF8(val) || style->useqq) |
Branch: 3 branches
| Branch | True | False | Total |
| else if (DO_UTF8(val) || style->useqq) |
27 |
2866 |
2893 |
| else if (DO_UTF8(val) || style->useqq) |
0 |
27 |
27 |
| else if (DO_UTF8(val) || style->useqq) |
2120 |
746 |
2866 |
|
| 1439 |
2147 |
▶ | i += esc_q_utf8(aTHX_ retval, c, i, DO_UTF8(val), style->useqq); |
Branch: 2 branches
| Branch | True | False | Total |
| i += esc_q_utf8(aTHX_ retval, c, i, DO_UTF8(val), style->useqq); |
27 |
2120 |
2147 |
| i += esc_q_utf8(aTHX_ retval, c, i, DO_UTF8(val), style->useqq); |
27 |
0 |
27 |
|
| 1440 |
|
| else { |
| 1441 |
746 |
| sv_grow(retval, SvCUR(retval)+3+2*i); /* 3: ""\0 */ |
| 1442 |
746 |
| r = SvPVX(retval) + SvCUR(retval); |
| 1443 |
746 |
| r[0] = '\''; |
| 1444 |
746 |
| i += esc_q(r+1, c, i); |
| 1445 |
746 |
| ++i; |
| 1446 |
746 |
| r[i++] = '\''; |
| 1447 |
746 |
| r[i] = '\0'; |
| 1448 |
746 |
| SvCUR_set(retval, SvCUR(retval)+i); |
| 1449 |
|
| } |
| 1450 |
|
| } |
| 1451 |
|
| } |
| 1452 |
|
| |
| 1453 |
4645 |
▶ | if (idlen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (idlen) { |
4645 |
0 |
4645 |
|
| 1454 |
4645 |
▶ | if (style->deepcopy) |
Branch: 1 branch
| Branch | True | False | Total |
| if (style->deepcopy) |
90 |
4555 |
4645 |
|
| 1455 |
90 |
| (void)hv_delete(seenhv, id, idlen, G_DISCARD); |
| 1456 |
4555 |
▶ | else if (namelen && seenentry) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (namelen && seenentry) { |
4555 |
0 |
4555 |
| else if (namelen && seenentry) { |
4539 |
16 |
4555 |
|
| 1457 |
4539 |
| SV *mark = *av_fetch(seenentry, 2, TRUE); |
| 1458 |
4539 |
| sv_setiv(mark,1); |
| 1459 |
|
| } |
| 1460 |
|
| } |
| 1461 |
4645 |
| return 1; |
| 1462 |
|
| } |
| 1463 |
|
| |
| 1464 |
|
| |
| 1465 |
|
| MODULE = Data::Dumper PACKAGE = Data::Dumper PREFIX = Data_Dumper_ |
| 1466 |
|
| |
| 1467 |
|
| # |
| 1468 |
|
| # This is the exact equivalent of Dump. Well, almost. The things that are |
| 1469 |
|
| # different as of now (due to Laziness): |
| 1470 |
|
| # * doesn't do deparse yet.' |
| 1471 |
|
| # |
| 1472 |
|
| |
| 1473 |
|
| void |
| 1474 |
|
| Data_Dumper_Dumpxs(href, ...) |
| 1475 |
|
| SV *href; |
| 1476 |
|
| PROTOTYPE: $;$$ |
| 1477 |
|
| PPCODE: |
| 1478 |
|
| { |
| 1479 |
|
| HV *hv; |
| 1480 |
|
| SV *retval, *valstr; |
| 1481 |
2978 |
| HV *seenhv = NULL; |
| 1482 |
|
| AV *postav, *todumpav, *namesav; |
| 1483 |
2978 |
| I32 terse = 0; |
| 1484 |
|
| SSize_t i, imax, postlen; |
| 1485 |
|
| SV **svp; |
| 1486 |
2978 |
| SV *apad = &PL_sv_undef; |
| 1487 |
|
| Style style; |
| 1488 |
|
| |
| 1489 |
2978 |
| SV *name_sv, *val = &PL_sv_undef, *varname = &PL_sv_undef; |
| 1490 |
2978 |
| I32 gimme = GIMME_V; |
| 1491 |
|
| |
| 1492 |
2978 |
▶ | if (!SvROK(href)) { /* call new to get an object first */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(href)) { /* call new to get an object first */ |
173 |
2805 |
2978 |
|
| 1493 |
173 |
▶ | if (items < 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items < 2) |
0 |
173 |
173 |
|
| 1494 |
0 |
| croak("Usage: Data::Dumper::Dumpxs(PACKAGE, VAL_ARY_REF, [NAME_ARY_REF])"); |
| 1495 |
|
| |
| 1496 |
173 |
| ENTER; |
| 1497 |
173 |
| SAVETMPS; |
| 1498 |
|
| |
| 1499 |
173 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
173 |
173 |
|
| 1500 |
173 |
▶ | EXTEND(SP, 3); /* 3 == max of all branches below */ |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 3); /* 3 == max of all branches below */ |
0 |
173 |
173 |
|
| 1501 |
173 |
| PUSHs(href); |
| 1502 |
173 |
| PUSHs(sv_2mortal(newSVsv(ST(1)))); |
| 1503 |
173 |
▶ | if (items >= 3) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items >= 3) |
56 |
117 |
173 |
|
| 1504 |
56 |
| PUSHs(sv_2mortal(newSVsv(ST(2)))); |
| 1505 |
173 |
| PUTBACK; |
| 1506 |
173 |
| i = perl_call_method("new", G_SCALAR); |
| 1507 |
173 |
| SPAGAIN; |
| 1508 |
173 |
▶ | if (i) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i) |
173 |
0 |
173 |
|
| 1509 |
173 |
| href = newSVsv(POPs); |
| 1510 |
|
| |
| 1511 |
173 |
| PUTBACK; |
| 1512 |
173 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
173 |
0 |
173 |
|
| 1513 |
173 |
| LEAVE; |
| 1514 |
173 |
▶ | if (i) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i) |
173 |
0 |
173 |
|
| 1515 |
173 |
| (void)sv_2mortal(href); |
| 1516 |
|
| } |
| 1517 |
|
| |
| 1518 |
2978 |
| todumpav = namesav = NULL; |
| 1519 |
2978 |
| style.indent = 2; |
| 1520 |
2978 |
| style.quotekeys = 1; |
| 1521 |
2978 |
| style.maxrecurse = 1000; |
| 1522 |
2978 |
| style.maxrecursed = FALSE; |
| 1523 |
2978 |
| style.purity = style.deepcopy = style.useqq = style.maxdepth |
| 1524 |
2978 |
| = style.use_sparse_seen_hash = style.trailingcomma = 0; |
| 1525 |
2978 |
| style.pad = style.xpad = style.sep = style.pair = style.sortkeys |
| 1526 |
2978 |
| = style.freezer = style.toaster = style.bless = &PL_sv_undef; |
| 1527 |
2978 |
| seenhv = NULL; |
| 1528 |
2978 |
| name_sv = sv_newmortal(); |
| 1529 |
|
| |
| 1530 |
2978 |
| retval = newSVpvs_flags("", SVs_TEMP); |
| 1531 |
2978 |
▶ | if (SvROK(href) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(href) |
2978 |
0 |
2978 |
|
| 1532 |
2978 |
▶ | && (hv = (HV*)SvRV((SV*)href)) |
Branch: 1 branch
| Branch | True | False | Total |
| && (hv = (HV*)SvRV((SV*)href)) |
2978 |
0 |
2978 |
|
| 1533 |
2978 |
▶ | && SvTYPE(hv) == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(hv) == SVt_PVHV) { |
2978 |
0 |
2978 |
|
| 1534 |
|
| |
| 1535 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "seen", FALSE)) && SvROK(*svp)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "seen", FALSE)) && SvROK(*svp)) |
2978 |
0 |
2978 |
| if ((svp = hv_fetchs(hv, "seen", FALSE)) && SvROK(*svp)) |
2978 |
0 |
2978 |
|
| 1536 |
2978 |
| seenhv = (HV*)SvRV(*svp); |
| 1537 |
|
| else |
| 1538 |
0 |
| style.use_sparse_seen_hash = 1; |
| 1539 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "noseen", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "noseen", FALSE))) |
2978 |
0 |
2978 |
|
| 1540 |
2978 |
▶ | style.use_sparse_seen_hash = (SvOK(*svp) && SvIV(*svp) != 0); |
Branch: 2 branches
| Branch | True | False | Total |
| style.use_sparse_seen_hash = (SvOK(*svp) && SvIV(*svp) != 0); |
2976 |
2 |
2978 |
| style.use_sparse_seen_hash = (SvOK(*svp) && SvIV(*svp) != 0); |
6 |
2970 |
2976 |
|
| 1541 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "todump", FALSE)) && SvROK(*svp)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "todump", FALSE)) && SvROK(*svp)) |
2978 |
0 |
2978 |
| if ((svp = hv_fetchs(hv, "todump", FALSE)) && SvROK(*svp)) |
2978 |
0 |
2978 |
|
| 1542 |
2978 |
| todumpav = (AV*)SvRV(*svp); |
| 1543 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "names", FALSE)) && SvROK(*svp)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "names", FALSE)) && SvROK(*svp)) |
2978 |
0 |
2978 |
| if ((svp = hv_fetchs(hv, "names", FALSE)) && SvROK(*svp)) |
2978 |
0 |
2978 |
|
| 1544 |
2978 |
| namesav = (AV*)SvRV(*svp); |
| 1545 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "indent", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "indent", FALSE))) |
2978 |
0 |
2978 |
|
| 1546 |
2978 |
| style.indent = SvIV(*svp); |
| 1547 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "purity", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "purity", FALSE))) |
2978 |
0 |
2978 |
|
| 1548 |
2978 |
| style.purity = SvIV(*svp); |
| 1549 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "terse", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "terse", FALSE))) |
2978 |
0 |
2978 |
|
| 1550 |
2978 |
| terse = SvTRUE(*svp); |
| 1551 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "useqq", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "useqq", FALSE))) |
2978 |
0 |
2978 |
|
| 1552 |
2978 |
| style.useqq = SvTRUE(*svp); |
| 1553 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "pad", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "pad", FALSE))) |
2978 |
0 |
2978 |
|
| 1554 |
2978 |
| style.pad = *svp; |
| 1555 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "xpad", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "xpad", FALSE))) |
2978 |
0 |
2978 |
|
| 1556 |
2978 |
| style.xpad = *svp; |
| 1557 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "apad", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "apad", FALSE))) |
2978 |
0 |
2978 |
|
| 1558 |
2978 |
| apad = *svp; |
| 1559 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "sep", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "sep", FALSE))) |
2978 |
0 |
2978 |
|
| 1560 |
2978 |
| style.sep = *svp; |
| 1561 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "pair", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "pair", FALSE))) |
2978 |
0 |
2978 |
|
| 1562 |
2978 |
| style.pair = *svp; |
| 1563 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "varname", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "varname", FALSE))) |
2978 |
0 |
2978 |
|
| 1564 |
2978 |
| varname = *svp; |
| 1565 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "freezer", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "freezer", FALSE))) |
2978 |
0 |
2978 |
|
| 1566 |
2978 |
| style.freezer = *svp; |
| 1567 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "toaster", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "toaster", FALSE))) |
2978 |
0 |
2978 |
|
| 1568 |
2978 |
| style.toaster = *svp; |
| 1569 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "deepcopy", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "deepcopy", FALSE))) |
2978 |
0 |
2978 |
|
| 1570 |
2978 |
| style.deepcopy = SvTRUE(*svp); |
| 1571 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "quotekeys", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "quotekeys", FALSE))) |
2978 |
0 |
2978 |
|
| 1572 |
2978 |
| style.quotekeys = SvTRUE(*svp); |
| 1573 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "trailingcomma", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "trailingcomma", FALSE))) |
2978 |
0 |
2978 |
|
| 1574 |
2978 |
| style.trailingcomma = SvTRUE(*svp); |
| 1575 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "deparse", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "deparse", FALSE))) |
2978 |
0 |
2978 |
|
| 1576 |
2978 |
| style.deparse = SvTRUE(*svp); |
| 1577 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "bless", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "bless", FALSE))) |
2978 |
0 |
2978 |
|
| 1578 |
2978 |
| style.bless = *svp; |
| 1579 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "maxdepth", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "maxdepth", FALSE))) |
2978 |
0 |
2978 |
|
| 1580 |
2978 |
| style.maxdepth = SvIV(*svp); |
| 1581 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "maxrecurse", FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "maxrecurse", FALSE))) |
2978 |
0 |
2978 |
|
| 1582 |
2978 |
| style.maxrecurse = SvIV(*svp); |
| 1583 |
2978 |
▶ | if ((svp = hv_fetchs(hv, "sortkeys", FALSE))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = hv_fetchs(hv, "sortkeys", FALSE))) { |
2978 |
0 |
2978 |
|
| 1584 |
2978 |
| SV *sv = *svp; |
| 1585 |
2978 |
▶ | if (! SvTRUE(sv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (! SvTRUE(sv)) |
177 |
2801 |
2978 |
|
| 1586 |
177 |
| style.sortkeys = NULL; |
| 1587 |
2801 |
▶ | else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) |
10 |
2791 |
2801 |
| else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) |
10 |
0 |
10 |
|
| 1588 |
10 |
| style.sortkeys = sv; |
| 1589 |
|
| else |
| 1590 |
|
| /* flag to use sortsv() for sorting hash keys */ |
| 1591 |
2791 |
| style.sortkeys = &PL_sv_yes; |
| 1592 |
|
| } |
| 1593 |
2978 |
| postav = newAV(); |
| 1594 |
2978 |
| sv_2mortal((SV*)postav); |
| 1595 |
|
| |
| 1596 |
2978 |
▶ | if (todumpav) |
Branch: 1 branch
| Branch | True | False | Total |
| if (todumpav) |
2978 |
0 |
2978 |
|
| 1597 |
2978 |
| imax = av_len(todumpav); |
| 1598 |
|
| else |
| 1599 |
0 |
| imax = -1; |
| 1600 |
2978 |
| valstr = newSVpvs_flags("", SVs_TEMP); |
| 1601 |
6695 |
▶ | for (i = 0; i <= imax; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= imax; ++i) { |
3717 |
2978 |
6695 |
|
| 1602 |
|
| SV *newapad; |
| 1603 |
|
| char *name; |
| 1604 |
|
| STRLEN name_len; |
| 1605 |
|
| |
| 1606 |
3717 |
| av_clear(postav); |
| 1607 |
3717 |
▶ | if ((svp = av_fetch(todumpav, i, FALSE))) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = av_fetch(todumpav, i, FALSE))) |
3717 |
0 |
3717 |
|
| 1608 |
3717 |
| val = *svp; |
| 1609 |
|
| else |
| 1610 |
0 |
| val = &PL_sv_undef; |
| 1611 |
3717 |
▶ | if ((svp = av_fetch(namesav, i, TRUE))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = av_fetch(namesav, i, TRUE))) { |
3717 |
0 |
3717 |
|
| 1612 |
3717 |
▶ | if (SvOK(*svp)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(*svp)) { |
2851 |
866 |
3717 |
|
| 1613 |
2851 |
| sv_setsv(name_sv, *svp); |
| 1614 |
2851 |
| name = SvPV(name_sv, name_len); |
| 1615 |
|
| } |
| 1616 |
|
| else { |
| 1617 |
866 |
| name = NULL; |
| 1618 |
|
| } |
| 1619 |
|
| } |
| 1620 |
|
| else { |
| 1621 |
0 |
| name = NULL; |
| 1622 |
|
| } |
| 1623 |
|
| |
| 1624 |
3717 |
▶ | if (name) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (name) { |
2851 |
866 |
3717 |
|
| 1625 |
2851 |
▶ | if (*name == '*') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*name == '*') { |
75 |
2776 |
2851 |
|
| 1626 |
75 |
▶ | if (SvROK(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(val)) { |
75 |
0 |
75 |
|
| 1627 |
75 |
| switch (SvTYPE(SvRV(val))) { |
| 1628 |
26 |
| case SVt_PVAV: |
| 1629 |
26 |
| *name = '@'; |
| 1630 |
26 |
| break; |
| 1631 |
35 |
| case SVt_PVHV: |
| 1632 |
35 |
| *name = '%'; |
| 1633 |
35 |
| break; |
| 1634 |
4 |
| case SVt_PVCV: |
| 1635 |
4 |
| *name = '*'; |
| 1636 |
4 |
| break; |
| 1637 |
10 |
| default: |
| 1638 |
10 |
| *name = '$'; |
| 1639 |
10 |
| break; |
| 1640 |
|
| } |
| 1641 |
|
| } |
| 1642 |
|
| else |
| 1643 |
0 |
| *name = '$'; |
| 1644 |
|
| } |
| 1645 |
2776 |
▶ | else if (*name != '$') { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (*name != '$') { |
171 |
2605 |
2776 |
|
| 1646 |
171 |
| sv_insert(name_sv, 0, 0, "$", 1); |
| 1647 |
171 |
| name = SvPV(name_sv, name_len); |
| 1648 |
|
| } |
| 1649 |
|
| } |
| 1650 |
|
| else { |
| 1651 |
866 |
| sv_setpvf(name_sv, "$%" SVf "%" IVdf, SVfARG(varname), (IV)(i+1)); |
| 1652 |
866 |
| name = SvPV(name_sv, name_len); |
| 1653 |
|
| } |
| 1654 |
|
| |
| 1655 |
3983 |
▶ | if (style.indent >= 2 && !terse) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (style.indent >= 2 && !terse) { |
270 |
3447 |
3717 |
| if (style.indent >= 2 && !terse) { |
266 |
4 |
270 |
|
| 1656 |
266 |
| SV * const tmpsv = sv_x(aTHX_ NULL, " ", 1, name_len + 3); |
| 1657 |
266 |
| newapad = sv_2mortal(newSVsv(apad)); |
| 1658 |
266 |
| sv_catsv(newapad, tmpsv); |
| 1659 |
266 |
| SvREFCNT_dec(tmpsv); |
| 1660 |
|
| } |
| 1661 |
|
| else |
| 1662 |
3451 |
| newapad = apad; |
| 1663 |
|
| |
| 1664 |
3717 |
| ENTER; |
| 1665 |
3717 |
| SAVETMPS; |
| 1666 |
3717 |
| PUTBACK; |
| 1667 |
3717 |
| DD_dump(aTHX_ val, name, name_len, valstr, seenhv, |
| 1668 |
|
| postav, 0, newapad, &style); |
| 1669 |
3717 |
| SPAGAIN; |
| 1670 |
3717 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
330 |
3387 |
3717 |
|
| 1671 |
3717 |
| LEAVE; |
| 1672 |
|
| |
| 1673 |
3717 |
| postlen = av_len(postav); |
| 1674 |
3717 |
▶ | if (postlen >= 0 || !terse) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (postlen >= 0 || !terse) { |
3681 |
36 |
3717 |
| if (postlen >= 0 || !terse) { |
1067 |
2614 |
3681 |
|
| 1675 |
1103 |
| sv_insert(valstr, 0, 0, " = ", 3); |
| 1676 |
1103 |
| sv_insert(valstr, 0, 0, name, name_len); |
| 1677 |
1103 |
| sv_catpvs(valstr, ";"); |
| 1678 |
|
| } |
| 1679 |
3717 |
| sv_catsv(retval, style.pad); |
| 1680 |
3717 |
| sv_catsv(retval, valstr); |
| 1681 |
3717 |
| sv_catsv(retval, style.sep); |
| 1682 |
3717 |
▶ | if (postlen >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (postlen >= 0) { |
36 |
3681 |
3717 |
|
| 1683 |
|
| SSize_t i; |
| 1684 |
36 |
| sv_catsv(retval, style.pad); |
| 1685 |
168 |
▶ | for (i = 0; i <= postlen; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= postlen; ++i) { |
132 |
36 |
168 |
|
| 1686 |
|
| SV *elem; |
| 1687 |
132 |
| svp = av_fetch(postav, i, FALSE); |
| 1688 |
132 |
▶ | if (svp && (elem = *svp)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (svp && (elem = *svp)) { |
132 |
0 |
132 |
| if (svp && (elem = *svp)) { |
132 |
0 |
132 |
|
| 1689 |
132 |
| sv_catsv(retval, elem); |
| 1690 |
132 |
▶ | if (i < postlen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (i < postlen) { |
96 |
36 |
132 |
|
| 1691 |
96 |
| sv_catpvs(retval, ";"); |
| 1692 |
96 |
| sv_catsv(retval, style.sep); |
| 1693 |
96 |
| sv_catsv(retval, style.pad); |
| 1694 |
|
| } |
| 1695 |
|
| } |
| 1696 |
|
| } |
| 1697 |
36 |
| sv_catpvs(retval, ";"); |
| 1698 |
36 |
| sv_catsv(retval, style.sep); |
| 1699 |
|
| } |
| 1700 |
3717 |
| SvPVCLEAR(valstr); |
| 1701 |
3717 |
▶ | if (gimme == G_ARRAY) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gimme == G_ARRAY) { |
175 |
3542 |
3717 |
|
| 1702 |
175 |
▶ | XPUSHs(retval); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(retval); |
0 |
175 |
175 |
|
| 1703 |
175 |
▶ | if (i < imax) /* not the last time thro ? */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (i < imax) /* not the last time thro ? */ |
59 |
116 |
175 |
|
| 1704 |
59 |
| retval = newSVpvs_flags("", SVs_TEMP); |
| 1705 |
|
| } |
| 1706 |
|
| } |
| 1707 |
|
| |
| 1708 |
|
| /* we defer croaking until here so that temporary SVs and |
| 1709 |
|
| * buffers won't be leaked */ |
| 1710 |
2978 |
▶ | if (style.maxrecursed) |
Branch: 1 branch
| Branch | True | False | Total |
| if (style.maxrecursed) |
4 |
2974 |
2978 |
|
| 1711 |
4 |
| croak("Recursion limit of %" IVdf " exceeded", |
| 1712 |
|
| style.maxrecurse); |
| 1713 |
|
| |
| 1714 |
|
| } |
| 1715 |
|
| else |
| 1716 |
0 |
| croak("Call to new() method failed to return HASH ref"); |
| 1717 |
2974 |
▶ | if (gimme != G_ARRAY) |
Branch: 1 branch
| Branch | True | False | Total |
| if (gimme != G_ARRAY) |
2858 |
116 |
2974 |
|
| 1718 |
2858 |
▶ | XPUSHs(retval); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(retval); |
0 |
2858 |
2858 |
|
| 1719 |
|
| } |
| 1720 |
|
| |
| 1721 |
|
| SV * |
| 1722 |
|
| Data_Dumper__vstring(sv) |
| 1723 |
|
| SV *sv; |
| 1724 |
|
| PROTOTYPE: $ |
| 1725 |
|
| CODE: |
| 1726 |
|
| { |
| 1727 |
|
| #ifdef SvVOK |
| 1728 |
1810 |
▶ | if(SvVOK(sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if(SvVOK(sv)) { |
6 |
1798 |
1804 |
| if(SvVOK(sv)) { |
6 |
0 |
6 |
|
| 1729 |
|
| STRLEN vstr_len; |
| 1730 |
6 |
| const char *vstr_pv = SvVSTRING(sv, vstr_len); |
| 1731 |
6 |
| RETVAL = newSVpvn(vstr_pv, vstr_len); |
| 1732 |
|
| } |
| 1733 |
|
| else |
| 1734 |
|
| #endif |
| 1735 |
1798 |
| RETVAL = &PL_sv_undef; |
| 1736 |
|
| } |
| 1737 |
|
| OUTPUT: RETVAL |