perl_syck.h

filter: Statementstmt 92.4% 787 / 851 Branchbran 68.0% 558 / 820 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 80.4% 1345 / 1671 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« syck_.c ↑ Summary perl_common.h »
1 /* Implementation-specific variables */
2 #undef PACKAGE_NAME
3 #undef NULL_LITERAL
4 #undef NULL_LITERAL_LENGTH
5 #undef SCALAR_NUMBER
6 #undef SCALAR_STRING
7 #undef SCALAR_QUOTED
8 #undef SCALAR_UTF8
9 #undef SEQ_NONE
10 #undef MAP_NONE
11 #undef IS_UTF8
12 #undef TYPE_IS_NULL
13 #undef OBJOF
14 #undef PERL_SYCK_PARSER_HANDLER
15 #undef PERL_SYCK_EMITTER_HANDLER
16 #undef PERL_SYCK_INDENT_LEVEL
17 #undef PERL_SYCK_MARK_EMITTER
18 #undef PERL_SYCK_EMITTER_MARK_NODE_FLAGS
19  
20 #ifdef YAML_IS_JSON
21 # define PACKAGE_NAME "JSON::Syck"
22 # define NULL_LITERAL "null"
23 # define NULL_LITERAL_LENGTH 4
24 # define SCALAR_NUMBER scalar_none
25 # define PERL_SYCK_EMITTER_MARK_NODE_FLAGS EMITTER_MARK_NODE_FLAG_PERMIT_DUPLICATE_NODES
26 int json_max_depth = 512;
27 char json_quote_char = '"';
28 static enum scalar_style json_quote_style = scalar_2quote;
29 # define SCALAR_STRING json_quote_style
30 # define SCALAR_QUOTED json_quote_style
31 # define SCALAR_UTF8 scalar_fold
32 # define SEQ_NONE seq_inline
33 # define MAP_NONE map_inline
34 # define IS_UTF8(x) TRUE
35 # define TYPE_IS_NULL(x) ((x == NULL) || strEQ( x, "str" ))
36 # define OBJOF(a) (a)
37 # define PERL_SYCK_PARSER_HANDLER json_syck_parser_handler
38 # define PERL_SYCK_EMITTER_HANDLER json_syck_emitter_handler
39 # define PERL_SYCK_MARK_EMITTER json_syck_mark_emitter
40 # define PERL_SYCK_INDENT_LEVEL 0
41 #else
42 # define PACKAGE_NAME "YAML::Syck"
43 # define REGEXP_LITERAL "REGEXP"
44 # define REGEXP_LITERAL_LENGTH 6
45 # define REF_LITERAL "="
46 # define REF_LITERAL_LENGTH 1
47 # define NULL_LITERAL "~"
48 # define NULL_LITERAL_LENGTH 1
49 # define SCALAR_NUMBER scalar_none
50 # define PERL_SYCK_EMITTER_MARK_NODE_FLAGS 0
51 static enum scalar_style yaml_quote_style = scalar_none;
52 # define SCALAR_STRING yaml_quote_style
53 # define SCALAR_QUOTED scalar_1quote
54 # define SCALAR_UTF8 scalar_fold
55 # define SEQ_NONE seq_none
56 # define MAP_NONE map_none
57 #ifdef SvUTF8
58 # define IS_UTF8(x) (SvUTF8(x))
59 #else
60 # define IS_UTF8(x) (FALSE)
61 #endif
62 # define TYPE_IS_NULL(x) ((x == NULL) || strEQ( x, "str" ))
63 # define OBJOF(a) (*tag ? tag : a)
64 # define PERL_SYCK_PARSER_HANDLER yaml_syck_parser_handler
65 # define PERL_SYCK_EMITTER_HANDLER yaml_syck_emitter_handler
66 # define PERL_SYCK_MARK_EMITTER yaml_syck_mark_emitter
67 # define PERL_SYCK_INDENT_LEVEL 2
68 #endif
69  
70 #define TRACK_OBJECT(sv) (av_push(((struct parser_xtra *)p->bonus)->objects, sv))
71 #define USE_OBJECT(sv) (SvREFCNT_inc(sv))
72 #define IS_SIGN(c) ((c) == '-' || (c) == '+')
73  
74 #ifndef YAML_IS_JSON
75  
76 #ifndef SvRV_set /* prior to 5.8.7; thx charsbar! */
77 #define SvRV_set(sv, val) \
78 STMT_START { \
79 (SvRV(sv) = (val)); } STMT_END
80 #endif
81  
82 static const char *
83 9360984 is_bad_alias_object( SV *sv ) {
84 SV *hv, **psv;
85  
86 9360984 ▶ if (! sv_isobject(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (! sv_isobject(sv)) 9360967 17 9360984
87 9360967 return NULL;
88  
89 17 hv = SvRV(sv);
90 17 ▶ if (! strnEQ(sv_reftype(hv, 1), "YAML::Syck::BadAlias", 20-1))
Branch: 1 branch
BranchTrueFalseTotal
if (! strnEQ(sv_reftype(hv, 1), "YAML::Syck::BadAlias", 20-1)) 7 10 17
91 7 return NULL;
92  
93 10 psv = hv_fetch((HV *) hv, "name", 4, 0);
94 10 ▶ if (! psv)
Branch: 1 branch
BranchTrueFalseTotal
if (! psv) 0 10 10
95 0 return NULL;
96  
97 10 return SvPVX(*psv);
98 }
99  
100 static void
101 10 register_bad_alias( SyckParser *p, const char *anchor, SV *sv ) {
102 HV *map;
103 SV **pref_av, *new_rvav;
104 AV *rvs;
105  
106 10 map = ((struct parser_xtra *)p->bonus)->bad_anchors;
107 10 pref_av = hv_fetch(map, anchor, strlen(anchor), 0);
108 10 ▶ if (! pref_av) {
Branch: 1 branch
BranchTrueFalseTotal
if (! pref_av) { 5 5 10
109 5 new_rvav = newRV_noinc((SV *) newAV());
110 5 hv_store(map, anchor, strlen(anchor), new_rvav, 0);
111 5 pref_av = &new_rvav;
112 }
113 10 rvs = (AV *) SvRV(*pref_av);
114  
115 10 SvREFCNT_inc(sv);
116 10 av_push(rvs, sv);
117 10 }
118  
119 static void
120 7 resolve_bad_alias( SyckParser *p, const char *anchor, SV *sv ) {
121 HV *map;
122 SV **pref_av, *entity;
123 AV *rvs;
124 I32 len, i;
125  
126 7 entity = SvRV(sv);
127  
128 7 map = ((struct parser_xtra *)p->bonus)->bad_anchors;
129 7 pref_av = hv_fetch(map, anchor, strlen(anchor), 0);
130 7 ▶ if (! pref_av)
Branch: 1 branch
BranchTrueFalseTotal
if (! pref_av) 2 5 7
131 2 return;
132  
133 5 rvs = (AV *) SvRV(*pref_av);
134 5 len = av_len(rvs)+1;
135 15 ▶ for (i = 0; i < len; i ++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i ++) { 10 5 15
136 10 SV **prv = av_fetch(rvs, i, 0);
137 10 ▶ if (prv) {
Branch: 1 branch
BranchTrueFalseTotal
if (prv) { 10 0 10
138 10 SvREFCNT_dec(SvRV(*prv));
139 10 SvRV_set(*prv, entity);
140 10 SvREFCNT_inc(entity);
141 }
142 }
143 5 av_clear(rvs);
144 }
145  
146 #endif
147  
148 SYMID
149 #ifdef YAML_IS_JSON
150 369 json_syck_parser_handler
151 #else
152 18723852 yaml_syck_parser_handler
153 #endif
154 (SyckParser *p, SyckNode *n) {
155 18724221 SV *sv = NULL;
156 AV *seq;
157 HV *map;
158 long i;
159 18724221 char *id = n->type_id;
160 #ifndef YAML_IS_JSON
161 18723852 struct parser_xtra *bonus = (struct parser_xtra *)p->bonus;
162 18723852 bool load_code = bonus->load_code;
163 18723852 bool load_blessed = bonus->load_blessed;
164 #endif
165  
166 18724285 ▶ while (id && (*id == '!')) { id++; }
Branch: 4 branches
BranchTrueFalseTotal
while (id && (*id == '!')) { id++; } 18721425 2491 18723916
while (id && (*id == '!')) { id++; } 64 18721361 18721425
while (id && (*id == '!')) { id++; } 297 72 369
while (id && (*id == '!')) { id++; } 0 297 297
167  
168 18724221 switch (n->kind) {
169 18722836 case syck_str_kind:
170 18722836 ▶ if (TYPE_IS_NULL(id)) {
Branch: 4 branches
BranchTrueFalseTotal
if (TYPE_IS_NULL(id)) { 18721313 1226 18722539
if (TYPE_IS_NULL(id)) { 18720491 822 18721313
if (TYPE_IS_NULL(id)) { 297 0 297
if (TYPE_IS_NULL(id)) { 202 95 297
171 37443838 ▶ if (strnEQ( n->data.str->ptr, NULL_LITERAL, 1+NULL_LITERAL_LENGTH)
Branch: 2 branches
BranchTrueFalseTotal
if (strnEQ( n->data.str->ptr, NULL_LITERAL, 1+NULL_LITERAL_LENGTH) 9 18721708 18721717
if (strnEQ( n->data.str->ptr, NULL_LITERAL, 1+NULL_LITERAL_LENGTH) 0 202 202
172 9 ▶ && (n->data.str->style == scalar_plain)) {
Branch: 2 branches
BranchTrueFalseTotal
&& (n->data.str->style == scalar_plain)) { 8 1 9
&& (n->data.str->style == scalar_plain)) { 0 0 0
173 8 sv = newSV(0);
174 }
175 else {
176 18721911 sv = newSVpvn(n->data.str->ptr, n->data.str->len);
177 18721911 ▶ CHECK_UTF8;
Branch: 6 branches
BranchTrueFalseTotal
CHECK_UTF8; 274 18721435 18721709
CHECK_UTF8; 274 0 274
CHECK_UTF8; 270 4 274
CHECK_UTF8; 50 152 202
CHECK_UTF8; 44 6 50
CHECK_UTF8; 44 0 44
178 }
179 917 ▶ } else if (strEQ( id, "null" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "null" )) { 6 816 822
} else if (strEQ( id, "null" )) { 20 75 95
180 26 sv = newSV(0);
181 891 ▶ } else if (strEQ( id, "bool#yes" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "bool#yes" )) { 13 803 816
} else if (strEQ( id, "bool#yes" )) { 0 75 75
182 13 sv = newSVsv(&PL_sv_yes);
183 878 ▶ } else if (strEQ( id, "bool#no" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "bool#no" )) { 23 780 803
} else if (strEQ( id, "bool#no" )) { 0 75 75
184 23 sv = newSVsv(&PL_sv_no);
185 855 ▶ } else if (strEQ( id, "default" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "default" )) { 2 778 780
} else if (strEQ( id, "default" )) { 0 75 75
186 2 sv = newSVpvn(n->data.str->ptr, n->data.str->len);
187 2 ▶ CHECK_UTF8;
Branch: 6 branches
BranchTrueFalseTotal
CHECK_UTF8; 0 2 2
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
188 853 ▶ } else if (strEQ( id, "float#base60" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "float#base60" )) { 11 767 778
} else if (strEQ( id, "float#base60" )) { 0 75 75
189 char *ptr, *end;
190 11 UV sixty = 1;
191 11 NV total = 0.0;
192 int is_neg;
193 11 syck_str_blow_away_commas( n );
194 11 ptr = n->data.str->ptr;
195 11 is_neg = (*ptr == '-');
196 11 ▶ if (*ptr == '-' || *ptr == '+') ptr++;
Branch: 4 branches
BranchTrueFalseTotal
if (*ptr == '-' || *ptr == '+') ptr++; 7 4 11
if (*ptr == '-' || *ptr == '+') ptr++; 1 6 7
if (*ptr == '-' || *ptr == '+') ptr++; 0 0 0
if (*ptr == '-' || *ptr == '+') ptr++; 0 0 0
197 11 end = n->data.str->ptr + n->data.str->len;
198 39 ▶ while ( end > ptr )
Branch: 2 branches
BranchTrueFalseTotal
while ( end > ptr ) 28 11 39
while ( end > ptr ) 0 0 0
199 {
200 28 NV bnum = 0;
201 28 char *colon = end - 1;
202 80 ▶ while ( colon > ptr && *colon != ':' )
Branch: 4 branches
BranchTrueFalseTotal
while ( colon > ptr && *colon != ':' ) 69 11 80
while ( colon > ptr && *colon != ':' ) 52 17 69
while ( colon > ptr && *colon != ':' ) 0 0 0
while ( colon > ptr && *colon != ':' ) 0 0 0
203 {
204 52 colon--;
205 }
206 28 ▶ if ( *colon == ':' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( *colon == ':' ) { 17 11 28
if ( *colon == ':' ) { 0 0 0
207 17 *colon = '\0';
208 17 bnum = Atof( colon + 1 );
209 17 end = colon;
210 } else {
211 11 bnum = Atof( ptr );
212 11 end = ptr;
213 }
214 28 total += bnum * sixty;
215 28 sixty *= 60;
216 }
217 11 ▶ sv = newSVnv((is_neg && total != 0.0) ? -total : total);
Branch: 4 branches
BranchTrueFalseTotal
sv = newSVnv((is_neg && total != 0.0) ? -total : total); 4 7 11
sv = newSVnv((is_neg && total != 0.0) ? -total : total); 3 1 4
sv = newSVnv((is_neg && total != 0.0) ? -total : total); 0 0 0
sv = newSVnv((is_neg && total != 0.0) ? -total : total); 0 0 0
218 #ifdef NV_NAN
219 842 ▶ } else if (strEQ( id, "float#nan" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "float#nan" )) { 3 764 767
} else if (strEQ( id, "float#nan" )) { 0 75 75
220 3 sv = newSVnv(NV_NAN);
221 #endif
222 #ifdef NV_INF
223 839 ▶ } else if (strEQ( id, "float#inf" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "float#inf" )) { 4 760 764
} else if (strEQ( id, "float#inf" )) { 0 75 75
224 4 sv = newSVnv(NV_INF);
225 835 ▶ } else if (strEQ( id, "float#neginf" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "float#neginf" )) { 3 757 760
} else if (strEQ( id, "float#neginf" )) { 0 75 75
226 3 sv = newSVnv(-NV_INF);
227 #endif
228 832 ▶ } else if (strnEQ( id, "float", 5 )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strnEQ( id, "float", 5 )) { 7 750 757
} else if (strnEQ( id, "float", 5 )) { 0 75 75
229 NV f;
230 7 syck_str_blow_away_commas( n );
231 7 f = Atof( n->data.str->ptr );
232 7 sv = newSVnv( f );
233 825 ▶ } else if (strEQ( id, "int#base60" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "int#base60" )) { 18 732 750
} else if (strEQ( id, "int#base60" )) { 0 75 75
234 char *ptr, *end;
235 18 UV sixty = 1;
236 18 UV total = 0;
237 int is_neg;
238 18 syck_str_blow_away_commas( n );
239 18 ptr = n->data.str->ptr;
240 18 is_neg = (*ptr == '-');
241 18 ▶ if (is_neg) ptr++;
Branch: 2 branches
BranchTrueFalseTotal
if (is_neg) ptr++; 5 13 18
if (is_neg) ptr++; 0 0 0
242 18 end = n->data.str->ptr + n->data.str->len;
243 65 ▶ while ( end > ptr )
Branch: 2 branches
BranchTrueFalseTotal
while ( end > ptr ) 47 18 65
while ( end > ptr ) 0 0 0
244 {
245 47 long bnum = 0;
246 47 char *colon = end - 1;
247 89 ▶ while ( colon > ptr && *colon != ':' )
Branch: 4 branches
BranchTrueFalseTotal
while ( colon > ptr && *colon != ':' ) 71 18 89
while ( colon > ptr && *colon != ':' ) 42 29 71
while ( colon > ptr && *colon != ':' ) 0 0 0
while ( colon > ptr && *colon != ':' ) 0 0 0
248 {
249 42 colon--;
250 }
251 47 ▶ if ( *colon == ':' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( *colon == ':' ) { 29 18 47
if ( *colon == ':' ) { 0 0 0
252 29 *colon = '\0';
253 29 bnum = strtol( colon + 1, NULL, 10 );
254 29 end = colon;
255 } else {
256 18 bnum = strtol( ptr, NULL, 10 );
257 18 end = ptr;
258 }
259 47 total += bnum * sixty;
260 47 sixty *= 60;
261 }
262 18 ▶ if (is_neg)
Branch: 2 branches
BranchTrueFalseTotal
if (is_neg) 5 13 18
if (is_neg) 0 0 0
263 5 sv = newSViv(-(IV)total);
264 else
265 13 sv = newSVuv(total);
266 807 ▶ } else if (strEQ( id, "int#hex" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "int#hex" )) { 16 716 732
} else if (strEQ( id, "int#hex" )) { 0 75 75
267 16 I32 flags = 0;
268 16 char *ptr = n->data.str->ptr;
269 16 STRLEN len = n->data.str->len;
270 16 int is_neg = (*ptr == '-');
271 16 syck_str_blow_away_commas( n );
272 16 ▶ if (IS_SIGN(*ptr)) { ptr++; len--; }
Branch: 4 branches
BranchTrueFalseTotal
if (IS_SIGN(*ptr)) { ptr++; len--; } 12 4 16
if (IS_SIGN(*ptr)) { ptr++; len--; } 4 8 12
if (IS_SIGN(*ptr)) { ptr++; len--; } 0 0 0
if (IS_SIGN(*ptr)) { ptr++; len--; } 0 0 0
273 16 UV uv = grok_hex( ptr, &len, &flags, NULL);
274 16 if (is_neg)
275 4 sv = newSViv(-(IV)uv);
276 else
277 12 sv = newSVuv(uv);
278 791 ▶ } else if (strEQ( id, "int#oct" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "int#oct" )) { 13 703 716
} else if (strEQ( id, "int#oct" )) { 0 75 75
279 13 I32 flags = 0;
280 13 char *ptr = n->data.str->ptr;
281 13 STRLEN len = n->data.str->len;
282 13 int is_neg = (*ptr == '-');
283 13 syck_str_blow_away_commas( n );
284 13 ▶ if (IS_SIGN(*ptr)) { ptr++; len--; }
Branch: 4 branches
BranchTrueFalseTotal
if (IS_SIGN(*ptr)) { ptr++; len--; } 10 3 13
if (IS_SIGN(*ptr)) { ptr++; len--; } 4 6 10
if (IS_SIGN(*ptr)) { ptr++; len--; } 0 0 0
if (IS_SIGN(*ptr)) { ptr++; len--; } 0 0 0
285 13 UV uv = grok_oct( ptr, &len, &flags, NULL);
286 13 if (is_neg)
287 3 sv = newSViv(-(IV)uv);
288 else
289 10 sv = newSVuv(uv);
290 778 ▶ } else if (strEQ( id, "int" ) ) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "int" ) ) { 42 661 703
} else if (strEQ( id, "int" ) ) { 75 0 75
291 UV uv;
292 int flags;
293  
294 117 syck_str_blow_away_commas( n );
295 117 flags = grok_number( n->data.str->ptr, n->data.str->len, &uv);
296  
297 117 if (flags == IS_NUMBER_IN_UV) {
298 111 ▶ if (uv <= IV_MAX) {
Branch: 2 branches
BranchTrueFalseTotal
if (uv <= IV_MAX) { 37 0 37
if (uv <= IV_MAX) { 74 0 74
299 111 sv = newSViv(uv);
300 }
301 else {
302 0 sv = newSVuv(uv);
303 }
304 }
305 6 ▶ else if ((flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) && (uv <= (UV) IV_MIN)) {
Branch: 4 branches
BranchTrueFalseTotal
else if ((flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) && (uv <= (UV) IV_MIN)) { 5 0 5
else if ((flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) && (uv <= (UV) IV_MIN)) { 5 0 5
else if ((flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) && (uv <= (UV) IV_MIN)) { 1 0 1
else if ((flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)) && (uv <= (UV) IV_MIN)) { 1 0 1
306 6 sv = newSViv(-(IV)uv);
307 }
308 else {
309 0 sv = newSVnv(Atof( n->data.str->ptr ));
310 }
311 661 ▶ } else if (strEQ( id, "binary" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "binary" )) { 201 460 661
} else if (strEQ( id, "binary" )) { 0 0 0
312 201 long len = 0;
313 201 char *blob = syck_base64dec(n->data.str->ptr, n->data.str->len, &len);
314 201 sv = newSVpv(blob, len);
315 201 syck_base64_free(blob);
316 #ifndef YAML_IS_JSON
317 #ifdef PERL_LOADMOD_NOIMPORT
318 673 ▶ } else if (strEQ(id, "perl/code") || strnEQ(id, "perl/code:", 10)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ(id, "perl/code") || strnEQ(id, "perl/code:", 10)) { 459 1 460
} else if (strEQ(id, "perl/code") || strnEQ(id, "perl/code:", 10)) { 223 236 459
319 SV *cv;
320 SV *sub;
321 224 char *pkg = id + 10;
322  
323 224 ▶ if (load_code) {
Branch: 1 branch
BranchTrueFalseTotal
if (load_code) { 220 4 224
324 SV *text;
325  
326 /* This code is copypasted from Storable.xs */
327  
328 /*
329 * prepend "sub " to the source
330 */
331  
332 220 text = newSVpvn(n->data.str->ptr, n->data.str->len);
333  
334 220 sub = newSVpvn("sub ", 4);
335 220 sv_catpv(sub, SvPV_nolen(text)); /* XXX no sv_catsv! */
336 220 SvREFCNT_dec(text);
337 } else {
338 4 sub = newSVpvn("sub {}", 6);
339 }
340  
341 224 ENTER;
342 224 SAVETMPS;
343  
344 224 sv_2mortal(sub);
345  
346 224 cv = eval_pv(SvPV_nolen(sub), FALSE);
347  
348 224 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 224 0 224
if (SvTRUE(ERRSV)) { 11 213 224
349 11 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 11 0 11
350 11 LEAVE;
351 22 ▶ croak("code %s did not evaluate to a subroutine reference\n", SvPV_nolen(ERRSV));
Branch: 1 branch
BranchTrueFalseTotal
croak("code %s did not evaluate to a subroutine reference\n", SvPV_nolen(ERRSV)); 11 0 11
352 }
353  
354 213 ▶ if (cv && SvROK(cv) && SvTYPE(SvRV(cv)) == SVt_PVCV) {
Branch: 3 branches
BranchTrueFalseTotal
if (cv && SvROK(cv) && SvTYPE(SvRV(cv)) == SVt_PVCV) { 213 0 213
if (cv && SvROK(cv) && SvTYPE(SvRV(cv)) == SVt_PVCV) { 213 0 213
if (cv && SvROK(cv) && SvTYPE(SvRV(cv)) == SVt_PVCV) { 213 0 213
355 213 sv = cv;
356 }
357 else {
358 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
359 0 LEAVE;
360 0 croak("code %s did not evaluate to a subroutine reference\n", SvPV_nolen(sub));
361 }
362  
363 213 SvREFCNT_inc(sv); /* prevent FREETMPS from freeing the mortal cv */
364  
365 213 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 213 0 213
366 213 LEAVE;
367  
368 213 ▶ if ( load_blessed && (*(pkg - 1) != '\0') && (*pkg != '\0') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( load_blessed && (*(pkg - 1) != '\0') && (*pkg != '\0') ) { 8 205 213
if ( load_blessed && (*(pkg - 1) != '\0') && (*pkg != '\0') ) { 7 1 8
if ( load_blessed && (*(pkg - 1) != '\0') && (*pkg != '\0') ) { 4 3 7
369 4 sv_bless(sv, gv_stashpv(pkg, TRUE));
370 }
371  
372 /* END Storable */
373  
374 236 ▶ } else if (strnEQ( n->data.str->ptr, REF_LITERAL, 1+REF_LITERAL_LENGTH)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (strnEQ( n->data.str->ptr, REF_LITERAL, 1+REF_LITERAL_LENGTH)) { 4 232 236
375 /* type tag in a scalar ref */
376 4 char *id_copy = savepv(id);
377 4 char *lang = id_copy;
378 4 char *type = strpbrk(id_copy, "/:");
379 4 ▶ if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; }
Branch: 2 branches
BranchTrueFalseTotal
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 2 2 4
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 0 2 2
380  
381 4 ▶ if (lang == NULL || (strEQ(lang, "perl"))) {
Branch: 2 branches
BranchTrueFalseTotal
if (lang == NULL || (strEQ(lang, "perl"))) { 4 0 4
if (lang == NULL || (strEQ(lang, "perl"))) { 2 2 4
382 2 ▶ if (type != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (type != NULL) { 1 1 2
383 1 sv = newSVpv(type, 0);
384 } else {
385 /* Tag has no type component (e.g. "!perl =") —
386 * fall back to raw scalar content */
387 1 sv = newSVpvn(n->data.str->ptr, n->data.str->len);
388 1 ▶ CHECK_UTF8;
Branch: 3 branches
BranchTrueFalseTotal
CHECK_UTF8; 0 1 1
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
389 }
390 }
391 else {
392 2 ▶ sv = newSVpv((type == NULL) ? lang : form("%s::%s", lang, type), 0);
Branch: 1 branch
BranchTrueFalseTotal
sv = newSVpv((type == NULL) ? lang : form("%s::%s", lang, type), 0); 1 1 2
393 }
394 4 Safefree(id_copy);
395 441 ▶ } else if ( strEQ( id, "perl/scalar" ) || strnEQ( id, "perl/scalar:", 12 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
} else if ( strEQ( id, "perl/scalar" ) || strnEQ( id, "perl/scalar:", 12 ) ) { 30 202 232
} else if ( strEQ( id, "perl/scalar" ) || strnEQ( id, "perl/scalar:", 12 ) ) { 7 23 30
396 209 char *pkg = id + 12;
397  
398 209 ▶ if (strnEQ( n->data.str->ptr, NULL_LITERAL, 1+NULL_LITERAL_LENGTH)
Branch: 1 branch
BranchTrueFalseTotal
if (strnEQ( n->data.str->ptr, NULL_LITERAL, 1+NULL_LITERAL_LENGTH) 2 207 209
399 2 ▶ && (n->data.str->style == scalar_plain)) {
Branch: 1 branch
BranchTrueFalseTotal
&& (n->data.str->style == scalar_plain)) { 2 0 2
400 2 sv = newSV(0);
401 }
402 else {
403 207 sv = newSVpvn(n->data.str->ptr, n->data.str->len);
404 207 ▶ CHECK_UTF8;
Branch: 3 branches
BranchTrueFalseTotal
CHECK_UTF8; 0 207 207
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
405 }
406  
407 209 sv = newRV_noinc(sv);
408  
409 209 ▶ if ( load_blessed && (*(pkg - 1) != '\0') && (*pkg != '\0') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( load_blessed && (*(pkg - 1) != '\0') && (*pkg != '\0') ) { 207 2 209
if ( load_blessed && (*(pkg - 1) != '\0') && (*pkg != '\0') ) { 5 202 207
if ( load_blessed && (*(pkg - 1) != '\0') && (*pkg != '\0') ) { 5 0 5
410 5 sv_bless(sv, gv_stashpv(id + 12, TRUE));
411 }
412  
413 30 ▶ } else if ( (strEQ(id, "perl/regexp") || strnEQ( id, "perl/regexp:", 12 ) ) ) {
Branch: 2 branches
BranchTrueFalseTotal
} else if ( (strEQ(id, "perl/regexp") || strnEQ( id, "perl/regexp:", 12 ) ) ) { 20 3 23
} else if ( (strEQ(id, "perl/regexp") || strnEQ( id, "perl/regexp:", 12 ) ) ) { 4 16 20
414 7 dSP;
415 7 SV *val = newSVpvn(n->data.str->ptr, n->data.str->len);
416 7 char *id_copy = savepv(id);
417 7 char *lang = id_copy;
418 7 char *type = strpbrk(id_copy, "/:");
419 7 ▶ if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; }
Branch: 2 branches
BranchTrueFalseTotal
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 7 0 7
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 0 7 7
420  
421 7 ENTER;
422 7 SAVETMPS;
423 7 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 7 7
424 7 ▶ XPUSHs(val);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(val); 0 7 7
425 7 PUTBACK;
426 7 call_pv("YAML::Syck::__qr_helper", G_SCALAR);
427 7 SPAGAIN;
428  
429 7 sv = newSVsv(POPs);
430  
431 7 PUTBACK;
432 7 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 7 0 7
433 7 LEAVE;
434  
435 /* bless it if necessary */
436 7 ▶ if ( type != NULL && strnEQ(type, "regexp:", 7)) {
Branch: 2 branches
BranchTrueFalseTotal
if ( type != NULL && strnEQ(type, "regexp:", 7)) { 7 0 7
if ( type != NULL && strnEQ(type, "regexp:", 7)) { 4 3 7
437 /* !perl/regexp:Foo::Bar blesses into Foo::Bar */
438 4 type += 7;
439 }
440  
441 7 ▶ if ( load_blessed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( load_blessed ) { 6 1 7
442 6 ▶ if (lang == NULL || (strEQ(lang, "perl"))) {
Branch: 2 branches
BranchTrueFalseTotal
if (lang == NULL || (strEQ(lang, "perl"))) { 6 0 6
if (lang == NULL || (strEQ(lang, "perl"))) { 6 0 6
443 /* !perl/regexp on it's own causes no blessing */
444 6 ▶ if ( (type != NULL) && strNE(type, "regexp") && (*type != '\0')) {
Branch: 3 branches
BranchTrueFalseTotal
if ( (type != NULL) && strNE(type, "regexp") && (*type != '\0')) { 6 0 6
if ( (type != NULL) && strNE(type, "regexp") && (*type != '\0')) { 3 3 6
if ( (type != NULL) && strNE(type, "regexp") && (*type != '\0')) { 3 0 3
445 3 sv_bless(sv, gv_stashpv(type, TRUE));
446 }
447 }
448 else {
449 0 ▶ sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE));
Branch: 1 branch
BranchTrueFalseTotal
sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE)); 0 0 0
450 }
451 }
452 7 Safefree(id_copy);
453 #endif /* PERL_LOADMOD_NOIMPORT */
454 #endif /* !YAML_IS_JSON */
455 } else {
456 /* croak("unknown node type: %s", id); */
457 16 sv = newSVpvn(n->data.str->ptr, n->data.str->len);
458 16 ▶ CHECK_UTF8;
Branch: 6 branches
BranchTrueFalseTotal
CHECK_UTF8; 0 16 16
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
CHECK_UTF8; 0 0 0
459 }
460 18722825 break;
461  
462 115 case syck_seq_kind:
463 /* load the seq into a new AV and place a ref to it in the SV */
464 115 seq = newAV();
465 377 ▶ for (i = 0; i < n->data.list->idx; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n->data.list->idx; i++) { 198 87 285
for (i = 0; i < n->data.list->idx; i++) { 64 28 92
466 262 SV *a = perl_syck_lookup_sym(p, syck_seq_read(n, i));
467 #ifndef YAML_IS_JSON
468 const char *forward_anchor;
469  
470 198 a = sv_2mortal(newSVsv(a));
471 198 forward_anchor = is_bad_alias_object(a);
472 198 ▶ if (forward_anchor)
Branch: 1 branch
BranchTrueFalseTotal
if (forward_anchor) 0 198 198
473 0 register_bad_alias(p, forward_anchor, a);
474 #endif
475 262 av_push(seq, a);
476 262 USE_OBJECT(a);
477 }
478 /* create the ref to the new array in the sv */
479 115 sv = newRV_noinc((SV*)seq);
480 #ifndef YAML_IS_JSON
481  
482 87 ▶ if (id) {
Branch: 1 branch
BranchTrueFalseTotal
if (id) { 5 82 87
483 /* bless it if necessary */
484 5 char *id_copy = savepv(id);
485 5 char *lang = id_copy;
486 5 char *type = strpbrk(id_copy, "/:");
487 5 ▶ if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; }
Branch: 2 branches
BranchTrueFalseTotal
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 5 0 5
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 0 5 5
488  
489 5 ▶ if ( type != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( type != NULL ) { 5 0 5
490 5 ▶ if (strnEQ(type, "array:", 6)) {
Branch: 1 branch
BranchTrueFalseTotal
if (strnEQ(type, "array:", 6)) { 4 1 5
491 /* !perl/array:Foo::Bar blesses into Foo::Bar */
492 4 type += 6;
493 }
494  
495 /* FIXME deprecated - here compatibility with @Foo::Bar style blessing */
496 5 ▶ while ( *type == '@' ) { type++; }
Branch: 1 branch
BranchTrueFalseTotal
while ( *type == '@' ) { type++; } 0 5 5
497 }
498  
499 5 ▶ if (load_blessed) {
Branch: 1 branch
BranchTrueFalseTotal
if (load_blessed) { 4 1 5
500 4 ▶ if (lang == NULL || (strEQ(lang, "perl"))) {
Branch: 2 branches
BranchTrueFalseTotal
if (lang == NULL || (strEQ(lang, "perl"))) { 4 0 4
if (lang == NULL || (strEQ(lang, "perl"))) { 4 0 4
501 /* !perl/array on it's own causes no blessing */
502 4 ▶ if ( (type != NULL) && strNE(type, "array") && *type != '\0' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( (type != NULL) && strNE(type, "array") && *type != '\0' ) { 4 0 4
if ( (type != NULL) && strNE(type, "array") && *type != '\0' ) { 3 1 4
if ( (type != NULL) && strNE(type, "array") && *type != '\0' ) { 3 0 3
503 3 sv_bless(sv, gv_stashpv(type, TRUE));
504 }
505 }
506 else {
507 0 ▶ sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE));
Branch: 1 branch
BranchTrueFalseTotal
sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE)); 0 0 0
508 }
509 }
510 5 Safefree(id_copy);
511 }
512 #endif
513 115 break;
514  
515 1270 case syck_map_kind:
516 #ifndef YAML_IS_JSON
517 1235 ▶ if ( (id != NULL) && (strEQ(id, "perl/ref") || strnEQ( id, "perl/ref:", 9 ) ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( (id != NULL) && (strEQ(id, "perl/ref") || strnEQ( id, "perl/ref:", 9 ) ) ) { 43 1183 1226
if ( (id != NULL) && (strEQ(id, "perl/ref") || strnEQ( id, "perl/ref:", 9 ) ) ) { 35 8 43
if ( (id != NULL) && (strEQ(id, "perl/ref") || strnEQ( id, "perl/ref:", 9 ) ) ) { 1 34 35
518 /* handle scalar references, that are a weird type of mappings */
519 9 SV* key = perl_syck_lookup_sym(p, syck_map_read(n, map_key, 0));
520 9 SV* val = perl_syck_lookup_sym(p, syck_map_read(n, map_value, 0));
521 9 char *ref_type = SvPVX(key);
522 #if 0 /* need not to duplicate scalar reference */
523 const char *forward_anchor;
524  
525 val = sv_2mortal(newSVsv(val));
526 forward_anchor = is_bad_alias_object(val);
527 if (forward_anchor)
528 register_bad_alias(p, forward_anchor, val);
529 #endif
530 9 sv = newRV_noinc(val);
531 9 USE_OBJECT(val);
532  
533 9 ▶ if ( load_blessed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( load_blessed ) { 8 1 9
534 8 ▶ if ( strnNE(ref_type, REF_LITERAL, REF_LITERAL_LENGTH+1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ( strnNE(ref_type, REF_LITERAL, REF_LITERAL_LENGTH+1)) { 0 8 8
535 /* handle the weird audrey scalar ref stuff */
536 0 sv_bless(sv, gv_stashpv(ref_type, TRUE));
537 }
538 else {
539 /* bless it if necessary */
540 8 char *id_copy = savepv(id);
541 8 char *lang = id_copy;
542 8 char *type = strpbrk(id_copy, "/:");
543 8 ▶ if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; }
Branch: 2 branches
BranchTrueFalseTotal
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 8 0 8
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 0 8 8
544  
545 8 ▶ if ( type != NULL && strnEQ(type, "ref:", 4)) {
Branch: 2 branches
BranchTrueFalseTotal
if ( type != NULL && strnEQ(type, "ref:", 4)) { 8 0 8
if ( type != NULL && strnEQ(type, "ref:", 4)) { 1 7 8
546 /* !perl/ref:Foo::Bar blesses into Foo::Bar */
547 1 type += 4;
548 }
549 8 ▶ if (lang == NULL || (strEQ(lang, "perl"))) {
Branch: 2 branches
BranchTrueFalseTotal
if (lang == NULL || (strEQ(lang, "perl"))) { 8 0 8
if (lang == NULL || (strEQ(lang, "perl"))) { 8 0 8
550 /* !perl/ref on it's own causes no blessing */
551 8 ▶ if ( (type != NULL) && strNE(type, "ref") && (*type != '\0')) {
Branch: 3 branches
BranchTrueFalseTotal
if ( (type != NULL) && strNE(type, "ref") && (*type != '\0')) { 8 0 8
if ( (type != NULL) && strNE(type, "ref") && (*type != '\0')) { 1 7 8
if ( (type != NULL) && strNE(type, "ref") && (*type != '\0')) { 1 0 1
552 1 sv_bless(sv, gv_stashpv(type, TRUE));
553 }
554 }
555 else {
556 0 ▶ sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE));
Branch: 1 branch
BranchTrueFalseTotal
sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE)); 0 0 0
557 }
558 8 Safefree(id_copy);
559 }
560 }
561 }
562 1217 ▶ else if ( (id != NULL) && (strEQ(id, "perl/regexp") || strnEQ( id, "perl/regexp:", 12 ) ) ) {
Branch: 3 branches
BranchTrueFalseTotal
else if ( (id != NULL) && (strEQ(id, "perl/regexp") || strnEQ( id, "perl/regexp:", 12 ) ) ) { 34 1183 1217
else if ( (id != NULL) && (strEQ(id, "perl/regexp") || strnEQ( id, "perl/regexp:", 12 ) ) ) { 34 0 34
else if ( (id != NULL) && (strEQ(id, "perl/regexp") || strnEQ( id, "perl/regexp:", 12 ) ) ) { 0 34 34
563 /* handle regexp references, that are a weird type of mappings */
564 0 dSP;
565 0 SV* key = perl_syck_lookup_sym(p, syck_map_read(n, map_key, 0));
566 0 SV* val = perl_syck_lookup_sym(p, syck_map_read(n, map_value, 0));
567 0 char *ref_type = SvPVX(key);
568  
569 0 ENTER;
570 0 SAVETMPS;
571 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
572 0 ▶ XPUSHs(val);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(val); 0 0 0
573 0 PUTBACK;
574 0 call_pv("YAML::Syck::__qr_helper", G_SCALAR);
575 0 SPAGAIN;
576  
577 0 sv = newSVsv(POPs);
578  
579 0 PUTBACK;
580 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
581 0 LEAVE;
582  
583 0 ▶ if ( load_blessed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( load_blessed ) { 0 0 0
584 0 ▶ if (strnNE(ref_type, REGEXP_LITERAL, REGEXP_LITERAL_LENGTH+1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (strnNE(ref_type, REGEXP_LITERAL, REGEXP_LITERAL_LENGTH+1)) { 0 0 0
585 /* handle the weird audrey scalar ref stuff */
586 0 sv_bless(sv, gv_stashpv(ref_type, TRUE));
587 }
588 else {
589 /* bless it if necessary */
590 0 char *id_copy = savepv(id);
591 0 char *lang = id_copy;
592 0 char *type = strpbrk(id_copy, "/:");
593 0 ▶ if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; }
Branch: 2 branches
BranchTrueFalseTotal
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 0 0 0
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 0 0 0
594  
595 0 ▶ if ( type != NULL && strnEQ(type, "regexp:", 7)) {
Branch: 2 branches
BranchTrueFalseTotal
if ( type != NULL && strnEQ(type, "regexp:", 7)) { 0 0 0
if ( type != NULL && strnEQ(type, "regexp:", 7)) { 0 0 0
596 /* !perl/regexp:Foo::Bar blesses into Foo::Bar */
597 0 type += 7;
598 }
599  
600 0 ▶ if (lang == NULL || (strEQ(lang, "perl"))) {
Branch: 2 branches
BranchTrueFalseTotal
if (lang == NULL || (strEQ(lang, "perl"))) { 0 0 0
if (lang == NULL || (strEQ(lang, "perl"))) { 0 0 0
601 /* !perl/regexp on it's own causes no blessing */
602 0 ▶ if ( (type != NULL) && strNE(type, "regexp") && (*type != '\0')) {
Branch: 3 branches
BranchTrueFalseTotal
if ( (type != NULL) && strNE(type, "regexp") && (*type != '\0')) { 0 0 0
if ( (type != NULL) && strNE(type, "regexp") && (*type != '\0')) { 0 0 0
if ( (type != NULL) && strNE(type, "regexp") && (*type != '\0')) { 0 0 0
603 0 sv_bless(sv, gv_stashpv(type, TRUE));
604 }
605 }
606 else {
607 0 ▶ sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE));
Branch: 1 branch
BranchTrueFalseTotal
sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE)); 0 0 0
608 }
609 0 Safefree(id_copy);
610 }
611 }
612 }
613 1224 ▶ else if (id && strnEQ(id, "perl:YAML::Syck::BadAlias", 25-1)) {
Branch: 2 branches
BranchTrueFalseTotal
else if (id && strnEQ(id, "perl:YAML::Syck::BadAlias", 25-1)) { 34 1183 1217
else if (id && strnEQ(id, "perl:YAML::Syck::BadAlias", 25-1)) { 7 27 34
614 7 SV* key = (SV *) syck_map_read(n, map_key, 0);
615 7 SV* val = (SV *) syck_map_read(n, map_value, 0);
616 7 map = newHV();
617 7 ▶ if (hv_store_ent(map, key, val, 0) != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (hv_store_ent(map, key, val, 0) != NULL) 7 0 7
618 7 USE_OBJECT(val);
619 7 sv = newRV_noinc((SV*)map);
620 7 sv_bless(sv, gv_stashpv("YAML::Syck::BadAlias", TRUE));
621 }
622 else
623 #endif
624 {
625 /* load the map into a new HV and place a ref to it in the SV */
626 #ifndef YAML_IS_JSON
627 1210 AV *merge_values = NULL;
628 #endif
629 1254 map = newHV();
630 9362118 ▶ for (i = 0; i < n->data.pairs->idx; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n->data.pairs->idx; i++) { 9360786 1210 9361996
for (i = 0; i < n->data.pairs->idx; i++) { 78 44 122
631 9360864 SV* key = perl_syck_lookup_sym(p, syck_map_read(n, map_key, i));
632 9360864 SV* val = perl_syck_lookup_sym(p, syck_map_read(n, map_value, i));
633 #ifndef YAML_IS_JSON
634 const char *forward_anchor;
635  
636 9360786 val = sv_2mortal(newSVsv(val));
637 9360786 forward_anchor = is_bad_alias_object(val);
638 9360786 ▶ if (forward_anchor)
Branch: 1 branch
BranchTrueFalseTotal
if (forward_anchor) 10 9360776 9360786
639 10 register_bad_alias(p, forward_anchor, val);
640  
641 /* YAML merge key (<<): defer merge processing until
642 * all explicit keys are stored, so explicit keys
643 * always take precedence over merged keys. */
644 9360786 ▶ if (p->implicit_typing) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->implicit_typing) { 181 9360605 9360786
645 STRLEN klen;
646 181 const char *kpv = SvPV(key, klen);
647 181 ▶ if (klen == 2 && kpv[0] == '<' && kpv[1] == '<') {
Branch: 3 branches
BranchTrueFalseTotal
if (klen == 2 && kpv[0] == '<' && kpv[1] == '<') { 10 171 181
if (klen == 2 && kpv[0] == '<' && kpv[1] == '<') { 7 3 10
if (klen == 2 && kpv[0] == '<' && kpv[1] == '<') { 7 0 7
648 7 ▶ if (!merge_values)
Branch: 1 branch
BranchTrueFalseTotal
if (!merge_values) 7 0 7
649 7 merge_values = newAV();
650 7 SvREFCNT_inc(val);
651 7 av_push(merge_values, val);
652 7 continue;
653 }
654 }
655 #endif
656 9360857 ▶ if (hv_store_ent(map, key, val, 0) != NULL)
Branch: 2 branches
BranchTrueFalseTotal
if (hv_store_ent(map, key, val, 0) != NULL) 9360779 0 9360779
if (hv_store_ent(map, key, val, 0) != NULL) 78 0 78
657 9360857 USE_OBJECT(val);
658 }
659 #ifndef YAML_IS_JSON
660 /* Apply merge keys: copy entries from referenced mappings
661 * into the parent hash, skipping keys that already exist. */
662 1210 ▶ if (merge_values) {
Branch: 1 branch
BranchTrueFalseTotal
if (merge_values) { 7 1203 1210
663 long mi;
664 14 ▶ for (mi = 0; mi <= av_len(merge_values); mi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (mi = 0; mi <= av_len(merge_values); mi++) { 7 7 14
665 7 SV **pmerge = av_fetch(merge_values, mi, 0);
666 7 ▶ if (!pmerge) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (!pmerge) continue; 0 7 7
667 11 ▶ if (SvROK(*pmerge) && SvTYPE(SvRV(*pmerge)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(*pmerge) && SvTYPE(SvRV(*pmerge)) == SVt_PVHV) { 7 0 7
if (SvROK(*pmerge) && SvTYPE(SvRV(*pmerge)) == SVt_PVHV) { 4 3 7
668 /* <<: *alias (single mapping) */
669 4 HV *merge_hv = (HV *)SvRV(*pmerge);
670 HE *he;
671 4 hv_iterinit(merge_hv);
672 15 ▶ while ((he = hv_iternext(merge_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(merge_hv))) { 7 4 11
673 7 SV *hkey = hv_iterkeysv(he);
674 7 ▶ if (!hv_exists_ent(map, hkey, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_exists_ent(map, hkey, 0)) { 6 1 7
675 6 SV *hval = hv_iterval(merge_hv, he);
676 6 SvREFCNT_inc(hval);
677 6 ▶ if (hv_store_ent(map, hkey, hval, 0) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (hv_store_ent(map, hkey, hval, 0) == NULL) 0 6 6
678 0 SvREFCNT_dec(hval);
679 }
680 }
681 }
682 3 ▶ else if (SvROK(*pmerge) && SvTYPE(SvRV(*pmerge)) == SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
else if (SvROK(*pmerge) && SvTYPE(SvRV(*pmerge)) == SVt_PVAV) { 3 0 3
else if (SvROK(*pmerge) && SvTYPE(SvRV(*pmerge)) == SVt_PVAV) { 3 0 3
683 /* <<: [*a, *b] (sequence of mappings) */
684 3 AV *merge_av = (AV *)SvRV(*pmerge);
685 long ai;
686 9 ▶ for (ai = 0; ai <= av_len(merge_av); ai++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ai = 0; ai <= av_len(merge_av); ai++) { 6 3 9
687 6 SV **pelem = av_fetch(merge_av, ai, 0);
688 HV *elem_hv;
689 HE *he;
690 6 ▶ if (!pelem || !SvROK(*pelem) || SvTYPE(SvRV(*pelem)) != SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (!pelem || !SvROK(*pelem) || SvTYPE(SvRV(*pelem)) != SVt_PVHV) 6 0 6
if (!pelem || !SvROK(*pelem) || SvTYPE(SvRV(*pelem)) != SVt_PVHV) 6 0 6
if (!pelem || !SvROK(*pelem) || SvTYPE(SvRV(*pelem)) != SVt_PVHV) 0 6 6
691 0 continue;
692 6 elem_hv = (HV *)SvRV(*pelem);
693 6 hv_iterinit(elem_hv);
694 22 ▶ while ((he = hv_iternext(elem_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(elem_hv))) { 10 6 16
695 10 SV *hkey = hv_iterkeysv(he);
696 10 ▶ if (!hv_exists_ent(map, hkey, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_exists_ent(map, hkey, 0)) { 9 1 10
697 9 SV *hval = hv_iterval(elem_hv, he);
698 9 SvREFCNT_inc(hval);
699 9 ▶ if (hv_store_ent(map, hkey, hval, 0) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (hv_store_ent(map, hkey, hval, 0) == NULL) 0 9 9
700 0 SvREFCNT_dec(hval);
701 }
702 }
703 }
704 }
705 }
706 7 SvREFCNT_dec((SV *)merge_values);
707 }
708 #endif
709 1254 sv = newRV_noinc((SV*)map);
710 #ifndef YAML_IS_JSON
711 1210 ▶ if (id) {
Branch: 1 branch
BranchTrueFalseTotal
if (id) { 27 1183 1210
712 /* bless it if necessary */
713 27 char *id_copy = savepv(id);
714 27 char *lang = id_copy;
715 27 char *type = strpbrk(id_copy, "/:");
716 27 ▶ if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; }
Branch: 2 branches
BranchTrueFalseTotal
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 23 4 27
if (type != NULL) { *type = '\0'; type++; if (*type == '\0') type = NULL; } 0 23 23
717  
718 27 ▶ if ( type != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( type != NULL ) { 23 4 27
719 23 ▶ if (strnEQ(type, "hash:", 5)) {
Branch: 1 branch
BranchTrueFalseTotal
if (strnEQ(type, "hash:", 5)) { 12 11 23
720 /* !perl/hash:Foo::Bar blesses into Foo::Bar */
721 12 type += 5;
722 }
723  
724 /* FIXME deprecated - here compatibility with %Foo::Bar style blessing */
725 23 ▶ while ( *type == '%' ) { type++; }
Branch: 1 branch
BranchTrueFalseTotal
while ( *type == '%' ) { type++; } 0 23 23
726 }
727  
728 27 ▶ if (load_blessed) {
Branch: 1 branch
BranchTrueFalseTotal
if (load_blessed) { 17 10 27
729 17 ▶ if (lang == NULL || (strEQ(lang, "perl"))) {
Branch: 2 branches
BranchTrueFalseTotal
if (lang == NULL || (strEQ(lang, "perl"))) { 17 0 17
if (lang == NULL || (strEQ(lang, "perl"))) { 12 5 17
730 /* !perl/hash on it's own causes no blessing */
731 12 ▶ if ( (type != NULL) && strNE(type, "hash") && *type != '\0' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( (type != NULL) && strNE(type, "hash") && *type != '\0' ) { 11 1 12
if ( (type != NULL) && strNE(type, "hash") && *type != '\0' ) { 10 1 11
if ( (type != NULL) && strNE(type, "hash") && *type != '\0' ) { 10 0 10
732 10 sv_bless(sv, gv_stashpv(type, TRUE));
733 }
734 } else {
735 5 ▶ sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE));
Branch: 1 branch
BranchTrueFalseTotal
sv_bless(sv, gv_stashpv((type == NULL) ? lang : form("%s::%s", lang, type), TRUE)); 4 1 5
736 }
737 }
738 27 Safefree(id_copy);
739 }
740 #endif
741 }
742 1270 break;
743 }
744  
745 #ifndef YAML_IS_JSON
746 /* Fix bad anchors using sv_setsv */
747 18723841 ▶ if (n->id) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->id) { 7 18723834 18723841
748 7 ▶ if (n->anchor)
Branch: 1 branch
BranchTrueFalseTotal
if (n->anchor) 7 0 7
749 7 resolve_bad_alias(p, n->anchor, sv);
750  
751 7 sv_setsv( perl_syck_lookup_sym(p, n->id), sv );
752 }
753 #endif
754  
755 18724210 TRACK_OBJECT(sv);
756  
757 18724210 return syck_add_sym(p, (char *)sv);
758 }
759  
760 #ifdef YAML_IS_JSON
761 149 static char* perl_json_preprocess(char *s) {
762 STRLEN i;
763 char *out;
764 char ch;
765 149 char in_string = '\0';
766 149 bool in_quote = 0;
767 char *pos;
768 149 STRLEN len = strlen(s);
769  
770 149 New(2006, out, len*2+1, char);
771 149 pos = out;
772  
773 2064 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 1915 149 2064
774 1915 ch = *(s+i);
775 1915 *pos++ = ch;
776 1915 ▶ if (in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_quote) { 97 1818 1915
777 97 in_quote = !in_quote;
778 97 ▶ if (ch == '\'' && json_quote_char == '\'') {
Branch: 2 branches
BranchTrueFalseTotal
if (ch == '\'' && json_quote_char == '\'') { 9 88 97
if (ch == '\'' && json_quote_char == '\'') { 9 0 9
779 /* JSON single-quote mode: \' is an escaped quote.
780 * Since we convert delimiters to " for YAML double-quote
781 * parsing, a literal ' needs no backslash inside "..." */
782 9 pos -= 2;
783 9 *pos++ = '\'';
784 }
785 88 ▶ else if (ch == '\'') {
Branch: 1 branch
BranchTrueFalseTotal
else if (ch == '\'') { 0 88 88
786 0 *(pos - 2) = '\'';
787 }
788 }
789 1818 ▶ else if (ch == '\\') {
Branch: 1 branch
BranchTrueFalseTotal
else if (ch == '\\') { 97 1721 1818
790 97 in_quote = 1;
791 }
792 1721 ▶ else if (in_string == '\0') {
Branch: 1 branch
BranchTrueFalseTotal
else if (in_string == '\0') { 849 872 1721
793 849 switch (ch) {
794 78 case ':': { *pos++ = ' '; break; }
795 70 case ',': { *pos++ = ' '; break; }
796 143 case '"': { in_string = '"'; break; }
797 52 case '\'': {
798 52 in_string = '\'';
799 52 ▶ if (json_quote_char == '\'') {
Branch: 1 branch
BranchTrueFalseTotal
if (json_quote_char == '\'') { 51 1 52
800 /* Convert ' delimiter to " so YAML double-quote
801 * parser handles escape sequences (\b, \n, etc.) */
802 51 *(pos - 1) = '"';
803 }
804 52 break;
805 }
806 }
807 }
808 872 ▶ else if (ch == in_string) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ch == in_string) { 195 677 872
809 195 in_string = '\0';
810 195 ▶ if (ch == '\'' && json_quote_char == '\'') {
Branch: 2 branches
BranchTrueFalseTotal
if (ch == '\'' && json_quote_char == '\'') { 52 143 195
if (ch == '\'' && json_quote_char == '\'') { 51 1 52
811 51 *(pos - 1) = '"';
812 }
813 }
814 677 ▶ else if (ch == '"' && json_quote_char == '\'' && in_string == '\'') {
Branch: 3 branches
BranchTrueFalseTotal
else if (ch == '"' && json_quote_char == '\'' && in_string == '\'') { 0 677 677
else if (ch == '"' && json_quote_char == '\'' && in_string == '\'') { 0 0 0
else if (ch == '"' && json_quote_char == '\'' && in_string == '\'') { 0 0 0
815 /* Unescaped " inside a single-quoted JSON string needs escaping
816 * because we converted the delimiters to " for YAML parsing */
817 0 *(pos - 1) = '\\';
818 0 *pos++ = '"';
819 }
820 }
821  
822 149 *pos = '\0';
823 149 return out;
824 }
825  
826 235 void perl_json_postprocess(SV *sv) {
827 STRLEN i;
828 char ch;
829 235 bool in_string = 0;
830 235 bool in_quote = 0;
831 char *pos;
832 235 char *s = SvPVX(sv);
833 235 STRLEN len = sv_len(sv);
834 235 STRLEN final_len = len;
835  
836 235 pos = s;
837  
838 /* Horrible kluge if your quote char does not match what's wrapping this line */
839 235 ▶ if ( (json_quote_char == '\'') && (len > 1) && (*s == '\"') && (*(s+len-2) == '\"') ) {
Branch: 4 branches
BranchTrueFalseTotal
if ( (json_quote_char == '\'') && (len > 1) && (*s == '\"') && (*(s+len-2) == '\"') ) { 57 178 235
if ( (json_quote_char == '\'') && (len > 1) && (*s == '\"') && (*(s+len-2) == '\"') ) { 57 0 57
if ( (json_quote_char == '\'') && (len > 1) && (*s == '\"') && (*(s+len-2) == '\"') ) { 0 57 57
if ( (json_quote_char == '\'') && (len > 1) && (*s == '\"') && (*(s+len-2) == '\"') ) { 0 0 0
840 0 *s = '\'';
841 0 *(s+len-2) = '\'';
842 }
843  
844 /* Strip spaces after ':' and ',' outside quoted strings to produce
845 * compact JSON. The C-level emitter outputs "key": "value", ... with
846 * spaces; this in-place compaction removes them. See t/json-postprocess.t.
847 */
848 4086 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 3851 235 4086
849 3851 ch = *(s+i);
850 3851 *pos++ = ch;
851 3851 ▶ if (in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_quote) { 96 3755 3851
852 96 in_quote = !in_quote;
853 }
854 3755 ▶ else if (ch == '\\') {
Branch: 1 branch
BranchTrueFalseTotal
else if (ch == '\\') { 96 3659 3755
855 96 in_quote = 1;
856 }
857 3659 ▶ else if (ch == json_quote_char) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ch == json_quote_char) { 456 3203 3659
858 456 in_string = !in_string;
859 }
860 3203 ▶ else if ((ch == ':' || ch == ',') && !in_string) {
Branch: 3 branches
BranchTrueFalseTotal
else if ((ch == ':' || ch == ',') && !in_string) { 3132 71 3203
else if ((ch == ':' || ch == ',') && !in_string) { 67 3065 3132
else if ((ch == ':' || ch == ',') && !in_string) { 124 14 138
861 124 i++; /* has to be a space afterwards */
862 124 final_len--;
863 }
864 }
865  
866 /* Remove the trailing newline */
867 235 ▶ if (final_len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (final_len > 0) { 235 0 235
868 235 final_len--; pos--;
869 }
870 235 *pos = '\0';
871 235 SvCUR_set(sv, final_len);
872 235 }
873 #endif
874  
875 /* Destructor for SAVEDESTRUCTOR_X: frees parser on croak.
876 * Registered after syck_new_parser() so Perl's scope unwinding handles
877 * cleanup even when croak() longjmps past the normal return path.
878 * Guarded because perl_syck.h is included twice (YAML and JSON modes). */
879 #ifndef CLEANUP_PARSER_DEFINED
880 #define CLEANUP_PARSER_DEFINED
881 static void
882 2214 cleanup_parser(pTHX_ void *p) {
883 2214 SyckParser **pp = (SyckParser **)p;
884 2214 ▶ if (*pp != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (*pp != NULL) { 22 2192 2214
885 22 syck_free_parser(*pp);
886 22 *pp = NULL;
887 }
888 2214 }
889 #endif
890  
891 #ifdef YAML_IS_JSON
892 149 static SV * LoadJSON (char *s) {
893 #else
894 2169 static SV * LoadYAML (char *s) {
895 #endif
896 SYMID v;
897 SyckParser *parser;
898 struct parser_xtra bonus;
899  
900 2318 SV *obj = &PL_sv_undef;
901 2318 SV *use_code = GvSV(gv_fetchpv(form("%s::UseCode", PACKAGE_NAME), TRUE, SVt_PV));
902 2318 SV *load_code = GvSV(gv_fetchpv(form("%s::LoadCode", PACKAGE_NAME), TRUE, SVt_PV));
903 2318 SV *implicit_typing = GvSV(gv_fetchpv(form("%s::ImplicitTyping", PACKAGE_NAME), TRUE, SVt_PV));
904 2318 SV *implicit_unicode = GvSV(gv_fetchpv(form("%s::ImplicitUnicode", PACKAGE_NAME), TRUE, SVt_PV));
905 2318 SV *singlequote = GvSV(gv_fetchpv(form("%s::SingleQuote", PACKAGE_NAME), TRUE, SVt_PV));
906 2318 SV *load_blessed = GvSV(gv_fetchpv(form("%s::LoadBlessed", PACKAGE_NAME), TRUE, SVt_PV));
907 2318 ▶ json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' );
Branch: 2 branches
BranchTrueFalseTotal
json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' ); 14 2155 2169
json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' ); 53 96 149
908  
909 2318 ENTER; SAVETMPS;
910  
911 /* Don't even bother if the string is empty. */
912 2318 ▶ if (*s == '\0') { FREETMPS; LEAVE; return &PL_sv_undef; }
Branch: 4 branches
BranchTrueFalseTotal
if (*s == '\0') { FREETMPS; LEAVE; return &PL_sv_undef; } 104 2065 2169
if (*s == '\0') { FREETMPS; LEAVE; return &PL_sv_undef; } 0 104 104
if (*s == '\0') { FREETMPS; LEAVE; return &PL_sv_undef; } 0 149 149
if (*s == '\0') { FREETMPS; LEAVE; return &PL_sv_undef; } 0 0 0
913  
914 #ifdef YAML_IS_JSON
915 149 s = perl_json_preprocess(s);
916 149 SAVEFREEPV(s); /* freed at LEAVE — also on croak */
917 #else
918 /* Special preprocessing to maintain compat with YAML.pm <= 0.35 */
919 2065 ▶ if (strnEQ( s, "--- #YAML:1.0", 13)) {
Branch: 1 branch
BranchTrueFalseTotal
if (strnEQ( s, "--- #YAML:1.0", 13)) { 2 2063 2065
920 2 s[4] = '%';
921 }
922 #endif
923  
924 2214 parser = syck_new_parser();
925  
926 /* Register destructor so croak() in parser callbacks (error_handler,
927 * parser_handler code-loading) won't leak the SyckParser. */
928 2214 SAVEDESTRUCTOR_X(cleanup_parser, &parser);
929  
930 2214 syck_parser_str_auto(parser, s, NULL);
931 2214 syck_parser_handler(parser, PERL_SYCK_PARSER_HANDLER);
932 2214 syck_parser_error_handler(parser, perl_syck_error_handler);
933 2214 syck_parser_bad_anchor_handler( parser, perl_syck_bad_anchor_handler );
934 2214 syck_parser_implicit_typing(parser, SvTRUE(implicit_typing));
935 2214 syck_parser_taguri_expansion(parser, 0);
936  
937 2214 bonus.objects = (AV*)sv_2mortal((SV*)newAV());
938 2214 bonus.implicit_unicode = SvTRUE(implicit_unicode);
939 2214 ▶ bonus.load_code = SvTRUE(use_code) || SvTRUE(load_code);
Branch: 4 branches
BranchTrueFalseTotal
bonus.load_code = SvTRUE(use_code) || SvTRUE(load_code); 1548 517 2065
bonus.load_code = SvTRUE(use_code) || SvTRUE(load_code); 4 1544 1548
bonus.load_code = SvTRUE(use_code) || SvTRUE(load_code); 149 0 149
bonus.load_code = SvTRUE(use_code) || SvTRUE(load_code); 0 149 149
940 2214 bonus.load_blessed = SvTRUE(load_blessed);
941 2214 parser->bonus = &bonus;
942  
943 #ifndef YAML_IS_JSON
944 2065 bonus.bad_anchors = (HV*)sv_2mortal((SV*)newHV());
945  
946 2065 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 206 1859 2065
947 206 SYMID prev_v = 0;
948  
949 /* Mortalize the AV so croak() during syck_parse() won't leak it.
950 * Use newRV_inc to compensate — the mortal entry decrements at LEAVE. */
951 206 obj = (SV*)sv_2mortal((SV*)newAV());
952 434 ▶ while ((v = syck_parse(parser)) && (v != prev_v)) {
Branch: 2 branches
BranchTrueFalseTotal
while ((v = syck_parse(parser)) && (v != prev_v)) { 434 0 434
while ((v = syck_parse(parser)) && (v != prev_v)) { 228 206 434
953 228 SV *cur = &PL_sv_undef;
954 228 ▶ if (!syck_lookup_sym(parser, v, (char **)&cur)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!syck_lookup_sym(parser, v, (char **)&cur)) { 0 228 228
955 0 break;
956 }
957  
958 228 av_push((AV*)obj, cur);
959 228 USE_OBJECT(cur);
960  
961 228 prev_v = v;
962 }
963 206 obj = newRV_inc(obj);
964 }
965 else
966 #endif
967 {
968 2008 v = syck_parse(parser);
969 1986 ▶ if (syck_lookup_sym(parser, v, (char **)&obj)) {
Branch: 2 branches
BranchTrueFalseTotal
if (syck_lookup_sym(parser, v, (char **)&obj)) { 1837 0 1837
if (syck_lookup_sym(parser, v, (char **)&obj)) { 149 0 149
970 1986 USE_OBJECT(obj);
971 }
972 }
973  
974 /* Normal path: free parser now and NULL the pointer so the
975 * SAVEDESTRUCTOR_X callback (at LEAVE) becomes a no-op. */
976 2192 syck_free_parser(parser);
977 2192 parser = NULL;
978  
979 /* In JSON mode, SAVEFREEPV(s) frees the preprocessed string at LEAVE. */
980  
981 2192 ▶ FREETMPS; LEAVE;
Branch: 2 branches
BranchTrueFalseTotal
FREETMPS; LEAVE; 2043 0 2043
FREETMPS; LEAVE; 149 0 149
982  
983 2192 return obj;
984 }
985  
986 void
987 #ifdef YAML_IS_JSON
988 25652 json_syck_mark_emitter
989 #else
990 7646 yaml_syck_mark_emitter
991 #endif
992 (SyckEmitter *e, SV *sv) {
993 33298 e->depth++;
994  
995 33298 ▶ if (syck_emitter_mark_node(e, (st_data_t)sv, PERL_SYCK_EMITTER_MARK_NODE_FLAGS) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (syck_emitter_mark_node(e, (st_data_t)sv, PERL_SYCK_EMITTER_MARK_NODE_FLAGS) == 0) { 190 7456 7646
if (syck_emitter_mark_node(e, (st_data_t)sv, PERL_SYCK_EMITTER_MARK_NODE_FLAGS) == 0) { 2 25650 25652
996 192 e->depth--;
997 192 return;
998 }
999  
1000 33106 ▶ if (e->depth >= e->max_depth) {
Branch: 2 branches
BranchTrueFalseTotal
if (e->depth >= e->max_depth) { 3 7453 7456
if (e->depth >= e->max_depth) { 46 25604 25650
1001 #ifdef YAML_IS_JSON
1002 46 croak("Dumping circular structures is not supported with JSON::Syck, consider increasing $JSON::Syck::MaxDepth higher then %d.", e->max_depth);
1003 #else
1004 3 croak("Structure is nested deeper than $YAML::Syck::MaxDepth (%d); increase $YAML::Syck::MaxDepth to dump deeper structures.", e->max_depth);
1005 #endif
1006 }
1007  
1008 33057 ▶ if (SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(sv)) { 3089 4364 7453
if (SvROK(sv)) { 12683 12921 25604
1009 15772 PERL_SYCK_MARK_EMITTER(e, SvRV(sv));
1010 #ifdef YAML_IS_JSON
1011 907 st_insert(e->markers, (st_data_t)sv, 0);
1012 #endif
1013 3228 e->depth--;
1014 3228 return;
1015 }
1016  
1017 17285 switch (SvTYPE(sv)) {
1018 8547 case SVt_PVAV: {
1019 I32 len, i;
1020 8547 len = av_len((AV*)sv) + 1;
1021 11144 ▶ for (i = 0; i < len; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 2466 1076 3542
for (i = 0; i < len; i++) { 6761 841 7602
1022 9227 SV** sav = av_fetch((AV*)sv, i, 0);
1023 9227 if (sav != NULL) {
1024 9227 PERL_SYCK_MARK_EMITTER( e, *sav );
1025 }
1026 }
1027 1917 break;
1028 }
1029 6508 case SVt_PVHV: {
1030 HE *he;
1031 6508 hv_iterinit((HV*)sv);
1032 #ifdef HV_ITERNEXT_WANTPLACEHOLDERS
1033 7428 ▶ while ((he = hv_iternext_flags((HV*)sv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
while ((he = hv_iternext_flags((HV*)sv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 858 583 1441
while ((he = hv_iternext_flags((HV*)sv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 5927 60 5987
1034 #else
1035 while ((he = hv_iternext((HV*)sv)) != NULL) {
1036 #endif
1037 6785 SV *val = hv_iterval((HV*)sv, he);
1038 6785 PERL_SYCK_MARK_EMITTER( e, val );
1039 }
1040 643 break;
1041 }
1042 2230 default:
1043 2230 break;
1044 }
1045  
1046 #ifdef YAML_IS_JSON
1047 1191 st_insert(e->markers, (st_data_t)sv, 0);
1048 #endif
1049 4790 --e->depth;
1050 }
1051  
1052  
1053 void
1054 #ifdef YAML_IS_JSON
1055 2167 json_syck_emitter_handler
1056 #else
1057 6988 yaml_syck_emitter_handler
1058 #endif
1059 (SyckEmitter *e, st_data_t data) {
1060 I32 len, i;
1061 9155 SV* sv = (SV*)data;
1062 9155 struct emitter_xtra *bonus = (struct emitter_xtra *)e->bonus;
1063 9155 char* tag = bonus->tag;
1064 9155 svtype ty = SvTYPE(sv);
1065 #ifndef YAML_IS_JSON
1066 6988 char dump_code = bonus->dump_code;
1067 6988 char implicit_binary = bonus->implicit_binary;
1068 6988 char* ref = NULL;
1069 6988 char* ref_orig = NULL;
1070 #endif
1071  
1072 #define OBJECT_TAG "tag:!perl:"
1073
1074 9155 ▶ if (SvMAGICAL(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvMAGICAL(sv)) { 17 6971 6988
if (SvMAGICAL(sv)) { 3 2164 2167
1075 20 mg_get(sv);
1076 }
1077  
1078 #ifndef YAML_IS_JSON
1079  
1080 /* Handle blessing into the right class */
1081 6988 ▶ if (sv_isobject(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(sv)) { 68 6920 6988
1082 68 ref = savepv(sv_reftype(SvRV(sv), TRUE));
1083 68 ref_orig = ref;
1084 68 bonus->cur_ref = ref; /* track for cleanup on croak */
1085 68 *tag = '\0';
1086 68 strcat(tag, OBJECT_TAG);
1087  
1088 68 switch (SvTYPE(SvRV(sv))) {
1089 11 case SVt_PVAV: { strcat(tag, "array:"); break; }
1090 23 case SVt_PVHV: { strcat(tag, "hash:"); break; }
1091 4 case SVt_PVCV: { strcat(tag, "code:"); break; }
1092 0 case SVt_PVGV: { strcat(tag, "glob:"); break; }
1093 #if PERL_VERSION > 10
1094 11 case SVt_REGEXP: {
1095 11 ▶ if (strEQ(ref, "Regexp")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(ref, "Regexp")) { 5 6 11
1096 5 strcat(tag, "regexp");
1097 5 ref += 6; /* empty string */
1098 } else {
1099 6 strcat(tag, "regexp:");
1100 }
1101 11 break;
1102 }
1103 #endif
1104  
1105 /* flatten scalar ref objects so that they dump as !perl/scalar:Foo::Bar foo */
1106 19 case SVt_PVMG: {
1107 19 ▶ if ( SvROK(SvRV(sv)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( SvROK(SvRV(sv)) ) { 2 17 19
1108 2 strcat(tag, "ref:");
1109 2 break;
1110 }
1111 #if PERL_VERSION > 10
1112 else {
1113 17 strcat(tag, "scalar:");
1114 17 sv = SvRV(sv);
1115 17 ty = SvTYPE(sv);
1116 17 break;
1117 }
1118 #else
1119 else {
1120 MAGIC *mg;
1121 if ( (mg = mg_find(SvRV(sv), PERL_MAGIC_qr) ) ) {
1122 if (strEQ(ref, "Regexp")) {
1123 strcat(tag, "regexp");
1124 ref += 6; /* empty string */
1125 }
1126 else {
1127 strcat(tag, "regexp:");
1128 }
1129 sv = newSVpvn(SvPV_nolen(sv), sv_len(sv));
1130 ty = SvTYPE(sv);
1131 }
1132 else {
1133 strcat(tag, "scalar:");
1134 sv = SvRV(sv);
1135 ty = SvTYPE(sv);
1136 }
1137 break;
1138 }
1139 #endif
1140 }
1141 0 default:
1142 0 break;
1143 }
1144 {
1145 /* Grow tag buffer if ref won't fit (prevents heap overflow) */
1146 68 STRLEN need = strlen(tag) + strlen(ref) + 1;
1147 68 ▶ if (need > bonus->tag_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (need > bonus->tag_len) { 2 66 68
1148 2 Renew(bonus->tag, need, char);
1149 2 bonus->tag_len = need;
1150 2 tag = bonus->tag;
1151 }
1152 }
1153 68 strcat(tag, ref);
1154 }
1155 #endif
1156  
1157 /*
1158 * For blessed scalar refs that were flattened (sv = SvRV(sv) in SVt_PVMG
1159 * above), the inner scalar may have an anchor from the marking pass.
1160 * Since we emit it via syck_emit_scalar() (not syck_emit()), we must
1161 * handle anchors/aliases manually here.
1162 */
1163 #ifndef YAML_IS_JSON
1164 6988 ▶ if (ref_orig != NULL && !SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref_orig != NULL && !SvROK(sv)) { 68 6920 6988
if (ref_orig != NULL && !SvROK(sv)) { 17 51 68
1165 st_data_t oid;
1166 17 char *anchor_name = NULL;
1167 27 if (e->anchors != NULL &&
1168 20 ▶ st_lookup(e->markers, (st_data_t)sv, &oid) &&
Branch: 1 branch
BranchTrueFalseTotal
st_lookup(e->markers, (st_data_t)sv, &oid) && 8 2 10
1169 10 st_lookup(e->anchors, (st_data_t)oid, (st_data_t *)&anchor_name))
1170 {
1171 8 ▶ if (e->anchored == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (e->anchored == NULL) { 4 4 8
1172 4 e->anchored = st_init_numtable();
1173 }
1174 8 ▶ if (!st_lookup(e->anchored, (st_data_t)anchor_name, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!st_lookup(e->anchored, (st_data_t)anchor_name, 0)) { 4 4 8
1175 /* First occurrence: write &N before the tag+scalar */
1176 4 char *an = S_ALLOC_N(char, strlen(anchor_name) + 3);
1177 4 sprintf(an, "&%s ", anchor_name);
1178 4 syck_emitter_write(e, an, strlen(anchor_name) + 2);
1179 4 S_FREE(an);
1180 4 st_insert(e->anchored, (st_data_t)anchor_name, 0);
1181 }
1182 else {
1183 /* Already emitted: write *N alias and return */
1184 4 char *an = S_ALLOC_N(char, strlen(anchor_name) + 2);
1185 4 sprintf(an, "*%s", anchor_name);
1186 4 syck_emitter_write(e, an, strlen(anchor_name) + 1);
1187 4 S_FREE(an);
1188 4 *tag = '\0';
1189 4 Safefree(ref_orig);
1190 4 bonus->cur_ref = NULL;
1191 4 return;
1192 }
1193 }
1194 }
1195 #endif
1196  
1197 9151 ▶ if (SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(sv)) { 2306 4678 6984
if (SvROK(sv)) { 908 1259 2167
1198 /* emit a scalar ref */
1199 #ifdef YAML_IS_JSON
1200 908 PERL_SYCK_EMITTER_HANDLER(e, (st_data_t)SvRV(sv));
1201 #else
1202 2306 switch (SvTYPE(SvRV(sv))) {
1203 2068 case SVt_PVAV:
1204 case SVt_PVHV:
1205 case SVt_PVCV: {
1206 /* Arrays, hashes and code values are inlined, and will be wrapped by a ref in the undumping */
1207 2068 e->indent = 0;
1208 2068 syck_emit_item(e, (st_data_t)SvRV(sv));
1209 2047 e->indent = PERL_SYCK_INDENT_LEVEL;
1210 2047 break;
1211 }
1212 #if PERL_VERSION > 10
1213 11 case SVt_REGEXP: {
1214 11 STRLEN len = sv_len(sv);
1215 22 ▶ syck_emit_scalar( e, OBJOF("tag:!perl:regexp"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), len );
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar( e, OBJOF("tag:!perl:regexp"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), len ); 11 0 11
1216 11 syck_emit_end(e);
1217 11 break;
1218 }
1219 #endif
1220 227 default: {
1221 SV *ref_sv;
1222 227 ▶ syck_emit_map(e, OBJOF("tag:!perl:ref"), MAP_NONE);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_map(e, OBJOF("tag:!perl:ref"), MAP_NONE); 2 225 227
1223 227 *tag = '\0';
1224 227 ref_sv = newSVpvn_share(REF_LITERAL, REF_LITERAL_LENGTH, 0);
1225 227 syck_emit_item( e, (st_data_t)ref_sv );
1226 227 SvREFCNT_dec(ref_sv);
1227 227 syck_emit_item( e, (st_data_t)SvRV(sv) );
1228 227 syck_emit_end(e);
1229 }
1230 }
1231 #endif
1232 }
1233 5937 ▶ else if (ty == SVt_NULL) {
Branch: 2 branches
BranchTrueFalseTotal
else if (ty == SVt_NULL) { 7 4671 4678
else if (ty == SVt_NULL) { 17 1242 1259
1234 /* emit an undef */
1235 24 syck_emit_scalar(e, "str", scalar_plain, 0, 0, 0, NULL_LITERAL, NULL_LITERAL_LENGTH);
1236 }
1237 5913 ▶ else if ((ty == SVt_PVMG) && !SvOK(sv)) {
Branch: 4 branches
BranchTrueFalseTotal
else if ((ty == SVt_PVMG) && !SvOK(sv)) { 19 4652 4671
else if ((ty == SVt_PVMG) && !SvOK(sv)) { 3 16 19
else if ((ty == SVt_PVMG) && !SvOK(sv)) { 2 1240 1242
else if ((ty == SVt_PVMG) && !SvOK(sv)) { 0 2 2
1238 /* emit an undef (typically pointed from a blesed SvRV) */
1239 3 ▶ syck_emit_scalar(e, OBJOF("str"), scalar_plain, 0, 0, 0, NULL_LITERAL, NULL_LITERAL_LENGTH);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), scalar_plain, 0, 0, 0, NULL_LITERAL, NULL_LITERAL_LENGTH); 3 0 3
1240 }
1241 8534 ▶ else if (SvPOK(sv) && ty != SVt_PVCV) {
Branch: 4 branches
BranchTrueFalseTotal
else if (SvPOK(sv) && ty != SVt_PVCV) { 2400 2268 4668
else if (SvPOK(sv) && ty != SVt_PVCV) { 2396 4 2400
else if (SvPOK(sv) && ty != SVt_PVCV) { 228 1014 1242
else if (SvPOK(sv) && ty != SVt_PVCV) { 228 0 228
1242 /* emit a string (exclude CVs: prototyped subs have SvPOK set for the
1243 * prototype string, but must go through the SVt_PVCV case below for
1244 * proper B::Deparse handling) */
1245 2624 STRLEN len = sv_len(sv);
1246  
1247 /* JSON should preserve quotes even on simple integers ("0" is true in javascript) */
1248 #ifndef YAML_IS_JSON
1249 2396 ▶ if (looks_like_number(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (looks_like_number(sv)) { 551 1845 2396
1250 1102 ▶ if(syck_str_is_unquotable_integer(SvPV_nolen(sv), sv_len(sv))) {
Branch: 1 branch
BranchTrueFalseTotal
if(syck_str_is_unquotable_integer(SvPV_nolen(sv), sv_len(sv))) { 526 25 551
1251 /* emit an unquoted number only if it's a very basic integer. /^-?[1-9][0-9]*$/ */
1252 1052 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_NUMBER, 0, 0, 0, SvPV_nolen(sv), len);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_NUMBER, 0, 0, 0, SvPV_nolen(sv), len); 0 526 526
1253 }
1254 else {
1255 /* Even though it looks like a number, quote it or it won't round trip correctly. */
1256 50 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_QUOTED, 0, 0, 0, SvPV_nolen(sv), len);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_QUOTED, 0, 0, 0, SvPV_nolen(sv), len); 0 25 25
1257 }
1258 }
1259 else
1260 #endif
1261 2073 if (len == 0) {
1262 15 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_QUOTED, 0, 0, 0, "", 0);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_QUOTED, 0, 0, 0, "", 0); 0 2 2
1263 }
1264 1843 ▶ else if (IS_UTF8(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (IS_UTF8(sv)) { 136 1707 1843
1265 /* if we support UTF8 and the string contains UTF8 */
1266 351 enum scalar_style old_s = e->style;
1267 351 e->style = SCALAR_UTF8;
1268 702 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), len);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), len); 0 136 136
1269 351 e->style = old_s;
1270 }
1271 #ifndef YAML_IS_JSON
1272 1707 ▶ else if (implicit_binary) {
Branch: 1 branch
BranchTrueFalseTotal
else if (implicit_binary) { 47 1660 1707
1273 /* scan string for high-bits in the SV */
1274 47 bool is_ascii = TRUE;
1275 47 char *str = SvPV_nolen(sv);
1276 47 STRLEN bin_len = sv_len(sv);
1277 STRLEN bi;
1278  
1279 347 ▶ for (bi = 0; bi < bin_len; bi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (bi = 0; bi < bin_len; bi++) { 301 46 347
1280 301 ▶ if (*(str + bi) & 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if (*(str + bi) & 0x80) { 1 300 301
1281 /* Binary here */
1282 1 char *base64 = syck_base64enc( str, bin_len );
1283 1 syck_emit_scalar(e, "tag:yaml.org,2002:binary", SCALAR_STRING, 0, 0, 0, base64, strlen(base64));
1284 1 syck_base64_free(base64);
1285 1 is_ascii = FALSE;
1286 1 break;
1287 }
1288 }
1289  
1290 47 ▶ if (is_ascii) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ascii) { 46 1 47
1291 46 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, str, bin_len);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, str, bin_len); 0 46 46
1292 }
1293 }
1294 #endif
1295 else {
1296 3320 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), len);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), len); 9 1651 1660
1297 }
1298 }
1299 3286 ▶ else if (SvNIOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
else if (SvNIOK(sv)) { 176 2096 2272
else if (SvNIOK(sv)) { 103 911 1014
1300 /* Stringify the sv, being careful not to overwrite its PV part */
1301 279 SV *sv2 = newSVsv(sv);
1302 STRLEN len;
1303 279 char *str = SvPV(sv2, len);
1304 279 ▶ if (SvIOK(sv) /* original SV was an int */
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(sv) /* original SV was an int */ 160 16 176
if (SvIOK(sv) /* original SV was an int */ 103 0 103
1305 263 ▶ && syck_str_is_unquotable_integer(str, len)) /* small enough to safely round-trip */
Branch: 2 branches
BranchTrueFalseTotal
&& syck_str_is_unquotable_integer(str, len)) /* small enough to safely round-trip */ 158 2 160
&& syck_str_is_unquotable_integer(str, len)) /* small enough to safely round-trip */ 103 0 103
1306 {
1307 261 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_NUMBER, 0, 0, 0, str, len);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_NUMBER, 0, 0, 0, str, len); 1 157 158
1308 } else {
1309 /* We need to quote it */
1310 18 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_QUOTED, 0, 0, 0, str, len);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_QUOTED, 0, 0, 0, str, len); 0 18 18
1311 }
1312 279 SvREFCNT_dec(sv2);
1313 }
1314 else {
1315 3007 switch (ty) {
1316 1919 case SVt_PVAV: { /* array */
1317 1919 ▶ syck_emit_seq(e, OBJOF("array"), SEQ_NONE);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_seq(e, OBJOF("array"), SEQ_NONE); 8 1069 1077
1318 1919 e->indent = PERL_SYCK_INDENT_LEVEL;
1319  
1320 1919 *tag = '\0';
1321 1919 len = av_len((AV*)sv) + 1;
1322 4521 ▶ for (i = 0; i < len; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 1704 1077 2781
for (i = 0; i < len; i++) { 898 842 1740
1323 2602 SV** sav = av_fetch((AV*)sv, i, 0);
1324 2602 if (sav == NULL) {
1325 0 syck_emit_item( e, (st_data_t)(&PL_sv_undef) );
1326 }
1327 else {
1328 2602 syck_emit_item( e, (st_data_t)(*sav) );
1329 }
1330 }
1331 1919 syck_emit_end(e);
1332 1919 return;
1333 }
1334 646 case SVt_PVHV: { /* hash */
1335 646 HV *hv = (HV*)sv;
1336 HE *he;
1337 646 ▶ syck_emit_map(e, OBJOF("hash"), MAP_NONE);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_map(e, OBJOF("hash"), MAP_NONE); 20 564 584
1338 646 e->indent = PERL_SYCK_INDENT_LEVEL;
1339  
1340 646 *tag = '\0';
1341 646 hv_iterinit((HV*)sv);
1342  
1343 646 if (e->sort_keys) {
1344 583 AV *av = (AV*)sv_2mortal((SV*)newAV());
1345 #ifdef HV_ITERNEXT_WANTPLACEHOLDERS
1346 1416 ▶ while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 833 583 1416
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 0 0 0
1347 #else
1348 while ((he = hv_iternext(hv)) != NULL) {
1349 #endif
1350 833 SV *key = hv_iterkeysv(he);
1351 833 av_store(av, AvFILLp(av)+1, key); /* av_push(), really */
1352 }
1353 583 len = av_len(av) + 1;
1354 583 STORE_HASH_SORT;
1355 1416 ▶ for (i = 0; i < len; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 833 583 1416
for (i = 0; i < len; i++) { 0 0 0
1356 833 SV *key = av_shift(av);
1357 833 HE *he = hv_fetch_ent(hv, key, 0, 0);
1358 833 ▶ SV *val = he ? HeVAL(he) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *val = he ? HeVAL(he) : &PL_sv_undef; 833 0 833
SV *val = he ? HeVAL(he) : &PL_sv_undef; 0 0 0
1359 833 ▶ if (val == NULL) { val = &PL_sv_undef; }
Branch: 2 branches
BranchTrueFalseTotal
if (val == NULL) { val = &PL_sv_undef; } 0 833 833
if (val == NULL) { val = &PL_sv_undef; } 0 0 0
1360 833 syck_emit_item( e, (st_data_t)key );
1361 833 syck_emit_item( e, (st_data_t)val );
1362 }
1363 }
1364 else {
1365 #ifdef HV_ITERNEXT_WANTPLACEHOLDERS
1366 152 ▶ while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 26 1 27
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 63 62 125
1367 #else
1368 while ((he = hv_iternext(hv)) != NULL) {
1369 #endif
1370 89 SV *key = hv_iterkeysv(he);
1371 89 SV *val = hv_iterval(hv, he);
1372 89 syck_emit_item( e, (st_data_t)key );
1373 89 syck_emit_item( e, (st_data_t)val );
1374 }
1375 }
1376 /* reset the hash pointer */
1377 646 hv_iterinit(hv);
1378 646 syck_emit_end(e);
1379 646 return;
1380 }
1381 236 case SVt_PVCV: { /* code */
1382 #ifdef YAML_IS_JSON
1383 1 syck_emit_scalar(e, "str", scalar_plain, 0, 0, 0, NULL_LITERAL, NULL_LITERAL_LENGTH);
1384 #else
1385  
1386 /* This following code is mostly copypasted from Storable */
1387  
1388 #if PERL_VERSION < 8
1389 syck_emit_scalar(e, OBJOF("tag:!perl:code:"), SCALAR_QUOTED, 0, 0, 0, "{ \"DUMMY\" }", 11);
1390 #else
1391 235 ▶ if ( !dump_code ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !dump_code ) { 3 232 235
1392 3 ▶ syck_emit_scalar(e, OBJOF("tag:!perl:code:"), SCALAR_QUOTED, 0, 0, 0, "{ \"DUMMY\" }", 11);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("tag:!perl:code:"), SCALAR_QUOTED, 0, 0, 0, "{ \"DUMMY\" }", 11); 2 1 3
1393 }
1394 else {
1395 232 dSP;
1396 int count, reallen;
1397 SV *text;
1398 232 CV *cv = (CV*)sv;
1399 232 SV *bdeparse = GvSV(gv_fetchpv(form("%s::DeparseObject", PACKAGE_NAME), TRUE, SVt_PV));
1400  
1401 232 ▶ if (!SvTRUE(bdeparse)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvTRUE(bdeparse)) { 0 232 232
1402 0 croak("B::Deparse initialization failed -- cannot dump code object");
1403 }
1404  
1405 232 ENTER;
1406 232 SAVETMPS;
1407  
1408 /*
1409 * call the coderef2text method
1410 */
1411  
1412 232 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 232 232
1413 232 ▶ XPUSHs(bdeparse); /* XXX is this already mortal? */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(bdeparse); /* XXX is this already mortal? */ 0 232 232
1414 232 ▶ XPUSHs(sv_2mortal(newRV_inc((SV*)cv)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_inc((SV*)cv))); 0 232 232
1415 232 PUTBACK;
1416 232 count = call_method("coderef2text", G_SCALAR);
1417 232 SPAGAIN;
1418 232 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 232 232
1419 0 croak("Unexpected return value from B::Deparse::coderef2text\n");
1420 }
1421  
1422 232 text = POPs;
1423 232 reallen = strlen(SvPV_nolen(text));
1424  
1425 /*
1426 * Empty code references or XS functions are deparsed as
1427 * "(prototype) ;" or ";".
1428 */
1429  
1430 464 ▶ if (reallen == 0 || *(SvPV_nolen(text)+reallen-1) == ';') {
Branch: 2 branches
BranchTrueFalseTotal
if (reallen == 0 || *(SvPV_nolen(text)+reallen-1) == ';') { 232 0 232
if (reallen == 0 || *(SvPV_nolen(text)+reallen-1) == ';') { 21 211 232
1431 21 croak("The result of B::Deparse::coderef2text was empty - maybe you're trying to serialize an XS function?\n");
1432 }
1433  
1434 /*
1435 * Now store the source code.
1436 */
1437  
1438 422 ▶ syck_emit_scalar(e, OBJOF("tag:!perl:code:"), SCALAR_UTF8, 0, 0, 0, SvPV_nolen(text), reallen);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("tag:!perl:code:"), SCALAR_UTF8, 0, 0, 0, SvPV_nolen(text), reallen); 2 209 211
1439  
1440 211 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 211 0 211
1441 211 LEAVE;
1442  
1443 /* END Storable */
1444 }
1445 #endif
1446 #endif
1447 215 *tag = '\0';
1448 215 break;
1449 }
1450 200 case SVt_PVGV: /* glob (not a filehandle, a symbol table entry) */
1451 case SVt_PVFM: { /* format */
1452 /* XXX TODO XXX */
1453 400 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), sv_len(sv));
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 0 200 200
1454 200 break;
1455 }
1456 0 case SVt_PVIO: { /* filehandle */
1457 0 ▶ syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), sv_len(sv));
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_scalar(e, OBJOF("str"), SCALAR_STRING, 0, 0, 0, SvPV_nolen(sv), sv_len(sv)); 0 0 0
1458 0 break;
1459 }
1460 6 default: {
1461 6 syck_emit_scalar(e, "str", scalar_plain, 0, 0, 0, NULL_LITERAL, NULL_LITERAL_LENGTH);
1462 }
1463 }
1464 }
1465 /* cleanup: */
1466 1263 *tag = '\0';
1467 #ifndef YAML_IS_JSON
1468 5281 ▶ if (ref_orig != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref_orig != NULL) { 64 5217 5281
1469 64 Safefree(ref_orig);
1470 64 bonus->cur_ref = NULL; /* already freed — prevent double-free in destructor */
1471 }
1472 #endif
1473 }
1474  
1475 /* Destructor for SAVEDESTRUCTOR_X: frees emitter and tag buffer on croak.
1476 * Registered after allocation so Perl's scope unwinding handles cleanup
1477 * even when a croak() longjmps past the normal return path.
1478 * Guarded because perl_syck.h is included twice (YAML and JSON modes). */
1479 #ifndef CLEANUP_EMITTER_BONUS_DEFINED
1480 #define CLEANUP_EMITTER_BONUS_DEFINED
1481 static void
1482 1514 cleanup_emitter_bonus(pTHX_ void *p) {
1483 1514 struct emitter_xtra *bonus = (struct emitter_xtra *)p;
1484 1514 ▶ if (bonus->cur_ref != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bonus->cur_ref != NULL) { 0 1514 1514
1485 0 Safefree(bonus->cur_ref);
1486 0 bonus->cur_ref = NULL;
1487 }
1488 1514 ▶ if (bonus->emitter != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bonus->emitter != NULL) { 70 1444 1514
1489 70 syck_free_emitter((SyckEmitter *)bonus->emitter);
1490 70 bonus->emitter = NULL;
1491 }
1492 1514 ▶ if (bonus->tag != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bonus->tag != NULL) { 70 1444 1514
1493 70 Safefree(bonus->tag);
1494 70 bonus->tag = NULL;
1495 }
1496 1514 }
1497 #endif
1498  
1499 void
1500 #ifdef YAML_IS_JSON
1501 281 DumpJSONImpl
1502 #else
1503 1233 DumpYAMLImpl
1504 #endif
1505 (SV *sv, struct emitter_xtra *bonus, SyckOutputHandler output_handler) {
1506 SyckEmitter *emitter;
1507 1514 SV *headless = GvSV(gv_fetchpv(form("%s::Headless", PACKAGE_NAME), TRUE, SVt_PV));
1508 1514 SV *implicit_binary = GvSV(gv_fetchpv(form("%s::ImplicitBinary", PACKAGE_NAME), TRUE, SVt_PV));
1509 1514 SV *use_code = GvSV(gv_fetchpv(form("%s::UseCode", PACKAGE_NAME), TRUE, SVt_PV));
1510 1514 SV *dump_code = GvSV(gv_fetchpv(form("%s::DumpCode", PACKAGE_NAME), TRUE, SVt_PV));
1511 1514 SV *sortkeys = GvSV(gv_fetchpv(form("%s::SortKeys", PACKAGE_NAME), TRUE, SVt_PV));
1512 1514 SV *max_depth = GvSV(gv_fetchpv(form("%s::MaxDepth", PACKAGE_NAME), TRUE, SVt_PV));
1513 #ifdef YAML_IS_JSON
1514 281 SV *singlequote = GvSV(gv_fetchpv(form("%s::SingleQuote", PACKAGE_NAME), TRUE, SVt_PV));
1515 281 ▶ json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' );
Branch: 1 branch
BranchTrueFalseTotal
json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' ); 57 224 281
1516 281 ▶ json_quote_style = (SvTRUE(singlequote) ? scalar_2quote_1 : scalar_2quote );
Branch: 1 branch
BranchTrueFalseTotal
json_quote_style = (SvTRUE(singlequote) ? scalar_2quote_1 : scalar_2quote ); 57 224 281
1517 #else
1518 1233 SV *singlequote = GvSV(gv_fetchpv(form("%s::SingleQuote", PACKAGE_NAME), TRUE, SVt_PV));
1519 1233 yaml_quote_style = (SvTRUE(singlequote) ? scalar_1quote : scalar_none);
1520 #endif
1521  
1522 1514 ENTER; SAVETMPS;
1523  
1524 /* Initialize B::Deparse BEFORE allocating the emitter, so that if
1525 * eval_pv croaks (longjmp) we don't leak the SyckEmitter. */
1526 #ifndef YAML_IS_JSON
1527 1233 ▶ if (SvTRUE(use_code) || SvTRUE(dump_code)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(use_code) || SvTRUE(dump_code)) { 414 819 1233
if (SvTRUE(use_code) || SvTRUE(dump_code)) { 28 386 414
1528 847 SV *bdeparse = GvSV(gv_fetchpv(form("%s::DeparseObject", PACKAGE_NAME), TRUE, SVt_PV));
1529  
1530 847 ▶ if (!SvTRUE(bdeparse)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvTRUE(bdeparse)) { 5 842 847
1531 5 eval_pv(form(
1532 "local $@; require B::Deparse; $%s::DeparseObject = B::Deparse->new",
1533 PACKAGE_NAME
1534 ), 1);
1535 }
1536 }
1537 #endif
1538  
1539 1514 emitter = syck_new_emitter();
1540  
1541 1514 if (SvIOK(max_depth))
1542 282 emitter->max_depth = SvIV(max_depth);
1543 #ifdef YAML_IS_JSON
1544 else
1545 0 emitter->max_depth = json_max_depth;
1546 281 emitter->indent = PERL_SYCK_INDENT_LEVEL;
1547 281 emitter->json_mode = 1;
1548 #endif
1549  
1550 1514 emitter->headless = SvTRUE(headless);
1551 1514 emitter->sort_keys = SvTRUE(sortkeys);
1552 1514 emitter->anchor_format = "%d";
1553  
1554 1514 New(801, bonus->tag, 512, char);
1555 1514 bonus->tag_len = 512;
1556 1514 *(bonus->tag) = '\0';
1557 1514 ▶ bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code);
Branch: 4 branches
BranchTrueFalseTotal
bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code); 414 819 1233
bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code); 28 386 414
bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code); 281 0 281
bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code); 0 281 281
1558 1514 bonus->implicit_binary = SvTRUE(implicit_binary);
1559 1514 bonus->emitter = emitter;
1560 1514 bonus->cur_ref = NULL;
1561 1514 emitter->bonus = bonus;
1562  
1563 /* Register destructor so croak() in callbacks (mark_emitter,
1564 * emitter_handler) won't leak the emitter or tag buffer. */
1565 1514 SAVEDESTRUCTOR_X(cleanup_emitter_bonus, bonus);
1566  
1567 1514 syck_emitter_handler( emitter, PERL_SYCK_EMITTER_HANDLER );
1568 1514 syck_output_handler( emitter, output_handler );
1569  
1570 1514 PERL_SYCK_MARK_EMITTER( emitter, sv );
1571  
1572 #ifdef YAML_IS_JSON
1573 235 st_free_table(emitter->markers);
1574 235 emitter->markers = st_init_numtable();
1575 #endif
1576  
1577 1465 syck_emit( emitter, (st_data_t)sv );
1578 1444 syck_emitter_flush( emitter, 0 );
1579  
1580 /* Normal path: clean up now and NULL the pointers so the
1581 * SAVEDESTRUCTOR_X callback (at LEAVE) becomes a no-op. */
1582 1444 syck_free_emitter( emitter );
1583 1444 bonus->emitter = NULL;
1584 1444 Safefree(bonus->tag);
1585 1444 bonus->tag = NULL;
1586  
1587 1444 ▶ FREETMPS; LEAVE;
Branch: 2 branches
BranchTrueFalseTotal
FREETMPS; LEAVE; 1067 142 1209
FREETMPS; LEAVE; 52 183 235
1588  
1589 1444 return;
1590 }
1591  
1592  
1593 SV*
1594 #ifdef YAML_IS_JSON
1595 268 DumpJSON
1596 #else
1597 1211 DumpYAML
1598 #endif
1599 (SV *sv) {
1600 1479 SV *implicit_unicode = GvSV(gv_fetchpv(form("%s::ImplicitUnicode", PACKAGE_NAME), TRUE, SVt_PV));
1601 struct emitter_xtra bonus;
1602 /* Mortalize so croak inside DumpImpl won't leak the SV.
1603 * SvREFCNT_inc before return counteracts the XS wrapper's sv_2mortal. */
1604 1479 SV *out = sv_2mortal(newSVpvn("", 0));
1605 1479 bonus.out.outsv = out;
1606 #ifdef YAML_IS_JSON
1607 268 DumpJSONImpl(sv, &bonus, perl_syck_output_handler_pv);
1608 222 ▶ if (SvCUR(out) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(out) > 0) { 222 0 222
1609 222 perl_json_postprocess(out);
1610 }
1611 #else
1612 1211 DumpYAMLImpl(sv, &bonus, perl_syck_output_handler_pv);
1613 #endif
1614 #ifdef SvUTF8_on
1615 1409 ▶ if (SvTRUE(implicit_unicode)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(implicit_unicode)) { 138 1049 1187
if (SvTRUE(implicit_unicode)) { 52 170 222
1616 190 SvUTF8_on(out);
1617 }
1618 #endif
1619 1409 ▶ SvREFCNT_inc_simple_void(out);
Branch: 2 branches
BranchTrueFalseTotal
SvREFCNT_inc_simple_void(out); 1187 0 1187
SvREFCNT_inc_simple_void(out); 222 0 222
1620 1409 return out;
1621 }
1622  
1623 int
1624 #ifdef YAML_IS_JSON
1625 6 DumpJSONFile
1626 #else
1627 11 DumpYAMLFile
1628 #endif
1629 (SV *sv, PerlIO *out) {
1630 struct emitter_xtra bonus;
1631 17 bonus.out.outio = out;
1632 17 bonus.ioerror = 0;
1633 #ifdef YAML_IS_JSON
1634 {
1635 /* Buffer into an SV so we can apply perl_json_postprocess(),
1636 * then write the postprocessed result to the file handle.
1637 * Mortalize buf so croak inside DumpJSONImpl won't leak it. */
1638 6 SV *buf = sv_2mortal(newSVpvn("", 0));
1639 STRLEN len;
1640 char *s;
1641 6 bonus.out.outsv = buf;
1642 6 DumpJSONImpl(sv, &bonus, perl_syck_output_handler_pv);
1643 6 ▶ if (SvCUR(buf) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(buf) > 0) { 6 0 6
1644 6 perl_json_postprocess(buf);
1645 }
1646 6 s = SvPV(buf, len);
1647 6 ▶ if (len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len > 0) { 6 0 6
1648 6 ▶ if (PerlIO_write(out, s, len) != (SSize_t)len) {
Branch: 1 branch
BranchTrueFalseTotal
if (PerlIO_write(out, s, len) != (SSize_t)len) { 0 6 6
1649 0 bonus.ioerror = errno;
1650 }
1651 }
1652 }
1653 #else
1654 11 DumpYAMLImpl(sv, &bonus, perl_syck_output_handler_io);
1655 #endif
1656 17 return bonus.ioerror;
1657 }
1658  
1659 int
1660 #ifdef YAML_IS_JSON
1661 7 DumpJSONInto
1662 #else
1663 11 DumpYAMLInto
1664 #endif
1665 (SV *sv, SV *out) {
1666 18 SV *implicit_unicode = GvSV(gv_fetchpv(form("%s::ImplicitUnicode", PACKAGE_NAME), TRUE, SVt_PV));
1667 struct emitter_xtra bonus;
1668 18 if (SvROK(out)) {
1669 18 out = SvRV(out);
1670 18 ▶ if (! SvPOK(out)) {
Branch: 2 branches
BranchTrueFalseTotal
if (! SvPOK(out)) { 6 5 11
if (! SvPOK(out)) { 5 2 7
1671 11 sv_setpv(out, "");
1672 }
1673 } else {
1674 0 return 0; /* perl wrapper should die for us */
1675 }
1676 18 bonus.out.outsv = out;
1677 #ifdef YAML_IS_JSON
1678 7 DumpJSONImpl(sv, &bonus, perl_syck_output_handler_mg);
1679 7 ▶ if (SvCUR(out) > 0) { /* XXX: needs to handle magic? */
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(out) > 0) { /* XXX: needs to handle magic? */ 7 0 7
1680 7 perl_json_postprocess(out);
1681 }
1682 #else
1683 11 DumpYAMLImpl(sv, &bonus, perl_syck_output_handler_mg);
1684 #endif
1685 #ifdef SvUTF8_on
1686 18 ▶ if (SvTRUE(implicit_unicode)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(implicit_unicode)) { 0 11 11
if (SvTRUE(implicit_unicode)) { 0 7 7
1687 0 SvUTF8_on(out); /* XXX: needs to handle magic? */
1688 }
1689 #endif
1690 18 return 1;
1691 }
1692  
« syck_.c ↑ Summary perl_common.h »