* parse.y (reg_named_capture_assign_iter): get rid of creating

unnecessary ID.

* parse.y (rb_enc_symname2_p): check for non-nul-terminated string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-12-19 07:32:00 +00:00
Родитель 26538a2091
Коммит 66417115a2
2 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -1,7 +1,12 @@
Wed Dec 19 16:26:35 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
Wed Dec 19 16:31:58 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (reg_named_capture_assign_iter): remove C99 dependency.
* parse.y (reg_named_capture_assign_iter): get rid of creating
unnecessary ID.
* parse.y (rb_enc_symname2_p): check for non-nul-terminated string.
Wed Dec 19 15:37:06 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* insnhelper.ci (vm_yield_with_cfunc): call cfunc with

20
parse.y
Просмотреть файл

@ -445,6 +445,7 @@ static void reg_fragment_check_gen(struct parser_params*, VALUE, int);
#define reg_fragment_check(str,options) reg_fragment_check_gen(parser, str, options)
static NODE *reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, NODE *match);
#define reg_named_capture_assign(regexp,match) reg_named_capture_assign_gen(parser,regexp,match)
int rb_enc_symname2_p(const char *, int, rb_encoding *);
#else
#define remove_begin(node) (node)
#endif /* !RIPPER */
@ -8494,6 +8495,9 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end,
{
reg_named_capture_assign_t *arg = (reg_named_capture_assign_t*)arg0;
struct parser_params* parser = arg->parser;
rb_encoding *enc = arg->enc;
int len = name_end - name;
const char *s = (const char *)name;
ID var;
arg->num++;
@ -8503,12 +8507,12 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end,
arg->fail_block = NEW_BEGIN(0);
}
var = rb_intern3((const char *)name, name_end-name, arg->enc);
if (!is_local_id(var)) {
compile_error(PARSER_ARG "named capture with a non local variable - %s",
rb_id2name(var));
if (!(len && rb_enc_islower(*name, enc) && rb_enc_symname2_p(s, len, enc))) {
compile_error(PARSER_ARG "named capture with a non local variable - %.*s",
len, name);
return ST_CONTINUE;
}
var = rb_intern3(s, len, enc);
if (dvar_defined(var) || local_id(var)) {
rb_warningS("named capture conflicts a local variable - %s",
rb_id2name(var));
@ -8795,9 +8799,15 @@ rb_symname_p(const char *name)
int
rb_enc_symname_p(const char *name, rb_encoding *enc)
{
return rb_enc_symname2_p(name, strlen(name), enc);
}
int
rb_enc_symname2_p(const char *name, int len, rb_encoding *enc)
{
const char *m = name;
const char *e = m + strlen(m);
const char *e = m + len;
int localid = Qfalse;
if (!m) return Qfalse;