ruby-changes:21959
From: nobu <ko1@a...>
Date: Sun, 11 Dec 2011 10:48:41 +0900 (JST)
Subject: [ruby-changes:21959] nobu:r34008 (trunk): * error.c (exit_initialize): deal with true and false as well as
nobu 2011-12-11 10:48:21 +0900 (Sun, 11 Dec 2011) New Revision: 34008 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34008 Log: * error.c (exit_initialize): deal with true and false as well as Kernel#exit. [ruby-dev:44951] [Bug #5728] Modified files: trunk/ChangeLog trunk/error.c trunk/test/ruby/test_exception.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34007) +++ ChangeLog (revision 34008) @@ -1,3 +1,8 @@ +Sun Dec 11 10:48:16 2011 Nobuyoshi Nakada <nobu@r...> + + * error.c (exit_initialize): deal with true and false as well as + Kernel#exit. [ruby-dev:44951] [Bug #5728] + Sun Dec 11 10:37:47 2011 Nobuyoshi Nakada <nobu@r...> * object.c (rb_check_to_int): new function to convert a VALUE to Index: error.c =================================================================== --- error.c (revision 34007) +++ error.c (revision 34008) @@ -749,17 +749,47 @@ * SystemExit.new(msg) -> system_exit * * Create a new +SystemExit+ exception with the given status and message. - * If status is not given, EXIT_SUCCESS is used. + * Status is true, false, or an integer. + * If status is not given, true is used. */ static VALUE exit_initialize(int argc, VALUE *argv, VALUE exc) { - VALUE status = INT2FIX(EXIT_SUCCESS); - if (argc > 0 && FIXNUM_P(argv[0])) { - status = *argv++; - --argc; + VALUE status; + if (argc > 0) { + status = *argv; + + switch (status) { + case Qtrue: + status = INT2FIX(EXIT_SUCCESS); + ++argv; + --argc; + break; + case Qfalse: + status = INT2FIX(EXIT_FAILURE); + ++argv; + --argc; + break; + default: + status = rb_check_to_int(status); + if (NIL_P(status)) { + status = INT2FIX(EXIT_SUCCESS); + } + else { +#if EXIT_SUCCESS != 0 + if (status == INT2FIX(0)) + status = INT2FIX(EXIT_SUCCESS); +#endif + ++argv; + --argc; + } + break; + } } + else { + status = INT2FIX(EXIT_SUCCESS); + } rb_call_super(argc, argv); rb_iv_set(exc, "status", status); return exc; Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 34007) +++ test/ruby/test_exception.rb (revision 34008) @@ -348,5 +348,19 @@ eis = SystemExit.new(7, "msg") assert_equal(7, eis.status) assert_equal("msg", eis.message) + + bug5728 = '[ruby-dev:44951]' + et = SystemExit.new(true) + assert_equal(true, et.success?, bug5728) + assert_equal("SystemExit", et.message, bug5728) + ef = SystemExit.new(false) + assert_equal(false, ef.success?, bug5728) + assert_equal("SystemExit", ef.message, bug5728) + ets = SystemExit.new(true, "msg") + assert_equal(true, ets.success?, bug5728) + assert_equal("msg", ets.message, bug5728) + efs = SystemExit.new(false, "msg") + assert_equal(false, efs.success?, bug5728) + assert_equal("msg", efs.message, bug5728) end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/