diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-18 09:29:01 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-18 09:29:01 +0000 |
commit | 2cbc7b69b7b5638edae760d57461dd4f4410622d (patch) | |
tree | 48ff0d3f98868bd89bb8d116c2073b165b80c031 | |
parent | d5ec36c486762ea99a443e76af39edb81d91b479 (diff) | |
download | ruby-2cbc7b69b7b5638edae760d57461dd4f4410622d.tar.gz |
* 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
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | transcode.c | 17 |
2 files changed, 24 insertions, 8 deletions
@@ -1,3 +1,18 @@ +Thu Sep 18 18:23:23 2008 Tanaka Akira <akr@fsij.org> + + * 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@ruby-lang.org> * transcode.c: add "Error" suffix for Encoding exception classes. diff --git a/transcode.c b/transcode.c index cd77ddbacd..b82729cb5b 100644 --- a/transcode.c +++ b/transcode.c @@ -2387,16 +2387,17 @@ rb_econv_open_opts(const char *source_encoding, const char *destination_encoding } 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 @@ str_transcode_enc_args(VALUE str, volatile VALUE *arg1, volatile VALUE *arg2, 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 @@ str_transcode_enc_args(VALUE str, volatile VALUE *arg1, volatile VALUE *arg2, 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 @@ econv_s_asciicompat_encoding(VALUE klass, VALUE arg) 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 @@ rb_econv_init_by_convpath(VALUE self, VALUE convpath, 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 = ""; |