| 1 |
|
| #include "perl_libyaml.h" |
| 2 |
|
| |
| 3 |
|
| static SV * |
| 4 |
|
| load_node(YAML *self); |
| 5 |
|
| static SV * |
| 6 |
|
| load_mapping(YAML *self, char *tag); |
| 7 |
|
| static SV * |
| 8 |
|
| load_sequence(YAML *); |
| 9 |
|
| static SV * |
| 10 |
|
| load_scalar(YAML *); |
| 11 |
|
| static SV * |
| 12 |
|
| load_alias(YAML *); |
| 13 |
|
| static SV * |
| 14 |
|
| load_scalar_ref(YAML *); |
| 15 |
|
| static SV * |
| 16 |
|
| load_regexp(YAML *); |
| 17 |
|
| static SV * |
| 18 |
|
| load_glob(YAML *); |
| 19 |
|
| static SV * |
| 20 |
|
| load_code(YAML *); |
| 21 |
|
| static void |
| 22 |
|
| dump_prewalk(YAML *, SV *); |
| 23 |
|
| static void |
| 24 |
|
| dump_document(YAML *, SV *); |
| 25 |
|
| static void |
| 26 |
|
| dump_node(YAML *, SV *); |
| 27 |
|
| static void |
| 28 |
|
| dump_hash(YAML *, SV *, yaml_char_t *, yaml_char_t *); |
| 29 |
|
| static void |
| 30 |
|
| dump_array(YAML *, SV *); |
| 31 |
|
| static void |
| 32 |
|
| dump_scalar(YAML *, SV *, yaml_char_t *); |
| 33 |
|
| static void |
| 34 |
|
| dump_ref(YAML *, SV *); |
| 35 |
|
| static void |
| 36 |
|
| dump_code(YAML *, SV *); |
| 37 |
|
| static SV* |
| 38 |
|
| dump_glob(YAML *, SV *); |
| 39 |
|
| static yaml_char_t * |
| 40 |
|
| get_yaml_anchor(YAML *, SV *); |
| 41 |
|
| static yaml_char_t * |
| 42 |
|
| get_yaml_tag(SV *); |
| 43 |
|
| static int |
| 44 |
|
| yaml_sv_write_handler(void *sv, unsigned char *buffer, size_t size); |
| 45 |
|
| static int |
| 46 |
|
| yaml_perlio_read_handler(void *data, unsigned char *buffer, size_t size, size_t *size_read); |
| 47 |
|
| static int |
| 48 |
|
| yaml_perlio_write_handler(void *data, unsigned char *buffer, size_t size); |
| 49 |
|
| |
| 50 |
|
| /* can honor lexical warnings and $^W */ |
| 51 |
|
| #if PERL_VERSION > 11 |
| 52 |
|
| #define Perl_warner Perl_ck_warner |
| 53 |
|
| #endif |
| 54 |
|
| |
| 55 |
|
| #if 0 |
| 56 |
|
| static const char* options[] = |
| 57 |
|
| { |
| 58 |
|
| /* Both */ |
| 59 |
|
| "boolean", /* "JSON::PP", "boolean" or 0 */ |
| 60 |
|
| "disableblessed", /* bool, default: 0 */ |
| 61 |
|
| "enablecode", /* bool, default: 0 */ |
| 62 |
|
| /* Loader */ |
| 63 |
|
| "nonstrict", /* bool, default: 0 */ |
| 64 |
|
| "loadcode", /* bool, default: 0 */ |
| 65 |
|
| /* Dumper */ |
| 66 |
|
| "dumpcode", /* bool, default: 0 */ |
| 67 |
|
| "noindentmap", /* bool, default: 0 */ |
| 68 |
|
| "indent", /* int, default: 2 */ |
| 69 |
|
| "wrapwidth", /* int, default: 80 */ |
| 70 |
|
| "canonical", /* bool, default: 0 */ |
| 71 |
|
| "quotenum", /* bool, default: 1 */ |
| 72 |
|
| "unicode", /* bool, default: 1 If unescaped Unicode characters are allowed */ |
| 73 |
|
| "encoding", /* "any", "utf8", "utf16le" or "utf16be" */ |
| 74 |
|
| "linebreak", /* "any", "cr", "ln" or "crln" */ |
| 75 |
|
| "openended", /* bool, default: 0 */ |
| 76 |
|
| }; |
| 77 |
|
| static int numoptions = sizeof(options)/sizeof(options[0]); |
| 78 |
|
| |
| 79 |
|
| #endif |
| 80 |
|
| |
| 81 |
|
| static SV * |
| 82 |
4 |
| fold_results(I32 count) |
| 83 |
|
| { |
| 84 |
4 |
| dSP; |
| 85 |
4 |
| SV *retval = &PL_sv_undef; |
| 86 |
|
| |
| 87 |
4 |
▶ | if (count > 1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (count > 1) { |
0 |
4 |
4 |
|
| 88 |
|
| /* convert multiple return items into a list reference */ |
| 89 |
0 |
| AV *av = newAV(); |
| 90 |
0 |
| SV *sv = &PL_sv_undef; |
| 91 |
|
| I32 i; |
| 92 |
|
| |
| 93 |
0 |
| av_extend(av, count - 1); |
| 94 |
0 |
▶ | for(i = 1; i <= count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 1; i <= count; i++) { |
0 |
0 |
0 |
|
| 95 |
0 |
| sv = POPs; |
| 96 |
0 |
▶ | if (SvOK(sv) && !av_store(av, count - i, SvREFCNT_inc(sv))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvOK(sv) && !av_store(av, count - i, SvREFCNT_inc(sv))) |
0 |
0 |
0 |
| if (SvOK(sv) && !av_store(av, count - i, SvREFCNT_inc(sv))) |
0 |
0 |
0 |
|
| 97 |
0 |
| SvREFCNT_dec(sv); |
| 98 |
|
| } |
| 99 |
0 |
| PUTBACK; |
| 100 |
|
| |
| 101 |
0 |
| retval = sv_2mortal((SV *) newRV_noinc((SV *) av)); |
| 102 |
|
| |
| 103 |
0 |
▶ | if (!SvOK(sv) || sv == &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvOK(sv) || sv == &PL_sv_undef) { |
0 |
0 |
0 |
| if (!SvOK(sv) || sv == &PL_sv_undef) { |
0 |
0 |
0 |
|
| 104 |
|
| /* if first element was undef, die */ |
| 105 |
0 |
| croak("%sCall error", ERRMSG); |
| 106 |
|
| } |
| 107 |
0 |
| return retval; |
| 108 |
|
| |
| 109 |
|
| } |
| 110 |
|
| else { |
| 111 |
4 |
▶ | if (count) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count) |
4 |
0 |
4 |
|
| 112 |
4 |
| retval = POPs; |
| 113 |
4 |
| PUTBACK; |
| 114 |
4 |
| return retval; |
| 115 |
|
| } |
| 116 |
|
| } |
| 117 |
|
| |
| 118 |
|
| static SV * |
| 119 |
4 |
| call_coderef(SV *code, AV *args) |
| 120 |
|
| { |
| 121 |
4 |
| dSP; |
| 122 |
|
| SV **svp; |
| 123 |
4 |
▶ | I32 count = args ? av_len(args) : -1; |
Branch: 1 branch
| Branch | True | False | Total |
| I32 count = args ? av_len(args) : -1; |
4 |
0 |
4 |
|
| 124 |
|
| I32 i; |
| 125 |
|
| |
| 126 |
4 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
4 |
4 |
|
| 127 |
8 |
▶ | for (i = 0; i <= count; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= count; i++) { |
4 |
4 |
8 |
|
| 128 |
4 |
▶ | if ((svp = av_fetch(args, i, FALSE))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((svp = av_fetch(args, i, FALSE))) { |
4 |
0 |
4 |
|
| 129 |
4 |
▶ | XPUSHs(*svp); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(*svp); |
0 |
4 |
4 |
|
| 130 |
|
| } |
| 131 |
|
| } |
| 132 |
4 |
| PUTBACK; |
| 133 |
4 |
| count = call_sv(code, G_ARRAY); |
| 134 |
4 |
| SPAGAIN; |
| 135 |
|
| |
| 136 |
4 |
| return fold_results(count); |
| 137 |
|
| } |
| 138 |
|
| |
| 139 |
|
| static SV * |
| 140 |
4 |
| find_coderef(const char *perl_var) |
| 141 |
|
| { |
| 142 |
|
| SV *coderef; |
| 143 |
|
| |
| 144 |
4 |
▶ | if ((coderef = get_sv(perl_var, FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((coderef = get_sv(perl_var, FALSE)) |
4 |
0 |
4 |
|
| 145 |
4 |
▶ | && SvROK(coderef) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvROK(coderef) |
4 |
0 |
4 |
|
| 146 |
4 |
▶ | && SvTYPE(SvRV(coderef)) == SVt_PVCV) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(coderef)) == SVt_PVCV) |
4 |
0 |
4 |
|
| 147 |
4 |
| return coderef; |
| 148 |
|
| |
| 149 |
0 |
| return NULL; |
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
|
| /* |
| 153 |
|
| * Piece together a parser/loader error message |
| 154 |
|
| */ |
| 155 |
|
| static char * |
| 156 |
8 |
| loader_error_msg(YAML *self, char *problem) |
| 157 |
|
| { |
| 158 |
|
| char *msg; |
| 159 |
8 |
▶ | if (!problem) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!problem) |
6 |
2 |
8 |
|
| 160 |
6 |
| problem = (char *)self->parser.problem; |
| 161 |
8 |
▶ | if (self->filename) |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->filename) |
0 |
8 |
8 |
|
| 162 |
0 |
▶ | msg = form("%s%s at file %s", |
Branch: 1 branch
| Branch | True | False | Total |
| msg = form("%s%s at file %s", |
0 |
0 |
0 |
|
| 163 |
|
| ERRMSG, (problem ? problem : "A problem"), self->filename); |
| 164 |
|
| else |
| 165 |
8 |
▶ | msg = form("%s%s at document %d", |
Branch: 1 branch
| Branch | True | False | Total |
| msg = form("%s%s at document %d", |
8 |
0 |
8 |
|
| 166 |
|
| ERRMSG, (problem ? problem : "A problem"), self->document); |
| 167 |
8 |
▶ | if (self->parser.problem_mark.line || |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->parser.problem_mark.line || |
4 |
4 |
8 |
|
| 168 |
4 |
▶ | self->parser.problem_mark.column) |
Branch: 1 branch
| Branch | True | False | Total |
| self->parser.problem_mark.column) |
1 |
3 |
4 |
|
| 169 |
5 |
| msg = form("%s, line: %ld, column: %ld\n", |
| 170 |
|
| msg, |
| 171 |
|
| (long)self->parser.problem_mark.line + 1, |
| 172 |
|
| (long)self->parser.problem_mark.column + 1); |
| 173 |
3 |
▶ | else if (self->parser.problem_offset) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (self->parser.problem_offset) |
1 |
2 |
3 |
|
| 174 |
1 |
| msg = form("%s, offset: %ld\n", msg, (long)self->parser.problem_offset); |
| 175 |
|
| else |
| 176 |
2 |
| msg = form("%s\n", msg); |
| 177 |
8 |
▶ | if (self->parser.context) |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->parser.context) |
4 |
4 |
8 |
|
| 178 |
4 |
| msg = form("%s%s at line: %ld, column: %ld\n", |
| 179 |
|
| msg, |
| 180 |
|
| self->parser.context, |
| 181 |
|
| (long)self->parser.context_mark.line + 1, |
| 182 |
|
| (long)self->parser.context_mark.column + 1); |
| 183 |
|
| |
| 184 |
8 |
| return msg; |
| 185 |
|
| } |
| 186 |
|
| |
| 187 |
|
| /* |
| 188 |
|
| * Set loader options from YAML* object. |
| 189 |
|
| */ |
| 190 |
|
| void |
| 191 |
110 |
| set_parser_options(YAML *self, yaml_parser_t *parser) |
| 192 |
|
| { |
| 193 |
110 |
| self->document = 0; |
| 194 |
110 |
| self->filename = NULL; |
| 195 |
110 |
| self->parser.read_handler = NULL; /* we allow setting it mult. times */ |
| 196 |
|
| |
| 197 |
110 |
▶ | if ((int)self->encoding) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((int)self->encoding) |
0 |
110 |
110 |
|
| 198 |
0 |
| yaml_parser_set_encoding(parser, self->encoding); |
| 199 |
|
| |
| 200 |
|
| /* As with YAML::Tiny. Default: strict Load */ |
| 201 |
|
| /* allow while parsing a quoted scalar found unknown escape character */ |
| 202 |
110 |
| parser->problem_nonstrict = self->flags & F_NONSTRICT; |
| 203 |
110 |
| } |
| 204 |
|
| |
| 205 |
|
| /* |
| 206 |
|
| * Set dumper options from YAML* object |
| 207 |
|
| */ |
| 208 |
|
| void |
| 209 |
88 |
| set_emitter_options(YAML *self, yaml_emitter_t *emitter) |
| 210 |
|
| { |
| 211 |
88 |
| yaml_emitter_set_unicode(emitter, self->flags & F_UNICODE); |
| 212 |
88 |
| yaml_emitter_set_indent(emitter, self->indent); |
| 213 |
88 |
| yaml_emitter_set_width(emitter, self->wrapwidth); |
| 214 |
88 |
▶ | if ((int)self->encoding) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((int)self->encoding) |
0 |
88 |
88 |
|
| 215 |
0 |
| yaml_emitter_set_encoding(emitter, self->encoding); |
| 216 |
88 |
▶ | if ((int)self->linebreak) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((int)self->linebreak) |
0 |
88 |
88 |
|
| 217 |
0 |
| yaml_emitter_set_break(emitter, self->linebreak); |
| 218 |
88 |
| emitter->indentless_map = self->flags & F_NOINDENTMAP; |
| 219 |
88 |
| emitter->open_ended = self->flags & F_OPENENDED; |
| 220 |
88 |
| yaml_emitter_set_canonical(emitter, self->flags & F_CANONICAL); |
| 221 |
88 |
| } |
| 222 |
|
| |
| 223 |
|
| static int |
| 224 |
110 |
| load_impl(YAML *self) |
| 225 |
|
| { |
| 226 |
110 |
| dXCPT; |
| 227 |
110 |
| dXSARGS; /* does POPMARK */ |
| 228 |
|
| SV *node; |
| 229 |
|
| |
| 230 |
110 |
| sp = mark; |
| 231 |
|
| if (0 && (items || ax)) {} /* XXX Quiet the -Wall warnings for now. */ |
| 232 |
|
| |
| 233 |
|
| /* Get the first event. Must be a STREAM_START */ |
| 234 |
110 |
▶ | if (!yaml_parser_parse(&self->parser, &self->event)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!yaml_parser_parse(&self->parser, &self->event)) |
1 |
109 |
110 |
|
| 235 |
1 |
| goto load_error; |
| 236 |
109 |
▶ | if (self->event.type != YAML_STREAM_START_EVENT) |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->event.type != YAML_STREAM_START_EVENT) |
0 |
109 |
109 |
|
| 237 |
0 |
| croak("%sExpected STREAM_START_EVENT; Got: %d != %d", |
| 238 |
|
| ERRMSG, self->event.type, YAML_STREAM_START_EVENT); |
| 239 |
|
| |
| 240 |
109 |
| self->anchors = (HV *)sv_2mortal((SV *)newHV()); |
| 241 |
|
| |
| 242 |
109 |
▶ | XCPT_TRY_START { |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_TRY_START { |
109 |
7 |
116 |
|
| 243 |
|
| |
| 244 |
|
| /* Keep calling load_node until end of stream */ |
| 245 |
|
| while (1) { |
| 246 |
216 |
| self->document++; |
| 247 |
|
| /* We are through with the previous event - delete it! */ |
| 248 |
216 |
| yaml_event_delete(&self->event); |
| 249 |
216 |
▶ | if (!yaml_parser_parse(&self->parser, &self->event)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!yaml_parser_parse(&self->parser, &self->event)) |
1 |
215 |
216 |
|
| 250 |
1 |
| goto load_error; |
| 251 |
215 |
▶ | if (self->event.type == YAML_STREAM_END_EVENT) |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->event.type == YAML_STREAM_END_EVENT) |
102 |
113 |
215 |
|
| 252 |
102 |
| break; |
| 253 |
113 |
| node = load_node(self); |
| 254 |
|
| /* We are through with the previous event - delete it! */ |
| 255 |
107 |
| yaml_event_delete(&self->event); |
| 256 |
107 |
| hv_clear(self->anchors); |
| 257 |
107 |
▶ | if (! node) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (! node) break; |
0 |
107 |
107 |
|
| 258 |
107 |
▶ | XPUSHs(sv_2mortal(node)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(node)); |
0 |
107 |
107 |
|
| 259 |
107 |
▶ | if (!yaml_parser_parse(&self->parser, &self->event)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!yaml_parser_parse(&self->parser, &self->event)) |
0 |
107 |
107 |
|
| 260 |
0 |
| goto load_error; |
| 261 |
107 |
▶ | if (self->event.type != YAML_DOCUMENT_END_EVENT) |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->event.type != YAML_DOCUMENT_END_EVENT) |
0 |
107 |
107 |
|
| 262 |
0 |
| croak("%sExpected DOCUMENT_END_EVENT", ERRMSG); |
| 263 |
|
| } |
| 264 |
|
| |
| 265 |
|
| /* Make sure the last event is a STREAM_END */ |
| 266 |
102 |
▶ | if (self->event.type != YAML_STREAM_END_EVENT) |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->event.type != YAML_STREAM_END_EVENT) |
0 |
102 |
102 |
|
| 267 |
0 |
| croak("%sExpected STREAM_END_EVENT; Got: %d != %d", |
| 268 |
|
| ERRMSG, self->event.type, YAML_STREAM_END_EVENT); |
| 269 |
|
| |
| 270 |
109 |
| } XCPT_TRY_END |
| 271 |
|
| |
| 272 |
109 |
▶ | XCPT_CATCH |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_CATCH |
7 |
102 |
109 |
|
| 273 |
|
| { |
| 274 |
7 |
| yaml_parser_delete(&self->parser); |
| 275 |
7 |
▶ | XCPT_RETHROW; |
Branch: 2 branches
| Branch | True | False | Total |
| XCPT_RETHROW; |
7 |
0 |
7 |
| XCPT_RETHROW; |
0 |
0 |
0 |
|
| 276 |
|
| } |
| 277 |
|
| |
| 278 |
102 |
| yaml_parser_delete(&self->parser); |
| 279 |
102 |
| PUTBACK; |
| 280 |
102 |
| return 1; |
| 281 |
|
| |
| 282 |
2 |
| load_error: |
| 283 |
2 |
| croak("%s", loader_error_msg(self, NULL)); |
| 284 |
|
| return 0; |
| 285 |
|
| } |
| 286 |
|
| |
| 287 |
|
| /* |
| 288 |
|
| * It takes a file or filename and turns it into 0 or more Perl objects. |
| 289 |
|
| */ |
| 290 |
|
| int |
| 291 |
6 |
| LoadFile(YAML *self, SV *sv_file) |
| 292 |
|
| { |
| 293 |
6 |
| FILE *file = NULL; |
| 294 |
|
| const char *fname; |
| 295 |
|
| STRLEN len; |
| 296 |
|
| int ret; |
| 297 |
|
| |
| 298 |
6 |
| yaml_parser_initialize(&self->parser); |
| 299 |
6 |
| set_parser_options(self, &self->parser); |
| 300 |
6 |
▶ | if (SvROK(sv_file)) { /* pv mg or io or gv */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(sv_file)) { /* pv mg or io or gv */ |
3 |
3 |
6 |
|
| 301 |
3 |
| SV *rv = SvRV(sv_file); |
| 302 |
|
| |
| 303 |
3 |
▶ | if (SvTYPE(rv) == SVt_PVIO) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(rv) == SVt_PVIO) { |
0 |
3 |
3 |
|
| 304 |
0 |
| self->perlio = IoIFP(rv); |
| 305 |
0 |
| yaml_parser_set_input(&self->parser, |
| 306 |
|
| &yaml_perlio_read_handler, |
| 307 |
|
| self); |
| 308 |
3 |
▶ | } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
Branch: 6 branches
| Branch | True | False | Total |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
2 |
1 |
3 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
2 |
0 |
2 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
0 |
2 |
2 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
0 |
0 |
0 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
2 |
0 |
2 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
2 |
0 |
2 |
|
| 309 |
2 |
| self->perlio = IoIFP(GvIOp(rv)); |
| 310 |
2 |
| yaml_parser_set_input(&self->parser, |
| 311 |
|
| &yaml_perlio_read_handler, |
| 312 |
|
| self); |
| 313 |
1 |
▶ | } else if (SvMAGIC(rv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvMAGIC(rv)) { |
0 |
1 |
1 |
|
| 314 |
0 |
| mg_get(rv); |
| 315 |
0 |
| fname = SvPV_const(rv, len); |
| 316 |
0 |
| goto pv_load; |
| 317 |
1 |
▶ | } else if (SvAMAGIC(sv_file)) { |
Branch: 3 branches
| Branch | True | False | Total |
| } else if (SvAMAGIC(sv_file)) { |
1 |
0 |
1 |
| } else if (SvAMAGIC(sv_file)) { |
1 |
0 |
1 |
| } else if (SvAMAGIC(sv_file)) { |
1 |
0 |
1 |
|
| 318 |
1 |
| fname = SvPV_const(sv_file, len); |
| 319 |
1 |
| goto pv_load; |
| 320 |
|
| } else { |
| 321 |
0 |
| croak("Invalid argument type for file: ref of %s", Perl_sv_peek(aTHX_ rv)); |
| 322 |
|
| return 0; |
| 323 |
|
| } |
| 324 |
|
| } |
| 325 |
3 |
▶ | else if (SvPOK(sv_file)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (SvPOK(sv_file)) { |
3 |
0 |
3 |
|
| 326 |
3 |
| fname = SvPV_const(sv_file, len); |
| 327 |
4 |
| pv_load: |
| 328 |
4 |
| file = fopen(fname, "rb"); |
| 329 |
4 |
▶ | if (!file) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!file) { |
0 |
4 |
4 |
|
| 330 |
0 |
| croak("Can't open '%s' for input", fname); |
| 331 |
|
| return 0; |
| 332 |
|
| } |
| 333 |
4 |
| self->filename = (char *)fname; |
| 334 |
4 |
| yaml_parser_set_input_file(&self->parser, file); |
| 335 |
0 |
▶ | } else if (SvTYPE(sv_file) == SVt_PVIO) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvTYPE(sv_file) == SVt_PVIO) { |
0 |
0 |
0 |
|
| 336 |
0 |
| self->perlio = IoIFP(sv_file); |
| 337 |
0 |
| yaml_parser_set_input(&self->parser, |
| 338 |
|
| &yaml_perlio_read_handler, |
| 339 |
|
| self); |
| 340 |
0 |
▶ | } else if (SvTYPE(sv_file) == SVt_PVGV |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvTYPE(sv_file) == SVt_PVGV |
0 |
0 |
0 |
|
| 341 |
0 |
▶ | && GvIO(sv_file)) { |
Branch: 5 branches
| Branch | True | False | Total |
| && GvIO(sv_file)) { |
0 |
0 |
0 |
| && GvIO(sv_file)) { |
0 |
0 |
0 |
| && GvIO(sv_file)) { |
0 |
0 |
0 |
| && GvIO(sv_file)) { |
0 |
0 |
0 |
| && GvIO(sv_file)) { |
0 |
0 |
0 |
|
| 342 |
0 |
| self->perlio = IoIFP(GvIOp(sv_file)); |
| 343 |
0 |
| yaml_parser_set_input(&self->parser, |
| 344 |
|
| &yaml_perlio_read_handler, |
| 345 |
|
| self); |
| 346 |
|
| } else { |
| 347 |
0 |
| croak("Invalid argument type for file: %s", Perl_sv_peek(aTHX_ sv_file)); |
| 348 |
|
| return 0; |
| 349 |
|
| } |
| 350 |
|
| |
| 351 |
6 |
| ret = load_impl(self); |
| 352 |
6 |
▶ | if (file) |
Branch: 1 branch
| Branch | True | False | Total |
| if (file) |
4 |
2 |
6 |
|
| 353 |
4 |
| fclose(file); |
| 354 |
2 |
▶ | else if (SvTYPE(sv_file) == SVt_PVIO) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (SvTYPE(sv_file) == SVt_PVIO) |
0 |
2 |
2 |
|
| 355 |
0 |
| PerlIO_close(IoIFP(sv_file)); |
| 356 |
6 |
| return ret; |
| 357 |
|
| } |
| 358 |
|
| |
| 359 |
|
| /* |
| 360 |
|
| * This is the main Load function. |
| 361 |
|
| * It takes a yaml stream and turns it into 0 or more Perl objects. |
| 362 |
|
| */ |
| 363 |
|
| int |
| 364 |
104 |
| Load(YAML *self, SV* yaml_sv) |
| 365 |
|
| { |
| 366 |
|
| const unsigned char *yaml_str; |
| 367 |
|
| STRLEN yaml_len; |
| 368 |
|
| |
| 369 |
104 |
| yaml_str = (const unsigned char *)SvPV_const(yaml_sv, yaml_len); |
| 370 |
104 |
| yaml_parser_initialize(&self->parser); |
| 371 |
104 |
| set_parser_options(self, &self->parser); |
| 372 |
104 |
▶ | if (DO_UTF8(yaml_sv)) { /* overrides encoding setting */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (DO_UTF8(yaml_sv)) { /* overrides encoding setting */ |
0 |
104 |
104 |
| if (DO_UTF8(yaml_sv)) { /* overrides encoding setting */ |
0 |
0 |
0 |
|
| 373 |
0 |
▶ | if (self->encoding == YAML_ANY_ENCODING) |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->encoding == YAML_ANY_ENCODING) |
0 |
0 |
0 |
|
| 374 |
0 |
| self->parser.encoding = YAML_UTF8_ENCODING; |
| 375 |
|
| } /* else check the BOM. don't check for decoded utf8. */ |
| 376 |
|
| |
| 377 |
104 |
| yaml_parser_set_input_string( |
| 378 |
|
| &self->parser, |
| 379 |
|
| yaml_str, |
| 380 |
|
| yaml_len); |
| 381 |
|
| |
| 382 |
104 |
| return load_impl(self); |
| 383 |
|
| } |
| 384 |
|
| |
| 385 |
|
| /* |
| 386 |
|
| * This is the main function for dumping any node. |
| 387 |
|
| */ |
| 388 |
|
| static SV * |
| 389 |
625 |
| load_node(YAML *self) |
| 390 |
|
| { |
| 391 |
625 |
| SV* return_sv = NULL; |
| 392 |
|
| /* This uses stack, but avoids (severe!) memory leaks */ |
| 393 |
|
| yaml_event_t uplevel_event; |
| 394 |
|
| |
| 395 |
625 |
| uplevel_event = self->event; |
| 396 |
|
| |
| 397 |
|
| /* Get the next parser event */ |
| 398 |
625 |
▶ | if (!yaml_parser_parse(&self->parser, &self->event)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!yaml_parser_parse(&self->parser, &self->event)) |
4 |
621 |
625 |
|
| 399 |
4 |
| goto load_error; |
| 400 |
|
| |
| 401 |
|
| /* These events don't need yaml_event_delete */ |
| 402 |
|
| /* Some kind of error occurred */ |
| 403 |
621 |
▶ | if (self->event.type == YAML_NO_EVENT) |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->event.type == YAML_NO_EVENT) |
0 |
621 |
621 |
|
| 404 |
0 |
| goto load_error; |
| 405 |
|
| |
| 406 |
|
| /* Return NULL when we hit the end of a scope */ |
| 407 |
621 |
▶ | if (self->event.type == YAML_DOCUMENT_END_EVENT || |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->event.type == YAML_DOCUMENT_END_EVENT || |
621 |
0 |
621 |
|
| 408 |
621 |
▶ | self->event.type == YAML_MAPPING_END_EVENT || |
Branch: 1 branch
| Branch | True | False | Total |
| self->event.type == YAML_MAPPING_END_EVENT || |
546 |
75 |
621 |
|
| 409 |
546 |
▶ | self->event.type == YAML_SEQUENCE_END_EVENT) |
Branch: 1 branch
| Branch | True | False | Total |
| self->event.type == YAML_SEQUENCE_END_EVENT) |
52 |
494 |
546 |
|
| 410 |
|
| { |
| 411 |
|
| /* restore the uplevel event, so it can be properly deleted */ |
| 412 |
127 |
| self->event = uplevel_event; |
| 413 |
127 |
| return return_sv; |
| 414 |
|
| } |
| 415 |
|
| |
| 416 |
|
| /* The rest all need cleanup */ |
| 417 |
494 |
| switch (self->event.type) { |
| 418 |
|
| char *tag; |
| 419 |
|
| |
| 420 |
|
| /* Handle loading a mapping */ |
| 421 |
78 |
| case YAML_MAPPING_START_EVENT: |
| 422 |
78 |
| tag = (char *)self->event.data.mapping_start.tag; |
| 423 |
|
| |
| 424 |
78 |
▶ | if (tag) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag) { |
32 |
46 |
78 |
|
| 425 |
|
| /* Handle mapping tagged as a Perl hard reference */ |
| 426 |
32 |
▶ | if (strEQ(tag, TAG_PERL_REF)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(tag, TAG_PERL_REF)) { |
16 |
16 |
32 |
|
| 427 |
16 |
| return_sv = load_scalar_ref(self); |
| 428 |
16 |
| break; |
| 429 |
|
| } |
| 430 |
|
| /* Handle mapping tagged as a Perl typeglob */ |
| 431 |
16 |
▶ | if (strEQ(tag, TAG_PERL_GLOB)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(tag, TAG_PERL_GLOB)) { |
0 |
16 |
16 |
|
| 432 |
0 |
| return_sv = load_glob(self); |
| 433 |
0 |
| break; |
| 434 |
|
| } |
| 435 |
|
| } |
| 436 |
|
| |
| 437 |
62 |
| return_sv = load_mapping(self, NULL); |
| 438 |
58 |
| break; |
| 439 |
|
| |
| 440 |
|
| /* Handle loading a sequence into an array */ |
| 441 |
52 |
| case YAML_SEQUENCE_START_EVENT: |
| 442 |
52 |
| return_sv = load_sequence(self); |
| 443 |
51 |
| break; |
| 444 |
|
| |
| 445 |
|
| /* Handle loading a scalar */ |
| 446 |
348 |
| case YAML_SCALAR_EVENT: |
| 447 |
348 |
| return_sv = load_scalar(self); |
| 448 |
348 |
| break; |
| 449 |
|
| |
| 450 |
|
| /* Handle loading an alias node */ |
| 451 |
16 |
| case YAML_ALIAS_EVENT: |
| 452 |
16 |
| return_sv = load_alias(self); |
| 453 |
16 |
| break; |
| 454 |
|
| |
| 455 |
0 |
| default: |
| 456 |
0 |
| croak("%sInvalid event '%d' at top level", |
| 457 |
|
| ERRMSG, (int) self->event.type); |
| 458 |
|
| } |
| 459 |
|
| |
| 460 |
489 |
| yaml_event_delete(&self->event); |
| 461 |
|
| |
| 462 |
|
| /* restore the uplevel event, so it can be properly deleted */ |
| 463 |
489 |
| self->event = uplevel_event; |
| 464 |
|
| |
| 465 |
489 |
| return return_sv; |
| 466 |
|
| |
| 467 |
4 |
| load_error: |
| 468 |
4 |
| croak("%s", loader_error_msg(self, NULL)); |
| 469 |
|
| } |
| 470 |
|
| |
| 471 |
|
| /* |
| 472 |
|
| * Load a YAML mapping into a Perl hash |
| 473 |
|
| */ |
| 474 |
|
| static SV * |
| 475 |
62 |
| load_mapping(YAML *self, char *tag) |
| 476 |
|
| { |
| 477 |
|
| SV *key_node; |
| 478 |
|
| SV *value_node; |
| 479 |
62 |
| HV *hash = newHV(); |
| 480 |
62 |
| SV *hash_ref = (SV *)newRV_noinc((SV *)hash); |
| 481 |
62 |
| char *anchor = (char *)self->event.data.mapping_start.anchor; |
| 482 |
|
| |
| 483 |
62 |
▶ | if (!tag) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!tag) |
62 |
0 |
62 |
|
| 484 |
62 |
| tag = (char *)self->event.data.mapping_start.tag; |
| 485 |
|
| |
| 486 |
|
| /* Store the anchor label if any */ |
| 487 |
62 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
5 |
57 |
62 |
|
| 488 |
5 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 489 |
|
| SvREFCNT_inc(hash_ref), 0); |
| 490 |
|
| |
| 491 |
|
| /* Get each key string and value node and put them in the hash */ |
| 492 |
173 |
▶ | while ((key_node = load_node(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((key_node = load_node(self))) { |
112 |
59 |
171 |
|
| 493 |
|
| assert(SvPOK(key_node)); |
| 494 |
112 |
| value_node = load_node(self); |
| 495 |
111 |
| (void)hv_store_ent(hash, sv_2mortal(key_node), value_node, 0); |
| 496 |
|
| } |
| 497 |
|
| |
| 498 |
|
| /* Deal with possibly blessing the hash if the YAML tag has a class */ |
| 499 |
59 |
▶ | if (tag) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag) { |
16 |
43 |
59 |
|
| 500 |
16 |
▶ | if (strEQ(tag, TAG_PERL_PREFIX "hash")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(tag, TAG_PERL_PREFIX "hash")) { |
14 |
2 |
16 |
|
| 501 |
|
| } |
| 502 |
14 |
▶ | else if (strEQ(tag, YAML_MAP_TAG)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(tag, YAML_MAP_TAG)) { |
13 |
1 |
14 |
|
| 503 |
|
| } |
| 504 |
|
| else { |
| 505 |
|
| char *klass; |
| 506 |
13 |
| char *prefix = TAG_PERL_PREFIX "hash:"; |
| 507 |
13 |
▶ | if (*tag == '!') { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*tag == '!') { |
3 |
10 |
13 |
|
| 508 |
3 |
| prefix = "!"; |
| 509 |
|
| } |
| 510 |
10 |
▶ | else if (strlen(tag) <= strlen(prefix) || |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strlen(tag) <= strlen(prefix) || |
9 |
1 |
10 |
|
| 511 |
9 |
▶ | ! strnEQ(tag, prefix, strlen(prefix))) |
Branch: 1 branch
| Branch | True | False | Total |
| ! strnEQ(tag, prefix, strlen(prefix))) |
0 |
9 |
9 |
|
| 512 |
1 |
| croak("%s", loader_error_msg(self, |
| 513 |
|
| form("bad tag found for hash: '%s'", tag))); |
| 514 |
12 |
▶ | if (!(self->flags & F_DISABLEBLESSED)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(self->flags & F_DISABLEBLESSED)) { |
10 |
2 |
12 |
|
| 515 |
10 |
| klass = tag + strlen(prefix); |
| 516 |
10 |
▶ | if (self->flags & F_SAFEMODE && |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->flags & F_SAFEMODE && |
2 |
8 |
10 |
|
| 517 |
4 |
| (!self->safeclasses || |
| 518 |
2 |
| !hv_exists(self->safeclasses, klass, strlen(klass)))) |
| 519 |
|
| { |
| 520 |
1 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 521 |
|
| WARNMSG "skipped loading unsafe HASH for class %s", |
| 522 |
|
| klass); |
| 523 |
1 |
| return hash_ref; |
| 524 |
|
| } |
| 525 |
9 |
| sv_bless(hash_ref, gv_stashpv(klass, TRUE)); |
| 526 |
|
| } |
| 527 |
|
| } |
| 528 |
|
| } |
| 529 |
|
| |
| 530 |
57 |
| return hash_ref; |
| 531 |
|
| } |
| 532 |
|
| |
| 533 |
|
| /* Load a YAML sequence into a Perl array */ |
| 534 |
|
| static SV * |
| 535 |
52 |
| load_sequence(YAML *self) |
| 536 |
|
| { |
| 537 |
|
| SV *node; |
| 538 |
52 |
| AV *array = newAV(); |
| 539 |
52 |
| SV *array_ref = (SV *)newRV_noinc((SV *)array); |
| 540 |
52 |
| char *anchor = (char *)self->event.data.sequence_start.anchor; |
| 541 |
52 |
| char *tag = (char *)self->event.data.mapping_start.tag; |
| 542 |
52 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
2 |
50 |
52 |
|
| 543 |
2 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 544 |
|
| SvREFCNT_inc(array_ref), 0); |
| 545 |
179 |
▶ | while ((node = load_node(self))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((node = load_node(self))) { |
127 |
52 |
179 |
|
| 546 |
127 |
| av_push(array, node); |
| 547 |
|
| } |
| 548 |
52 |
▶ | if (tag) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag) { |
13 |
39 |
52 |
|
| 549 |
13 |
▶ | if (strEQ(tag, TAG_PERL_PREFIX "array")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(tag, TAG_PERL_PREFIX "array")) { |
11 |
2 |
13 |
|
| 550 |
|
| } |
| 551 |
11 |
▶ | else if (strEQ(tag, YAML_SEQ_TAG)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(tag, YAML_SEQ_TAG)) { |
10 |
1 |
11 |
|
| 552 |
|
| } |
| 553 |
|
| else { |
| 554 |
|
| char *klass; |
| 555 |
10 |
| char *prefix = TAG_PERL_PREFIX "array:"; |
| 556 |
|
| |
| 557 |
10 |
▶ | if (*tag == '!') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*tag == '!') |
3 |
7 |
10 |
|
| 558 |
3 |
| prefix = "!"; |
| 559 |
7 |
▶ | else if (strlen(tag) <= strlen(prefix) || |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strlen(tag) <= strlen(prefix) || |
6 |
1 |
7 |
|
| 560 |
6 |
▶ | ! strnEQ(tag, prefix, strlen(prefix))) |
Branch: 1 branch
| Branch | True | False | Total |
| ! strnEQ(tag, prefix, strlen(prefix))) |
0 |
6 |
6 |
|
| 561 |
1 |
| croak("%s", loader_error_msg(self, |
| 562 |
|
| form("bad tag found for array: '%s'", tag))); |
| 563 |
9 |
▶ | if (!(self->flags & F_DISABLEBLESSED)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(self->flags & F_DISABLEBLESSED)) { |
7 |
2 |
9 |
|
| 564 |
7 |
| klass = tag + strlen(prefix); |
| 565 |
7 |
▶ | if (self->flags & F_SAFEMODE && |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->flags & F_SAFEMODE && |
2 |
5 |
7 |
|
| 566 |
4 |
| (!self->safeclasses || |
| 567 |
2 |
| !hv_exists(self->safeclasses, klass, strlen(klass)))) |
| 568 |
|
| { |
| 569 |
1 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 570 |
|
| WARNMSG "skipped loading unsafe ARRAY for class %s", |
| 571 |
|
| klass); |
| 572 |
1 |
| return array_ref; |
| 573 |
|
| } |
| 574 |
6 |
| sv_bless(array_ref, gv_stashpv(klass, TRUE)); |
| 575 |
|
| } |
| 576 |
|
| } |
| 577 |
|
| } |
| 578 |
50 |
| return array_ref; |
| 579 |
|
| } |
| 580 |
|
| |
| 581 |
|
| /* Load a YAML scalar into a Perl scalar */ |
| 582 |
|
| static SV * |
| 583 |
348 |
| load_scalar(YAML *self) |
| 584 |
|
| { |
| 585 |
|
| SV *scalar; |
| 586 |
348 |
| char *string = (char *)self->event.data.scalar.value; |
| 587 |
348 |
| STRLEN length = (STRLEN)self->event.data.scalar.length; |
| 588 |
348 |
| char *anchor = (char *)self->event.data.scalar.anchor; |
| 589 |
348 |
| char *tag = (char *)self->event.data.scalar.tag; |
| 590 |
348 |
| yaml_scalar_style_t style = self->event.data.scalar.style; |
| 591 |
348 |
▶ | if (tag) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag) { |
37 |
311 |
348 |
|
| 592 |
37 |
▶ | if (strEQ(tag, YAML_STR_TAG)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(tag, YAML_STR_TAG)) { |
6 |
31 |
37 |
|
| 593 |
6 |
| style = YAML_SINGLE_QUOTED_SCALAR_STYLE; |
| 594 |
|
| } |
| 595 |
31 |
▶ | else if (strEQ(tag, YAML_INT_TAG) || strEQ(tag, YAML_FLOAT_TAG)) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (strEQ(tag, YAML_INT_TAG) || strEQ(tag, YAML_FLOAT_TAG)) { |
30 |
1 |
31 |
| else if (strEQ(tag, YAML_INT_TAG) || strEQ(tag, YAML_FLOAT_TAG)) { |
1 |
29 |
30 |
|
| 596 |
|
| /* TODO check int/float */ |
| 597 |
2 |
| scalar = newSVpvn(string, length); |
| 598 |
2 |
▶ | if ( looks_like_number(scalar) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( looks_like_number(scalar) ) { |
2 |
0 |
2 |
|
| 599 |
|
| /* numify */ |
| 600 |
2 |
▶ | SvIV_please(scalar); |
Branch: 2 branches
| Branch | True | False | Total |
| SvIV_please(scalar); |
2 |
0 |
2 |
| SvIV_please(scalar); |
2 |
0 |
2 |
|
| 601 |
|
| } |
| 602 |
|
| else { |
| 603 |
0 |
| croak("%s", loader_error_msg(self, |
| 604 |
|
| form("Invalid content found for !!int tag: '%s'", |
| 605 |
|
| tag))); |
| 606 |
|
| } |
| 607 |
2 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
0 |
2 |
2 |
|
| 608 |
0 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 609 |
|
| SvREFCNT_inc(scalar), 0); |
| 610 |
2 |
| return scalar; |
| 611 |
|
| } |
| 612 |
29 |
▶ | else if (strEQ(tag, YAML_NULL_TAG) && |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(tag, YAML_NULL_TAG) && |
4 |
25 |
29 |
|
| 613 |
4 |
▶ | (strEQ(string, "~") || |
Branch: 1 branch
| Branch | True | False | Total |
| (strEQ(string, "~") || |
3 |
1 |
4 |
|
| 614 |
3 |
▶ | strEQ(string, "null") || |
Branch: 1 branch
| Branch | True | False | Total |
| strEQ(string, "null") || |
2 |
1 |
3 |
|
| 615 |
2 |
▶ | strEQ(string, ""))) |
Branch: 1 branch
| Branch | True | False | Total |
| strEQ(string, ""))) |
2 |
0 |
2 |
|
| 616 |
|
| { |
| 617 |
4 |
| scalar = newSV(0); |
| 618 |
4 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
1 |
3 |
4 |
|
| 619 |
1 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 620 |
|
| SvREFCNT_inc(scalar), 0); |
| 621 |
4 |
| return scalar; |
| 622 |
|
| } |
| 623 |
|
| else { |
| 624 |
|
| char *klass; |
| 625 |
25 |
| char *prefix = TAG_PERL_PREFIX "regexp"; |
| 626 |
25 |
▶ | if (strnEQ(tag, prefix, strlen(prefix))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strnEQ(tag, prefix, strlen(prefix))) |
11 |
14 |
25 |
|
| 627 |
11 |
| return load_regexp(self); |
| 628 |
14 |
| prefix = TAG_PERL_PREFIX "code"; |
| 629 |
14 |
▶ | if (strnEQ(tag, prefix, strlen(prefix))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strnEQ(tag, prefix, strlen(prefix))) |
6 |
8 |
14 |
|
| 630 |
6 |
| return load_code(self); |
| 631 |
8 |
| prefix = TAG_PERL_PREFIX "scalar:"; |
| 632 |
8 |
▶ | if (*tag == '!') |
Branch: 1 branch
| Branch | True | False | Total |
| if (*tag == '!') |
3 |
5 |
8 |
|
| 633 |
3 |
| prefix = "!"; |
| 634 |
5 |
▶ | else if (strlen(tag) <= strlen(prefix) || |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strlen(tag) <= strlen(prefix) || |
5 |
0 |
5 |
|
| 635 |
5 |
▶ | !strnEQ(tag, prefix, strlen(prefix))) |
Branch: 1 branch
| Branch | True | False | Total |
| !strnEQ(tag, prefix, strlen(prefix))) |
0 |
5 |
5 |
|
| 636 |
0 |
| croak("%sbad tag found for scalar: '%s'", ERRMSG, tag); |
| 637 |
8 |
| klass = tag + strlen(prefix); |
| 638 |
8 |
▶ | if (!(self->flags & F_DISABLEBLESSED)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(self->flags & F_DISABLEBLESSED)) |
6 |
2 |
8 |
|
| 639 |
6 |
▶ | if (self->flags & F_SAFEMODE && |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->flags & F_SAFEMODE && |
2 |
4 |
6 |
|
| 640 |
4 |
| (!self->safeclasses || |
| 641 |
2 |
| !hv_exists(self->safeclasses, klass, strlen(klass)))) |
| 642 |
|
| { |
| 643 |
1 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 644 |
|
| WARNMSG "skipped loading unsafe SCALAR for class %s", |
| 645 |
|
| klass); |
| 646 |
1 |
| scalar = newSVpvn(string, length); |
| 647 |
|
| } else { |
| 648 |
5 |
| scalar = sv_setref_pvn(newSV(0), klass, string, strlen(string)); |
| 649 |
|
| } |
| 650 |
|
| else |
| 651 |
2 |
| scalar = newSVpvn(string, length); |
| 652 |
8 |
| SvUTF8_on(scalar); |
| 653 |
8 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
0 |
8 |
8 |
|
| 654 |
0 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 655 |
|
| SvREFCNT_inc(scalar), 0); |
| 656 |
8 |
| return scalar; |
| 657 |
|
| } |
| 658 |
|
| } |
| 659 |
|
| |
| 660 |
311 |
▶ | else if (style == YAML_PLAIN_SCALAR_STYLE) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (style == YAML_PLAIN_SCALAR_STYLE) { |
283 |
28 |
311 |
|
| 661 |
283 |
▶ | if (strEQ(string, "~") || strEQ(string, "null") || strEQ(string, "")) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (strEQ(string, "~") || strEQ(string, "null") || strEQ(string, "")) { |
276 |
7 |
283 |
| if (strEQ(string, "~") || strEQ(string, "null") || strEQ(string, "")) { |
274 |
2 |
276 |
| if (strEQ(string, "~") || strEQ(string, "null") || strEQ(string, "")) { |
8 |
266 |
274 |
|
| 662 |
17 |
| scalar = newSV(0); |
| 663 |
17 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
3 |
14 |
17 |
|
| 664 |
3 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 665 |
|
| SvREFCNT_inc(scalar), 0); |
| 666 |
17 |
| return scalar; |
| 667 |
|
| } |
| 668 |
266 |
▶ | else if (strEQ(string, "true")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(string, "true")) { |
12 |
254 |
266 |
|
| 669 |
|
| #if (PERL_BCDVERSION >= 0x5008009) |
| 670 |
12 |
▶ | if (self->boolean == YAML_BOOLEAN_JSONPP) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->boolean == YAML_BOOLEAN_JSONPP) { |
3 |
9 |
12 |
|
| 671 |
3 |
| scalar = sv_setref_iv(newSV(1), "JSON::PP::Boolean", 1); |
| 672 |
|
| } |
| 673 |
9 |
▶ | else if (self->boolean == YAML_BOOLEAN_BOOLEAN) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (self->boolean == YAML_BOOLEAN_BOOLEAN) { |
1 |
8 |
9 |
|
| 674 |
1 |
| scalar = sv_setref_iv(newSV(1), "boolean", 1); |
| 675 |
|
| } |
| 676 |
|
| else |
| 677 |
|
| #endif |
| 678 |
|
| { |
| 679 |
8 |
| scalar = &PL_sv_yes; |
| 680 |
|
| } |
| 681 |
12 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
1 |
11 |
12 |
|
| 682 |
1 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 683 |
|
| SvREFCNT_inc(scalar), 0); |
| 684 |
12 |
| return scalar; |
| 685 |
|
| } |
| 686 |
254 |
▶ | else if (strEQ(string, "false")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(string, "false")) { |
7 |
247 |
254 |
|
| 687 |
|
| #if (PERL_BCDVERSION >= 0x5008009) |
| 688 |
7 |
▶ | if (self->boolean == YAML_BOOLEAN_JSONPP) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->boolean == YAML_BOOLEAN_JSONPP) { |
3 |
4 |
7 |
|
| 689 |
3 |
| scalar = sv_setref_iv(newSV(0), "JSON::PP::Boolean", 0); |
| 690 |
|
| } |
| 691 |
4 |
▶ | else if (self->boolean == YAML_BOOLEAN_BOOLEAN) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (self->boolean == YAML_BOOLEAN_BOOLEAN) { |
1 |
3 |
4 |
|
| 692 |
1 |
| scalar = sv_setref_iv(newSV(0), "boolean", 0); |
| 693 |
|
| } |
| 694 |
|
| else |
| 695 |
|
| #endif |
| 696 |
|
| { |
| 697 |
3 |
| scalar = &PL_sv_no; |
| 698 |
|
| } |
| 699 |
7 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
1 |
6 |
7 |
|
| 700 |
1 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 701 |
|
| SvREFCNT_inc(scalar), 0); |
| 702 |
7 |
| return scalar; |
| 703 |
|
| } |
| 704 |
|
| } |
| 705 |
|
| |
| 706 |
281 |
| scalar = newSVpvn(string, length); |
| 707 |
|
| |
| 708 |
281 |
▶ | if (style == YAML_PLAIN_SCALAR_STYLE && looks_like_number(scalar) ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (style == YAML_PLAIN_SCALAR_STYLE && looks_like_number(scalar) ) { |
247 |
34 |
281 |
| if (style == YAML_PLAIN_SCALAR_STYLE && looks_like_number(scalar) ) { |
48 |
199 |
247 |
|
| 709 |
|
| /* numify */ |
| 710 |
48 |
▶ | SvIV_please(scalar); |
Branch: 2 branches
| Branch | True | False | Total |
| SvIV_please(scalar); |
48 |
0 |
48 |
| SvIV_please(scalar); |
48 |
0 |
48 |
|
| 711 |
|
| } |
| 712 |
|
| |
| 713 |
281 |
| (void)sv_utf8_decode(scalar); |
| 714 |
281 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
1 |
280 |
281 |
|
| 715 |
1 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 716 |
|
| SvREFCNT_inc(scalar), 0); |
| 717 |
281 |
| return scalar; |
| 718 |
|
| } |
| 719 |
|
| |
| 720 |
|
| /* Load a scalar marked as a regexp as a Perl regular expression. |
| 721 |
|
| * This operation is less common and is tricky, so doing it in Perl code for |
| 722 |
|
| * now. |
| 723 |
|
| */ |
| 724 |
|
| static SV * |
| 725 |
11 |
| load_regexp(YAML * self) |
| 726 |
|
| { |
| 727 |
11 |
| dSP; |
| 728 |
11 |
| char *string = (char *)self->event.data.scalar.value; |
| 729 |
11 |
| STRLEN length = (STRLEN)self->event.data.scalar.length; |
| 730 |
11 |
| char *anchor = (char *)self->event.data.scalar.anchor; |
| 731 |
11 |
| char *tag = (char *)self->event.data.scalar.tag; |
| 732 |
11 |
| char *prefix = (char*)TAG_PERL_PREFIX "regexp:"; |
| 733 |
|
| |
| 734 |
11 |
| SV *regexp = newSVpvn(string, length); |
| 735 |
11 |
| SvUTF8_on(regexp); |
| 736 |
|
| |
| 737 |
11 |
| ENTER; |
| 738 |
11 |
| SAVETMPS; |
| 739 |
11 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
11 |
11 |
|
| 740 |
11 |
▶ | XPUSHs(regexp); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(regexp); |
0 |
11 |
11 |
|
| 741 |
11 |
| PUTBACK; |
| 742 |
11 |
| call_pv("YAML::Safe::__qr_loader", G_SCALAR); |
| 743 |
11 |
| SPAGAIN; |
| 744 |
11 |
| regexp = newSVsv(POPs); |
| 745 |
|
| |
| 746 |
11 |
| PUTBACK; |
| 747 |
11 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
11 |
0 |
11 |
|
| 748 |
11 |
| LEAVE; |
| 749 |
|
| |
| 750 |
11 |
▶ | if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
8 |
3 |
11 |
| if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
0 |
3 |
3 |
|
| 751 |
3 |
▶ | if (!(self->flags & F_DISABLEBLESSED)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(self->flags & F_DISABLEBLESSED)) { |
1 |
2 |
3 |
|
| 752 |
2 |
| char *klass = tag + strlen(prefix); |
| 753 |
2 |
▶ | if (self->flags & F_SAFEMODE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->flags & F_SAFEMODE) { |
0 |
2 |
2 |
|
| 754 |
0 |
| if (!self->safeclasses || |
| 755 |
0 |
| !hv_exists(self->safeclasses, klass, strlen(klass))) |
| 756 |
|
| { |
| 757 |
0 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 758 |
|
| WARNMSG "skipped loading unsafe REGEXP for class %s", |
| 759 |
|
| klass); |
| 760 |
0 |
| goto cont_rx; |
| 761 |
|
| } |
| 762 |
|
| } |
| 763 |
2 |
| sv_bless(regexp, gv_stashpv(klass, TRUE)); |
| 764 |
|
| } |
| 765 |
|
| } |
| 766 |
9 |
| cont_rx: |
| 767 |
11 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
1 |
10 |
11 |
|
| 768 |
1 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 769 |
|
| SvREFCNT_inc(regexp), 0); |
| 770 |
11 |
| return regexp; |
| 771 |
|
| } |
| 772 |
|
| |
| 773 |
|
| /* Load a scalar marked as code as a Perl code reference. |
| 774 |
|
| * This operation is less common and is tricky, so doing it in Perl code for |
| 775 |
|
| * now. |
| 776 |
|
| */ |
| 777 |
|
| SV* |
| 778 |
6 |
| load_code(YAML * self) |
| 779 |
|
| { |
| 780 |
6 |
| dSP; |
| 781 |
6 |
| char *string = (char *)self->event.data.scalar.value; |
| 782 |
6 |
| STRLEN length = (STRLEN)self->event.data.scalar.length; |
| 783 |
6 |
| char *anchor = (char *)self->event.data.scalar.anchor; |
| 784 |
6 |
| char *tag = (char *)self->event.data.scalar.tag; |
| 785 |
6 |
| char *prefix = TAG_PERL_PREFIX "code:"; |
| 786 |
|
| SV *code; |
| 787 |
|
| |
| 788 |
6 |
▶ | if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
6 |
0 |
6 |
| if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
6 |
0 |
6 |
|
| 789 |
6 |
| char *klass = tag + strlen(prefix); |
| 790 |
6 |
▶ | if (self->flags & F_SAFEMODE && |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->flags & F_SAFEMODE && |
2 |
4 |
6 |
|
| 791 |
4 |
| (!self->safeclasses || |
| 792 |
2 |
| !hv_exists(self->safeclasses, klass, strlen(klass)))) |
| 793 |
|
| { |
| 794 |
1 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 795 |
|
| WARNMSG "skipped loading unsafe CODE for class %s", |
| 796 |
|
| klass); |
| 797 |
1 |
| return &PL_sv_undef; |
| 798 |
|
| } |
| 799 |
|
| } |
| 800 |
|
| |
| 801 |
5 |
▶ | if (!(self->flags & F_LOADCODE)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(self->flags & F_LOADCODE)) { |
1 |
4 |
5 |
|
| 802 |
1 |
| tag = ""; |
| 803 |
1 |
| string = "{}"; |
| 804 |
1 |
| length = 2; |
| 805 |
|
| } |
| 806 |
|
| |
| 807 |
5 |
| code = newSVpvn(string, length); |
| 808 |
5 |
| SvUTF8_on(code); |
| 809 |
|
| |
| 810 |
5 |
| ENTER; |
| 811 |
5 |
| SAVETMPS; |
| 812 |
5 |
▶ | PUSHMARK(sp); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(sp); |
0 |
5 |
5 |
|
| 813 |
5 |
▶ | XPUSHs(code); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(code); |
0 |
5 |
5 |
|
| 814 |
5 |
| PUTBACK; |
| 815 |
5 |
| call_pv("YAML::Safe::__code_loader", G_SCALAR); |
| 816 |
5 |
| SPAGAIN; |
| 817 |
5 |
| code = newSVsv(POPs); |
| 818 |
|
| |
| 819 |
5 |
| PUTBACK; |
| 820 |
5 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
5 |
0 |
5 |
|
| 821 |
5 |
| LEAVE; |
| 822 |
|
| |
| 823 |
5 |
▶ | if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
4 |
1 |
5 |
| if (strlen(tag) > strlen(prefix) && strnEQ(tag, prefix, strlen(prefix))) { |
4 |
0 |
4 |
|
| 824 |
4 |
▶ | if (!(self->flags & F_DISABLEBLESSED)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(self->flags & F_DISABLEBLESSED)) { |
4 |
0 |
4 |
|
| 825 |
4 |
| char *klass = tag + strlen(prefix); |
| 826 |
4 |
| sv_bless(code, gv_stashpv(klass, TRUE)); |
| 827 |
|
| } |
| 828 |
|
| } |
| 829 |
|
| |
| 830 |
5 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
0 |
5 |
5 |
|
| 831 |
0 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 832 |
|
| SvREFCNT_inc(code), 0); |
| 833 |
5 |
| return code; |
| 834 |
|
| } |
| 835 |
|
| |
| 836 |
|
| |
| 837 |
|
| /* |
| 838 |
|
| * Load a reference to a previously loaded node. |
| 839 |
|
| */ |
| 840 |
|
| static SV * |
| 841 |
16 |
| load_alias(YAML *self) |
| 842 |
|
| { |
| 843 |
16 |
| char *anchor = (char *)self->event.data.alias.anchor; |
| 844 |
16 |
| SV **entry = hv_fetch(self->anchors, anchor, strlen(anchor), 0); |
| 845 |
16 |
▶ | if (entry) |
Branch: 1 branch
| Branch | True | False | Total |
| if (entry) |
16 |
0 |
16 |
|
| 846 |
16 |
| return SvREFCNT_inc(*entry); |
| 847 |
0 |
| croak("%sNo anchor for alias '%s'", ERRMSG, anchor); |
| 848 |
|
| } |
| 849 |
|
| |
| 850 |
|
| /* |
| 851 |
|
| * Load a Perl hard reference. |
| 852 |
|
| */ |
| 853 |
|
| SV * |
| 854 |
16 |
| load_scalar_ref(YAML *self) |
| 855 |
|
| { |
| 856 |
|
| SV *value_node; |
| 857 |
16 |
| char *anchor = (char *)self->event.data.mapping_start.anchor; |
| 858 |
16 |
| SV *rv = newRV_noinc(&PL_sv_undef); |
| 859 |
16 |
▶ | if (anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (anchor) |
2 |
14 |
16 |
|
| 860 |
2 |
| (void)hv_store(self->anchors, anchor, strlen(anchor), |
| 861 |
|
| SvREFCNT_inc(rv), 0); |
| 862 |
16 |
| load_node(self); /* Load the single hash key (=) */ |
| 863 |
16 |
| value_node = load_node(self); |
| 864 |
16 |
| SvRV(rv) = value_node; |
| 865 |
16 |
▶ | if (load_node(self)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (load_node(self)) |
0 |
16 |
16 |
|
| 866 |
0 |
| croak("%sExpected end of node", ERRMSG); |
| 867 |
16 |
| return rv; |
| 868 |
|
| } |
| 869 |
|
| |
| 870 |
|
| /* |
| 871 |
|
| * Load a Perl typeglob. |
| 872 |
|
| */ |
| 873 |
|
| static SV * |
| 874 |
0 |
| load_glob(YAML *self) |
| 875 |
|
| { |
| 876 |
|
| /* XXX Call back a Perl sub to do something interesting here */ |
| 877 |
0 |
| return load_mapping(self, (char*)TAG_PERL_PREFIX "hash"); |
| 878 |
|
| } |
| 879 |
|
| |
| 880 |
|
| /* -------------------------------------------------------------------------- */ |
| 881 |
|
| |
| 882 |
|
| |
| 883 |
|
| /* |
| 884 |
|
| * This is the main Dump function. |
| 885 |
|
| * Take zero or more Perl objects from the stack |
| 886 |
|
| * and return a YAML stream (as a string) |
| 887 |
|
| */ |
| 888 |
|
| int |
| 889 |
83 |
| Dump(YAML *self, int yaml_ix) |
| 890 |
|
| { |
| 891 |
83 |
| dXSARGS; /* does POPMARK */ |
| 892 |
|
| yaml_event_t event_stream_start; |
| 893 |
|
| yaml_event_t event_stream_end; |
| 894 |
|
| int i; |
| 895 |
83 |
| SV *yaml = sv_2mortal(newSVpvn("", 0)); |
| 896 |
|
| |
| 897 |
83 |
| sp = mark; |
| 898 |
|
| |
| 899 |
83 |
| yaml_emitter_initialize(&self->emitter); |
| 900 |
83 |
| set_emitter_options(self, &self->emitter); |
| 901 |
83 |
| yaml_emitter_set_output( |
| 902 |
|
| &self->emitter, |
| 903 |
|
| &yaml_sv_write_handler, |
| 904 |
|
| (void *)yaml); |
| 905 |
|
| |
| 906 |
83 |
| yaml_stream_start_event_initialize(&event_stream_start, self->encoding); |
| 907 |
83 |
| yaml_emitter_emit(&self->emitter, &event_stream_start); |
| 908 |
|
| |
| 909 |
83 |
| self->anchors = (HV *)sv_2mortal((SV *)newHV()); |
| 910 |
83 |
| self->shadows = (HV *)sv_2mortal((SV *)newHV()); |
| 911 |
|
| |
| 912 |
186 |
▶ | for (i = yaml_ix; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = yaml_ix; i < items; i++) { |
103 |
83 |
186 |
|
| 913 |
103 |
| self->anchor = 0; |
| 914 |
|
| |
| 915 |
103 |
| dump_prewalk(self, ST(i)); |
| 916 |
103 |
| dump_document(self, ST(i)); |
| 917 |
|
| |
| 918 |
103 |
| hv_clear(self->anchors); |
| 919 |
103 |
| hv_clear(self->shadows); |
| 920 |
|
| } |
| 921 |
|
| |
| 922 |
|
| /* End emitting and destroy the emitter object */ |
| 923 |
83 |
| yaml_stream_end_event_initialize(&event_stream_end); |
| 924 |
83 |
| yaml_emitter_emit(&self->emitter, &event_stream_end); |
| 925 |
83 |
| yaml_emitter_delete(&self->emitter); |
| 926 |
|
| |
| 927 |
|
| /* Put the YAML stream scalar on the XS output stack */ |
| 928 |
83 |
▶ | if (yaml) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (yaml) { |
83 |
0 |
83 |
|
| 929 |
83 |
| sp = PL_stack_base + ax - 1; /* ax 0 */ |
| 930 |
83 |
| SvUTF8_off(yaml); |
| 931 |
83 |
▶ | XPUSHs(yaml); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(yaml); |
0 |
83 |
83 |
|
| 932 |
83 |
| PUTBACK; |
| 933 |
83 |
| return 1; |
| 934 |
|
| } else { |
| 935 |
0 |
| PUTBACK; |
| 936 |
0 |
| return 0; |
| 937 |
|
| } |
| 938 |
|
| } |
| 939 |
|
| |
| 940 |
|
| /* |
| 941 |
|
| * Dump zero or more Perl objects into the file |
| 942 |
|
| */ |
| 943 |
|
| int |
| 944 |
5 |
| DumpFile(YAML *self, SV *sv_file, int yaml_ix) |
| 945 |
|
| { |
| 946 |
5 |
| dXSARGS; |
| 947 |
|
| yaml_event_t event_stream_start; |
| 948 |
|
| yaml_event_t event_stream_end; |
| 949 |
5 |
| FILE *file = NULL; |
| 950 |
|
| const char *fname; |
| 951 |
|
| STRLEN len; |
| 952 |
|
| long i; |
| 953 |
|
| |
| 954 |
5 |
| sp = mark; |
| 955 |
|
| |
| 956 |
5 |
| yaml_emitter_initialize(&self->emitter); |
| 957 |
5 |
| set_emitter_options(self, &self->emitter); |
| 958 |
|
| |
| 959 |
5 |
▶ | if (SvROK(sv_file)) { /* pv mg or io or gv */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(sv_file)) { /* pv mg or io or gv */ |
3 |
2 |
5 |
|
| 960 |
3 |
| SV *rv = SvRV(sv_file); |
| 961 |
|
| |
| 962 |
3 |
▶ | if (SvTYPE(rv) == SVt_PVIO) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(rv) == SVt_PVIO) { |
0 |
3 |
3 |
|
| 963 |
0 |
| self->perlio = IoOFP(rv); |
| 964 |
0 |
| yaml_emitter_set_output(&self->emitter, |
| 965 |
|
| &yaml_perlio_write_handler, |
| 966 |
|
| self); |
| 967 |
3 |
▶ | } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
Branch: 6 branches
| Branch | True | False | Total |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
2 |
1 |
3 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
2 |
0 |
2 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
0 |
2 |
2 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
0 |
0 |
0 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
2 |
0 |
2 |
| } else if (SvTYPE(rv) == SVt_PVGV && GvIO(rv)) { |
2 |
0 |
2 |
|
| 968 |
2 |
| self->perlio = IoOFP(GvIOp(SvRV(sv_file))); |
| 969 |
2 |
| yaml_emitter_set_output(&self->emitter, |
| 970 |
|
| &yaml_perlio_write_handler, |
| 971 |
|
| self); |
| 972 |
1 |
▶ | } else if (SvMAGIC(rv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvMAGIC(rv)) { |
0 |
1 |
1 |
|
| 973 |
0 |
| mg_get(rv); |
| 974 |
0 |
| fname = SvPV_const(rv, len); |
| 975 |
0 |
| goto pv_dump; |
| 976 |
1 |
▶ | } else if (SvAMAGIC(sv_file)) { |
Branch: 3 branches
| Branch | True | False | Total |
| } else if (SvAMAGIC(sv_file)) { |
1 |
0 |
1 |
| } else if (SvAMAGIC(sv_file)) { |
1 |
0 |
1 |
| } else if (SvAMAGIC(sv_file)) { |
1 |
0 |
1 |
|
| 977 |
1 |
| fname = SvPV_const(sv_file, len); |
| 978 |
1 |
| goto pv_dump; |
| 979 |
|
| } else { |
| 980 |
0 |
| croak("Invalid argument type for file: ref of %s", Perl_sv_peek(aTHX_ rv)); |
| 981 |
|
| return 0; |
| 982 |
|
| } |
| 983 |
|
| } |
| 984 |
2 |
▶ | else if (SvPOK(sv_file)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (SvPOK(sv_file)) { |
2 |
0 |
2 |
|
| 985 |
2 |
| fname = (const char *)SvPV_const(sv_file, len); |
| 986 |
3 |
| pv_dump: |
| 987 |
3 |
| file = fopen(fname, "wb"); |
| 988 |
3 |
▶ | if (!file) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!file) { |
0 |
3 |
3 |
|
| 989 |
0 |
| croak("Can't open '%s' for output", fname); |
| 990 |
|
| return 0; |
| 991 |
|
| } |
| 992 |
3 |
| self->filename = (char *)fname; |
| 993 |
3 |
| yaml_emitter_set_output_file(&self->emitter, file); |
| 994 |
0 |
▶ | } else if (SvTYPE(sv_file) == SVt_PVIO) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (SvTYPE(sv_file) == SVt_PVIO) { |
0 |
0 |
0 |
|
| 995 |
0 |
| self->perlio = IoOFP(sv_file); |
| 996 |
0 |
| yaml_emitter_set_output(&self->emitter, |
| 997 |
|
| &yaml_perlio_write_handler, |
| 998 |
|
| self); |
| 999 |
0 |
▶ | } else if (SvTYPE(sv_file) == SVt_PVGV && GvIO(sv_file)) { |
Branch: 6 branches
| Branch | True | False | Total |
| } else if (SvTYPE(sv_file) == SVt_PVGV && GvIO(sv_file)) { |
0 |
0 |
0 |
| } else if (SvTYPE(sv_file) == SVt_PVGV && GvIO(sv_file)) { |
0 |
0 |
0 |
| } else if (SvTYPE(sv_file) == SVt_PVGV && GvIO(sv_file)) { |
0 |
0 |
0 |
| } else if (SvTYPE(sv_file) == SVt_PVGV && GvIO(sv_file)) { |
0 |
0 |
0 |
| } else if (SvTYPE(sv_file) == SVt_PVGV && GvIO(sv_file)) { |
0 |
0 |
0 |
| } else if (SvTYPE(sv_file) == SVt_PVGV && GvIO(sv_file)) { |
0 |
0 |
0 |
|
| 1000 |
0 |
| self->perlio = IoOFP(GvIOp(sv_file)); |
| 1001 |
0 |
| yaml_emitter_set_output(&self->emitter, |
| 1002 |
|
| &yaml_perlio_write_handler, |
| 1003 |
|
| self); |
| 1004 |
|
| } else { |
| 1005 |
|
| /* sv_peek since 5.005 */ |
| 1006 |
0 |
| croak("Invalid argument type for file: %s", Perl_sv_peek(aTHX_ sv_file)); |
| 1007 |
|
| return 0; |
| 1008 |
|
| } |
| 1009 |
|
| |
| 1010 |
5 |
| yaml_stream_start_event_initialize(&event_stream_start, |
| 1011 |
|
| self->encoding); |
| 1012 |
5 |
▶ | if (!yaml_emitter_emit(&self->emitter, &event_stream_start)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!yaml_emitter_emit(&self->emitter, &event_stream_start)) { |
0 |
5 |
5 |
|
| 1013 |
0 |
| PUTBACK; |
| 1014 |
0 |
| return 0; |
| 1015 |
|
| } |
| 1016 |
|
| |
| 1017 |
5 |
| self->anchors = (HV *)sv_2mortal((SV *)newHV()); |
| 1018 |
5 |
| self->shadows = (HV *)sv_2mortal((SV *)newHV()); |
| 1019 |
|
| |
| 1020 |
|
| /* ST(yaml_ix) is the file */ |
| 1021 |
12 |
▶ | for (i = yaml_ix+1; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = yaml_ix+1; i < items; i++) { |
7 |
5 |
12 |
|
| 1022 |
7 |
| self->anchor = 0; |
| 1023 |
|
| |
| 1024 |
7 |
| dump_prewalk(self, ST(i)); |
| 1025 |
7 |
| dump_document(self, ST(i)); |
| 1026 |
|
| |
| 1027 |
7 |
| hv_clear(self->anchors); |
| 1028 |
7 |
| hv_clear(self->shadows); |
| 1029 |
|
| } |
| 1030 |
|
| |
| 1031 |
|
| /* End emitting and destroy the emitter object */ |
| 1032 |
5 |
| yaml_stream_end_event_initialize(&event_stream_end); |
| 1033 |
5 |
▶ | if (!yaml_emitter_emit(&self->emitter, &event_stream_end)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!yaml_emitter_emit(&self->emitter, &event_stream_end)) { |
0 |
5 |
5 |
|
| 1034 |
0 |
| PUTBACK; |
| 1035 |
0 |
| return 0; |
| 1036 |
|
| } |
| 1037 |
5 |
| yaml_emitter_delete(&self->emitter); |
| 1038 |
5 |
▶ | if (file) |
Branch: 1 branch
| Branch | True | False | Total |
| if (file) |
3 |
2 |
5 |
|
| 1039 |
3 |
| fclose(file); |
| 1040 |
2 |
▶ | else if (SvTYPE(sv_file) == SVt_PVIO) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (SvTYPE(sv_file) == SVt_PVIO) |
0 |
2 |
2 |
|
| 1041 |
0 |
| PerlIO_close(IoOFP(sv_file)); |
| 1042 |
|
| |
| 1043 |
5 |
| PUTBACK; |
| 1044 |
5 |
| return 1; |
| 1045 |
|
| } |
| 1046 |
|
| |
| 1047 |
|
| /* |
| 1048 |
|
| * In order to know which nodes will need anchors (for later aliasing) it is |
| 1049 |
|
| * necessary to walk the entire data structure first. Once a node has been |
| 1050 |
|
| * seen twice you can stop walking it. That way we can handle circular refs. |
| 1051 |
|
| * All the node information is stored in an HV. |
| 1052 |
|
| */ |
| 1053 |
|
| static void |
| 1054 |
308 |
| dump_prewalk(YAML *self, SV *node) |
| 1055 |
|
| { |
| 1056 |
|
| int i; |
| 1057 |
|
| U32 ref_type; |
| 1058 |
|
| |
| 1059 |
308 |
▶ | if (! (SvROK(node) || SvTYPE(node) == SVt_PVGV)) return; |
Branch: 2 branches
| Branch | True | False | Total |
| if (! (SvROK(node) || SvTYPE(node) == SVt_PVGV)) return; |
164 |
144 |
308 |
| if (! (SvROK(node) || SvTYPE(node) == SVt_PVGV)) return; |
159 |
5 |
164 |
|
| 1060 |
|
| |
| 1061 |
|
| { |
| 1062 |
149 |
▶ | SV *object = SvROK(node) ? SvRV(node) : node; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *object = SvROK(node) ? SvRV(node) : node; |
144 |
5 |
149 |
|
| 1063 |
|
| SV **seen = |
| 1064 |
149 |
| hv_fetch(self->anchors, (char *)&object, sizeof(object), 0); |
| 1065 |
149 |
▶ | if (seen) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (seen) { |
17 |
132 |
149 |
|
| 1066 |
17 |
▶ | if (*seen == &PL_sv_undef) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*seen == &PL_sv_undef) { |
16 |
1 |
17 |
|
| 1067 |
16 |
| (void)hv_store(self->anchors, (char *)&object, sizeof(object), |
| 1068 |
|
| &PL_sv_yes, 0); |
| 1069 |
|
| } |
| 1070 |
17 |
| return; |
| 1071 |
|
| } |
| 1072 |
132 |
| (void)hv_store(self->anchors, (char *)&object, sizeof(object), |
| 1073 |
|
| &PL_sv_undef, 0); |
| 1074 |
|
| } |
| 1075 |
|
| |
| 1076 |
132 |
▶ | if (SvTYPE(node) == SVt_PVGV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(node) == SVt_PVGV) { |
2 |
130 |
132 |
|
| 1077 |
2 |
| node = dump_glob(self, node); |
| 1078 |
|
| } |
| 1079 |
|
| |
| 1080 |
132 |
| ref_type = SvTYPE(SvRV(node)); |
| 1081 |
132 |
▶ | if (ref_type == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ref_type == SVt_PVAV) { |
44 |
88 |
132 |
|
| 1082 |
44 |
| AV *array = (AV *)SvRV(node); |
| 1083 |
44 |
| int array_size = av_len(array) + 1; |
| 1084 |
135 |
▶ | for (i = 0; i < array_size; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < array_size; i++) { |
91 |
44 |
135 |
|
| 1085 |
91 |
| SV **entry = av_fetch(array, i, 0); |
| 1086 |
91 |
▶ | if (entry) |
Branch: 1 branch
| Branch | True | False | Total |
| if (entry) |
91 |
0 |
91 |
|
| 1087 |
91 |
| dump_prewalk(self, *entry); |
| 1088 |
|
| } |
| 1089 |
|
| } |
| 1090 |
88 |
▶ | else if (ref_type == SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (ref_type == SVt_PVHV) { |
48 |
40 |
88 |
|
| 1091 |
48 |
| HV *hash = (HV *)SvRV(node); |
| 1092 |
|
| HE *he; |
| 1093 |
48 |
| hv_iterinit(hash); |
| 1094 |
190 |
▶ | while ((he = hv_iternext(hash))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(hash))) { |
94 |
48 |
142 |
|
| 1095 |
94 |
| SV *val = HeVAL(he); |
| 1096 |
94 |
▶ | if (val) |
Branch: 1 branch
| Branch | True | False | Total |
| if (val) |
6 |
88 |
94 |
|
| 1097 |
88 |
| dump_prewalk(self, val); |
| 1098 |
|
| } |
| 1099 |
|
| } |
| 1100 |
40 |
▶ | else if (ref_type <= SVt_PVNV || ref_type == SVt_PVGV) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (ref_type <= SVt_PVNV || ref_type == SVt_PVGV) { |
24 |
16 |
40 |
| else if (ref_type <= SVt_PVNV || ref_type == SVt_PVGV) { |
3 |
21 |
24 |
|
| 1101 |
19 |
| SV *scalar = SvRV(node); |
| 1102 |
19 |
| dump_prewalk(self, scalar); |
| 1103 |
|
| } |
| 1104 |
|
| } |
| 1105 |
|
| |
| 1106 |
|
| static void |
| 1107 |
110 |
| dump_document(YAML *self, SV *node) |
| 1108 |
|
| { |
| 1109 |
|
| yaml_event_t event_document_start; |
| 1110 |
|
| yaml_event_t event_document_end; |
| 1111 |
110 |
| yaml_document_start_event_initialize( |
| 1112 |
|
| &event_document_start, NULL, NULL, NULL, 0); |
| 1113 |
110 |
| yaml_emitter_emit(&self->emitter, &event_document_start); |
| 1114 |
110 |
| dump_node(self, node); |
| 1115 |
110 |
| yaml_document_end_event_initialize(&event_document_end, 1); |
| 1116 |
110 |
| yaml_emitter_emit(&self->emitter, &event_document_end); |
| 1117 |
110 |
| } |
| 1118 |
|
| |
| 1119 |
|
| static void |
| 1120 |
402 |
| dump_node(YAML *self, SV *node) |
| 1121 |
|
| { |
| 1122 |
402 |
| yaml_char_t *anchor = NULL; |
| 1123 |
402 |
| yaml_char_t *tag = NULL; |
| 1124 |
402 |
| const char *klass = NULL; |
| 1125 |
|
| |
| 1126 |
402 |
▶ | if (SvTYPE(node) == SVt_PVGV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(node) == SVt_PVGV) { |
5 |
397 |
402 |
|
| 1127 |
|
| SV **svr; |
| 1128 |
5 |
| tag = (yaml_char_t *)TAG_PERL_PREFIX "glob"; |
| 1129 |
5 |
| anchor = get_yaml_anchor(self, node); |
| 1130 |
5 |
▶ | if (anchor && strEQ((char *)anchor, "")) |
Branch: 2 branches
| Branch | True | False | Total |
| if (anchor && strEQ((char *)anchor, "")) |
3 |
2 |
5 |
| if (anchor && strEQ((char *)anchor, "")) |
3 |
0 |
3 |
|
| 1131 |
3 |
| return; |
| 1132 |
2 |
| svr = hv_fetch(self->shadows, (char *)&node, sizeof(node), 0); |
| 1133 |
2 |
▶ | if (svr) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (svr) { |
2 |
0 |
2 |
|
| 1134 |
2 |
| node = SvREFCNT_inc(*svr); |
| 1135 |
|
| } |
| 1136 |
|
| } |
| 1137 |
|
| |
| 1138 |
399 |
▶ | if (SvROK(node)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(node)) { |
146 |
253 |
399 |
|
| 1139 |
146 |
| SV *rnode = SvRV(node); |
| 1140 |
146 |
| U32 ref_type = SvTYPE(rnode); |
| 1141 |
146 |
▶ | if (ref_type == SVt_PVHV) |
Branch: 1 branch
| Branch | True | False | Total |
| if (ref_type == SVt_PVHV) |
53 |
93 |
146 |
|
| 1142 |
53 |
| dump_hash(self, node, anchor, tag); |
| 1143 |
93 |
▶ | else if (ref_type == SVt_PVAV) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (ref_type == SVt_PVAV) |
50 |
43 |
93 |
|
| 1144 |
50 |
| dump_array(self, node); |
| 1145 |
43 |
▶ | else if (ref_type <= SVt_PVNV || ref_type == SVt_PVGV) |
Branch: 2 branches
| Branch | True | False | Total |
| else if (ref_type <= SVt_PVNV || ref_type == SVt_PVGV) |
25 |
18 |
43 |
| else if (ref_type <= SVt_PVNV || ref_type == SVt_PVGV) |
4 |
21 |
25 |
|
| 1146 |
22 |
| dump_ref(self, node); |
| 1147 |
21 |
▶ | else if (ref_type == SVt_PVCV) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (ref_type == SVt_PVCV) |
5 |
16 |
21 |
|
| 1148 |
5 |
| dump_code(self, node); |
| 1149 |
16 |
▶ | else if (ref_type == SVt_PVMG) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (ref_type == SVt_PVMG) { |
10 |
6 |
16 |
|
| 1150 |
|
| MAGIC *mg; |
| 1151 |
10 |
| yaml_char_t *tag = NULL; |
| 1152 |
10 |
▶ | if (SvMAGICAL(rnode)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvMAGICAL(rnode)) { |
0 |
10 |
10 |
|
| 1153 |
0 |
▶ | if ((mg = mg_find(rnode, PERL_MAGIC_qr))) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ((mg = mg_find(rnode, PERL_MAGIC_qr))) { |
0 |
0 |
0 |
|
| 1154 |
0 |
| tag = (yaml_char_t *)form(TAG_PERL_PREFIX "regexp"); |
| 1155 |
0 |
| klass = sv_reftype(rnode, TRUE); |
| 1156 |
0 |
▶ | if (!strEQ(klass, "Regexp")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!strEQ(klass, "Regexp")) |
0 |
0 |
0 |
|
| 1157 |
0 |
| tag = (yaml_char_t *)form("%s:%s", tag, klass); |
| 1158 |
|
| } |
| 1159 |
0 |
| dump_scalar(self, node, tag); |
| 1160 |
|
| } |
| 1161 |
|
| else { |
| 1162 |
10 |
| klass = sv_reftype(rnode, TRUE); |
| 1163 |
10 |
▶ | if (self->boolean != YAML_BOOLEAN_NONE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->boolean != YAML_BOOLEAN_NONE) { |
8 |
2 |
10 |
|
| 1164 |
8 |
▶ | if (SvIV(node)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvIV(node)) |
4 |
4 |
8 |
|
| 1165 |
4 |
| dump_scalar(self, &PL_sv_yes, NULL); |
| 1166 |
|
| else |
| 1167 |
4 |
| dump_scalar(self, &PL_sv_no, NULL); |
| 1168 |
|
| } |
| 1169 |
|
| else { |
| 1170 |
2 |
| tag = (yaml_char_t *)form( |
| 1171 |
|
| TAG_PERL_PREFIX "scalar:%s", |
| 1172 |
|
| klass); |
| 1173 |
2 |
| node = rnode; |
| 1174 |
2 |
| dump_scalar(self, node, tag); |
| 1175 |
|
| } |
| 1176 |
|
| } |
| 1177 |
|
| } |
| 1178 |
|
| #if PERL_VERSION >= 11 |
| 1179 |
6 |
▶ | else if (ref_type == SVt_REGEXP) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (ref_type == SVt_REGEXP) { |
6 |
0 |
6 |
|
| 1180 |
6 |
| yaml_char_t *tag = (yaml_char_t *)form(TAG_PERL_PREFIX "regexp"); |
| 1181 |
6 |
| klass = sv_reftype(rnode, TRUE); |
| 1182 |
6 |
▶ | if (!strEQ(klass, "Regexp")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!strEQ(klass, "Regexp")) |
1 |
5 |
6 |
|
| 1183 |
1 |
| tag = (yaml_char_t *)form("%s:%s", tag, klass); |
| 1184 |
6 |
| dump_scalar(self, node, tag); |
| 1185 |
|
| } |
| 1186 |
|
| #endif |
| 1187 |
|
| else { |
| 1188 |
0 |
| printf("YAML::Safe dump unhandled ref. type == '%d'!\n", |
| 1189 |
|
| (int)ref_type); |
| 1190 |
0 |
| dump_scalar(self, rnode, NULL); |
| 1191 |
|
| } |
| 1192 |
|
| } |
| 1193 |
|
| else { |
| 1194 |
253 |
| dump_scalar(self, node, NULL); |
| 1195 |
|
| } |
| 1196 |
|
| } |
| 1197 |
|
| |
| 1198 |
|
| static yaml_char_t * |
| 1199 |
130 |
| get_yaml_anchor(YAML *self, SV *node) |
| 1200 |
|
| { |
| 1201 |
|
| yaml_event_t event_alias; |
| 1202 |
|
| SV *iv; |
| 1203 |
130 |
| SV **seen = hv_fetch(self->anchors, (char *)&node, sizeof(node), 0); |
| 1204 |
130 |
▶ | if (seen && *seen != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (seen && *seen != &PL_sv_undef) { |
128 |
2 |
130 |
| if (seen && *seen != &PL_sv_undef) { |
33 |
95 |
128 |
|
| 1205 |
33 |
▶ | if (*seen == &PL_sv_yes) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*seen == &PL_sv_yes) { |
16 |
17 |
33 |
|
| 1206 |
16 |
| self->anchor++; |
| 1207 |
16 |
| iv = newSViv(self->anchor); |
| 1208 |
16 |
| (void)hv_store(self->anchors, (char *)&node, sizeof(node), iv, 0); |
| 1209 |
16 |
| return (yaml_char_t*)SvPV_nolen(iv); |
| 1210 |
|
| } |
| 1211 |
|
| else { |
| 1212 |
17 |
| yaml_char_t *anchor = (yaml_char_t *)SvPV_nolen(*seen); |
| 1213 |
17 |
| yaml_alias_event_initialize(&event_alias, anchor); |
| 1214 |
17 |
| yaml_emitter_emit(&self->emitter, &event_alias); |
| 1215 |
17 |
| return (yaml_char_t *) ""; |
| 1216 |
|
| } |
| 1217 |
|
| } |
| 1218 |
97 |
| return NULL; |
| 1219 |
|
| } |
| 1220 |
|
| |
| 1221 |
|
| static yaml_char_t * |
| 1222 |
95 |
| get_yaml_tag(SV *node) |
| 1223 |
|
| { |
| 1224 |
95 |
| yaml_char_t *tag = NULL; |
| 1225 |
95 |
| char *kind = (char*)""; |
| 1226 |
|
| char *klass; |
| 1227 |
|
| |
| 1228 |
95 |
▶ | if (! (sv_isobject(node) |
Branch: 1 branch
| Branch | True | False | Total |
| if (! (sv_isobject(node) |
82 |
13 |
95 |
|
| 1229 |
82 |
▶ | || (SvRV(node) && ( SvTYPE(SvRV(node)) == SVt_PVCV)))) |
Branch: 2 branches
| Branch | True | False | Total |
| || (SvRV(node) && ( SvTYPE(SvRV(node)) == SVt_PVCV)))) |
82 |
0 |
82 |
| || (SvRV(node) && ( SvTYPE(SvRV(node)) == SVt_PVCV)))) |
81 |
1 |
82 |
|
| 1230 |
81 |
| return NULL; |
| 1231 |
14 |
| klass = (char *)sv_reftype(SvRV(node), TRUE); |
| 1232 |
|
| |
| 1233 |
14 |
| switch (SvTYPE(SvRV(node))) { |
| 1234 |
3 |
| case SVt_PVAV: |
| 1235 |
3 |
| tag = (yaml_char_t *)form("%s%s:%s", TAG_PERL_PREFIX, "array", klass); |
| 1236 |
3 |
| break; |
| 1237 |
6 |
| case SVt_PVHV: |
| 1238 |
6 |
| tag = (yaml_char_t *)form("%s%s:%s", TAG_PERL_PREFIX, "hash", klass); |
| 1239 |
6 |
| break; |
| 1240 |
5 |
| case SVt_PVCV: |
| 1241 |
5 |
| kind = (char*)"code"; |
| 1242 |
5 |
▶ | if (strEQ(klass, "CODE")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(klass, "CODE")) |
1 |
4 |
5 |
|
| 1243 |
1 |
| tag = (yaml_char_t *)form("%s%s", TAG_PERL_PREFIX, kind); |
| 1244 |
|
| else |
| 1245 |
4 |
| tag = (yaml_char_t *)form("%s%s:%s", TAG_PERL_PREFIX, kind, klass); |
| 1246 |
5 |
| break; |
| 1247 |
0 |
| default: |
| 1248 |
0 |
| tag = (yaml_char_t *)form("%s%s", TAG_PERL_PREFIX, klass); |
| 1249 |
0 |
| break; |
| 1250 |
|
| } |
| 1251 |
14 |
▶ | if (!tag) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!tag) |
0 |
14 |
14 |
|
| 1252 |
0 |
| tag = (yaml_char_t *)form("%s%s:%s", TAG_PERL_PREFIX, kind, klass); |
| 1253 |
14 |
| return tag; |
| 1254 |
|
| } |
| 1255 |
|
| |
| 1256 |
|
| static void |
| 1257 |
53 |
| dump_hash( |
| 1258 |
|
| YAML *self, SV *node, |
| 1259 |
|
| yaml_char_t *anchor, yaml_char_t *tag) |
| 1260 |
|
| { |
| 1261 |
|
| yaml_event_t event_mapping_start; |
| 1262 |
|
| yaml_event_t event_mapping_end; |
| 1263 |
|
| STRLEN i, len; |
| 1264 |
|
| AV *av; |
| 1265 |
53 |
| HV *hash = (HV *)SvRV(node); |
| 1266 |
|
| HE *he; |
| 1267 |
|
| |
| 1268 |
53 |
▶ | if (!anchor) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!anchor) |
53 |
0 |
53 |
|
| 1269 |
53 |
| anchor = get_yaml_anchor(self, (SV *)hash); |
| 1270 |
53 |
▶ | if (anchor && strEQ((char*)anchor, "")) |
Branch: 2 branches
| Branch | True | False | Total |
| if (anchor && strEQ((char*)anchor, "")) |
10 |
43 |
53 |
| if (anchor && strEQ((char*)anchor, "")) |
5 |
5 |
10 |
|
| 1271 |
5 |
| return; |
| 1272 |
|
| |
| 1273 |
48 |
▶ | if (!tag) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!tag) |
46 |
2 |
48 |
|
| 1274 |
46 |
| tag = get_yaml_tag(node); |
| 1275 |
48 |
▶ | if (tag && self->flags & F_SAFEMODE) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (tag && self->flags & F_SAFEMODE) { |
8 |
40 |
48 |
| if (tag && self->flags & F_SAFEMODE) { |
1 |
7 |
8 |
|
| 1276 |
1 |
| char *prefix = TAG_PERL_PREFIX "hash:"; |
| 1277 |
1 |
| char *klass = (char*)tag + strlen(prefix); |
| 1278 |
1 |
| STRLEN len = strlen(klass); |
| 1279 |
1 |
▶ | if (SvOBJECT(node)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOBJECT(node)) { |
0 |
1 |
1 |
|
| 1280 |
0 |
| HV* stash = SvSTASH(node); |
| 1281 |
0 |
▶ | klass = HvNAME_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
|
| 1282 |
0 |
▶ | len = HvNAMELEN_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
|
| 1283 |
0 |
▶ | if (HvNAMEUTF8(stash)) |
Branch: 7 branches
| Branch | True | False | Total |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
|
| 1284 |
0 |
| len = -len; |
| 1285 |
|
| } |
| 1286 |
2 |
| if (!self->safeclasses || |
| 1287 |
1 |
| !hv_exists(self->safeclasses, klass, len)) |
| 1288 |
|
| { |
| 1289 |
0 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 1290 |
|
| WARNMSG "skipped dumping unsafe HASH in class %s", |
| 1291 |
|
| klass); |
| 1292 |
0 |
| hash = (HV*)sv_2mortal((SV*)newHV()); |
| 1293 |
|
| } |
| 1294 |
|
| } |
| 1295 |
|
| |
| 1296 |
48 |
| yaml_mapping_start_event_initialize( |
| 1297 |
|
| &event_mapping_start, anchor, tag, 0, YAML_BLOCK_MAPPING_STYLE); |
| 1298 |
48 |
| yaml_emitter_emit(&self->emitter, &event_mapping_start); |
| 1299 |
|
| |
| 1300 |
48 |
| av = newAV(); |
| 1301 |
48 |
| len = 0; |
| 1302 |
48 |
| hv_iterinit(hash); |
| 1303 |
139 |
▶ | while ((he = hv_iternext(hash))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(hash))) { |
91 |
48 |
139 |
|
| 1304 |
91 |
| SV *key = hv_iterkeysv(he); |
| 1305 |
91 |
| av_store(av, AvFILLp(av)+1, key); /* av_push(), really */ |
| 1306 |
91 |
| len++; |
| 1307 |
|
| } |
| 1308 |
48 |
| STORE_HASH_SORT; |
| 1309 |
139 |
▶ | for (i = 0; i < len; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < len; i++) { |
91 |
48 |
139 |
|
| 1310 |
91 |
| SV *key = av_shift(av); |
| 1311 |
91 |
| HE *he = hv_fetch_ent(hash, key, 0, 0); |
| 1312 |
91 |
▶ | SV *val = he ? HeVAL(he) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV *val = he ? HeVAL(he) : NULL; |
91 |
0 |
91 |
|
| 1313 |
91 |
▶ | if (val == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (val == NULL) |
0 |
91 |
91 |
|
| 1314 |
0 |
| val = &PL_sv_undef; |
| 1315 |
91 |
| dump_node(self, key); |
| 1316 |
91 |
| dump_node(self, val); |
| 1317 |
|
| } |
| 1318 |
|
| |
| 1319 |
48 |
| SvREFCNT_dec(av); |
| 1320 |
|
| |
| 1321 |
48 |
| yaml_mapping_end_event_initialize(&event_mapping_end); |
| 1322 |
48 |
| yaml_emitter_emit(&self->emitter, &event_mapping_end); |
| 1323 |
|
| } |
| 1324 |
|
| |
| 1325 |
|
| static void |
| 1326 |
50 |
| dump_array(YAML *self, SV *node) |
| 1327 |
|
| { |
| 1328 |
|
| yaml_event_t event_sequence_start; |
| 1329 |
|
| yaml_event_t event_sequence_end; |
| 1330 |
|
| yaml_char_t *tag; |
| 1331 |
50 |
| AV *array = (AV *)SvRV(node); |
| 1332 |
|
| STRLEN i; |
| 1333 |
50 |
| STRLEN array_size = av_len(array) + 1; |
| 1334 |
|
| |
| 1335 |
50 |
| yaml_char_t *anchor = get_yaml_anchor(self, (SV *)array); |
| 1336 |
50 |
▶ | if (anchor && strEQ((char *)anchor, "")) |
Branch: 2 branches
| Branch | True | False | Total |
| if (anchor && strEQ((char *)anchor, "")) |
12 |
38 |
50 |
| if (anchor && strEQ((char *)anchor, "")) |
6 |
6 |
12 |
|
| 1337 |
6 |
| return; |
| 1338 |
44 |
| tag = get_yaml_tag(node); |
| 1339 |
44 |
▶ | if (tag && self->flags & F_SAFEMODE) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (tag && self->flags & F_SAFEMODE) { |
3 |
41 |
44 |
| if (tag && self->flags & F_SAFEMODE) { |
1 |
2 |
3 |
|
| 1340 |
1 |
| char *prefix = TAG_PERL_PREFIX "array:"; |
| 1341 |
1 |
| char *klass = (char*)tag + strlen(prefix); |
| 1342 |
1 |
| STRLEN len = strlen(klass); |
| 1343 |
1 |
▶ | if (SvOBJECT(node)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOBJECT(node)) { |
0 |
1 |
1 |
|
| 1344 |
0 |
| HV* stash = SvSTASH(node); |
| 1345 |
0 |
▶ | klass = HvNAME_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
|
| 1346 |
0 |
▶ | len = HvNAMELEN_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
|
| 1347 |
0 |
▶ | if (HvNAMEUTF8(stash)) |
Branch: 7 branches
| Branch | True | False | Total |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
| if (HvNAMEUTF8(stash)) |
0 |
0 |
0 |
|
| 1348 |
0 |
| len = -len; |
| 1349 |
|
| } |
| 1350 |
2 |
| if (!self->safeclasses || |
| 1351 |
1 |
| !hv_exists(self->safeclasses, klass, len)) |
| 1352 |
|
| { |
| 1353 |
0 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 1354 |
|
| WARNMSG "skipped dumping unsafe ARRAY in class %s", |
| 1355 |
|
| klass); |
| 1356 |
0 |
| array_size = 0; |
| 1357 |
|
| } |
| 1358 |
|
| } |
| 1359 |
|
| |
| 1360 |
44 |
| yaml_sequence_start_event_initialize( |
| 1361 |
|
| &event_sequence_start, anchor, tag, 0, YAML_BLOCK_SEQUENCE_STYLE); |
| 1362 |
44 |
| yaml_emitter_emit(&self->emitter, &event_sequence_start); |
| 1363 |
|
| |
| 1364 |
135 |
▶ | for (i = 0; i < array_size; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < array_size; i++) { |
91 |
44 |
135 |
|
| 1365 |
91 |
| SV **entry = av_fetch(array, i, 0); |
| 1366 |
91 |
▶ | if (entry == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (entry == NULL) |
0 |
91 |
91 |
|
| 1367 |
0 |
| dump_node(self, &PL_sv_undef); |
| 1368 |
|
| else |
| 1369 |
91 |
| dump_node(self, *entry); |
| 1370 |
|
| } |
| 1371 |
44 |
| yaml_sequence_end_event_initialize(&event_sequence_end); |
| 1372 |
44 |
| yaml_emitter_emit(&self->emitter, &event_sequence_end); |
| 1373 |
|
| } |
| 1374 |
|
| |
| 1375 |
|
| static void |
| 1376 |
269 |
| dump_scalar(YAML *self, SV *node, yaml_char_t *tag) |
| 1377 |
|
| { |
| 1378 |
|
| yaml_event_t event_scalar; |
| 1379 |
|
| char *string; |
| 1380 |
|
| STRLEN string_len; |
| 1381 |
|
| int plain_implicit, quoted_implicit; |
| 1382 |
269 |
| yaml_scalar_style_t style = YAML_PLAIN_SCALAR_STYLE; |
| 1383 |
|
| |
| 1384 |
269 |
▶ | if (tag) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (tag) { |
8 |
261 |
269 |
|
| 1385 |
8 |
▶ | if (self->flags & F_SAFEMODE && SvOBJECT(node)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (self->flags & F_SAFEMODE && SvOBJECT(node)) { |
1 |
7 |
8 |
| if (self->flags & F_SAFEMODE && SvOBJECT(node)) { |
1 |
0 |
1 |
|
| 1386 |
1 |
| HV* stash = SvSTASH(node); |
| 1387 |
1 |
▶ | char *klass = HvNAME_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| char *klass = HvNAME_get(stash); |
1 |
0 |
1 |
| char *klass = HvNAME_get(stash); |
1 |
0 |
1 |
| char *klass = HvNAME_get(stash); |
0 |
1 |
1 |
| char *klass = HvNAME_get(stash); |
0 |
0 |
0 |
| char *klass = HvNAME_get(stash); |
1 |
0 |
1 |
| char *klass = HvNAME_get(stash); |
0 |
1 |
1 |
|
| 1388 |
1 |
▶ | STRLEN len = HvNAMELEN_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| STRLEN len = HvNAMELEN_get(stash); |
1 |
0 |
1 |
| STRLEN len = HvNAMELEN_get(stash); |
1 |
0 |
1 |
| STRLEN len = HvNAMELEN_get(stash); |
0 |
1 |
1 |
| STRLEN len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| STRLEN len = HvNAMELEN_get(stash); |
1 |
0 |
1 |
| STRLEN len = HvNAMELEN_get(stash); |
0 |
1 |
1 |
|
| 1389 |
1 |
▶ | if (HvNAMEUTF8(stash)) |
Branch: 7 branches
| Branch | True | False | Total |
| if (HvNAMEUTF8(stash)) |
1 |
0 |
1 |
| if (HvNAMEUTF8(stash)) |
1 |
0 |
1 |
| if (HvNAMEUTF8(stash)) |
0 |
1 |
1 |
| if (HvNAMEUTF8(stash)) |
1 |
0 |
1 |
| if (HvNAMEUTF8(stash)) |
0 |
1 |
1 |
| if (HvNAMEUTF8(stash)) |
0 |
1 |
1 |
| if (HvNAMEUTF8(stash)) |
0 |
1 |
1 |
|
| 1390 |
0 |
| len = -len; |
| 1391 |
2 |
| if (!self->safeclasses || |
| 1392 |
1 |
| !hv_exists(self->safeclasses, klass, len)) |
| 1393 |
|
| { |
| 1394 |
0 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 1395 |
|
| WARNMSG "skipped dumping unsafe SCALAR for class %s", |
| 1396 |
|
| klass); |
| 1397 |
0 |
| node = &PL_sv_undef; |
| 1398 |
|
| } |
| 1399 |
|
| } |
| 1400 |
8 |
| plain_implicit = quoted_implicit = 0; |
| 1401 |
|
| } |
| 1402 |
|
| else { |
| 1403 |
261 |
| tag = (yaml_char_t *)TAG_PERL_STR; |
| 1404 |
261 |
| plain_implicit = quoted_implicit = 1; |
| 1405 |
|
| } |
| 1406 |
|
| |
| 1407 |
269 |
| SvGETMAGIC(node); |
| 1408 |
269 |
▶ | if (!SvOK(node)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(node)) { |
6 |
263 |
269 |
|
| 1409 |
6 |
| string = "~"; |
| 1410 |
6 |
| string_len = 1; |
| 1411 |
6 |
| style = YAML_PLAIN_SCALAR_STYLE; |
| 1412 |
|
| } |
| 1413 |
263 |
▶ | else if (node == &PL_sv_yes) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (node == &PL_sv_yes) { |
6 |
257 |
263 |
|
| 1414 |
6 |
| string = "true"; |
| 1415 |
6 |
| string_len = 4; |
| 1416 |
6 |
| style = YAML_PLAIN_SCALAR_STYLE; |
| 1417 |
|
| } |
| 1418 |
257 |
▶ | else if (node == &PL_sv_no) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (node == &PL_sv_no) { |
6 |
251 |
257 |
|
| 1419 |
6 |
| string = "false"; |
| 1420 |
6 |
| string_len = 5; |
| 1421 |
6 |
| style = YAML_PLAIN_SCALAR_STYLE; |
| 1422 |
|
| } |
| 1423 |
|
| else { |
| 1424 |
251 |
| SV *node_clone = sv_mortalcopy(node); |
| 1425 |
251 |
| string = SvPV_nomg(node_clone, string_len); |
| 1426 |
251 |
| if ( |
| 1427 |
251 |
▶ | (string_len == 0) || |
Branch: 1 branch
| Branch | True | False | Total |
| (string_len == 0) || |
246 |
5 |
251 |
|
| 1428 |
246 |
▶ | (string_len == 1 && strEQ(string, "~")) || |
Branch: 2 branches
| Branch | True | False | Total |
| (string_len == 1 && strEQ(string, "~")) || |
41 |
205 |
246 |
| (string_len == 1 && strEQ(string, "~")) || |
40 |
1 |
41 |
|
| 1429 |
245 |
▶ | (string_len == 4 && |
Branch: 1 branch
| Branch | True | False | Total |
| (string_len == 4 && |
25 |
220 |
245 |
|
| 1430 |
25 |
▶ | (strEQ(string, "true") || strEQ(string, "null"))) || |
Branch: 2 branches
| Branch | True | False | Total |
| (strEQ(string, "true") || strEQ(string, "null"))) || |
20 |
5 |
25 |
| (strEQ(string, "true") || strEQ(string, "null"))) || |
20 |
0 |
20 |
|
| 1431 |
240 |
▶ | (string_len == 5 && strEQ(string, "false")) || |
Branch: 2 branches
| Branch | True | False | Total |
| (string_len == 5 && strEQ(string, "false")) || |
22 |
218 |
240 |
| (string_len == 5 && strEQ(string, "false")) || |
17 |
5 |
22 |
|
| 1432 |
235 |
▶ | (SvTYPE(node_clone) >= SVt_PVGV) || |
Branch: 1 branch
| Branch | True | False | Total |
| (SvTYPE(node_clone) >= SVt_PVGV) || |
235 |
0 |
235 |
|
| 1433 |
235 |
▶ | ( (self->flags & F_QUOTENUM) && |
Branch: 1 branch
| Branch | True | False | Total |
| ( (self->flags & F_QUOTENUM) && |
228 |
7 |
235 |
|
| 1434 |
410 |
| !SvNIOK(node_clone) && |
| 1435 |
182 |
| looks_like_number(node_clone) ) ) |
| 1436 |
|
| { |
| 1437 |
20 |
| style = YAML_SINGLE_QUOTED_SCALAR_STYLE; |
| 1438 |
|
| } else { |
| 1439 |
231 |
▶ | if (!SvUTF8(node_clone)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvUTF8(node_clone)) { |
202 |
29 |
231 |
|
| 1440 |
|
| /* copy to new SV and promote to utf8 */ |
| 1441 |
202 |
| SV *utf8sv = sv_mortalcopy(node_clone); |
| 1442 |
|
| |
| 1443 |
|
| /* get string and length out of utf8 */ |
| 1444 |
202 |
| string = SvPVutf8(utf8sv, string_len); |
| 1445 |
|
| } |
| 1446 |
231 |
▶ | if(strchr(string, '\n')) |
Branch: 1 branch
| Branch | True | False | Total |
| if(strchr(string, '\n')) |
4 |
227 |
231 |
|
| 1447 |
4 |
| style = (string_len > 30) ? YAML_LITERAL_SCALAR_STYLE |
| 1448 |
4 |
▶ | : YAML_DOUBLE_QUOTED_SCALAR_STYLE; |
Branch: 1 branch
| Branch | True | False | Total |
| : YAML_DOUBLE_QUOTED_SCALAR_STYLE; |
1 |
3 |
4 |
|
| 1449 |
|
| } |
| 1450 |
|
| } |
| 1451 |
269 |
| yaml_scalar_event_initialize( |
| 1452 |
|
| &event_scalar, |
| 1453 |
|
| NULL, /* anchor */ |
| 1454 |
|
| tag, |
| 1455 |
|
| (unsigned char *) string, |
| 1456 |
|
| (int) string_len, |
| 1457 |
|
| plain_implicit, |
| 1458 |
|
| quoted_implicit, |
| 1459 |
|
| style); |
| 1460 |
269 |
▶ | if (! yaml_emitter_emit(&self->emitter, &event_scalar)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (! yaml_emitter_emit(&self->emitter, &event_scalar)) |
0 |
269 |
269 |
|
| 1461 |
0 |
| croak("%sEmit scalar '%s', error: %s\n", |
| 1462 |
|
| ERRMSG, string, self->emitter.problem); |
| 1463 |
269 |
| } |
| 1464 |
|
| |
| 1465 |
|
| static void |
| 1466 |
5 |
| dump_code(YAML *self, SV *node) |
| 1467 |
|
| { |
| 1468 |
|
| yaml_event_t event_scalar; |
| 1469 |
|
| yaml_char_t *tag; |
| 1470 |
5 |
| yaml_scalar_style_t style = YAML_SINGLE_QUOTED_SCALAR_STYLE; |
| 1471 |
5 |
| char *string = "{ \"DUMMY\" }"; |
| 1472 |
|
| |
| 1473 |
5 |
| tag = get_yaml_tag(node); |
| 1474 |
|
| |
| 1475 |
5 |
▶ | if (self->flags & F_DUMPCODE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->flags & F_DUMPCODE) { |
3 |
2 |
5 |
|
| 1476 |
|
| /* load_module(PERL_LOADMOD_NOIMPORT, newSVpv("B::Deparse", 0), NULL); |
| 1477 |
|
| */ |
| 1478 |
|
| SV *code; |
| 1479 |
3 |
| SV *result = NULL; |
| 1480 |
3 |
▶ | if (self->flags & F_SAFEMODE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->flags & F_SAFEMODE) { |
2 |
1 |
3 |
|
| 1481 |
|
| char *klass; STRLEN len; |
| 1482 |
2 |
| SV* rnode = SvRV(node); |
| 1483 |
4 |
| HV* stash = SvOBJECT(rnode) |
| 1484 |
2 |
| ? SvSTASH(rnode) |
| 1485 |
2 |
▶ | : GvSTASH(CvGV(rnode)); |
Branch: 1 branch
| Branch | True | False | Total |
| : GvSTASH(CvGV(rnode)); |
2 |
0 |
2 |
|
| 1486 |
2 |
▶ | if (!stash) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!stash) |
0 |
2 |
2 |
|
| 1487 |
0 |
| stash = CvSTASH(rnode); |
| 1488 |
2 |
▶ | klass = HvNAME_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| klass = HvNAME_get(stash); |
2 |
0 |
2 |
| klass = HvNAME_get(stash); |
2 |
0 |
2 |
| klass = HvNAME_get(stash); |
0 |
2 |
2 |
| klass = HvNAME_get(stash); |
0 |
0 |
0 |
| klass = HvNAME_get(stash); |
2 |
0 |
2 |
| klass = HvNAME_get(stash); |
0 |
2 |
2 |
|
| 1489 |
2 |
▶ | len = HvNAMELEN_get(stash); |
Branch: 6 branches
| Branch | True | False | Total |
| len = HvNAMELEN_get(stash); |
2 |
0 |
2 |
| len = HvNAMELEN_get(stash); |
2 |
0 |
2 |
| len = HvNAMELEN_get(stash); |
0 |
2 |
2 |
| len = HvNAMELEN_get(stash); |
0 |
0 |
0 |
| len = HvNAMELEN_get(stash); |
2 |
0 |
2 |
| len = HvNAMELEN_get(stash); |
0 |
2 |
2 |
|
| 1490 |
2 |
▶ | if (HvNAMEUTF8(stash)) |
Branch: 7 branches
| Branch | True | False | Total |
| if (HvNAMEUTF8(stash)) |
2 |
0 |
2 |
| if (HvNAMEUTF8(stash)) |
2 |
0 |
2 |
| if (HvNAMEUTF8(stash)) |
0 |
2 |
2 |
| if (HvNAMEUTF8(stash)) |
2 |
0 |
2 |
| if (HvNAMEUTF8(stash)) |
0 |
2 |
2 |
| if (HvNAMEUTF8(stash)) |
0 |
2 |
2 |
| if (HvNAMEUTF8(stash)) |
0 |
2 |
2 |
|
| 1491 |
0 |
| len = -len; |
| 1492 |
2 |
▶ | if (!self->safeclasses || !hv_exists(self->safeclasses, klass, len)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!self->safeclasses || !hv_exists(self->safeclasses, klass, len)) { |
2 |
0 |
2 |
| if (!self->safeclasses || !hv_exists(self->safeclasses, klass, len)) { |
1 |
1 |
2 |
|
| 1493 |
1 |
| Perl_warner(aTHX_ packWARN(WARN_MISC), |
| 1494 |
|
| WARNMSG "skipped dumping unsafe CODE for class %s", |
| 1495 |
|
| klass); |
| 1496 |
1 |
| string = "{ \"UNSAFE\" }"; |
| 1497 |
1 |
| result = &PL_sv_undef; |
| 1498 |
|
| } |
| 1499 |
|
| } |
| 1500 |
3 |
▶ | if (result != &PL_sv_undef) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (result != &PL_sv_undef) { |
2 |
1 |
3 |
|
| 1501 |
2 |
| AV *args = newAV(); |
| 1502 |
2 |
| av_push(args, SvREFCNT_inc(node)); |
| 1503 |
2 |
| code = find_coderef("YAML::Safe::coderef2text"); |
| 1504 |
2 |
| result = call_coderef(code, (AV*)sv_2mortal((SV *)args)); |
| 1505 |
|
| } |
| 1506 |
3 |
▶ | if (result && result != &PL_sv_undef) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (result && result != &PL_sv_undef) { |
3 |
0 |
3 |
| if (result && result != &PL_sv_undef) { |
2 |
1 |
3 |
|
| 1507 |
2 |
| string = SvPV_nolen(result); |
| 1508 |
2 |
| style = YAML_LITERAL_SCALAR_STYLE; |
| 1509 |
|
| } |
| 1510 |
|
| } |
| 1511 |
|
| |
| 1512 |
10 |
▶ | yaml_scalar_event_initialize( |
Branch: 1 branch
| Branch | True | False | Total |
| yaml_scalar_event_initialize( |
5 |
0 |
5 |
|
| 1513 |
|
| &event_scalar, |
| 1514 |
|
| NULL, /* anchor */ |
| 1515 |
|
| tag, |
| 1516 |
|
| (unsigned char *)string, |
| 1517 |
5 |
| string ? strlen(string) : 0, |
| 1518 |
|
| 0, |
| 1519 |
|
| 0, |
| 1520 |
|
| style); |
| 1521 |
5 |
| yaml_emitter_emit(&self->emitter, &event_scalar); |
| 1522 |
5 |
| } |
| 1523 |
|
| |
| 1524 |
|
| static SV * |
| 1525 |
2 |
| dump_glob(YAML *self, SV *node) |
| 1526 |
|
| { |
| 1527 |
|
| SV *result; |
| 1528 |
2 |
| SV *code = find_coderef("YAML::Safe::glob2hash"); |
| 1529 |
2 |
| AV *args = newAV(); |
| 1530 |
|
| /* TODO: safemode */ |
| 1531 |
2 |
| av_push(args, SvREFCNT_inc(node)); |
| 1532 |
2 |
| args = (AV *)sv_2mortal((SV *)args); |
| 1533 |
2 |
| result = call_coderef(code, args); |
| 1534 |
2 |
| (void)hv_store(self->shadows, (char *)&node, sizeof(node), |
| 1535 |
|
| result, 0); |
| 1536 |
2 |
| return result; |
| 1537 |
|
| } |
| 1538 |
|
| |
| 1539 |
|
| /* XXX Refo this to just dump a special map */ |
| 1540 |
|
| static void |
| 1541 |
22 |
| dump_ref(YAML *self, SV *node) |
| 1542 |
|
| { |
| 1543 |
|
| yaml_event_t event_mapping_start; |
| 1544 |
|
| yaml_event_t event_mapping_end; |
| 1545 |
|
| yaml_event_t event_scalar; |
| 1546 |
22 |
| SV *referent = SvRV(node); |
| 1547 |
|
| |
| 1548 |
22 |
| yaml_char_t *anchor = get_yaml_anchor(self, referent); |
| 1549 |
22 |
▶ | if (anchor && strEQ((char *)anchor, "")) |
Branch: 2 branches
| Branch | True | False | Total |
| if (anchor && strEQ((char *)anchor, "")) |
8 |
14 |
22 |
| if (anchor && strEQ((char *)anchor, "")) |
3 |
5 |
8 |
|
| 1550 |
3 |
| return; |
| 1551 |
|
| |
| 1552 |
19 |
| yaml_mapping_start_event_initialize( |
| 1553 |
|
| &event_mapping_start, anchor, |
| 1554 |
|
| (unsigned char *)TAG_PERL_PREFIX "ref", |
| 1555 |
|
| 0, YAML_BLOCK_MAPPING_STYLE); |
| 1556 |
19 |
| yaml_emitter_emit(&self->emitter, &event_mapping_start); |
| 1557 |
|
| |
| 1558 |
19 |
| yaml_scalar_event_initialize( |
| 1559 |
|
| &event_scalar, |
| 1560 |
|
| NULL, /* anchor */ |
| 1561 |
|
| NULL, /* tag */ |
| 1562 |
|
| (unsigned char *)"=", 1, |
| 1563 |
|
| 1, 1, |
| 1564 |
|
| YAML_PLAIN_SCALAR_STYLE); |
| 1565 |
19 |
| yaml_emitter_emit(&self->emitter, &event_scalar); |
| 1566 |
19 |
| dump_node(self, referent); |
| 1567 |
|
| |
| 1568 |
19 |
| yaml_mapping_end_event_initialize(&event_mapping_end); |
| 1569 |
19 |
| yaml_emitter_emit(&self->emitter, &event_mapping_end); |
| 1570 |
|
| } |
| 1571 |
|
| |
| 1572 |
|
| static int |
| 1573 |
103 |
| yaml_sv_write_handler(void *sv, unsigned char *buffer, size_t size) |
| 1574 |
|
| { |
| 1575 |
103 |
| sv_catpvn((SV *)sv, (const char *)buffer, (STRLEN)size); |
| 1576 |
103 |
| return 1; |
| 1577 |
|
| } |
| 1578 |
|
| |
| 1579 |
|
| static int |
| 1580 |
4 |
| yaml_perlio_read_handler(void *data, unsigned char *buffer, size_t size, size_t *size_read) |
| 1581 |
|
| { |
| 1582 |
4 |
| YAML *self = (YAML *)data; |
| 1583 |
|
| |
| 1584 |
4 |
| *size_read = PerlIO_read(self->perlio, buffer, size); |
| 1585 |
4 |
| return !PerlIO_error(self->perlio); |
| 1586 |
|
| } |
| 1587 |
|
| |
| 1588 |
|
| static int |
| 1589 |
2 |
| yaml_perlio_write_handler(void *data, unsigned char *buffer, size_t size) |
| 1590 |
|
| { |
| 1591 |
2 |
| YAML *self = (YAML *)data; |
| 1592 |
2 |
| return (PerlIO_write(self->perlio, (char*)buffer, (long)size) == (SSize_t)size); |
| 1593 |
|
| } |
| 1594 |
|
| |
| 1595 |
|
| /* XXX Make -Wall not complain about 'local_patches' not being used. */ |
| 1596 |
|
| #if !defined(PERL_PATCHLEVEL_H_IMPLICIT) |
| 1597 |
0 |
| void xxx_local_patches() { |
| 1598 |
0 |
▶ | if (local_patches[0]) |
Branch: 1 branch
| Branch | True | False | Total |
| if (local_patches[0]) |
0 |
0 |
0 |
|
| 1599 |
0 |
| printf("%s", local_patches[0]); |
| 1600 |
0 |
| } |
| 1601 |
|
| #endif |
| 1602 |
|
| |
| 1603 |
|
| void |
| 1604 |
23 |
| yaml_destroy (YAML *self) |
| 1605 |
|
| { |
| 1606 |
23 |
▶ | if (!self) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!self) |
0 |
23 |
23 |
|
| 1607 |
0 |
| return; |
| 1608 |
|
| /* self->filename gets deleted with sv_file */ |
| 1609 |
23 |
| yaml_parser_delete (&self->parser); |
| 1610 |
23 |
| yaml_event_delete (&self->event); |
| 1611 |
23 |
| yaml_emitter_delete (&self->emitter); |
| 1612 |
23 |
| Zero(self, 1, YAML); |
| 1613 |
|
| } |