aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-02 14:36:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-02 14:36:25 +0000
commitd9274e7d6bbffd15291ffc6bdd5fefbde79f5cb8 (patch)
treeb611b62f1dccaaaaf76d013e3fab3569c1b0b395 /parse.y
parent46e848a65a866663161edecc81d1b46aa3e36de3 (diff)
downloadruby-d9274e7d6bbffd15291ffc6bdd5fefbde79f5cb8.tar.gz
* parse.y (reg_compile_gen): set error if failed to compile regexp
literal. [ruby-dev:31336] * re.c (rb_reg_compile): should not use regexp which could not get initialized. [ruby-dev:31333] return error message to let the parser know it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y25
1 files changed, 19 insertions, 6 deletions
diff --git a/parse.y b/parse.y
index 7457b9c85e..9b3fbe914c 100644
--- a/parse.y
+++ b/parse.y
@@ -419,6 +419,8 @@ extern int rb_dvar_defined(ID);
extern int rb_local_defined(ID);
extern int rb_parse_in_eval(void);
+static VALUE reg_compile_gen(struct parser_params*, const char *, long, int);
+#define reg_compile(ptr,len,options) reg_compile_gen(parser, ptr, len, options)
#else
#define remove_begin(node) (node)
#endif /* !RIPPER */
@@ -3611,18 +3613,16 @@ regexp : tREGEXP_BEG xstring_contents tREGEXP_END
int options = $3;
NODE *node = $2;
if (!node) {
- node = NEW_LIT(rb_reg_compile("", 0, options & ~RE_OPTION_ONCE,
- ruby_sourcefile, ruby_sourceline));
+ node = NEW_LIT(reg_compile("", 0, options));
}
else switch (nd_type(node)) {
case NODE_STR:
{
VALUE src = node->nd_lit;
nd_set_type(node, NODE_LIT);
- node->nd_lit = rb_reg_compile(RSTRING_PTR(src),
- RSTRING_LEN(src),
- options & ~RE_OPTION_ONCE,
- ruby_sourcefile, ruby_sourceline);
+ node->nd_lit = reg_compile(RSTRING_PTR(src),
+ RSTRING_LEN(src),
+ options);
}
break;
default:
@@ -8101,6 +8101,19 @@ dvar_curr_gen(struct parser_params *parser, ID id)
vtable_included(lvtbl->vars, id));
}
+static VALUE
+reg_compile_gen(struct parser_params* parser, const char *ptr, long len, int options)
+{
+ VALUE rb_reg_compile(const char *, long, int);
+ VALUE re = rb_reg_compile(ptr, len, (options) & ~RE_OPTION_ONCE);
+
+ if (TYPE(re) == T_STRING) {
+ compile_error(PARSER_ARG "%s", RSTRING_PTR(re));
+ return Qnil;
+ }
+ return re;
+}
+
void
rb_gc_mark_parser(void)
{