psych 3.1.0 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +24 -0
  3. data/{ext/psych/yaml/LICENSE → LICENSE} +9 -7
  4. data/README.md +22 -17
  5. data/ext/psych/depend +14 -0
  6. data/ext/psych/extconf.rb +42 -28
  7. data/ext/psych/psych.c +6 -4
  8. data/ext/psych/psych_emitter.c +155 -121
  9. data/ext/psych/psych_parser.c +274 -302
  10. data/ext/psych/psych_to_ruby.c +0 -1
  11. data/ext/psych/psych_yaml_tree.c +0 -13
  12. data/lib/psych/class_loader.rb +10 -8
  13. data/lib/psych/core_ext.rb +1 -1
  14. data/lib/psych/exception.rb +16 -2
  15. data/lib/psych/handler.rb +1 -1
  16. data/lib/psych/handlers/document_stream.rb +1 -1
  17. data/lib/psych/handlers/recorder.rb +1 -1
  18. data/lib/psych/json/stream.rb +2 -2
  19. data/lib/psych/json/tree_builder.rb +1 -1
  20. data/lib/psych/nodes/node.rb +5 -5
  21. data/lib/psych/nodes/scalar.rb +1 -1
  22. data/lib/psych/nodes.rb +7 -7
  23. data/lib/psych/parser.rb +13 -0
  24. data/lib/psych/scalar_scanner.rb +39 -47
  25. data/lib/psych/syntax_error.rb +1 -1
  26. data/lib/psych/tree_builder.rb +3 -3
  27. data/lib/psych/versions.rb +3 -3
  28. data/lib/psych/visitors/json_tree.rb +1 -1
  29. data/lib/psych/visitors/to_ruby.rb +60 -26
  30. data/lib/psych/visitors/visitor.rb +17 -3
  31. data/lib/psych/visitors/yaml_tree.rb +103 -71
  32. data/lib/psych/visitors.rb +6 -6
  33. data/lib/psych.rb +260 -138
  34. metadata +20 -53
  35. data/.gitignore +0 -16
  36. data/.travis.yml +0 -22
  37. data/CHANGELOG.rdoc +0 -583
  38. data/Gemfile +0 -3
  39. data/Mavenfile +0 -7
  40. data/Rakefile +0 -48
  41. data/bin/console +0 -7
  42. data/bin/setup +0 -6
  43. data/ext/psych/yaml/api.c +0 -1393
  44. data/ext/psych/yaml/config.h +0 -10
  45. data/ext/psych/yaml/dumper.c +0 -394
  46. data/ext/psych/yaml/emitter.c +0 -2324
  47. data/ext/psych/yaml/loader.c +0 -444
  48. data/ext/psych/yaml/parser.c +0 -1370
  49. data/ext/psych/yaml/reader.c +0 -469
  50. data/ext/psych/yaml/scanner.c +0 -3578
  51. data/ext/psych/yaml/writer.c +0 -141
  52. data/ext/psych/yaml/yaml.h +0 -1971
  53. data/ext/psych/yaml/yaml_private.h +0 -688
  54. data/psych.gemspec +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b628607fc4e3ef10c115fad87828d70df6be24f347804f6cf4230ca52b945fde
4
- data.tar.gz: 1fe6f870598501b36fb154f220290f4386a411f809484a8e1ffc0d16f43fb7d8
3
+ metadata.gz: e8c48b70d7c4ff53b1d536997a6e63173cb7e123e3f6e70f82c5de8596d93c4c
4
+ data.tar.gz: c49d610314f1628a1e84267010dcfac5a076276eac2cad8dbbba9079ede9e08f
5
5
  SHA512:
