From 1afbc71ac2176d2179630a4d3f8b1de8710330e1 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 17 May 2016 08:25:58 +0000 Subject: [PATCH] forgot to commit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/-test-/testutil/extconf.rb | 8 ++++++++ ext/-test-/testutil/init.c | 11 +++++++++++ ext/-test-/testutil/integer.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 ext/-test-/testutil/extconf.rb create mode 100644 ext/-test-/testutil/init.c create mode 100644 ext/-test-/testutil/integer.c diff --git a/ext/-test-/testutil/extconf.rb b/ext/-test-/testutil/extconf.rb new file mode 100644 index 0000000000..157a3d62b8 --- /dev/null +++ b/ext/-test-/testutil/extconf.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: false +$INCFLAGS << " -I$(topdir) -I$(top_srcdir)" +$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] +inits = $srcs.map {|s| File.basename(s, ".*")} +inits.delete("init") +inits.map! {|s|"X(#{s})"} +$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\"" +create_makefile("-test-/testutil") diff --git a/ext/-test-/testutil/init.c b/ext/-test-/testutil/init.c new file mode 100644 index 0000000000..cf2804df4f --- /dev/null +++ b/ext/-test-/testutil/init.c @@ -0,0 +1,11 @@ +#include "ruby.h" + +#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);} + +void +Init_testutil(void) +{ + VALUE mBug = rb_define_module("Bug"); + VALUE klass = rb_define_class_under(mBug, "TestUtil", rb_cObject); + TEST_INIT_FUNCS(init); +} diff --git a/ext/-test-/testutil/integer.c b/ext/-test-/testutil/integer.c new file mode 100644 index 0000000000..da5812c616 --- /dev/null +++ b/ext/-test-/testutil/integer.c @@ -0,0 +1,29 @@ +#include "internal.h" + +static VALUE +int_bignum_p(VALUE self) +{ + return RB_TYPE_P(self, T_BIGNUM) ? Qtrue : Qfalse; +} + +static VALUE +int_fixnum_p(VALUE self) +{ + return FIXNUM_P(self) ? Qtrue : Qfalse; +} + +static VALUE +rb_int_to_bignum(VALUE x) +{ + if (FIXNUM_P(x)) + x = rb_int2big(FIX2LONG(x)); + return x; +} + +void +Init_integer(VALUE klass) +{ + rb_define_method(rb_cInteger, "bignum?", int_bignum_p, 0); + rb_define_method(rb_cInteger, "fixnum?", int_fixnum_p, 0); + rb_define_method(rb_cInteger, "to_bignum", rb_int_to_bignum, 0); +}