ruby-changes:27984
From: akr <ko1@a...>
Date: Mon, 1 Apr 2013 20:59:08 +0900 (JST)
Subject: [ruby-changes:27984] akr:r40036 (trunk): * ext/-test-/num2int/num2int.c: Return string for result, instead of
akr 2013-04-01 20:58:55 +0900 (Mon, 01 Apr 2013) New Revision: 40036 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40036 Log: * ext/-test-/num2int/num2int.c: Return string for result, instead of printing. * test/-ext-/num2int/test_num2int.rb: updated to follow above change. Modified files: trunk/ChangeLog trunk/ext/-test-/num2int/num2int.c trunk/test/-ext-/num2int/test_num2int.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 40035) +++ ChangeLog (revision 40036) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Apr 1 20:57:57 2013 Tanaka Akira <akr@f...> + + * ext/-test-/num2int/num2int.c: Return string for result, instead of + printing. + + * test/-ext-/num2int/test_num2int.rb: updated to follow above change. + Mon Apr 1 20:08:07 2013 Tanaka Akira <akr@f...> * numeric.c (rb_num2long): Don't use SIGNED_VALUE uselessly. Index: ext/-test-/num2int/num2int.c =================================================================== --- ext/-test-/num2int/num2int.c (revision 40035) +++ ext/-test-/num2int/num2int.c (revision 40036) @@ -1,161 +1,109 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/num2int/num2int.c#L1 #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) https://github.com/ruby/ruby/blob/trunk/ext/-test-/num2int/num2int.c#L111 { 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); } Index: test/-ext-/num2int/test_num2int.rb =================================================================== --- test/-ext-/num2int/test_num2int.rb (revision 40035) +++ test/-ext-/num2int/test_num2int.rb (revision 40036) @@ -33,12 +33,11 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L33 def assert_num2i_success_internal(exp, func, arg) mesg = "#{func}(#{arg.inspect})" - method = "print_#{func}".downcase - out = err = nil + method = "rb_#{func}".downcase + out = nil assert_nothing_raised(mesg) { - out, err = capture_io { Num2int.send(method, arg) } + out = Num2int.send(method, arg) } - STDERR.puts err if err && !err.empty? assert_equal(exp, out, mesg) end @@ -60,7 +59,7 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L59 end def assert_num2i_error_internal(func, arg) - method = "print_#{func}".downcase + method = "rb_#{func}".downcase assert_raise(RangeError, "#{func}(#{arg.inspect})") { Num2int.send(method, arg) } @@ -85,12 +84,11 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L84 def assert_fix2i_success_internal(exp, func, arg) mesg = "#{func}(#{arg.inspect})" - method = "print_#{func}".downcase - out = err = nil + method = "rb_#{func}".downcase + out = nil assert_nothing_raised(mesg) { - out, err = capture_io { Num2int.send(method, arg) } + out = Num2int.send(method, arg) } - STDERR.puts err if err && !err.empty? assert_equal(exp, out, mesg) end @@ -101,7 +99,7 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L99 end def assert_fix2i_error_internal(func, arg) - method = "print_#{func}".downcase + method = "rb_#{func}".downcase assert_raise(RangeError, "#{func}(#{arg.inspect})") { Num2int.send(method, arg) } @@ -178,7 +176,7 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L176 assert_num2i_success(:ll, FIXNUM_MIN-1) assert_num2i_success(:ll, FIXNUM_MAX) assert_num2i_success(:ll, FIXNUM_MAX+1) - end if defined?(Num2int.print_num2ll) + end if defined?(Num2int.rb_num2ll) def test_num2ull assert_num2i_success(:ull, 0) @@ -191,7 +189,7 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L189 assert_num2i_success(:ull, FIXNUM_MIN-1, ULLONG_MAX-FIXNUM_MAX-1) assert_num2i_success(:ull, FIXNUM_MAX) assert_num2i_success(:ull, FIXNUM_MAX+1) - end if defined?(Num2int.print_num2ull) + end if defined?(Num2int.rb_num2ull) def test_fix2short assert_fix2i_success(:short, 0) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/