6
- metadata.gz: 24898c2f34f70c0a8de488d818b4f92487315ad5605669f34d066f721ba889d5df2a3f184bafda94c46d1e36d47f2014f2e8645f5ac5ddf3fc0f9c0c3c7fefd2
7
- data.tar.gz: 90412192fb3318218ab650386e4ab511fa8531bb75a161e2587e10a3bbba190d1c8fd1604d24ded9c4a75836a2a76e01ef1cc50f29950fbbd13724714752d0ee
6
+ metadata.gz: 2d3d710995bfd6eb317994dd13024e5e3fd2967dbd379a1d510f86f7517177d2cc5e292a7d3b14c999071cc35ce625715ee3549fab90ce966567ba6e91f2475c
7
+ data.tar.gz: f1570e565d5dd8c9e5984155dfbc1418a594aaa871fab7b7fabe62f05bc0a3e72ab141dd9f39c09689f8f4949a5c6e58fa9b1ca99c26db3552b0c9866a6032ad
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
- Copyright (c) 2006 Kirill Simonov
1
+ MIT License
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
- of the Software, and to permit persons to whom the Software is furnished to do
8
- so, subject to the following conditions:
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,9 +1,7 @@
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
- * https://github.com/ruby/psych
3
+ * https://github.com/ruby/psych
4
+ * https://docs.ruby-lang.org/en/master/Psych.html
7
5
 
8
6
  ## Description
9
7
 
@@ -15,8 +13,8 @@ serialize and de-serialize most Ruby objects to and from the YAML format.
15
13
  ## Examples
16
14
 
