Project

General

Profile

Backport #6815 ยป backport.patch

tenderlovemaking (Aaron Patterson), 07/31/2012 10:57 AM

View differences:

ChangeLog
1
Tue Jul 31 10:36:12 2012  Aaron Patterson <aaron@tenderlovemaking.com>
2

  
3
	* ext/psych/lib/psych.rb: updated to released version.
4

  
5
	* ext/psych/psych.gemspec: ditto
6

  
7
Thu Jul 19 09:33:46 2012  Aaron Patterson <aaron@tenderlovemaking.com>
8

  
9
	* ext/psych/emitter.c (initialize): allow a configuration object to be
10
	  passed to the constructor so that mutation isn't required after
11
	  instantiation.
12

  
13
	* ext/psych/lib/psych/handler.rb: add configuration object
14

  
15
	* ext/psych/lib/psych/visitors/emitter.rb: use configuration object if
16
	  extra configuration is present.
17

  
18
Tue Jul 17 03:56:34 2012  Aaron Patterson <aaron@tenderlovemaking.com>
19

  
20
	* ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
21
	  are properly referenced. Patched by Joe Rafaniello via Github:
22
	    https://github.com/tenderlove/psych/pull/69
23
	* ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
24
	* test/psych/test_alias_and_anchor.rb: test for change
25

  
26
Sat Jun 16 01:27:14 2012  Aaron Patterson <aaron@tenderlovemaking.com>
27

  
28
	* ext/psych/lib/psych.rb: bumping psych to 1.3.3
29
	* ext/psych/psych.gemspec: ditto
30

  
31
Fri May 18 15:53:05 2012  KOSAKI Motohiro  <kosaki.motohiro@gmail.com>
32

  
33
	* ext/psych/extconf.rb: Use an exception instaed of bare abort.
34

  
35
Fri May 18 01:28:21 2012  Aaron Patterson <aaron@tenderlovemaking.com>
36

  
37
	* ext/psych/parser.c (transcode_string): fix encoding index names.
38
	  Thanks markizko for reporting.
39

  
40
Wed May 16 05:11:29 2012  Aaron Patterson <aaron@tenderlovemaking.com>
41

  
42
	* ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
43
	  subclass dumping and loading.
44

  
45
	* test/psych/test_array.rb: pertinent tests
46

  
47
	* test/psych/test_string.rb: ditto
48

  
49
Wed May 16 01:31:21 2012  Aaron Patterson <aaron@tenderlovemaking.com>
50

  
51
	* ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to
