rb_id2str over rb_id2name

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-11-25 18:44:22 +00:00
parent d0ac6d5879
commit 606e855622
7 changed files with 32 additions and 29 deletions

View File

@ -699,16 +699,16 @@ rb_define_class_id_under(VALUE outer, ID id, VALUE super)
if (rb_const_defined_at(outer, id)) { if (rb_const_defined_at(outer, id)) {
klass = rb_const_get_at(outer, id); klass = rb_const_get_at(outer, id);
if (!RB_TYPE_P(klass, T_CLASS)) { if (!RB_TYPE_P(klass, T_CLASS)) {
rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id)); rb_raise(rb_eTypeError, "%"PRIsVALUE" is not a class", rb_id2str(id));
} }
if (rb_class_real(RCLASS_SUPER(klass)) != super) { if (rb_class_real(RCLASS_SUPER(klass)) != super) {
rb_name_error(id, "%s is already defined", rb_id2name(id)); rb_name_error(id, "%"PRIsVALUE" is already defined", rb_id2str(id));
} }
return klass; return klass;
} }
if (!super) { if (!super) {
rb_warn("no super class for `%s::%s', Object assumed", rb_warn("no super class for `%"PRIsVALUE"::%"PRIsVALUE"', Object assumed",
rb_class2name(outer), rb_id2name(id)); rb_class_path(outer), rb_id2str(id));
} }
klass = rb_define_class_id(id, super); klass = rb_define_class_id(id, super);
rb_set_class_path_string(klass, outer, rb_id2str(id)); rb_set_class_path_string(klass, outer, rb_id2str(id));

View File

