From: nobu.nakada@... Date: 2001-11-16T12:44:32+09:00 Subject: [ruby-dev:15187] Re: strange behavior about PTY.spawn なかだです。 At Fri, 16 Nov 2001 11:41:02 +0900, akira yamada / やまだあきら wrote: > というのは当り前でSIGSTOPが来るとloop{}において例外が発生するのですよね(^_^; > で, たとえばですがこういう感じにするというのはどうでしょうか? あんまりちゃんと読んでないのですが、例外を投げるのはThread.main よりもThread.currentの方がよくないでしょうか。 [ruby-dev:15185]へのパッチです。 --- pty.c~ Fri Nov 16 12:21:03 2001 +++ pty.c Fri Nov 16 12:43:21 2001 @@ -119,15 +119,6 @@ pty_raise(cpid, sig, th) char buf[1024]; - if (NIL_P(th)) { - snprintf(buf, sizeof(buf), - "eval %%Q{Thread.main.raise 'pty - process %d received signal: %d'}, nil, \"%s\", %d", - cpid, sig, ruby_sourcefile, ruby_sourceline); - rb_eval_string(buf); - } - else { - snprintf(buf, sizeof(buf), "pty - process %d received signal: %d", cpid, sig); - rb_funcall(th, rb_intern("raise"), 2, - rb_eRuntimeError, rb_str_new2(buf)); - } + snprintf(buf, sizeof(buf), "pty - process %d received signal: %d", cpid, sig); + rb_funcall(th, rb_intern("raise"), 2, rb_eRuntimeError, rb_str_new2(buf)); } @@ -140,13 +131,18 @@ pty_yield(res) } +struct pty_wait { + int pid; + VALUE thread; +}; + static VALUE -pty_syswait(thver) - VALUE thver; +pty_syswait(w) + struct pty_wait *w; { int pid, cpid, status; VALUE th; - pid = NUM2INT(RARRAY(thver)->ptr[0]); - th = RARRAY(thver)->ptr[1]; + pid = w->pid; + th = w->thread; cpid = rb_waitpid(pid, &status, WUNTRACED); @@ -399,6 +395,7 @@ pty_getpty(self, command) VALUE self, command; { - VALUE res, thc, thy, thver; + VALUE res, thc, thy; struct pty_info info; + struct pty_wait winfo; OpenFile *wfptr,*rfptr; VALUE rport = rb_obj_alloc(rb_cFile); @@ -427,5 +424,5 @@ pty_getpty(self, command) rb_ary_store(res,2,INT2FIX(info.child_pid)); - thver = rb_ary_new2(2); + winfo.pid = info.child_pid; printf("start watching PTY command (%d)\n", info.child_pid); @@ -433,7 +430,6 @@ pty_getpty(self, command) thy = rb_thread_create(pty_yield, (void*)res); - rb_ary_store(thver,0,(VALUE)INT2NUM(info.child_pid)); - rb_ary_store(thver,1,(VALUE)thy); - thc = rb_thread_create(pty_syswait, (void*)thver); + winfo.thread = thy; + thc = rb_thread_create(pty_syswait, (void*)&winfo); rb_funcall(thy, rb_intern("run"), 0, 0); @@ -444,7 +440,6 @@ pty_getpty(self, command) } else { - rb_ary_store(thver,0,(VALUE)INT2NUM(info.child_pid)); - rb_ary_store(thver,1,(VALUE)Qnil); - thc = rb_thread_create(pty_syswait, (void*)thver); + winfo.thread = rb_thread_current(); + thc = rb_thread_create(pty_syswait, (void*)&winfo); return res; } -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