summaryrefslogtreecommitdiff
path: root/ext/-test-/bignum
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-08 19:07:16 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-09 22:38:06 +0900
commit590dc06e3840cc7b00d80ccaac9fbf42573428f8 (patch)
treee5f6aa316246401b8d89e7419ddf0976238c04b5 /ext/-test-/bignum
parent161a20df28dd09ff35a32a7e2b7ce6cab7079707 (diff)
Get rid of defining methods for tests in core classes
Not to interfere in other tests.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4043
Diffstat (limited to 'ext/-test-/bignum')
-rw-r--r--ext/-test-/bignum/big2str.c12
-rw-r--r--ext/-test-/bignum/div.c8
-rw-r--r--ext/-test-/bignum/intpack.c40
-rw-r--r--ext/-test-/bignum/mul.c28
-rw-r--r--ext/-test-/bignum/str2big.c16
5 files changed, 52 insertions, 52 deletions
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)
}
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)
#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)
#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)
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)
}
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)
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 @@
#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
}
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
}
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)
}
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)
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)
}
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, VALUE x, VALUE y)
{
return rb_big_norm(rb_big_mul_toom3(big(x), big(y)));
}
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
static VALUE
-mul_gmp(VALUE x, VALUE y)
+mul_gmp(VALUE klass, VALUE x, VALUE y)
{
return rb_big_norm(rb_big_mul_gmp(big(x), big(y)));
}
@@ -54,12 +54,12 @@ mul_gmp(VALUE x, VALUE y)
void
Init_mul(VALUE klass)
{
- rb_define_const(rb_cInteger, "SIZEOF_BDIGIT", INT2NUM(SIZEOF_BDIGIT));
- rb_define_const(rb_cInteger, "BITSPERDIG", INT2NUM(SIZEOF_BDIGIT * CHAR_BIT));
- rb_define_method(rb_cInteger, "big_mul_normal", mul_normal, 1);
- rb_define_method(rb_cInteger, "big_sq_fast", sq_fast, 0);
- rb_define_method(rb_cInteger, "big_mul_balance", mul_balance, 1);
- rb_define_method(rb_cInteger, "big_mul_karatsuba", mul_karatsuba, 1);
- rb_define_method(rb_cInteger, "big_mul_toom3", mul_toom3, 1);
- rb_define_method(rb_cInteger, "big_mul_gmp", mul_gmp, 1);
+ rb_define_const(klass, "SIZEOF_BDIGIT", INT2NUM(SIZEOF_BDIGIT));
+ rb_define_const(klass, "BITSPERDIG", INT2NUM(SIZEOF_BDIGIT * CHAR_BIT));
+ rb_define_singleton_method(klass, "big_mul_normal", mul_normal, 2);
+ rb_define_singleton_method(klass, "big_sq_fast", sq_fast, 1);
+ rb_define_singleton_method(klass, "big_mul_balance", mul_balance, 2);
+ rb_define_singleton_method(klass, "big_mul_karatsuba", mul_karatsuba, 2);
+ rb_define_singleton_method(klass, "big_mul_toom3", mul_toom3, 2);
+ rb_define_singleton_method(klass, "big_mul_gmp", mul_gmp, 2);
}
diff --git a/ext/-test-/bignum/str2big.c b/ext/-test-/bignum/str2big.c
index 7dd2da9..337cf8f 100644
--- a/ext/-test-/bignum/str2big.c
+++ b/ext/-test-/bignum/str2big.c
@@ -1,26 +1,26 @@
#include "internal/bignum.h"
static VALUE
-str2big_poweroftwo(VALUE str, VALUE vbase, VALUE badcheck)
+str2big_poweroftwo(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
{
return rb_str2big_poweroftwo(str, NUM2INT(vbase), RTEST(badcheck));
}
static VALUE
-str2big_normal(VALUE str, VALUE vbase, VALUE badcheck)
+str2big_normal(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
{
return rb_str2big_normal(str, NUM2INT(vbase), RTEST(badcheck));
}
static VALUE
-str2big_karatsuba(VALUE str, VALUE vbase, VALUE badcheck)
+str2big_karatsuba(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
{
return rb_str2big_karatsuba(str, NUM2INT(vbase), RTEST(badcheck));
}
#if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
static VALUE
-str2big_gmp(VALUE str, VALUE vbase, VALUE badcheck)
+str2big_gmp(VALUE klass, VALUE str, VALUE vbase, VALUE badcheck)
{
return rb_str2big_gmp(str, NUM2INT(vbase), RTEST(badcheck));
}
@@ -31,8 +31,8 @@ str2big_gmp(VALUE str, VALUE vbase, VALUE badcheck)
void
Init_str2big(VALUE klass)
{
- rb_define_method(rb_cString, "str2big_poweroftwo", str2big_poweroftwo, 2);
- rb_define_method(rb_cString, "str2big_normal", str2big_normal, 2);
- rb_define_method(rb_cString, "str2big_karatsuba", str2big_karatsuba, 2);
- rb_define_method(rb_cString, "str2big_gmp", str2big_gmp, 2);
+ rb_define_singleton_method(klass, "str2big_poweroftwo", str2big_poweroftwo, 3);
+ rb_define_singleton_method(klass, "str2big_normal", str2big_normal, 3);
+ rb_define_singleton_method(klass, "str2big_karatsuba", str2big_karatsuba, 3);
+ rb_define_singleton_method(klass, "str2big_gmp", str2big_gmp, 3);
}