summaryrefslogtreecommitdiff
path: root/ext/-test-/num2int
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-01 11:58:55 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-01 11:58:55 +0000
commit0cbe2f4902aa3de9a082776d4fcc574bc50d5aa5 (patch)
treeedf823dcaa066728854f672fa0a77650cdb517e3 /ext/-test-/num2int
parent4e52c3c60c3b012631493d1ba6254d448e0eb7c5 (diff)
* ext/-test-/num2int/num2int.c: Return string for result, instead of
printing. * test/-ext-/num2int/test_num2int.rb: updated to follow above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-/num2int')
-rw-r--r--ext/-test-/num2int/num2int.c130
1 files changed, 39 insertions, 91 deletions
diff --git a/ext/-test-/num2int/num2int.c b/ext/-test-/num2int/num2int.c
index f433858..a64082d 100644
--- a/ext/-test-/num2int/num2int.c
+++ b/ext/-test-/num2int/num2int.c
@@ -1,161 +1,109 @@
#include <ruby.h>
static VALUE
-print_num2short(VALUE obj, VALUE num)
+test_num2short(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%d", NUM2SHORT(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_num2ushort(VALUE obj, VALUE num)
+test_num2ushort(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%u", NUM2USHORT(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_num2int(VALUE obj, VALUE num)
+test_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);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_num2uint(VALUE obj, VALUE num)
+test_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);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_num2long(VALUE obj, VALUE num)
+test_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);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_num2ulong(VALUE obj, VALUE num)
+test_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);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
#ifdef HAVE_LONG_LONG
static VALUE
-print_num2ll(VALUE obj, VALUE num)
+test_num2ll(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%"PRI_LL_PREFIX"d", NUM2LL(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_num2ull(VALUE obj, VALUE num)
+test_num2ull(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%"PRI_LL_PREFIX"u", NUM2ULL(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
#endif
static VALUE
-print_fix2short(VALUE obj, VALUE num)
+test_fix2short(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%d", FIX2SHORT(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_fix2int(VALUE obj, VALUE num)
+test_fix2int(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%d", FIX2INT(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_fix2uint(VALUE obj, VALUE num)
+test_fix2uint(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%u", FIX2UINT(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_fix2long(VALUE obj, VALUE num)
+test_fix2long(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%ld", FIX2LONG(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
static VALUE
-print_fix2ulong(VALUE obj, VALUE num)
+test_fix2ulong(VALUE obj, VALUE num)
{
char buf[128];
- VALUE str;
-
sprintf(buf, "%lu", FIX2ULONG(num));
- str = rb_str_new_cstr(buf);
- rb_io_write(rb_stdout, str);
- return Qnil;
+ return rb_str_new_cstr(buf);
}
void
@@ -163,26 +111,26 @@ Init_num2int(void)
{
VALUE cNum2int = rb_path2class("TestNum2int::Num2int");
- rb_define_singleton_method(cNum2int, "print_num2short", print_num2short, 1);
- rb_define_singleton_method(cNum2int, "print_num2ushort", print_num2ushort, 1);
+ rb_define_singleton_method(cNum2int, "rb_num2short", test_num2short, 1);
+ rb_define_singleton_method(cNum2int, "rb_num2ushort", test_num2ushort, 1);
- 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, "rb_num2int", test_num2int, 1);
+ rb_define_singleton_method(cNum2int, "rb_num2uint", test_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, "rb_num2long", test_num2long, 1);
+ rb_define_singleton_method(cNum2int, "rb_num2ulong", test_num2ulong, 1);
#ifdef HAVE_LONG_LONG
- rb_define_singleton_method(cNum2int, "print_num2ll", print_num2ll, 1);
- rb_define_singleton_method(cNum2int, "print_num2ull", print_num2ull, 1);
+ rb_define_singleton_method(cNum2int, "rb_num2ll", test_num2ll, 1);
+ rb_define_singleton_method(cNum2int, "rb_num2ull", test_num2ull, 1);
#endif
- rb_define_singleton_method(cNum2int, "print_fix2short", print_fix2short, 1);
+ rb_define_singleton_method(cNum2int, "rb_fix2short", test_fix2short, 1);
- rb_define_singleton_method(cNum2int, "print_fix2int", print_fix2int, 1);
- rb_define_singleton_method(cNum2int, "print_fix2uint", print_fix2uint, 1);
+ rb_define_singleton_method(cNum2int, "rb_fix2int", test_fix2int, 1);
+ rb_define_singleton_method(cNum2int, "rb_fix2uint", test_fix2uint, 1);
- rb_define_singleton_method(cNum2int, "print_fix2long", print_fix2long, 1);
- rb_define_singleton_method(cNum2int, "print_fix2ulong", print_fix2ulong, 1);
+ rb_define_singleton_method(cNum2int, "rb_fix2long", test_fix2long, 1);
+ rb_define_singleton_method(cNum2int, "rb_fix2ulong", test_fix2ulong, 1);
}