rb_builtin_type_name
* error.c (rb_builtin_type_name): extract from rb_check_type() for debug purpose. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
468c703d30
commit
13bc74fa74
33
error.c
33
error.c
@ -416,8 +416,21 @@ static const struct types {
|
|||||||
{T_UNDEF, "undef"}, /* internal use: #undef; should not happen */
|
{T_UNDEF, "undef"}, /* internal use: #undef; should not happen */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const char *
|
||||||
|
rb_builtin_type_name(int t)
|
||||||
|
{
|
||||||
|
const struct types *type = builtin_types;
|
||||||
|
const struct types *const typeend = builtin_types +
|
||||||
|
sizeof(builtin_types) / sizeof(builtin_types[0]);
|
||||||
|
while (type < typeend) {
|
||||||
|
if (type->type == t) return type->name;
|
||||||
|
type++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
builtin_type_name(VALUE x)
|
builtin_class_name(VALUE x)
|
||||||
{
|
{
|
||||||
const char *etype;
|
const char *etype;
|
||||||
|
|
||||||
@ -445,9 +458,6 @@ builtin_type_name(VALUE x)
|
|||||||
void
|
void
|
||||||
rb_check_type(VALUE x, int t)
|
rb_check_type(VALUE x, int t)
|
||||||
{
|
{
|
||||||
const struct types *type = builtin_types;
|
|
||||||
const struct types *const typeend = builtin_types +
|
|
||||||
sizeof(builtin_types) / sizeof(builtin_types[0]);
|
|
||||||
int xt;
|
int xt;
|
||||||
|
|
||||||
if (x == Qundef) {
|
if (x == Qundef) {
|
||||||
@ -456,15 +466,10 @@ rb_check_type(VALUE x, int t)
|
|||||||
|
|
||||||
xt = TYPE(x);
|
xt = TYPE(x);
|
||||||
if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
|
if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
|
||||||
while (type < typeend) {
|
const char *tname = rb_builtin_type_name(t);
|
||||||
if (type->type == t) {
|
if (tname) {
|
||||||
const char *etype;
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
||||||
|
builtin_class_name(x), tname);
|
||||||
etype = builtin_type_name(x);
|
|
||||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
|
|
||||||
etype, type->name);
|
|
||||||
}
|
|
||||||
type++;
|
|
||||||
}
|
}
|
||||||
if (xt > T_MASK && xt <= 0x3f) {
|
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);
|
rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
|
||||||
@ -500,7 +505,7 @@ rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
|
|||||||
static const char mesg[] = "wrong argument type %s (expected %s)";
|
static const char mesg[] = "wrong argument type %s (expected %s)";
|
||||||
|
|
||||||
if (!RB_TYPE_P(obj, T_DATA)) {
|
if (!RB_TYPE_P(obj, T_DATA)) {
|
||||||
etype = builtin_type_name(obj);
|
etype = builtin_class_name(obj);
|
||||||
rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
|
rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
|
||||||
}
|
}
|
||||||
if (!RTYPEDDATA_P(obj)) {
|
if (!RTYPEDDATA_P(obj)) {
|
||||||
|
@ -85,6 +85,7 @@ void rb_gc_mark_encodings(void);
|
|||||||
NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4));
|
NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4));
|
||||||
VALUE rb_check_backtrace(VALUE);
|
VALUE rb_check_backtrace(VALUE);
|
||||||
NORETURN(void rb_async_bug_errno(const char *,int));
|
NORETURN(void rb_async_bug_errno(const char *,int));
|
||||||
|
const char *rb_builtin_type_name(int t);
|
||||||
|
|
||||||
/* eval_error.c */
|
/* eval_error.c */
|
||||||
void ruby_error_print(void);
|
void ruby_error_print(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user