From: matz@... (Yukihiro Matsumoto) Date: 2001-09-08T04:39:07+09:00 Subject: [ruby-dev:14747] Re: [BUG] $_ on thread switching まつもと ゆきひろです In message "[ruby-dev:14746] Re: [BUG] $_ on thread switching" on 01/09/08, nobu.nakada@nifty.ne.jp writes: | rb_thread_restore_context()で$_, $~を書き戻すときに、別の |SCOPEを使っているスレッド同士では復元できないということのようで |すが、どう直せばいいもんだか。 ほぼ[ruby-list:14746]と同じ内容ですね。 | これって結局、スレッドローカルじゃなきゃいけない$_や$~がスレッ |ド間で共有されなきゃいけないruby_scope->local_varsにある、とい |うところに問題がありそうな気がするんですが、どこに持っていった |らいいのやら。FRAMEあたりかなぁ。 その後、歯磨きしながら考えてたら、以下のパッチで直りそうです。 駆け込みでやや不安なのですが。 --- ../ruby1.6/eval.c Thu Sep 6 16:47:46 2001 +++ eval.c Sat Sep 8 04:32:01 2001 @@ -7154,6 +7267,7 @@ rb_thread_save_context(th) { VALUE *pos; int len; + static VALUE tval; len = stack_length(&pos); th->stk_len = 0; @@ -7181,8 +7295,12 @@ rb_thread_save_context(th) th->tracing = tracing; th->errinfo = ruby_errinfo; th->last_status = rb_last_status; - th->last_line = rb_lastline_get(); - th->last_match = rb_backref_get(); + tval = rb_lastline_get(); + rb_lastline_set(th->last_line); + th->last_line = tval; + tval = rb_backref_get(); + rb_backref_set(th->last_match); + th->last_match = tval; th->safe = ruby_safe_level; th->file = ruby_sourcefile; @@ -7246,6 +7364,7 @@ rb_thread_restore_context(th, exit) VALUE v; static rb_thread_t tmp; static int ex; + static VALUE tval; if (!th->stk_ptr) rb_bug("unsaved context"); @@ -7282,8 +7401,12 @@ rb_thread_restore_context(th, exit) FLUSH_REGISTER_WINDOWS; MEMCPY(tmp->stk_pos, tmp->stk_ptr, VALUE, tmp->stk_len); + tval = rb_lastline_get(); rb_lastline_set(tmp->last_line); + tmp->last_line = tval; + tval = rb_backref_get(); rb_backref_set(tmp->last_match); + tmp->last_match = tval; longjmp(tmp->context, ex); }