psych 3.3.2 → 5.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +24 -0
  3. data/README.md +6 -5
  4. data/ext/psych/depend +13 -1
  5. data/ext/psych/extconf.rb +40 -30
  6. data/ext/psych/psych.c +1 -1
  7. data/ext/psych/psych_emitter.c +155 -120
  8. data/ext/psych/psych_parser.c +267 -281
  9. data/lib/psych/class_loader.rb +5 -5
  10. data/lib/psych/core_ext.rb +1 -1
  11. data/lib/psych/exception.rb +16 -2
  12. data/lib/psych/handlers/document_stream.rb +1 -1
  13. data/lib/psych/handlers/recorder.rb +1 -1
  14. data/lib/psych/json/stream.rb +2 -2
  15. data/lib/psych/json/tree_builder.rb +1 -1
  16. data/lib/psych/nodes/node.rb +5 -5
  17. data/lib/psych/nodes.rb +7 -7
  18. data/lib/psych/parser.rb +13 -0
  19. data/lib/psych/scalar_scanner.rb +24 -19
  20. data/lib/psych/syntax_error.rb +1 -1
  21. data/lib/psych/tree_builder.rb +3 -3
  22. data/lib/psych/versions.rb +2 -2
  23. data/lib/psych/visitors/json_tree.rb +1 -1
  24. data/lib/psych/visitors/to_ruby.rb +12 -11
  25. data/lib/psych/visitors/yaml_tree.rb +71 -27
  26. data/lib/psych/visitors.rb +6 -6
  27. data/lib/psych.rb +204 -106
  28. metadata +37 -25
  29. data/.gitignore +0 -16
  30. data/Gemfile +0 -9
  31. data/Mavenfile +0 -7
  32. data/Rakefile +0 -41
  33. data/bin/console +0 -7
  34. data/bin/setup +0 -6
  35. data/ext/psych/yaml/LICENSE +0 -19
  36. data/ext/psych/yaml/api.c +0 -1393
  37. data/ext/psych/yaml/config.h +0 -80
  38. data/ext/psych/yaml/dumper.c +0 -394
  39. data/ext/psych/yaml/emitter.c +0 -2358
  40. data/ext/psych/yaml/loader.c +0 -544
  41. data/ext/psych/yaml/parser.c +0 -1375
  42. data/ext/psych/yaml/reader.c +0 -469
  43. data/ext/psych/yaml/scanner.c +0 -3598
  44. data/ext/psych/yaml/writer.c +0 -141
  45. data/ext/psych/yaml/yaml.h +0 -1985
  46. data/ext/psych/yaml/yaml_private.h +0 -688
  47. data/psych.gemspec +0 -67
@@ -32,9 +32,9 @@ static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read)
32
32
  *read = 0;
33
33
 
34
34
  if(! NIL_P(string)) {
35
- void * str = (void *)StringValuePtr(string);
36
- *read = (size_t)RSTRING_LEN(string);
37
- memcpy(buf, str, *read);
35
+ void * str = (void *)StringValuePtr(string);
36
+ *read = (size_t)RSTRING_LEN(string);
37
+ memcpy(buf, str, *read);
38
38
  }
39
39
 
40
40
  return 1;
@@ -79,21 +79,25 @@ static VALUE allocate(VALUE klass)
79
79
 
80
80
  static VALUE make_exception(yaml_parser_t * parser, VALUE path)
81
81
  {
82
- size_t line, column;
83
- VALUE ePsychSyntaxError;
82
+ if (parser->error == YAML_MEMORY_ERROR) {
83
+ return rb_eNoMemError;
84
+ } else {
85
+ size_t line, column;
86
+ VALUE ePsychSyntaxError;
84
87
 
85
- line = parser->context_mark.line + 1;
86
- column = parser->context_mark.column + 1;
88
+ line = parser->context_mark.line + 1;
89
+ column = parser->context_mark.column + 1;
87
90
 
88
- ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
91
+ ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
89
92
 
90
- return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
91
- path,
92
- SIZET2NUM(line),
93
- SIZET2NUM(column),
94
- SIZET2NUM(parser->problem_offset),
95
- parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
96
- parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
93
+ return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
94
+ path,
95
+ SIZET2NUM(line),
96
+ SIZET2NUM(column),
97
+ SIZET2NUM(parser->problem_offset),
98
+ parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
99
+ parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
100
+ }
97
101
  }
