aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-17 08:25:58 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-17 08:25:58 +0000
commitfdb4d270180bf08729bf772a7aee4fcb6f601424 (patch)
tree9535786ba4af5bfc24644cb533c3f92508dc3643
parent0362ad83a7c1852d638915859ca56f49d39fb8ac (diff)
downloadruby-fdb4d270180bf08729bf772a7aee4fcb6f601424.tar.gz
forgot to commit.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/-test-/testutil/extconf.rb8
-rw-r--r--ext/-test-/testutil/init.c11
-rw-r--r--ext/-test-/testutil/integer.c29
3 files changed, 48 insertions, 0 deletions
diff --git a/ext/-test-/testutil/extconf.rb b/ext/-test-/testutil/extconf.rb
new file mode 100644
index 0000000..157a3d6
--- /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 0000000..cf2804d
--- /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 0000000..da5812c
--- /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);
+}