ruby-changes:43041
From: nobu <ko1@a...>
Date: Sun, 22 May 2016 17:07:03 +0900 (JST)
Subject: [ruby-changes:43041] nobu:r55115 (trunk): transcode.c: GC guards
nobu 2016-05-22 17:06:57 +0900 (Sun, 22 May 2016) New Revision: 55115 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55115 Log: transcode.c: GC guards * transcode.c (enc_arg, str_transcode_enc_args, econv_args): remove volatile, and add GC guards in callers. [ruby-core:75664] [Bug #12411] Modified files: trunk/ChangeLog trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 55114) +++ ChangeLog (revision 55115) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun May 22 17:06:55 2016 Nobuyoshi Nakada <nobu@r...> + + * transcode.c (enc_arg, str_transcode_enc_args, econv_args): + remove volatile, and add GC guards in callers. + [ruby-core:75664] [Bug #12411] + Sun May 22 16:27:00 2016 Nobuyoshi Nakada <nobu@r...> * ext/-test-/integer/core_ext.c: move testutil/integer.c. Index: transcode.c =================================================================== --- transcode.c (revision 55114) +++ transcode.c (revision 55115) @@ -2607,7 +2607,7 @@ rb_econv_open_opts(const char *source_en https://github.com/ruby/ruby/blob/trunk/transcode.c#L2607 } static int -enc_arg(volatile VALUE *arg, const char **name_p, rb_encoding **enc_p) +enc_arg(VALUE *arg, const char **name_p, rb_encoding **enc_p) { rb_encoding *enc; const char *n; @@ -2631,7 +2631,7 @@ enc_arg(volatile VALUE *arg, const char https://github.com/ruby/ruby/blob/trunk/transcode.c#L2631 } static int -str_transcode_enc_args(VALUE str, volatile VALUE *arg1, volatile VALUE *arg2, +str_transcode_enc_args(VALUE str, VALUE *arg1, VALUE *arg2, const char **sname_p, rb_encoding **senc_p, const char **dname_p, rb_encoding **denc_p) { @@ -2662,7 +2662,7 @@ str_transcode0(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/transcode.c#L2662 { VALUE dest; VALUE str = *self; - volatile VALUE arg1, arg2; + VALUE arg1, arg2; long blen, slen; unsigned char *buf, *bp, *sp; const unsigned char *fromp; @@ -2740,6 +2740,8 @@ str_transcode0(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/transcode.c#L2740 /* set encoding */ if (!denc) { dencidx = rb_define_dummy_encoding(dname); + RB_GC_GUARD(arg1); + RB_GC_GUARD(arg2); } *self = dest; @@ -2992,7 +2994,7 @@ econv_s_asciicompat_encoding(VALUE klass https://github.com/ruby/ruby/blob/trunk/transcode.c#L2994 static void econv_args(int argc, VALUE *argv, - volatile VALUE *snamev_p, volatile VALUE *dnamev_p, + VALUE *snamev_p, VALUE *dnamev_p, const char **sname_p, const char **dname_p, rb_encoding **senc_p, rb_encoding **denc_p, int *ecflags_p, @@ -3136,7 +3138,7 @@ search_convpath_i(const char *sname, con https://github.com/ruby/ruby/blob/trunk/transcode.c#L3138 static VALUE econv_s_search_convpath(int argc, VALUE *argv, VALUE klass) { - volatile VALUE snamev, dnamev; + VALUE snamev, dnamev; const char *sname, *dname; rb_encoding *senc, *denc; int ecflags; @@ -3151,8 +3153,12 @@ econv_s_search_convpath(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/transcode.c#L3153 if (NIL_P(convpath)) rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags)); - if (decorate_convpath(convpath, ecflags) == -1) - rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags)); + if (decorate_convpath(convpath, ecflags) == -1) { + VALUE exc = rb_econv_open_exc(sname, dname, ecflags); + RB_GC_GUARD(snamev); + RB_GC_GUARD(dnamev); + rb_exc_raise(exc); + } return convpath; } @@ -3208,7 +3214,7 @@ rb_econv_init_by_convpath(VALUE self, VA https://github.com/ruby/ruby/blob/trunk/transcode.c#L3214 DATA_PTR(self) = ec; for (i = 0; i < RARRAY_LEN(convpath); i++) { - volatile VALUE snamev, dnamev; + VALUE snamev, dnamev; VALUE pair; elt = rb_ary_entry(convpath, i); if (!NIL_P(pair = rb_check_array_type(elt))) { @@ -3225,8 +3231,12 @@ rb_econv_init_by_convpath(VALUE self, VA https://github.com/ruby/ruby/blob/trunk/transcode.c#L3231 } if (DECORATOR_P(sname, dname)) { ret = rb_econv_add_converter(ec, sname, dname, ec->num_trans); - if (ret == -1) - rb_raise(rb_eArgError, "decoration failed: %s", dname); + if (ret == -1) { + VALUE msg = rb_sprintf("decoration failed: %s", dname); + RB_GC_GUARD(snamev); + RB_GC_GUARD(dnamev); + rb_exc_raise(rb_exc_new_str(rb_eArgError, msg)); + } } else { int j = ec->num_trans; @@ -3235,8 +3245,12 @@ rb_econv_init_by_convpath(VALUE self, VA https://github.com/ruby/ruby/blob/trunk/transcode.c#L3245 arg.index = ec->num_trans; arg.ret = 0; ret = transcode_search_path(sname, dname, rb_econv_init_by_convpath_i, &arg); - if (ret == -1 || arg.ret == -1) - rb_raise(rb_eArgError, "adding conversion failed: %s to %s", sname, dname); + if (ret == -1 || arg.ret == -1) { + VALUE msg = rb_sprintf("adding conversion failed: %s to %s", sname, dname); + RB_GC_GUARD(snamev); + RB_GC_GUARD(dnamev); + rb_exc_raise(rb_exc_new_str(rb_eArgError, msg)); + } if (first) { first = 0; *senc_p = senc; @@ -3370,7 +3384,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/transcode.c#L3384 econv_init(int argc, VALUE *argv, VALUE self) { VALUE ecopts; - volatile VALUE snamev, dnamev; + VALUE snamev, dnamev; const char *sname, *dname; rb_encoding *senc, *denc; rb_econv_t *ec; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/