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

ruby-changes:40166

From: nobu <ko1@a...>
Date: Fri, 23 Oct 2015 21:11:02 +0900 (JST)
Subject: [ruby-changes:40166] nobu:r52247 (trunk): error.c: separate class names

nobu	2015-10-23 21:10:40 +0900 (Fri, 23 Oct 2015)

  New Revision: 52247

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

  Log:
    error.c: separate class names
    
    * error.c (name_err_mesg_to_str): separate class names from the
      receiver description.
    * vm_eval.c (make_no_method_exception, raise_method_missing): add
      format specifiers for class names.

  Modified files:
    trunk/ChangeLog
    trunk/error.c
    trunk/vm_eval.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52246)
+++ ChangeLog	(revision 52247)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct 23 21:10:37 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* error.c (name_err_mesg_to_str): separate class names from the
+	  receiver description.
+
+	* vm_eval.c (make_no_method_exception, raise_method_missing): add
+	  format specifiers for class names.
+
 Fri Oct 23 18:10:32 2015  SHIBATA Hiroshi  <hsbt@r...>
 
 	* .gitignore: ignored environmantal wrapper files.
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 52246)
+++ vm_eval.c	(revision 52247)
@@ -677,7 +677,7 @@ make_no_method_exception(VALUE exc, cons https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L677
     VALUE args[3];
 
     if (!format) {
-	format = "undefined method `%s' for %s";
+	format = "undefined method `%s' for %s%s%s";
     }
     args[n++] = rb_name_err_mesg_new(rb_str_new_cstr(format), obj, argv[0]);
     args[n++] = argv[0];
@@ -706,17 +706,17 @@ raise_method_missing(rb_thread_t *th, in https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L706
     stack_check();
 
     if (last_call_status & MISSING_PRIVATE) {
-	format = "private method `%s' called for %s";
+	format = "private method `%s' called for %s%s%s";
     }
     else if (last_call_status & MISSING_PROTECTED) {
-	format = "protected method `%s' called for %s";
+	format = "protected method `%s' called for %s%s%s";
     }
     else if (last_call_status & MISSING_VCALL) {
-	format = "undefined local variable or method `%s' for %s";
+	format = "undefined local variable or method `%s' for %s%s%s";
 	exc = rb_eNameError;
     }
     else if (last_call_status & MISSING_SUPER) {
-	format = "super: no superclass method `%s' for %s";
+	format = "super: no superclass method `%s' for %s%s%s";
     }
 
     {
Index: error.c
===================================================================
--- error.c	(revision 52246)
+++ error.c	(revision 52247)
@@ -1219,20 +1219,19 @@ name_err_mesg_to_str(VALUE obj) https://github.com/ruby/ruby/blob/trunk/error.c#L1219
     mesg = ptr[NAME_ERR_MESG__MESG];
     if (NIL_P(mesg)) return Qnil;
     else {
-	const char *desc = 0;
-	VALUE d = 0, args[NAME_ERR_MESG_COUNT];
-	int state = 0;
+	VALUE c, s, d = 0, args[4];
+	int state = 0, singleton = 0;
 
 	obj = ptr[NAME_ERR_MESG__RECV];
 	switch (obj) {
 	  case Qnil:
-	    desc = "nil";
+	    d = rb_fstring_cstr("nil");
 	    break;
 	  case Qtrue:
-	    desc = "true";
+	    d = rb_fstring_cstr("true");
 	    break;
 	  case Qfalse:
-	    desc = "false";
+	    d = rb_fstring_cstr("false");
 	    break;
 	  default:
 	    d = rb_protect(rb_inspect, obj, &state);
@@ -1241,18 +1240,22 @@ name_err_mesg_to_str(VALUE obj) https://github.com/ruby/ruby/blob/trunk/error.c#L1240
 	    if (NIL_P(d) || RSTRING_LEN(d) > 65) {
 		d = rb_any_to_s(obj);
 	    }
-	    desc = RSTRING_PTR(d);
+	    singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] == '#');
+	    d = QUOTE(d);
 	    break;
 	}
-	if (desc && desc[0] != '#') {
-	    d = d ? rb_str_dup(d) : rb_str_new2(desc);
-	    rb_str_cat2(d, ":");
-	    rb_str_append(d, rb_class_name(CLASS_OF(obj)));
+	if (!singleton) {
+	    s = rb_fstring_cstr(":");
+	    c = rb_class_name(CLASS_OF(obj));
 	}
-	args[0] = mesg;
-	args[1] = ptr[NAME_ERR_MESG__NAME];
-	args[2] = d;
-	mesg = rb_f_sprintf(NAME_ERR_MESG_COUNT, args);
+	else {
+	    c = s = rb_fstring_cstr("");
+	}
+	args[0] = ptr[NAME_ERR_MESG__NAME];
+	args[1] = d;
+	args[2] = s;
+	args[3] = c;
+	mesg = rb_str_format(4, args, mesg);
     }
     return mesg;
 }

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

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