diff --git a/ChangeLog b/ChangeLog index ea756b04a6..3e1de62240 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Dec 11 10:34:39 2011 Nobuyoshi Nakada + + * process.c (rb_exit_status_code): extract from rb_f_exit_bang and + rb_f_exit. assume 0 to be success in Kernel#exit! too. + Fri Dec 9 19:24:31 2011 NARUSE, Yui * enc/trans/iso-8859-16-tbl.rb: add ISO-8859-16 converter. diff --git a/process.c b/process.c index 05ee2b2dfe..b3bdc8d8c8 100644 --- a/process.c +++ b/process.c @@ -2795,6 +2795,29 @@ rb_f_fork(VALUE obj) #define rb_f_fork rb_f_notimplement #endif +static int +exit_status_code(VALUE status) +{ + int istatus; + + switch (status) { + case Qtrue: + istatus = EXIT_SUCCESS; + break; + case Qfalse: + istatus = EXIT_FAILURE; + break; + default: + istatus = NUM2INT(status); +#if EXIT_SUCCESS != 0 + if (istatus == 0) + istatus = EXIT_SUCCESS; +#endif + break; + } + return istatus; +} + /* * call-seq: * Process.exit!(status=false) @@ -2814,17 +2837,7 @@ rb_f_exit_bang(int argc, VALUE *argv, VALUE obj) rb_secure(4); if (argc > 0 && rb_scan_args(argc, argv, "01", &status) == 1) { - switch (status) { - case Qtrue: - istatus = EXIT_SUCCESS; - break; - case Qfalse: - istatus = EXIT_FAILURE; - break; - default: - istatus = NUM2INT(status); - break; - } + istatus = exit_status_code(status); } else { istatus = EXIT_FAILURE; @@ -2898,21 +2911,7 @@ rb_f_exit(int argc, VALUE *argv) rb_secure(4); if (argc > 0 && rb_scan_args(argc, argv, "01", &status) == 1) { - switch (status) { - case Qtrue: - istatus = EXIT_SUCCESS; - break; - case Qfalse: - istatus = EXIT_FAILURE; - break; - default: - istatus = NUM2INT(status); -#if EXIT_SUCCESS != 0 - if (istatus == 0) - istatus = EXIT_SUCCESS; -#endif - break; - } + istatus = exit_status_code(status); } else { istatus = EXIT_SUCCESS;