diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-12-15 05:33:34 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-12-15 05:33:34 +0000 |
commit | 9dccfb5513d6344b1fd113c403255b44c486fc3e (patch) | |
tree | 64b1ba351170634981de284ff29aa3859a9def16 /error.c | |
parent | 57537ccb0ef8ccd644e0ca4196aebb834970f3f8 (diff) |
* error.c (rb_check_typeddata): refine error message with
including expected struct name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 44 |
1 files changed, 27 insertions, 17 deletions
@@ -378,6 +378,30 @@ static const struct types { {T_UNDEF, "undef"}, /* internal use: #undef; should not happen */ }; +static const char * +builtin_type_name(VALUE x) +{ + const char *etype; + + if (NIL_P(x)) { + etype = "nil"; + } + else if (FIXNUM_P(x)) { + etype = "Fixnum"; + } + else if (SYMBOL_P(x)) { + etype = "Symbol"; + } + else if (rb_special_const_p(x)) { + x = rb_obj_as_string(x); + etype = StringValuePtr(x); + } + else { + etype = rb_obj_classname(x); + } + return etype; +} + void rb_check_type(VALUE x, int t) { @@ -396,22 +420,7 @@ rb_check_type(VALUE x, int t) if (type->type == t) { const char *etype; - if (NIL_P(x)) { - etype = "nil"; - } - else if (FIXNUM_P(x)) { - etype = "Fixnum"; - } - else if (SYMBOL_P(x)) { - etype = "Symbol"; - } - else if (rb_special_const_p(x)) { - x = rb_obj_as_string(x); - etype = StringValuePtr(x); - } - else { - etype = rb_obj_classname(x); - } + etype = builtin_type_name(xt); rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", etype, type->name); } @@ -451,7 +460,8 @@ rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type) static const char mesg[] = "wrong argument type %s (expected %s)"; if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA) { - Check_Type(obj, T_DATA); + etype = builtin_type_name(obj); + rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name); } if (!RTYPEDDATA_P(obj)) { etype = rb_obj_classname(obj); |