diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-28 02:40:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-09-28 02:40:46 +0000 |
commit | 6b3b9965421f8a8320af0f5c10d285f5a2739d27 (patch) | |
tree | 6689e8d252ca17f1f90626d7ade4b144dbfccdd7 /error.c | |
parent | a3facc8132b8589a5bd02f89bc029fe71d6b3919 (diff) | |
download | ruby-6b3b9965421f8a8320af0f5c10d285f5a2739d27.tar.gz |
preserve encodings in error messages
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 39 |
1 files changed, 29 insertions, 10 deletions
@@ -520,9 +520,8 @@ rb_builtin_type_name(int t) return 0; } -#define builtin_class_name rb_builtin_class_name -const char * -rb_builtin_class_name(VALUE x) +static const char * +builtin_class_name(VALUE x) { const char *etype; @@ -542,6 +541,17 @@ rb_builtin_class_name(VALUE x) etype = "false"; } else { + etype = NULL; + } + return etype; +} + +const char * +rb_builtin_class_name(VALUE x) +{ + const char *etype = builtin_class_name(x); + + if (!etype) { etype = rb_obj_classname(x); } return etype; @@ -560,8 +570,13 @@ rb_check_type(VALUE x, int t) if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) { const char *tname = rb_builtin_type_name(t); if (tname) { - rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", - builtin_class_name(x), tname); + const char *cname = builtin_class_name(x); + if (cname) + rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", + cname, tname); + else + rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected %s)", + rb_obj_class(x), tname); } if (xt > T_MASK && xt <= 0x3f) { rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt); @@ -594,19 +609,23 @@ void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type) { const char *etype; - static const char mesg[] = "wrong argument type %s (expected %s)"; if (!RB_TYPE_P(obj, T_DATA)) { + wrong_type: etype = builtin_class_name(obj); - rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name); + if (!etype) + rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected %s)", + rb_obj_class(obj), data_type->wrap_struct_name); + wrong_datatype: + rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", + etype, data_type->wrap_struct_name); } if (!RTYPEDDATA_P(obj)) { - etype = rb_obj_classname(obj); - rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name); + goto wrong_type; } else if (!rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) { etype = RTYPEDDATA_TYPE(obj)->wrap_struct_name; - rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name); + goto wrong_datatype; } return DATA_PTR(obj); } |