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

ruby-changes:37366

From: usa <ko1@a...>
Date: Fri, 30 Jan 2015 16:43:32 +0900 (JST)
Subject: [ruby-changes:37366] usa:r49447 (ruby_2_0_0): merge revision(s) 48803: [Backport #10568]

usa	2015-01-30 16:42:52 +0900 (Fri, 30 Jan 2015)

  New Revision: 49447

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

  Log:
    merge revision(s) 48803: [Backport #10568]
    
    * pack.c (str_associate, str_associated): keep associated objects
      in an instance variables, instead of in the internal structure.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/pack.c
    branches/ruby_2_0_0/test/ruby/test_pack.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 49446)
+++ ruby_2_0_0/ChangeLog	(revision 49447)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Fri Jan 30 16:26:57 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* pack.c (str_associate, str_associated): keep associated objects
+	  in an instance variables, instead of in the internal structure.
+
 Fri Jan 30 16:11:47 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/rdoc/text.rb (expand_tabs): get rid of infinite loop with
Index: ruby_2_0_0/pack.c
===================================================================
--- ruby_2_0_0/pack.c	(revision 49446)
+++ ruby_2_0_0/pack.c	(revision 49447)
@@ -261,6 +261,31 @@ static void qpencode(VALUE,VALUE,long); https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/pack.c#L261
 
 static unsigned long utf8_to_uv(const char*,long*);
 
+static ID id_associated;
+
+static void
+str_associate(VALUE str, VALUE add)
+{
+    VALUE assoc;
+
+    assoc = rb_attr_get(str, id_associated);
+    if (RB_TYPE_P(assoc, T_ARRAY)) {
+	/* already associated */
+	rb_ary_concat(assoc, add);
+    }
+    else {
+	rb_ivar_set(str, id_associated, add);
+    }
+}
+
+static VALUE
+str_associated(VALUE str)
+{
+    VALUE assoc = rb_attr_get(str, id_associated);
+    if (NIL_P(assoc)) assoc = Qfalse;
+    return assoc;
+}
+
 /*
  *  call-seq:
  *     arr.pack ( aTemplateString ) -> aBinaryString
@@ -1038,7 +1063,7 @@ pack_pack(VALUE ary, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/pack.c#L1063
     }
 
     if (associates) {
-	rb_str_associate(res, associates);
+	str_associate(res, associates);
     }
     OBJ_INFECT(res, fmt);
     switch (enc_info) {
@@ -2055,7 +2080,7 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/pack.c#L2080
 		if (t) {
 		    VALUE a, *p, *pend;
 
-		    if (!(a = rb_str_associated(str))) {
+		    if (!(a = str_associated(str))) {
 			rb_raise(rb_eArgError, "no associated pointer");
 		    }
 		    p = RARRAY_PTR(a);
@@ -2064,7 +2089,7 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/pack.c#L2089
 			if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {
 			    if (len < RSTRING_LEN(*p)) {
 				tmp = rb_tainted_str_new(t, len);
-				rb_str_associate(tmp, a);
+				str_associate(tmp, a);
 			    }
 			    else {
 				tmp = *p;
@@ -2097,7 +2122,7 @@ pack_unpack(VALUE str, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/pack.c#L2122
 		    if (t) {
 			VALUE a, *p, *pend;
 
-			if (!(a = rb_str_associated(str))) {
+			if (!(a = str_associated(str))) {
 			    rb_raise(rb_eArgError, "no associated pointer");
 			}
 			p = RARRAY_PTR(a);
@@ -2273,4 +2298,6 @@ Init_pack(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/pack.c#L2298
 {
     rb_define_method(rb_cArray, "pack", pack_pack, 1);
     rb_define_method(rb_cString, "unpack", pack_unpack, 1);
+
+    id_associated = rb_intern_const("__pack_associated__");
 }
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 49446)
+++ ruby_2_0_0/version.h	(revision 49447)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2015-01-30"
-#define RUBY_PATCHLEVEL 627
+#define RUBY_PATCHLEVEL 628
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 1
Index: ruby_2_0_0/test/ruby/test_pack.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_pack.rb	(revision 49446)
+++ ruby_2_0_0/test/ruby/test_pack.rb	(revision 49447)
@@ -181,7 +181,7 @@ class TestPack < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_pack.rb#L181
     assert_equal a[0], a.pack("p").unpack("p")[0]
     assert_equal a, a.pack("p").freeze.unpack("p*")
     assert_raise(ArgumentError) { (a.pack("p") + "").unpack("p*") }
-    assert_raise(ArgumentError) { (a.pack("p") << "d").unpack("p*") }
+    assert_equal a, (a.pack("p") << "d").unpack("p*")
   end
 
   def test_format_string_modified

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44804


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

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