perl_syck.h

filter: Statementstmt 92.3% 788 / 853 Branchbran 67.8% 560 / 826 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 80.2% 1348 / 1679 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 9361010 is_bad_alias_object( SV *sv ) {
84 SV *hv, **psv;
85  
86 9361010 ▶ if (! sv_isobject(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (! sv_isobject(sv)) 9360993 17 9361010
87 9360993 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 18723905 yaml_syck_parser_handler
153 #endif
154 (SyckParser *p, SyckNode *n) {
155 18724274 SV *sv = NULL;
156 AV *seq;
157 HV *map;
158 long i;
159 18724274 char *id = n->type_id;
160 #ifndef YAML_IS_JSON
161 18723905 struct parser_xtra *bonus = (struct parser_xtra *)p->bonus;
162 18723905 bool load_code = bonus->load_code;
163 18723905 bool load_blessed = bonus->load_blessed;
164 #endif
165  
166 18724338 ▶ while (id && (*id == '!')) { id++; }
Branch: 4 branches
BranchTrueFalseTotal
while (id && (*id == '!')) { id++; } 18721437 2532 18723969
while (id && (*id == '!')) { id++; } 64 18721373 18721437
while (id && (*id == '!')) { id++; } 297 72 369
while (id && (*id == '!')) { id++; } 0 297 297
167  
168 18724274 switch (n->kind) {
169 18722869 case syck_str_kind:
170 18722869 ▶ if (TYPE_IS_NULL(id)) {
Branch: 4 branches
BranchTrueFalseTotal
if (TYPE_IS_NULL(id)) { 18721325 1247 18722572
if (TYPE_IS_NULL(id)) { 18720506 819 18721325
if (TYPE_IS_NULL(id)) { 297 0 297
if (TYPE_IS_NULL(id)) { 202 95 297
171 37443910 ▶ 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 18721744 18721753
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 18721947 sv = newSVpvn(n->data.str->ptr, n->data.str->len);
177 18721947 ▶ CHECK_UTF8;
Branch: 6 branches
BranchTrueFalseTotal
CHECK_UTF8; 274 18721471 18721745
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 914 ▶ } else if (strEQ( id, "null" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "null" )) { 6 813 819
} else if (strEQ( id, "null" )) { 20 75 95
180 26 sv = newSV(0);
181 888 ▶ } else if (strEQ( id, "bool#yes" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "bool#yes" )) { 13 800 813
} else if (strEQ( id, "bool#yes" )) { 0 75 75
182 13 sv = newSVsv(&PL_sv_yes);
183 875 ▶ } else if (strEQ( id, "bool#no" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "bool#no" )) { 23 777 800
} else if (strEQ( id, "bool#no" )) { 0 75 75
184 23 sv = newSVsv(&PL_sv_no);
185 852 ▶ } else if (strEQ( id, "default" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "default" )) { 2 775 777
} 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 850 ▶ } else if (strEQ( id, "float#base60" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "float#base60" )) { 11 764 775
} 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 839 ▶ } else if (strEQ( id, "float#nan" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "float#nan" )) { 3 761 764
} else if (strEQ( id, "float#nan" )) { 0 75 75
220 3 sv = newSVnv(NV_NAN);
221 #endif
222 #ifdef NV_INF
223 836 ▶ } else if (strEQ( id, "float#inf" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "float#inf" )) { 4 757 761
} else if (strEQ( id, "float#inf" )) { 0 75 75
224 4 sv = newSVnv(NV_INF);
225 832 ▶ } else if (strEQ( id, "float#neginf" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "float#neginf" )) { 3 754 757
} else if (strEQ( id, "float#neginf" )) { 0 75 75
226 3 sv = newSVnv(-NV_INF);
227 #endif
228 829 ▶ } else if (strnEQ( id, "float", 5 )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strnEQ( id, "float", 5 )) { 7 747 754
} 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 822 ▶ } else if (strEQ( id, "int#base60" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "int#base60" )) { 18 729 747
} 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 804 ▶ } else if (strEQ( id, "int#hex" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "int#hex" )) { 16 713 729
} 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 788 ▶ } else if (strEQ( id, "int#oct" )) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "int#oct" )) { 13 700 713
} 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 775 ▶ } else if (strEQ( id, "int" ) ) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (strEQ( id, "int" ) ) { 39 661 700
} else if (strEQ( id, "int" ) ) { 75 0 75
291 UV uv;
292 int flags;
293  
294 114 syck_str_blow_away_commas( n );
295 114 flags = grok_number( n->data.str->ptr, n->data.str->len, &uv);
296  
297 114 if (flags == IS_NUMBER_IN_UV) {
298 108 ▶ if (uv <= IV_MAX) {
Branch: 2 branches
BranchTrueFalseTotal
if (uv <= IV_MAX) { 34 0 34
if (uv <= IV_MAX) { 74 0 74
299 108 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 18722858 break;
461  
462 120 case syck_seq_kind:
463 /* load the seq into a new AV and place a ref to it in the SV */
464 120 seq = newAV();
465 392 ▶ for (i = 0; i < n->data.list->idx; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n->data.list->idx; i++) { 208 92 300
for (i = 0; i < n->data.list->idx; i++) { 64 28 92
466 272 SV *a = perl_syck_lookup_sym(p, syck_seq_read(n, i));
467 #ifndef YAML_IS_JSON
468 const char *forward_anchor;
469  
470 208 a = sv_2mortal(newSVsv(a));
471 208 forward_anchor = is_bad_alias_object(a);
472 208 ▶ if (forward_anchor)
Branch: 1 branch
BranchTrueFalseTotal
if (forward_anchor) 0 208 208
473 0 register_bad_alias(p, forward_anchor, a);
474 #endif
475 272 av_push(seq, a);
476 272 USE_OBJECT(a);
477 }
478 /* create the ref to the new array in the sv */
479 120 sv = newRV_noinc((SV*)seq);
480 #ifndef YAML_IS_JSON
481  
482 92 ▶ if (id) {
Branch: 1 branch
BranchTrueFalseTotal
if (id) { 5 87 92
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 120 break;
514  
515 1285 case syck_map_kind:
516 #ifndef YAML_IS_JSON
517 1250 ▶ 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 1198 1241
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 1232 ▶ 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 1198 1232
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 1239 ▶ 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 1198 1232
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 1225 AV *merge_values = NULL;
628 #endif
629 1269 map = newHV();
630 9362149 ▶ for (i = 0; i < n->data.pairs->idx; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < n->data.pairs->idx; i++) { 9360802 1225 9362027
for (i = 0; i < n->data.pairs->idx; i++) { 78 44 122
631 9360880 SV* key = perl_syck_lookup_sym(p, syck_map_read(n, map_key, i));
632 9360880 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 9360802 val = sv_2mortal(newSVsv(val));
637 9360802 forward_anchor = is_bad_alias_object(val);
638 9360802 ▶ if (forward_anchor)
Branch: 1 branch
BranchTrueFalseTotal
if (forward_anchor) 10 9360792 9360802
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 9360802 ▶ if (p->implicit_typing) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->implicit_typing) { 183 9360619 9360802
645 STRLEN klen;
646 183 const char *kpv = SvPV(key, klen);
647 183 ▶ if (klen == 2 && kpv[0] == '<' && kpv[1] == '<') {
Branch: 3 branches
BranchTrueFalseTotal
if (klen == 2 && kpv[0] == '<' && kpv[1] == '<') { 10 173 183
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 9360873 ▶ if (hv_store_ent(map, key, val, 0) != NULL)
Branch: 2 branches
BranchTrueFalseTotal
if (hv_store_ent(map, key, val, 0) != NULL) 9360795 0 9360795
if (hv_store_ent(map, key, val, 0) != NULL) 78 0 78
657 9360873 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 1225 ▶ if (merge_values) {
Branch: 1 branch
BranchTrueFalseTotal
if (merge_values) { 7 1218 1225
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 1269 sv = newRV_noinc((SV*)map);
710 #ifndef YAML_IS_JSON
711 1225 ▶ if (id) {
Branch: 1 branch
BranchTrueFalseTotal
if (id) { 27 1198 1225
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 1285 break;
743 }
744  
745 #ifndef YAML_IS_JSON
746 /* Fix bad anchors using sv_setsv */
747 18723894 ▶ if (n->id) {
Branch: 1 branch
BranchTrueFalseTotal
if (n->id) { 7 18723887 18723894
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 18724263 TRACK_OBJECT(sv);
756  
757 18724263 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 2225 cleanup_parser(pTHX_ void *p) {
883 2225 SyckParser **pp = (SyckParser **)p;
884 2225 ▶ if (*pp != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (*pp != NULL) { 22 2203 2225
885 22 syck_free_parser(*pp);
886 22 *pp = NULL;
887 }
888 2225 }
889 #endif
890  
891 #ifdef YAML_IS_JSON
892 149 static SV * LoadJSON (char *s) {
893 #else
894 2180 static SV * LoadYAML (char *s) {
895 #endif
896 SYMID v;
897 SyckParser *parser;
898 struct parser_xtra bonus;
899  
900 2329 SV *obj = &PL_sv_undef;
901 2329 SV *use_code = GvSV(gv_fetchpv(form("%s::UseCode", PACKAGE_NAME), TRUE, SVt_PV));
902 2329 SV *load_code = GvSV(gv_fetchpv(form("%s::LoadCode", PACKAGE_NAME), TRUE, SVt_PV));
903 2329 SV *implicit_typing = GvSV(gv_fetchpv(form("%s::ImplicitTyping", PACKAGE_NAME), TRUE, SVt_PV));
904 2329 SV *implicit_unicode = GvSV(gv_fetchpv(form("%s::ImplicitUnicode", PACKAGE_NAME), TRUE, SVt_PV));
905 2329 SV *singlequote = GvSV(gv_fetchpv(form("%s::SingleQuote", PACKAGE_NAME), TRUE, SVt_PV));
906 2329 SV *load_blessed = GvSV(gv_fetchpv(form("%s::LoadBlessed", PACKAGE_NAME), TRUE, SVt_PV));
907 2329 ▶ json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' );
Branch: 2 branches
BranchTrueFalseTotal
json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' ); 14 2166 2180
json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' ); 53 96 149
908  
909 2329 ENTER; SAVETMPS;
910  
911 /* Don't even bother if the string is empty. */
912 2329 ▶ if (*s == '\0') { FREETMPS; LEAVE; return &PL_sv_undef; }
Branch: 4 branches
BranchTrueFalseTotal
if (*s == '\0') { FREETMPS; LEAVE; return &PL_sv_undef; } 104 2076 2180
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 2076 ▶ if (strnEQ( s, "--- #YAML:1.0", 13)) {
Branch: 1 branch
BranchTrueFalseTotal
if (strnEQ( s, "--- #YAML:1.0", 13)) { 2 2074 2076
920 2 s[4] = '%';
921 }
922 #endif
923  
924 2225 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 2225 SAVEDESTRUCTOR_X(cleanup_parser, &parser);
929  
930 2225 syck_parser_str_auto(parser, s, NULL);
931 2225 syck_parser_handler(parser, PERL_SYCK_PARSER_HANDLER);
932 2225 syck_parser_error_handler(parser, perl_syck_error_handler);
933 2225 syck_parser_bad_anchor_handler( parser, perl_syck_bad_anchor_handler );
934 2225 syck_parser_implicit_typing(parser, SvTRUE(implicit_typing));
935 2225 syck_parser_taguri_expansion(parser, 0);
936  
937 2225 bonus.objects = (AV*)sv_2mortal((SV*)newAV());
938 2225 bonus.implicit_unicode = SvTRUE(implicit_unicode);
939 2225 ▶ bonus.load_code = SvTRUE(use_code) || SvTRUE(load_code);
Branch: 4 branches
BranchTrueFalseTotal
bonus.load_code = SvTRUE(use_code) || SvTRUE(load_code); 1559 517 2076
bonus.load_code = SvTRUE(use_code) || SvTRUE(load_code); 4 1555 1559
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 2225 bonus.load_blessed = SvTRUE(load_blessed);
941 2225 parser->bonus = &bonus;
942  
943 #ifndef YAML_IS_JSON
944 2076 bonus.bad_anchors = (HV*)sv_2mortal((SV*)newHV());
945  
946 2076 ▶ if (GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) { 214 1862 2076
947 214 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 214 obj = (SV*)sv_2mortal((SV*)newAV());
952 450 ▶ while ((v = syck_parse(parser)) && (v != prev_v)) {
Branch: 2 branches
BranchTrueFalseTotal
while ((v = syck_parse(parser)) && (v != prev_v)) { 450 0 450
while ((v = syck_parse(parser)) && (v != prev_v)) { 236 214 450
953 236 SV *cur = &PL_sv_undef;
954 236 ▶ if (!syck_lookup_sym(parser, v, (char **)&cur)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!syck_lookup_sym(parser, v, (char **)&cur)) { 0 236 236
955 0 break;
956 }
957  
958 236 av_push((AV*)obj, cur);
959 236 USE_OBJECT(cur);
960  
961 236 prev_v = v;
962 }
963 214 obj = newRV_inc(obj);
964 }
965 else
966 #endif
967 {
968 2011 v = syck_parse(parser);
969 1989 ▶ if (syck_lookup_sym(parser, v, (char **)&obj)) {
Branch: 2 branches
BranchTrueFalseTotal
if (syck_lookup_sym(parser, v, (char **)&obj)) { 1840 0 1840
if (syck_lookup_sym(parser, v, (char **)&obj)) { 149 0 149
970 1989 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 2203 syck_free_parser(parser);
977 2203 parser = NULL;
978  
979 /* In JSON mode, SAVEFREEPV(s) frees the preprocessed string at LEAVE. */
980  
981 2203 ▶ FREETMPS; LEAVE;
Branch: 2 branches
BranchTrueFalseTotal
FREETMPS; LEAVE; 2054 0 2054
FREETMPS; LEAVE; 149 0 149
982  
983 2203 return obj;
984 }
985  
986 void
987 #ifdef YAML_IS_JSON
988 25652 json_syck_mark_emitter
989 #else
990 7680 yaml_syck_mark_emitter
991 #endif
992 (SyckEmitter *e, SV *sv) {
993 33332 e->depth++;
994  
995 33332 ▶ 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 7490 7680
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 33140 ▶ if (e->depth >= e->max_depth) {
Branch: 2 branches
BranchTrueFalseTotal
if (e->depth >= e->max_depth) { 3 7487 7490
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 33091 ▶ if (SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(sv)) { 3100 4387 7487
if (SvROK(sv)) { 12683 12921 25604
1009 15783 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 3239 e->depth--;
1014 3239 return;
1015 }
1016  
1017 17308 switch (SvTYPE(sv)) {
1018 8548 case SVt_PVAV: {
1019 I32 len, i;
1020 8548 len = av_len((AV*)sv) + 1;
1021 11148 ▶ for (i = 0; i < len; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 2469 1077 3546
for (i = 0; i < len; i++) { 6761 841 7602
1022 9230 SV** sav = av_fetch((AV*)sv, i, 0);
1023 9230 if (sav != NULL) {
1024 9230 PERL_SYCK_MARK_EMITTER( e, *sav );
1025 }
1026 }
1027 1918 break;
1028 }
1029 6518 case SVt_PVHV: {
1030 HE *he;
1031 6518 hv_iterinit((HV*)sv);
1032 #ifdef HV_ITERNEXT_WANTPLACEHOLDERS
1033 7448 ▶ 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) { 868 593 1461
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 6795 SV *val = hv_iterval((HV*)sv, he);
1038 6795 PERL_SYCK_MARK_EMITTER( e, val );
1039 }
1040 653 break;
1041 }
1042 2242 default:
1043 2242 break;
1044 }
1045  
1046 #ifdef YAML_IS_JSON
1047 1191 st_insert(e->markers, (st_data_t)sv, 0);
1048 #endif
1049 4813 --e->depth;
1050 }
1051  
1052  
1053 void
1054 #ifdef YAML_IS_JSON
1055 2167 json_syck_emitter_handler
1056 #else
1057 7032 yaml_syck_emitter_handler
1058 #endif
1059 (SyckEmitter *e, st_data_t data) {
1060 I32 len, i;
1061 9199 SV* sv = (SV*)data;
1062 9199 struct emitter_xtra *bonus = (struct emitter_xtra *)e->bonus;
1063 9199 char* tag = bonus->tag;
1064 9199 svtype ty = SvTYPE(sv);
1065 #ifndef YAML_IS_JSON
1066 7032 char dump_code = bonus->dump_code;
1067 7032 char implicit_binary = bonus->implicit_binary;
1068 7032 char* ref = NULL;
1069 7032 char* ref_orig = NULL;
1070 #endif
1071  
1072 #define OBJECT_TAG "tag:!perl:"
1073
1074 9199 ▶ if (SvMAGICAL(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvMAGICAL(sv)) { 17 7015 7032
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 7032 ▶ if (sv_isobject(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(sv)) { 68 6964 7032
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 7032 ▶ if (ref_orig != NULL && !SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref_orig != NULL && !SvROK(sv)) { 68 6964 7032
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 9195 ▶ if (SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(sv)) { 2317 4711 7028
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 2317 switch (SvTYPE(SvRV(sv))) {
1203 2079 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 2079 e->indent = 0;
1208 2079 syck_emit_item(e, (st_data_t)SvRV(sv));
1209 2058 e->indent = PERL_SYCK_INDENT_LEVEL;
1210 2058 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 5970 ▶ else if (ty == SVt_NULL) {
Branch: 2 branches
BranchTrueFalseTotal
else if (ty == SVt_NULL) { 7 4704 4711
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 5946 ▶ else if ((ty == SVt_PVMG) && !SvOK(sv)) {
Branch: 4 branches
BranchTrueFalseTotal
else if ((ty == SVt_PVMG) && !SvOK(sv)) { 19 4685 4704
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 8586 ▶ else if (SvPOK(sv) && ty != SVt_PVCV) {
Branch: 4 branches
BranchTrueFalseTotal
else if (SvPOK(sv) && ty != SVt_PVCV) { 2419 2282 4701
else if (SvPOK(sv) && ty != SVt_PVCV) { 2415 4 2419
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 2643 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 2415 ▶ if (looks_like_number(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (looks_like_number(sv)) { 558 1857 2415
1250 558 ▶ if(!(SvIOK(sv) || SvNOK(sv))) {
Branch: 2 branches
BranchTrueFalseTotal
if(!(SvIOK(sv) || SvNOK(sv))) { 557 1 558
if(!(SvIOK(sv) || SvNOK(sv))) { 557 0 557
1251 /* POK-only: string that looks numeric — quote to preserve type */
1252 1114 ▶ 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 557 557
1253 }
1254 2 ▶ else if(syck_str_is_unquotable_integer(SvPV_nolen(sv), sv_len(sv))) {
Branch: 1 branch
BranchTrueFalseTotal
else if(syck_str_is_unquotable_integer(SvPV_nolen(sv), sv_len(sv))) { 1 0 1
1255 /* emit an unquoted number only if it's a very basic integer. /^-?[1-9][0-9]*$/ */
1256 2 ▶ 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 1 1
1257 }
1258 else {
1259 /* Even though it looks like a number, quote it or it won't round trip correctly. */
1260 0 ▶ 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 0 0
1261 }
1262 }
1263 else
1264 #endif
1265 2085 if (len == 0) {
1266 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
1267 }
1268 1855 ▶ else if (IS_UTF8(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (IS_UTF8(sv)) { 136 1719 1855
1269 /* if we support UTF8 and the string contains UTF8 */
1270 351 enum scalar_style old_s = e->style;
1271 351 e->style = SCALAR_UTF8;
1272 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
1273 351 e->style = old_s;
1274 }
1275 #ifndef YAML_IS_JSON
1276 1719 ▶ else if (implicit_binary) {
Branch: 1 branch
BranchTrueFalseTotal
else if (implicit_binary) { 47 1672 1719
1277 /* scan string for high-bits in the SV */
1278 47 bool is_ascii = TRUE;
1279 47 char *str = SvPV_nolen(sv);
1280 47 STRLEN bin_len = sv_len(sv);
1281 STRLEN bi;
1282  
1283 347 ▶ for (bi = 0; bi < bin_len; bi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (bi = 0; bi < bin_len; bi++) { 301 46 347
1284 301 ▶ if (*(str + bi) & 0x80) {
Branch: 1 branch
BranchTrueFalseTotal
if (*(str + bi) & 0x80) { 1 300 301
1285 /* Binary here */
1286 1 char *base64 = syck_base64enc( str, bin_len );
1287 1 syck_emit_scalar(e, "tag:yaml.org,2002:binary", SCALAR_STRING, 0, 0, 0, base64, strlen(base64));
1288 1 syck_base64_free(base64);
1289 1 is_ascii = FALSE;
1290 1 break;
1291 }
1292 }
1293  
1294 47 ▶ if (is_ascii) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ascii) { 46 1 47
1295 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
1296 }
1297 }
1298 #endif
1299 else {
1300 3344 ▶ 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 1663 1672
1301 }
1302 }
1303 3300 ▶ else if (SvNIOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
else if (SvNIOK(sv)) { 179 2107 2286
else if (SvNIOK(sv)) { 103 911 1014
1304 /* Stringify the sv, being careful not to overwrite its PV part */
1305 282 SV *sv2 = newSVsv(sv);
1306 STRLEN len;
1307 282 char *str = SvPV(sv2, len);
1308 282 ▶ if (SvIOK(sv) /* original SV was an int */
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(sv) /* original SV was an int */ 163 16 179
if (SvIOK(sv) /* original SV was an int */ 103 0 103
1309 266 ▶ && 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 */ 161 2 163
&& syck_str_is_unquotable_integer(str, len)) /* small enough to safely round-trip */ 103 0 103
1310 {
1311 264 ▶ 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 160 161
1312 } else {
1313 /* We need to quote it */
1314 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
1315 }
1316 282 SvREFCNT_dec(sv2);
1317 }
1318 else {
1319 3018 switch (ty) {
1320 1920 case SVt_PVAV: { /* array */
1321 1920 ▶ syck_emit_seq(e, OBJOF("array"), SEQ_NONE);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_seq(e, OBJOF("array"), SEQ_NONE); 8 1070 1078
1322 1920 e->indent = PERL_SYCK_INDENT_LEVEL;
1323  
1324 1920 *tag = '\0';
1325 1920 len = av_len((AV*)sv) + 1;
1326 4525 ▶ for (i = 0; i < len; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 1707 1078 2785
for (i = 0; i < len; i++) { 898 842 1740
1327 2605 SV** sav = av_fetch((AV*)sv, i, 0);
1328 2605 if (sav == NULL) {
1329 0 syck_emit_item( e, (st_data_t)(&PL_sv_undef) );
1330 }
1331 else {
1332 2605 syck_emit_item( e, (st_data_t)(*sav) );
1333 }
1334 }
1335 1920 syck_emit_end(e);
1336 1920 return;
1337 }
1338 656 case SVt_PVHV: { /* hash */
1339 656 HV *hv = (HV*)sv;
1340 HE *he;
1341 656 ▶ syck_emit_map(e, OBJOF("hash"), MAP_NONE);
Branch: 1 branch
BranchTrueFalseTotal
syck_emit_map(e, OBJOF("hash"), MAP_NONE); 20 574 594
1342 656 e->indent = PERL_SYCK_INDENT_LEVEL;
1343  
1344 656 *tag = '\0';
1345 656 hv_iterinit((HV*)sv);
1346  
1347 656 if (e->sort_keys) {
1348 593 AV *av = (AV*)sv_2mortal((SV*)newAV());
1349 #ifdef HV_ITERNEXT_WANTPLACEHOLDERS
1350 1436 ▶ while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 843 593 1436
while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) != NULL) { 0 0 0
1351 #else
1352 while ((he = hv_iternext(hv)) != NULL) {
1353 #endif
1354 843 SV *key = hv_iterkeysv(he);
1355 843 av_store(av, AvFILLp(av)+1, key); /* av_push(), really */
1356 }
1357 593 len = av_len(av) + 1;
1358 593 STORE_HASH_SORT;
1359 1436 ▶ for (i = 0; i < len; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 843 593 1436
for (i = 0; i < len; i++) { 0 0 0
1360 843 SV *key = av_shift(av);
1361 843 HE *he = hv_fetch_ent(hv, key, 0, 0);
1362 843 ▶ SV *val = he ? HeVAL(he) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *val = he ? HeVAL(he) : &PL_sv_undef; 843 0 843
SV *val = he ? HeVAL(he) : &PL_sv_undef; 0 0 0
1363 843 ▶ if (val == NULL) { val = &PL_sv_undef; }
Branch: 2 branches
BranchTrueFalseTotal
if (val == NULL) { val = &PL_sv_undef; } 0 843 843
if (val == NULL) { val = &PL_sv_undef; } 0 0 0
1364 843 syck_emit_item( e, (st_data_t)key );
1365 843 syck_emit_item( e, (st_data_t)val );
1366 }
1367 }
1368 else {
1369 #ifdef HV_ITERNEXT_WANTPLACEHOLDERS
1370 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
1371 #else
1372 while ((he = hv_iternext(hv)) != NULL) {
1373 #endif
1374 89 SV *key = hv_iterkeysv(he);
1375 89 SV *val = hv_iterval(hv, he);
1376 89 syck_emit_item( e, (st_data_t)key );
1377 89 syck_emit_item( e, (st_data_t)val );
1378 }
1379 }
1380 /* reset the hash pointer */
1381 656 hv_iterinit(hv);
1382 656 syck_emit_end(e);
1383 656 return;
1384 }
1385 236 case SVt_PVCV: { /* code */
1386 #ifdef YAML_IS_JSON
1387 1 syck_emit_scalar(e, "str", scalar_plain, 0, 0, 0, NULL_LITERAL, NULL_LITERAL_LENGTH);
1388 #else
1389  
1390 /* This following code is mostly copypasted from Storable */
1391  
1392 #if PERL_VERSION < 8
1393 syck_emit_scalar(e, OBJOF("tag:!perl:code:"), SCALAR_QUOTED, 0, 0, 0, "{ \"DUMMY\" }", 11);
1394 #else
1395 235 ▶ if ( !dump_code ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !dump_code ) { 3 232 235
1396 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
1397 }
1398 else {
1399 232 dSP;
1400 int count, reallen;
1401 SV *text;
1402 232 CV *cv = (CV*)sv;
1403 232 SV *bdeparse = GvSV(gv_fetchpv(form("%s::DeparseObject", PACKAGE_NAME), TRUE, SVt_PV));
1404  
1405 232 ▶ if (!SvTRUE(bdeparse)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvTRUE(bdeparse)) { 0 232 232
1406 0 croak("B::Deparse initialization failed -- cannot dump code object");
1407 }
1408  
1409 232 ENTER;
1410 232 SAVETMPS;
1411  
1412 /*
1413 * call the coderef2text method
1414 */
1415  
1416 232 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 232 232
1417 232 ▶ XPUSHs(bdeparse); /* XXX is this already mortal? */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(bdeparse); /* XXX is this already mortal? */ 0 232 232
1418 232 ▶ XPUSHs(sv_2mortal(newRV_inc((SV*)cv)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_inc((SV*)cv))); 0 232 232
1419 232 PUTBACK;
1420 232 count = call_method("coderef2text", G_SCALAR);
1421 232 SPAGAIN;
1422 232 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 232 232
1423 0 croak("Unexpected return value from B::Deparse::coderef2text\n");
1424 }
1425  
1426 232 text = POPs;
1427 232 reallen = strlen(SvPV_nolen(text));
1428  
1429 /*
1430 * Empty code references or XS functions are deparsed as
1431 * "(prototype) ;" or ";".
1432 */
1433  
1434 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
1435 21 croak("The result of B::Deparse::coderef2text was empty - maybe you're trying to serialize an XS function?\n");
1436 }
1437  
1438 /*
1439 * Now store the source code.
1440 */
1441  
1442 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
1443  
1444 211 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 211 0 211
1445 211 LEAVE;
1446  
1447 /* END Storable */
1448 }
1449 #endif
1450 #endif
1451 215 *tag = '\0';
1452 215 break;
1453 }
1454 200 case SVt_PVGV: /* glob (not a filehandle, a symbol table entry) */
1455 case SVt_PVFM: { /* format */
1456 /* XXX TODO XXX */
1457 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
1458 200 break;
1459 }
1460 0 case SVt_PVIO: { /* filehandle */
1461 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
1462 0 break;
1463 }
1464 6 default: {
1465 6 syck_emit_scalar(e, "str", scalar_plain, 0, 0, 0, NULL_LITERAL, NULL_LITERAL_LENGTH);
1466 }
1467 }
1468 }
1469 /* cleanup: */
1470 1263 *tag = '\0';
1471 #ifndef YAML_IS_JSON
1472 5314 ▶ if (ref_orig != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref_orig != NULL) { 64 5250 5314
1473 64 Safefree(ref_orig);
1474 64 bonus->cur_ref = NULL; /* already freed — prevent double-free in destructor */
1475 }
1476 #endif
1477 }
1478  
1479 /* Destructor for SAVEDESTRUCTOR_X: frees emitter and tag buffer on croak.
1480 * Registered after allocation so Perl's scope unwinding handles cleanup
1481 * even when a croak() longjmps past the normal return path.
1482 * Guarded because perl_syck.h is included twice (YAML and JSON modes). */
1483 #ifndef CLEANUP_EMITTER_BONUS_DEFINED
1484 #define CLEANUP_EMITTER_BONUS_DEFINED
1485 static void
1486 1524 cleanup_emitter_bonus(pTHX_ void *p) {
1487 1524 struct emitter_xtra *bonus = (struct emitter_xtra *)p;
1488 1524 ▶ if (bonus->cur_ref != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bonus->cur_ref != NULL) { 0 1524 1524
1489 0 Safefree(bonus->cur_ref);
1490 0 bonus->cur_ref = NULL;
1491 }
1492 1524 ▶ if (bonus->emitter != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bonus->emitter != NULL) { 70 1454 1524
1493 70 syck_free_emitter((SyckEmitter *)bonus->emitter);
1494 70 bonus->emitter = NULL;
1495 }
1496 1524 ▶ if (bonus->tag != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bonus->tag != NULL) { 70 1454 1524
1497 70 Safefree(bonus->tag);
1498 70 bonus->tag = NULL;
1499 }
1500 1524 }
1501 #endif
1502  
1503 void
1504 #ifdef YAML_IS_JSON
1505 281 DumpJSONImpl
1506 #else
1507 1243 DumpYAMLImpl
1508 #endif
1509 (SV *sv, struct emitter_xtra *bonus, SyckOutputHandler output_handler) {
1510 SyckEmitter *emitter;
1511 1524 SV *headless = GvSV(gv_fetchpv(form("%s::Headless", PACKAGE_NAME), TRUE, SVt_PV));
1512 1524 SV *implicit_binary = GvSV(gv_fetchpv(form("%s::ImplicitBinary", PACKAGE_NAME), TRUE, SVt_PV));
1513 1524 SV *use_code = GvSV(gv_fetchpv(form("%s::UseCode", PACKAGE_NAME), TRUE, SVt_PV));
1514 1524 SV *dump_code = GvSV(gv_fetchpv(form("%s::DumpCode", PACKAGE_NAME), TRUE, SVt_PV));
1515 1524 SV *sortkeys = GvSV(gv_fetchpv(form("%s::SortKeys", PACKAGE_NAME), TRUE, SVt_PV));
1516 1524 SV *max_depth = GvSV(gv_fetchpv(form("%s::MaxDepth", PACKAGE_NAME), TRUE, SVt_PV));
1517 #ifdef YAML_IS_JSON
1518 281 SV *singlequote = GvSV(gv_fetchpv(form("%s::SingleQuote", PACKAGE_NAME), TRUE, SVt_PV));
1519 281 ▶ json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' );
Branch: 1 branch
BranchTrueFalseTotal
json_quote_char = (SvTRUE(singlequote) ? '\'' : '"' ); 57 224 281
1520 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
1521 #else
1522 1243 SV *singlequote = GvSV(gv_fetchpv(form("%s::SingleQuote", PACKAGE_NAME), TRUE, SVt_PV));
1523 1243 yaml_quote_style = (SvTRUE(singlequote) ? scalar_1quote : scalar_none);
1524 #endif
1525  
1526 1524 ENTER; SAVETMPS;
1527  
1528 /* Initialize B::Deparse BEFORE allocating the emitter, so that if
1529 * eval_pv croaks (longjmp) we don't leak the SyckEmitter. */
1530 #ifndef YAML_IS_JSON
1531 1243 ▶ if (SvTRUE(use_code) || SvTRUE(dump_code)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(use_code) || SvTRUE(dump_code)) { 424 819 1243
if (SvTRUE(use_code) || SvTRUE(dump_code)) { 28 396 424
1532 847 SV *bdeparse = GvSV(gv_fetchpv(form("%s::DeparseObject", PACKAGE_NAME), TRUE, SVt_PV));
1533  
1534 847 ▶ if (!SvTRUE(bdeparse)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvTRUE(bdeparse)) { 5 842 847
1535 5 eval_pv(form(
1536 "local $@; require B::Deparse; $%s::DeparseObject = B::Deparse->new",
1537 PACKAGE_NAME
1538 ), 1);
1539 }
1540 }
1541 #endif
1542  
1543 1524 emitter = syck_new_emitter();
1544  
1545 1524 if (SvIOK(max_depth))
1546 282 emitter->max_depth = SvIV(max_depth);
1547 #ifdef YAML_IS_JSON
1548 else
1549 0 emitter->max_depth = json_max_depth;
1550 281 emitter->indent = PERL_SYCK_INDENT_LEVEL;
1551 281 emitter->json_mode = 1;
1552 #endif
1553  
1554 1524 emitter->headless = SvTRUE(headless);
1555 1524 emitter->sort_keys = SvTRUE(sortkeys);
1556 1524 emitter->anchor_format = "%d";
1557  
1558 1524 New(801, bonus->tag, 512, char);
1559 1524 bonus->tag_len = 512;
1560 1524 *(bonus->tag) = '\0';
1561 1524 ▶ bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code);
Branch: 4 branches
BranchTrueFalseTotal
bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code); 424 819 1243
bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code); 28 396 424
bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code); 281 0 281
bonus->dump_code = SvTRUE(use_code) || SvTRUE(dump_code); 0 281 281
1562 1524 bonus->implicit_binary = SvTRUE(implicit_binary);
1563 1524 bonus->emitter = emitter;
1564 1524 bonus->cur_ref = NULL;
1565 1524 emitter->bonus = bonus;
1566  
1567 /* Register destructor so croak() in callbacks (mark_emitter,
1568 * emitter_handler) won't leak the emitter or tag buffer. */
1569 1524 SAVEDESTRUCTOR_X(cleanup_emitter_bonus, bonus);
1570  
1571 1524 syck_emitter_handler( emitter, PERL_SYCK_EMITTER_HANDLER );
1572 1524 syck_output_handler( emitter, output_handler );
1573  
1574 1524 PERL_SYCK_MARK_EMITTER( emitter, sv );
1575  
1576 #ifdef YAML_IS_JSON
1577 235 st_free_table(emitter->markers);
1578 235 emitter->markers = st_init_numtable();
1579 #endif
1580  
1581 1475 syck_emit( emitter, (st_data_t)sv );
1582 1454 syck_emitter_flush( emitter, 0 );
1583  
1584 /* Normal path: clean up now and NULL the pointers so the
1585 * SAVEDESTRUCTOR_X callback (at LEAVE) becomes a no-op. */
1586 1454 syck_free_emitter( emitter );
1587 1454 bonus->emitter = NULL;
1588 1454 Safefree(bonus->tag);
1589 1454 bonus->tag = NULL;
1590  
1591 1454 ▶ FREETMPS; LEAVE;
Branch: 2 branches
BranchTrueFalseTotal
FREETMPS; LEAVE; 1077 142 1219
FREETMPS; LEAVE; 52 183 235
1592  
1593 1454 return;
1594 }
1595  
1596  
1597 SV*
1598 #ifdef YAML_IS_JSON
1599 268 DumpJSON
1600 #else
1601 1221 DumpYAML
1602 #endif
1603 (SV *sv) {
1604 1489 SV *implicit_unicode = GvSV(gv_fetchpv(form("%s::ImplicitUnicode", PACKAGE_NAME), TRUE, SVt_PV));
1605 struct emitter_xtra bonus;
1606 /* Mortalize so croak inside DumpImpl won't leak the SV.
1607 * SvREFCNT_inc before return counteracts the XS wrapper's sv_2mortal. */
1608 1489 SV *out = sv_2mortal(newSVpvn("", 0));
1609 1489 bonus.out.outsv = out;
1610 #ifdef YAML_IS_JSON
1611 268 DumpJSONImpl(sv, &bonus, perl_syck_output_handler_pv);
1612 222 ▶ if (SvCUR(out) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(out) > 0) { 222 0 222
1613 222 perl_json_postprocess(out);
1614 }
1615 #else
1616 1221 DumpYAMLImpl(sv, &bonus, perl_syck_output_handler_pv);
1617 #endif
1618 #ifdef SvUTF8_on
1619 1419 ▶ if (SvTRUE(implicit_unicode)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(implicit_unicode)) { 138 1059 1197
if (SvTRUE(implicit_unicode)) { 52 170 222
1620 190 SvUTF8_on(out);
1621 }
1622 #endif
1623 1419 ▶ SvREFCNT_inc_simple_void(out);
Branch: 2 branches
BranchTrueFalseTotal
SvREFCNT_inc_simple_void(out); 1197 0 1197
SvREFCNT_inc_simple_void(out); 222 0 222
1624 1419 return out;
1625 }
1626  
1627 int
1628 #ifdef YAML_IS_JSON
1629 6 DumpJSONFile
1630 #else
1631 11 DumpYAMLFile
1632 #endif
1633 (SV *sv, PerlIO *out) {
1634 struct emitter_xtra bonus;
1635 17 bonus.out.outio = out;
1636 17 bonus.ioerror = 0;
1637 #ifdef YAML_IS_JSON
1638 {
1639 /* Buffer into an SV so we can apply perl_json_postprocess(),
1640 * then write the postprocessed result to the file handle.
1641 * Mortalize buf so croak inside DumpJSONImpl won't leak it. */
1642 6 SV *buf = sv_2mortal(newSVpvn("", 0));
1643 STRLEN len;
1644 char *s;
1645 6 bonus.out.outsv = buf;
1646 6 DumpJSONImpl(sv, &bonus, perl_syck_output_handler_pv);
1647 6 ▶ if (SvCUR(buf) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(buf) > 0) { 6 0 6
1648 6 perl_json_postprocess(buf);
1649 }
1650 6 s = SvPV(buf, len);
1651 6 ▶ if (len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len > 0) { 6 0 6
1652 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
1653 0 bonus.ioerror = errno;
1654 }
1655 }
1656 }
1657 #else
1658 11 DumpYAMLImpl(sv, &bonus, perl_syck_output_handler_io);
1659 #endif
1660 17 return bonus.ioerror;
1661 }
1662  
1663 int
1664 #ifdef YAML_IS_JSON
1665 7 DumpJSONInto
1666 #else
1667 11 DumpYAMLInto
1668 #endif
1669 (SV *sv, SV *out) {
1670 18 SV *implicit_unicode = GvSV(gv_fetchpv(form("%s::ImplicitUnicode", PACKAGE_NAME), TRUE, SVt_PV));
1671 struct emitter_xtra bonus;
1672 18 if (SvROK(out)) {
1673 18 out = SvRV(out);
1674 18 ▶ if (! SvPOK(out)) {
Branch: 2 branches
BranchTrueFalseTotal
if (! SvPOK(out)) { 6 5 11
if (! SvPOK(out)) { 5 2 7
1675 11 sv_setpv(out, "");
1676 }
1677 } else {
1678 0 return 0; /* perl wrapper should die for us */
1679 }
1680 18 bonus.out.outsv = out;
1681 #ifdef YAML_IS_JSON
1682 7 DumpJSONImpl(sv, &bonus, perl_syck_output_handler_mg);
1683 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
1684 7 perl_json_postprocess(out);
1685 }
1686 #else
1687 11 DumpYAMLImpl(sv, &bonus, perl_syck_output_handler_mg);
1688 #endif
1689 #ifdef SvUTF8_on
1690 18 ▶ if (SvTRUE(implicit_unicode)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(implicit_unicode)) { 0 11 11
if (SvTRUE(implicit_unicode)) { 0 7 7
1691 0 SvUTF8_on(out); /* XXX: needs to handle magic? */
1692 }
1693 #endif
1694 18 return 1;
1695 }
1696  
« syck_.c ↑ Summary perl_common.h »