Undump.xs

filter: Statementstmt 85.7% 379 / 442 Branchbran 42.3% 344 / 812 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 57.6% 723 / 1254 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/lib/Data/Undump.pm »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include "ppport.h"
5  
6 /*
7 Grammar:
8  
9 INTEGER: /-?(?:0|[1-9][0-9]+)/x
10 FLOAT: /-?(?:0|[1-9][0-9]+)\.([0-9]+)/x
11 BAREWORD: / [A-Za-z_]+ [0-9A-Za-z_]* /x
12 Q_STRING: /'(?:\\\\|\\'|.)*'/s
13 QQ_STRING: /"(?:\\x\{[A-Fa-f0-9]+\}|\\[0-6]{1,2}(?![0-6])|\\[0-6]{3}|\\.|.)*"/i
14 SIMPLE_COMMA: ','
15 FAT_COMMA: '=>'
16 OPEN_HASH: '{'
17 CLOSE_HASH: '}'
18 OPEN_ARRAY: '['
19 CLOSE_ARRAY: ']'
20 UNDEF: 'undef'
21  
22 VALUE: UNDEF | INTEGER | FLOAT | QUOTED_STRING | HASH | ARRAY
23 KEY: INTEGER | FLOAT | BAREWORD | QUOTED_STRING
24  
25 KEY_VALUE_LIST: (KEY FAT_COMMA VALUE (SIMPLE_COMMA KEY FAT_COMMA VALUE)*)?
26 VALUE_LIST: (VALUE (SIMPLE_COMMA VALUE)*)?
27  
28 HASH: OPEN_HASH KEY_VALUE_LIST CLOSE_HASH
29 ARRAY: OPEN_ARRAY VALUE_LIST CLOSE_ARRAY
30 */
31 /* 1 shows errors, 2 trace */
32 #define MYDEBUG 0
33  
34 #define TOKEN_ERROR 0
35 #define TOKEN_COMMA 1
36 #define TOKEN_OPEN 2
37 #define TOKEN_CLOSE 3
38 #define TOKEN_UNDEF 4
39 #define TOKEN_IV 5
40 #define TOKEN_NV 6
41 #define TOKEN_BAREWORD 7
42 #define TOKEN_Q_STRING 8
43 #define TOKEN_QQ_STRING 9
44 #define TOKEN_WS 10
45 #define TOKEN_BLESS 11
46 #define TOKEN_REF 12
47 #define TOKEN_UNKNOWN 13
48  
49 #define COND_ISWHITE(ch) ( (ch) == ' ' || (ch) == '\n' || (ch) == '\t' || (ch) == '\r' )
50 #define CASE_ISWHITE ' ': case '\n': case '\t': case '\r'
51 #define EAT_WHITES_AND_COMMENTS(p) STMT_START { while ( COND_ISWHITE(*p) || *p == '#' ) { if (*p == '#') { while ( *p && *p != '\n' ) p++; } else p++; } } STMT_END
52  
53 const char * const token_name[]= {
54 "TOKEN_ERROR",
55 "TOKEN_COMMA",
56 "TOKEN_OPEN",
57 "TOKEN_CLOSE",
58 "TOKEN_UNDEF",
59 "TOKEN_IV",
60 "TOKEN_NV",
61 "TOKEN_BAREWORD",
62 "TOKEN_Q_STRING",
63 "TOKEN_QQ_STRING",
64 "TOKEN_WS",
65 "TOKEN_BLESS",
66 "TOKEN_UNKNOWN"
67 };
68  
69 const char bareword_start[]= {
70 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
71 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74 0, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
75 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 0, 0, 0, 0, 95,
76 0, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
77 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 0, 0, 0, 0, 0,
78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 };
87  
88 const char bareword_rest[]= {
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0, 0, 0, 0, 0, 0,
93 0, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
94 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 0, 0, 0, 0, 95,
95 0, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
96 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 0, 0, 0, 0, 0,
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
105 };
106  
107  
108  
109  
110 typedef struct parse_state {
111 STRLEN string_len;
112 const char *string_start;
113 const char *string_end;
114 SV *parse_sv;
115 const char *parse_ptr;
116 U32 line_num;
117 } parse_state;
118  
119  
120 typedef struct frame_state {
121 const char *token_start;
122 const char *first_escape;
123  
124 const char *key;
125 STRLEN key_len;
126 SV *thing;
127 SV *got_key;
128 SV *got;
129  
130 U8 token;
131 U8 depth;
132 char stop_char;
133 U32 flags;
134 U32 refs;
135 } frame_state;
136  
137  
138 SV* _undump(pTHX_ parse_state *ps, char obj_char, U8 call_depth);
139  
140 /* undump a DD style data structure. Takes a plain SV (magic not currently respected)
141 * containing a DD Terse/Deepcopy style data dumper output (no $VAR1 = at the front
142 * allowed currently) and returns either undef for a failed parse, or a scalar value
143 * of the value parsed.
144 *
145 * Possible future enhancements:
146 * qr//
147 * ref to object. Eg \['foo']
148 * Make it possible to parse a list instead of a scalar.
149 * Blessed objects?
150 * Cyclic structures?
151 * Less/more tolerant parsing rules?
152 * Filters? (Block things by their position in the structure?)
153 * Conversion? (IE, we have '[1,1,1]' in the input, and we know we wont need it
154 * so parse it as '1,1,1' instead.
155 */
156  
157 158196 SV* undump(pTHX_ SV* sv) {
158 parse_state ps;
159 158196 SV *undumped= 0;
160  
161 158196 ▶ if ( !SvOK(sv) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !SvOK(sv) ) { 0 158196 158196
162 0 ▶ sv_setpv(ERRSV,"Bad argument\n");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpv(ERRSV,"Bad argument\n"); 0 0 0
163 0 return newSV(0);
164 }
165 158196 ps.parse_sv= sv;
166 158196 ps.parse_ptr= ps.string_start= SvPV(sv, ps.string_len);
167 158196 ps.string_end= ps.string_start + ps.string_len;
168 158196 ps.line_num= 0;
169  
170 158196 ▶ if ( SvLEN(sv) <= ps.string_len || ps.parse_ptr[ps.string_len] != 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( SvLEN(sv) <= ps.string_len || ps.parse_ptr[ps.string_len] != 0 ) { 158196 0 158196
if ( SvLEN(sv) <= ps.string_len || ps.parse_ptr[ps.string_len] != 0 ) { 0 158196 158196
171 0 ▶ sv_setpv(ERRSV,"Malformed input string in undump (missing tail null)\n");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpv(ERRSV,"Malformed input string in undump (missing tail null)\n"); 0 0 0
172 0 return newSV(0);
173 }
174  
175 158246 ▶ EAT_WHITES_AND_COMMENTS(ps.parse_ptr);
Branch: 8 branches
BranchTrueFalseTotal
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 2 6 8
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 44 0 44
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 42 2 44
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 2 158202 158204
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 2 158200 158202
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 2 158198 158200
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 0 158198 158198
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 2 158196 158198
176 158196 ▶ if (ps.parse_ptr < ps.string_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (ps.parse_ptr < ps.string_end) { 158196 0 158196
177 158196 undumped= _undump(aTHX_ &ps, 0, 0);
178 158257 ▶ EAT_WHITES_AND_COMMENTS(ps.parse_ptr);
Branch: 8 branches
BranchTrueFalseTotal
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 3 7 10
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 51 3 54
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 51 0 51
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 7 158199 158206
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 0 158199 158199
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 0 158199 158199
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 0 158199 158199
EAT_WHITES_AND_COMMENTS(ps.parse_ptr); 3 158196 158199
179 }
180 158196 ▶ if (undumped) {
Branch: 1 branch
BranchTrueFalseTotal
if (undumped) { 157547 649 158196
181 157547 ▶ if (ps.parse_ptr < ps.string_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (ps.parse_ptr < ps.string_end) { 1 157546 157547
182 1 ▶ sv_setpv(ERRSV,"Unhandled tail garbage\n");
Branch: 1 branch
BranchTrueFalseTotal
sv_setpv(ERRSV,"Unhandled tail garbage\n"); 1 0 1
183 1 SvREFCNT_dec(undumped);
184 1 return newSV(0);
185 } else {
186 157546 ▶ sv_setsv(ERRSV,&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV,&PL_sv_undef); 157546 0 157546
187 157546 return undumped;
188 }
189 } else {
190 649 return newSV(0);
191 }
192 }
193  
194 #define fs_token (fs->token)
195 #define fs_token_start (fs->token_start)
196 #define fs_first_escape (fs->first_escape)
197  
198 #define fs_stop_char (fs->stop_char)
199 #define fs_key (fs->key)
200 #define fs_key_len (fs->key_len)
201 #define fs_thing (fs->thing)
202 #define fs_got_key (fs->got_key)
203 #define fs_got (fs->got)
204 #define fs_depth (fs->depth)
205 #define fs_flags (fs->flags)
206 #define fs_refs (fs->refs)
207  
208 #define ps_parse_sv (ps->parse_sv)
209 #define ps_string_start (ps->string_start)
210 #define ps_string_end (ps->string_end)
211 #define ps_string_len (ps->string_len)
212 #define ps_parse_ptr (ps->parse_ptr)
213 #define ps_line_num (ps->line_num)
214  
215 #define fsf_WANT_KEY 0x00000001
216 #define fsf_ALLOW_COMMA 0x00000002
217 #define fsf_REQUIRE_FAT_COMMA 0x00000004
218  
219 #define WANT_KEY(fs) (fs_flags & fsf_WANT_KEY)
220 #define WANT_KEY_on(fs) (fs_flags= fs_flags | fsf_WANT_KEY)
221 #define WANT_KEY_off(fs) (fs_flags= fs_flags & (~fsf_WANT_KEY))
222 #define ALLOW_COMMA(fs) (fs_flags & fsf_ALLOW_COMMA)
223 #define ALLOW_COMMA_on(fs) (fs_flags= fs_flags | fsf_ALLOW_COMMA)
224 #define ALLOW_COMMA_off(fs) (fs_flags= fs_flags & (~fsf_ALLOW_COMMA))
225 #define REQUIRE_FAT_COMMA(fs) (fs_flags & fsf_REQUIRE_FAT_COMMA)
226 #define REQUIRE_FAT_COMMA_on(fs) (fs_flags= fs_flags | fsf_REQUIRE_FAT_COMMA)
227 #define REQUIRE_FAT_COMMA_off(fs) (fs_flags= fs_flags & (~fsf_REQUIRE_FAT_COMMA))
228  
229 #define DEPTH(D,T) ( ( (D) * 4 ) + ( ( (T) == TOKEN_OPEN || (T) == TOKEN_BLESS ) - ( (T) == TOKEN_CLOSE ) ) * 2 )
230  
231 #define BAIL(ps,fs) STMT_START { \
232 if(fs_got) SvREFCNT_dec(fs_got); \
233 if(fs_got_key) SvREFCNT_dec(fs_got_key); \
234 if(fs_thing) SvREFCNT_dec(fs_thing); \
235 return 0; \
236 } STMT_END
237  
238 #define SHOW_POSITION( ps, fs, show_len ) STMT_START {\
239 int remaining= (ps_string_end) - (ps_parse_ptr); \
240 int token_len= (ps_parse_ptr) - (fs_token_start); \
241 int backup_len=0;\
242 const char *backup_pos;\
243 if (ps_string_start < fs_token_start) { \
244 backup_len= fs_token_start - ps_string_start; \
245 if (backup_len > show_len) { \
246 backup_len= show_len; \
247 } \
248 backup_pos= fs_token_start - backup_len; \
249 } else { \
250 backup_pos= 0; \
251 } \
252 warn("%*sprior:'%.*s'\n" \
253 "%*stoken:'%.*s'%s\n" \
254 "%*sto-go:'%.*s'%s\n\n", \
255 DEPTH((fs_depth),(fs_token)), "", \
256 backup_len, backup_pos, \
257 DEPTH((fs_depth),(fs_token)), "", \
258 ( ( token_len > (show_len) ) ? (show_len) : token_len) , (fs_token_start), \
259 ( ( token_len > (show_len) ) ? "..." : ""), \
260 DEPTH((fs_depth),(fs_token)), "", \
261 ( ( remaining > (show_len) ) ? (show_len) : remaining ) , (ps_parse_ptr), \
262 ( ( remaining > (show_len) ) ? "..." : "") \
263 ); \
264 } STMT_END
265  
266 #define PANIC(ps,fs,X) STMT_START { \
267 if (MYDEBUG) { \
268 warn("%*s%s\n",DEPTH((fs_depth),(fs_token)) , "", (X)); \
269 SHOW_POSITION(ps,fs, 32); \
270 } \
271 sv_setpvf( ERRSV, "%s\n", (X) ); \
272 BAIL(ps,fs);\
273 } STMT_END
274  
275 #define PANICf1(ps,fs,F,X) STMT_START { \
276 if (MYDEBUG) { \
277 warn("%*s" F "\n",DEPTH((fs_depth),(fs_token)),"", (X)); \
278 SHOW_POSITION(ps,fs, 32); \
279 }\
280 sv_setpvf( ERRSV, F "\n", (X) ); \
281 BAIL(ps,fs);\
282 } STMT_END
283  
284 #define PANICf2(ps,fs,F,X,Y) STMT_START { \
285 if (MYDEBUG) { \
286 warn("%*s" F "\n",DEPTH((fs_depth),(fs_token)),"", (X),(Y)); \
287 SHOW_POSITION(ps,fs, 32); \
288 } \
289 sv_setpvf( ERRSV, F "\n", (X), (Y)); \
290 BAIL(ps,fs);\
291 } STMT_END
292  
293 #define ERROR(ps,fs,X) STMT_START { \
294 if (MYDEBUG>1) { \
295 warn("%*s%s\n",DEPTH((fs_depth),(fs_token)) , "", (X)); \
296 SHOW_POSITION(ps,fs, 32); \
297 } \
298 sv_setpvf( ERRSV, "%s\n", (X) ); \
299 BAIL(ps,fs);\
300 } STMT_END
301  
302 #define ERRORf1(ps,fs,F,X) STMT_START { \
303 if (MYDEBUG>1) { \
304 warn("%*s" F "\n",DEPTH((fs_depth),(fs_token)),"", (X)); \
305 SHOW_POSITION(ps,fs, 32); \
306 } \
307 sv_setpvf( ERRSV, F "\n", (X) ); \
308 BAIL(ps,fs);\
309 } STMT_END
310  
311 #define ERRORf2(ps, fs, F,X,Y) STMT_START { \
312 if (MYDEBUG>1) { \
313 warn("%*s" F "\n",DEPTH((fs_depth),(fs_token)),"", (X),(Y)); \
314 SHOW_POSITION(ps, fs, 32); \
315 } \
316 sv_setpvf( ERRSV, F "\n", (X), (Y)); \
317 BAIL(ps,fs);\
318 } STMT_END
319  
320 #define SHOW_TOKEN(ps,fs) \
321 if (MYDEBUG>1) warn("%*s%-2d %*s %.*s\n", DEPTH((fs_depth), (fs_token)), "", \
322 fs_token, -20, token_name[((fs_token)<TOKEN_UNKNOWN) ? (fs_token) : TOKEN_UNKNOWN ],(int)((ps_parse_ptr) - (fs_token_start)), (fs_token_start))
323  
324  
325 #define DONE_KEY_break \
326 WANT_KEY_off(fs); \
327 ALLOW_COMMA_on(fs); \
328 break
329 #define DONE_KEY_SIMPLE_break \
330 fs_key= fs_token_start; \
331 fs_key_len= ps_parse_ptr - fs_token_start; \
332 DONE_KEY_break
333  
334 2557 static inline U8 scan_double_quote(parse_state* const ps, frame_state* const fs) {
335 2557 fs_first_escape= 0;
336 4991982 ▶ while (ps_parse_ptr < ps_string_end && *ps_parse_ptr != '"') {
Branch: 2 branches
BranchTrueFalseTotal
while (ps_parse_ptr < ps_string_end && *ps_parse_ptr != '"') { 4991981 1 4991982
while (ps_parse_ptr < ps_string_end && *ps_parse_ptr != '"') { 4989425 2556 4991981
337 /* check if its an escape */
338 4989425 ▶ if (*ps_parse_ptr == '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if (*ps_parse_ptr == '\\') { 84579 4904846 4989425
339 84579 ▶ if (!fs_first_escape)
Branch: 1 branch
BranchTrueFalseTotal
if (!fs_first_escape) 2542 82037 84579
340 2542 fs_first_escape= ps_parse_ptr;
341 84579 if (*++ps_parse_ptr > 127) {
342 ERROR(ps,fs,"Illegal character in input");
343 }
344 4904846 ▶ } else if (*ps_parse_ptr == '$' || *ps_parse_ptr == '@') {
Branch: 2 branches
BranchTrueFalseTotal
} else if (*ps_parse_ptr == '$' || *ps_parse_ptr == '@') { 4904846 0 4904846
} else if (*ps_parse_ptr == '$' || *ps_parse_ptr == '@') { 0 4904846 4904846
345 0 ▶ ERROR(ps,fs,"Unescaped '$' and '@' are illegal in double quoted strings");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Unescaped '$' and '@' are illegal in double quoted strings"); 0 0 0
ERROR(ps,fs,"Unescaped '$' and '@' are illegal in double quoted strings"); 0 0 0
ERROR(ps,fs,"Unescaped '$' and '@' are illegal in double quoted strings"); 0 0 0
ERROR(ps,fs,"Unescaped '$' and '@' are illegal in double quoted strings"); 0 0 0
346 } else if (*ps_parse_ptr > 127) {
347 ERROR(ps,fs,"Illegal character in input");
348 }
349 4989425 ps_parse_ptr++;
350 }
351 2557 ▶ if (ps_parse_ptr >= ps_string_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (ps_parse_ptr >= ps_string_end) { 1 2556 2557
352 1 ▶ ERROR(ps,fs,"unterminated double quoted string");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"unterminated double quoted string"); 1 0 1
ERROR(ps,fs,"unterminated double quoted string"); 0 1 1
ERROR(ps,fs,"unterminated double quoted string"); 0 1 1
ERROR(ps,fs,"unterminated double quoted string"); 0 1 1
353 }
354 assert(*ps_parse_ptr == '"');
355 2556 ps_parse_ptr++; /* skip over the trailing quote */
356 2556 return TOKEN_QQ_STRING;
357 }
358  
359 8001655 static inline U8 scan_single_quote(parse_state* const ps, frame_state* const fs) {
360 8001655 fs_first_escape= 0;
361 178652980 ▶ while (ps_parse_ptr < ps_string_end && *ps_parse_ptr != '\'') {
Branch: 2 branches
BranchTrueFalseTotal
while (ps_parse_ptr < ps_string_end && *ps_parse_ptr != '\'') { 178652979 1 178652980
while (ps_parse_ptr < ps_string_end && *ps_parse_ptr != '\'') { 170651325 8001654 178652979
362 /* check if its an escape */
363 170651325 ▶ if (*ps_parse_ptr == '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if (*ps_parse_ptr == '\\') { 10 170651315 170651325
364 10 ▶ if (!fs_first_escape)
Branch: 1 branch
BranchTrueFalseTotal
if (!fs_first_escape) 6 4 10
365 6 fs_first_escape= ps_parse_ptr;
366 10 if (*++ps_parse_ptr > 127) {
367 ERROR(ps,fs,"Illegal character in input");
368 }
369 } else if (*ps_parse_ptr > 127) {
370 ERROR(ps,fs,"Illegal character in input");
371 }
372 170651325 ps_parse_ptr++;
373 }
374 8001655 ▶ if (ps_parse_ptr >= ps_string_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (ps_parse_ptr >= ps_string_end) { 1 8001654 8001655
375 1 ▶ ERROR(ps,fs,"unterminated single quoted string");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"unterminated single quoted string"); 1 0 1
ERROR(ps,fs,"unterminated single quoted string"); 0 1 1
ERROR(ps,fs,"unterminated single quoted string"); 0 1 1
ERROR(ps,fs,"unterminated single quoted string"); 0 1 1
376 }
377 assert(*ps_parse_ptr == '\'');
378 8001654 ps_parse_ptr++; /* skip over the trailing quote */
379 8001654 return TOKEN_Q_STRING;
380 }
381  
382 /* recursively undump a DD style dump
383 *
384 * If called with an obj_char then we are building an object of that type, otherwise we are searching for
385 * a new value. When we encounter a '[' we gobble it up and then call the child with '[' as the obj_char
386 * where it then parses until it encounters a ']' which it eats, and then return whatever it built.
387 *
388 * We restrict to objects nested 100 items deep.
389 *
390 * If anything bogus in the input stream is encountered we free everything created so far, and return 0
391 * to unwind.
392 *
393 * Returns either an SV or NULL indicating an error.
394 *
395 */
396 6421086 SV* _undump(pTHX_ parse_state *ps, char obj_char, U8 call_depth) {
397 6421086 char ch= 0;
398 frame_state fss;
399 6421086 frame_state *fs= &fss;
400  
401 6421086 fs_token= TOKEN_ERROR;
402 6421086 fs_flags= 0;
403 6421086 fs_refs= 0;
404 6421086 fs_key= 0;
405 6421086 fs_key_len= 0;
406 6421086 fs_thing= 0;
407 6421086 fs_got_key= 0;
408 6421086 fs_got= 0;
409 6421086 fs_depth= call_depth;
410  
411 6421086 ▶ if (call_depth > 100) {
Branch: 1 branch
BranchTrueFalseTotal
if (call_depth > 100) { 0 6421086 6421086
412 0 ▶ PANIC(ps,fs,"Structure is nested too deep");
Branch: 4 branches
BranchTrueFalseTotal
PANIC(ps,fs,"Structure is nested too deep"); 0 0 0
PANIC(ps,fs,"Structure is nested too deep"); 0 0 0
PANIC(ps,fs,"Structure is nested too deep"); 0 0 0
PANIC(ps,fs,"Structure is nested too deep"); 0 0 0
413 }
414  
415 6421086 ▶ if (!obj_char) {
Branch: 1 branch
BranchTrueFalseTotal
if (!obj_char) { 158200 6262886 6421086
416 158200 fs_stop_char= 0;
417 6262886 ▶ } else if (obj_char == '[') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (obj_char == '[') { 4123373 2139513 6262886
418 4123373 fs_thing= (SV*)newAV();
419 4123373 fs_stop_char= ']';
420 2139513 ▶ } else if (obj_char == '{') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (obj_char == '{') { 2139513 0 2139513
421 2139513 fs_key= 0;
422 2139513 fs_key_len= 0;
423 2139513 fs_thing= (SV*)newHV();
424 2139513 WANT_KEY_on(fs);
425 2139513 fs_stop_char= '}';
426 } else {
427 0 ▶ PANICf1(ps,fs, "Unknown obj char '%c'", obj_char);
Branch: 4 branches
BranchTrueFalseTotal
PANICf1(ps,fs, "Unknown obj char '%c'", obj_char); 0 0 0
PANICf1(ps,fs, "Unknown obj char '%c'", obj_char); 0 0 0
PANICf1(ps,fs, "Unknown obj char '%c'", obj_char); 0 0 0
PANICf1(ps,fs, "Unknown obj char '%c'", obj_char); 0 0 0
428 }
429  
430 30816761 REPARSE:
431 74314757 ▶ while ( ps_parse_ptr < ps_string_end) {
Branch: 1 branch
BranchTrueFalseTotal
while ( ps_parse_ptr < ps_string_end) { 74314752 5 74314757
432 74314752 fs_token_start= ps_parse_ptr;
433 74314752 fs_token= TOKEN_ERROR;
434 74314752 ch= *(ps_parse_ptr++);
435 74314752 switch (ch) {
436 2 case '#':
437 16 ▶ while ( *ps_parse_ptr && *ps_parse_ptr != '\n' ) ps_parse_ptr++;
Branch: 2 branches
BranchTrueFalseTotal
while ( *ps_parse_ptr && *ps_parse_ptr != '\n' ) ps_parse_ptr++; 15 1 16
while ( *ps_parse_ptr && *ps_parse_ptr != '\n' ) ps_parse_ptr++; 14 1 15
438 case CASE_ISWHITE:
439 355 ▶ EAT_WHITES_AND_COMMENTS(ps_parse_ptr);
Branch: 8 branches
BranchTrueFalseTotal
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 5 100 105
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 58 1 59
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 54 4 58
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 95 206 301
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 5 201 206
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 201 201
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 201 201
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 5 196 201
440 196 goto REPARSE;
441 12716607 case '=':
442 12716607 ▶ if ( *ps_parse_ptr != '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( *ps_parse_ptr != '>' ) { 0 12716607 12716607
443 0 ▶ ERROR(ps,fs,"Encountered assignment '=' or unterminated fat comma '=>'");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Encountered assignment '=' or unterminated fat comma '=>'"); 0 0 0
ERROR(ps,fs,"Encountered assignment '=' or unterminated fat comma '=>'"); 0 0 0
ERROR(ps,fs,"Encountered assignment '=' or unterminated fat comma '=>'"); 0 0 0
ERROR(ps,fs,"Encountered assignment '=' or unterminated fat comma '=>'"); 0 0 0
444 }
445 12716607 REQUIRE_FAT_COMMA_off(fs);
446 12716607 ps_parse_ptr++;
447 /* fallthrough */
448 30816569 case ',':
449 /* comma */
450 30816569 ▶ if ( REQUIRE_FAT_COMMA(fs) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( REQUIRE_FAT_COMMA(fs) ) { 2 30816567 30816569
451 2 ▶ ERROR(ps,fs,"expected fat comma after bareword");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"expected fat comma after bareword"); 2 0 2
ERROR(ps,fs,"expected fat comma after bareword"); 0 2 2
ERROR(ps,fs,"expected fat comma after bareword"); 0 2 2
ERROR(ps,fs,"expected fat comma after bareword"); 2 0 2
452 }
453 30816567 ▶ else if ( ! ALLOW_COMMA(fs) ) {
Branch: 1 branch
BranchTrueFalseTotal
else if ( ! ALLOW_COMMA(fs) ) { 2 30816565 30816567
454 2 ▶ ERRORf2(ps,fs,"unexpected %s when expecting a %s",
Branch: 6 branches
BranchTrueFalseTotal
ERRORf2(ps,fs,"unexpected %s when expecting a %s", 1 1 2
ERRORf2(ps,fs,"unexpected %s when expecting a %s", 2 0 2
ERRORf2(ps,fs,"unexpected %s when expecting a %s", 2 0 2
ERRORf2(ps,fs,"unexpected %s when expecting a %s", 0 2 2
ERRORf2(ps,fs,"unexpected %s when expecting a %s", 0 2 2
ERRORf2(ps,fs,"unexpected %s when expecting a %s", 2 0 2
455 (ch=='=' ? "fat comma" : "comma"),(WANT_KEY(fs) ? "key" : "value"));
456 }
457 30816565 ALLOW_COMMA_off(fs);
458 30816565 goto REPARSE;
459 631 case '$':
460 case '%':
461 case '@':
462 631 ps_parse_ptr--;
463 631 ▶ ERROR(ps,fs,"Encountered variable in input. This is not eval - can not undump code");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Encountered variable in input. This is not eval - can not undump code"); 631 0 631
ERROR(ps,fs,"Encountered variable in input. This is not eval - can not undump code"); 0 631 631
ERROR(ps,fs,"Encountered variable in input. This is not eval - can not undump code"); 0 631 631
ERROR(ps,fs,"Encountered variable in input. This is not eval - can not undump code"); 630 1 631
464 6262887 case '{':
465 case '[':
466 6262887 fs_token= TOKEN_OPEN;
467 6262887 break;
468 6260983 case ']':
469 case '}':
470 6260983 fs_token= TOKEN_CLOSE;
471 6260983 break;
472 11 case '\\':
473 11 fs_token= TOKEN_REF;
474 11 break;
475 8001655 case '\'':
476 8001655 ▶ if (!(fs_token= scan_single_quote(ps,fs)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(fs_token= scan_single_quote(ps,fs))) 1 8001654 8001655
477 1 ▶ BAIL(ps,fs);
Branch: 3 branches
BranchTrueFalseTotal
BAIL(ps,fs); 0 1 1
BAIL(ps,fs); 0 1 1
BAIL(ps,fs); 0 1 1
478 8001654 break;
479 2557 case '"':
480 2557 ▶ if (!(fs_token= scan_double_quote(ps,fs)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(fs_token= scan_double_quote(ps,fs))) 1 2556 2557
481 1 ▶ BAIL(ps,fs);
Branch: 3 branches
BranchTrueFalseTotal
BAIL(ps,fs); 0 1 1
BAIL(ps,fs); 0 1 1
BAIL(ps,fs); 0 1 1
482 2556 break;
483 6306 case '-':
484 6306 ch= *ps_parse_ptr;
485 6306 ▶ if ( '0' == ch ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( '0' == ch ) { 1 6305 6306
486 1 ps_parse_ptr++;
487 1 ▶ if (*ps_parse_ptr != '.') {
Branch: 1 branch
BranchTrueFalseTotal
if (*ps_parse_ptr != '.') { 0 1 1
488 0 ▶ ERROR(ps,fs,"Negative number start with a zero that is not fractional is illegal");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Negative number start with a zero that is not fractional is illegal"); 0 0 0
ERROR(ps,fs,"Negative number start with a zero that is not fractional is illegal"); 0 0 0
ERROR(ps,fs,"Negative number start with a zero that is not fractional is illegal"); 0 0 0
ERROR(ps,fs,"Negative number start with a zero that is not fractional is illegal"); 0 0 0
489 }
490 1 goto DO_DECIMAL;
491 6305 ▶ } else if ( '1' <= ch && ch <= '9' ) {
Branch: 2 branches
BranchTrueFalseTotal
} else if ( '1' <= ch && ch <= '9' ) { 6305 0 6305
} else if ( '1' <= ch && ch <= '9' ) { 6304 1 6305
492 6304 ps_parse_ptr++;
493 } else {
494 1 ▶ ERROR(ps,fs,"bare '-' only allowed to signify negative number");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"bare '-' only allowed to signify negative number"); 1 0 1
ERROR(ps,fs,"bare '-' only allowed to signify negative number"); 0 1 1
ERROR(ps,fs,"bare '-' only allowed to signify negative number"); 0 1 1
ERROR(ps,fs,"bare '-' only allowed to signify negative number"); 0 1 1
495 }
496 6304 goto DO_NUMBER;
497 8823783 case '0':
498 8823783 ▶ if ( ps_parse_ptr < ps_string_end && ('0' <= *ps_parse_ptr && *ps_parse_ptr <= '9')) {
Branch: 3 branches
BranchTrueFalseTotal
if ( ps_parse_ptr < ps_string_end && ('0' <= *ps_parse_ptr && *ps_parse_ptr <= '9')) { 8823782 1 8823783
if ( ps_parse_ptr < ps_string_end && ('0' <= *ps_parse_ptr && *ps_parse_ptr <= '9')) { 5416741 3407041 8823782
if ( ps_parse_ptr < ps_string_end && ('0' <= *ps_parse_ptr && *ps_parse_ptr <= '9')) { 3407040 1 3407041
499 1 ▶ ERROR(ps,fs,"Zero may not be followed by another digit at the start of a number");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Zero may not be followed by another digit at the start of a number"); 1 0 1
ERROR(ps,fs,"Zero may not be followed by another digit at the start of a number"); 0 1 1
ERROR(ps,fs,"Zero may not be followed by another digit at the start of a number"); 0 1 1
ERROR(ps,fs,"Zero may not be followed by another digit at the start of a number"); 0 1 1
500 }
501 case '1':
502 case '2':
503 case '3':
504 case '4':
505 case '5':
506 case '6':
507 case '7':
508 case '8':
509 case '9':
510 8823782 DO_NUMBER:
511 /* number */
512 12824323 ch= *ps_parse_ptr;
513 31878715 ▶ while ( '0' <= ch && ch <= '9' ) {
Branch: 2 branches
BranchTrueFalseTotal
while ( '0' <= ch && ch <= '9' ) { 23199797 8678918 31878715
while ( '0' <= ch && ch <= '9' ) { 19054392 4145405 23199797
514 19054392 ch= *(++ps_parse_ptr);
515 }
516 12824323 ▶ if ( ch == '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ch == '.' ) { 6 12824317 12824323
517 6 DO_DECIMAL:
518 7 ch= *(++ps_parse_ptr);
519 7 ▶ if ( '0' <= ch && ch <= '9' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( '0' <= ch && ch <= '9' ) { 6 1 7
if ( '0' <= ch && ch <= '9' ) { 6 0 6
520 6 ch= *(++ps_parse_ptr);
521 } else {
522 1 ▶ ERROR(ps,fs,"Unexpected end of floating point number after decimal point");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Unexpected end of floating point number after decimal point"); 1 0 1
ERROR(ps,fs,"Unexpected end of floating point number after decimal point"); 0 1 1
ERROR(ps,fs,"Unexpected end of floating point number after decimal point"); 0 1 1
ERROR(ps,fs,"Unexpected end of floating point number after decimal point"); 0 1 1
523 }
524 13 ▶ while ('0' <= ch && ch <= '9') {
Branch: 2 branches
BranchTrueFalseTotal
while ('0' <= ch && ch <= '9') { 7 6 13
while ('0' <= ch && ch <= '9') { 7 0 7
525 7 ch= *(++ps_parse_ptr);
526 }
527 6 fs_token= TOKEN_NV;
528 } else {
529 12824317 fs_token= TOKEN_IV;
530 }
531 12824323 break;
532 10144937 default:
533 10144937 ▶ if (bareword_start[(U8)ch]) {
Branch: 1 branch
BranchTrueFalseTotal
if (bareword_start[(U8)ch]) { 10144937 0 10144937
534 10144937 ch= *ps_parse_ptr;
535 116752347 ▶ while ( bareword_rest[(U8)ch] ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( bareword_rest[(U8)ch] ) { 106607410 10144937 116752347
536 106607410 ch= *(++ps_parse_ptr);
537 }
538 } else {
539 0 ps_parse_ptr--;
540 0 ▶ PANICf2(ps,fs,"Unexpected character '%c' codepoint 0x%02x while parsing bareword",ch,ch);
Branch: 4 branches
BranchTrueFalseTotal
PANICf2(ps,fs,"Unexpected character '%c' codepoint 0x%02x while parsing bareword",ch,ch); 0 0 0
PANICf2(ps,fs,"Unexpected character '%c' codepoint 0x%02x while parsing bareword",ch,ch); 0 0 0
PANICf2(ps,fs,"Unexpected character '%c' codepoint 0x%02x while parsing bareword",ch,ch); 0 0 0
PANICf2(ps,fs,"Unexpected character '%c' codepoint 0x%02x while parsing bareword",ch,ch); 0 0 0
541 }
542 /* for some reason all the interesting keywords are 5 characters long */
543 10144937 ▶ if ( 5 == (ps_parse_ptr - fs_token_start) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( 5 == (ps_parse_ptr - fs_token_start) ) { 115930 10029007 10144937
544 115930 if (
545 115930 ▶ 'b' == fs_token_start[0] &&
Branch: 1 branch
BranchTrueFalseTotal
'b' == fs_token_start[0] && 4 115926 115930
546 4 ▶ 'l' == fs_token_start[1] &&
Branch: 1 branch
BranchTrueFalseTotal
'l' == fs_token_start[1] && 4 0 4
547 4 ▶ 'e' == fs_token_start[2] &&
Branch: 1 branch
BranchTrueFalseTotal
'e' == fs_token_start[2] && 4 0 4
548 4 ▶ 's' == fs_token_start[3] &&
Branch: 1 branch
BranchTrueFalseTotal
's' == fs_token_start[3] && 4 0 4
549 4 ▶ 's' == fs_token_start[4]
Branch: 1 branch
BranchTrueFalseTotal
's' == fs_token_start[4] 4 0 4
550 ){
551 4 fs_token= TOKEN_BLESS;
552 115926 } else if (
553 115926 ▶ 'u' == fs_token_start[0] &&
Branch: 1 branch
BranchTrueFalseTotal
'u' == fs_token_start[0] && 34026 81900 115926
554 34026 ▶ 'n' == fs_token_start[1] &&
Branch: 1 branch
BranchTrueFalseTotal
'n' == fs_token_start[1] && 32766 1260 34026
555 32766 ▶ 'd' == fs_token_start[2] &&
Branch: 1 branch
BranchTrueFalseTotal
'd' == fs_token_start[2] && 32766 0 32766
556 32766 ▶ 'e' == fs_token_start[3] &&
Branch: 1 branch
BranchTrueFalseTotal
'e' == fs_token_start[3] && 32766 0 32766
557 32766 ▶ 'f' == fs_token_start[4]
Branch: 1 branch
BranchTrueFalseTotal
'f' == fs_token_start[4] 32766 0 32766
558 ){
559 32766 fs_token= TOKEN_UNDEF;
560 } else {
561 83160 fs_token= TOKEN_BAREWORD;
562 }
563 } else {
564 10029007 fs_token= TOKEN_BAREWORD;
565 }
566 } /* switch */
567 43497351 ▶ if (REQUIRE_FAT_COMMA(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (REQUIRE_FAT_COMMA(fs)) { 1 43497350 43497351
568 1 ▶ ERROR(ps,fs,"expected fat comma after bareword");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"expected fat comma after bareword"); 1 0 1
ERROR(ps,fs,"expected fat comma after bareword"); 0 1 1
ERROR(ps,fs,"expected fat comma after bareword"); 0 1 1
ERROR(ps,fs,"expected fat comma after bareword"); 1 0 1
569 43497350 ▶ } else if (ALLOW_COMMA(fs) && fs_token != TOKEN_CLOSE) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (ALLOW_COMMA(fs) && fs_token != TOKEN_CLOSE) { 6260331 37237019 43497350
} else if (ALLOW_COMMA(fs) && fs_token != TOKEN_CLOSE) { 0 6260331 6260331
570 0 ▶ ERRORf1(ps,fs,"Expecting comma got %s",token_name[fs_token]);
Branch: 4 branches
BranchTrueFalseTotal
ERRORf1(ps,fs,"Expecting comma got %s",token_name[fs_token]); 0 0 0
ERRORf1(ps,fs,"Expecting comma got %s",token_name[fs_token]); 0 0 0
ERRORf1(ps,fs,"Expecting comma got %s",token_name[fs_token]); 0 0 0
ERRORf1(ps,fs,"Expecting comma got %s",token_name[fs_token]); 0 0 0
571 }
572 SHOW_TOKEN(ps,fs);
573 43497350 switch (fs_token) {
574 11 case TOKEN_REF:
575 11 ▶ if (WANT_KEY(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WANT_KEY(fs)) { 0 11 11
576 0 ▶ ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch);
Branch: 4 branches
BranchTrueFalseTotal
ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch); 0 0 0
ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch); 0 0 0
ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch); 0 0 0
ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch); 0 0 0
577 }
578 11 ▶ if (fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_got) { 0 11 11
579 0 ▶ ERROR(ps,fs,"Multiple objects in stream?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
580 }
581 11 fs_refs++;
582 11 break;
583 4 case TOKEN_BLESS:
584 4 ▶ if ( *ps_parse_ptr != '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ( *ps_parse_ptr != '(') { 0 4 4
585 0 ▶ ERROR(ps,fs,"expected a '(' after 'bless'");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"expected a '(' after 'bless'"); 0 0 0
ERROR(ps,fs,"expected a '(' after 'bless'"); 0 0 0
ERROR(ps,fs,"expected a '(' after 'bless'"); 0 0 0
ERROR(ps,fs,"expected a '(' after 'bless'"); 0 0 0
586 } else {
587 4 ps_parse_ptr++;
588 /* ERROR(ps,fs,"after bless("); */
589 }
590 4 ▶ if (WANT_KEY(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WANT_KEY(fs)) { 0 4 4
591 0 ▶ ERROR(ps,fs,"unexpected bless() call when expecting a key");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"unexpected bless() call when expecting a key"); 0 0 0
ERROR(ps,fs,"unexpected bless() call when expecting a key"); 0 0 0
ERROR(ps,fs,"unexpected bless() call when expecting a key"); 0 0 0
ERROR(ps,fs,"unexpected bless() call when expecting a key"); 0 0 0
592 }
593 4 ch= 0; /* flag for blessing */
594 6262891 case TOKEN_OPEN:
595 6262891 ▶ if (WANT_KEY(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WANT_KEY(fs)) { 1 6262890 6262891
596 1 ▶ ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch);
Branch: 4 branches
BranchTrueFalseTotal
ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch); 1 0 1
ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch); 0 1 1
ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch); 0 1 1
ERRORf1(ps,fs,"unexpected open bracket '%c' when expecting a key", ch); 1 0 1
597 }
598 6262890 ▶ if (fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_got) { 0 6262890 6262890
599 0 ▶ ERROR(ps,fs,"Multiple objects in stream?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
600 }
601 6262890 fs_got= _undump( aTHX_ ps, ch, call_depth+1);
602 6262890 ▶ if (!fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
if (!fs_got) { 1903 6260987 6262890
603 1903 ▶ BAIL(ps,fs);
Branch: 3 branches
BranchTrueFalseTotal
BAIL(ps,fs); 0 1903 1903
BAIL(ps,fs); 0 1903 1903
BAIL(ps,fs); 1261 642 1903
604 } else {
605 6260987 ▶ if ( ch == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ch == 0 ) { 4 6260983 6260987
606 char quote;
607 HV *stash;
608 5 ▶ EAT_WHITES_AND_COMMENTS(ps_parse_ptr);
Branch: 8 branches
BranchTrueFalseTotal
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 1 1
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 0 0
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 0 0
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 1 4 5
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 4 4
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 4 4
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 4 4
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 4 4
609 4 ▶ if (*ps_parse_ptr == ',') {
Branch: 1 branch
BranchTrueFalseTotal
if (*ps_parse_ptr == ',') { 4 0 4
610 4 ps_parse_ptr++;
611 18 ▶ EAT_WHITES_AND_COMMENTS(ps_parse_ptr);
Branch: 8 branches
BranchTrueFalseTotal
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 1 7 8
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 7 0 7
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 6 1 7
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 6 6 12
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 1 5 6
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 5 5
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 0 5 5
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); 1 4 5
612 } else {
613 0 ▶ ERROR(ps,fs,"expected a comma after object in bless()");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"expected a comma after object in bless()"); 0 0 0
ERROR(ps,fs,"expected a comma after object in bless()"); 0 0 0
ERROR(ps,fs,"expected a comma after object in bless()"); 0 0 0
ERROR(ps,fs,"expected a comma after object in bless()"); 0 0 0
614 }
615 4 ch= *ps_parse_ptr;
616 4 ▶ if ( ch != '\'' && ch != '\"') {
Branch: 2 branches
BranchTrueFalseTotal
if ( ch != '\'' && ch != '\"') { 4 0 4
if ( ch != '\'' && ch != '\"') { 0 4 4
617 0 ▶ ERROR(ps,fs,"Expected quoted class name after object in bless()");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Expected quoted class name after object in bless()"); 0 0 0
ERROR(ps,fs,"Expected quoted class name after object in bless()"); 0 0 0
ERROR(ps,fs,"Expected quoted class name after object in bless()"); 0 0 0
ERROR(ps,fs,"Expected quoted class name after object in bless()"); 0 0 0
618 }
619 4 quote= ch;
620 4 fs_token_start= ++ps_parse_ptr;
621 4 ▶ if (!bareword_start[(U8)*ps_parse_ptr]) {
Branch: 1 branch
BranchTrueFalseTotal
if (!bareword_start[(U8)*ps_parse_ptr]) { 0 4 4
622 0 ▶ ERROR(ps,fs,"Expected classname to start with [A-Za-z_]");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Expected classname to start with [A-Za-z_]"); 0 0 0
ERROR(ps,fs,"Expected classname to start with [A-Za-z_]"); 0 0 0
ERROR(ps,fs,"Expected classname to start with [A-Za-z_]"); 0 0 0
ERROR(ps,fs,"Expected classname to start with [A-Za-z_]"); 0 0 0
623 }
624 do {
625 15 ch= *(++ps_parse_ptr);
626 15 ▶ if (ch == ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (ch == ':') { 1 14 15
627 1 ch= *(++ps_parse_ptr);
628 1 ▶ if (ch != ':') {
Branch: 1 branch
BranchTrueFalseTotal
if (ch != ':') { 0 1 1
629 0 ▶ ERROR(ps,fs,"Single colon in class name?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Single colon in class name?"); 0 0 0
ERROR(ps,fs,"Single colon in class name?"); 0 0 0
ERROR(ps,fs,"Single colon in class name?"); 0 0 0
ERROR(ps,fs,"Single colon in class name?"); 0 0 0
630 } else {
631 1 ch= *(++ps_parse_ptr);
632 }
633 }
634 }
635 15 ▶ while (bareword_rest[(U8)ch]);
Branch: 1 branch
BranchTrueFalseTotal
while (bareword_rest[(U8)ch]); 11 4 15
636 4 ▶ if (ch != quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (ch != quote) { 0 4 4
637 0 ▶ ERROR(ps,fs,"Unterminated or corrupt classname");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Unterminated or corrupt classname"); 0 0 0
ERROR(ps,fs,"Unterminated or corrupt classname"); 0 0 0
ERROR(ps,fs,"Unterminated or corrupt classname"); 0 0 0
ERROR(ps,fs,"Unterminated or corrupt classname"); 0 0 0
638 }
639  
640 /* XXX: mortalize 'got; here? can this die? */
641 4 stash= gv_stashpvn(fs_token_start, ps_parse_ptr - fs_token_start, 1);
642 4 ▶ if (!stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!stash) { 0 4 4
643 0 ▶ PANIC(ps,fs,"Failed to load stash");
Branch: 4 branches
BranchTrueFalseTotal
PANIC(ps,fs,"Failed to load stash"); 0 0 0
PANIC(ps,fs,"Failed to load stash"); 0 0 0
PANIC(ps,fs,"Failed to load stash"); 0 0 0
PANIC(ps,fs,"Failed to load stash"); 0 0 0
644 }
645 4 ++ps_parse_ptr; /* skip quote */
646 23 ▶ EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */
Branch: 8 branches
BranchTrueFalseTotal
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */ 1 6 7
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */ 13 0 13
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */ 12 1 13
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */ 5 6 11
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */ 1 5 6
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */ 0 5 5
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */ 0 5 5
EAT_WHITES_AND_COMMENTS(ps_parse_ptr); /* eat optional whitespace after quote */ 1 4 5
647 4 ch= *ps_parse_ptr; /* check we have a close paren */
648 4 ▶ if (ch != ')') {
Branch: 1 branch
BranchTrueFalseTotal
if (ch != ')') { 1 3 4
649 1 ▶ ERRORf1(ps,fs,"expecting a close paren for bless but got a '%c'",ch);
Branch: 4 branches
BranchTrueFalseTotal
ERRORf1(ps,fs,"expecting a close paren for bless but got a '%c'",ch); 1 0 1
ERRORf1(ps,fs,"expecting a close paren for bless but got a '%c'",ch); 1 0 1
ERRORf1(ps,fs,"expecting a close paren for bless but got a '%c'",ch); 0 1 1
ERRORf1(ps,fs,"expecting a close paren for bless but got a '%c'",ch); 0 1 1
650 } else {
651 3 ps_parse_ptr++;
652 }
653 /* and finally do the blessing */
654 if(0) do_sv_dump(0, Perl_debug_log, fs_got, 0, 4, 0, 0);
655 3 sv_bless(fs_got,stash);
656 if(0) do_sv_dump(0, Perl_debug_log, fs_got, 0, 4, 0, 0);
657
658 }
659 6260986 goto GOT_SV;
660 }
661 /* unreached */
662 break;
663 6260983 case TOKEN_CLOSE:
664 {
665 6260983 ▶ if (fs_stop_char == ch) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_stop_char == ch) { 6260983 0 6260983
666 6260983 ▶ if (fs_got_key || fs_key) {
Branch: 2 branches
BranchTrueFalseTotal
if (fs_got_key || fs_key) { 6260983 0 6260983
if (fs_got_key || fs_key) { 0 6260983 6260983
667 0 ▶ ERROR(ps,fs,"Odd number of items in hash constructor");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Odd number of items in hash constructor"); 0 0 0
ERROR(ps,fs,"Odd number of items in hash constructor"); 0 0 0
ERROR(ps,fs,"Odd number of items in hash constructor"); 0 0 0
ERROR(ps,fs,"Odd number of items in hash constructor"); 0 0 0
668 }
669 6260983 return newRV_noinc((SV *)fs_thing);
670 0 ▶ } else if (!fs_stop_char) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (!fs_stop_char) { 0 0 0
671 0 ▶ ERRORf1(ps,fs,"Unexpected close bracket '%c'",ch);
Branch: 4 branches
BranchTrueFalseTotal
ERRORf1(ps,fs,"Unexpected close bracket '%c'",ch); 0 0 0
ERRORf1(ps,fs,"Unexpected close bracket '%c'",ch); 0 0 0
ERRORf1(ps,fs,"Unexpected close bracket '%c'",ch); 0 0 0
ERRORf1(ps,fs,"Unexpected close bracket '%c'",ch); 0 0 0
672 } else {
673 0 ▶ ERRORf2(ps,fs,"Unexpected close '%c' while parsing %s",
Branch: 5 branches
BranchTrueFalseTotal
ERRORf2(ps,fs,"Unexpected close '%c' while parsing %s", 0 0 0
ERRORf2(ps,fs,"Unexpected close '%c' while parsing %s", 0 0 0
ERRORf2(ps,fs,"Unexpected close '%c' while parsing %s", 0 0 0
ERRORf2(ps,fs,"Unexpected close '%c' while parsing %s", 0 0 0
ERRORf2(ps,fs,"Unexpected close '%c' while parsing %s", 0 0 0
674 ch, (fs_stop_char == '}') ? "HASH" : "ARRAY");
675 }
676 break;
677 }
678 32766 case TOKEN_UNDEF:
679 32766 ▶ if (WANT_KEY(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WANT_KEY(fs)) { 1 32765 32766
680 1 ▶ ERROR(ps,fs,"got an undef when we wanted a key");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"got an undef when we wanted a key"); 1 0 1
ERROR(ps,fs,"got an undef when we wanted a key"); 0 1 1
ERROR(ps,fs,"got an undef when we wanted a key"); 0 1 1
ERROR(ps,fs,"got an undef when we wanted a key"); 1 0 1
681 }
682 32765 ▶ if (fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_got) { 0 32765 32765
683 0 ▶ ERROR(ps,fs,"Multiple objects in stream?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
684 }
685 32765 fs_got= newSV(0);
686 32765 goto GOT_SV;
687 /* unreached */
688 break;
689
690 8004210 case TOKEN_Q_STRING:
691 case TOKEN_QQ_STRING:{
692 /* nothing to unescape - we are done now */
693 8004210 fs_token_start++; /* skip the first quote */
694 8004210 ▶ if ( !fs_first_escape ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !fs_first_escape ) { 8001662 2548 8004210
695 /* it didnt contain any escapes */
696 8001662 ▶ if ( WANT_KEY(fs) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( WANT_KEY(fs) ) { 2604427 5397235 8001662
697 2604427 fs_key= fs_token_start;
698 2604427 fs_key_len= ps_parse_ptr - fs_token_start - 1; /* remove trailing quote */
699  
700 2604427 WANT_KEY_off(fs);
701 2604427 ALLOW_COMMA_on(fs);
702 2604427 break;
703 }
704 5397235 ▶ if (fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_got) { 0 5397235 5397235
705 0 ▶ ERROR(ps,fs,"Multiple objects in stream?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
706 }
707 5397235 fs_got= newSVpvn(fs_token_start, ps_parse_ptr - fs_token_start - 1); /* remove trailing quote */
708 5397235 goto GOT_SV;
709 } else {
710 /* contains escapes - so we have to unescape it */
711 2548 STRLEN len= 0;
712 2548 I32 grok_flags= 0;
713 const char *grok_start;
714 2548 char is_uni= 0;
715 2548 char must_upgrade= 0;
716 char *new_str_begin;
717 const char *esc_read;
718 const char *esc_read_end;
719  
720 char *esc_write;
721 char *esc_write_end;
722
723 2548 ▶ if (fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_got) { 0 2548 2548
724 0 ▶ ERROR(ps,fs,"Multiple objects in stream?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
725 }
726 /* create a new SV with a copy of the raw escaped string in it
727 * note that we always have "room" to do this, all escaped structures
728 * convert to something shorter than their escaped form, so we can do
729 * things in place */
730  
731 2548 fs_got= newSVpvn(fs_token_start, ps_parse_ptr - fs_token_start - 1); /* remove trailing quote */
732 /* the sv now contains a copy of the unescaped string */
733  
734 2548 new_str_begin= SvPV(fs_got, len);
735 2548 esc_write= new_str_begin + ( fs_first_escape - fs_token_start );
736 2548 esc_write_end= new_str_begin + len;
737  
738 2548 esc_read_end= fs_token_start + len;
739 2548 esc_read= fs_token_start + ( fs_first_escape - fs_token_start );
740  
741 2548 ▶ if (*esc_read != '\\' || *esc_write != '\\') {
Branch: 2 branches
BranchTrueFalseTotal
if (*esc_read != '\\' || *esc_write != '\\') { 2548 0 2548
if (*esc_read != '\\' || *esc_write != '\\') { 0 2548 2548
742 0 ▶ PANIC(ps,fs,"when parsing quoted string failed start quote sanity check");
Branch: 4 branches
BranchTrueFalseTotal
PANIC(ps,fs,"when parsing quoted string failed start quote sanity check"); 0 0 0
PANIC(ps,fs,"when parsing quoted string failed start quote sanity check"); 0 0 0
PANIC(ps,fs,"when parsing quoted string failed start quote sanity check"); 0 0 0
PANIC(ps,fs,"when parsing quoted string failed start quote sanity check"); 0 0 0
743 }
744 2548 ▶ if (fs_token == TOKEN_Q_STRING) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_token == TOKEN_Q_STRING) { 6 2542 2548
745 do {
746 14 ▶ if (*esc_read == '\\' && (esc_read[1] == '\\' || esc_read[1] == '\'')) {
Branch: 3 branches
BranchTrueFalseTotal
if (*esc_read == '\\' && (esc_read[1] == '\\' || esc_read[1] == '\'')) { 10 4 14
if (*esc_read == '\\' && (esc_read[1] == '\\' || esc_read[1] == '\'')) { 6 4 10
if (*esc_read == '\\' && (esc_read[1] == '\\' || esc_read[1] == '\'')) { 6 0 6
747 10 esc_read++;
748 }
749 14 *esc_write++= *esc_read++;
750 14 ▶ } while (esc_read < esc_read_end);
Branch: 1 branch
BranchTrueFalseTotal
} while (esc_read < esc_read_end); 8 6 14
751 } else { /* TOKEN_QQ_STRING */
752 171684 ▶ while (esc_read < esc_read_end) {
Branch: 1 branch
BranchTrueFalseTotal
while (esc_read < esc_read_end) { 169142 2542 171684
753 169142 U32 cp= *esc_read++;
754 169142 ▶ if ( cp == '\\' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( cp == '\\' ) { 84579 84563 169142
755 84579 ▶ if (esc_read >= esc_read_end) {
Branch: 1 branch
BranchTrueFalseTotal
if (esc_read >= esc_read_end) { 0 84579 84579
756 0 ▶ PANIC(ps,fs,"ran off end of string");
Branch: 4 branches
BranchTrueFalseTotal
PANIC(ps,fs,"ran off end of string"); 0 0 0
PANIC(ps,fs,"ran off end of string"); 0 0 0
PANIC(ps,fs,"ran off end of string"); 0 0 0
PANIC(ps,fs,"ran off end of string"); 0 0 0
757 }
758 84579 ch= *esc_read++;
759 84579 switch (ch) {
760 12 case '0':
761 case '1':
762 case '2':
763 case '3':
764 case '4':
765 case '5':
766 case '6':
767 case '7':
768 /* first octal digit */
769 12 grok_start= esc_read - 1; /* it was advanced earlier */
770 12 ch= *esc_read;
771 12 ▶ if ('0' <= ch && ch <= '7') {
Branch: 2 branches
BranchTrueFalseTotal
if ('0' <= ch && ch <= '7') { 12 0 12
if ('0' <= ch && ch <= '7') { 12 0 12
772 /* second octal digit */
773 12 esc_read++;
774 12 ch= *esc_read;
775 12 ▶ if ('0' <= ch && ch <= '7') {
Branch: 2 branches
BranchTrueFalseTotal
if ('0' <= ch && ch <= '7') { 4 8 12
if ('0' <= ch && ch <= '7') { 4 0 4
776 /* third octal digit */
777 4 esc_read++;
778 }
779 }
780 12 len= esc_read - grok_start;
781 12 cp= grok_oct((char *)grok_start, &len, &grok_flags, 0);
782 12 ▶ if (cp>127) {
Branch: 1 branch
BranchTrueFalseTotal
if (cp>127) { 2 10 12
783 2 must_upgrade=1;
784 }
785 12 break;
786 10099 case 'x':
787 10099 ▶ if (*esc_read != '{') {
Branch: 1 branch
BranchTrueFalseTotal
if (*esc_read != '{') { 0 10099 10099
788 0 ▶ ERROR(ps,fs,"truncated \\x{} sequence?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"truncated \\x{} sequence?"); 0 0 0
ERROR(ps,fs,"truncated \\x{} sequence?"); 0 0 0
ERROR(ps,fs,"truncated \\x{} sequence?"); 0 0 0
ERROR(ps,fs,"truncated \\x{} sequence?"); 0 0 0
789 } else {
790 10099 esc_read++;
791 }
792 10099 grok_start= esc_read;
793 31567 ▶ while (*esc_read && *esc_read != '}') esc_read++;
Branch: 2 branches
BranchTrueFalseTotal
while (*esc_read && *esc_read != '}') esc_read++; 31567 0 31567
while (*esc_read && *esc_read != '}') esc_read++; 21468 10099 31567
794 10099 ▶ if (*esc_read != '}') {
Branch: 1 branch
BranchTrueFalseTotal
if (*esc_read != '}') { 0 10099 10099
795 0 ▶ ERROR(ps,fs,"unterminated \\x{} in double quoted string");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"unterminated \\x{} in double quoted string"); 0 0 0
ERROR(ps,fs,"unterminated \\x{} in double quoted string"); 0 0 0
ERROR(ps,fs,"unterminated \\x{} in double quoted string"); 0 0 0
ERROR(ps,fs,"unterminated \\x{} in double quoted string"); 0 0 0
796 } else {
797 10099 len= esc_read - grok_start;
798 10099 esc_read++; /* skip '}' */
799 }
800 if (0) warn("hex: %.*s\n", (int)len, grok_start);
801 10099 ▶ if (len) {
Branch: 1 branch
BranchTrueFalseTotal
if (len) { 10099 0 10099
802 10099 cp= grok_hex((char *)grok_start, &len, &grok_flags, 0);
803 } else {
804 0 ▶ ERROR(ps,fs,"empty \\x{} escape?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"empty \\x{} escape?"); 0 0 0
ERROR(ps,fs,"empty \\x{} escape?"); 0 0 0
ERROR(ps,fs,"empty \\x{} escape?"); 0 0 0
ERROR(ps,fs,"empty \\x{} escape?"); 0 0 0
805 }
806  
807 if (0) warn("cp: %d\n len: %d flags: %d", cp, (int)len, grok_flags);
808 10099 ▶ if ( !is_uni ) { /* otherwise it would be in octal */
Branch: 1 branch
BranchTrueFalseTotal
if ( !is_uni ) { /* otherwise it would be in octal */ 2527 7572 10099
809 STRLEN len;
810 2527 is_uni= 1;
811 2527 ▶ if (must_upgrade) {
Branch: 1 branch
BranchTrueFalseTotal
if (must_upgrade) { 0 2527 2527
812 0 SvCUR_set(fs_got, esc_write - new_str_begin);
813 0 len= sv_utf8_upgrade_nomg(fs_got);
814 0 new_str_begin= SvPV_nolen(fs_got);
815 0 esc_write= new_str_begin+len;
816 0 esc_write_end= new_str_begin + SvLEN(fs_got);
817 } else {
818 2527 SvUTF8_on(fs_got);
819 }
820 }
821 10099 ▶ if (cp>0x10FFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if (cp>0x10FFFF) { 0 10099 10099
822 0 ▶ ERRORf1(ps,fs,"Illegal codepoint in \\x{%x}",cp);
Branch: 4 branches
BranchTrueFalseTotal
ERRORf1(ps,fs,"Illegal codepoint in \\x{%x}",cp); 0 0 0
ERRORf1(ps,fs,"Illegal codepoint in \\x{%x}",cp); 0 0 0
ERRORf1(ps,fs,"Illegal codepoint in \\x{%x}",cp); 0 0 0
ERRORf1(ps,fs,"Illegal codepoint in \\x{%x}",cp); 0 0 0
823 }
824 10099 break;
825 /* printf-style backslashes, formfeeds, newlines, etc */
826 0 case 'a': cp= '\007'; break; /* "\a" => "\\a", */
827 0 case 'b': cp= '\b'; break; /* "\b" => "\\b", */
828 0 case 'e': cp= '\033'; break; /* "\e" => "\\e", */
829 0 case 'f': cp= '\f'; break; /* "\f" => "\\f", */
830 0 case 'n': cp= '\n'; break; /* "\n" => "\\n", */
831 0 case 'r': cp= '\r'; break; /* "\r" => "\\r", */
832 0 case 't': cp= '\t'; break; /* "\t" => "\\t", */
833 74468 default: cp= ch; break; /* literal */
834 } /* switch on escape type */
835 84579 ▶ if (is_uni) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_uni) { 77616 6963 84579
836 /*
837 if ( esc_write_end - esc_write < UTF8_MAXBYTES + 1 ) {
838 SvCUR_set(fs_got, esc_write - new_str_begin);
839 new_str_begin= SvGROW(fs_got, UTF8_MAXBYTES + 1);
840 esc_write= SvEND(fs_got);
841 esc_write_end= new_str_begin + SvLEN(fs_got);
842 }
843 */
844 77616 esc_write= uvchr_to_utf8(esc_write, cp);
845 }
846 else {
847 6963 *esc_write++= (char)cp;
848 }
849 } /* end - is an escape */
850 else {
851 84563 const char *no_esc_start= esc_read - 1;
852 4833500 ▶ while ( *esc_read != '\\' && esc_read < esc_read_end ) {
Branch: 2 branches
BranchTrueFalseTotal
while ( *esc_read != '\\' && esc_read < esc_read_end ) { 4751465 82035 4833500
while ( *esc_read != '\\' && esc_read < esc_read_end ) { 4748937 2528 4751465
853 4748937 esc_read++;
854 }
855 84563 len= esc_read - no_esc_start + 1;
856 /*
857 if ( is_uni && esc_write_end - esc_write < len ) {
858 SvCUR_set(fs_got, esc_write - new_str_begin);
859 new_str_begin= SvGROW(fs_got, len);
860 esc_write= SvEND(fs_got);
861 esc_write_end= new_str_begin + SvLEN(fs_got);
862 }
863 */
864 84563 Copy(no_esc_start, esc_write, len - 1, char);
865 84563 esc_write += esc_read - no_esc_start;
866 }
867 } /* while */
868 } /* TOKEN_Q_STRING or TOKEN_QQ_STRING */
869 2548 SvCUR_set(fs_got, esc_write - new_str_begin);
870 2548 *esc_write++= 0;
871 2548 ▶ if (WANT_KEY(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WANT_KEY(fs)) { 7 2541 2548
872 /* we contain stuff that will be used as a hash key lookup */
873 7 fs_got_key= fs_got; /* swap got over to the got_key var for later */
874 7 fs_key= 0; /* make sure we dont get confused about two keys */
875 7 fs_got= 0; /* clear got */
876 7 DONE_KEY_break;
877 } else {
878 /* and now do something with the SV */
879 2541 goto GOT_SV;
880 }
881 }
882 /* not reached */
883 }
884 10112166 case TOKEN_BAREWORD:
885 /* fallthrough */
886 10112166 REQUIRE_FAT_COMMA_on(fs);
887 10112166 ▶ if (WANT_KEY(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WANT_KEY(fs)) { 10112163 3 10112166
888 10112163 DONE_KEY_SIMPLE_break;
889 }
890 3 ▶ if (fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_got) { 0 3 3
891 0 ▶ ERROR(ps,fs,"Multiple objects in stream?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
892 }
893 3 fs_got= newSVpvn(fs_token_start, ps_parse_ptr - fs_token_start);
894 3 goto GOT_SV;
895 12824317 case TOKEN_IV:{
896 /* fallthrough */
897 12824317 ▶ if (WANT_KEY(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WANT_KEY(fs)) { 9 12824308 12824317
898 9 DONE_KEY_SIMPLE_break;
899 }
900 12824308 ch= ps_parse_ptr - fs_token_start;
901 12824308 ▶ if (fs_token_start[0] == '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_token_start[0] == '-') { 6301 12818007 12824308
902 6301 IV iv= 0;
903 6301 ▶ if ( ch < 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ch < 12) { 6301 0 6301
904 6301 fs_token_start++;
905 6301 switch (ch) {
906 1 case 11: iv -= (*fs_token_start++ - '0') * 1000000000L;
907 1 case 10: iv -= (*fs_token_start++ - '0') * 100000000L;
908 1 case 9: iv -= (*fs_token_start++ - '0') * 10000000L;
909 1261 case 8: iv -= (*fs_token_start++ - '0') * 1000000L;
910 1891 case 7: iv -= (*fs_token_start++ - '0') * 100000L;
911 3781 case 6: iv -= (*fs_token_start++ - '0') * 10000L;
912 5671 case 5: iv -= (*fs_token_start++ - '0') * 1000L;
913 5671 case 4: iv -= (*fs_token_start++ - '0') * 100L;
914 5671 case 3: iv -= (*fs_token_start++ - '0') * 10L;
915 6301 case 2: iv -= (*fs_token_start++ - '0') * 1L;
916 6301 break;
917 0 default:
918 0 ▶ PANICf1(ps,fs,"Strange length for negative integer in switch: %d", ch);
Branch: 4 branches
BranchTrueFalseTotal
PANICf1(ps,fs,"Strange length for negative integer in switch: %d", ch); 0 0 0
PANICf1(ps,fs,"Strange length for negative integer in switch: %d", ch); 0 0 0
PANICf1(ps,fs,"Strange length for negative integer in switch: %d", ch); 0 0 0
PANICf1(ps,fs,"Strange length for negative integer in switch: %d", ch); 0 0 0
919 }
920 6301 fs_got= newSViv(iv);
921 } else {
922 0 goto MAKE_SV;
923 }
924 } else {
925 12818007 ▶ if (ch < 11 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ch < 11 ) { 12741777 76230 12818007
926 12741777 UV uv= 0;
927 12741777 switch (ch) {
928 62371 case 10: uv += (*fs_token_start++ - '0') * 1000000000L;
929 1531531 case 9: uv += (*fs_token_start++ - '0') * 100000000L;
930 2015371 case 8: uv += (*fs_token_start++ - '0') * 10000000L;
931 2108611 case 7: uv += (*fs_token_start++ - '0') * 1000000L;
932 2144521 case 6: uv += (*fs_token_start++ - '0') * 100000L;
933 2230201 case 5: uv += (*fs_token_start++ - '0') * 10000L;
934 2371321 case 4: uv += (*fs_token_start++ - '0') * 1000L;
935 2688844 case 3: uv += (*fs_token_start++ - '0') * 100L;
936 3057400 case 2: uv += (*fs_token_start++ - '0') * 10L;
937 12741777 case 1: uv += (*fs_token_start++ - '0') * 1L;
938 12741777 break;
939 0 default:
940 0 ▶ PANICf1(ps,fs,"Strange length for integer in switch: %d", ch);
Branch: 4 branches
BranchTrueFalseTotal
PANICf1(ps,fs,"Strange length for integer in switch: %d", ch); 0 0 0
PANICf1(ps,fs,"Strange length for integer in switch: %d", ch); 0 0 0
PANICf1(ps,fs,"Strange length for integer in switch: %d", ch); 0 0 0
PANICf1(ps,fs,"Strange length for integer in switch: %d", ch); 0 0 0
941 }
942 12741777 fs_got= newSVuv(uv);
943 } else {
944 76230 goto MAKE_SV;
945 }
946 }
947 12748078 goto GOT_SV;
948 }
949 6 case TOKEN_NV:
950 {
951 6 ▶ if (WANT_KEY(fs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (WANT_KEY(fs)) { 0 6 6
952 0 DONE_KEY_SIMPLE_break;
953 }
954 6 MAKE_SV:
955 76236 ▶ if (fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_got) { 0 76236 76236
956 0 ▶ ERROR(ps,fs,"Multiple objects in stream?");
Branch: 4 branches
BranchTrueFalseTotal
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
ERROR(ps,fs,"Multiple objects in stream?"); 0 0 0
957 }
958 76236 fs_got= newSVpvn(fs_token_start, ps_parse_ptr - fs_token_start);
959 24517844 GOT_SV:
960 24517855 ▶ while ( fs_refs > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( fs_refs > 0 ) { 11 24517844 24517855
961 11 fs_got= newRV_noinc((SV*)fs_got);
962 11 fs_refs--;
963 }
964 24517844 ▶ if (obj_char == '{') {
Branch: 1 branch
BranchTrueFalseTotal
if (obj_char == '{') { 12715339 11802505 24517844
965 HE *ent;
966 12715339 ▶ if (fs_key) {
Branch: 1 branch
BranchTrueFalseTotal
if (fs_key) { 12715332 7 12715339
967 12715332 ent= hv_common((HV *)fs_thing, NULL, fs_key, fs_key_len, 0, HV_FETCH_LVALUE, NULL, 0);
968 7 ▶ } else if (fs_got_key) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (fs_got_key) { 7 0 7
969 7 ent= hv_common((HV *)fs_thing, fs_got_key, NULL, 0, 0, HV_FETCH_LVALUE, NULL, 0);
970 7 SvREFCNT_dec(fs_got_key);
971 7 fs_got_key= 0;
972 } else {
973 0 ▶ PANIC(ps,fs,"got something to store, but no key?");
Branch: 4 branches
BranchTrueFalseTotal
PANIC(ps,fs,"got something to store, but no key?"); 0 0 0
PANIC(ps,fs,"got something to store, but no key?"); 0 0 0
PANIC(ps,fs,"got something to store, but no key?"); 0 0 0
PANIC(ps,fs,"got something to store, but no key?"); 0 0 0
974 }
975 12715339 ▶ if (!ent) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ent) { 0 12715339 12715339
976 0 ▶ PANIC(ps,fs,"failed to store in hash");
Branch: 4 branches
BranchTrueFalseTotal
PANIC(ps,fs,"failed to store in hash"); 0 0 0
PANIC(ps,fs,"failed to store in hash"); 0 0 0
PANIC(ps,fs,"failed to store in hash"); 0 0 0
PANIC(ps,fs,"failed to store in hash"); 0 0 0
977 }
978 12715339 ▶ if (SvOK(HeVAL(ent))) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(HeVAL(ent))) { 0 12715339 12715339
979 0 ▶ ERRORf2(ps,fs,"duplicate key '%.*s' is illegal", (int)fs_key_len, fs_key);
Branch: 4 branches
BranchTrueFalseTotal
ERRORf2(ps,fs,"duplicate key '%.*s' is illegal", (int)fs_key_len, fs_key); 0 0 0
ERRORf2(ps,fs,"duplicate key '%.*s' is illegal", (int)fs_key_len, fs_key); 0 0 0
ERRORf2(ps,fs,"duplicate key '%.*s' is illegal", (int)fs_key_len, fs_key); 0 0 0
ERRORf2(ps,fs,"duplicate key '%.*s' is illegal", (int)fs_key_len, fs_key); 0 0 0
980 } else {
981 12715339 SvREFCNT_dec(HeVAL(ent));
982 12715339 HeVAL(ent)= fs_got;
983 }
984 12715339 fs_key= 0;
985 12715339 fs_got= 0;
986 12715339 WANT_KEY_on(fs);
987 12715339 ALLOW_COMMA_on(fs);
988 11802505 ▶ } else if (obj_char == '[') {
Branch: 1 branch
BranchTrueFalseTotal
} else if (obj_char == '[') { 11644954 157551 11802505
989 /* av_push does not return anything - a little worrying? maybe better to av_store()*/
990 11644954 av_push((AV*)fs_thing, fs_got);
991 11644954 fs_got= 0;
992 11644954 ALLOW_COMMA_on(fs);
993 } else {
994 157551 return fs_got;
995 }
996 24360293 break;
997 }
998 0 default:
999 0 ▶ PANICf2(ps,fs,"unhandled fs_token %d '%s'",
Branch: 4 branches
BranchTrueFalseTotal
PANICf2(ps,fs,"unhandled fs_token %d '%s'", 0 0 0
PANICf2(ps,fs,"unhandled fs_token %d '%s'", 0 0 0
PANICf2(ps,fs,"unhandled fs_token %d '%s'", 0 0 0
PANICf2(ps,fs,"unhandled fs_token %d '%s'", 0 0 0
1000 fs_token, token_name[fs_token<TOKEN_UNKNOWN ? fs_token : TOKEN_UNKNOWN]);
1001 }
1002 } /* while */
1003 5 ▶ if ( ps_parse_ptr < ps_string_end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ps_parse_ptr < ps_string_end ) { 0 5 5
1004 0 ▶ PANIC(ps,fs,"fallen off the loop with text left");
Branch: 4 branches
BranchTrueFalseTotal
PANIC(ps,fs,"fallen off the loop with text left"); 0 0 0
PANIC(ps,fs,"fallen off the loop with text left"); 0 0 0
PANIC(ps,fs,"fallen off the loop with text left"); 0 0 0
PANIC(ps,fs,"fallen off the loop with text left"); 0 0 0
1005 5 ▶ } else if (!fs_got) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (!fs_got) { 5 0 5
1006 5 ▶ ERRORf1(ps,fs,
Branch: 6 branches
BranchTrueFalseTotal
ERRORf1(ps,fs, 2 3 5
ERRORf1(ps,fs, 2 0 2
ERRORf1(ps,fs, 5 0 5
ERRORf1(ps,fs, 0 5 5
ERRORf1(ps,fs, 0 5 5
ERRORf1(ps,fs, 5 0 5
1007 "unterminated %s constructor", obj_char == '{' ? "HASH" : obj_char == '[' ? "ARRAY" : "UNKNOWN");
1008 } else {
1009 0 return fs_got;
1010 }
1011 }
1012  
1013  
1014 MODULE = Data::Undump PACKAGE = Data::Undump
1015  
1016 PROTOTYPES: DISABLE
1017  
1018  
1019 SV *
1020 undump (sv)
1021 SV *sv
1022 CODE:
1023 158196 RETVAL = undump(aTHX_ sv);
1024 OUTPUT: RETVAL
1025  
↑ Summary blib/lib/Data/Undump.pm »