summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-28 09:43:49 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-28 09:43:49 +0000
commit90d5bcf9104fe58887cf705b718a9c7b537b51a5 (patch)
treeddad772917567e032a6b34254ebdf4f9d321bbb0
parent8af7ed60368c030e95ec782022538254d256d590 (diff)
* re.c (rb_reg_expr_str): need to escape if the coderage is invalid.
* error.c, include/ruby/intern.h (rb_compile_error_with_enc): new function to raise syntax error, with source encoding'ed message. * parse.y (compile_error): use above function. [ruby-core:33951] (#4217) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--error.c23
-rw-r--r--include/ruby/intern.h1
-rw-r--r--parse.y6
4 files changed, 33 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 38ff661107..5b7aa43150 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Tue Dec 28 18:36:38 2010 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * re.c (rb_reg_expr_str): need to escape if the coderage is invalid.
+
+ * error.c, include/ruby/intern.h (rb_compile_error_with_enc): new
+ function to raise syntax error, with source encoding'ed message.
+
+ * parse.y (compile_error): use above function.
+ [ruby-core:33951] (#4217)
+
Tue Dec 28 07:37:38 2010 Tanaka Akira <akr@fsij.org>
* ruby.c: parenthesize macro arguments.
diff --git a/error.c b/error.c
index bfbc86cce9..ab252a6d6b 100644
--- a/error.c
+++ b/error.c
@@ -88,7 +88,19 @@ compile_snprintf(char *buf, long len, const char *file, int line, const char *fm
}
}
-static void err_append(const char*);
+static void err_append(const char*, rb_encoding *);
+
+void
+rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt, ...)
+{
+ va_list args;
+ char buf[BUFSIZ];
+
+ va_start(args, fmt);
+ compile_snprintf(buf, BUFSIZ, file, line, fmt, args);
+ va_end(args);
+ err_append(buf, (rb_encoding *)enc);
+}
void
rb_compile_error(const char *file, int line, const char *fmt, ...)
@@ -99,7 +111,7 @@ rb_compile_error(const char *file, int line, const char *fmt, ...)
va_start(args, fmt);
compile_snprintf(buf, BUFSIZ, file, line, fmt, args);
va_end(args);
- err_append(buf);
+ err_append(buf, NULL);
}
void
@@ -111,7 +123,7 @@ rb_compile_error_append(const char *fmt, ...)
va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);
- err_append(buf);
+ err_append(buf, NULL);
}
static void
@@ -1644,14 +1656,15 @@ Init_syserr(void)
}
static void
-err_append(const char *s)
+err_append(const char *s, rb_encoding *enc)
{
rb_thread_t *th = GET_THREAD();
VALUE err = th->errinfo;
if (th->mild_compile_error) {
if (!RTEST(err)) {
- err = rb_exc_new2(rb_eSyntaxError, s);
+ err = rb_exc_new3(rb_eSyntaxError,
+ rb_enc_str_new(s, strlen(s), enc));
th->errinfo = err;
}
else {
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 46fcb03c58..9f6fe9f52f 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -209,6 +209,7 @@ PRINTF_ARGS(NORETURN(void rb_loaderror(const char*, ...)), 1, 2);
PRINTF_ARGS(NORETURN(void rb_name_error(ID, const char*, ...)), 2, 3);
NORETURN(void rb_invalid_str(const char*, const char*));
PRINTF_ARGS(void rb_compile_error(const char*, int, const char*, ...), 3, 4);
+PRINTF_ARGS(void rb_compile_error_with_enc(const char*, int, void *, const char*, ...), 4, 5);
PRINTF_ARGS(void rb_compile_error_append(const char*, ...), 1, 2);
NORETURN(void rb_load_fail(const char*));
NORETURN(void rb_error_frozen(const char*));
diff --git a/parse.y b/parse.y
index f0b7358a99..bbe842edee 100644
--- a/parse.y
+++ b/parse.y
@@ -308,6 +308,7 @@ static int parser_yyerror(struct parser_params*, const char*);
#define ruby__end__seen (parser->parser_ruby__end__seen)
#define ruby_sourceline (parser->parser_ruby_sourceline)
#define ruby_sourcefile (parser->parser_ruby_sourcefile)
+#define current_enc (parser->enc)
#define yydebug (parser->parser_yydebug)
#ifdef RIPPER
#else
@@ -586,8 +587,9 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
# define compile_error ripper_compile_error
# define PARSER_ARG parser,
#else
-# define compile_error parser->nerr++,rb_compile_error
-# define PARSER_ARG ruby_sourcefile, ruby_sourceline,
+# define rb_compile_error rb_compile_error_with_enc
+# define compile_error parser->nerr++,rb_compile_error_with_enc
+# define PARSER_ARG ruby_sourcefile, ruby_sourceline, current_enc,
#endif
/* Older versions of Yacc set YYMAXDEPTH to a very low value by default (150,