From 6f02547d83ec4651999b55f606672084cb0fe22b Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 22 Dec 2012 15:04:57 +0000 Subject: internal.h: quote unprintable * internal.h (QUOTE, QUOTE_ID): quote unprintable chars in strings and IDs. [Bug #7574] [ruby-dev:46749] * string.c (rb_str_quote_unprintable): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++ eval_error.c | 12 ++--- internal.h | 4 ++ object.c | 68 +++++++++++++++--------- proc.c | 4 +- string.c | 26 ++++++++++ test/ruby/test_module.rb | 8 ++- variable.c | 131 ++++++++++++++++++++++++++--------------------- vm_method.c | 4 +- 9 files changed, 168 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63eace45df..c1c8f52106 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Dec 23 00:04:54 2012 Nobuyoshi Nakada + + * internal.h (QUOTE, QUOTE_ID): quote unprintable chars in strings and + IDs. [Bug #7574] [ruby-dev:46749] + + * string.c (rb_str_quote_unprintable): ditto. + Sat Dec 22 23:59:18 2012 Nobuyoshi Nakada * error.c (rb_compile_error, rb_compile_warn, rb_compile_warning), diff --git a/eval_error.c b/eval_error.c index 76140fcded..c7ccf82a0a 100644 --- a/eval_error.c +++ b/eval_error.c @@ -213,19 +213,19 @@ rb_print_undef(VALUE klass, ID id, int scope) case NOEX_PRIVATE: v = " private"; break; case NOEX_PROTECTED: v = " protected"; break; } - rb_name_error(id, "undefined%s method `%s' for %s `%s'", v, - rb_id2name(id), + rb_name_error(id, "undefined%s method `%"PRIsVALUE"' for %s `%"PRIsVALUE"'", v, + QUOTE_ID(id), (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class", - rb_class2name(klass)); + rb_class_name(klass)); } void rb_print_undef_str(VALUE klass, VALUE name) { - rb_name_error_str(name, "undefined method `%s' for %s `%s'", - RSTRING_PTR(name), + rb_name_error_str(name, "undefined method `%"PRIsVALUE"' for %s `%"PRIsVALUE"'", + QUOTE(name), (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class", - rb_class2name(klass)); + rb_class_name(klass)); } static int diff --git a/internal.h b/internal.h index 4ae0edf4b6..2c407d52c5 100644 --- a/internal.h +++ b/internal.h @@ -265,6 +265,10 @@ size_t rb_strftime(char *s, size_t maxsize, const char *format, rb_encoding *enc /* string.c */ int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p); int rb_str_symname_p(VALUE); +VALUE rb_str_quote_unprintable(VALUE); +VALUE rb_id_quote_unprintable(ID); +#define QUOTE(str) rb_str_quote_unprintable(str) +#define QUOTE_ID(id) rb_id_quote_unprintable(id) /* struct.c */ VALUE rb_struct_init_copy(VALUE copy, VALUE s); diff --git a/object.c b/object.c index 896c6047f1..8c85e0d657 100644 --- a/object.c +++ b/object.c @@ -1931,7 +1931,8 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) if (p >= pend || !*p) { wrong_name: - rb_raise(rb_eNameError, "wrong constant name %s", path); + rb_raise(rb_eNameError, "wrong constant name %"PRIsVALUE, + QUOTE(name)); } if (p + 2 < pend && p[0] == ':' && p[1] == ':') { @@ -1943,13 +1944,14 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) while (p < pend) { VALUE part; - long len; + long len, beglen; while (p < pend && *p != ':') p++; if (pbeg == p) goto wrong_name; id = rb_check_id_cstr(pbeg, len = p-pbeg, enc); + beglen = pbeg-path; if (p < pend && p[0] == ':') { if (!nestable) goto wrong_name; @@ -1959,26 +1961,29 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) } if (!RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) { - rb_raise(rb_eTypeError, "%s does not refer to class/module", path); + rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module", + QUOTE(name)); } if (!id) { if (!ISUPPER(*pbeg) || !rb_enc_symname2_p(pbeg, len, enc)) { - part = rb_str_subseq(name, pbeg-path, len); - rb_name_error_str(part, "wrong constant name %s", RSTRING_PTR(part)); + part = rb_str_subseq(name, beglen, len); + rb_name_error_str(part, "wrong constant name %"PRIsVALUE, + QUOTE(part)); } else if (!rb_method_basic_definition_p(CLASS_OF(mod), id_const_missing)) { id = rb_intern3(pbeg, len, enc); } else { - part = rb_str_subseq(name, pbeg-path, len); - rb_name_error_str(part, "uninitialized constant %.*s%s", - rb_long2int(pbeg-path), path, - RSTRING_PTR(part)); + part = rb_str_subseq(name, beglen, len); + rb_name_error_str(part, "uninitialized constant %"PRIsVALUE"%"PRIsVALUE, + rb_str_subseq(name, 0, beglen), + QUOTE(part)); } } if (!rb_is_const_id(id)) { - rb_name_error(id, "wrong constant name %s", rb_id2name(id)); + rb_name_error(id, "wrong constant name %"PRIsVALUE, + QUOTE_ID(id)); } mod = RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id); } @@ -2004,7 +2009,8 @@ rb_mod_const_set(VALUE mod, VALUE name, VALUE value) ID id = rb_to_id(name); if (!rb_is_const_id(id)) { - rb_name_error(id, "wrong constant name %s", rb_id2name(id)); + rb_name_error(id, "wrong constant name %"PRIsVALUE, + QUOTE_ID(id)); } rb_const_set(mod, id, value); return value; @@ -2043,11 +2049,13 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod) return Qfalse; } else { - rb_name_error_str(name, "wrong constant name %s", RSTRING_PTR(name)); + rb_name_error_str(name, "wrong constant name %"PRIsVALUE, + QUOTE(name)); } } if (!rb_is_const_id(id)) { - rb_name_error(id, "wrong constant name %s", rb_id2name(id)); + rb_name_error(id, "wrong constant name %"PRIsVALUE, + QUOTE_ID(id)); } return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id); } @@ -2082,11 +2090,13 @@ rb_obj_ivar_get(VALUE obj, VALUE iv) return Qnil; } else { - rb_name_error_str(iv, "`%s' is not allowed as an instance variable name", RSTRING_PTR(iv)); + rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name", + QUOTE(iv)); } } if (!rb_is_instance_id(id)) { - rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id)); + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name", + QUOTE_ID(id)); } return rb_ivar_get(obj, id); } @@ -2117,7 +2127,8 @@ rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val) ID id = rb_to_id(iv); if (!rb_is_instance_id(id)) { - rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id)); + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name", + QUOTE_ID(id)); } return rb_ivar_set(obj, id, val); } @@ -2150,11 +2161,13 @@ rb_obj_ivar_defined(VALUE obj, VALUE iv) return Qfalse; } else { - rb_name_error_str(iv, "`%s' is not allowed as an instance variable name", RSTRING_PTR(iv)); + rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name", + QUOTE(iv)); } } if (!rb_is_instance_id(id)) { - rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id)); + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name", + QUOTE_ID(id)); } return rb_ivar_defined(obj, id); } @@ -2180,15 +2193,17 @@ rb_mod_cvar_get(VALUE obj, VALUE iv) if (!id) { if (rb_is_class_name(iv)) { - rb_name_error_str(iv, "uninitialized class variable %s in %s", - RSTRING_PTR(iv), rb_class2name(obj)); + rb_name_error_str(iv, "uninitialized class variable %"PRIsVALUE" in %"PRIsVALUE"", + iv, rb_class_name(obj)); } else { - rb_name_error_str(iv, "`%s' is not allowed as a class variable name", RSTRING_PTR(iv)); + rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name", + QUOTE(iv)); } } if (!rb_is_class_id(id)) { - rb_name_error(id, "`%s' is not allowed as a class variable name", rb_id2name(id)); + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name", + QUOTE_ID(id)); } return rb_cvar_get(obj, id); } @@ -2216,7 +2231,8 @@ rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val) ID id = rb_to_id(iv); if (!rb_is_class_id(id)) { - rb_name_error(id, "`%s' is not allowed as a class variable name", rb_id2name(id)); + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name", + QUOTE_ID(id)); } rb_cvar_set(obj, id, val); return val; @@ -2246,11 +2262,13 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv) return Qfalse; } else { - rb_name_error_str(iv, "`%s' is not allowed as a class variable name", RSTRING_PTR(iv)); + rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as a class variable name", + QUOTE(iv)); } } if (!rb_is_class_id(id)) { - rb_name_error(id, "`%s' is not allowed as a class variable name", rb_id2name(id)); + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a class variable name", + QUOTE_ID(id)); } return rb_cvar_defined(obj, id); } diff --git a/proc.c b/proc.c index 3dcbf60d31..5b1313a468 100644 --- a/proc.c +++ b/proc.c @@ -1169,8 +1169,8 @@ rb_method_name_error(VALUE klass, VALUE str) else if (RB_TYPE_P(c, T_MODULE)) { s0 = " module"; } - rb_name_error_str(str, "undefined method `%s' for%s `%s'", - RSTRING_PTR(str), s0, rb_class2name(c)); + rb_name_error_str(str, "undefined method `%"PRIsVALUE"' for%s `%"PRIsVALUE"'", + QUOTE(str), s0, rb_class_name(c)); } /* diff --git a/string.c b/string.c index 2033da2165..1e5dab37f1 100644 --- a/string.c +++ b/string.c @@ -4534,6 +4534,7 @@ rb_str_inspect(VALUE str) } } switch (c) { + case '\0': cc = '0'; break; case '\n': cc = 'n'; break; case '\r': cc = 'r'; break; case '\t': cc = 't'; break; @@ -7784,6 +7785,31 @@ rb_str_symname_p(VALUE sym) return TRUE; } +VALUE +rb_str_quote_unprintable(VALUE str) +{ + rb_encoding *enc; + const char *ptr; + long len; + rb_encoding *resenc = rb_default_internal_encoding(); + + if (resenc == NULL) resenc = rb_default_external_encoding(); + enc = STR_ENC_GET(str); + ptr = RSTRING_PTR(str); + len = RSTRING_LEN(str); + if ((resenc != enc && !rb_str_is_ascii_only_p(str)) || + !sym_printable(ptr, ptr + len, enc)) { + return rb_str_inspect(str); + } + return str; +} + +VALUE +rb_id_quote_unprintable(ID id) +{ + return rb_str_quote_unprintable(rb_id2str(id)); +} + /* * call-seq: * sym.inspect -> string diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 8afb34ae78..52f643489c 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -588,7 +588,9 @@ class TestModule < Test::Unit::TestCase assert_raise(NameError) { c1.const_get(:foo) } bug5084 = '[ruby-dev:44200]' assert_raise(TypeError, bug5084) { c1.const_get(1) } - assert_raise(NameError) { Object.const_get("String\0") } + bug7574 = '[ruby-dev:46749]' + e = assert_raise(NameError) { Object.const_get("String\0") } + assert_equal("wrong constant name \"String\\0\"", e.message, bug7574) end def test_const_defined_invalid_name @@ -596,7 +598,9 @@ class TestModule < Test::Unit::TestCase assert_raise(NameError) { c1.const_defined?(:foo) } bug5084 = '[ruby-dev:44200]' assert_raise(TypeError, bug5084) { c1.const_defined?(1) } - assert_raise(NameError) { Object.const_defined?("String\0") } + bug7574 = '[ruby-dev:46749]' + e = assert_raise(NameError) { Object.const_defined?("String\0") } + assert_equal("wrong constant name \"String\\0\"", e.message, bug7574) end def test_const_get_no_inherited diff --git a/variable.c b/variable.c index 6bd447b46c..2597015d50 100644 --- a/variable.c +++ b/variable.c @@ -335,23 +335,26 @@ rb_path_to_class(VALUE pathname) } pbeg = p = path; if (path[0] == '#') { - rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path); + rb_raise(rb_eArgError, "can't retrieve anonymous class %"PRIsVALUE, + QUOTE(pathname)); } while (*p) { while (*p && *p != ':') p++; - id = rb_intern3(pbeg, p-pbeg, enc); + id = rb_check_id_cstr(pbeg, p-pbeg, enc); if (p[0] == ':') { if (p[1] != ':') goto undefined_class; p += 2; pbeg = p; } - if (!rb_const_defined_at(c, id)) { + if (!id || !rb_const_defined_at(c, id)) { undefined_class: - rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path); + rb_raise(rb_eArgError, "undefined class/module %.*"PRIsVALUE, + (int)(p-path), pathname); } c = rb_const_get_at(c, id); if (!RB_TYPE_P(c, T_MODULE) && !RB_TYPE_P(c, T_CLASS)) { - rb_raise(rb_eTypeError, "%s does not refer to class/module", path); + rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module", + pathname); } } RB_GC_GUARD(pathname); @@ -459,7 +462,7 @@ rb_global_entry(ID id) VALUE undef_getter(ID id, void *data, struct global_variable *var) { - rb_warning("global variable `%s' not initialized", rb_id2name(id)); + rb_warning("global variable `%"PRIsVALUE"' not initialized", QUOTE_ID(id)); return Qnil; } @@ -521,7 +524,7 @@ var_marker(VALUE *var) void readonly_setter(VALUE val, ID id, void *data, struct global_variable *gvar) { - rb_name_error(id, "%s is a read-only variable", rb_id2name(id)); + rb_name_error(id, "%"PRIsVALUE" is a read-only variable", QUOTE_ID(id)); } static int @@ -707,10 +710,10 @@ rb_f_untrace_var(int argc, VALUE *argv) rb_scan_args(argc, argv, "11", &var, &cmd); id = rb_check_id(&var); if (!id) { - rb_name_error_str(var, "undefined global variable %s", RSTRING_PTR(var)); + rb_name_error_str(var, "undefined global variable %"PRIsVALUE"", QUOTE(var)); } if (!st_lookup(rb_global_tbl, (st_data_t)id, &data)) { - rb_name_error(id, "undefined global variable %s", rb_id2name(id)); + rb_name_error(id, "undefined global variable %"PRIsVALUE"", QUOTE_ID(id)); } trace = (entry = (struct global_entry *)data)->var->trace; @@ -916,7 +919,7 @@ generic_ivar_get(VALUE obj, ID id, int warn) } } if (warn) { - rb_warning("instance variable %s not initialized", rb_id2name(id)); + rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id)); } return Qnil; } @@ -1099,7 +1102,7 @@ ivar_get(VALUE obj, ID id, int warn) break; } if (warn) { - rb_warning("instance variable %s not initialized", rb_id2name(id)); + rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id)); } return Qnil; } @@ -1402,14 +1405,17 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name) rb_check_frozen(obj); if (!id) { if (rb_is_instance_name(name)) { - rb_name_error_str(name, "instance variable %s not defined", RSTRING_PTR(name)); + rb_name_error_str(name, "instance variable %"PRIsVALUE" not defined", + name); } else { - rb_name_error_str(name, "`%s' is not allowed as an instance variable name", RSTRING_PTR(name)); + rb_name_error_str(name, "`%"PRIsVALUE"' is not allowed as an instance variable name", + QUOTE(name)); } } if (!rb_is_instance_id(id)) { - rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id)); + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as an instance variable name", + QUOTE_ID(id)); } if (SPECIAL_CONST_P(obj)) goto generic; @@ -1442,7 +1448,7 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name) } break; } - rb_name_error(id, "instance variable %s not defined", rb_id2name(id)); + rb_name_error(id, "instance variable %"PRIsVALUE" not defined", QUOTE_ID(id)); UNREACHABLE; } @@ -1452,11 +1458,11 @@ static void uninitialized_constant(VALUE klass, ID id) { if (klass && rb_class_real(klass) != rb_cObject) - rb_name_error(id, "uninitialized constant %s::%s", - rb_class2name(klass), - rb_id2name(id)); + rb_name_error(id, "uninitialized constant %"PRIsVALUE"::%"PRIsVALUE"", + rb_class_name(klass), + QUOTE_ID(id)); else { - rb_name_error(id, "uninitialized constant %s", rb_id2name(id)); + rb_name_error(id, "uninitialized constant %"PRIsVALUE"", QUOTE_ID(id)); } } @@ -1598,7 +1604,8 @@ rb_autoload(VALUE mod, ID id, const char *file) struct autoload_data_i *ele; if (!rb_is_const_id(id)) { - rb_raise(rb_eNameError, "autoload must be constant name: %s", rb_id2name(id)); + rb_raise(rb_eNameError, "autoload must be constant name: %"PRIsVALUE"", + QUOTE_ID(id)); } if (!file || !*file) { rb_raise(rb_eArgError, "empty file name"); @@ -1823,7 +1830,8 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility) while (RCLASS_CONST_TBL(tmp) && st_lookup(RCLASS_CONST_TBL(tmp), (st_data_t)id, &data)) { rb_const_entry_t *ce = (rb_const_entry_t *)data; if (visibility && ce->flag == CONST_PRIVATE) { - rb_name_error(id, "private constant %s::%s referenced", rb_class2name(klass), rb_id2name(id)); + rb_name_error(id, "private constant %"PRIsVALUE"::%"PRIsVALUE" referenced", + rb_class_name(klass), QUOTE_ID(id)); } value = ce->value; if (value == Qundef) { @@ -1834,8 +1842,8 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility) continue; } if (exclude && tmp == rb_cObject && klass != rb_cObject) { - rb_warn("toplevel constant %s referenced by %s::%s", - rb_id2name(id), rb_class2name(klass), rb_id2name(id)); + rb_warn("toplevel constant %"PRIsVALUE" referenced by %"PRIsVALUE"::%"PRIsVALUE"", + QUOTE_ID(id), rb_class_name(klass), QUOTE_ID(id)); } return value; } @@ -1906,15 +1914,17 @@ rb_mod_remove_const(VALUE mod, VALUE name) if (!id) { if (rb_is_const_name(name)) { - rb_name_error_str(name, "constant %s::%s not defined", - rb_class2name(mod), RSTRING_PTR(name)); + rb_name_error_str(name, "constant %"PRIsVALUE"::%"PRIsVALUE" not defined", + rb_class_name(mod), name); } else { - rb_name_error_str(name, "`%s' is not allowed as a constant name", RSTRING_PTR(name)); + rb_name_error_str(name, "`%"PRIsVALUE"' is not allowed as a constant name", + QUOTE_ID(name)); } } if (!rb_is_const_id(id)) { - rb_name_error(id, "`%s' is not allowed as a constant name", rb_id2name(id)); + rb_name_error(id, "`%"PRIsVALUE"' is not allowed as a constant name", + QUOTE_ID(id)); } return rb_const_remove(mod, id); } @@ -1930,11 +1940,11 @@ rb_const_remove(VALUE mod, ID id) rb_check_frozen(mod); if (!RCLASS_CONST_TBL(mod) || !st_delete(RCLASS_CONST_TBL(mod), &n, &v)) { if (rb_const_defined_at(mod, id)) { - rb_name_error(id, "cannot remove %s::%s", - rb_class2name(mod), rb_id2name(id)); + rb_name_error(id, "cannot remove %"PRIsVALUE"::%"PRIsVALUE"", + rb_class_name(mod), QUOTE_ID(id)); } - rb_name_error(id, "constant %s::%s not defined", - rb_class2name(mod), rb_id2name(id)); + rb_name_error(id, "constant %"PRIsVALUE"::%"PRIsVALUE" not defined", + rb_class_name(mod), QUOTE_ID(id)); } rb_vm_change_state(); @@ -2129,8 +2139,8 @@ rb_const_set(VALUE klass, ID id, VALUE val) VALUE visibility = CONST_PUBLIC; if (NIL_P(klass)) { - rb_raise(rb_eTypeError, "no class/module to define constant %s", - rb_id2name(id)); + rb_raise(rb_eTypeError, "no class/module to define constant %"PRIsVALUE"", + QUOTE_ID(id)); } check_before_mod_set(klass, id, val, "constant"); @@ -2157,16 +2167,16 @@ rb_const_set(VALUE klass, ID id, VALUE val) autoload_delete(klass, id); } else { - const char *name = rb_id2name(id); + VALUE name = QUOTE_ID(id); visibility = ce->flag; if (klass == rb_cObject) - rb_warn("already initialized constant %s", name); + rb_warn("already initialized constant %"PRIsVALUE"", name); else - rb_warn("already initialized constant %s::%s", - rb_class2name(klass), name); + rb_warn("already initialized constant %"PRIsVALUE"::%"PRIsVALUE"", + rb_class_name(klass), name); if (!NIL_P(ce->file) && ce->line) { rb_compile_warn(RSTRING_PTR(ce->file), ce->line, - "previous definition of %s was here", name); + "previous definition of %"PRIsVALUE" was here", name); } } } @@ -2216,25 +2226,28 @@ set_const_visibility(VALUE mod, int argc, VALUE *argv, rb_const_flag_t flag) } if (argc == 0) { - rb_warning("%s with no argument is just ignored", rb_id2name(rb_frame_callee())); + rb_warning("%"PRIsVALUE" with no argument is just ignored", + QUOTE_ID(rb_frame_callee())); } for (i = 0; i < argc; i++) { VALUE val = argv[i]; id = rb_check_id(&val); if (!id) { - if ( i > 0 ) + if (i > 0) rb_clear_cache_by_class(mod); - rb_name_error_str(val, "constant %s::%s not defined", rb_class2name(mod), RSTRING_PTR(val)); + rb_name_error_str(val, "constant %"PRIsVALUE"::%"PRIsVALUE" not defined", + rb_class_name(mod), QUOTE(val)); } if (RCLASS_CONST_TBL(mod) && st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) { ((rb_const_entry_t*)v)->flag = flag; } else { - if ( i > 0 ) + if (i > 0) rb_clear_cache_by_class(mod); - rb_name_error(id, "constant %s::%s not defined", rb_class2name(mod), rb_id2name(id)); + rb_name_error(id, "constant %"PRIsVALUE"::%"PRIsVALUE" not defined", + rb_class_name(mod), QUOTE_ID(id)); } } rb_clear_cache_by_class(mod); @@ -2319,9 +2332,9 @@ rb_cvar_set(VALUE klass, ID id, VALUE val) st_data_t did = id; if (RTEST(ruby_verbose)) { - rb_warning("class variable %s of %s is overtaken by %s", - rb_id2name(id), rb_class2name(original_module(front)), - rb_class2name(original_module(target))); + rb_warning("class variable %"PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"", + QUOTE_ID(id), rb_class_name(original_module(front)), + rb_class_name(original_module(target))); } if (BUILTIN_TYPE(front) == T_CLASS) { st_delete(RCLASS_IV_TBL(front),&did,0); @@ -2349,16 +2362,16 @@ rb_cvar_get(VALUE klass, ID id) tmp = klass; CVAR_LOOKUP(&value, {if (!front) front = klass; target = klass;}); if (!target) { - rb_name_error(id,"uninitialized class variable %s in %s", - rb_id2name(id), rb_class2name(tmp)); + rb_name_error(id, "uninitialized class variable %"PRIsVALUE" in %"PRIsVALUE"", + QUOTE_ID(id), rb_class_name(tmp)); } if (front && target != front) { st_data_t did = id; if (RTEST(ruby_verbose)) { - rb_warning("class variable %s of %s is overtaken by %s", - rb_id2name(id), rb_class2name(original_module(front)), - rb_class2name(original_module(target))); + rb_warning("class variable %"PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"", + QUOTE_ID(id), rb_class_name(original_module(front)), + rb_class_name(original_module(target))); } if (BUILTIN_TYPE(front) == T_CLASS) { st_delete(RCLASS_IV_TBL(front),&did,0); @@ -2535,15 +2548,15 @@ rb_mod_remove_cvar(VALUE mod, VALUE name) if (!id) { if (rb_is_class_name(name)) { - rb_name_error_str(name, "class variable %s not defined for %s", - RSTRING_PTR(name), rb_class2name(mod)); + rb_name_error_str(name, "class variable %"PRIsVALUE" not defined for %"PRIsVALUE"", + name, rb_class_name(mod)); } else { - rb_name_error_str(name, "wrong class variable name %s", RSTRING_PTR(name)); + rb_name_error_str(name, "wrong class variable name %"PRIsVALUE"", QUOTE(name)); } } if (!rb_is_class_id(id)) { - rb_name_error(id, "wrong class variable name %s", rb_id2name(id)); + rb_name_error(id, "wrong class variable name %"PRIsVALUE"", QUOTE_ID(id)); } if (!OBJ_UNTRUSTED(mod) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't remove class variable"); @@ -2552,11 +2565,11 @@ rb_mod_remove_cvar(VALUE mod, VALUE name) return (VALUE)val; } if (rb_cvar_defined(mod, id)) { - rb_name_error(id, "cannot remove %s for %s", - rb_id2name(id), rb_class2name(mod)); + rb_name_error(id, "cannot remove %"PRIsVALUE" for %"PRIsVALUE"", + QUOTE_ID(id), rb_class_name(mod)); } - rb_name_error(id, "class variable %s not defined for %s", - rb_id2name(id), rb_class2name(mod)); + rb_name_error(id, "class variable %"PRIsVALUE" not defined for %"PRIsVALUE"", + QUOTE_ID(id), rb_class_name(mod)); UNREACHABLE; } diff --git a/vm_method.c b/vm_method.c index 8ca3f936e4..6a394811b6 100644 --- a/vm_method.c +++ b/vm_method.c @@ -865,8 +865,8 @@ rb_undef(VALUE klass, ID id) else if (RB_TYPE_P(c, T_MODULE)) { s0 = " module"; } - rb_name_error(id, "undefined method `%s' for%s `%s'", - rb_id2name(id), s0, rb_class2name(c)); + rb_name_error(id, "undefined method `%"PRIsVALUE"' for%s `%"PRIsVALUE"'", + QUOTE_ID(id), s0, rb_class_name(c)); } rb_add_method(klass, id, VM_METHOD_TYPE_UNDEF, 0, NOEX_PUBLIC); -- cgit v1.2.3