ext: get rid of inadvertent ID creation

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-08-03 01:56:16 +00:00
parent 1d670ab0f0
commit 27c4fb3361
7 changed files with 29 additions and 16 deletions

View File

@ -38,7 +38,7 @@ bug_sym_attrset(VALUE self, VALUE name)
static VALUE
bug_id2str(VALUE self, VALUE sym)
{
return rb_id2str(SYM2ID(sym));
return rb_sym2str(sym);
}
static VALUE

View File

@ -287,7 +287,10 @@ object_allocations_reporter_i(st_data_t key, st_data_t val, st_data_t ptr)
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;

View File

@ -545,7 +545,7 @@ iow_inspect(VALUE self)
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. */

View File

@ -244,8 +244,10 @@ dump_object(VALUE obj, struct dump_config *dc)
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);
}

View File

@ -376,7 +376,10 @@ ossl_pkcs7_sym2typeid(VALUE sym)
{ 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)

View File

@ -1032,7 +1032,8 @@ strscan_aref(VALUE self, VALUE idx)
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:

View File

@ -831,15 +831,15 @@ get_eval_string_core(obj, enc_flag, self)
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)
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)
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);
}