ruby-changes:29299
From: nobu <ko1@a...>
Date: Mon, 17 Jun 2013 17:00:07 +0900 (JST)
Subject: [ruby-changes:29299] nobu:r41351 (trunk): tkutil.c: prevent temporary objects from GC
nobu 2013-06-17 16:59:55 +0900 (Mon, 17 Jun 2013) New Revision: 41351 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41351 Log: tkutil.c: prevent temporary objects from GC * ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and rb_intern_str() instead of rb_intern() and RSTRING_PTR() with RB_GC_GUARD(), to prevent temporary objects from GC. [ruby-core:39000] [Bug #5199] Modified files: trunk/ChangeLog trunk/ext/tk/tkutil/tkutil.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41350) +++ ChangeLog (revision 41351) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jun 17 16:59:53 2013 Nobuyoshi Nakada <nobu@r...> + + * ext/tk/tkutil/tkutil.c: use rb_sprintf(), rb_id2str(), and + rb_intern_str() instead of rb_intern() and RSTRING_PTR() with + RB_GC_GUARD(), to prevent temporary objects from GC. + [ruby-core:39000] [Bug #5199] + Mon Jun 17 14:27:54 2013 Zachary Scott <zachary@z...> * vm_backtrace.c: Update rdoc for Backtrace#label with @_ko1 Index: ext/tk/tkutil/tkutil.c =================================================================== --- ext/tk/tkutil/tkutil.c (revision 41350) +++ ext/tk/tkutil/tkutil.c (revision 41351) @@ -897,8 +897,7 @@ get_eval_string_core(obj, enc_flag, self https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L897 } } - rb_warning("fail to convert '%s' to string for Tk", - RSTRING_PTR(rb_funcall(obj, rb_intern("inspect"), 0, 0))); + rb_warning("fail to convert '%+"PRIsVALUE"' to string for Tk", obj); return obj; } @@ -1248,7 +1247,7 @@ each_attr_def(key, value, klass) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1247 switch(TYPE(key)) { case T_STRING: - key_id = rb_intern(RSTRING_PTR(key)); + key_id = rb_intern_str(key); break; case T_SYMBOL: key_id = SYM2ID(key); @@ -1260,7 +1259,7 @@ each_attr_def(key, value, klass) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1259 switch(TYPE(value)) { case T_STRING: - value_id = rb_intern(RSTRING_PTR(value)); + value_id = rb_intern_str(value); break; case T_SYMBOL: value_id = SYM2ID(value); @@ -1300,7 +1299,7 @@ cbsubst_sym_to_subst(self, sym) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1299 VALUE sym; { struct cbsubst_info *inf; - const char *str; + VALUE str; char *buf, *ptr; int idx; long len; @@ -1313,12 +1312,12 @@ cbsubst_sym_to_subst(self, sym) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1312 struct cbsubst_info, inf); if (!NIL_P(ret = rb_hash_aref(inf->aliases, sym))) { - str = rb_id2name(SYM2ID(ret)); + str = rb_id2str(SYM2ID(ret)); } else { - str = rb_id2name(SYM2ID(sym)); + str = rb_id2str(SYM2ID(sym)); } - id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str))); + id = rb_intern_str(rb_sprintf("@%"PRIsVALUE, str)); for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) { if (inf->ivar[idx] == id) break; @@ -1355,7 +1354,7 @@ cbsubst_get_subst_arg(argc, argv, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1354 VALUE self; { struct cbsubst_info *inf; - const char *str; + VALUE str; char *buf, *ptr; int i, idx; long len; @@ -1370,28 +1369,28 @@ cbsubst_get_subst_arg(argc, argv, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1369 for(i = 0; i < argc; i++) { switch(TYPE(argv[i])) { case T_STRING: - str = RSTRING_PTR(argv[i]); - arg_sym = ID2SYM(rb_intern(str)); + str = argv[i]; + arg_sym = ID2SYM(rb_intern_str(argv[i])); break; case T_SYMBOL: arg_sym = argv[i]; - str = rb_id2name(SYM2ID(arg_sym)); + str = rb_id2str(SYM2ID(arg_sym)); break; default: rb_raise(rb_eArgError, "arg #%d is not a String or a Symbol", i); } if (!NIL_P(ret = rb_hash_aref(inf->aliases, arg_sym))) { - str = rb_id2name(SYM2ID(ret)); + str = rb_id2str(SYM2ID(ret)); } - id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str))); + id = rb_intern_str(rb_sprintf("@%"PRIsVALUE, str)); for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) { if (inf->ivar[idx] == id) break; } if (idx >= CBSUBST_TBL_MAX) { - rb_raise(rb_eArgError, "cannot find attribute :%s", str); + rb_raise(rb_eArgError, "cannot find attribute :%"PRIsVALUE, str); } *(ptr++) = '%'; @@ -1573,7 +1572,7 @@ cbsubst_table_setup(argc, argv, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1572 subst_inf->full_subst_length += 3; id = SYM2ID(RARRAY_PTR(inf)[2]); - subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id)))); + subst_inf->ivar[chr] = rb_intern_str(rb_sprintf("@%"PRIsVALUE, rb_id2str(id))); rb_attr(self, id, 1, 0, Qtrue); } @@ -1612,7 +1611,7 @@ cbsubst_table_setup(argc, argv, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1611 subst_inf->full_subst_length += (subst_inf->keylen[chr] + 2); id = SYM2ID(RARRAY_PTR(inf)[2]); - subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id)))); + subst_inf->ivar[chr] = rb_intern_str(rb_sprintf("@%"PRIsVALUE, rb_id2str(id))); rb_attr(self, id, 1, 0, Qtrue); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/