[#36672] [Bug #616] instance_eval and Module#to_s — Shyouhei Urabe <redmine@...>

Bug #616: instance_eval and Module#to_s

12 messages 2008/10/06

[#36750] [Bug #650] Marshal.load raises RegexpError — Shyouhei Urabe <redmine@...>

Bug #650: Marshal.load raises RegexpError

30 messages 2008/10/15
[#36769] Re: [Bug #650] Marshal.load raises RegexpError — Yukihiro Matsumoto <matz@...> 2008/10/17

まつもと ゆきひろです

[#36771] Re: [Bug #650] Marshal.load raises RegexpError — Urabe Shyouhei <shyouhei@...> 2008/10/17

卜部です。

[#36772] Re: [Bug #650] Marshal.load raises RegexpError — Yukihiro Matsumoto <matz@...> 2008/10/17

まつもと ゆきひろです

[#36773] Re: [Bug #650] Marshal.load raises RegexpError — Urabe Shyouhei <shyouhei@...> 2008/10/17

卜部です。

[#36784] Re: [Bug #650] Marshal.load raises RegexpError — Yukihiro Matsumoto <matz@...> 2008/10/18

まつもと ゆきひろです

[#36785] Re: [Bug #650] Marshal.load raises RegexpError — Urabe Shyouhei <shyouhei@...> 2008/10/18

卜部です。

[#36793] Re: [Bug #650] Marshal.load raises RegexpError — Yukihiro Matsumoto <matz@...> 2008/10/19

まつもと ゆきひろです

[#36794] Re: [Bug #650] Marshal.load raises RegexpError — Urabe Shyouhei <shyouhei@...> 2008/10/19

Yukihiro Matsumoto さんは書きました:

[#36823] Re: [Bug #650] Marshal.load raises RegexpError — Yukihiro Matsumoto <matz@...> 2008/10/21

まつもと ゆきひろです

[#36830] Re: [Bug #650] Marshal.load raises RegexpError — Urabe Shyouhei <shyouhei@...> 2008/10/21

もとの正規表現にバグがあるのは認めますが、それに巻き込まれてでかいPStore

[#36833] Re: [Bug #650] Marshal.load raises RegexpError — Yukihiro Matsumoto <matz@...> 2008/10/21

まつもと ゆきひろです

[#36764] Re: [ruby-cvs:27036] Ruby:r19818 (trunk): * transcode.c (str_transcode0): String#encode without argument now — Martin Duerst <duerst@...>

まつもとさん、こんばんは。

11 messages 2008/10/17
[#36767] Re: [ruby-cvs:27036] Ruby:r19818 (trunk): * transcode.c (str_transcode0): String#encode without argument now — Yukihiro Matsumoto <matz@...> 2008/10/17

まつもと ゆきひろです

[#36799] Re: [ruby-cvs:27036] Ruby:r19818 (trunk): * transcode.c (str_transcode0): String#encode without argument now — Martin Duerst <duerst@...> 2008/10/20

まつもとさん、こんにちは。

[#36774] ConverterNotFoundError while making Ruby in Windows(trunk) — Masaki Suketa <masaki.suketa@...>

助田です。

13 messages 2008/10/17
[#36797] Re: ConverterNotFoundError while making Ruby in Windows(trunk) — "U.Nakamura" <usa@...> 2008/10/20

こんにちは、なかむら(う)です。

[#36800] Re: ConverterNotFoundError while making Ruby in Windows(trunk) — "U.Nakamura" <usa@...> 2008/10/20

こんにちは、なかむら(う)です。

[#36789] [Bug #660] 数字を3桁ずつコンマで区切るsprintf書式指定 — "rubikitch ." <redmine@...>

Bug #660: 数字を3桁ずつコンマで区切るsprintf書式指定

13 messages 2008/10/19

[#37007] [Bug:1.9] 1+1+1+...+1 dumps core — "Yusuke ENDOH" <mame@...>

遠藤です。

13 messages 2008/10/31

[ruby-dev:36974] Re: initial value of $.

From: Nobuyoshi Nakada <nobu@...>
Date: 2008-10-28 08:06:27 UTC
List: ruby-dev #36974
なかだです。

At Tue, 28 Oct 2008 01:10:42 +0900,
Yukihiro Matsumoto wrote in [ruby-dev:36959]:
> となると、「スレッドローカルにする」というのは互換性問題が発
> 生しにくい上に、問題も生じにくい妥協点かもしれません。が、今
> のままでも別に困ってないのも事実なので、rb_loadの修正だけで
> 十分と言うのももっともな気がします。

他のメソッドとの干渉を防げるという点ではsvarにするというのもいい
のではないかと思いますが、スレッドローカルにするパッチです。

ついでに、rewindのときの$.の動作は少しおかしいような気もします。


Index: io.c
===================================================================
--- io.c	(revision 19983)
+++ io.c	(working copy)
@@ -122,5 +122,5 @@ VALUE rb_default_rs;
 static VALUE argf;
 
-static ID id_write, id_read, id_getc, id_flush, id_readpartial;
+static ID id_write, id_read, id_getc, id_flush, id_readpartial, id_lineno;
 static VALUE sym_mode, sym_perm, sym_extenc, sym_intenc, sym_encoding, sym_open_args;
 static VALUE sym_textmode, sym_binmode;
@@ -132,5 +132,4 @@ struct argf {
     int gets_lineno;
     int init_p, next_p;
-    VALUE lineno;
     VALUE argv;
     char *inplace;
@@ -198,4 +197,18 @@ static int max_file_descriptor = NOFILE;
 #define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
 
+static VALUE
+get_last_lineno(void)
+{
+    VALUE n = rb_thread_local_aref(rb_thread_current(), id_lineno);
+    if (NIL_P(n)) return INT2FIX(0);
+    return n;
+}
+
+static VALUE
+set_last_lineno(int num)
+{
+    return rb_thread_local_aset(rb_thread_current(), id_lineno, INT2FIX(num));
+}
+
 #if defined(_WIN32)
 #define is_socket(fd, path)	rb_w32_is_socket(fd)
@@ -1079,7 +1092,4 @@ rb_io_rewind(VALUE io)
     GetOpenFile(io, fptr);
     if (io_seek(fptr, 0L, 0) < 0) rb_sys_fail_path(fptr->pathv);
-    if (io == ARGF.current_file) {
-	ARGF.gets_lineno -= fptr->lineno;
-    }
     fptr->lineno = 0;
 
@@ -2085,5 +2095,5 @@ rb_io_getline_fast(rb_io_t *fptr, rb_enc
     ENC_CODERANGE_SET(str, cr);
     fptr->lineno++;
-    ARGF.lineno = INT2FIX(fptr->lineno);
+    set_last_lineno(fptr->lineno);
     return str;
 }
@@ -2220,5 +2230,5 @@ rb_io_getline_1(VALUE rs, long limit, VA
 	if (!nolimit) {
 	    fptr->lineno++;
-	    ARGF.lineno = INT2FIX(fptr->lineno);
+	    set_last_lineno(fptr->lineno);
 	}
     }
@@ -5805,5 +5815,4 @@ argf_mark(void *ptr)
     rb_gc_mark(p->filename);
     rb_gc_mark(p->current_file);
-    rb_gc_mark(p->lineno);
     rb_gc_mark(p->argv);
     rb_gc_mark(p->encs.ecopts);
@@ -5822,5 +5831,5 @@ argf_init(struct argf *p, VALUE v)
     p->filename = Qnil;
     p->current_file = Qnil;
-    p->lineno = INT2FIX(0);
+    p->gets_lineno = 0;
     p->argv = v;
 }
@@ -5863,6 +5872,7 @@ static VALUE
 argf_set_lineno(VALUE argf, VALUE val)
 {
-    ARGF.gets_lineno = NUM2INT(val);
-    ARGF.lineno = INT2FIX(ARGF.gets_lineno);
+    int n = NUM2INT(val);
+    ARGF.gets_lineno = n;
+    set_last_lineno(n);
     return Qnil;
 }
@@ -5871,5 +5881,5 @@ static VALUE
 argf_lineno(VALUE argf)
 {
-    return ARGF.lineno;
+    return INT2FIX(ARGF.gets_lineno);
 }
 
@@ -6050,5 +6060,5 @@ argf_getline(int argc, VALUE *argv, VALU
     if (!NIL_P(line)) {
 	ARGF.gets_lineno++;
-	ARGF.lineno = INT2FIX(ARGF.gets_lineno);
+	set_last_lineno(ARGF.gets_lineno);
     }
     return line;
@@ -6058,6 +6068,5 @@ static VALUE
 argf_lineno_getter(ID id, VALUE *var)
 {
-    VALUE argf = *var;
-    return ARGF.lineno;
+    return get_last_lineno();
 }
 
@@ -6068,5 +6077,5 @@ argf_lineno_setter(VALUE val, ID id, VAL
     int n = NUM2INT(val);
     ARGF.gets_lineno = n;
-    ARGF.lineno = INT2FIX(n);
+    set_last_lineno(n);
 }
 
@@ -6145,5 +6154,5 @@ rb_gets(void)
     if (!NIL_P(line)) {
 	ARGF.gets_lineno++;
-	ARGF.lineno = INT2FIX(ARGF.gets_lineno);
+	set_last_lineno(ARGF.gets_lineno);
     }
 
@@ -7756,9 +7765,19 @@ static VALUE
 argf_rewind(VALUE argf)
 {
+    rb_io_t *fptr;
+    VALUE io, ret;
+    int lineno = 0;
+
     if (!next_argv()) {
 	rb_raise(rb_eArgError, "no stream to rewind");
     }
     ARGF_FORWARD(0, 0);
-    return rb_io_rewind(ARGF.current_file);
+    io = ARGF.current_file;
+    GetOpenFile(io, fptr);
+    lineno = fptr->lineno;
+    ret = rb_io_rewind(io);
+    ARGF.gets_lineno -= lineno;
+    set_last_lineno(ARGF.gets_lineno);
+    return ret;
 }
 
@@ -8253,4 +8272,5 @@ Init_IO(void)
     id_flush = rb_intern("flush");
     id_readpartial = rb_intern("readpartial");
+    id_lineno = rb_intern("$.");
 
     rb_define_global_function("syscall", rb_f_syscall, -1);
Index: test/ruby/test_argf.rb
===================================================================
--- test/ruby/test_argf.rb	(revision 19983)
+++ test/ruby/test_argf.rb	(working copy)
@@ -63,13 +63,13 @@ class TestArgf < Test::Unit::TestCase
       a.rewind
       b.rewind
-      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["1", 1, "1", 3]
-      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["2", 2, "2", 4]
-      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["3", 3, "3", 5]
-      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["4", 4, "4", 6]
-      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 7]
+      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["1", 1, "1", 1]
+      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["2", 2, "2", 2]
+      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["3", 3, "3", 3]
+      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["4", 4, "4", 4]
+      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 5]
       a.rewind
       b.rewind
-      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 8]
-      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["6", 6, "6", 9]
+      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 5]
+      p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["6", 6, "6", 6]
     SRC
     expected = src.scan(/\#=> *(.*+)/).flatten
@@ -91,8 +91,8 @@ class TestArgf < Test::Unit::TestCase
       a.gets; p $.  #=> 2
       a.gets; p $.  #=> 3
-      a.rewind; p $.  #=> 3
+      a.rewind; p $.  #=> 2
       a.gets; p $.  #=> 3
       a.gets; p $.  #=> 4
-      a.rewind; p $.  #=> 4
+      a.rewind; p $.  #=> 2
       a.gets; p $.  #=> 3
       a.lineno = 1000; p $.  #=> 1000
@@ -114,12 +114,12 @@ class TestArgf < Test::Unit::TestCase
       a.gets; p $.  #=> 1
       a.gets; p $.  #=> 2
-      a.gets; p $.  #=> 1
-      a.rewind; p $.  #=> 1
-      a.gets; p $.  #=> 1
-      a.gets; p $.  #=> 2
-      a.gets; p $.  #=> 1
-      a.lineno = 1000; p $.  #=> 1
-      a.gets; p $.  #=> 2
-      a.gets; p $.  #=> 2
+      a.gets; p $.  #=> 3
+      a.rewind; p $.  #=> 2
+      a.gets; p $.  #=> 3
+      a.gets; p $.  #=> 4
+      a.gets; p $.  #=> 5
+      a.lineno = 1000; p $.  #=> 1000
+      a.gets; p $.  #=> 1001
+      a.gets; p $.  #=> 1001
       $. = 2000
       a.gets; p $.  #=> 2000


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next