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

ruby-changes:42580

From: nobu <ko1@a...>
Date: Wed, 20 Apr 2016 14:56:10 +0900 (JST)
Subject: [ruby-changes:42580] nobu:r54654 (trunk): error.c: SyntaxError#initialize

nobu	2016-04-20 15:52:30 +0900 (Wed, 20 Apr 2016)

  New Revision: 54654

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

  Log:
    error.c: SyntaxError#initialize
    
    * error.c (syntax_error_initialize): move the default message,
      "compile error", from parse.y.  the default parameter should
      belong to the class definition.
    * parse.y (yycompile0): use the default parameter.

  Modified files:
    trunk/ChangeLog
    trunk/error.c
    trunk/parse.y
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54653)
+++ ChangeLog	(revision 54654)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr 20 15:52:28 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* error.c (syntax_error_initialize): move the default message,
+	  "compile error", from parse.y.  the default parameter should
+	  belong to the class definition.
+
+	* parse.y (yycompile0): use the default parameter.
+
 Wed Apr 20 10:25:53 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* compile.c (append_compile_error): use rb_syntax_error_append.
Index: parse.y
===================================================================
--- parse.y	(revision 54653)
+++ parse.y	(revision 54654)
@@ -5551,8 +5551,7 @@ yycompile0(VALUE arg) https://github.com/ruby/ruby/blob/trunk/parse.y#L5551
     if (parser->error_p) {
 	VALUE mesg = parser->error_buffer;
 	if (!mesg) {
-	    mesg = rb_fstring_cstr("compile error");
-	    mesg = rb_exc_new_str(rb_eSyntaxError, mesg);
+	    mesg = rb_class_new_instance(0, 0, rb_eSyntaxError);
 	}
 	rb_set_errinfo(mesg);
 	return 0;
Index: error.c
===================================================================
--- error.c	(revision 54653)
+++ error.c	(revision 54654)
@@ -1362,6 +1362,25 @@ rb_invalid_str(const char *str, const ch https://github.com/ruby/ruby/blob/trunk/error.c#L1362
 }
 
 /*
+ * call-seq:
+ *   SyntaxError.new([msg])  -> syntax_error
+ *
+ * Construct a SyntaxError exception.
+ */
+
+static VALUE
+syntax_error_initialize(int argc, VALUE *argv, VALUE self)
+{
+    VALUE mesg;
+    if (argc == 0) {
+	mesg = rb_fstring_cstr("compile error");
+	argc = 1;
+	argv = &mesg;
+    }
+    return rb_call_super(argc, argv);
+}
+
+/*
  *  Document-module: Errno
  *
  *  Ruby exception objects are subclasses of <code>Exception</code>.
@@ -1960,6 +1979,7 @@ Init_Exception(void) https://github.com/ruby/ruby/blob/trunk/error.c#L1979
 
     rb_eScriptError = rb_define_class("ScriptError", rb_eException);
     rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);
+    rb_define_method(rb_eSyntaxError, "initialize", syntax_error_initialize, -1);
 
     rb_eLoadError   = rb_define_class("LoadError", rb_eScriptError);
     /* the path failed to load */

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

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