なかだです。

今のところ、可搬性のある形で成功/失敗を親プロセスに通知しようと
すると、

  success ? exit : abort

のようにしなければなりません。そこで、exit/exit!で、true/false
を受け付けるようにするってのはどうでしょうか。

また、systemで成功=0でハードコードされているのも望ましくないの
では。

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

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


Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.595 diff -u -2 -p -r1.595 eval.c --- eval.c 27 Nov 2003 13:08:27 -0000 1.595 +++ eval.c 27 Nov 2003 14:04:15 -0000 @@ -3896,5 +3896,15 @@ rb_f_exit(argc, argv) rb_secure(4); 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 { @@ -3923,5 +3933,5 @@ rb_f_abort(argc, argv) StringValue(argv[0]); 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 */ @@ -8408,5 +8418,5 @@ rb_thread_switch(n) ruby_current_node = th_raise_node; error_print(); - terminate_process(1, 0, 0); + terminate_process(EXIT_FAILURE, 0, 0); break; case RESTORE_NORMAL: Index: process.c =================================================================== RCS file: /cvs/ruby/src/ruby/process.c,v retrieving revision 1.89 diff -u -2 -p -r1.89 process.c --- process.c 4 Nov 2003 09:13:57 -0000 1.89 +++ process.c 27 Nov 2003 14:16:58 -0000 @@ -31,4 +31,7 @@ #include <ctype.h> +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 @@ -879,5 +882,15 @@ rb_f_exit_bang(argc, argv, obj) rb_secure(4); 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 { @@ -953,7 +966,4 @@ rb_f_system(argc, argv) status = do_spawn(RSTRING(cmd)->ptr); last_status_set(status, 0); - - if (status == 0) return Qtrue; - return Qfalse; #elif defined(__human68k__) || defined(__DJGPP__) || defined(_WIN32) volatile VALUE prog = 0; @@ -991,5 +1001,4 @@ rb_f_system(argc, argv) last_status_set(status == -1 ? 127 : status, 0); #endif - return status == 0 ? Qtrue : Qfalse; #elif defined(__VMS) VALUE cmd; @@ -1012,7 +1021,4 @@ rb_f_system(argc, argv) status = system(RSTRING(cmd)->ptr); last_status_set((status & 0xff) << 8, 0); - - if (status == 0) return Qtrue; - return Qfalse; #else volatile VALUE prog = 0; @@ -1065,8 +1071,9 @@ rb_f_system(argc, argv) } - if (NUM2INT(rb_last_status) == 0) - return Qtrue; - return Qfalse; + status = NUM2INT(rb_last_status); #endif + + if (status == EXIT_SUCCESS) return Qtrue; + return Qfalse; }
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