psych 3.0.3 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +3 -6
- data/Rakefile +2 -16
- data/ext/psych/depend +2 -0
- data/ext/psych/extconf.rb +6 -2
- data/ext/psych/psych.c +6 -3
- data/ext/psych/psych_parser.c +20 -33
- data/ext/psych/psych_yaml_tree.c +0 -12
- data/ext/psych/yaml/api.c +48 -47
- data/ext/psych/yaml/config.h +77 -7
- data/ext/psych/yaml/dumper.c +3 -3
- data/ext/psych/yaml/emitter.c +48 -19
- data/ext/psych/yaml/loader.c +210 -110
- data/ext/psych/yaml/parser.c +11 -6
- data/ext/psych/yaml/reader.c +3 -3
- data/ext/psych/yaml/scanner.c +52 -28
- data/ext/psych/yaml/yaml.h +42 -28
- data/ext/psych/yaml/yaml_private.h +46 -20
- data/lib/psych.rb +171 -77
- data/lib/psych/class_loader.rb +6 -4
- data/lib/psych/handler.rb +1 -1
- data/lib/psych/nodes/node.rb +2 -2
- data/lib/psych/scalar_scanner.rb +23 -36
- data/lib/psych/versions.rb +4 -3
- data/lib/psych/visitors/to_ruby.rb +50 -17
- data/lib/psych/visitors/visitor.rb +17 -3
- data/lib/psych/visitors/yaml_tree.rb +30 -42
- data/psych.gemspec +18 -14
- metadata +10 -55
- data/.travis.yml +0 -20
- data/CHANGELOG.rdoc +0 -576
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc79877c9edee404384093bf5d8588162529b662c53c32ac7640dfe2c8c25855
|
4
|
+
data.tar.gz: ba8c0cc414092f566944869bba1f70e3343a93c50f9ac9a52156b2d16c729649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7356287aed8bd380f9e3fd31077dccbabb0fc70aac69abc82d76e80caea2d0c661a3a9d684d431fe3acbb71f68242d3f478512bdcdee3485d3fa66b14cdc5a5d
|
7
|
+
data.tar.gz: 9f6791b68628eb14f35a76a7a1fb7569dd9e9aa65533b005c65f80a0b2ec6bb78b10cc4d1830c177daaadcbfa93b03bf858aa29f6788f2ef45a4c8720f5476c2
|
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
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:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,22 +1,19 @@
|
|
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
|
7
4
|
|
8
5
|
## Description
|
9
6
|
|
10
7
|
Psych is a YAML parser and emitter. Psych leverages
|
11
|
-
[libyaml](
|
8
|
+
[libyaml](https://pyyaml.org/wiki/LibYAML) for its YAML parsing and emitting
|
12
9
|
capabilities. In addition to wrapping libyaml, Psych also knows how to
|
13
10
|
serialize and de-serialize most Ruby objects to and from the YAML format.
|
14
11
|
|
15
12
|
## Examples
|
16
13
|
|
17
14
|
```ruby
|
18
|
-
#
|
19
|
-
Psych.
|
15
|
+
# Safely load YAML in to a Ruby object
|
16
|
+
Psych.safe_load('--- foo') # => 'foo'
|
20
17
|
|
21
18
|
# Emit YAML from a Ruby object
|
22
19
|
Psych.dump("foo") # => "--- foo\n...\n"
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ if RUBY_PLATFORM =~ /java/
|
|
20
20
|
# and tell maven via system properties the snakeyaml version
|
21
21
|
# this is basically the same as running from the commandline:
|
22
22
|
# rmvn dependency:build-classpath -Dsnakeyaml.version='use version from Psych::DEFAULT_SNAKEYAML_VERSION here'
|
23
|
-
Maven::Ruby::Maven.new.exec('dependency:build-classpath', "-Dsnakeyaml.version
|
23
|
+
Maven::Ruby::Maven.new.exec('dependency:build-classpath', "-Dsnakeyaml.version=#{Psych::DEFAULT_SNAKEYAML_VERSION}", '-Dverbose=true')
|
24
24
|
ext.source_version = '1.7'
|
25
25
|
ext.target_version = '1.7'
|
26
26
|
ext.classpath = File.read('pkg/classpath')
|
@@ -28,21 +28,7 @@ if RUBY_PLATFORM =~ /java/
|
|
28
28
|
end
|
29
29
|
else
|
30
30
|
require 'rake/extensiontask'
|
31
|
-
|
32
|
-
Rake::ExtensionTask.new("psych", spec) do |ext|
|
33
|
-
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
|
34
|
-
ext.cross_compile = true
|
35
|
-
ext.cross_platform = %w[x86-mingw32 x64-mingw32]
|
36
|
-
ext.cross_compiling do |s|
|
37
|
-
s.files.concat ["lib/2.2/psych.so", "lib/2.3/psych.so", "lib/2.4/psych.so"]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
desc "Compile binaries for mingw platform using rake-compiler-dock"
|
43
|
-
task 'build:mingw' do
|
44
|
-
require 'rake_compiler_dock'
|
45
|
-
RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.2.2:2.3.0:2.4.0"
|
31
|
+
Rake::ExtensionTask.new("psych")
|
46
32
|
end
|
47
33
|
|
48
34
|
task :default => [:compile, :test]
|
data/ext/psych/depend
CHANGED
data/ext/psych/extconf.rb
CHANGED
@@ -13,8 +13,10 @@ if enable_config("bundled-libyaml", false) || !(find_header('yaml.h') && find_li
|
|
13
13
|
$VPATH << "$(srcdir)/yaml"
|
14
14
|
$INCFLAGS << " -I$(srcdir)/yaml"
|
15
15
|
|
16
|
-
$srcs = Dir.glob("#{$srcdir}/{,yaml/}*.c").map {|n| File.basename(n)}
|
16
|
+
$srcs = Dir.glob("#{$srcdir}/{,yaml/}*.c").map {|n| File.basename(n)}.sort
|
17
17
|
|
18
|
+
header = 'yaml/yaml.h'
|
19
|
+
header = "{$(VPATH)}#{header}" if $nmake
|
18
20
|
if have_macro("_WIN32")
|
19
21
|
$CPPFLAGS << " -DYAML_DECLARE_STATIC -DHAVE_CONFIG_H"
|
20
22
|
end
|
@@ -34,6 +36,8 @@ if enable_config("bundled-libyaml", false) || !(find_header('yaml.h') && find_li
|
|
34
36
|
have_header 'config.h'
|
35
37
|
end
|
36
38
|
|
37
|
-
create_makefile 'psych'
|
39
|
+
create_makefile 'psych' do |mk|
|
40
|
+
mk << "YAML_H = #{header}".strip << "\n"
|
41
|
+
end
|
38
42
|
|
39
43
|
# :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_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;
|
@@ -28,7 +27,7 @@ static ID id_event_location;
|
|
28
27
|
static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read)
|
29
28
|
{
|
30
29
|
VALUE io = (VALUE)data;
|
31
|
-
VALUE string = rb_funcall(io, id_read, 1,
|
30
|
+
VALUE string = rb_funcall(io, id_read, 1, SIZET2NUM(size));
|
32
31
|
|
33
32
|
*read = 0;
|
34
33
|
|
@@ -81,15 +80,18 @@ static VALUE allocate(VALUE klass)
|
|
81
80
|
static VALUE make_exception(yaml_parser_t * parser, VALUE path)
|
82
81
|
{
|
83
82
|
size_t line, column;
|
83
|
+
VALUE ePsychSyntaxError;
|
84
84
|
|
85
85
|
line = parser->context_mark.line + 1;
|
86
86
|
column = parser->context_mark.column + 1;
|
87
87
|
|
88
|
+
ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
|
89
|
+
|
88
90
|
return rb_funcall(ePsychSyntaxError, rb_intern("new"), 6,
|
89
91
|
path,
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
SIZET2NUM(line),
|
93
|
+
SIZET2NUM(column),
|
94
|
+
SIZET2NUM(parser->problem_offset),
|
93
95
|
parser->problem ? rb_usascii_str_new2(parser->problem) : Qnil,
|
94
96
|
parser->context ? rb_usascii_str_new2(parser->context) : Qnil);
|
95
97
|
}
|
@@ -254,7 +256,6 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
254
256
|
yaml_parser_t * parser;
|
255
257
|
yaml_event_t event;
|
256
258
|
int done = 0;
|
257
|
-
int tainted = 0;
|
258
259
|
int state = 0;
|
259
260
|
int parser_encoding = YAML_ANY_ENCODING;
|
260
261
|
int encoding = rb_utf8_encindex();
|
@@ -273,13 +274,10 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
273
274
|
yaml_parser_delete(parser);
|
274
275
|
yaml_parser_initialize(parser);
|
275
276
|
|
276
|
-
if (OBJ_TAINTED(yaml)) tainted = 1;
|
277
|
-
|
278
277
|
if (rb_respond_to(yaml, id_read)) {
|
279
278
|
yaml = transcode_io(yaml, &parser_encoding);
|
280
279
|
yaml_parser_set_encoding(parser, parser_encoding);
|
281
280
|
yaml_parser_set_input(parser, io_reader, (void *)yaml);
|
282
|
-
if (RTEST(rb_obj_is_kind_of(yaml, rb_cIO))) tainted = 1;
|
283
281
|
} else {
|
284
282
|
StringValue(yaml);
|
285
283
|
yaml = transcode_string(yaml, &parser_encoding);
|
@@ -305,10 +303,10 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
305
303
|
rb_exc_raise(exception);
|
306
304
|
}
|
307
305
|
|
308
|
-
start_line =
|
309
|
-
start_column =
|
310
|
-
end_line =
|
311
|
-
end_column =
|
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);
|
312
310
|
|
313
311
|
event_args[0] = handler;
|
314
312
|
event_args[1] = start_line;
|
@@ -323,7 +321,7 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
323
321
|
VALUE args[2];
|
324
322
|
|
325
323
|
args[0] = handler;
|
326
|
-
args[1] = INT2NUM(
|
324
|
+
args[1] = INT2NUM(event.data.stream_start.encoding);
|
327
325
|
rb_protect(protected_start_stream, (VALUE)args, &state);
|
328
326
|
}
|
329
327
|
break;
|
@@ -336,8 +334,8 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
336
334
|
VALUE version = event.data.document_start.version_directive ?
|
337
335
|
rb_ary_new3(
|
338
336
|
(long)2,
|
339
|
-
INT2NUM(
|
340
|
-
INT2NUM(
|
337
|
+
INT2NUM(event.data.document_start.version_directive->major),
|
338
|
+
INT2NUM(event.data.document_start.version_directive->minor)
|
341
339
|
) : rb_ary_new();
|
342
340
|
|
343
341
|
if(event.data.document_start.tag_directives.start) {
|
@@ -350,13 +348,11 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
350
348
|
VALUE prefix = Qnil;
|
351
349
|
if(start->handle) {
|
352
350
|
handle = rb_str_new2((const char *)start->handle);
|
353
|
-
if (tainted) OBJ_TAINT(handle);
|
354
351
|
PSYCH_TRANSCODE(handle, encoding, internal_enc);
|
355
352
|
}
|
356
353
|
|
357
354
|
if(start->prefix) {
|
358
355
|
prefix = rb_str_new2((const char *)start->prefix);
|
359
|
-
if (tainted) OBJ_TAINT(prefix);
|
360
356
|
PSYCH_TRANSCODE(prefix, encoding, internal_enc);
|
361
357
|
}
|
362
358
|
|
@@ -385,7 +381,6 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
385
381
|
VALUE alias = Qnil;
|
386
382
|
if(event.data.alias.anchor) {
|
387
383
|
alias = rb_str_new2((const char *)event.data.alias.anchor);
|
388
|
-
if (tainted) OBJ_TAINT(alias);
|
389
384
|
PSYCH_TRANSCODE(alias, encoding, internal_enc);
|
390
385
|
}
|
391
386
|
|
@@ -404,19 +399,16 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
404
399
|
(const char *)event.data.scalar.value,
|
405
400
|
(long)event.data.scalar.length
|
406
401
|
);
|
407
|
-
if (tainted) OBJ_TAINT(val);
|
408
402
|
|
409
403
|
PSYCH_TRANSCODE(val, encoding, internal_enc);
|
410
404
|
|
411
405
|
if(event.data.scalar.anchor) {
|
412
406
|
anchor = rb_str_new2((const char *)event.data.scalar.anchor);
|
413
|
-
if (tainted) OBJ_TAINT(anchor);
|
414
407
|
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
415
408
|
}
|
416
409
|
|
417
410
|
if(event.data.scalar.tag) {
|
418
411
|
tag = rb_str_new2((const char *)event.data.scalar.tag);
|
419
|
-
if (tainted) OBJ_TAINT(tag);
|
420
412
|
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
421
413
|
}
|
422
414
|
|
@@ -426,7 +418,7 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
426
418
|
quoted_implicit =
|
427
419
|
event.data.scalar.quoted_implicit == 0 ? Qfalse : Qtrue;
|
428
420
|
|
429
|
-
style = INT2NUM(
|
421
|
+
style = INT2NUM(event.data.scalar.style);
|
430
422
|
|
431
423
|
args[0] = handler;
|
432
424
|
args[1] = val;
|
@@ -446,21 +438,19 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
446
438
|
VALUE implicit, style;
|
447
439
|
if(event.data.sequence_start.anchor) {
|
448
440
|
anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
|
449
|
-
if (tainted) OBJ_TAINT(anchor);
|
450
441
|
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
451
442
|
}
|
452
443
|
|
453
444
|
tag = Qnil;
|
454
445
|
if(event.data.sequence_start.tag) {
|
455
446
|
tag = rb_str_new2((const char *)event.data.sequence_start.tag);
|
456
|
-
if (tainted) OBJ_TAINT(tag);
|
457
447
|
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
458
448
|
}
|
459
449
|
|
460
450
|
implicit =
|
461
451
|
event.data.sequence_start.implicit == 0 ? Qfalse : Qtrue;
|
462
452
|
|
463
|
-
style = INT2NUM(
|
453
|
+
style = INT2NUM(event.data.sequence_start.style);
|
464
454
|
|
465
455
|
args[0] = handler;
|
466
456
|
args[1] = anchor;
|
@@ -482,20 +472,18 @@ static VALUE parse(int argc, VALUE *argv, VALUE self)
|
|
482
472
|
VALUE implicit, style;
|
483
473
|
if(event.data.mapping_start.anchor) {
|
484
474
|
anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
|
485
|
-
if (tainted) OBJ_TAINT(anchor);
|
486
475
|
PSYCH_TRANSCODE(anchor, encoding, internal_enc);
|
487
476
|
}
|
488
477
|
|
489
478
|
if(event.data.mapping_start.tag) {
|
490
479
|
tag = rb_str_new2((const char *)event.data.mapping_start.tag);
|
491
|
-
if (tainted) OBJ_TAINT(tag);
|
492
480
|
PSYCH_TRANSCODE(tag, encoding, internal_enc);
|
493
481
|
}
|
494
482
|
|
495
483
|
implicit =
|
496
484
|
event.data.mapping_start.implicit == 0 ? Qfalse : Qtrue;
|
497
485
|
|
498
|
-
style = INT2NUM(
|
486
|
+
style = INT2NUM(event.data.mapping_start.style);
|
499
487
|
|
500
488
|
args[0] = handler;
|
501
489
|
args[1] = anchor;
|
@@ -539,9 +527,9 @@ static VALUE mark(VALUE self)
|
|
539
527
|
|
540
528
|
TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
|
541
529
|
mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
|
542
|
-
args[0] =
|
543
|
-
args[1] =
|
544
|
-
args[2] =
|
530
|
+
args[0] = SIZET2NUM(parser->mark.index);
|
531
|
+
args[1] = SIZET2NUM(parser->mark.line);
|
532
|
+
args[2] = SIZET2NUM(parser->mark.column);
|
545
533
|
|
546
534
|
return rb_class_new_instance(3, args, mark_klass);
|
547
535
|
}
|
@@ -569,7 +557,6 @@ void Init_psych_parser(void)
|
|
569
557
|
rb_define_const(cPsychParser, "UTF16BE", INT2NUM(YAML_UTF16BE_ENCODING));
|
570
558
|
|
571
559
|
rb_require("psych/syntax_error");
|
572
|
-
ePsychSyntaxError = rb_const_get(mPsych, rb_intern("SyntaxError"));
|
573
560
|
|
574
561
|
rb_define_method(cPsychParser, "parse", parse, -1);
|
575
562
|
rb_define_method(cPsychParser, "mark", mark, 0);
|
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(StringValueCStr(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: */
|
data/ext/psych/yaml/api.c
CHANGED
@@ -74,7 +74,7 @@ YAML_DECLARE(int)
|
|
74
74
|
yaml_string_extend(yaml_char_t **start,
|
75
75
|
yaml_char_t **pointer, yaml_char_t **end)
|
76
76
|
{
|
77
|
-
yaml_char_t *new_start = yaml_realloc(*start, (*end - *start)*2);
|
77
|
+
yaml_char_t *new_start = (yaml_char_t *)yaml_realloc((void*)*start, (*end - *start)*2);
|
78
78
|
|
79
79
|
if (!new_start) return 0;
|
80
80
|
|
@@ -94,8 +94,9 @@ yaml_string_extend(yaml_char_t **start,
|
|
94
94
|
YAML_DECLARE(int)
|
95
95
|
yaml_string_join(
|
96
96
|
yaml_char_t **a_start, yaml_char_t **a_pointer, yaml_char_t **a_end,
|
97
|
-
yaml_char_t **b_start, yaml_char_t **b_pointer, yaml_char_t **b_end)
|
97
|
+
yaml_char_t **b_start, yaml_char_t **b_pointer, SHIM(yaml_char_t **b_end))
|
98
98
|
{
|
99
|
+
UNUSED_PARAM(b_end)
|
99
100
|
if (*b_start == *b_pointer)
|
100
101
|
return 1;
|
101
102
|
|
@@ -117,7 +118,12 @@ yaml_string_join(
|
|
117
118
|
YAML_DECLARE(int)
|
118
119
|
yaml_stack_extend(void **start, void **top, void **end)
|
119
120
|
{
|
120
|
-
void *new_start
|
121
|
+
void *new_start;
|
122
|
+
|
123
|
+
if ((char *)*end - (char *)*start >= INT_MAX / 2)
|
124
|
+
return 0;
|
125
|
+
|
126
|
+
new_start = yaml_realloc(*start, ((char *)*end - (char *)*start)*2);
|
121
127
|
|
122
128
|
if (!new_start) return 0;
|
123
129
|
|
@@ -177,17 +183,17 @@ yaml_parser_initialize(yaml_parser_t *parser)
|
|
177
183
|
goto error;
|
178
184
|
if (!BUFFER_INIT(parser, parser->buffer, INPUT_BUFFER_SIZE))
|
179
185
|
goto error;
|
180
|
-
if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE))
|
186
|
+
if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_SIZE, yaml_token_t*))
|
181
187
|
goto error;
|
182
|
-
if (!STACK_INIT(parser, parser->indents,
|
188
|
+
if (!STACK_INIT(parser, parser->indents, int*))
|
183
189
|
goto error;
|
184
|
-
if (!STACK_INIT(parser, parser->simple_keys,
|
190
|
+
if (!STACK_INIT(parser, parser->simple_keys, yaml_simple_key_t*))
|
185
191
|
goto error;
|
186
|
-
if (!STACK_INIT(parser, parser->states,
|
192
|
+
if (!STACK_INIT(parser, parser->states, yaml_parser_state_t*))
|
187
193
|
goto error;
|
188
|
-
if (!STACK_INIT(parser, parser->marks,
|
194
|
+
if (!STACK_INIT(parser, parser->marks, yaml_mark_t*))
|
189
195
|
goto error;
|
190
|
-
if (!STACK_INIT(parser, parser->tag_directives,
|
196
|
+
if (!STACK_INIT(parser, parser->tag_directives, yaml_tag_directive_t*))
|
191
197
|
goto error;
|
192
198
|
|
193
199
|
return 1;
|
@@ -243,7 +249,7 @@ static int
|
|
243
249
|
yaml_string_read_handler(void *data, unsigned char *buffer, size_t size,
|
244
250
|
size_t *size_read)
|
245
251
|
{
|
246
|
-
yaml_parser_t *parser = data;
|
252
|
+
yaml_parser_t *parser = (yaml_parser_t *)data;
|
247
253
|
|
248
254
|
if (parser->input.string.current == parser->input.string.end) {
|
249
255
|
*size_read = 0;
|
@@ -269,7 +275,7 @@ static int
|
|
269
275
|
yaml_file_read_handler(void *data, unsigned char *buffer, size_t size,
|
270
276
|
size_t *size_read)
|
271
277
|
{
|
272
|
-
yaml_parser_t *parser = data;
|
278
|
+
yaml_parser_t *parser = (yaml_parser_t *)data;
|
273
279
|
|
274
280
|
*size_read = fread(buffer, 1, size, parser->input.file);
|
275
281
|
return !ferror(parser->input.file);
|
@@ -355,13 +361,13 @@ yaml_emitter_initialize(yaml_emitter_t *emitter)
|
|
355
361
|
goto error;
|
356
362
|
if (!BUFFER_INIT(emitter, emitter->raw_buffer, OUTPUT_RAW_BUFFER_SIZE))
|
357
363
|
goto error;
|
358
|
-
if (!STACK_INIT(emitter, emitter->states,
|
364
|
+
if (!STACK_INIT(emitter, emitter->states, yaml_emitter_state_t*))
|
359
365
|
goto error;
|
360
|
-
if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE))
|
366
|
+
if (!QUEUE_INIT(emitter, emitter->events, INITIAL_QUEUE_SIZE, yaml_event_t*))
|
361
367
|
goto error;
|
362
|
-
if (!STACK_INIT(emitter, emitter->indents,
|
368
|
+
if (!STACK_INIT(emitter, emitter->indents, int*))
|
363
369
|
goto error;
|
364
|
-
if (!STACK_INIT(emitter, emitter->tag_directives,
|
370
|
+
if (!STACK_INIT(emitter, emitter->tag_directives, yaml_tag_directive_t*))
|
365
371
|
goto error;
|
366
372
|
|
367
373
|
return 1;
|
@@ -413,7 +419,7 @@ yaml_emitter_delete(yaml_emitter_t *emitter)
|
|
413
419
|
static int
|
414
420
|
yaml_string_write_handler(void *data, unsigned char *buffer, size_t size)
|
415
421
|
{
|
416
|
-
|
422
|
+
yaml_emitter_t *emitter = (yaml_emitter_t *)data;
|
417
423
|
|
418
424
|
if (emitter->output.string.size - *emitter->output.string.size_written
|
419
425
|
< size) {
|
@@ -439,7 +445,7 @@ yaml_string_write_handler(void *data, unsigned char *buffer, size_t size)
|
|
439
445
|
static int
|
440
446
|
yaml_file_write_handler(void *data, unsigned char *buffer, size_t size)
|
441
447
|
{
|
442
|
-
yaml_emitter_t *emitter = data;
|
448
|
+
yaml_emitter_t *emitter = (yaml_emitter_t *)data;
|
443
449
|
|
444
450
|
return (fwrite(buffer, 1, size, emitter->output.file) == size);
|
445
451
|
}
|
@@ -617,10 +623,10 @@ yaml_token_delete(yaml_token_t *token)
|
|
617
623
|
*/
|
618
624
|
|
619
625
|
static int
|
620
|
-
yaml_check_utf8(yaml_char_t *start, size_t length)
|
626
|
+
yaml_check_utf8(const yaml_char_t *start, size_t length)
|
621
627
|
{
|
622
|
-
yaml_char_t *end = start+length;
|
623
|
-
yaml_char_t *pointer = start;
|
628
|
+
const yaml_char_t *end = start+length;
|
629
|
+
const yaml_char_t *pointer = start;
|
624
630
|
|
625
631
|
while (pointer < end) {
|
626
632
|
unsigned char octet;
|
@@ -717,7 +723,7 @@ yaml_document_start_event_initialize(yaml_event_t *event,
|
|
717
723
|
/* Valid tag directives are expected. */
|
718
724
|
|
719
725
|
if (version_directive) {
|
720
|
-
version_directive_copy =
|
726
|
+
version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t);
|
721
727
|
if (!version_directive_copy) goto error;
|
722
728
|
version_directive_copy->major = version_directive->major;
|
723
729
|
version_directive_copy->minor = version_directive->minor;
|
@@ -725,7 +731,7 @@ yaml_document_start_event_initialize(yaml_event_t *event,
|
|
725
731
|
|
726
732
|
if (tag_directives_start != tag_directives_end) {
|
727
733
|
yaml_tag_directive_t *tag_directive;
|
728
|
-
if (!STACK_INIT(&context, tag_directives_copy,
|
734
|
+
if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*))
|
729
735
|
goto error;
|
730
736
|
for (tag_directive = tag_directives_start;
|
731
737
|
tag_directive != tag_directives_end; tag_directive ++) {
|
@@ -788,7 +794,7 @@ yaml_document_end_event_initialize(yaml_event_t *event, int implicit)
|
|
788
794
|
*/
|
789
795
|
|
790
796
|
YAML_DECLARE(int)
|
791
|
-
yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor)
|
797
|
+
yaml_alias_event_initialize(yaml_event_t *event, const yaml_char_t *anchor)
|
792
798
|
{
|
793
799
|
yaml_mark_t mark = { 0, 0, 0 };
|
794
800
|
yaml_char_t *anchor_copy = NULL;
|
@@ -813,8 +819,8 @@ yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor)
|
|
813
819
|
|
814
820
|
YAML_DECLARE(int)
|
815
821
|
yaml_scalar_event_initialize(yaml_event_t *event,
|
816
|
-
yaml_char_t *anchor, yaml_char_t *tag,
|
817
|
-
yaml_char_t *value, int length,
|
822
|
+
const yaml_char_t *anchor, const yaml_char_t *tag,
|
823
|
+
const yaml_char_t *value, int length,
|
818
824
|
int plain_implicit, int quoted_implicit,
|
819
825
|
yaml_scalar_style_t style)
|
820
826
|
{
|
@@ -839,11 +845,11 @@ yaml_scalar_event_initialize(yaml_event_t *event,
|
|
839
845
|
}
|
840
846
|
|
841
847
|
if (length < 0) {
|
842
|
-
length = strlen((char *)value);
|
848
|
+
length = (int)strlen((char *)value);
|
843
849
|
}
|
844
850
|
|
845
851
|
if (!yaml_check_utf8(value, length)) goto error;
|
846
|
-
value_copy =
|
852
|
+
value_copy = YAML_MALLOC(length+1);
|
847
853
|
if (!value_copy) goto error;
|
848
854
|
memcpy(value_copy, value, length);
|
849
855
|
value_copy[length] = '\0';
|
@@ -867,7 +873,7 @@ error:
|
|
867
873
|
|
868
874
|
YAML_DECLARE(int)
|
869
875
|
yaml_sequence_start_event_initialize(yaml_event_t *event,
|
870
|
-
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
|
876
|
+
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
|
871
877
|
yaml_sequence_style_t style)
|
872
878
|
{
|
873
879
|
yaml_mark_t mark = { 0, 0, 0 };
|
@@ -922,7 +928,7 @@ yaml_sequence_end_event_initialize(yaml_event_t *event)
|
|
922
928
|
|
923
929
|
YAML_DECLARE(int)
|
924
930
|
yaml_mapping_start_event_initialize(yaml_event_t *event,
|
925
|
-
yaml_char_t *anchor, yaml_char_t *tag, int implicit,
|
931
|
+
const yaml_char_t *anchor, const yaml_char_t *tag, int implicit,
|
926
932
|
yaml_mapping_style_t style)
|
927
933
|
{
|
928
934
|
yaml_mark_t mark = { 0, 0, 0 };
|
@@ -1055,10 +1061,10 @@ yaml_document_initialize(yaml_document_t *document,
|
|
1055
1061
|
(tag_directives_start == tag_directives_end));
|
1056
1062
|
/* Valid tag directives are expected. */
|
1057
1063
|
|
1058
|
-
if (!STACK_INIT(&context, nodes,
|
1064
|
+
if (!STACK_INIT(&context, nodes, yaml_node_t*)) goto error;
|
1059
1065
|
|
1060
1066
|
if (version_directive) {
|
1061
|
-
version_directive_copy =
|
1067
|
+
version_directive_copy = YAML_MALLOC_STATIC(yaml_version_directive_t);
|
1062
1068
|
if (!version_directive_copy) goto error;
|
1063
1069
|
version_directive_copy->major = version_directive->major;
|
1064
1070
|
version_directive_copy->minor = version_directive->minor;
|
@@ -1066,7 +1072,7 @@ yaml_document_initialize(yaml_document_t *document,
|
|
1066
1072
|
|
1067
1073
|
if (tag_directives_start != tag_directives_end) {
|
1068
1074
|
yaml_tag_directive_t *tag_directive;
|
1069
|
-
if (!STACK_INIT(&context, tag_directives_copy,
|
1075
|
+
if (!STACK_INIT(&context, tag_directives_copy, yaml_tag_directive_t*))
|
1070
1076
|
goto error;
|
1071
1077
|
for (tag_directive = tag_directives_start;
|
1072
1078
|
tag_directive != tag_directives_end; tag_directive ++) {
|
@@ -1116,13 +1122,8 @@ error:
|
|
1116
1122
|
YAML_DECLARE(void)
|
1117
1123
|
yaml_document_delete(yaml_document_t *document)
|
1118
1124
|
{
|
1119
|
-
struct {
|
1120
|
-
yaml_error_type_t error;
|
1121
|
-
} context;
|
1122
1125
|
yaml_tag_directive_t *tag_directive;
|
1123
1126
|
|
1124
|
-
context.error = YAML_NO_ERROR; /* Eliminate a compliler warning. */
|
1125
|
-
|
1126
1127
|
assert(document); /* Non-NULL document object is expected. */
|
1127
1128
|
|
1128
1129
|
while (!STACK_EMPTY(&context, document->nodes)) {
|
@@ -1192,7 +1193,7 @@ yaml_document_get_root_node(yaml_document_t *document)
|
|
1192
1193
|
|
1193
1194
|
YAML_DECLARE(int)
|
1194
1195
|
yaml_document_add_scalar(yaml_document_t *document,
|
1195
|
-
yaml_char_t *tag, yaml_char_t *value, int length,
|
1196
|
+
const yaml_char_t *tag, const yaml_char_t *value, int length,
|
1196
1197
|
yaml_scalar_style_t style)
|
1197
1198
|
{
|
1198
1199
|
struct {
|
@@ -1215,11 +1216,11 @@ yaml_document_add_scalar(yaml_document_t *document,
|
|
1215
1216
|
if (!tag_copy) goto error;
|
1216
1217
|
|
1217
1218
|
if (length < 0) {
|
1218
|
-
length = strlen((char *)value);
|
1219
|
+
length = (int)strlen((char *)value);
|
1219
1220
|
}
|
1220
1221
|
|
1221
1222
|
if (!yaml_check_utf8(value, length)) goto error;
|
1222
|
-
value_copy =
|
1223
|
+
value_copy = YAML_MALLOC(length+1);
|
1223
1224
|
if (!value_copy) goto error;
|
1224
1225
|
memcpy(value_copy, value, length);
|
1225
1226
|
value_copy[length] = '\0';
|
@@ -1227,7 +1228,7 @@ yaml_document_add_scalar(yaml_document_t *document,
|
|
1227
1228
|
SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark);
|
1228
1229
|
if (!PUSH(&context, document->nodes, node)) goto error;
|
1229
1230
|
|
1230
|
-
return document->nodes.top - document->nodes.start;
|
1231
|
+
return (int)(document->nodes.top - document->nodes.start);
|
1231
1232
|
|
1232
1233
|
error:
|
1233
1234
|
yaml_free(tag_copy);
|
@@ -1242,7 +1243,7 @@ error:
|
|
1242
1243
|
|
1243
1244
|
YAML_DECLARE(int)
|
1244
1245
|
yaml_document_add_sequence(yaml_document_t *document,
|
1245
|
-
yaml_char_t *tag, yaml_sequence_style_t style)
|
1246
|
+
const yaml_char_t *tag, yaml_sequence_style_t style)
|
1246
1247
|
{
|
1247
1248
|
struct {
|
1248
1249
|
yaml_error_type_t error;
|
@@ -1266,13 +1267,13 @@ yaml_document_add_sequence(yaml_document_t *document,
|
|
1266
1267
|
tag_copy = yaml_strdup(tag);
|
1267
1268
|
if (!tag_copy) goto error;
|
1268
1269
|
|
1269
|
-
if (!STACK_INIT(&context, items,
|
1270
|
+
if (!STACK_INIT(&context, items, yaml_node_item_t*)) goto error;
|
1270
1271
|
|
1271
1272
|
SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end,
|
1272
1273
|
style, mark, mark);
|
1273
1274
|
if (!PUSH(&context, document->nodes, node)) goto error;
|
1274
1275
|
|
1275
|
-
return document->nodes.top - document->nodes.start;
|
1276
|
+
return (int)(document->nodes.top - document->nodes.start);
|
1276
1277
|
|
1277
1278
|
error:
|
1278
1279
|
STACK_DEL(&context, items);
|
@@ -1287,7 +1288,7 @@ error:
|
|
1287
1288
|
|
1288
1289
|
YAML_DECLARE(int)
|
1289
1290
|
yaml_document_add_mapping(yaml_document_t *document,
|
1290
|
-
yaml_char_t *tag, yaml_mapping_style_t style)
|
1291
|
+
const yaml_char_t *tag, yaml_mapping_style_t style)
|
1291
1292
|
{
|
1292
1293
|
struct {
|
1293
1294
|
yaml_error_type_t error;
|
@@ -1311,13 +1312,13 @@ yaml_document_add_mapping(yaml_document_t *document,
|
|
1311
1312
|
tag_copy = yaml_strdup(tag);
|
1312
1313
|
if (!tag_copy) goto error;
|
1313
1314
|
|
1314
|
-
if (!STACK_INIT(&context, pairs,
|
1315
|
+
if (!STACK_INIT(&context, pairs, yaml_node_pair_t*)) goto error;
|
1315
1316
|
|
1316
1317
|
MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end,
|
1317
1318
|
style, mark, mark);
|
1318
1319
|
if (!PUSH(&context, document->nodes, node)) goto error;
|
1319
1320
|
|
1320
|
-
return document->nodes.top - document->nodes.start;
|
1321
|
+
return (int)(document->nodes.top - document->nodes.start);
|
1321
1322
|
|
1322
1323
|
error:
|
1323
1324
|
STACK_DEL(&context, pairs);
|