@ -444,7 +444,8 @@ validate_label(st_data_t name, st_data_t label, st_data_t arg)
do { do {
int ret; int ret;
COMPILE_ERROR((ruby_sourcefile, lobj->position, COMPILE_ERROR((ruby_sourcefile, lobj->position,
"%s: undefined label", rb_id2name((ID)name))); "%"PRIsVALUE": undefined label",
rb_id2str((ID)name)));
if (ret) break; if (ret) break;
} while (0); } while (0);
} }
@ -3960,7 +3961,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ID id = node->nd_vid; ID id = node->nd_vid;
int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id); int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id);
debugs("lvar: %s idx: %d\n", rb_id2name(id), idx); debugs("lvar: %"PRIsVALUE" idx: %d\n", rb_id2str(id), idx);
COMPILE(ret, "rvalue", node->nd_value); COMPILE(ret, "rvalue", node->nd_value);
if (!poped) { if (!poped) {
@ -3974,7 +3975,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
case NODE_DASGN_CURR:{ case NODE_DASGN_CURR:{
int idx, lv, ls; int idx, lv, ls;
COMPILE(ret, "dvalue", node->nd_value); COMPILE(ret, "dvalue", node->nd_value);
debugp_param("dassn id", rb_str_new2(rb_id2name(node->nd_vid) ? rb_id2name(node->nd_vid) : "*")); debugi("dassn id", rb_id2str(node->nd_vid) ? node->nd_vid : '*');
if (!poped) { if (!poped) {
ADD_INSN(ret, line, dup); ADD_INSN(ret, line, dup);
@ -3983,7 +3984,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls); idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls);
if (idx < 0) { if (idx < 0) {
rb_bug("NODE_DASGN(_CURR): unknown id (%s)", rb_id2name(node->nd_vid)); rb_bug("NODE_DASGN(_CURR): unknown id (%"PRIsVALUE")", rb_id2str(node->nd_vid));
} }
ADD_INSN2(ret, line, setlocal, INT2FIX(ls - idx), INT2FIX(lv)); ADD_INSN2(ret, line, setlocal, INT2FIX(ls - idx), INT2FIX(lv));
@ -4758,7 +4759,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ID id = node->nd_vid; ID id = node->nd_vid;
int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id); int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id);
debugs("id: %s idx: %d\n", rb_id2name(id), idx); debugs("id: %"PRIsVALUE" idx: %d\n", rb_id2str(id), idx);
ADD_INSN2(ret, line, getlocal, INT2FIX(idx), INT2FIX(get_lvar_level(iseq))); ADD_INSN2(ret, line, getlocal, INT2FIX(idx), INT2FIX(get_lvar_level(iseq)));
} }
break; break;
@ -4769,7 +4770,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
if (!poped) { if (!poped) {
idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls); idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls);
if (idx < 0) { if (idx < 0) {
rb_bug("unknown dvar (%s)", rb_id2name(node->nd_vid)); rb_bug("unknown dvar (%"PRIsVALUE")", rb_id2str(node->nd_vid));
} }
ADD_INSN2(ret, line, getlocal, INT2FIX(ls - idx), INT2FIX(lv)); ADD_INSN2(ret, line, getlocal, INT2FIX(ls - idx), INT2FIX(lv));
} }
@ -5076,7 +5077,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
VALUE iseqval = VALUE iseqval =
NEW_CHILD_ISEQVAL( NEW_CHILD_ISEQVAL(
node->nd_body, node->nd_body,
rb_sprintf("<class:%s>", rb_id2name(node->nd_cpath->nd_mid)), rb_sprintf("<class:%"PRIsVALUE">", rb_id2str(node->nd_cpath->nd_mid)),
ISEQ_TYPE_CLASS, line); ISEQ_TYPE_CLASS, line);
VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath); VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath);
int flags = VM_DEFINECLASS_TYPE_CLASS; int flags = VM_DEFINECLASS_TYPE_CLASS;
@ -5094,7 +5095,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
case NODE_MODULE:{ case NODE_MODULE:{
VALUE iseqval = NEW_CHILD_ISEQVAL( VALUE iseqval = NEW_CHILD_ISEQVAL(
node->nd_body, node->nd_body,
rb_sprintf("<module:%s>", rb_id2name(node->nd_cpath->nd_mid)), rb_sprintf("<module:%"PRIsVALUE">", rb_id2str(node->nd_cpath->nd_mid)),
ISEQ_TYPE_CLASS, line); ISEQ_TYPE_CLASS, line);
VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath); VALUE noscope = compile_cpath(ret, iseq, node->nd_cpath);
@ -5558,7 +5559,7 @@ insn_data_to_s_detail(INSN *iobj)
{ {
struct rb_global_entry *entry = (struct rb_global_entry *) struct rb_global_entry *entry = (struct rb_global_entry *)
(OPERAND_AT(iobj, j) & (~1)); (OPERAND_AT(iobj, j) & (~1));
rb_str_cat2(str, rb_id2name(entry->id)); rb_str_append(str, rb_id2str(entry->id));
break; break;
} }
case TS_IC: /* inline cache */ case TS_IC: /* inline cache */
@ -5567,7 +5568,10 @@ insn_data_to_s_detail(INSN *iobj)
case TS_CALLINFO: /* call info */ case TS_CALLINFO: /* call info */
{ {
rb_call_info_t *ci = (rb_call_info_t *)OPERAND_AT(iobj, j); rb_call_info_t *ci = (rb_call_info_t *)OPERAND_AT(iobj, j);
rb_str_catf(str, "<callinfo:%s, %d>", ci->mid ? rb_id2name(ci->mid) : "", ci->orig_argc); rb_str_cat2(str, "<callinfo:");
if (ci->mid)
rb_str_catf(str, "%"PRIsVALUE, rb_id2str(ci->mid));
rb_str_catf(str, ", %d>", ci->orig_argc);
break; break;
} }
case TS_CDHASH: /* case/when condition cache */ case TS_CDHASH: /* case/when condition cache */

View File

@ -115,7 +115,7 @@ ID
ruby_debug_print_id(int level, int debug_level, const char *header, ID id) ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
{ {
if (level < debug_level) { if (level < debug_level) {
fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id)); fprintf(stderr, "DBG> %s: %"PRIsVALUE"\n", header, rb_id2str(id));
fflush(stderr); fflush(stderr);
} }
return id; return id;

View File

@ -1952,8 +1952,8 @@ void
rb_notimplement(void) rb_notimplement(void)
{ {
rb_raise(rb_eNotImpError, rb_raise(rb_eNotImpError,
"%s() function is unimplemented on this machine", "%"PRIsVALUE"() function is unimplemented on this machine",
rb_id2name(rb_frame_this_func())); rb_id2str(rb_frame_this_func()));
} }
void void

View File

@ -22,20 +22,20 @@ warn_printf(const char *fmt, ...)
static void static void
error_pos(void) error_pos(void)
{ {
const char *sourcefile = rb_sourcefile(); VALUE sourcefile = rb_sourcefilename();
int sourceline = rb_sourceline(); int sourceline = rb_sourceline();
if (sourcefile) { if (sourcefile) {
ID caller_name; ID caller_name;
if (sourceline == 0) { if (sourceline == 0) {
warn_printf("%s", sourcefile); warn_printf("%"PRIsVALUE, sourcefile);
} }
else if ((caller_name = rb_frame_callee()) != 0) { else if ((caller_name = rb_frame_callee()) != 0) {
warn_printf("%s:%d:in `%s'", sourcefile, sourceline, warn_printf("%"PRIsVALUE":%d:in `%"PRIsVALUE"'", sourcefile, sourceline,
rb_id2name(caller_name)); rb_id2str(caller_name));
} }
else { else {
warn_printf("%s:%d", sourcefile, sourceline); warn_printf("%"PRIsVALUE":%d", sourcefile, sourceline);
} }
} }
} }

2
gc.c
View File

@ -2717,7 +2717,7 @@ id2ref(VALUE obj, VALUE objid)
if ((ptr % sizeof(RVALUE)) == (4 << 2)) { if ((ptr % sizeof(RVALUE)) == (4 << 2)) {
ID symid = ptr / sizeof(RVALUE); ID symid = ptr / sizeof(RVALUE);
if (rb_id2name(symid) == 0) if (rb_id2str(symid) == 0)
rb_raise(rb_eRangeError, "%p is not symbol id value", p0); rb_raise(rb_eRangeError, "%p is not symbol id value", p0);
return ID2SYM(symid); return ID2SYM(symid);
} }

11
vm.c
View File

@ -1729,15 +1729,14 @@ rb_thread_current_status(const rb_thread_t *th)
if (cfp->pc != 0) { if (cfp->pc != 0) {
rb_iseq_t *iseq = cfp->iseq; rb_iseq_t *iseq = cfp->iseq;
int line_no = rb_vm_get_sourceline(cfp); int line_no = rb_vm_get_sourceline(cfp);
char *file = RSTRING_PTR(iseq->location.path); str = rb_sprintf("%"PRIsVALUE":%d:in `%"PRIsVALUE"'",
str = rb_sprintf("%s:%d:in `%s'", iseq->location.path, line_no, iseq->location.label);
file, line_no, RSTRING_PTR(iseq->location.label));
} }
} }
else if (cfp->me->def->original_id) { else if (cfp->me->def->original_id) {
str = rb_sprintf("`%s#%s' (cfunc)", str = rb_sprintf("`%"PRIsVALUE"#%"PRIsVALUE"' (cfunc)",
rb_class2name(cfp->me->klass), rb_class_path(cfp->me->klass),
rb_id2name(cfp->me->def->original_id)); rb_id2str(cfp->me->def->original_id));
} }
return str; return str;