17
15
  ```ruby
18
- # Load YAML in to a Ruby object
19
- Psych.load('--- foo') # => 'foo'
16
+ # Safely load YAML in to a Ruby object
17
+ Psych.safe_load('--- foo') # => 'foo'
20
18
 
21
19
  # Emit YAML from a Ruby object
22
20
  Psych.dump("foo") # => "--- foo\n...\n"
@@ -24,34 +22,41 @@ Psych.dump("foo") # => "--- foo\n...\n"
24
22
 
25
23
  ## Dependencies
26
24
 
27
- * libyaml
25
+ * libyaml
28
26
 
29
27
  ## Installation
30
28
 
31
29
  Psych has been included with MRI since 1.9.2, and is the default YAML parser
32
30
  in 1.9.3.
33
31
 
34
- If you want a newer gem release of Psych, you can use rubygems:
32
+ If you want a newer gem release of Psych, you can use RubyGems:
33
+
34
+ ```bash
35
+ gem install psych
36
+ ```
35
37
 
36
- gem install psych
38
+ Psych supported the static build with specific version of libyaml sources. You can build psych with libyaml-0.2.5 like this.
39
+
40
+ ```bash
41
+ gem install psych -- --with-libyaml-source-dir=/path/to/libyaml-0.2.5
42
+ ```
37
43
 
38
44
  In order to use the gem release in your app, and not the stdlib version,
39
45
  you'll need the following:
40
46
 
41
- gem 'psych'
42
- require 'psych'
47
+ ```ruby
48
+ gem 'psych'
49
+ require 'psych'
50
+ ```
43
51
 
44
52
  Or if you use Bundler add this to your `Gemfile`:
45
53
 
46
- gem 'psych'
54
+ ```ruby
55
+ gem 'psych'
56
+ ```
47
57
 
48
58
  JRuby ships with a pure Java implementation of Psych.
49
59
 
50
- If you're on Rubinius, Psych is available in 1.9 mode, please refer to the
51
- Language Modes section of the [Rubinius
52
- README](https://github.com/rubinius/rubinius#readme) for more information on
53
- building and 1.9 mode.
54
-
55
60
  ## License
56
61
 
57
62
  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
2
  # frozen_string_literal: true
3
3
  require 'mkmf'
4
- require 'fileutils'
5
4
 
6
- # :stopdoc:
7
-
8
- dir_config 'libyaml'
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
- if have_macro("_WIN32")
19
- $CPPFLAGS << " -DYAML_DECLARE_STATIC -DHAVE_CONFIG_H"
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
- have_header 'dlfcn.h'
23
- have_header 'inttypes.h'
24
- have_header 'memory.h'
25
- have_header 'stdint.h'
26
- have_header 'stdlib.h'
27
- have_header 'strings.h'
28
- have_header 'string.h'
29
- have_header 'sys/stat.h'
30
- have_header 'sys/types.h'
31
- have_header 'unistd.h'
32
-
33
- find_header 'yaml.h'
34
- have_header 'config.h'
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((long)major);
15
- list[1] = INT2NUM((long)minor);
16
- list[2] = INT2NUM((long)patch);
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);
@@ -31,4 +34,3 @@ void Init_psych(void)
31
34
  Init_psych_to_ruby();
32
35
  Init_psych_yaml_tree();
33
36
  }
34
- /* vim: set noet sws=4 sw=4: */
@@ -17,7 +17,7 @@ static ID id_canonical;
17
17
  static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
18
18
  {
19
19
  if(!yaml_emitter_emit(emitter, event))
20
- rb_raise(rb_eRuntimeError, "%s", emitter->problem);
20
+ rb_raise(rb_eRuntimeError, "%s", emitter->problem);
21
21
  }
22
22
 
23
23
  static int writer(void *ctx, unsigned char *buffer, size_t size)
@@ -82,13 +82,13 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
82
82
  TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
83
83
 
84
84
  if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
85
- line_width = rb_funcall(options, id_line_width, 0);
86
- indent = rb_funcall(options, id_indentation, 0);
87
- canonical = rb_funcall(options, id_canonical, 0);
85
+ line_width = rb_funcall(options, id_line_width, 0);
86
+ indent = rb_funcall(options, id_indentation, 0);
87
+ canonical = rb_funcall(options, id_canonical, 0);
88
88
 
89
- yaml_emitter_set_width(emitter, NUM2INT(line_width));
90
- yaml_emitter_set_indent(emitter, NUM2INT(indent));
91
- yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
89
+ yaml_emitter_set_width(emitter, NUM2INT(line_width));
90
+ yaml_emitter_set_indent(emitter, NUM2INT(indent));
91
+ yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
92
92
  }
93
93
 
94
94
  rb_ivar_set(self, id_io, io);
@@ -136,84 +136,118 @@ static VALUE end_stream(VALUE self)
136
136
  return self;
137
137
  }
138
138
 
139
- /* call-seq: emitter.start_document(version, tags, implicit)
140
- *
141
- * Start a document emission with YAML +version+, +tags+, and an +implicit+
142
- * start.
143
- *
144
- * See Psych::Handler#start_document
145
- */
146
- static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
139
+ struct start_document_data {
140
+ VALUE self;
141
+ VALUE version;
142
+ VALUE tags;
143
+ VALUE imp;
144
+
145
+ yaml_tag_directive_t * head;
146
+ };
147
+
148
+ static VALUE start_document_try(VALUE d)
147
149
  {
150
+ struct start_document_data * data = (struct start_document_data *)d;
151
+ VALUE self = data->self;
152
+ VALUE version = data->version;
153
+ VALUE tags = data->tags;
154
+ VALUE imp = data->imp;
155
+
148
156
  yaml_emitter_t * emitter;
149
- yaml_tag_directive_t * head = NULL;
150
157
  yaml_tag_directive_t * tail = NULL;
151
158
  yaml_event_t event;
152
159
  yaml_version_directive_t version_directive;
153
160
  TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
154
161
 
155
-
156
162
  Check_Type(version, T_ARRAY);
157
163
 
158
164
  if(RARRAY_LEN(version) > 0) {
159
- VALUE major = rb_ary_entry(version, (long)0);
160
- VALUE minor = rb_ary_entry(version, (long)1);
165
+ VALUE major = rb_ary_entry(version, (long)0);
166
+ VALUE minor = rb_ary_entry(version, (long)1);
161
167
 
162
- version_directive.major = NUM2INT(major);
163
- version_directive.minor = NUM2INT(minor);
168
+ version_directive.major = NUM2INT(major);
169
+ version_directive.minor = NUM2INT(minor);
164
170
  }
165
171
 
166
172
  if(RTEST(tags)) {
167
- long i = 0;
168
- long len;
169
- rb_encoding * encoding = rb_utf8_encoding();
170
-
171
- Check_Type(tags, T_ARRAY);
172
-
173
- len = RARRAY_LEN(tags);
174
- head = xcalloc((size_t)len, sizeof(yaml_tag_directive_t));
175
- tail = head;
176
-
177
- for(i = 0; i < len && i < RARRAY_LEN(tags); i++) {
178
- VALUE tuple = RARRAY_AREF(tags, i);
179
- VALUE name;
180
- VALUE value;
181
-
182
- Check_Type(tuple, T_ARRAY);
183
-
184
- if(RARRAY_LEN(tuple) < 2) {
185
- xfree(head);
186
- rb_raise(rb_eRuntimeError, "tag tuple must be of length 2");
187
- }
188
- name = RARRAY_AREF(tuple, 0);
189
- value = RARRAY_AREF(tuple, 1);
190
- StringValue(name);
191
- StringValue(value);
192
- name = rb_str_export_to_enc(name, encoding);
193
- value = rb_str_export_to_enc(value, encoding);
194
-
195
- tail->handle = (yaml_char_t *)StringValueCStr(name);
196
- tail->prefix = (yaml_char_t *)StringValueCStr(value);
197
-
198
- tail++;
199
- }
173
+ long i = 0;
174
+ long len;
175
+ rb_encoding * encoding = rb_utf8_encoding();
176
+
177
+ Check_Type(tags, T_ARRAY);
178
+
179
+ len = RARRAY_LEN(tags);
180
+ data->head = xcalloc((size_t)len, sizeof(yaml_tag_directive_t));
181
+ tail = data->head;
182
+
183
+ for(i = 0; i < len && i < RARRAY_LEN(tags); i++) {
184
+ VALUE tuple = RARRAY_AREF(tags, i);
185
+ VALUE name;
186
+ VALUE value;
187
+
188
+ Check_Type(tuple, T_ARRAY);
189
+
190
+ if(RARRAY_LEN(tuple) < 2) {
191
+ rb_raise(rb_eRuntimeError, "tag tuple must be of length 2");
192
+ }
193
+
194
+ name = RARRAY_AREF(tuple, 0);
195
+ value = RARRAY_AREF(tuple, 1);
196
+ StringValue(name);
197
+ StringValue(value);
198
+ name = rb_str_export_to_enc(name, encoding);
199
+ value = rb_str_export_to_enc(value, encoding);
200
+
201
+ tail->handle = (yaml_char_t *)StringValueCStr(name);
202
+ tail->prefix = (yaml_char_t *)StringValueCStr(value);
203
+
204
+ tail++;
205
+ }
200
206
  }
201
207
 
202
208
  yaml_document_start_event_initialize(
203
- &event,
204
- (RARRAY_LEN(version) > 0) ? &version_directive : NULL,
205
- head,
206
- tail,
207
- imp ? 1 : 0
208
- );
209
+ &event,
210
+ (RARRAY_LEN(version) > 0) ? &version_directive : NULL,
211
+ data->head,
212
+ tail,
213
+ imp ? 1 : 0
214
+ );
209
215
 
210
216
  emit(emitter, &event);
211
217
 
212
- if(head) xfree(head);
213
-
214
218
  return self;
215
219
  }
216
220
 
221
+ static VALUE start_document_ensure(VALUE d)
222
+ {
223
+ struct start_document_data * data = (struct start_document_data *)d;
224
+
225
+ xfree(data->head);
226
+
227
+ return Qnil;
228
+ }
229
+
230
+ /* call-seq: emitter.start_document(version, tags, implicit)
231
+ *
232
+ * Start a document emission with YAML +version+, +tags+, and an +implicit+
233
+ * start.
234
+ *
235
+ * See Psych::Handler#start_document
236
+ */
237
+ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
238
+ {
239
+ struct start_document_data data = {
240
+ .self = self,
241
+ .version = version,
242
+ .tags = tags,
243
+ .imp = imp,
244
+
245
+ .head = NULL,
246
+ };
247
+
248
+ return rb_ensure(start_document_try, (VALUE)&data, start_document_ensure, (VALUE)&data);
249
+ }
250
+
217
251
  /* call-seq: emitter.end_document(implicit)
218
252
  *
219
253
  * End a document emission with an +implicit+ ending.
@@ -241,14 +275,14 @@ static VALUE end_document(VALUE self, VALUE imp)
241
275
  * See Psych::Handler#scalar
242
276
  */
243
277
  static VALUE scalar(
244
- VALUE self,
245
- VALUE value,
246
- VALUE anchor,
247
- VALUE tag,
248
- VALUE plain,
249
- VALUE quoted,
250
- VALUE style
251
- ) {
278
+ VALUE self,
279
+ VALUE value,
280
+ VALUE anchor,
281
+ VALUE tag,
282
+ VALUE plain,
283
+ VALUE quoted,
284
+ VALUE style
285
+ ) {
252
286
  yaml_emitter_t * emitter;
253
287
  yaml_event_t event;
254
288
  rb_encoding *encoding;
@@ -261,25 +295,26 @@ static VALUE scalar(
261
295
  value = rb_str_export_to_enc(value, encoding);
262
296
 
263
297
  if(!NIL_P(anchor)) {
264
- Check_Type(anchor, T_STRING);
265
- anchor = rb_str_export_to_enc(anchor, encoding);
298
+ Check_Type(anchor, T_STRING);
299
+ anchor = rb_str_export_to_enc(anchor, encoding);
266
300
  }
267
301
 
268
302
  if(!NIL_P(tag)) {
269
- Check_Type(tag, T_STRING);
270
- tag = rb_str_export_to_enc(tag, encoding);
303
+ Check_Type(tag, T_STRING);
304
+ tag = rb_str_export_to_enc(tag, encoding);
271
305
  }
272
306
 
307
+ const char *value_ptr = StringValuePtr(value);
273
308
  yaml_scalar_event_initialize(
274
- &event,
275
- (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
276
- (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
277
- (yaml_char_t*)StringValuePtr(value),
278
- (int)RSTRING_LEN(value),
279
- plain ? 1 : 0,
280
- quoted ? 1 : 0,
281
- (yaml_scalar_style_t)NUM2INT(style)
282
- );
309
+ &event,
310
+ (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
311
+ (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
312
+ (yaml_char_t*)value_ptr,
313
+ (int)RSTRING_LEN(value),
314
+ plain ? 1 : 0,
315
+ quoted ? 1 : 0,
316
+ (yaml_scalar_style_t)NUM2INT(style)
317
+ );
283
318
 
284
319
  emit(emitter, &event);
285
320
 
@@ -294,36 +329,36 @@ static VALUE scalar(
294
329
  * See Psych::Handler#start_sequence
295
330
  */
296
331
  static VALUE start_sequence(
297
- VALUE self,
298
- VALUE anchor,
299
- VALUE tag,
300
- VALUE implicit,
301
- VALUE style
302
- ) {
332
+ VALUE self,
333
+ VALUE anchor,
334
+ VALUE tag,
335
+ VALUE implicit,
336
+ VALUE style
337
+ ) {
303
338
  yaml_emitter_t * emitter;
304
339
  yaml_event_t event;
305
340
 
306
341
  rb_encoding * encoding = rb_utf8_encoding();
307
342
 
308
343
  if(!NIL_P(anchor)) {
309
- Check_Type(anchor, T_STRING);
310
- anchor = rb_str_export_to_enc(anchor, encoding);
344
+ Check_Type(anchor, T_STRING);
345
+ anchor = rb_str_export_to_enc(anchor, encoding);
311
346
  }
312
347
 
313
348
  if(!NIL_P(tag)) {
314
- Check_Type(tag, T_STRING);
315
- tag = rb_str_export_to_enc(tag, encoding);
349
+ Check_Type(tag, T_STRING);
350
+ tag = rb_str_export_to_enc(tag, encoding);
316
351
  }
317
352
 
318
353
  TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
319
354
 
320
355
  yaml_sequence_start_event_initialize(
321
- &event,
322
- (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
323
- (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
324
- implicit ? 1 : 0,
325
- (yaml_sequence_style_t)NUM2INT(style)
326
- );
356
+ &event,
357
+ (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
358
+ (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
359
+ implicit ? 1 : 0,
360
+ (yaml_sequence_style_t)NUM2INT(style)
361
+ );
327
362
 
328
363
  emit(emitter, &event);
329
364
 
@@ -357,12 +392,12 @@ static VALUE end_sequence(VALUE self)
357
392
  * See Psych::Handler#start_mapping
358
393
  */
359
394
  static VALUE start_mapping(
360
- VALUE self,
361
- VALUE anchor,
362
- VALUE tag,
363
- VALUE implicit,
364
- VALUE style
365
- ) {
395
+ VALUE self,
396
+ VALUE anchor,
397
+ VALUE tag,
398
+ VALUE implicit,
399
+ VALUE style
400
+ ) {
366
401
  yaml_emitter_t * emitter;
367
402
  yaml_event_t event;
368
403
  rb_encoding *encoding;
@@ -372,22 +407,22 @@ static VALUE start_mapping(
372
407
  encoding = rb_utf8_encoding();
373
408
 
374
409
  if(!NIL_P(anchor)) {
375
- Check_Type(anchor, T_STRING);
376
- anchor = rb_str_export_to_enc(anchor, encoding);
410
+ Check_Type(anchor, T_STRING);
411
+ anchor = rb_str_export_to_enc(anchor, encoding);
377
412
  }
378
413
 
379
414
  if(!NIL_P(tag)) {
380
- Check_Type(tag, T_STRING);
381
- tag = rb_str_export_to_enc(tag, encoding);
415
+ Check_Type(tag, T_STRING);
416
+ tag = rb_str_export_to_enc(tag, encoding);
382
417
  }
383
418
 
384
419
  yaml_mapping_start_event_initialize(
385
- &event,
386
- (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
387
- (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
388
- implicit ? 1 : 0,
389
- (yaml_mapping_style_t)NUM2INT(style)
390
- );
420
+ &event,
421
+ (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
422
+ (yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
423
+ implicit ? 1 : 0,
424
+ (yaml_mapping_style_t)NUM2INT(style)
425
+ );
391
426
 
392
427
  emit(emitter, &event);
393
428
 
@@ -426,14 +461,14 @@ static VALUE alias(VALUE self, VALUE anchor)
426
461
  TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
427
462
 
428
463
  if(!NIL_P(anchor)) {
429
- Check_Type(anchor, T_STRING);
430
- anchor = rb_str_export_to_enc(anchor, rb_utf8_encoding());
464
+ Check_Type(anchor, T_STRING);
465
+ anchor = rb_str_export_to_enc(anchor, rb_utf8_encoding());
431
466
  }
432
467
 
433
468
  yaml_alias_event_initialize(
434
- &event,
435
- (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor))
436
- );
469
+ &event,
470
+ (yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor))
471
+ );
437
472
 
438
473
  emit(emitter, &event);
439
474
 
@@ -552,4 +587,3 @@ void Init_psych_emitter(void)
552
587
  id_indentation = rb_intern("indentation");
553
588
  id_canonical = rb_intern("canonical");
554
589
  }
555
- /* vim: set noet sws=4 sw=4: */