ruby-changes:7887
From: akr <ko1@a...>
Date: Thu, 18 Sep 2008 18:29:22 +0900 (JST)
Subject: [ruby-changes:7887] Ruby:r19408 (trunk): * transcode.c (enc_arg): must take pointer argument to avoid GC
akr 2008-09-18 18:29:01 +0900 (Thu, 18 Sep 2008) New Revision: 19408 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19408 Log: * transcode.c (enc_arg): must take pointer argument to avoid GC problem. StringValueCStr modifies the argument and it should be preserved while the string StringValueCStr returns is used. Since the string is used by caller, the modified argument should be hold by caller. Actually GC.stress = true def (o=Object.new).to_str() "universal"+"_newline" end "\u3042".encode(o, "")' causes curious warning: rb_define_const: invalid name `' for constant Modified files: trunk/ChangeLog trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 19407) +++ ChangeLog (revision 19408) @@ -1,3 +1,18 @@ +Thu Sep 18 18:23:23 2008 Tanaka Akira <akr@f...> + + * transcode.c (enc_arg): must take pointer argument to avoid GC + problem. StringValueCStr modifies the argument and it should be + preserved while the string StringValueCStr returns is used. + Since the string is used by caller, the modified argument should be + hold by caller. Actually + GC.stress = true + def (o=Object.new).to_str() + "universal"+"_newline" + end + "\u3042".encode(o, "")' + causes curious warning: + rb_define_const: invalid name `' for constant + Thu Sep 18 17:32:44 2008 Yukihiro Matsumoto <matz@r...> * transcode.c: add "Error" suffix for Encoding exception classes. Index: transcode.c =================================================================== --- transcode.c (revision 19407) +++ transcode.c (revision 19408) @@ -2387,16 +2387,17 @@ } static int -enc_arg(VALUE arg, const char **name_p, rb_encoding **enc_p) +enc_arg(volatile VALUE *arg, const char **name_p, rb_encoding **enc_p) { rb_encoding *enc; const char *n; int encidx; + VALUE encval; - if ((encidx = rb_to_encoding_index(arg)) < 0) { + if ((encidx = rb_to_encoding_index(encval = *arg)) < 0) { enc = NULL; encidx = 0; - n = StringValueCStr(arg); + n = StringValueCStr(*arg); } else { enc = rb_enc_from_index(encidx); @@ -2418,7 +2419,7 @@ const char *sname, *dname; int sencidx, dencidx; - dencidx = enc_arg(*arg1, &dname, &denc); + dencidx = enc_arg(arg1, &dname, &denc); if (NIL_P(*arg2)) { sencidx = rb_enc_get_index(str); @@ -2426,7 +2427,7 @@ sname = rb_enc_name(senc); } else { - sencidx = enc_arg(*arg2, &sname, &senc); + sencidx = enc_arg(arg2, &sname, &senc); } *sname_p = sname; @@ -2670,7 +2671,7 @@ const char *arg_name, *result_name; rb_encoding *arg_enc, *result_enc; - enc_arg(arg, &arg_name, &arg_enc); + enc_arg(&arg, &arg_name, &arg_enc); result_name = rb_econv_asciicompat_encoding(arg_name); @@ -2881,9 +2882,9 @@ if (RARRAY_LEN(pair) != 2) rb_raise(rb_eArgError, "not a 2-element array in convpath"); snamev = rb_ary_entry(pair, 0); - enc_arg(snamev, &sname, &senc); + enc_arg(&snamev, &sname, &senc); dnamev = rb_ary_entry(pair, 1); - enc_arg(dnamev, &dname, &denc); + enc_arg(&dnamev, &dname, &denc); } else { sname = ""; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/