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

ruby-changes:26295

From: naruse <ko1@a...>
Date: Wed, 12 Dec 2012 19:52:02 +0900 (JST)
Subject: [ruby-changes:26295] naruse:r38346 (trunk): * ext/json: merge JSON 1.7.5.

naruse	2012-12-12 19:51:49 +0900 (Wed, 12 Dec 2012)

  New Revision: 38346

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

  Log:
    * ext/json: merge JSON 1.7.5.
      fix tests and other fixes.

  Added files:
    trunk/test/json/test_json_generic_object.rb
  Modified files:
    trunk/ChangeLog
    trunk/ext/json/fbuffer/fbuffer.h
    trunk/ext/json/generator/depend
    trunk/ext/json/generator/generator.c
    trunk/ext/json/generator/generator.h
    trunk/ext/json/lib/json/add/time.rb
    trunk/ext/json/lib/json/common.rb
    trunk/ext/json/lib/json/version.rb
    trunk/ext/json/parser/depend
    trunk/test/json/test_json_addition.rb
    trunk/test/json/test_json_string_matching.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38345)
+++ ChangeLog	(revision 38346)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 12 19:48:59 2012  NARUSE, Yui  <naruse@r...>
+
+	* ext/json: merge JSON 1.7.5.
+	  fix tests and other fixes.
+
 Wed Dec 12 18:30:29 2012  Shugo Maeda  <shugo@r...>
 
 	* class.c (rb_prepend_module): move refined methods from the origin
Index: ext/json/fbuffer/fbuffer.h
===================================================================
--- ext/json/fbuffer/fbuffer.h	(revision 38345)
+++ ext/json/fbuffer/fbuffer.h	(revision 38346)
@@ -5,6 +5,27 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/fbuffer/fbuffer.h#L5
 #include "ruby.h"
 #include <assert.h>
 
+#ifndef RHASH_SIZE
+#define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries)
+#endif
+
+#ifndef RFLOAT_VALUE
+#define RFLOAT_VALUE(val) (RFLOAT(val)->value)
+#endif
+
+#ifndef RARRAY_PTR
+#define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
+#endif
+#ifndef RARRAY_LEN
+#define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
+#endif
+#ifndef RSTRING_PTR
+#define RSTRING_PTR(string) RSTRING(string)->ptr
+#endif
+#ifndef RSTRING_LEN
+#define RSTRING_LEN(string) RSTRING(string)->len
+#endif
+
 #ifdef HAVE_RUBY_ENCODING_H
 #include "ruby/encoding.h"
 #define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
Index: ext/json/generator/depend
===================================================================
--- ext/json/generator/depend	(revision 38345)
+++ ext/json/generator/depend	(revision 38346)
@@ -1 +1 @@
-generator.o: generator.c generator.h $(srcdir)/../fbuffer/fbuffer.h $(ruby_headers)
+generator.o: generator.c generator.h $(srcdir)/../fbuffer/fbuffer.h
Index: ext/json/generator/generator.c
===================================================================
--- ext/json/generator/generator.c	(revision 38345)
+++ ext/json/generator/generator.c	(revision 38346)
@@ -864,7 +864,7 @@ static int isArrayOrObject(VALUE string) https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L864
     if (string_len < 2) return 0;
     for (; p < q && isspace(*p); p++);
     for (; q > p && isspace(*q); q--);
-    return *p == '[' && *q == ']' || *p == '{' && *q == '}';
+    return (*p == '[' && *q == ']') || (*p == '{' && *q == '}');
 }
 
 /*
Index: ext/json/generator/generator.h
===================================================================
--- ext/json/generator/generator.h	(revision 38345)
+++ ext/json/generator/generator.h	(revision 38346)
@@ -16,27 +16,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.h#L16
 
 #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
 
-#ifndef RHASH_SIZE
-#define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries)
-#endif
-
-#ifndef RFLOAT_VALUE
-#define RFLOAT_VALUE(val) (RFLOAT(val)->value)
-#endif
-
-#ifndef RARRAY_PTR
-#define RARRAY_PTR(ARRAY) RARRAY(ARRAY)->ptr
-#endif
-#ifndef RARRAY_LEN
-#define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
-#endif
-#ifndef RSTRING_PTR
-#define RSTRING_PTR(string) RSTRING(string)->ptr
-#endif
-#ifndef RSTRING_LEN
-#define RSTRING_LEN(string) RSTRING(string)->len
-#endif
-
 /* unicode defintions */
 
 #define UNI_STRICT_CONVERSION 1
Index: ext/json/lib/json/version.rb
===================================================================
--- ext/json/lib/json/version.rb	(revision 38345)
+++ ext/json/lib/json/version.rb	(revision 38346)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/version.rb#L1
 module JSON
   # JSON version
-  VERSION         = '1.7.1'
+  VERSION         = '1.7.5'
   VERSION_ARRAY   = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
   VERSION_MAJOR   = VERSION_ARRAY[0] # :nodoc:
   VERSION_MINOR   = VERSION_ARRAY[1] # :nodoc:
