psych 2.2.1 → 5.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +24 -0
- data/{ext/psych/yaml/LICENSE → LICENSE} +9 -7
- data/README.md +13 -13
- data/ext/psych/depend +14 -0
- data/ext/psych/extconf.rb +43 -29
- data/ext/psych/psych.c +6 -3
- data/ext/psych/psych_emitter.c +10 -9
- data/ext/psych/psych_parser.c +69 -72
- data/ext/psych/psych_yaml_tree.c +0 -12
- data/lib/psych/class_loader.rb +11 -9
- data/lib/psych/coder.rb +1 -1
- data/lib/psych/core_ext.rb +3 -20
- data/lib/psych/exception.rb +17 -3
- data/lib/psych/handler.rb +8 -3
- data/lib/psych/handlers/document_stream.rb +2 -2
- data/lib/psych/handlers/recorder.rb +2 -2
- data/lib/psych/json/ruby_events.rb +1 -1
- data/lib/psych/json/stream.rb +3 -3
- data/lib/psych/json/tree_builder.rb +2 -2
- data/lib/psych/json/yaml_events.rb +1 -1
- data/lib/psych/nodes/alias.rb +3 -1
- data/lib/psych/nodes/document.rb +3 -1
- data/lib/psych/nodes/mapping.rb +3 -1
- data/lib/psych/nodes/node.rb +24 -5
- data/lib/psych/nodes/scalar.rb +4 -2
- data/lib/psych/nodes/sequence.rb +3 -1
- data/lib/psych/nodes/stream.rb +3 -1
- data/lib/psych/nodes.rb +8 -8
- data/lib/psych/omap.rb +1 -1
- data/lib/psych/parser.rb +14 -1
- data/lib/psych/scalar_scanner.rb +39 -47
- data/lib/psych/set.rb +1 -1
- data/lib/psych/stream.rb +1 -1
- data/lib/psych/streaming.rb +1 -1
- data/lib/psych/syntax_error.rb +2 -2
- data/lib/psych/tree_builder.rb +48 -8
- data/lib/psych/versions.rb +5 -4
- data/lib/psych/visitors/depth_first.rb +1 -1
- data/lib/psych/visitors/emitter.rb +1 -1
- data/lib/psych/visitors/json_tree.rb +2 -2
- data/lib/psych/visitors/to_ruby.rb +61 -31
- data/lib/psych/visitors/visitor.rb +18 -4
- data/lib/psych/visitors/yaml_tree.rb +111 -123
- data/lib/psych/visitors.rb +7 -7
- data/lib/psych/y.rb +1 -1
- data/lib/psych.rb +333 -96
- metadata +16 -52
- data/.gitignore +0 -14
- data/.travis.yml +0 -18
- data/CHANGELOG.rdoc +0 -576
- data/Gemfile +0 -3
- data/Mavenfile +0 -7
- data/Rakefile +0 -33
- data/bin/console +0 -7
- data/bin/setup +0 -6
- data/ext/psych/.gitignore +0 -11
- data/ext/psych/yaml/api.c +0 -1392
- data/ext/psych/yaml/config.h +0 -10
- data/ext/psych/yaml/dumper.c +0 -394
- data/ext/psych/yaml/emitter.c +0 -2329
- data/ext/psych/yaml/loader.c +0 -444
- data/ext/psych/yaml/parser.c +0 -1374
- data/ext/psych/yaml/reader.c +0 -469
- data/ext/psych/yaml/scanner.c +0 -3576
- data/ext/psych/yaml/writer.c +0 -141
- data/ext/psych/yaml/yaml.h +0 -1971
- data/ext/psych/yaml/yaml_private.h +0 -662
- data/lib/psych/deprecated.rb +0 -86
- data/psych.gemspec +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 39bdb85aafa27b992e7e8db6905f6e1bc52976bbfc3f71e0ce1adee552a89682
|
4
|
+
data.tar.gz: a8d566aa3e16cde752a41ffdb5990af2b2d4f7082ad8774dbd3a8250636fef20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca436b4d85c8c931bfc9b05d2f16a52f03d01f65c5d708419f75ce926ba55ef9aa4af95a811fec0309773ec6f8963002ffa5ead5cc2f69e1666d3759f24a688b
|
7
|
+
data.tar.gz: bc2aabe53f58a0eb15fed477c96767bc4267ce6bd1f929010c580a0891fdbe28517fdf030a09356dd9b84000c60e1fe7d403d2d9414b5b3a7db8bfa152f5ba5a
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
## How to contribute to Psych
|
2
|
+
|
3
|
+
Full details [here](https://bugs.ruby-lang.org/projects/ruby/wiki/HowToContribute)
|
4
|
+
|
5
|
+
#### **Did you find a bug?**
|
6
|
+
|
7
|
+
* **Do not open an issue if the bug is a security vulnerability
|
8
|
+
in Psych**, instead refer to our [security policy](https://www.ruby-lang.org/en/security/) and email [here](security@ruby-lang.org).
|
9
|
+
|
10
|
+
* **Ensure the bug was not already reported** by searching on ruby-core, the ruby github repo and on Psych's github repo. More info [here](https://bugs.ruby-lang.org/projects/ruby/wiki/HowToReport)
|
11
|
+
|
12
|
+
* If you're unable to find an open issue addressing the problem, [open a new one](https://bugs.ruby-lang.org/). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
|
13
|
+
|
14
|
+
#### **Did you write a patch that fixes a bug?**
|
15
|
+
|
16
|
+
* Open a new GitHub pull request with the patch for small fixes. Anything larger look [here](https://bugs.ruby-lang.org/projects/ruby/wiki/HowToContribute); submit a Feature.
|
17
|
+
|
18
|
+
* Ensure you clearly describe the problem and solution. Include the relevant ticket/issue number if applicable.
|
19
|
+
|
20
|
+
Psych is a volunteer effort. We encourage you to pitch in and [join the team](https://github.com/ruby/psych/contributors)!
|
21
|
+
|
22
|
+
Thanks! :heart: :heart: :heart:
|
23
|
+
|
24
|
+
The Psych Team
|
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
MIT License
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
Copyright (c) 2009 Aaron Patterson, et al.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
9
11
|
|
10
12
|
The above copyright notice and this permission notice shall be included in all
|
11
13
|
copies or substantial portions of the Software.
|
data/README.md
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# Psych
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/ruby/psych.svg?branch=master)](https://travis-ci.org/ruby/psych)
|
4
|
-
[![Build status](https://ci.appveyor.com/api/projects/status/2t6x109xfmbx209k/branch/master?svg=true)](https://ci.appveyor.com/project/ruby/psych/branch/master)
|
5
|
-
|
6
3
|
* https://github.com/ruby/psych
|
4
|
+
* https://docs.ruby-lang.org/en/master/Psych.html
|
7
5
|
|
8
6
|
## Description
|
9
7
|
|
10
8
|
Psych is a YAML parser and emitter. Psych leverages
|
11
|
-
[libyaml](
|
9
|
+
[libyaml](https://pyyaml.org/wiki/LibYAML) for its YAML parsing and emitting
|
12
10
|
capabilities. In addition to wrapping libyaml, Psych also knows how to
|
13
11
|
serialize and de-serialize most Ruby objects to and from the YAML format.
|
14
12
|
|
15
13
|
## Examples
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
```ruby
|
16
|
+
# Safely load YAML in to a Ruby object
|
17
|
+
Psych.safe_load('--- foo') # => 'foo'
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
# Emit YAML from a Ruby object
|
20
|
+
Psych.dump("foo") # => "--- foo\n...\n"
|
21
|
+
```
|
22
22
|
|
23
23
|
## Dependencies
|
24
24
|
|
@@ -33,6 +33,11 @@ If you want a newer gem release of Psych, you can use rubygems:
|
|
33
33
|
|
34
34
|
gem install psych
|
35
35
|
|
36
|
+
|
37
|
+
Psych supported the static build with specific version of libyaml sources. You can build psych with libyaml-0.2.5 like this.
|
38
|
+
|
39
|
+
gem install psych -- --with-libyaml-source-dir=/path/to/libyaml-0.2.5
|
40
|
+
|
36
41
|
In order to use the gem release in your app, and not the stdlib version,
|
37
42
|
you'll need the following:
|
38
43
|
|
@@ -45,11 +50,6 @@ Or if you use Bundler add this to your `Gemfile`:
|
|
45
50
|
|
46
51
|
JRuby ships with a pure Java implementation of Psych.
|
47
52
|
|
48
|
-
If you're on Rubinius, Psych is available in 1.9 mode, please refer to the
|
49
|
-
Language Modes section of the [Rubinius
|
50
|
-
README](https://github.com/rubinius/rubinius#readme) for more information on
|
51
|
-
building and 1.9 mode.
|
52
|
-
|
53
53
|
## License
|
54
54
|
|
55
55
|
Copyright 2009 Aaron Patterson, et al.
|
data/ext/psych/depend
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
$(TARGET_SO): $(LIBYAML)
|
2
|
+
|
3
|
+
libyaml $(LIBYAML):
|
4
|
+
cd libyaml && $(MAKE)
|
5
|
+
$(AR) $(ARFLAGS) $(LIBYAML) $(LIBYAML_OBJDIR)/*.$(OBJEXT)
|
6
|
+
$(RANLIB) $(LIBYAML)
|
7
|
+
|
8
|
+
clean-so::
|
9
|
+
-cd libyaml && $(MAKE) clean
|
10
|
+
|
11
|
+
distclean-so::
|
12
|
+
-cd libyaml && $(MAKE) distclean
|
13
|
+
-$(Q)$(RMDIRS) libyaml/* libyaml
|
14
|
+
|
1
15
|
$(OBJS): $(HDRS) $(ruby_headers) \
|
2
16
|
$(hdrdir)/ruby/encoding.h \
|
3
17
|
$(hdrdir)/ruby/oniguruma.h
|
data/ext/psych/extconf.rb
CHANGED
@@ -1,39 +1,53 @@
|
|
1
1
|
# -*- coding: us-ascii -*-
|
2
|
-
# frozen_string_literal:
|
2
|
+
# frozen_string_literal: true
|
3
3
|
require 'mkmf'
|
4
|
-
require 'fileutils'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
if enable_config("bundled-libyaml", false) || !(find_header('yaml.h') && find_library('yaml', 'yaml_get_version'))
|
11
|
-
# Embed libyaml since we could not find it.
|
12
|
-
|
13
|
-
$VPATH << "$(srcdir)/yaml"
|
14
|
-
$INCFLAGS << " -I$(srcdir)/yaml"
|
15
|
-
|
16
|
-
$srcs = Dir.glob("#{$srcdir}/{,yaml/}*.c").map {|n| File.basename(n)}
|
5
|
+
if $mswin or $mingw or $cygwin
|
6
|
+
$CPPFLAGS << " -DYAML_DECLARE_STATIC"
|
7
|
+
end
|
17
8
|
|
18
|
-
|
19
|
-
|
9
|
+
yaml_source = with_config("libyaml-source-dir")
|
10
|
+
if yaml_source
|
11
|
+
yaml_source = yaml_source.gsub(/\$\((\w+)\)|\$\{(\w+)\}/) {ENV[$1||$2]}
|
12
|
+
yaml_source = yaml_source.chomp("/")
|
13
|
+
yaml_configure = "#{File.expand_path(yaml_source)}/configure"
|
14
|
+
unless File.exist?(yaml_configure)
|
15
|
+
raise "Configure script not found in #{yaml_source.quote}"
|
20
16
|
end
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
18
|
+
puts("Configuring libyaml source in #{yaml_source.quote}")
|
19
|
+
yaml = "libyaml"
|
20
|
+
Dir.mkdir(yaml) unless File.directory?(yaml)
|
21
|
+
shared = $enable_shared || !$static
|
22
|
+
args = [
|
23
|
+
yaml_configure,
|
24
|
+
"--enable-#{shared ? 'shared' : 'static'}",
|
25
|
+
"--host=#{RbConfig::CONFIG['host'].sub(/-unknown-/, '-').sub(/arm64/, 'arm')}",
|
26
|
+
"CC=#{RbConfig::CONFIG['CC']}",
|
27
|
+
*(["CFLAGS=-w"] if RbConfig::CONFIG["GCC"] == "yes"),
|
28
|
+
]
|
29
|
+
puts(args.quote.join(' '))
|
30
|
+
unless system(*args, chdir: yaml)
|
31
|
+
raise "failed to configure libyaml"
|
32
|
+
end
|
33
|
+
inc = yaml_source.start_with?("#$srcdir/") ? "$(srcdir)#{yaml_source[$srcdir.size..-1]}" : yaml_source
|
34
|
+
$INCFLAGS << " -I#{yaml}/include -I#{inc}/include"
|
35
|
+
puts("INCFLAGS=#$INCFLAGS")
|
36
|
+
libyaml = "libyaml.#$LIBEXT"
|
37
|
+
$cleanfiles << libyaml
|
38
|
+
$LOCAL_LIBS.prepend("$(LIBYAML) ")
|
39
|
+
else # default to pre-installed libyaml
|
40
|
+
pkg_config('yaml-0.1')
|
41
|
+
dir_config('libyaml')
|
42
|
+
find_header('yaml.h') or abort "yaml.h not found"
|
43
|
+
find_library('yaml', 'yaml_get_version') or abort "libyaml not found"
|
35
44
|
end
|
36
45
|
|
37
|
-
create_makefile 'psych'
|
46
|
+
create_makefile 'psych' do |mk|
|
47
|
+
mk << "LIBYAML = #{libyaml}".strip << "\n"
|
48
|
+
mk << "LIBYAML_OBJDIR = libyaml/src#{shared ? '/.libs' : ''}\n"
|
49
|
+
mk << "OBJEXT = #$OBJEXT"
|
50
|
+
mk << "RANLIB = #{config_string('RANLIB') || config_string('NULLCMD')}\n"
|
51
|
+
end
|
38
52
|
|
39
53
|
# :startdoc:
|
data/ext/psych/psych.c
CHANGED
@@ -11,9 +11,9 @@ static VALUE libyaml_version(VALUE module)
|
|
11
11
|
|
12
12
|
yaml_get_version(&major, &minor, &patch);
|
13
13
|
|
14
|
-
list[0] = INT2NUM(
|
15
|
-
list[1] = INT2NUM(
|
16
|
-
list[2] = INT2NUM(
|
14
|
+
list[0] = INT2NUM(major);
|
15
|
+
list[1] = INT2NUM(minor);
|
16
|
+
list[2] = INT2NUM(patch);
|
17
17
|
|
18
18
|
return rb_ary_new4((long)3, list);
|
19
19
|
}
|
@@ -22,6 +22,9 @@ VALUE mPsych;
|
|
22
22
|
|
23
23
|
void Init_psych(void)
|
24
24
|
{
|
25
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
26
|
+
RB_EXT_RACTOR_SAFE(true);
|
27
|
+
#endif
|
25
28
|
mPsych = rb_define_module("Psych");
|
26
29
|
|
27
30
|
rb_define_singleton_method(mPsych, "libyaml_version", libyaml_version, 0);
|
data/ext/psych/psych_emitter.c
CHANGED
@@ -192,8 +192,8 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
|
|
192
192
|
name = rb_str_export_to_enc(name, encoding);
|
193
193
|
value = rb_str_export_to_enc(value, encoding);
|
194
194
|
|
195
|
-
tail->handle = (yaml_char_t *)
|
196
|
-
tail->prefix = (yaml_char_t *)
|
195
|
+
tail->handle = (yaml_char_t *)StringValueCStr(name);
|
196
|
+
tail->prefix = (yaml_char_t *)StringValueCStr(value);
|
197
197
|
|
198
198
|
tail++;
|
199
199
|
}
|
@@ -272,8 +272,8 @@ static VALUE scalar(
|
|
272
272
|
|
273
273
|
yaml_scalar_event_initialize(
|
274
274
|
&event,
|
275
|
-
(yaml_char_t *)(NIL_P(anchor) ? NULL :
|
276
|
-
(yaml_char_t *)(NIL_P(tag) ? NULL :
|
275
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
|
276
|
+
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
|
277
277
|
(yaml_char_t*)StringValuePtr(value),
|
278
278
|
(int)RSTRING_LEN(value),
|
279
279
|
plain ? 1 : 0,
|
@@ -319,8 +319,8 @@ static VALUE start_sequence(
|
|
319
319
|
|
320
320
|
yaml_sequence_start_event_initialize(
|
321
321
|
&event,
|
322
|
-
(yaml_char_t *)(NIL_P(anchor) ? NULL :
|
323
|
-
(yaml_char_t *)(NIL_P(tag) ? NULL :
|
322
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
|
323
|
+
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
|
324
324
|
implicit ? 1 : 0,
|
325
325
|
(yaml_sequence_style_t)NUM2INT(style)
|
326
326
|
);
|
@@ -383,8 +383,8 @@ static VALUE start_mapping(
|
|
383
383
|
|
384
384
|
yaml_mapping_start_event_initialize(
|
385
385
|
&event,
|
386
|
-
(yaml_char_t *)(NIL_P(anchor) ? NULL :
|
387
|
-
(yaml_char_t *)(NIL_P(tag) ? NULL :
|
386
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
|
387
|
+
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
|
388
388
|
implicit ? 1 : 0,
|
389
389
|
(yaml_mapping_style_t)NUM2INT(style)
|
390
390
|
);
|
@@ -432,7 +432,7 @@ static VALUE alias(VALUE self, VALUE anchor)
|
|
432
432
|
|
433
433
|
yaml_alias_event_initialize(
|
434
434
|
&event,
|
435
|
-
(yaml_char_t *)(NIL_P(anchor) ? NULL :
|
435
|
+
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor))
|
436
436
|
);
|
437
437
|
|
438
438
|
emit(emitter, &event);
|
@@ -521,6 +521,7 @@ static VALUE set_line_width(VALUE self, VALUE width)
|
|
521
521
|
|
522
522
|
void Init_psych_emitter(void)
|
523
523
|
{
|
524
|
+
#undef rb_intern
|
524
525
|
VALUE psych = rb_define_module("Psych");
|
525
526
|
VALUE handler = rb_define_class_under(psych, "Handler", rb_cObject);
|
526
527
|
cPsychEmitter = rb_define_class_under(psych, "Emitter", handler);
|
data/ext/psych/psych_parser.c
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#include <psych.h>
|
2
2
|
|
3
3
|
VALUE cPsychParser;
|
4
|
-
VALUE ePsychSyntaxError;
|
5
4
|
|
6
5
|
static ID id_read;
|
7
6
|
static ID id_path;
|
@@ -16,6 +15,7 @@ static ID id_start_sequence;
|
|
16
15
|
static ID id_end_sequence;
|
17
16
|
static ID id_start_mapping;
|
18
17
|
static ID id_end_mapping;
|
18
|
+
static ID id_event_location;
|
19
19
|
|
20
20
|
#define PSYCH_TRANSCODE(_str, _yaml_enc, _internal_enc) \
|
21
21
|
do { \
|
@@ -27,7 +27,7 @@ static ID id_end_mapping;
|
|
27
27
|
static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read)
|
28
28
|
{
|
29
29
|
VALUE io = (VALUE)data;
|
30
|
-
VALUE string = rb_funcall(io, id_read, 1,
|
30
|
+
VALUE string = rb_funcall(io, id_read, 1, SIZET2NUM(size));
|
31
31
|
|
32
32
|
*read = 0;
|
33
33
|
|
@@ -79,18 +79,25 @@ static VALUE allocate(VALUE klass)
|
|
79
79
|
|
80
80
|
static VALUE make_exception(yaml_parser_t * parser, VALUE path)
|
81
81
|
{
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
82
|
+
if (parser->error == YAML_MEMORY_ERROR) {
|
83
|
+
return rb_eNoMemError;
|
84
|
+
} else {
|
85
|
+
size_t line, column;
|
86
|
+
VALUE ePsychSyntaxError;
|
87
|
+
|
88
|
+
line = parser->context_mark.line + 1;
|
89
|
+
column = parser->context_mark.column + 1;
|
90
|
+
|
91
|
+
ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
|
92
|
+
|
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
|
+
}
|
94
101
|
}
|
95
102
|
|
96
103
|
static VALUE transcode_string(VALUE src, int * parser_encoding)
|
@@ -232,47 +239,31 @@ static VALUE protected_end_stream(VALUE handler)
|
|
232
239
|
return rb_funcall(handler, id_end_stream, 0);
|
233
240
|
}
|
234
241
|
|
235
|
-
|
236
|
-
|
237
|
-
*
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
* See Psych::Parser and Psych::Parser#handler
|
243
|
-
*/
|
244
|
-
static VALUE parse(int argc, VALUE *argv, VALUE self)
|
242
|
+
static VALUE protected_event_location(VALUE pointer)
|
243
|
+
{
|
244
|
+
VALUE *args = (VALUE *)pointer;
|
245
|
+
return rb_funcall3(args[0], id_event_location, 4, args + 1);
|
246
|
+
}
|
247
|
+
|
248
|
+
static VALUE parse(VALUE self, VALUE handler, VALUE yaml, VALUE path)
|
245
249
|
{
|
246
|
-
VALUE yaml, path;
|
247
250
|
yaml_parser_t * parser;
|
248
251
|
yaml_event_t event;
|
249
252
|
int done = 0;
|
250
|
-
int tainted = 0;
|
251
253
|
int state = 0;
|
252
254
|
int parser_encoding = YAML_ANY_ENCODING;
|
253
255
|
int encoding = rb_utf8_encindex();
|
254
256
|
rb_encoding * internal_enc = rb_default_internal_encoding();
|
255
|
-
VALUE handler = rb_iv_get(self, "@handler");
|
256
|
-
|
257
|
-
if (rb_scan_args(argc, argv, "11", &yaml, &path) == 1) {
|
258
|
-
if(rb_respond_to(yaml, id_path))
|
259
|
-
path = rb_funcall(yaml, id_path, 0);
|
260
|
-
else
|
261
|
-
path = rb_str_new2("<unknown>");
|
262
|
-
}
|
263
257
|
|
264
258
|
TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
|
265
259
|
|
266
260
|
yaml_parser_delete(parser);
|
267
261
|
yaml_parser_initialize(parser);
|
268
262
|
|
269
|
-
if (OBJ_TAINTED(yaml)) tainted = 1;
|
270
|
-
|
271
263
|
if (rb_respond_to(yaml, id_read)) {
|
272
264
|
yaml = transcode_io(yaml, &parser_encoding);
|
273
265
|
yaml_parser_set_encoding(parser, parser_encoding);
|
274
266
|
yaml_parser_set_input(parser, io_reader, (void *)yaml);
|
275
|
-
if (RTEST(rb_obj_is_kind_of(yaml, rb_cIO))) tainted = 1;
|
276
267
|
} else {
|
277
268
|
StringValue(yaml);
|
278
269
|
yaml = transcode_string(yaml, &parser_encoding);
|
@@ -285,7 +276,10 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
285
276
|
}
|
286
277
|
|
287
278
|
while(!done) {
|
288
|
-
|
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)) {
|
289
283
|
VALUE exception;
|
290
284
|
|
291
285
|
exception = make_exception(parser, path);
|
@@ -295,13 +289,25 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
295
289
|
rb_exc_raise(exception);
|
296
290
|
}
|
297
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
|
+
|
298
304
|
switch(event.type) {
|
299
305
|
case YAML_STREAM_START_EVENT:
|
300
306
|
{
|
301
307
|
VALUE args[2];
|
302
308
|
|
303
309
|
args[0] = handler;
|
304
|
-
args[1] = INT2NUM(
|
310
|
+
args[1] = INT2NUM(event.data.stream_start.encoding);
|
305
311
|
rb_protect(protected_start_stream, (VALUE)args, &state);
|
306
312
|
}
|
307
313
|
break;
|
@@ -314,8 +320,8 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
314
320
|
VALUE version = event.data.document_start.version_directive ?
|
315
321
|
rb_ary_new3(
|
316
322
|
(long)2,
|
317
|
-
INT2NUM(
|
318
|
-
INT2NUM(
|
323
|
+
INT2NUM(event.data.document_start.version_directive->major),
|
324
|
+
INT2NUM(event.data.document_start.version_directive->minor)
|
319
325
|
) : rb_ary_new();
|
320
326
|
|
321
327
|
if(event.data.document_start.tag_directives.start) {
|
@@ -328,13 +334,11 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
328
334
|
VALUE prefix = Qnil;
|
329
335
|
if(start->handle) {
|
330
336
|
handle = rb_str_new2((const char *)start->handle);
|
331
|
-
if (tainted) OBJ_TAINT(handle);
|
332
337
|
PSYCH_TRANSCODE(handle, encoding, internal_enc);
|
333
338
|
}
|
334
339
|
|
335
340
|
if(start->prefix) {
|
336
341
|
prefix = rb_str_new2((const char *)start->prefix);
|
337
|
-
if (tainted) OBJ_TAINT(prefix);
|
338
342
|
PSYCH_TRANSCODE(prefix, encoding, internal_enc);
|
339
343
|
}
|
340
344
|
|
@@ -363,7 +367,6 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
363
367
|
VALUE alias = Qnil;
|
364
368
|
if(event.data.alias.anchor) {
|
365
369
|
alias = rb_str_new2((const char *)event.data.alias.anchor);
|
366
|
-
if (tainted) OBJ_TAINT(alias);
|
367
370
|
PSYCH_TRANSCODE(alias, encoding, internal_enc);
|
368
371
|
}
|
369
372
|
|
@@ -382,19 +385,16 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
382
385
|
(const char *)event.data.scalar.value,
|
383
386
|
(long)event.data.scalar.length
|
384
387
|
);
|
385
|
-
if (tainted) OBJ_TAINT(val);
|
386
388
|
|
387
389
|
PSYCH_TRANSCODE(val, encoding, internal_enc);
|
388
390
|
|
389
391
|
if(event.data.scalar.anchor) {
|
390
392
|
anchor = rb_str_new2((const char *)event.data.scalar.anchor);
|
391
|
-
if (tainted) OBJ_TAINT(anchor);
|
392
393
|
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
393
394
|
}
|
394
395
|
|
395
396
|
if(event.data.scalar.tag) {
|
396
397
|
tag = rb_str_new2((const char *)event.data.scalar.tag);
|
397
|
-
if (tainted) OBJ_TAINT(tag);
|
398
398
|
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
399
399
|
}
|
400
400
|
|
@@ -404,7 +404,7 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
404
404
|
quoted_implicit =
|
405
405
|
event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
|
406
406
|
|
407
|
-
style = INT2NUM(
|
407
|
+
style = INT2NUM(event.data.scalar.style);
|
408
408
|
|
409
409
|
args[0] = handler;
|
410
410
|
args[1] = val;
|
@@ -424,21 +424,19 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
424
424
|
VALUE implicit, style;
|
425
425
|
if(event.data.sequence_start.anchor) {
|
426
426
|
anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
|
427
|
-
if (tainted) OBJ_TAINT(anchor);
|
428
427
|
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
429
428
|
}
|
430
429
|
|
431
430
|
tag = Qnil;
|
432
431
|
if(event.data.sequence_start.tag) {
|
433
432
|
tag = rb_str_new2((const char *)event.data.sequence_start.tag);
|
434
|
-
if (tainted) OBJ_TAINT(tag);
|
435
433
|
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
436
434
|
}
|
437
435
|
|
438
436
|
implicit =
|
439
437
|
event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
|
440
438
|
|
441
|
-
style = INT2NUM(
|
439
|
+
style = INT2NUM(event.data.sequence_start.style);
|
442
440
|
|
443
441
|
args[0] = handler;
|
444
442
|
args[1] = anchor;
|
@@ -460,20 +458,18 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
460
458
|
VALUE implicit, style;
|
461
459
|
if(event.data.mapping_start.anchor) {
|
462
460
|
anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
|
463
|
-
if (tainted) OBJ_TAINT(anchor);
|
464
461
|
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
465
462
|
}
|
466
463
|
|
467
464
|
if(event.data.mapping_start.tag) {
|
468
465
|
tag = rb_str_new2((const char *)event.data.mapping_start.tag);
|
469
|
-
if (tainted) OBJ_TAINT(tag);
|
470
466
|
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
471
467
|
}
|
472
468
|
|
473
469
|
implicit =
|
474
470
|
event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
|
475
471
|
|
476
|
-
style = INT2NUM(
|
472
|
+
style = INT2NUM(event.data.mapping_start.style);
|
477
473
|
|
478
474
|
args[0] = handler;
|
479
475
|
args[1] = anchor;
|
@@ -517,15 +513,16 @@ static VALUE mark(VALUE self)
|
|
517
513
|
|
518
514
|
TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
|
519
515
|
mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
|
520
|
-
args[0] =
|
521
|
-
args[1] =
|
522
|
-
args[2] =
|
516
|
+
args[0] = SIZET2NUM(parser->mark.index);
|
517
|
+
args[1] = SIZET2NUM(parser->mark.line);
|
518
|
+
args[2] = SIZET2NUM(parser->mark.column);
|
523
519
|
|
524
520
|
return rb_class_new_instance(3, args, mark_klass);
|
525
521
|
}
|
526
522
|
|
527
523
|
void Init_psych_parser(void)
|
528
524
|
{
|
525
|
+
#undef rb_intern
|
529
526
|
#if 0
|
530
527
|
mPsych = rb_define_module("Psych");
|
531
528
|
#endif
|
@@ -546,23 +543,23 @@ void Init_psych_parser(void)
|
|
546
543
|
rb_define_const(cPsychParser, "UTF16BE", INT2NUM(YAML_UTF16BE_ENCODING));
|
547
544
|
|
548
545
|
rb_require("psych/syntax_error");
|
549
|
-
ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
|
550
546
|
|
551
|
-
|
547
|
+
rb_define_private_method(cPsychParser, "_native_parse", parse, 3);
|
552
548
|
rb_define_method(cPsychParser, "mark", mark, 0);
|
553
549
|
|
554
|
-
id_read
|
555
|
-
id_path
|
556
|
-
id_empty
|
557
|
-
id_start_stream
|
558
|
-
id_end_stream
|
559
|
-
id_start_document
|
560
|
-
id_end_document
|
561
|
-
id_alias
|
562
|
-
id_scalar
|
563
|
-
id_start_sequence
|
564
|
-
id_end_sequence
|
565
|
-
id_start_mapping
|
566
|
-
id_end_mapping
|
550
|
+
id_read = rb_intern("read");
|
551
|
+
id_path = rb_intern("path");
|
552
|
+
id_empty = rb_intern("empty");
|
553
|
+
id_start_stream = rb_intern("start_stream");
|
554
|
+
id_end_stream = rb_intern("end_stream");
|
555
|
+
id_start_document = rb_intern("start_document");
|
556
|
+
id_end_document = rb_intern("end_document");
|
557
|
+
id_alias = rb_intern("alias");
|
558
|
+
id_scalar = rb_intern("scalar");
|
559
|
+
id_start_sequence = rb_intern("start_sequence");
|
560
|
+
id_end_sequence = rb_intern("end_sequence");
|
561
|
+
id_start_mapping = rb_intern("start_mapping");
|
562
|
+
id_end_mapping = rb_intern("end_mapping");
|
563
|
+
id_event_location = rb_intern("event_location");
|
567
564
|
}
|
568
565
|
/* vim: set noet sws=4 sw=4: */
|
data/ext/psych/psych_yaml_tree.c
CHANGED
@@ -2,23 +2,11 @@
|
|
2
2
|
|
3
3
|
VALUE cPsychVisitorsYamlTree;
|
4
4
|
|
5
|
-
/*
|
6
|
-
* call-seq: private_iv_get(target, prop)
|
7
|
-
*
|
8
|
-
* Get the private instance variable +prop+ from +target+
|
9
|
-
*/
|
10
|
-
static VALUE private_iv_get(VALUE self, VALUE target, VALUE prop)
|
11
|
-
{
|
12
|
-
return rb_attr_get(target, rb_intern(StringValuePtr(prop)));
|
13
|
-
}
|
14
|
-
|
15
5
|
void Init_psych_yaml_tree(void)
|
16
6
|
{
|
17
7
|
VALUE psych = rb_define_module("Psych");
|
18
8
|
VALUE visitors = rb_define_module_under(psych, "Visitors");
|
19
9
|
VALUE visitor = rb_define_class_under(visitors, "Visitor", rb_cObject);
|
20
10
|
cPsychVisitorsYamlTree = rb_define_class_under(visitors, "YAMLTree", visitor);
|
21
|
-
|
22
|
-
rb_define_private_method(cPsychVisitorsYamlTree, "private_iv_get", private_iv_get, 2);
|
23
11
|
}
|
24
12
|
/* vim: set noet sws=4 sw=4: */
|