ruby-changes:64810
From: Nobuyoshi <ko1@a...>
Date: Sat, 9 Jan 2021 22:38:21 +0900 (JST)
Subject: [ruby-changes:64810] 590dc06e38 (master): Get rid of defining methods for tests in core classes
https://git.ruby-lang.org/ruby.git/commit/?id=590dc06e38 From 590dc06e3840cc7b00d80ccaac9fbf42573428f8 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 8 Jan 2021 19:07:16 +0900 Subject: Get rid of defining methods for tests in core classes Not to interfere in other tests. diff --git a/ext/-test-/array/resize/resize.c b/ext/-test-/array/resize/resize.c index 08bcee3..cfe910e 100644 --- a/ext/-test-/array/resize/resize.c +++ b/ext/-test-/array/resize/resize.c @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/array/resize/resize.c#L1 #include "ruby/ruby.h" static VALUE -ary_resize(VALUE ary, VALUE len) +ary_resize(VALUE klass, VALUE ary, VALUE len) { rb_ary_resize(ary, NUM2LONG(len)); return ary; @@ -10,5 +10,7 @@ ary_resize(VALUE ary, VALUE len) https://github.com/ruby/ruby/blob/trunk/ext/-test-/array/resize/resize.c#L10 void Init_resize(void) { - rb_define_method(rb_cArray, "__resize__", ary_resize, 1); + VALUE mBug = rb_define_module("Bug"); + VALUE klass = rb_define_class_under(mBug, "Array", rb_cObject); + rb_define_singleton_method(klass, "__resize__", ary_resize, 2); } diff --git a/ext/-test-/bignum/big2str.c b/ext/-test-/bignum/big2str.c index bc5a933..255e8ad 100644 --- a/ext/-test-/bignum/big2str.c +++ b/ext/-test-/bignum/big2str.c @@ -12,7 +12,7 @@ big(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/big2str.c#L12 } static VALUE -big2str_generic(VALUE x, VALUE vbase) +big2str_generic(VALUE klass, VALUE x, VALUE vbase) { int base = NUM2INT(vbase); if (base < 2 || 36 < base) @@ -23,7 +23,7 @@ big2str_generic(VALUE x, VALUE vbase) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/big2str.c#L23 #define POW2_P(x) (((x)&((x)-1))==0) static VALUE -big2str_poweroftwo(VALUE x, VALUE vbase) +big2str_poweroftwo(VALUE klass, VALUE x, VALUE vbase) { int base = NUM2INT(vbase); if (base < 2 || 36 < base || !POW2_P(base)) @@ -33,7 +33,7 @@ big2str_poweroftwo(VALUE x, VALUE vbase) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/big2str.c#L33 #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H) static VALUE -big2str_gmp(VALUE x, VALUE vbase) +big2str_gmp(VALUE klass, VALUE x, VALUE vbase) { int base = NUM2INT(vbase); if (base < 2 || 36 < base) @@ -47,7 +47,7 @@ big2str_gmp(VALUE x, VALUE vbase) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/big2str.c#L47 void Init_big2str(VALUE klass) { - rb_define_method(rb_cInteger, "big2str_generic", big2str_generic, 1); - rb_define_method(rb_cInteger, "big2str_poweroftwo", big2str_poweroftwo, 1); - rb_define_method(rb_cInteger, "big2str_gmp", big2str_gmp, 1); + rb_define_singleton_method(klass, "big2str_generic", big2str_generic, 2); + rb_define_singleton_method(klass, "big2str_poweroftwo", big2str_poweroftwo, 2); + rb_define_singleton_method(klass, "big2str_gmp", big2str_gmp, 2); } diff --git a/ext/-test-/bignum/div.c b/ext/-test-/bignum/div.c index 2be0d2d..85ee067 100644 --- a/ext/-test-/bignum/div.c +++ b/ext/-test-/bignum/div.c @@ -12,14 +12,14 @@ big(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/div.c#L12 } static VALUE -divrem_normal(VALUE x, VALUE y) +divrem_normal(VALUE klass, VALUE x, VALUE y) { return rb_big_norm(rb_big_divrem_normal(big(x), big(y))); } #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H) static VALUE -divrem_gmp(VALUE x, VALUE y) +divrem_gmp(VALUE klass, VALUE x, VALUE y) { return rb_big_norm(rb_big_divrem_gmp(big(x), big(y))); } @@ -30,6 +30,6 @@ divrem_gmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/div.c#L30 void Init_div(VALUE klass) { - rb_define_method(rb_cInteger, "big_divrem_normal", divrem_normal, 1); - rb_define_method(rb_cInteger, "big_divrem_gmp", divrem_gmp, 1); + rb_define_singleton_method(klass, "big_divrem_normal", divrem_normal, 2); + rb_define_singleton_method(klass, "big_divrem_gmp", divrem_gmp, 2); } diff --git a/ext/-test-/bignum/intpack.c b/ext/-test-/bignum/intpack.c index 698362f..d559150 100644 --- a/ext/-test-/bignum/intpack.c +++ b/ext/-test-/bignum/intpack.c @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/intpack.c#L1 #include "internal/bignum.h" static VALUE -rb_integer_pack_raw_m(VALUE val, VALUE buf, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags) +rb_integer_pack_raw_m(VALUE klass, VALUE val, VALUE buf, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags) { int sign; size_t numwords = 0; @@ -17,7 +17,7 @@ rb_integer_pack_raw_m(VALUE val, VALUE buf, VALUE numwords_arg, VALUE wordsize_a https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/intpack.c#L17 } static VALUE -rb_integer_pack_m(VALUE val, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags) +rb_integer_pack_m(VALUE klass, VALUE val, VALUE numwords_arg, VALUE wordsize_arg, VALUE nails, VALUE flags) { int sign; size_t numwords = NUM2SIZET(numwords_arg); @@ -45,7 +45,7 @@ rb_integer_unpack_m(VALUE klass, VALUE buf, VALUE numwords, VALUE wordsize, VALU https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/intpack.c#L45 } static VALUE -rb_integer_test_numbits_2comp_without_sign(VALUE val) +rb_integer_test_numbits_2comp_without_sign(VALUE klass, VALUE val) { size_t size; int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val); @@ -54,7 +54,7 @@ rb_integer_test_numbits_2comp_without_sign(VALUE val) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/intpack.c#L54 } static VALUE -rb_integer_test_numbytes_2comp_with_sign(VALUE val) +rb_integer_test_numbytes_2comp_with_sign(VALUE klass, VALUE val) { int neg = FIXNUM_P(val) ? FIX2LONG(val) < 0 : BIGNUM_NEGATIVE_P(val); int nlz_bits; @@ -67,21 +67,21 @@ rb_integer_test_numbytes_2comp_with_sign(VALUE val) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/intpack.c#L67 void Init_intpack(VALUE klass) { - rb_define_method(rb_cInteger, "test_pack_raw", rb_integer_pack_raw_m, 5); - rb_define_method(rb_cInteger, "test_pack", rb_integer_pack_m, 4); - rb_define_singleton_method(rb_cInteger, "test_unpack", rb_integer_unpack_m, 5); - rb_define_const(rb_cInteger, "INTEGER_PACK_MSWORD_FIRST", INT2NUM(INTEGER_PACK_MSWORD_FIRST)); - rb_define_const(rb_cInteger, "INTEGER_PACK_LSWORD_FIRST", INT2NUM(INTEGER_PACK_LSWORD_FIRST)); - rb_define_const(rb_cInteger, "INTEGER_PACK_MSBYTE_FIRST", INT2NUM(INTEGER_PACK_MSBYTE_FIRST)); - rb_define_const(rb_cInteger, "INTEGER_PACK_LSBYTE_FIRST", INT2NUM(INTEGER_PACK_LSBYTE_FIRST)); - rb_define_const(rb_cInteger, "INTEGER_PACK_NATIVE_BYTE_ORDER", INT2NUM(INTEGER_PACK_NATIVE_BYTE_ORDER)); - rb_define_const(rb_cInteger, "INTEGER_PACK_2COMP", INT2NUM(INTEGER_PACK_2COMP)); - rb_define_const(rb_cInteger, "INTEGER_PACK_LITTLE_ENDIAN", INT2NUM(INTEGER_PACK_LITTLE_ENDIAN)); - rb_define_const(rb_cInteger, "INTEGER_PACK_BIG_ENDIAN", INT2NUM(INTEGER_PACK_BIG_ENDIAN)); - rb_define_const(rb_cInteger, "INTEGER_PACK_FORCE_BIGNUM", INT2NUM(INTEGER_PACK_FORCE_BIGNUM)); - rb_define_const(rb_cInteger, "INTEGER_PACK_NEGATIVE", INT2NUM(INTEGER_PACK_NEGATIVE)); - rb_define_const(rb_cInteger, "INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION", INT2NUM(INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION)); + rb_define_singleton_method(klass, "test_pack_raw", rb_integer_pack_raw_m, 6); + rb_define_singleton_method(klass, "test_pack", rb_integer_pack_m, 5); + rb_define_singleton_method(klass, "test_unpack", rb_integer_unpack_m, 5); + rb_define_const(klass, "INTEGER_PACK_MSWORD_FIRST", INT2NUM(INTEGER_PACK_MSWORD_FIRST)); + rb_define_const(klass, "INTEGER_PACK_LSWORD_FIRST", INT2NUM(INTEGER_PACK_LSWORD_FIRST)); + rb_define_const(klass, "INTEGER_PACK_MSBYTE_FIRST", INT2NUM(INTEGER_PACK_MSBYTE_FIRST)); + rb_define_const(klass, "INTEGER_PACK_LSBYTE_FIRST", INT2NUM(INTEGER_PACK_LSBYTE_FIRST)); + rb_define_const(klass, "INTEGER_PACK_NATIVE_BYTE_ORDER", INT2NUM(INTEGER_PACK_NATIVE_BYTE_ORDER)); + rb_define_const(klass, "INTEGER_PACK_2COMP", INT2NUM(INTEGER_PACK_2COMP)); + rb_define_const(klass, "INTEGER_PACK_LITTLE_ENDIAN", INT2NUM(INTEGER_PACK_LITTLE_ENDIAN)); + rb_define_const(klass, "INTEGER_PACK_BIG_ENDIAN", INT2NUM(INTEGER_PACK_BIG_ENDIAN)); + rb_define_const(klass, "INTEGER_PACK_FORCE_BIGNUM", INT2NUM(INTEGER_PACK_FORCE_BIGNUM)); + rb_define_const(klass, "INTEGER_PACK_NEGATIVE", INT2NUM(INTEGER_PACK_NEGATIVE)); + rb_define_const(klass, "INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION", INT2NUM(INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION)); - rb_define_method(rb_cInteger, "test_numbits_2comp_without_sign", rb_integer_test_numbits_2comp_without_sign, 0); - rb_define_method(rb_cInteger, "test_numbytes_2comp_with_sign", rb_integer_test_numbytes_2comp_with_sign, 0); + rb_define_singleton_method(klass, "test_numbits_2comp_without_sign", rb_integer_test_numbits_2comp_without_sign, 1); + rb_define_singleton_method(klass, "test_numbytes_2comp_with_sign", rb_integer_test_numbytes_2comp_with_sign, 1); } diff --git a/ext/-test-/bignum/mul.c b/ext/-test-/bignum/mul.c index 1b6eb91..05ba103 100644 --- a/ext/-test-/bignum/mul.c +++ b/ext/-test-/bignum/mul.c @@ -12,38 +12,38 @@ big(VALUE x) https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/mul.c#L12 } static VALUE -mul_normal(VALUE x, VALUE y) +mul_normal(VALUE klass, VALUE x, VALUE y) { return rb_big_norm(rb_big_mul_normal(big(x), big(y))); } static VALUE -sq_fast(VALUE x) +sq_fast(VALUE klass, VALUE x) { return rb_big_norm(rb_big_sq_fast(big(x))); } static VALUE -mul_balance(VALUE x, VALUE y) +mul_balance(VALUE klass, VALUE x, VALUE y) { return rb_big_norm(rb_big_mul_balance(big(x), big(y))); } static VALUE -mul_karatsuba(VALUE x, VALUE y) +mul_karatsuba(VALUE klass, VALUE x, VALUE y) { return rb_big_norm(rb_big_mul_karatsuba(big(x), big(y))); } static VALUE -mul_toom3(VALUE x, VALUE y) +mul_toom3(VALUE klass, (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/