diff options
Diffstat (limited to 'ext/-test-/integer')
| -rw-r--r-- | ext/-test-/integer/core_ext.c | 36 | ||||
| -rw-r--r-- | ext/-test-/integer/depend | 40 | ||||
| -rw-r--r-- | ext/-test-/integer/extconf.rb | 3 | ||||
| -rw-r--r-- | ext/-test-/integer/init.c | 11 | ||||
| -rw-r--r-- | ext/-test-/integer/my_integer.c | 16 |
5 files changed, 106 insertions, 0 deletions
diff --git a/ext/-test-/integer/core_ext.c b/ext/-test-/integer/core_ext.c new file mode 100644 index 0000000000..510ba4a1e6 --- /dev/null +++ b/ext/-test-/integer/core_ext.c @@ -0,0 +1,36 @@ +#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; +} + +static VALUE +positive_pow(VALUE x, VALUE y) +{ + return rb_int_positive_pow(NUM2LONG(x), NUM2ULONG(y)); +} + +void +Init_core_ext(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); + rb_define_method(rb_cInteger, "positive_pow", positive_pow, 1); +} diff --git a/ext/-test-/integer/depend b/ext/-test-/integer/depend new file mode 100644 index 0000000000..48f04d9ca0 --- /dev/null +++ b/ext/-test-/integer/depend @@ -0,0 +1,40 @@ +# AUTOGENERATED DEPENDENCIES START +core_ext.o: $(RUBY_EXTCONF_H) +core_ext.o: $(arch_hdrdir)/ruby/config.h +core_ext.o: $(hdrdir)/ruby/backward.h +core_ext.o: $(hdrdir)/ruby/defines.h +core_ext.o: $(hdrdir)/ruby/encoding.h +core_ext.o: $(hdrdir)/ruby/intern.h +core_ext.o: $(hdrdir)/ruby/io.h +core_ext.o: $(hdrdir)/ruby/missing.h +core_ext.o: $(hdrdir)/ruby/onigmo.h +core_ext.o: $(hdrdir)/ruby/oniguruma.h +core_ext.o: $(hdrdir)/ruby/ruby.h +core_ext.o: $(hdrdir)/ruby/st.h +core_ext.o: $(hdrdir)/ruby/subst.h +core_ext.o: $(top_srcdir)/include/ruby.h +core_ext.o: $(top_srcdir)/internal.h +core_ext.o: core_ext.c +init.o: $(RUBY_EXTCONF_H) +init.o: $(arch_hdrdir)/ruby/config.h +init.o: $(hdrdir)/ruby/backward.h +init.o: $(hdrdir)/ruby/defines.h +init.o: $(hdrdir)/ruby/intern.h +init.o: $(hdrdir)/ruby/missing.h +init.o: $(hdrdir)/ruby/ruby.h +init.o: $(hdrdir)/ruby/st.h +init.o: $(hdrdir)/ruby/subst.h +init.o: $(top_srcdir)/include/ruby.h +init.o: init.c +my_integer.o: $(RUBY_EXTCONF_H) +my_integer.o: $(arch_hdrdir)/ruby/config.h +my_integer.o: $(hdrdir)/ruby/backward.h +my_integer.o: $(hdrdir)/ruby/defines.h +my_integer.o: $(hdrdir)/ruby/intern.h +my_integer.o: $(hdrdir)/ruby/missing.h +my_integer.o: $(hdrdir)/ruby/ruby.h +my_integer.o: $(hdrdir)/ruby/st.h +my_integer.o: $(hdrdir)/ruby/subst.h +my_integer.o: $(top_srcdir)/include/ruby.h +my_integer.o: my_integer.c +# AUTOGENERATED DEPENDENCIES END diff --git a/ext/-test-/integer/extconf.rb b/ext/-test-/integer/extconf.rb new file mode 100644 index 0000000000..d786b15db9 --- /dev/null +++ b/ext/-test-/integer/extconf.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: false +require_relative "../auto_ext.rb" +auto_ext(inc: true) diff --git a/ext/-test-/integer/init.c b/ext/-test-/integer/init.c new file mode 100644 index 0000000000..fc256ea16b --- /dev/null +++ b/ext/-test-/integer/init.c @@ -0,0 +1,11 @@ +#include "ruby.h" + +#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);} + +void +Init_integer(void) +{ + VALUE mBug = rb_define_module("Bug"); + VALUE klass = rb_define_class_under(mBug, "Integer", rb_cObject); + TEST_INIT_FUNCS(init); +} diff --git a/ext/-test-/integer/my_integer.c b/ext/-test-/integer/my_integer.c new file mode 100644 index 0000000000..d86474bd7d --- /dev/null +++ b/ext/-test-/integer/my_integer.c @@ -0,0 +1,16 @@ +#include "ruby.h" + +static VALUE +my_integer_s_new(VALUE klass) +{ + return Data_Wrap_Struct(klass, 0, 0, 0); +} + +void +Init_my_integer(VALUE klass) +{ + VALUE cMyInteger; + + cMyInteger = rb_define_class_under(klass, "MyInteger", rb_cInteger); + rb_define_singleton_method(cMyInteger, "new", my_integer_s_new, 0); +} |
