* eval.c (rb_f_exit), process.c (rb_f_exit_bang): treat true as

success, false as failure.  [ruby-dev:22067]

* eval.c (rb_f_abort, rb_thread_switch), process.c (rb_f_system): use
  ANSI macro instead of hard coded value.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-11-27 15:34:53 +00:00
parent 868d5ba485
commit 99fb5f4871
6 changed files with 46 additions and 23 deletions

View File

@ -1,3 +1,11 @@
Fri Nov 28 00:34:44 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_f_exit), process.c (rb_f_exit_bang): treat true as
success, false as failure. [ruby-dev:22067]
* eval.c (rb_f_abort, rb_thread_switch), process.c (rb_f_system): use
ANSI macro instead of hard coded value.
Thu Nov 27 22:05:48 2003 Akinori MUSHA <knu@iDaemons.org> Thu Nov 27 22:05:48 2003 Akinori MUSHA <knu@iDaemons.org>
* eval.c, gc.c: FreeBSD/ia64 currently does not have a way for a * eval.c, gc.c: FreeBSD/ia64 currently does not have a way for a

16
eval.c
View File

@ -3895,7 +3895,17 @@ rb_f_exit(argc, argv)
rb_secure(4); rb_secure(4);
if (rb_scan_args(argc, argv, "01", &status) == 1) { if (rb_scan_args(argc, argv, "01", &status) == 1) {
istatus = NUM2INT(status); switch (status) {
case T_TRUE:
istatus = EXIT_SUCCESS;
break;
case T_FALSE:
istatus = EXIT_FAILURE;
break;
default:
istatus = NUM2INT(status);
break;
}
} }
else { else {
istatus = EXIT_SUCCESS; istatus = EXIT_SUCCESS;
@ -3922,7 +3932,7 @@ rb_f_abort(argc, argv)
rb_scan_args(argc, argv, "1", &mesg); rb_scan_args(argc, argv, "1", &mesg);
StringValue(argv[0]); StringValue(argv[0]);
rb_io_puts(argc, argv, rb_stderr); rb_io_puts(argc, argv, rb_stderr);
terminate_process(1, RSTRING(argv[0])->ptr, RSTRING(argv[0])->len); terminate_process(EXIT_FAILURE, RSTRING(argv[0])->ptr, RSTRING(argv[0])->len);
} }
return Qnil; /* not reached */ return Qnil; /* not reached */
} }
@ -8407,7 +8417,7 @@ rb_thread_switch(n)
ruby_errinfo = th_raise_argv[0]; ruby_errinfo = th_raise_argv[0];
ruby_current_node = th_raise_node; ruby_current_node = th_raise_node;
error_print(); error_print();
terminate_process(1, 0, 0); terminate_process(EXIT_FAILURE, 0, 0);
break; break;
case RESTORE_NORMAL: case RESTORE_NORMAL:
default: default:

View File

@ -94,7 +94,7 @@ module Test
retry retry
rescue rescue
end end
abort if @red exit !@red
end end
def stop(*) # :nodoc: def stop(*) # :nodoc:

View File

@ -406,7 +406,7 @@ module Test
retry retry
rescue rescue
end end
abort if @red exit !@red
end # def start_ui end # def start_ui
private :start_ui private :start_ui

View File

@ -102,7 +102,7 @@ module Test
retry retry
rescue rescue
end end
abort if @red exit !@red
end end
def stop # :nodoc: def stop # :nodoc:

View File

@ -30,6 +30,9 @@
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE #ifndef EXIT_FAILURE
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#endif #endif
@ -878,7 +881,17 @@ rb_f_exit_bang(argc, argv, obj)
rb_secure(4); rb_secure(4);
if (rb_scan_args(argc, argv, "01", &status) == 1) { if (rb_scan_args(argc, argv, "01", &status) == 1) {
istatus = NUM2INT(status); switch (status) {
case T_TRUE:
istatus = EXIT_SUCCESS;
break;
case T_FALSE:
istatus = EXIT_FAILURE;
break;
default:
istatus = NUM2INT(status);
break;
}
} }
else { else {
istatus = EXIT_FAILURE; istatus = EXIT_FAILURE;
@ -930,9 +943,9 @@ rb_f_system(argc, argv)
int argc; int argc;
VALUE *argv; VALUE *argv;
{ {
int status;
#if defined(__EMX__) #if defined(__EMX__)
VALUE cmd; VALUE cmd;
int status;
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
@ -952,12 +965,8 @@ rb_f_system(argc, argv)
SafeStringValue(cmd); SafeStringValue(cmd);
status = do_spawn(RSTRING(cmd)->ptr); status = do_spawn(RSTRING(cmd)->ptr);
last_status_set(status, 0); last_status_set(status, 0);
if (status == 0) return Qtrue;
return Qfalse;
#elif defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32) #elif defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32)
volatile VALUE prog = 0; volatile VALUE prog = 0;
int status;
fflush(stdout); fflush(stdout);
fflush(stderr); fflush(stderr);
@ -990,10 +999,8 @@ rb_f_system(argc, argv)
#else #else
last_status_set(status == -1 ? 127 : status, 0); last_status_set(status == -1 ? 127 : status, 0);
#endif #endif
return status == 0 ? Qtrue : Qfalse;
#elif defined(__VMS) #elif defined(__VMS)
VALUE cmd; VALUE cmd;
int status;
if (argc == 0) { if (argc == 0) {
rb_last_status = Qnil; rb_last_status = Qnil;
@ -1011,9 +1018,6 @@ rb_f_system(argc, argv)
SafeStringValue(cmd); SafeStringValue(cmd);
status = system(RSTRING(cmd)->ptr); status = system(RSTRING(cmd)->ptr);
last_status_set((status & 0xff) << 8, 0); last_status_set((status & 0xff) << 8, 0);
if (status == 0) return Qtrue;
return Qfalse;
#else #else
volatile VALUE prog = 0; volatile VALUE prog = 0;
int pid; int pid;
@ -1064,10 +1068,11 @@ rb_f_system(argc, argv)
rb_syswait(pid); rb_syswait(pid);
} }
if (NUM2INT(rb_last_status) == 0) status = NUM2INT(rb_last_status);
return Qtrue;
return Qfalse;
#endif #endif
if (status == EXIT_SUCCESS) return Qtrue;
return Qfalse;
} }
static VALUE static VALUE