aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-24 09:43:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-24 09:43:22 +0000
commitd8fb49fba47212649fa4bb21770bf65e6177c5a4 (patch)
tree06cf68a9e42f2c91245f5d552468eeb59d14eed7
parent22742411548d8b8fad25c272aed0781e3218042a (diff)
downloadruby-d8fb49fba47212649fa4bb21770bf65e6177c5a4.tar.gz
deprecate exposed internal functions
* error.c (rb_compile_error_with_enc, rb_compile_error), (rb_compile_bug): deprecate internal functions. * parse.y (parser_yyerror): construct exception message with source code and carret. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--NEWS4
-rw-r--r--error.c4
-rw-r--r--include/ruby/intern.h6
-rw-r--r--parse.y32
5 files changed, 36 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 09c725646b..187d24281b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Dec 24 18:43:19 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * error.c (rb_compile_error_with_enc, rb_compile_error),
+ (rb_compile_bug): deprecate internal functions.
+
+ * parse.y (parser_yyerror): construct exception message with
+ source code and carret.
+
Thu Dec 24 17:25:42 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (append_compile_error), parse.y (compile_error):
diff --git a/NEWS b/NEWS
index ceba5321a4..8d5d68c624 100644
--- a/NEWS
+++ b/NEWS
@@ -338,6 +338,10 @@ with all sufficient information, see the ChangeLog file or Redmine
* rb_autoload() deprecated, use rb_funcall() instead. [Feature #11664]
+* rb_compile_error_with_enc(), rb_compile_error(), and rb_compile_bug()
+ deprecated. these functions are exposed but only for internal use.
+ external libraries should not use them.
+
=== Supported platform changes
* OS/2 is no longer supported
diff --git a/error.c b/error.c
index f2c86448e7..a42f789804 100644
--- a/error.c
+++ b/error.c
@@ -127,6 +127,7 @@ compile_err_append(VALUE mesg)
th->base_block = prev_base_block;
}
+#if 0
void
rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt, ...)
{
@@ -150,6 +151,7 @@ rb_compile_error(const char *file, int line, const char *fmt, ...)
va_end(args);
compile_err_append(str);
}
+#endif
void
rb_compile_error_str(VALUE file, int line, void *enc, const char *fmt, ...)
@@ -483,6 +485,7 @@ rb_async_bug_errno(const char *mesg, int errno_arg)
abort();
}
+#if 0
void
rb_compile_bug(const char *file, int line, const char *fmt, ...)
{
@@ -490,6 +493,7 @@ rb_compile_bug(const char *file, int line, const char *fmt, ...)
abort();
}
+#endif
void
rb_compile_bug_str(VALUE file, int line, const char *fmt, ...)
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index d43dc67780..99b850c895 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -253,9 +253,9 @@ PRINTF_ARGS(NORETURN(void rb_loaderror_with_path(VALUE path, const char*, ...)),
PRINTF_ARGS(NORETURN(void rb_name_error(ID, const char*, ...)), 2, 3);
PRINTF_ARGS(NORETURN(void rb_name_error_str(VALUE, 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);
+DEPRECATED(PRINTF_ARGS(void rb_compile_error(const char*, int, const char*, ...), 3, 4));
+DEPRECATED(PRINTF_ARGS(void rb_compile_error_with_enc(const char*, int, void *, const char*, ...), 4, 5));
+DEPRECATED(PRINTF_ARGS(void rb_compile_error_append(const char*, ...), 1, 2));
NORETURN(void rb_error_frozen(const char*));
NORETURN(void rb_error_frozen_object(VALUE));
void rb_error_untrusted(VALUE);
diff --git a/parse.y b/parse.y
index 59614b6936..b0c5bd9e78 100644
--- a/parse.y
+++ b/parse.y
@@ -5409,11 +5409,12 @@ parser_yyerror(struct parser_params *parser, const char *msg)
#ifndef RIPPER
const int max_line_margin = 30;
const char *p, *pe;
+ const char *pre = "", *post = "";
+ const char *code = "", *carret = "", *newline = "";
char *buf;
long len;
int i;
- compile_error(PARSER_ARG "%s", msg);
p = lex_p;
while (lex_pbeg <= p) {
if (*p == '\n') break;
@@ -5430,7 +5431,6 @@ parser_yyerror(struct parser_params *parser, const char *msg)
len = pe - p;
if (len > 4) {
char *p2;
- const char *pre = "", *post = "";
if (len > max_line_margin * 2 + 10) {
if (lex_p - p > max_line_margin) {
@@ -5443,22 +5443,24 @@ parser_yyerror(struct parser_params *parser, const char *msg)
}
len = pe - p;
}
- buf = ALLOCA_N(char, len+2);
- MEMCPY(buf, p, char, len);
- buf[len] = '\0';
- rb_compile_error_with_enc(NULL, 0, (void *)current_enc, "%s%s%s", pre, buf, post);
-
i = (int)(lex_p - p);
- p2 = buf; pe = buf + len;
-
- while (p2 < pe) {
- if (*p2 != '\t') *p2 = ' ';
- p2++;
+ buf = ALLOCA_N(char, i+2);
+ code = p;
+ carret = p2 = buf;
+ while (i-- > 0) {
+ *p2++ = *p++ == '\t' ? '\t' : ' ';
}
- buf[i] = '^';
- buf[i+1] = '\0';
- rb_compile_error_append("%s%s", pre, buf);
+ *p2++ = '^';
+ *p2 = '\0';
+ newline = "\n";
+ }
+ else {
+ len = 0;
}
+ compile_error(PARSER_ARG "%s%s""%s%.*s%s%s""%s%s",
+ msg, newline,
+ pre, (int)len, code, post, newline,
+ pre, carret);
#else
dispatch1(parse_error, STR_NEW2(msg));
ripper_error();