[前][次][番号順一覧][スレッド一覧]

ruby-changes:24198

From: nobu <ko1@a...>
Date: Fri, 29 Jun 2012 11:26:57 +0900 (JST)
Subject: [ruby-changes:24198] nobu:r36249 (trunk): rb_builtin_type_name

nobu	2012-06-29 11:26:46 +0900 (Fri, 29 Jun 2012)

  New Revision: 36249

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36249

  Log:
    rb_builtin_type_name
    
    * error.c (rb_builtin_type_name): extract from rb_check_type() for
      debug purpose.

  Modified files:
    trunk/error.c
    trunk/internal.h

Index: error.c
===================================================================
--- error.c	(revision 36248)
+++ error.c	(revision 36249)
@@ -416,8 +416,21 @@
     {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 *
-builtin_type_name(VALUE x)
+builtin_class_name(VALUE x)
 {
     const char *etype;
 
@@ -445,9 +458,6 @@
 void
 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;
 
     if (x == Qundef) {
@@ -456,15 +466,10 @@
 
     xt = TYPE(x);
     if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
-	while (type < typeend) {
-	    if (type->type == t) {
-		const char *etype;
-
-		etype = builtin_type_name(x);
-		rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
-			 etype, type->name);
-	    }
-	    type++;
+	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);
 	}
 	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);
@@ -500,7 +505,7 @@
     static const char mesg[] = "wrong argument type %s (expected %s)";
 
     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);
     }
     if (!RTYPEDDATA_P(obj)) {
Index: internal.h
===================================================================
--- internal.h	(revision 36248)
+++ internal.h	(revision 36249)
@@ -85,6 +85,7 @@
 NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4));
 VALUE rb_check_backtrace(VALUE);
 NORETURN(void rb_async_bug_errno(const char *,int));
+const char *rb_builtin_type_name(int t);
 
 /* eval_error.c */
 void ruby_error_print(void);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]