98
102
 
99
103
  static VALUE transcode_string(VALUE src, int * parser_encoding)
@@ -104,18 +108,18 @@ static VALUE transcode_string(VALUE src, int * parser_encoding)
104
108
  int source_encoding = rb_enc_get_index(src);
105
109
 
106
110
  if (source_encoding == utf8) {
107
- *parser_encoding = YAML_UTF8_ENCODING;
108
- return src;
111
+ *parser_encoding = YAML_UTF8_ENCODING;
112
+ return src;
109
113
  }
110
114
 
111
115
  if (source_encoding == utf16le) {
112
- *parser_encoding = YAML_UTF16LE_ENCODING;
113
- return src;
116
+ *parser_encoding = YAML_UTF16LE_ENCODING;
117
+ return src;
114
118
  }
115
119
 
116
120
  if (source_encoding == utf16be) {
117
- *parser_encoding = YAML_UTF16BE_ENCODING;
118
- return src;
121
+ *parser_encoding = YAML_UTF16BE_ENCODING;
122
+ return src;
119
123
  }
120
124
 
121
125
  src = rb_str_export_to_enc(src, rb_utf8_encoding());
@@ -134,36 +138,36 @@ static VALUE transcode_io(VALUE src, int * parser_encoding)
134
138
 
135
139
  /* if no encoding is returned, assume ascii8bit. */
136
140
  if (NIL_P(io_external_encoding)) {
137
- io_external_enc_index = rb_ascii8bit_encindex();
141
+ io_external_enc_index = rb_ascii8bit_encindex();
138
142
  } else {
139
- io_external_enc_index = rb_to_encoding_index(io_external_encoding);
143
+ io_external_enc_index = rb_to_encoding_index(io_external_encoding);
140
144
  }
141
145
 
142
146
  /* Treat US-ASCII as utf_8 */
143
147
  if (io_external_enc_index == rb_usascii_encindex()) {
144
- *parser_encoding = YAML_UTF8_ENCODING;
145
- return src;
148
+ *parser_encoding = YAML_UTF8_ENCODING;
149
+ return src;
146
150
  }
147
151
 
148
152
  if (io_external_enc_index == rb_utf8_encindex()) {
149
- *parser_encoding = YAML_UTF8_ENCODING;
150
- return src;
153
+ *parser_encoding = YAML_UTF8_ENCODING;
154
+ return src;
151
155
  }
152
156
 
153
157
  if (io_external_enc_index == rb_enc_find_index("UTF-16LE")) {
154
- *parser_encoding = YAML_UTF16LE_ENCODING;
155
- return src;
158
+ *parser_encoding = YAML_UTF16LE_ENCODING;
159
+ return src;
156
160
  }
157
161
 
158
162
  if (io_external_enc_index == rb_enc_find_index("UTF-16BE")) {
159
- *parser_encoding = YAML_UTF16BE_ENCODING;
160
- return src;
163
+ *parser_encoding = YAML_UTF16BE_ENCODING;
164
+ return src;
161
165
  }
162
166
 
163
167
  /* Just guess on ASCII-8BIT */
164
168
  if (io_external_enc_index == rb_ascii8bit_encindex()) {
165
- *parser_encoding = YAML_ANY_ENCODING;
166
- return src;
169
+ *parser_encoding = YAML_ANY_ENCODING;
170
+ return src;
167
171
  }
168
172
 
