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

ruby-changes:60324

From: nagachika <ko1@a...>
Date: Sat, 7 Mar 2020 19:04:03 +0900 (JST)
Subject: [ruby-changes:60324] 7c9bd12af5 (ruby_2_6): merge revision(s) 77596fb7a91cc119b25ac9e19b3c8682709765b4: [Backport #16138]

https://git.ruby-lang.org/ruby.git/commit/?id=7c9bd12af5

From 7c9bd12af58e712f08a9808246bfa5c28e5bc854 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Sat, 7 Mar 2020 10:03:51 +0000
Subject: merge revision(s) 77596fb7a91cc119b25ac9e19b3c8682709765b4: [Backport
 #16138]

	Do not turn on keyword_init for Struct subclass if keyword hash is
	 empty

	This was accidentally turned on because there was no checking for
	Qundef.

	Also, since only a single keyword is currently supported, simplify
	the rb_get_kwargs call.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

diff --git a/struct.c b/struct.c
index c0cef33..f34882e 100644
--- a/struct.c
+++ b/struct.c
@@ -516,7 +516,7 @@ rb_struct_define_under(VALUE outer, const char *name, ...) https://github.com/ruby/ruby/blob/trunk/struct.c#L516
 static VALUE
 rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
 {
-    VALUE name, rest, keyword_init;
+    VALUE name, rest, keyword_init = Qfalse;
     long i;
     VALUE st;
     st_table *tbl;
@@ -532,18 +532,16 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass) https://github.com/ruby/ruby/blob/trunk/struct.c#L532
     }
 
     if (RB_TYPE_P(argv[argc-1], T_HASH)) {
-	VALUE kwargs[1];
 	static ID keyword_ids[1];
 
 	if (!keyword_ids[0]) {
 	    keyword_ids[0] = rb_intern("keyword_init");
 	}
-	rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, kwargs);
+        rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, &keyword_init);
+        if (keyword_init == Qundef) {
+            keyword_init = Qfalse;
+        }
 	--argc;
-	keyword_init = kwargs[0];
-    }
-    else {
-	keyword_init = Qfalse;
     }
 
     rest = rb_ident_hash_new();
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb
index 4748419..0046e9b 100644
--- a/test/ruby/test_struct.rb
+++ b/test/ruby/test_struct.rb
@@ -92,6 +92,10 @@ module TestStruct https://github.com/ruby/ruby/blob/trunk/test/ruby/test_struct.rb#L92
     assert_equal([:utime, :stime, :cutime, :cstime], Process.times.members)
   end
 
+  def test_struct_new_with_empty_hash
+    assert_equal({:a=>1}, Struct.new(:a, {}).new({:a=>1}).a)
+  end
+
   def test_struct_new_with_keyword_init
     @Struct.new("KeywordInitTrue", :a, :b, keyword_init: true)
     @Struct.new("KeywordInitFalse", :a, :b, keyword_init: false)
diff --git a/version.h b/version.h
index 52ec4e4..33ca92c 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.6"
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 128
+#define RUBY_PATCHLEVEL 129
 
 #define RUBY_RELEASE_YEAR 2020
 #define RUBY_RELEASE_MONTH 3
-- 
cgit v0.10.2


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

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