[前][次][番号順一覧][スレッド一覧]

ruby-changes:24604

From: tenderlove <ko1@a...>
Date: Wed, 8 Aug 2012 05:50:20 +0900 (JST)
Subject: [ruby-changes:24604] tenderlove:r36654 (ruby_1_9_3): merge revision(s) r36583, r36458, r36414, r36103, r35690, r35681, r35658, r35657, r35655, r35492: [Backport #6815]

tenderlove	2012-08-08 05:50:05 +0900 (Wed, 08 Aug 2012)

  New Revision: 36654

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36654

  Log:
    merge revision(s) r36583, r36458, r36414, r36103, r35690, r35681, r35658, r35657, r35655, r35492: [Backport #6815]
    
        * ext/psych/lib/psych.rb: updated to released version.
    
        * ext/psych/psych.gemspec: ditto
    
        * ext/psych/emitter.c (initialize): allow a configuration object to be
          passed to the constructor so that mutation isn't required after
          instantiation.
    
        * ext/psych/lib/psych/handler.rb: add configuration object
    
        * ext/psych/lib/psych/visitors/emitter.rb: use configuration object if
          extra configuration is present.
    
        * ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
          are properly referenced. Patched by Joe Rafaniello via Github:
            https://github.com/tenderlove/psych/pull/69
        * ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
        * test/psych/test_alias_and_anchor.rb: test for change
    
        * ext/psych/lib/psych.rb: bumping psych to 1.3.3
        * ext/psych/psych.gemspec: ditto
    
        * ext/psych/extconf.rb: Use an exception instaed of bare abort.
    
        * ext/psych/parser.c (transcode_string): fix encoding index names.
          Thanks markizko for reporting.
    
        * ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
          subclass dumping and loading.
    
        * test/psych/test_array.rb: pertinent tests
    
        * test/psych/test_string.rb: ditto
    
        * ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to
          Psych::Omap objects rather than hashes. [Bug #6425]
    
        * test/psych/test_omap.rb: pertinent test.
    
        * ext/psych/lib/psych/visitors/yaml_tree.rb: keep a reference to
          custom coders so that GC does not impact dumped yaml reference ids.
    
        * ext/psych/lib/psych/json/yaml_events.rb: implicit styles should not
          be changeable for JSON events.

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/ext/psych/emitter.c
    branches/ruby_1_9_3/ext/psych/extconf.rb
    branches/ruby_1_9_3/ext/psych/lib/psych/handler.rb
    branches/ruby_1_9_3/ext/psych/lib/psych/json/yaml_events.rb
    branches/ruby_1_9_3/ext/psych/lib/psych/visitors/emitter.rb
    branches/ruby_1_9_3/ext/psych/lib/psych/visitors/to_ruby.rb
    branches/ruby_1_9_3/ext/psych/lib/psych/visitors/yaml_tree.rb
    branches/ruby_1_9_3/ext/psych/lib/psych.rb
    branches/ruby_1_9_3/ext/psych/parser.c
    branches/ruby_1_9_3/test/psych/test_alias_and_anchor.rb
    branches/ruby_1_9_3/test/psych/test_array.rb
    branches/ruby_1_9_3/test/psych/test_omap.rb
    branches/ruby_1_9_3/test/psych/test_string.rb
    branches/ruby_1_9_3/version.h

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 36653)
+++ ruby_1_9_3/ChangeLog	(revision 36654)
@@ -1,3 +1,68 @@
+Tue Jul 31 10:36:12 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych.rb: updated to released version.
+
+	* ext/psych/psych.gemspec: ditto
+
+Thu Jul 19 09:33:46 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/emitter.c (initialize): allow a configuration object to be
+	  passed to the constructor so that mutation isn't required after
+	  instantiation.
+
+	* ext/psych/lib/psych/handler.rb: add configuration object
+
+	* ext/psych/lib/psych/visitors/emitter.rb: use configuration object if
+	  extra configuration is present.
+
+Tue Jul 17 03:56:34 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
+	  are properly referenced. Patched by Joe Rafaniello via Github:
+	    https://github.com/tenderlove/psych/pull/69
+	* ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
+	* test/psych/test_alias_and_anchor.rb: test for change
+
+Sat Jun 16 01:27:14 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych.rb: bumping psych to 1.3.3
+	* ext/psych/psych.gemspec: ditto
+
+Fri May 18 15:53:05 2012  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* ext/psych/extconf.rb: Use an exception instaed of bare abort.
+
+Fri May 18 01:28:21 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/parser.c (transcode_string): fix encoding index names.
+	  Thanks markizko for reporting.
+
+Wed May 16 05:11:29 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
+	  subclass dumping and loading.
+
+	* test/psych/test_array.rb: pertinent tests
+
+	* test/psych/test_string.rb: ditto
+
+Wed May 16 01:31:21 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to
+	  Psych::Omap objects rather than hashes. [Bug #6425]
+
+	* test/psych/test_omap.rb: pertinent test.
+
+Wed May 16 01:15:45 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/visitors/yaml_tree.rb: keep a reference to
+	  custom coders so that GC does not impact dumped yaml reference ids.
+
+Mon Apr 30 04:43:53 2012  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/json/yaml_events.rb: implicit styles should not
+	  be changeable for JSON events.
+
 Sun Jul 29 04:32:31 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (ruby_pc): make configurable.  [Bug #6051]
Index: ruby_1_9_3/ext/psych/lib/psych/handler.rb
===================================================================
--- ruby_1_9_3/ext/psych/lib/psych/handler.rb	(revision 36653)
+++ ruby_1_9_3/ext/psych/lib/psych/handler.rb	(revision 36654)
@@ -11,6 +11,21 @@
   # See Psych::Parser for more details
   class Handler
     ###
+    # Configuration options for dumping YAML.
+    class DumperOptions
+      attr_accessor :line_width, :indentation, :canonical
+
+      def initialize
+        @line_width  = 0
+        @indentation = 2
+        @canonical   = false
+      end
+    end
+
+    # Default dumping options
+    OPTIONS = DumperOptions.new
+
+    ###
     # Called with +encoding+ when the YAML stream starts.  This method is
     # called once per stream.  A stream may contain multiple documents.
     #
Index: ruby_1_9_3/ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ruby_1_9_3/ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 36653)
+++ ruby_1_9_3/ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 36654)
@@ -20,6 +20,7 @@
         @st       = {}
         @ss       = ss
         @options  = options
+        @coders   = []
 
         @dispatch_cache = Hash.new do |h,klass|
           method = "visit_#{(klass.name || '').split('::').join('_')}"
@@ -253,7 +254,7 @@
           maptag = '!ruby/string'
           maptag << ":#{o.class}" unless o.class == ::String
 
-          @emitter.start_mapping nil, maptag, false, Nodes::Mapping::BLOCK
+          register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
           @emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
           @emitter.scalar str, nil, tag, plain, quote, style
 
@@ -406,6 +407,7 @@
       end
 
       def dump_coder o
+        @coders << o
         tag = Psych.dump_tags[o.class]
         unless tag
           klass = o.class == Object ? nil : o.class.name
Index: ruby_1_9_3/ext/psych/lib/psych/visitors/to_ruby.rb
===================================================================
--- ruby_1_9_3/ext/psych/lib/psych/visitors/to_ruby.rb	(revision 36653)
+++ ruby_1_9_3/ext/psych/lib/psych/visitors/to_ruby.rb	(revision 36654)
@@ -147,8 +147,8 @@
           string = members.delete 'str'
 
           if klass
-            string = klass.allocate
-            string.replace string
+            string = klass.allocate.replace string
+            register(o, string)
           end
 
           init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
@@ -222,6 +222,13 @@
         when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
           revive_hash resolve_class($1).new, o
 
+        when '!omap', 'tag:yaml.org,2002:omap'
+          map = register(o, Psych::Omap.new)
+          o.children.each_slice(2) do |l,r|
+            map[accept(l)] = accept r
+          end
+          map
+
         else
           revive_hash({}, o)
         end
Index: ruby_1_9_3/ext/psych/lib/psych/visitors/emitter.rb
===================================================================
--- ruby_1_9_3/ext/psych/lib/psych/visitors/emitter.rb	(revision 36653)
+++ ruby_1_9_3/ext/psych/lib/psych/visitors/emitter.rb	(revision 36654)
@@ -2,10 +2,17 @@
   module Visitors
     class Emitter < Psych::Visitors::Visitor
       def initialize io, options = {}
-        @handler = Psych::Emitter.new io
-        @handler.indentation = options[:indentation] if options[:indentation]
-        @handler.canonical = options[:canonical] if options[:canonical]
-        @handler.line_width = options[:line_width] if options[:line_width]
+        opts = [:indentation, :canonical, :line_width].find_all { |opt|
+          options.key?(opt)
+        }
+
+        if opts.empty?
+          @handler = Psych::Emitter.new io
+        else
+          du = Handler::DumperOptions.new
+          opts.each { |option| du.send :"#{option}=", options[option] }
+          @handler = Psych::Emitter.new io, du
+        end
       end
 
       def visit_Psych_Nodes_Stream o
Index: ruby_1_9_3/ext/psych/lib/psych/json/yaml_events.rb
===================================================================
--- ruby_1_9_3/ext/psych/lib/psych/json/yaml_events.rb	(revision 36653)
+++ ruby_1_9_3/ext/psych/lib/psych/json/yaml_events.rb	(revision 36654)
@@ -10,11 +10,11 @@
       end
 
       def start_mapping anchor, tag, implicit, style
-        super(anchor, nil, implicit, Nodes::Mapping::FLOW)
+        super(anchor, nil, true, Nodes::Mapping::FLOW)
       end
 
       def start_sequence anchor, tag, implicit, style
-        super(anchor, nil, implicit, Nodes::Sequence::FLOW)
+        super(anchor, nil, true, Nodes::Sequence::FLOW)
       end
 
       def scalar value, anchor, tag, plain, quoted, style
Index: ruby_1_9_3/ext/psych/lib/psych.rb
===================================================================
--- ruby_1_9_3/ext/psych/lib/psych.rb	(revision 36653)
+++ ruby_1_9_3/ext/psych/lib/psych.rb	(revision 36654)
@@ -93,7 +93,7 @@
 
 module Psych
   # The version is Psych you're using
-  VERSION         = '1.3.2'
+  VERSION         = '1.3.4'
 
   # The version of libyaml Psych is using
   LIBYAML_VERSION = Psych.libyaml_version.join '.'
Index: ruby_1_9_3/ext/psych/extconf.rb
===================================================================
--- ruby_1_9_3/ext/psych/extconf.rb	(revision 36653)
+++ ruby_1_9_3/ext/psych/extconf.rb	(revision 36654)
@@ -5,7 +5,7 @@
 dir_config 'libyaml'
 
 def asplode missing
-  abort "#{missing} is missing. Please install libyaml."
+  raise "#{missing} is missing. Please install libyaml."
 end
 
 asplode('yaml.h')  unless find_header  'yaml.h'
Index: ruby_1_9_3/ext/psych/emitter.c
===================================================================
--- ruby_1_9_3/ext/psych/emitter.c	(revision 36653)
+++ ruby_1_9_3/ext/psych/emitter.c	(revision 36654)
@@ -2,6 +2,9 @@
 
 VALUE cPsychEmitter;
 static ID id_write;
+static ID id_line_width;
+static ID id_indentation;
+static ID id_canonical;
 
 static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
 {
@@ -39,15 +42,30 @@
     return Data_Wrap_Struct(klass, 0, dealloc, emitter);
 }
 
-/* call-seq: Psych::Emitter.new(io)
+/* call-seq: Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS)
  *
  * Create a new Psych::Emitter that writes to +io+.
  */
-static VALUE initialize(VALUE self, VALUE io)
+static VALUE initialize(int argc, VALUE *argv, VALUE self)
 {
     yaml_emitter_t * emitter;
+    VALUE io, options;
+    VALUE line_width;
+    VALUE indent;
+    VALUE canonical;
+
     Data_Get_Struct(self, yaml_emitter_t, emitter);
 
+    if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
+	line_width = rb_funcall(options, id_line_width, 0);
+	indent     = rb_funcall(options, id_indentation, 0);
+	canonical  = rb_funcall(options, id_canonical, 0);
+
+	yaml_emitter_set_width(emitter, NUM2INT(line_width));
+	yaml_emitter_set_indent(emitter, NUM2INT(indent));
+	yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
+    }
+
     yaml_emitter_set_output(emitter, writer, (void *)io);
 
     return self;
@@ -494,7 +512,7 @@
 
     rb_define_alloc_func(cPsychEmitter, allocate);
 
-    rb_define_method(cPsychEmitter, "initialize", initialize, 1);
+    rb_define_method(cPsychEmitter, "initialize", initialize, -1);
     rb_define_method(cPsychEmitter, "start_stream", start_stream, 1);
     rb_define_method(cPsychEmitter, "end_stream", end_stream, 0);
     rb_define_method(cPsychEmitter, "start_document", start_document, 3);
@@ -512,6 +530,9 @@
     rb_define_method(cPsychEmitter, "line_width", line_width, 0);
     rb_define_method(cPsychEmitter, "line_width=", set_line_width, 1);
 
-    id_write = rb_intern("write");
+    id_write       = rb_intern("write");
+    id_line_width  = rb_intern("line_width");
+    id_indentation = rb_intern("indentation");
+    id_canonical   = rb_intern("canonical");
 }
 /* vim: set noet sws=4 sw=4: */
Index: ruby_1_9_3/ext/psych/parser.c
===================================================================
--- ruby_1_9_3/ext/psych/parser.c	(revision 36653)
+++ ruby_1_9_3/ext/psych/parser.c	(revision 36654)
@@ -79,8 +79,8 @@
 static VALUE transcode_string(VALUE src, int * parser_encoding)
 {
     int utf8    = rb_utf8_encindex();
-    int utf16le = rb_enc_find_index("UTF16_LE");
-    int utf16be = rb_enc_find_index("UTF16_BE");
+    int utf16le = rb_enc_find_index("UTF-16LE");
+    int utf16be = rb_enc_find_index("UTF-16BE");
     int source_encoding = rb_enc_get_index(src);
 
     if (source_encoding == utf8) {
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 36653)
+++ ruby_1_9_3/version.h	(revision 36654)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 258
+#define RUBY_PATCHLEVEL 259
 
 #define RUBY_RELEASE_DATE "2012-07-29"
 #define RUBY_RELEASE_YEAR 2012
Index: ruby_1_9_3/test/psych/test_array.rb
===================================================================
--- ruby_1_9_3/test/psych/test_array.rb	(revision 36653)
+++ ruby_1_9_3/test/psych/test_array.rb	(revision 36654)
@@ -14,6 +14,16 @@
       @list = [{ :a => 'b' }, 'foo']
     end
 
+    def test_another_subclass_with_attributes
+      y = Y.new.tap {|y| y.val = 1}
+      y << "foo" << "bar"
+      y = Psych.load Psych.dump y
+
+      assert_equal %w{foo bar}, y
+      assert_equal Y, y.class
+      assert_equal 1, y.val
+    end
+
     def test_subclass
       yaml = Psych.dump X.new
       assert_match X.name, yaml
Index: ruby_1_9_3/test/psych/test_omap.rb
===================================================================
--- ruby_1_9_3/test/psych/test_omap.rb	(revision 36653)
+++ ruby_1_9_3/test/psych/test_omap.rb	(revision 36654)
@@ -2,6 +2,13 @@
 
 module Psych
   class TestOmap < TestCase
+    def test_parse_as_map
+      o = Psych.load "--- !!omap\na: 1\nb: 2"
+      assert_kind_of Psych::Omap, o
+      assert_equal 1, o['a']
+      assert_equal 2, o['b']
+    end
+
     def test_self_referential
       map = Psych::Omap.new
       map['foo'] = 'bar'
Index: ruby_1_9_3/test/psych/test_alias_and_anchor.rb
===================================================================
--- ruby_1_9_3/test/psych/test_alias_and_anchor.rb	(revision 36653)
+++ ruby_1_9_3/test/psych/test_alias_and_anchor.rb	(revision 36654)
@@ -1,5 +1,13 @@
 require 'psych/helper'
 
+class ObjectWithInstanceVariables
+  attr_accessor :var1, :var2
+end
+
+class SubStringWithInstanceVariables < String
+  attr_accessor :var1
+end
+
 module Psych
  class TestAliasAndAnchor < TestCase
    def test_mri_compatibility
@@ -14,6 +22,40 @@
      result.each {|el| assert_same(result[0], el) }
    end
 
+   def test_mri_compatibility_object_with_ivars
+  yaml = <<EOYAML
+--- 
+- &id001 !ruby/object:ObjectWithInstanceVariables 
+  var1: test1
+  var2: test2
+- *id001
+- *id001
+EOYAML
+
+     result = Psych.load yaml
+     result.each do |el| 
+      assert_same(result[0], el)
+      assert_equal('test1', el.var1)
+      assert_equal('test2', el.var2)
+    end
+   end
+
+   def test_mri_compatibility_substring_with_ivars
+    yaml = <<EOYAML
+--- 
+- &id001 !str:SubStringWithInstanceVariables 
+  str: test
+  "@var1": test
+- *id001
+- *id001
+EOYAML
+     result = Psych.load yaml
+     result.each do |el|
+      assert_same(result[0], el)
+      assert_equal('test', el.var1)
+    end
+   end
+
    def test_anchor_alias_round_trip
      o = Object.new
      original = [o,o,o]
@@ -22,5 +64,33 @@
      result = Psych.load yaml
      result.each {|el| assert_same(result[0], el) }
    end
+
+   def test_anchor_alias_round_trip_object_with_ivars
+     o = ObjectWithInstanceVariables.new
+     o.var1 = 'test1'
+     o.var2 = 'test2'
+     original = [o,o,o]
+
+     yaml = Psych.dump original
+     result = Psych.load yaml
+     result.each do |el|
+      assert_same(result[0], el)
+      assert_equal('test1', el.var1)
+      assert_equal('test2', el.var2)
+    end
+   end
+
+   def test_anchor_alias_round_trip_substring_with_ivars
+     o = SubStringWithInstanceVariables.new
+     o.var1 = 'test'
+     original = [o,o,o]
+
+     yaml = Psych.dump original
+     result = Psych.load yaml
+     result.each do |el|
+      assert_same(result[0], el)
+      assert_equal('test', el.var1)
+    end
+   end
  end
 end
Index: ruby_1_9_3/test/psych/test_string.rb
===================================================================
--- ruby_1_9_3/test/psych/test_string.rb	(revision 36653)
+++ ruby_1_9_3/test/psych/test_string.rb	(revision 36654)
@@ -9,6 +9,13 @@
       attr_accessor :val
     end
 
+    def test_another_subclass_with_attributes
+      y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
+      assert_equal "foo", y
+      assert_equal Y, y.class
+      assert_equal 1, y.val
+    end
+
     def test_backwards_with_syck
       x = Psych.load "--- !str:#{X.name} foo\n\n"
       assert_equal X, x.class

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]