169
173
  /* If the external encoding is something we don't know how to handle,
@@ -241,18 +245,8 @@ static VALUE protected_event_location(VALUE pointer)
241
245
  return rb_funcall3(args[0], id_event_location, 4, args + 1);
242
246
  }
243
247
 
244
- /*
245
- * call-seq:
246
- * parser.parse(yaml)
247
- *
248
- * Parse the YAML document contained in +yaml+. Events will be called on
249
- * the handler set on the parser instance.
250
- *
251
- * See Psych::Parser and Psych::Parser#handler
252
- */
253
- static VALUE parse(int argc, VALUE *argv, VALUE self)
248
+ static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path)
254
249
  {
255
- VALUE yaml, path;
256
250
  yaml_parser_t * parser;
257
251
  yaml_event_t event;
258
252
  int done = 0;
@@ -260,14 +254,6 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
260
254
  int parser_encoding = YAML_ANY_ENCODING;
261
255
  int encoding = rb_utf8_encindex();
262
256
  rb_encoding * internal_enc = rb_default_internal_encoding();
263
- VALUE handler = rb_iv_get(self, "@handler");
264
-
265
- if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) {
266
- if(rb_respond_to(yaml, id_path))
267
- path = rb_funcall(yaml, id_path, 0);
268
- else
269
- path = rb_str_new2("<unknown>");
270
- }
271
257
 
272
258
  TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
273
259
 
@@ -275,238 +261,238 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
275
261
  yaml_parser_initialize(parser);
276
262
 
277
263
  if (rb_respond_to(yaml, id_read)) {
278
- yaml = transcode_io(yaml, &parser_encoding);
279
- yaml_parser_set_encoding(parser, parser_encoding);
280
- yaml_parser_set_input(parser, io_reader, (void *)yaml);
264
+ yaml = transcode_io(yaml, &parser_encoding);
265
+ yaml_parser_set_encoding(parser, parser_encoding);
266
+ yaml_parser_set_input(parser, io_reader, (void *)yaml);
281
267
  } else {
282
- StringValue(yaml);
283
- yaml = transcode_string(yaml, &parser_encoding);
284
- yaml_parser_set_encoding(parser, parser_encoding);
285
- yaml_parser_set_input_string(
286
- parser,
287
- (const unsigned char *)RSTRING_PTR(yaml),
288
- (size_t)RSTRING_LEN(yaml)
289
- );
268
+ StringValue(yaml);
269
+ yaml = transcode_string(yaml, &parser_encoding);
270
+ yaml_parser_set_encoding(parser, parser_encoding);
271
+ yaml_parser_set_input_string(
272
+ parser,
273
+ (const unsigned char *)RSTRING_PTR(yaml),
274
+ (size_t)RSTRING_LEN(yaml)
275
+ );
290
276
  }
291
277
 