Index: ext/json/lib/json/add/time.rb
===================================================================
--- ext/json/lib/json/add/time.rb	(revision 38345)
+++ ext/json/lib/json/add/time.rb	(revision 38346)
@@ -20,10 +20,13 @@ class Time https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/add/time.rb#L20
   # Returns a hash, that will be turned into a JSON object and represent this
   # object.
   def as_json(*)
+    nanoseconds = [ tv_usec * 1000 ]
+    respond_to?(:tv_nsec) and nanoseconds << tv_nsec
+    nanoseconds = nanoseconds.max
     {
       JSON.create_id => self.class.name,
       's'            => tv_sec,
-      'n'            => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
+      'n'            => nanoseconds,
     }
   end
 
Index: ext/json/lib/json/common.rb
===================================================================
--- ext/json/lib/json/common.rb	(revision 38345)
+++ ext/json/lib/json/common.rb	(revision 38346)
@@ -103,7 +103,13 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L103
   MinusInfinity = -Infinity
 
   # The base exception for JSON errors.
-  class JSONError < StandardError; end
+  class JSONError < StandardError
+    def self.wrap(exception)
+      obj = new("Wrapped(#{exception.class}): #{exception.message.inspect}")
+      obj.set_backtrace exception.backtrace
+      obj
+    end
+  end
 
   # This exception is raised if a parser error occurs.
   class ParserError < JSONError; end
@@ -399,7 +405,10 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L405
   end
 
   # Shortuct for iconv.
-  if ::String.method_defined?(:encode)
+  if ::String.method_defined?(:encode) &&
+    # XXX Rubinius doesn't support ruby 1.9 encoding yet
+    defined?(RUBY_ENGINE) && RUBY_ENGINE != 'rbx'
+  then
     # Encodes string using Ruby's _String.encode_
     def self.iconv(to, from, string)
       string.encode(to, from)
Index: ext/json/parser/depend
===================================================================
--- ext/json/parser/depend	(revision 38345)
+++ ext/json/parser/depend	(revision 38346)
@@ -1 +1 @@
-parser.o: parser.c parser.h $(srcdir)/../fbuffer/fbuffer.h $(ruby_headers)
+parser.o: parser.c parser.h $(srcdir)/../fbuffer/fbuffer.h
Index: test/json/test_json_addition.rb
===================================================================
--- test/json/test_json_addition.rb	(revision 38345)
+++ test/json/test_json_addition.rb	(revision 38346)
@@ -119,7 +119,7 @@ class TestJSONAddition < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/json/test_json_addition.rb#L119
     json_raw_object = raw.to_json_raw_object
     hash = { 'json_class' => 'String', 'raw'=> raw_array }
     assert_equal hash, json_raw_object
-    assert_match(/\A\{.*\}\Z/, json)
+    assert_match(/\A\{.*\}\z/, json)
     assert_match(/"json_class":"String"/, json)
     assert_match(/"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json)
     raw_again = JSON.parse(json)
Index: test/json/test_json_string_matching.rb
===================================================================
--- test/json/test_json_string_matching.rb	(revision 38345)
+++ test/json/test_json_string_matching.rb	(revision 38346)
@@ -28,13 +28,13 @@ class TestJSONStringMatching < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/json/test_json_string_matching.rb#L28
     t_json = [ t ].to_json
     assert_equal [ t ],
       JSON.parse(t_json,
-        :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
+        :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
     assert_equal [ t.strftime('%FT%T%z') ],
       JSON.parse(t_json,
-        :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
+        :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
     assert_equal [ t.strftime('%FT%T%z') ],
       JSON.parse(t_json,
-        :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime },
+        :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime },
         :create_additions => false)
   end
 end
Index: test/json/test_json_generic_object.rb
===================================================================
--- test/json/test_json_generic_object.rb	(revision 0)
+++ test/json/test_json_generic_object.rb	(revision 38346)
@@ -0,0 +1,35 @@ https://github.com/ruby/ruby/blob/trunk/test/json/test_json_generic_object.rb#L1
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+
+require 'test/unit'
+require File.join(File.dirname(__FILE__), 'setup_variant')
+class TestJSONGenericObject < Test::Unit::TestCase
+  include JSON
+
+  def setup
+    @go = GenericObject[ :a => 1, :b => 2 ]
+  end
+
+  def test_attributes
+    assert_equal 1, @go.a
+    assert_equal 1, @go[:a]
+    assert_equal 2, @go.b
+    assert_equal 2, @go[:b]
+    assert_nil @go.c
+    assert_nil @go[:c]
+  end
+
+  def test_generate_json
+    assert_equal @go, JSON(JSON(@go))
+  end
+
+  def test_parse_json
+    assert_equal @go, l = JSON('{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }')
+    assert_equal 1, l.a
+    assert_equal @go, l = JSON('{ "a": 1, "b": 2 }', :object_class => GenericObject)
+    assert_equal 1, l.a
+    assert_equal GenericObject[:a => GenericObject[:b => 2]],
+      l = JSON('{ "a": { "b": 2 } }', :object_class => GenericObject)
+    assert_equal 2, l.a.b
+  end
+end

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

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