ruby-changes:34961
From: nobu <ko1@a...>
Date: Sun, 3 Aug 2014 10:56:24 +0900 (JST)
Subject: [ruby-changes:34961] nobu:r47043 (trunk): ext: get rid of inadvertent ID creation
nobu 2014-08-03 10:56:16 +0900 (Sun, 03 Aug 2014) New Revision: 47043 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47043 Log: ext: get rid of inadvertent ID creation Modified files: trunk/ext/-test-/symbol/type.c trunk/ext/objspace/object_tracing.c trunk/ext/objspace/objspace.c trunk/ext/objspace/objspace_dump.c trunk/ext/openssl/ossl_pkcs7.c trunk/ext/strscan/strscan.c trunk/ext/tk/tkutil/tkutil.c Index: ext/objspace/objspace.c =================================================================== --- ext/objspace/objspace.c (revision 47042) +++ ext/objspace/objspace.c (revision 47043) @@ -545,7 +545,7 @@ iow_inspect(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L545 VALUE obj = (VALUE)DATA_PTR(self); VALUE type = type2sym(BUILTIN_TYPE(obj)); - return rb_sprintf("#<InternalObject:%p %s>", (void *)obj, rb_id2name(SYM2ID(type))); + return rb_sprintf("#<InternalObject:%p %"PRIsVALUE">", (void *)obj, rb_sym2str(type)); } /* Returns the Object#object_id of the internal object. */ Index: ext/objspace/objspace_dump.c =================================================================== --- ext/objspace/objspace_dump.c (revision 47042) +++ ext/objspace/objspace_dump.c (revision 47043) @@ -244,8 +244,10 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L244 if ((ainfo = objspace_lookup_allocation_info(obj))) { dump_append(dc, ", \"file\":\"%s\", \"line\":%lu", ainfo->path, ainfo->line); - if (RTEST(ainfo->mid)) - dump_append(dc, ", \"method\":\"%s\"", rb_id2name(SYM2ID(ainfo->mid))); + if (RTEST(ainfo->mid)) { + VALUE m = rb_sym2str(ainfo->mid); + dump_append(dc, ", \"method\":\"%s\"", RSTRING_PTR(m)); + } dump_append(dc, ", \"generation\":%"PRIuSIZE, ainfo->generation); } Index: ext/objspace/object_tracing.c =================================================================== --- ext/objspace/object_tracing.c (revision 47042) +++ ext/objspace/object_tracing.c (revision 47043) @@ -287,7 +287,10 @@ object_allocations_reporter_i(st_data_t https://github.com/ruby/ruby/blob/trunk/ext/objspace/object_tracing.c#L287 if (info->class_path) fprintf(out, "C: %s", info->class_path); else fprintf(out, "C: %p", (void *)info->klass); fprintf(out, "@%s:%lu", info->path ? info->path : "", info->line); - if (!NIL_P(info->mid)) fprintf(out, " (%s)", rb_id2name(SYM2ID(info->mid))); + if (!NIL_P(info->mid)) { + VALUE m = rb_sym2str(info->mid); + fprintf(out, " (%s)", RSTRING_PTR(m)); + } fprintf(out, ")\n"); return ST_CONTINUE; Index: ext/-test-/symbol/type.c =================================================================== --- ext/-test-/symbol/type.c (revision 47042) +++ ext/-test-/symbol/type.c (revision 47043) @@ -38,7 +38,7 @@ bug_sym_attrset(VALUE self, VALUE name) https://github.com/ruby/ruby/blob/trunk/ext/-test-/symbol/type.c#L38 static VALUE bug_id2str(VALUE self, VALUE sym) { - return rb_id2str(SYM2ID(sym)); + return rb_sym2str(sym); } static VALUE Index: ext/tk/tkutil/tkutil.c =================================================================== --- ext/tk/tkutil/tkutil.c (revision 47042) +++ ext/tk/tkutil/tkutil.c (revision 47043) @@ -831,15 +831,15 @@ get_eval_string_core(obj, enc_flag, self https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L831 if (RTEST(enc_flag)) { if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) { return rb_funcall(self, ID_toUTF8, 1, - rb_str_new2(rb_id2name(SYM2ID(obj)))); + rb_str_dup(rb_sym2str(obj))); } else { - return fromDefaultEnc_toUTF8(rb_str_new2(rb_id2name(SYM2ID(obj))), self); + return fromDefaultEnc_toUTF8(rb_sym2str(obj), self); } } else { #ifdef HAVE_RB_SYM_TO_S return rb_sym_to_s(obj); #else - return rb_str_new2(rb_id2name(SYM2ID(obj))); + return rb_sym2str(obj); #endif } @@ -1312,9 +1312,9 @@ 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_id2str(SYM2ID(ret)); + str = rb_sym2str(ret); } else { - str = rb_id2str(SYM2ID(sym)); + str = rb_sym2str(sym); } id = rb_intern_str(rb_sprintf("@%"PRIsVALUE, str)); @@ -1370,26 +1370,30 @@ cbsubst_get_subst_arg(argc, argv, self) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1370 switch(TYPE(argv[i])) { case T_STRING: str = argv[i]; - arg_sym = ID2SYM(rb_intern_str(argv[i])); + arg_sym = rb_check_symbol(&str); + if (NIL_P(arg_sym)) goto not_found; break; case T_SYMBOL: arg_sym = argv[i]; - str = rb_id2str(SYM2ID(arg_sym)); + str = rb_sym2str(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_id2str(SYM2ID(ret)); + str = rb_sym2str(ret); } - id = rb_intern_str(rb_sprintf("@%"PRIsVALUE, str)); + ret = rb_sprintf("@%"PRIsVALUE, str); + id = rb_check_id(&ret); + if (!id) goto not_found; for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) { if (inf->ivar[idx] == id) break; } if (idx >= CBSUBST_TBL_MAX) { + not_found: rb_raise(rb_eArgError, "cannot find attribute :%"PRIsVALUE, str); } Index: ext/openssl/ossl_pkcs7.c =================================================================== --- ext/openssl/ossl_pkcs7.c (revision 47042) +++ ext/openssl/ossl_pkcs7.c (revision 47043) @@ -376,7 +376,10 @@ ossl_pkcs7_sym2typeid(VALUE sym) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkcs7.c#L376 { NULL, 0 }, }; - if (RB_TYPE_P(sym, T_SYMBOL)) s = rb_id2name(SYM2ID(sym)); + if (RB_TYPE_P(sym, T_SYMBOL)) { + sym = rb_sym2str(sym); + s = RSTRING_PTR(sym); + } else s = StringValuePtr(sym); for(i = 0; i < numberof(p7_type_tab); i++){ if(p7_type_tab[i].name == NULL) Index: ext/strscan/strscan.c =================================================================== --- ext/strscan/strscan.c (revision 47042) +++ ext/strscan/strscan.c (revision 47043) @@ -1032,7 +1032,8 @@ strscan_aref(VALUE self, VALUE idx) https://github.com/ruby/ruby/blob/trunk/ext/strscan/strscan.c#L1032 switch (TYPE(idx)) { case T_SYMBOL: - name = rb_id2name(SYM2ID(idx)); + idx = rb_sym2str(idx); + name = RSTRING_PTR(idx); goto name_to_backref; break; case T_STRING: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/