292
278
  while(!done) {
293
- VALUE event_args[5];
294
- VALUE start_line, start_column, end_line, end_column;
295
-
296
- if(!yaml_parser_parse(parser, &event)) {
297
- VALUE exception;
298
-
299
- exception = make_exception(parser, path);
300
- yaml_parser_delete(parser);
301
- yaml_parser_initialize(parser);
302
-
303
- rb_exc_raise(exception);
304
- }
305
-
306
- start_line = SIZET2NUM(event.start_mark.line);
307
- start_column = SIZET2NUM(event.start_mark.column);
308
- end_line = SIZET2NUM(event.end_mark.line);
309
- end_column = SIZET2NUM(event.end_mark.column);
310
-
311
- event_args[0] = handler;
312
- event_args[1] = start_line;
313
- event_args[2] = start_column;
314
- event_args[3] = end_line;
315
- event_args[4] = end_column;
316
- rb_protect(protected_event_location, (VALUE)event_args, &state);
317
-
318
- switch(event.type) {
319
- case YAML_STREAM_START_EVENT:
320
- {
321
- VALUE args[2];
322
-
323
- args[0] = handler;
324
- args[1] = INT2NUM(event.data.stream_start.encoding);
325
- rb_protect(protected_start_stream, (VALUE)args, &state);
326
- }
327
- break;
328
- case YAML_DOCUMENT_START_EVENT:
329
- {
330
- VALUE args[4];
331
- /* Get a list of tag directives (if any) */
332
- VALUE tag_directives = rb_ary_new();
333
- /* Grab the document version */
334
- VALUE version = event.data.document_start.version_directive ?
335
- rb_ary_new3(
336
- (long)2,
337
- INT2NUM(event.data.document_start.version_directive->major),
338
- INT2NUM(event.data.document_start.version_directive->minor)
339
- ) : rb_ary_new();
340
-
341
- if(event.data.document_start.tag_directives.start) {
342
- yaml_tag_directive_t *start =
343
- event.data.document_start.tag_directives.start;
344
- yaml_tag_directive_t *end =
345
- event.data.document_start.tag_directives.end;
346
- for(; start != end; start++) {
347
- VALUE handle = Qnil;
348
- VALUE prefix = Qnil;
349
- if(start->handle) {
350
- handle = rb_str_new2((const char *)start->handle);
351
- PSYCH_TRANSCODE(handle, encoding, internal_enc);
352
- }
353
-
354
- if(start->prefix) {
355
- prefix = rb_str_new2((const char *)start->prefix);
356
- PSYCH_TRANSCODE(prefix, encoding, internal_enc);
357
- }
358
-
359
- rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix));
360
- }
361
- }
362
- args[0] = handler;
363
- args[1] = version;
364
- args[2] = tag_directives;
365
- args[3] = event.data.document_start.implicit == 1 ? Qtrue : Qfalse;
366
- rb_protect(protected_start_document, (VALUE)args, &state);
367
- }
368
- break;
369
- case YAML_DOCUMENT_END_EVENT:
370
- {
371
- VALUE args[2];
372
-
373
- args[0] = handler;
374
- args[1] = event.data.document_end.implicit == 1 ? Qtrue : Qfalse;
375
- rb_protect(protected_end_document, (VALUE)args, &state);
376
- }
377
- break;
378
- case YAML_ALIAS_EVENT:
379
- {
380
- VALUE args[2];
381
- VALUE alias = Qnil;
382
- if(event.data.alias.anchor) {
383
- alias = rb_str_new2((const char *)event.data.alias.anchor);
384
- PSYCH_TRANSCODE(alias, encoding, internal_enc);
385
- }
386
-
387
- args[0] = handler;
388
- args[1] = alias;
389
- rb_protect(protected_alias, (VALUE)args, &state);
390
- }
391
- break;
392
- case YAML_SCALAR_EVENT:
393
- {
394
- VALUE args[7];
395
- VALUE anchor = Qnil;
396
- VALUE tag = Qnil;
397
- VALUE plain_implicit, quoted_implicit, style;
398
- VALUE val = rb_str_new(
399
- (const char *)event.data.scalar.value,
400
- (long)event.data.scalar.length
401
- );
402
-
403
- PSYCH_TRANSCODE(val, encoding, internal_enc);
404
-
405
- if(event.data.scalar.anchor) {
406
- anchor = rb_str_new2((const char *)event.data.scalar.anchor);
407
- PSYCH_TRANSCODE(anchor, encoding, internal_enc);
408
- }
409
-
410
- if(event.data.scalar.tag) {
411
- tag = rb_str_new2((const char *)event.data.scalar.tag);
412
- PSYCH_TRANSCODE(tag, encoding, internal_enc);
413
- }
414
-
415
- plain_implicit =
416
- event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
417
-
418
- quoted_implicit =
419
- event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
420
-
421
- style = INT2NUM(event.data.scalar.style);
422
-
423
- args[0] = handler;
424
- args[1] = val;
425
- args[2] = anchor;
426
- args[3] = tag;
427
- args[4] = plain_implicit;
428
- args[5] = quoted_implicit;
429
- args[6] = style;
430
- rb_protect(protected_scalar, (VALUE)args, &state);
431
- }
432
- break;
433
- case YAML_SEQUENCE_START_EVENT:
434
- {
435
- VALUE args[5];
436
- VALUE anchor = Qnil;
437
- VALUE tag = Qnil;
438
- VALUE implicit, style;
439
- if(event.data.sequence_start.anchor) {
440
- anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
441
- PSYCH_TRANSCODE(anchor, encoding, internal_enc);
442
- }
443
-
444
- tag = Qnil;
445
- if(event.data.sequence_start.tag) {
446
- tag = rb_str_new2((const char *)event.data.sequence_start.tag);
447
- PSYCH_TRANSCODE(tag, encoding, internal_enc);
448
- }
449
-
450
- implicit =
451
- event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
452
-
453
- style = INT2NUM(event.data.sequence_start.style);
454
-
455
- args[0] = handler;
456
- args[1] = anchor;
457
- args[2] = tag;
458
- args[3] = implicit;
459
- args[4] = style;
460
-
461
- rb_protect(protected_start_sequence, (VALUE)args, &state);
462
- }
463
- break;
464
- case YAML_SEQUENCE_END_EVENT:
465
- rb_protect(protected_end_sequence, handler, &state);
466
- break;
467
- case YAML_MAPPING_START_EVENT:
468
- {
469
- VALUE args[5];
470
- VALUE anchor = Qnil;
471
- VALUE tag = Qnil;
472
- VALUE implicit, style;
473
- if(event.data.mapping_start.anchor) {
474
- anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
475
- PSYCH_TRANSCODE(anchor, encoding, internal_enc);
476
- }
477
-
478
- if(event.data.mapping_start.tag) {
479
- tag = rb_str_new2((const char *)event.data.mapping_start.tag);
480
- PSYCH_TRANSCODE(tag, encoding, internal_enc);
481
- }
482
-
483
- implicit =
484
- event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
485
-
486
- style = INT2NUM(event.data.mapping_start.style);
487
-
488
- args[0] = handler;
489
- args[1] = anchor;
490
- args[2] = tag;
491
- args[3] = implicit;
492
- args[4] = style;
493
-
494
- rb_protect(protected_start_mapping, (VALUE)args, &state);
495
- }
496
- break;
497
- case YAML_MAPPING_END_EVENT:
498
- rb_protect(protected_end_mapping, handler, &state);
499
- break;
500
- case YAML_NO_EVENT:
501
- rb_protect(protected_empty, handler, &state);
502
- break;
503
- case YAML_STREAM_END_EVENT:
504
- rb_protect(protected_end_stream, handler, &state);
505
- done = 1;
506
- break;
507
- }
508
- yaml_event_delete(&event);
509
- if (state) rb_jump_tag(state);
279
+ VALUE event_args[5];
280
+ VALUE start_line, start_column, end_line, end_column;
281
+
282
+ if(parser->error || !yaml_parser_parse(parser, &event)) {
283
+ VALUE exception;
284
+
285
+ exception = make_exception(parser, path);
286
+ yaml_parser_delete(parser);
287
+ yaml_parser_initialize(parser);
288
+
289
+ rb_exc_raise(exception);
290
+ }
291
+
292
+ start_line = SIZET2NUM(event.start_mark.line);
293
+ start_column = SIZET2NUM(event.start_mark.column);
294
+ end_line = SIZET2NUM(event.end_mark.line);
295
+ end_column = SIZET2NUM(event.end_mark.column);
296
+
297
+ event_args[0] = handler;
298
+ event_args[1] = start_line;
299
+ event_args[2] = start_column;
300
+ event_args[3] = end_line;
301
+ event_args[4] = end_column;
302
+ rb_protect(protected_event_location, (VALUE)event_args, &state);
303
+
304
+ switch(event.type) {
305
+ case YAML_STREAM_START_EVENT:
306
+ {
307
+ VALUE args[2];
308
+
309
+ args[0] = handler;
310
+ args[1] = INT2NUM(event.data.stream_start.encoding);
311
+ rb_protect(protected_start_stream, (VALUE)args, &state);
312
+ }
313
+ break;
314
+ case YAML_DOCUMENT_START_EVENT:
315
+ {
316
+ VALUE args[4];
317
+ /* Get a list of tag directives (if any) */
318
+ VALUE tag_directives = rb_ary_new();
319
+ /* Grab the document version */
320
+ VALUE version = event.data.document_start.version_directive ?
321
+ rb_ary_new3(
322
+ (long)2,
323
+ INT2NUM(event.data.document_start.version_directive->major),
324
+ INT2NUM(event.data.document_start.version_directive->minor)
325
+ ) : rb_ary_new();
326
+
327
+ if(event.data.document_start.tag_directives.start) {
328
+ yaml_tag_directive_t *start =
329
+ event.data.document_start.tag_directives.start;
330
+ yaml_tag_directive_t *end =
331
+ event.data.document_start.tag_directives.end;
332
+ for(; start != end; start++) {
333
+ VALUE handle = Qnil;
334
+ VALUE prefix = Qnil;
335
+ if(start->handle) {
336
+ handle = rb_str_new2((const char *)start->handle);
337
+ PSYCH_TRANSCODE(handle, encoding, internal_enc);
338
+ }
339
+
340
+ if(start->prefix) {
341
+ prefix = rb_str_new2((const char *)start->prefix);
342
+ PSYCH_TRANSCODE(prefix, encoding, internal_enc);
343
+ }
344
+
345
+ rb_ary_push(tag_directives, rb_ary_new3((long)2, handle, prefix));
346
+ }
347
+ }
348
+ args[0] = handler;
349
+ args[1] = version;
350
+ args[2] = tag_directives;
351
+ args[3] = event.data.document_start.implicit == 1 ? Qtrue : Qfalse;
352
+ rb_protect(protected_start_document, (VALUE)args, &state);
353
+ }
354
+ break;
355
+ case YAML_DOCUMENT_END_EVENT:
356
+ {
357
+ VALUE args[2];
358
+
359
+ args[0] = handler;
360
+ args[1] = event.data.document_end.implicit == 1 ? Qtrue : Qfalse;
361
+ rb_protect(protected_end_document, (VALUE)args, &state);
362
+ }
363
+ break;
364
+ case YAML_ALIAS_EVENT:
365
+ {
366
+ VALUE args[2];
367
+ VALUE alias = Qnil;
368
+ if(event.data.alias.anchor) {
369
+ alias = rb_str_new2((const char *)event.data.alias.anchor);
370
+ PSYCH_TRANSCODE(alias, encoding, internal_enc);
371
+ }
372
+
373
+ args[0] = handler;
374
+ args[1] = alias;
375
+ rb_protect(protected_alias, (VALUE)args, &state);
376
+ }
377
+ break;
378
+ case YAML_SCALAR_EVENT:
379
+ {
380
+ VALUE args[7];
381
+ VALUE anchor = Qnil;
382
+ VALUE tag = Qnil;
383
+ VALUE plain_implicit, quoted_implicit, style;
384
+ VALUE val = rb_str_new(
385
+ (const char *)event.data.scalar.value,
386
+ (long)event.data.scalar.length
387
+ );
388
+
389
+ PSYCH_TRANSCODE(val, encoding, internal_enc);
390
+
391
+ if(event.data.scalar.anchor) {
392
+ anchor = rb_str_new2((const char *)event.data.scalar.anchor);
393
+ PSYCH_TRANSCODE(anchor, encoding, internal_enc);
394
+ }
395
+
396
+ if(event.data.scalar.tag) {
397
+ tag = rb_str_new2((const char *)event.data.scalar.tag);
398
+ PSYCH_TRANSCODE(tag, encoding, internal_enc);
399
+ }
400
+
401
+ plain_implicit =
402
+ event.data.scalar.plain_implicit == 0 ? Qfalse : Qtrue;
403
+
404
+ quoted_implicit =
405
+ event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
406
+
407
+ style = INT2NUM(event.data.scalar.style);
408
+
409
+ args[0] = handler;
410
+ args[1] = val;
411
+ args[2] = anchor;
412
+ args[3] = tag;
413
+ args[4] = plain_implicit;
414
+ args[5] = quoted_implicit;
415
+ args[6] = style;
416
+ rb_protect(protected_scalar, (VALUE)args, &state);
417
+ }
418
+ break;
419
+ case YAML_SEQUENCE_START_EVENT:
420
+ {
421
+ VALUE args[5];
422
+ VALUE anchor = Qnil;
423
+ VALUE tag = Qnil;
424
+ VALUE implicit, style;
425
+ if(event.data.sequence_start.anchor) {
426
+ anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
427
+ PSYCH_TRANSCODE(anchor, encoding, internal_enc);
428
+ }
429
+
430
+ tag = Qnil;
431
+ if(event.data.sequence_start.tag) {
432
+ tag = rb_str_new2((const char *)event.data.sequence_start.tag);
433
+ PSYCH_TRANSCODE(tag, encoding, internal_enc);
434
+ }
435
+
436
+ implicit =
437
+ event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
438
+
439
+ style = INT2NUM(event.data.sequence_start.style);
440
+
441
+ args[0] = handler;
442
+ args[1] = anchor;
443
+ args[2] = tag;
444
+ args[3] = implicit;
445
+ args[4] = style;
446
+
447
+ rb_protect(protected_start_sequence, (VALUE)args, &state);
448
+ }
449
+ break;
450
+ case YAML_SEQUENCE_END_EVENT:
451
+ rb_protect(protected_end_sequence, handler, &state);
452
+ break;
453
+ case YAML_MAPPING_START_EVENT:
454
+ {
455
+ VALUE args[5];
456
+ VALUE anchor = Qnil;
457
+ VALUE tag = Qnil;
458
+ VALUE implicit, style;
459
+ if(event.data.mapping_start.anchor) {
460
+ anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
461
+ PSYCH_TRANSCODE(anchor, encoding, internal_enc);
462
+ }
463
+
464
+ if(event.data.mapping_start.tag) {
465
+ tag = rb_str_new2((const char *)event.data.mapping_start.tag);
466
+ PSYCH_TRANSCODE(tag, encoding, internal_enc);
467
+ }
468
+
469
+ implicit =
470
+ event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
471
+
472
+ style = INT2NUM(event.data.mapping_start.style);
473
+
474
+ args[0] = handler;
475
+ args[1] = anchor;
476
+ args[2] = tag;
477
+ args[3] = implicit;
478
+ args[4] = style;
479
+
480
+ rb_protect(protected_start_mapping, (VALUE)args, &state);
481
+ }
482
+ break;
483
+ case YAML_MAPPING_END_EVENT:
484
+ rb_protect(protected_end_mapping, handler, &state);
485
+ break;
486
+ case YAML_NO_EVENT:
487
+ rb_protect(protected_empty, handler, &state);
488
+ break;
489
+ case YAML_STREAM_END_EVENT:
490
+ rb_protect(protected_end_stream, handler, &state);
491
+ done = 1;
492
+ break;
493
+ }
494
+ yaml_event_delete(&event);
495
+ if (state) rb_jump_tag(state);
510
496
  }
