From: Tietew Date: 2002-10-26T23:28:47+09:00 Subject: [ruby-dev:18582] embedded ruby interpreter friendly patch Tietew です。 [ruby-dev:13943] で提案してそのまま忘れ去られているっぽい ruby_stop の変更 (exit(3) を呼ばない ruby_stop) と,例外の表示を すぐ送って欲しいという2点についてパッチを提案します。 1.7 に対するパッチです。 後者は,やはり組み込み Ruby なのですが,コンソールがないので unnamed pipe を作って stdout/stderr をリダイレクトしています。他 スレッドで読み出しているのですが,バッファリングされているとコン ソールのようにすぐに反映されないのでちょっと困ってしまうのです。 (そのほかについては STDOUT.sync = STDERR.sync = true すればよい) Index: eval.c =================================================================== RCS file: /src/ruby/eval.c,v retrieving revision 1.344 diff -u -2 -p -r1.344 eval.c --- eval.c 25 Oct 2002 18:39:29 -0000 1.344 +++ eval.c 26 Oct 2002 14:26:44 -0000 @@ -1045,4 +1045,5 @@ error_print() } } + fflush(stderr); } @@ -1230,5 +1231,5 @@ ruby_finalize() } -void +int ruby_stop(ex) int ex; @@ -1252,8 +1253,8 @@ ruby_stop(ex) POP_TAG(); ruby_finalize(); - exit(ex); + return ex; } -void +int ruby_run() { @@ -1262,5 +1263,5 @@ ruby_run() volatile NODE *tmp; - if (ruby_nerrs > 0) exit(ruby_nerrs); + if (ruby_nerrs > 0) return ruby_nerrs; Init_stack((void*)&tmp); @@ -1276,5 +1277,5 @@ ruby_run() if (state && !ex) ex = state; - ruby_stop(ex); + return ruby_stop(ex); } @@ -3612,4 +3613,5 @@ rb_longjmp(tag, mesg) ruby_sourcefile, ruby_sourceline, RSTRING(e)->ptr); + fflush(stderr); } @@ -8121,4 +8123,5 @@ rb_thread_schedule() } END_FOREACH_FROM(curr, th); + fflush(stderr); next = main_thread; rb_thread_ready(next); @@ -8783,5 +8786,5 @@ rb_thread_start_0(fn, arg, th_arg) status = th->status; - if (th == main_thread) ruby_stop(state); + if (th == main_thread) exit(ruby_stop(state)); rb_thread_remove(th); Index: intern.h =================================================================== RCS file: /src/ruby/intern.h,v retrieving revision 1.98 diff -u -2 -p -r1.98 intern.h --- intern.h 23 Oct 2002 10:17:29 -0000 1.98 +++ intern.h 26 Oct 2002 14:26:44 -0000 @@ -173,5 +173,5 @@ void rb_mark_end_proc _((void)); void rb_exec_end_proc _((void)); void ruby_finalize _((void)); -void ruby_stop _((int)); +int ruby_stop _((int)); void rb_gc_mark_threads _((void)); void rb_thread_start_timer _((void)); Index: main.c =================================================================== RCS file: /src/ruby/main.c,v retrieving revision 1.8 diff -u -2 -p -r1.8 main.c --- main.c 18 Apr 2002 08:46:18 -0000 1.8 +++ main.c 26 Oct 2002 14:26:44 -0000 @@ -48,5 +48,4 @@ main(argc, argv, envp) ruby_init(); ruby_options(argc, argv); - ruby_run(); - return 0; + return ruby_run(); } Index: ruby.h =================================================================== RCS file: /src/ruby/ruby.h,v retrieving revision 1.70 diff -u -2 -p -r1.70 ruby.h --- ruby.h 9 Sep 2002 10:26:02 -0000 1.70 +++ ruby.h 26 Oct 2002 14:26:45 -0000 @@ -538,5 +538,5 @@ VALUE rb_require _((const char*)); void ruby_init _((void)); void ruby_options _((int, char**)); -void ruby_run _((void)); +int ruby_run _((void)); EXTERN VALUE rb_mKernel; —[ Tietew ]—————————————————————————— メ : tietew@tietew.net / tietew@raug.net / tietew@masuclub.net ホペ: http://www.tietew.net/ Tietew Windows Lab. http://www.masuclub.net/ 鱒倶楽部 指紋: 26CB 71BB B595 09C4 0153 81C4 773C 963A D51B 8CAA