summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-17 05:35:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-17 05:35:10 +0000
commitb5e6b46e90101dbd092469e183070635634d9394 (patch)
treeebe1414c533d6d40818fd442bf90e31e4e2625e9 /parse.y
parent9d7ff244c35119c9d9c0014bfb7ece8b3c689be6 (diff)
* parse.y (lex_get_str, lex_io_gets, rb_parser_compile_string):
must be ascii compatible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y51
1 files changed, 36 insertions, 15 deletions
diff --git a/parse.y b/parse.y
index 41706eaf34..6084bcaa84 100644
--- a/parse.y
+++ b/parse.y
@@ -5031,10 +5031,21 @@ yycompile(struct parser_params *parser, const char *f, int line)
}
#endif /* !RIPPER */
+static rb_encoding *
+must_be_ascii_compatible(VALUE s)
+{
+ rb_encoding *enc = rb_enc_get(s);
+ if (!rb_enc_asciicompat(enc)) {
+ rb_raise(rb_eArgError, "invalid source encoding");
+ }
+ return enc;
+}
+
static VALUE
lex_get_str(struct parser_params *parser, VALUE s)
{
char *beg, *end, *pend;
+ rb_encoding *enc = must_be_ascii_compatible(s);
beg = RSTRING_PTR(s);
if (lex_gets_ptr) {
@@ -5047,18 +5058,20 @@ lex_get_str(struct parser_params *parser, VALUE s)
if (*end++ == '\n') break;
}
lex_gets_ptr = end - RSTRING_PTR(s);
- return rb_enc_str_new(beg, end - beg, rb_enc_get(s));
+ return rb_enc_str_new(beg, end - beg, enc);
}
static VALUE
lex_getline(struct parser_params *parser)
{
VALUE line = (*parser->parser_lex_gets)(parser, parser->parser_lex_input);
+ if (NIL_P(line)) return line;
+ must_be_ascii_compatible(line);
#ifndef RIPPER
- if (ruby_debug_lines && !NIL_P(line)) {
+ if (ruby_debug_lines) {
rb_ary_push(ruby_debug_lines, line);
}
- if (ruby_coverage && !NIL_P(line)) {
+ if (ruby_coverage) {
rb_ary_push(ruby_coverage, Qnil);
}
#endif
@@ -5068,16 +5081,8 @@ lex_getline(struct parser_params *parser)
static const rb_data_type_t parser_data_type;
#ifndef RIPPER
-NODE*
-rb_compile_string(const char *f, VALUE s, int line)
-{
- VALUE volatile vparser = rb_parser_new();
-
- return rb_parser_compile_string(vparser, f, s, line);
-}
-
-NODE*
-rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
+static NODE*
+parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
{
struct parser_params *parser;
NODE *node;
@@ -5097,15 +5102,31 @@ rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int lin
}
NODE*
+rb_compile_string(const char *f, VALUE s, int line)
+{
+ must_be_ascii_compatible(s);
+ return parser_compile_string(rb_parser_new(), f, s, line);
+}
+
+NODE*
+rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
+{
+ must_be_ascii_compatible(s);
+ return parser_compile_string(vparser, f, s, line);
+}
+
+NODE*
rb_compile_cstr(const char *f, const char *s, int len, int line)
{
- return rb_compile_string(f, rb_str_new(s, len), line);
+ VALUE str = rb_str_new(s, len);
+ return parser_compile_string(rb_parser_new(), f, str, line);
}
NODE*
rb_parser_compile_cstr(volatile VALUE vparser, const char *f, const char *s, int len, int line)
{
- return rb_parser_compile_string(vparser, f, rb_str_new(s, len), line);
+ VALUE str = rb_str_new(s, len);
+ return parser_compile_string(vparser, f, str, line);
}
static VALUE