511
497
 
512
498
  return self;
@@ -558,7 +544,7 @@ void Init_psych_parser(void)
558
544
 
559
545
  rb_require("psych/syntax_error");
560
546
 
561
- rb_define_method(cPsychParser, "parse", parse, -1);
547
+ rb_define_private_method(cPsychParser, "_native_parse", parse, 3);
562
548
  rb_define_method(cPsychParser, "mark", mark, 0);
563
549
 
564
550
  id_read = rb_intern("read");
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'psych/omap'
3
- require 'psych/set'
2
+ require_relative 'omap'
3
+ require_relative 'set'
4
4
 
5
5
  module Psych
6
6
  class ClassLoader # :nodoc:
@@ -35,7 +35,7 @@ module Psych
35
35
 
36
36
  constants.each do |const|
37
37
  konst = const_get const
38
- class_eval <<~RUBY
38
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
39
39
  def #{const.to_s.downcase}
40
40
  load #{konst.inspect}
41
41
  end
@@ -86,7 +86,7 @@ module Psych
86
86
  if @symbols.include? sym
87
87
  super
88
88
  else
89
- raise DisallowedClass, 'Symbol'
89
+ raise DisallowedClass.new('load', 'Symbol')
90
90
  end
91
91
  end
92
92
 
@@ -96,7 +96,7 @@ module Psych
96
96
  if @classes.include? klassname
97
97
  super
98
98
  else
99
- raise DisallowedClass, klassname
99
+ raise DisallowedClass.new('load', klassname)
100
100
  end
101
101
  end
102
102
  end