1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-05-22 08:06:57 +00:00
parent 006634b489
commit 6ce18e3a8b
2 changed files with 33 additions and 13 deletions

View file

@ -1,3 +1,9 @@
Sun May 22 17:06:55 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* ext/-test-/integer/core_ext.c: move testutil/integer.c.

View file

@ -2607,7 +2607,7 @@ rb_econv_open_opts(const char *source_encoding, const char *destination_encoding
}
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 **name_p, rb_encoding **enc_p)
}
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, VALUE *self, int ecflags, VALUE ecopts)
{
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, VALUE *self, int ecflags, VALUE ecopts)
/* 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, VALUE arg)
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, const char *dname, int depth, void *arg)
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 *argv, VALUE klass)
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, VALUE convpath,
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, VALUE convpath,
}
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, VALUE convpath,
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
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;