52
	  Psych::Omap objects rather than hashes. [Bug #6425]
53

  
54
	* test/psych/test_omap.rb: pertinent test.
55

  
56
Wed May 16 01:15:45 2012  Aaron Patterson <aaron@tenderlovemaking.com>
57

  
58
	* ext/psych/lib/psych/visitors/yaml_tree.rb: keep a reference to
59
	  custom coders so that GC does not impact dumped yaml reference ids.
60

  
61
Mon Apr 30 04:43:53 2012  Aaron Patterson <aaron@tenderlovemaking.com>
62

  
63
	* ext/psych/lib/psych/json/yaml_events.rb: implicit styles should not
64
	  be changeable for JSON events.
65

  
1 66
Sun Jul 29 04:32:31 2012  Nobuyoshi Nakada  <nobu@ruby-lang.org>
2 67

  
3 68
	* configure.in (ruby_pc): make configurable.  [Bug #6051]
ext/psych/emitter.c
2 2

  
3 3
VALUE cPsychEmitter;
4 4
static ID id_write;
5
static ID id_line_width;
6
static ID id_indentation;
7
static ID id_canonical;
5 8

  
6 9
static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
7 10
{
......
39 42
    return Data_Wrap_Struct(klass, 0, dealloc, emitter);
40 43
}
41 44

  
42
/* call-seq: Psych::Emitter.new(io)
45
/* call-seq: Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS)
43 46
 *
44 47
 * Create a new Psych::Emitter that writes to +io+.
45 48
 */
46
static VALUE initialize(VALUE self, VALUE io)
49
static VALUE initialize(int argc, VALUE *argv, VALUE self)
47 50
{
48 51
    yaml_emitter_t * emitter;
52
    VALUE io, options;
53
    VALUE line_width;
54
    VALUE indent;
55
    VALUE canonical;
56

  
49 57
    Data_Get_Struct(self, yaml_emitter_t, emitter);
50 58

  
59
    if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
60
	line_width = rb_funcall(options, id_line_width, 0);
61
	indent     = rb_funcall(options, id_indentation, 0);
62
	canonical  = rb_funcall(options, id_canonical, 0);
63

  
64
	yaml_emitter_set_width(emitter, NUM2INT(line_width));
65
	yaml_emitter_set_indent(emitter, NUM2INT(indent));
66
	yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
67
    }
68

  
51 69
    yaml_emitter_set_output(emitter, writer, (void *)io);
52 70

  
53 71
    return self;
......
494 512

  
495 513
    rb_define_alloc_func(cPsychEmitter, allocate);
496 514

  
497
    rb_define_method(cPsychEmitter, "initialize", initialize, 1);
515
    rb_define_method(cPsychEmitter, "initialize", initialize, -1);
498 516
    rb_define_method(cPsychEmitter, "start_stream", start_stream, 1);
499 517
    rb_define_method(cPsychEmitter, "end_stream", end_stream, 0);
500 518
    rb_define_method(cPsychEmitter, "start_document", start_document, 3);
......
512 530
    rb_define_method(cPsychEmitter, "line_width", line_width, 0);
513 531
    rb_define_method(cPsychEmitter, "line_width=", set_line_width, 1);
514 532

  
515
    id_write = rb_intern("write");
533
    id_write       = rb_intern("write");
534
    id_line_width  = rb_intern("line_width");
535
    id_indentation = rb_intern("indentation");
536
    id_canonical   = rb_intern("canonical");
516 537
}
517 538
/* vim: set noet sws=4 sw=4: */
ext/psych/extconf.rb
5 5
dir_config 'libyaml'
6 6

  
7 7
def asplode missing
8
  abort "#{missing} is missing. Please install libyaml."
8
  raise "#{missing} is missing. Please install libyaml."
9 9
end
10 10

  
11 11
asplode('yaml.h')  unless find_header  'yaml.h'
ext/psych/lib/psych.rb
93 93

  
94 94
module Psych
95 95
  # The version is Psych you're using
96
  VERSION         = '1.3.2'
96
  VERSION         = '1.3.4'
97 97

  
98 98
  # The version of libyaml Psych is using
99 99
  LIBYAML_VERSION = Psych.libyaml_version.join '.'
ext/psych/lib/psych/handler.rb
11 11
  # See Psych::Parser for more details
12 12
  class Handler
13 13
    ###
14
    # Configuration options for dumping YAML.
15
    class DumperOptions
16
      attr_accessor :line_width, :indentation, :canonical
17

  
18
      def initialize
19
        @line_width  = 0
20
        @indentation = 2
21
        @canonical   = false
22
      end
23
    end
24

  
25
    # Default dumping options
26
    OPTIONS = DumperOptions.new
27

  
28
    ###
14 29
    # Called with +encoding+ when the YAML stream starts.  This method is
15 30
    # called once per stream.  A stream may contain multiple documents.
16 31
    #
ext/psych/lib/psych/json/yaml_events.rb
10 10
      end
11 11

  
12 12
      def start_mapping anchor, tag, implicit, style
13
        super(anchor, nil, implicit, Nodes::Mapping::FLOW)
13
        super(anchor, nil, true, Nodes::Mapping::FLOW)
14 14
      end
15 15

  
16 16
      def start_sequence anchor, tag, implicit, style
17
        super(anchor, nil, implicit, Nodes::Sequence::FLOW)
17
        super(anchor, nil, true, Nodes::Sequence::FLOW)
18 18
      end
19 19

  
20 20
      def scalar value, anchor, tag, plain, quoted, style
ext/psych/lib/psych/visitors/emitter.rb
2 2
  module Visitors
3 3
    class Emitter < Psych::Visitors::Visitor
4 4
      def initialize io, options = {}
5
        @handler = Psych::Emitter.new io
6
        @handler.indentation = options[:indentation] if options[:indentation]
7
        @handler.canonical = options[:canonical] if options[:canonical]
8
        @handler.line_width = options[:line_width] if options[:line_width]
5
        opts = [:indentation, :canonical, :line_width].find_all { |opt|
6
          options.key?(opt)
7
        }
8

  
9
        if opts.empty?
10
          @handler = Psych::Emitter.new io
11
        else
12
          du = Handler::DumperOptions.new
13
          opts.each { |option| du.send :"#{option}=", options[option] }
14
          @handler = Psych::Emitter.new io, du
15
        end
9 16
      end
10 17

  
11 18
      def visit_Psych_Nodes_Stream o
ext/psych/lib/psych/visitors/to_ruby.rb
147 147
          string = members.delete 'str'
148 148

  
149 149
          if klass
150
            string = klass.allocate
151
            string.replace string
150
            string = klass.allocate.replace string
151
            register(o, string)
152 152
          end
153 153

  
154 154
          init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
......
222 222
        when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
223 223
          revive_hash resolve_class($1).new, o
224 224

  
225
        when '!omap', 'tag:yaml.org,2002:omap'
226
          map = register(o, Psych::Omap.new)
227
          o.children.each_slice(2) do |l,r|
228
            map[accept(l)] = accept r
229
          end
230
          map
231

  
225 232
        else
226 233
          revive_hash({}, o)
227 234
        end
ext/psych/lib/psych/visitors/yaml_tree.rb
20 20
        @st       = {}
21 21
        @ss       = ss
22 22
        @options  = options
23
        @coders   = []
23 24

  
24 25
        @dispatch_cache = Hash.new do |h,klass|
25 26
          method = "visit_#{(klass.name || '').split('::').join('_')}"
......
253 254
          maptag = '!ruby/string'
254 255
          maptag << ":#{o.class}" unless o.class == ::String
255 256

  
256
          @emitter.start_mapping nil, maptag, false, Nodes::Mapping::BLOCK
257
          register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
257 258
          @emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
258 259
          @emitter.scalar str, nil, tag, plain, quote, style
259 260

  
......
406 407
      end
407 408

  
408 409
      def dump_coder o
410
        @coders << o
409 411
        tag = Psych.dump_tags[o.class]
410 412
        unless tag
411 413
          klass = o.class == Object ? nil : o.class.name
ext/psych/parser.c
79 79
static VALUE transcode_string(VALUE src, int * parser_encoding)
80 80
{
81 81
    int utf8    = rb_utf8_encindex();
82
    int utf16le = rb_enc_find_index("UTF16_LE");
83
    int utf16be = rb_enc_find_index("UTF16_BE");
82
    int utf16le = rb_enc_find_index("UTF-16LE");
83
    int utf16be = rb_enc_find_index("UTF-16BE");
84 84
    int source_encoding = rb_enc_get_index(src);
85 85

  
86 86
    if (source_encoding == utf8) {
test/psych/test_alias_and_anchor.rb
1 1
require 'psych/helper'
2 2

  
3
class ObjectWithInstanceVariables
4
  attr_accessor :var1, :var2
5
end
6

  
7
class SubStringWithInstanceVariables < String
8
  attr_accessor :var1
9
end
10

  
3 11
module Psych
4 12
 class TestAliasAndAnchor < TestCase
5 13
   def test_mri_compatibility
......
14 22
     result.each {|el| assert_same(result[0], el) }
15 23
   end
16 24

  
25
   def test_mri_compatibility_object_with_ivars
26
  yaml = <<EOYAML
27
--- 
28
- &id001 !ruby/object:ObjectWithInstanceVariables 
29
  var1: test1
30
  var2: test2
31
- *id001
32
- *id001
33
EOYAML
34

  
35
     result = Psych.load yaml
36
     result.each do |el| 
37
      assert_same(result[0], el)
38
      assert_equal('test1', el.var1)
39
      assert_equal('test2', el.var2)
40
    end
41
   end
42

  
43
   def test_mri_compatibility_substring_with_ivars
44
    yaml = <<EOYAML
45
--- 
46
- &id001 !str:SubStringWithInstanceVariables 
47
  str: test
48
  "@var1": test
49
- *id001
50
- *id001
51
EOYAML
52
     result = Psych.load yaml
53
     result.each do |el|
54
      assert_same(result[0], el)
55
      assert_equal('test', el.var1)
56
    end
57
   end
58

  
17 59
   def test_anchor_alias_round_trip
18 60
     o = Object.new
19 61
     original = [o,o,o]
......
22 64
     result = Psych.load yaml
23 65
     result.each {|el| assert_same(result[0], el) }
24 66
   end
67

  
68
   def test_anchor_alias_round_trip_object_with_ivars
69
     o = ObjectWithInstanceVariables.new
70
     o.var1 = 'test1'
71
     o.var2 = 'test2'
72
     original = [o,o,o]
73

  
74
     yaml = Psych.dump original
75
     result = Psych.load yaml
76
     result.each do |el|
77
      assert_same(result[0], el)
78
      assert_equal('test1', el.var1)
79
      assert_equal('test2', el.var2)
80
    end
81
   end
82

  
83
   def test_anchor_alias_round_trip_substring_with_ivars
84
     o = SubStringWithInstanceVariables.new
85
     o.var1 = 'test'
86
     original = [o,o,o]
87

  
88
     yaml = Psych.dump original
89
     result = Psych.load yaml
90
     result.each do |el|
91
      assert_same(result[0], el)
92
      assert_equal('test', el.var1)
93
    end
94
   end
25 95
 end
26 96
end
test/psych/test_array.rb
14 14
      @list = [{ :a => 'b' }, 'foo']
15 15
    end
16 16

  
17
    def test_another_subclass_with_attributes
18
      y = Y.new.tap {|y| y.val = 1}
19
      y << "foo" << "bar"
20
      y = Psych.load Psych.dump y
21

  
22
      assert_equal %w{foo bar}, y
23
      assert_equal Y, y.class
24
      assert_equal 1, y.val
25
    end
26

  
17 27
    def test_subclass
18 28
      yaml = Psych.dump X.new
19 29
      assert_match X.name, yaml
test/psych/test_omap.rb
2 2

  
3 3
module Psych
4 4
  class TestOmap < TestCase
5
    def test_parse_as_map
6
      o = Psych.load "--- !!omap\na: 1\nb: 2"
7
      assert_kind_of Psych::Omap, o
8
      assert_equal 1, o['a']
9
      assert_equal 2, o['b']
10
    end
11

  
5 12
    def test_self_referential
6 13
      map = Psych::Omap.new
7 14
      map['foo'] = 'bar'
test/psych/test_string.rb
9 9
      attr_accessor :val
10 10
    end
11 11

  
12
    def test_another_subclass_with_attributes
13
      y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
14
      assert_equal "foo", y
15
      assert_equal Y, y.class
16
      assert_equal 1, y.val
17
    end
18

  
12 19
    def test_backwards_with_syck
13 20
      x = Psych.load "--- !str:#{X.name} foo\n\n"
14 21
      assert_equal X, x.class