From 74a13c76349b3b463514f60beb9f02c2ba301ad6 Mon Sep 17 00:00:00 2001 From: kosaki Date: Mon, 14 Nov 2011 03:45:47 +0000 Subject: * numeric.c (check_uint): fix off-by-one bug of NUM2UINT. * bignum.c (rb_big2ulong): fix off-by-one bug of NUM2ULONG. * test/-ext-/num2int/test_num2int.rb: add a testcase for NUM2INT() NUM2UINT(), NUM2LONG(), NUM2ULONG(), NUM2LL and NUM2ULL(). * ext/-test-/num2int/depend: ditto. * ext/-test-/num2int/extconf.rb: ditto. * ext/-test-/num2int/num2int.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/-test-/num2int/depend | 1 + ext/-test-/num2int/extconf.rb | 1 + ext/-test-/num2int/num2int.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 ext/-test-/num2int/depend create mode 100644 ext/-test-/num2int/extconf.rb create mode 100644 ext/-test-/num2int/num2int.c (limited to 'ext/-test-/num2int') diff --git a/ext/-test-/num2int/depend b/ext/-test-/num2int/depend new file mode 100644 index 0000000000..7a85cdb6c0 --- /dev/null +++ b/ext/-test-/num2int/depend @@ -0,0 +1 @@ +num2int.o: $(top_srcdir)/numeric.c $(hdrdir)/ruby/ruby.h diff --git a/ext/-test-/num2int/extconf.rb b/ext/-test-/num2int/extconf.rb new file mode 100644 index 0000000000..2bc820e480 --- /dev/null +++ b/ext/-test-/num2int/extconf.rb @@ -0,0 +1 @@ +create_makefile("-test-/num2int/num2int") diff --git a/ext/-test-/num2int/num2int.c b/ext/-test-/num2int/num2int.c new file mode 100644 index 0000000000..a7242a982c --- /dev/null +++ b/ext/-test-/num2int/num2int.c @@ -0,0 +1,86 @@ +#include + +extern VALUE rb_stdout; + +static VALUE +print_num2int(VALUE obj, VALUE num) +{ + char buf[128]; + VALUE str; + + sprintf(buf, "%d", NUM2INT(num)); + str = rb_str_new_cstr(buf); + rb_io_write(rb_stdout, str); +} + +static VALUE +print_num2uint(VALUE obj, VALUE num) +{ + char buf[128]; + VALUE str; + + sprintf(buf, "%u", NUM2UINT(num)); + str = rb_str_new_cstr(buf); + rb_io_write(rb_stdout, str); +} + +static VALUE +print_num2long(VALUE obj, VALUE num) +{ + char buf[128]; + VALUE str; + + sprintf(buf, "%ld", NUM2LONG(num)); + str = rb_str_new_cstr(buf); + rb_io_write(rb_stdout, str); +} + +static VALUE +print_num2ulong(VALUE obj, VALUE num) +{ + char buf[128]; + VALUE str; + + sprintf(buf, "%lu", NUM2ULONG(num)); + str = rb_str_new_cstr(buf); + rb_io_write(rb_stdout, str); +} + +static VALUE +print_num2ll(VALUE obj, VALUE num) +{ + char buf[128]; + VALUE str; + + sprintf(buf, "%lld", NUM2LL(num)); + str = rb_str_new_cstr(buf); + rb_io_write(rb_stdout, str); +} + +static VALUE +print_num2ull(VALUE obj, VALUE num) +{ + char buf[128]; + VALUE str; + + sprintf(buf, "%llu", NUM2ULL(num)); + str = rb_str_new_cstr(buf); + rb_io_write(rb_stdout, str); +} + + +void +Init_num2int(void) +{ + VALUE cNum2int = rb_path2class("TestNum2int::Num2int"); + + rb_define_singleton_method(cNum2int, "print_num2int", print_num2int, 1); + rb_define_singleton_method(cNum2int, "print_num2uint", print_num2uint, 1); + + rb_define_singleton_method(cNum2int, "print_num2long", print_num2long, 1); + rb_define_singleton_method(cNum2int, "print_num2ulong", print_num2ulong, 1); + + rb_define_singleton_method(cNum2int, "print_num2ll", print_num2ll, 1); + rb_define_singleton_method(cNum2int, "print_num2ull", print_num2ull, 1); +} + -- cgit v1.2.3