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

ruby-changes:67547

From: Nobuyoshi <ko1@a...>
Date: Thu, 2 Sep 2021 09:12:32 +0900 (JST)
Subject: [ruby-changes:67547] ab63f6d854 (master): Refined test [Bug #18140]

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

From ab63f6d8543903f177c46634f38e5428655f003b Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 2 Sep 2021 09:11:41 +0900
Subject: Refined test [Bug #18140]

---
 ext/-test-/array/concat/to_ary_conact.c | 48 +++++++--------------------------
 test/ruby/test_array.rb                 |  5 +++-
 2 files changed, 13 insertions(+), 40 deletions(-)

diff --git a/ext/-test-/array/concat/to_ary_conact.c b/ext/-test-/array/concat/to_ary_conact.c
index a61659a..ec1fd32 100644
--- a/ext/-test-/array/concat/to_ary_conact.c
+++ b/ext/-test-/array/concat/to_ary_conact.c
@@ -1,63 +1,33 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/array/concat/to_ary_conact.c#L1
 #include "ruby.h"
 
-VALUE cFoo;
-
-// Foo
-
-typedef struct {
-    int dummy;
-} Foo;
-
-static void Foo_free(void* _self) {
-    xfree(_self);
-}
-
-static rb_data_type_t Foo_type = {
-    "Foo",
-    {NULL, Foo_free, NULL },
-    .flags = RUBY_TYPED_FREE_IMMEDIATELY,
-};
-
-static VALUE Foo_alloc(VALUE klass) {
-    Foo* _self = ALLOC(Foo);
-    return TypedData_Wrap_Struct(klass, &Foo_type, _self);
-}
-
 // Bar
 
 typedef struct {
     int dummy;
 } Bar;
 
-static void Bar_free(void* _self) {
-    xfree(_self);
-}
-
 static rb_data_type_t Bar_type = {
     "Bar",
-    {NULL, Bar_free, NULL },
-    .flags = RUBY_TYPED_FREE_IMMEDIATELY,
+    {NULL, RUBY_TYPED_DEFAULT_FREE, NULL },
 };
 
-static VALUE Bar_alloc(VALUE klass) {
-    Bar* bar = ALLOC(Bar);
-    return TypedData_Wrap_Struct(klass, &Bar_type, bar);
+static VALUE
+Bar_alloc(VALUE klass)
+{
+    return TypedData_Wrap_Struct(klass, &Bar_type, NULL);
 }
 
 VALUE Bar_to_ary(VALUE _self) {
     VALUE ary = rb_ary_new2(2);
-    rb_ary_push(ary, Foo_alloc(cFoo));
-    rb_ary_push(ary, Foo_alloc(cFoo));
-    rb_ary_push(ary, Foo_alloc(cFoo));
+    VALUE foo = rb_ary_new2(0);
+    rb_ary_push(ary, foo);
+    rb_ary_push(ary, foo);
+    rb_ary_push(ary, foo);
     return ary;
 }
 
 void Init_to_ary_concat() {
     VALUE mBug = rb_define_module("Bug");
-    cFoo = rb_define_class_under(mBug, "Foo", rb_cObject);
-    rb_gc_register_address(&cFoo);
-    rb_define_alloc_func(cFoo, Foo_alloc);
-
     VALUE bar = rb_define_class_under(mBug, "Bar", rb_cObject);
     rb_define_alloc_func(bar, Bar_alloc);
     rb_define_method(bar, "to_ary", Bar_to_ary, 0);
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 4cb4904..a97a9c2 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -656,7 +656,10 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L656
     assert_raise(FrozenError) { @cls[0].freeze.concat(:foo) }
 
     a = @cls[nil]
-    def (x = Object.new).to_ary; Array.new(10) {nil} << :ok; end
+    def (x = Object.new).to_ary
+      ary = Array.new(2)
+      ary << [] << [] << :ok
+    end
     EnvUtil.under_gc_stress {a.concat(x)}
     GC.start
     assert_equal(:ok, a.last)
-- 
cgit v1.1


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

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