mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* parse.y (primary): preserve and clear in_single and in_def using
stack to prevent nested method errors in singleton class bodies. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e393a67aa9
commit
2db6b52feb
6 changed files with 75 additions and 36 deletions
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,12 @@
|
||||||
|
Tue Feb 13 01:13:43 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* parse.y (primary): preserve and clear in_single and in_def using
|
||||||
|
stack to prevent nested method errors in singleton class bodies.
|
||||||
|
|
||||||
|
Sat Feb 10 23:43:49 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
||||||
|
|
||||||
|
* hash.c (rb_any_hash): dumped core on machines sizeof(int) != sizeof(long).
|
||||||
|
|
||||||
Sun Feb 11 16:00:30 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
Sun Feb 11 16:00:30 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (stack_length): use __builtin_frame_address() only if
|
* eval.c (stack_length): use __builtin_frame_address() only if
|
||||||
|
@ -7,7 +16,12 @@ Sun Feb 11 16:00:30 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in: add ac_cv_func_getpgrp_void=yes on DJGPP.
|
* configure.in: add ac_cv_func_getpgrp_void=yes on DJGPP.
|
||||||
|
|
||||||
Fri Feb 10 00:06:28 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
Sat Feb 10 23:07:15 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* regex.c (PREV_IS_A_LETTER): should not treat c>0x7f as a word
|
||||||
|
character if -Kn.
|
||||||
|
|
||||||
|
Sat Feb 10 00:06:28 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
|
||||||
|
|
||||||
* win32/win32.c (win32_stat): replace stat for enable when pathname
|
* win32/win32.c (win32_stat): replace stat for enable when pathname
|
||||||
ends with '/' or '\' for mswin32 on Win9X / Win2k.
|
ends with '/' or '\' for mswin32 on Win9X / Win2k.
|
||||||
|
@ -25,6 +39,10 @@ Fri Feb 9 22:54:57 2001 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
* ruby.c (ruby_init_loadpath): convert '\\' to '/'
|
* ruby.c (ruby_init_loadpath): convert '\\' to '/'
|
||||||
before finding executable file path.
|
before finding executable file path.
|
||||||
|
|
||||||
|
Fri Feb 9 17:41:53 2001 Triet H. Lai <thlai@mail.usyd.edu.au>
|
||||||
|
|
||||||
|
* dir.c (rb_glob_helper): do not follow symbolic links.
|
||||||
|
|
||||||
Fri Feb 8 23:53:08 2001 Usaku Nakamura <usa@osb.att.ne.jp>
|
Fri Feb 8 23:53:08 2001 Usaku Nakamura <usa@osb.att.ne.jp>
|
||||||
|
|
||||||
* win32/config.h.in (inline): add inline definition.
|
* win32/config.h.in (inline): add inline definition.
|
||||||
|
|
13
dir.c
13
dir.c
|
@ -601,11 +601,22 @@ rb_glob_helper(path, flag, func, arg)
|
||||||
rb_glob_helper(buf, flag, func, arg);
|
rb_glob_helper(buf, flag, func, arg);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
if (lstat(dir, &st) < 0) {
|
||||||
|
free(base);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (S_ISDIR(st.st_mode)) {
|
||||||
dirp = opendir(dir);
|
dirp = opendir(dir);
|
||||||
if (dirp == NULL) {
|
if (dirp == NULL) {
|
||||||
free(base);
|
free(base);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
free(base);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
#define BASE (*base && !(*base == '/' && !base[1]))
|
#define BASE (*base && !(*base == '/' && !base[1]))
|
||||||
|
|
||||||
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
|
for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
|
||||||
|
@ -636,7 +647,7 @@ rb_glob_helper(path, flag, func, arg)
|
||||||
free(base);
|
free(base);
|
||||||
free(magic);
|
free(magic);
|
||||||
while (link) {
|
while (link) {
|
||||||
stat(link->path, &st); /* should success */
|
lstat(link->path, &st); /* should success */
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
int len = strlen(link->path);
|
int len = strlen(link->path);
|
||||||
int mlen = strlen(m);
|
int mlen = strlen(m);
|
||||||
|
|
9
hash.c
9
hash.c
|
@ -79,16 +79,16 @@ static int
|
||||||
rb_any_hash(a)
|
rb_any_hash(a)
|
||||||
VALUE a;
|
VALUE a;
|
||||||
{
|
{
|
||||||
unsigned int hval;
|
VALUE hval;
|
||||||
|
|
||||||
switch (TYPE(a)) {
|
switch (TYPE(a)) {
|
||||||
case T_FIXNUM:
|
case T_FIXNUM:
|
||||||
case T_SYMBOL:
|
case T_SYMBOL:
|
||||||
hval = a;
|
return (int)a;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
hval = rb_str_hash(a);
|
return rb_str_hash(a);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -98,9 +98,8 @@ rb_any_hash(a)
|
||||||
hval = rb_funcall(hval, '%', 1, INT2FIX(65439));
|
hval = rb_funcall(hval, '%', 1, INT2FIX(65439));
|
||||||
}
|
}
|
||||||
ENABLE_INTS;
|
ENABLE_INTS;
|
||||||
hval = FIX2LONG(hval);
|
return (int)FIX2LONG(hval);
|
||||||
}
|
}
|
||||||
return hval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct st_hash_type objhash = {
|
static struct st_hash_type objhash = {
|
||||||
|
|
|
@ -9,9 +9,8 @@
|
||||||
|
|
||||||
for k,v in ENV
|
for k,v in ENV
|
||||||
next unless /^[a-zA-Z][_a-zA-Z0-9]*/ =~ k
|
next unless /^[a-zA-Z][_a-zA-Z0-9]*/ =~ k
|
||||||
v = v.gsub(/\\/) {|s| '\\'+s}
|
|
||||||
eval <<EOS
|
eval <<EOS
|
||||||
$#{k} = %q\0#{v}\0
|
$#{k} = v
|
||||||
trace_var "$#{k}", proc{|v|
|
trace_var "$#{k}", proc{|v|
|
||||||
ENV[%q!#{k}!] = v
|
ENV[%q!#{k}!] = v
|
||||||
$#{k} = v
|
$#{k} = v
|
||||||
|
|
55
parse.y
55
parse.y
|
@ -87,6 +87,7 @@ static stack_type cmdarg_stack = 0;
|
||||||
|
|
||||||
static int class_nest = 0;
|
static int class_nest = 0;
|
||||||
static int in_single = 0;
|
static int in_single = 0;
|
||||||
|
static int in_def = 0;
|
||||||
static int compile_for_eval = 0;
|
static int compile_for_eval = 0;
|
||||||
static ID cur_mid = 0;
|
static ID cur_mid = 0;
|
||||||
|
|
||||||
|
@ -314,13 +315,13 @@ stmts : none
|
||||||
|
|
||||||
stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
|
stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
|
||||||
{
|
{
|
||||||
if (cur_mid || in_single)
|
if (in_def || in_single)
|
||||||
yyerror("alias within method");
|
yyerror("alias within method");
|
||||||
$$ = NEW_ALIAS($2, $4);
|
$$ = NEW_ALIAS($2, $4);
|
||||||
}
|
}
|
||||||
| kALIAS tGVAR tGVAR
|
| kALIAS tGVAR tGVAR
|
||||||
{
|
{
|
||||||
if (cur_mid || in_single)
|
if (in_def || in_single)
|
||||||
yyerror("alias within method");
|
yyerror("alias within method");
|
||||||
$$ = NEW_VALIAS($2, $3);
|
$$ = NEW_VALIAS($2, $3);
|
||||||
}
|
}
|
||||||
|
@ -328,7 +329,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
|
||||||
{
|
{
|
||||||
char buf[3];
|
char buf[3];
|
||||||
|
|
||||||
if (cur_mid || in_single)
|
if (in_def || in_single)
|
||||||
yyerror("alias within method");
|
yyerror("alias within method");
|
||||||
sprintf(buf, "$%c", $3->nd_nth);
|
sprintf(buf, "$%c", $3->nd_nth);
|
||||||
$$ = NEW_VALIAS($2, rb_intern(buf));
|
$$ = NEW_VALIAS($2, rb_intern(buf));
|
||||||
|
@ -340,7 +341,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
|
||||||
}
|
}
|
||||||
| kUNDEF undef_list
|
| kUNDEF undef_list
|
||||||
{
|
{
|
||||||
if (cur_mid || in_single)
|
if (in_def || in_single)
|
||||||
yyerror("undef within method");
|
yyerror("undef within method");
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
}
|
}
|
||||||
|
@ -392,7 +393,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
|
||||||
}
|
}
|
||||||
| klBEGIN
|
| klBEGIN
|
||||||
{
|
{
|
||||||
if (cur_mid || in_single) {
|
if (in_def || in_single) {
|
||||||
yyerror("BEGIN in method");
|
yyerror("BEGIN in method");
|
||||||
}
|
}
|
||||||
local_push();
|
local_push();
|
||||||
|
@ -406,7 +407,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
|
||||||
}
|
}
|
||||||
| klEND '{' compstmt '}'
|
| klEND '{' compstmt '}'
|
||||||
{
|
{
|
||||||
if (compile_for_eval && (cur_mid || in_single)) {
|
if (compile_for_eval && (in_def || in_single)) {
|
||||||
yyerror("END in method; use at_exit");
|
yyerror("END in method; use at_exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,7 +438,7 @@ expr : mlhs '=' mrhs
|
||||||
}
|
}
|
||||||
| kRETURN ret_args
|
| kRETURN ret_args
|
||||||
{
|
{
|
||||||
if (!compile_for_eval && !cur_mid && !in_single)
|
if (!compile_for_eval && !in_def && !in_single)
|
||||||
yyerror("return appeared outside of method");
|
yyerror("return appeared outside of method");
|
||||||
$$ = NEW_RETURN($2);
|
$$ = NEW_RETURN($2);
|
||||||
}
|
}
|
||||||
|
@ -495,7 +496,7 @@ command : operation command_args
|
||||||
}
|
}
|
||||||
| kSUPER command_args
|
| kSUPER command_args
|
||||||
{
|
{
|
||||||
if (!compile_for_eval && !cur_mid && !in_single)
|
if (!compile_for_eval && !in_def && !in_single)
|
||||||
yyerror("super called outside of method");
|
yyerror("super called outside of method");
|
||||||
$$ = new_super($2);
|
$$ = new_super($2);
|
||||||
fixpos($$, $2);
|
fixpos($$, $2);
|
||||||
|
@ -1148,20 +1149,20 @@ primary : literal
|
||||||
}
|
}
|
||||||
| kRETURN '(' ret_args ')'
|
| kRETURN '(' ret_args ')'
|
||||||
{
|
{
|
||||||
if (!compile_for_eval && !cur_mid && !in_single)
|
if (!compile_for_eval && !in_def && !in_single)
|
||||||
yyerror("return appeared outside of method");
|
yyerror("return appeared outside of method");
|
||||||
value_expr($3);
|
value_expr($3);
|
||||||
$$ = NEW_RETURN($3);
|
$$ = NEW_RETURN($3);
|
||||||
}
|
}
|
||||||
| kRETURN '(' ')'
|
| kRETURN '(' ')'
|
||||||
{
|
{
|
||||||
if (!compile_for_eval && !cur_mid && !in_single)
|
if (!compile_for_eval && !in_def && !in_single)
|
||||||
yyerror("return appeared outside of method");
|
yyerror("return appeared outside of method");
|
||||||
$$ = NEW_RETURN(0);
|
$$ = NEW_RETURN(0);
|
||||||
}
|
}
|
||||||
| kRETURN
|
| kRETURN
|
||||||
{
|
{
|
||||||
if (!compile_for_eval && !cur_mid && !in_single)
|
if (!compile_for_eval && !in_def && !in_single)
|
||||||
yyerror("return appeared outside of method");
|
yyerror("return appeared outside of method");
|
||||||
$$ = NEW_RETURN(0);
|
$$ = NEW_RETURN(0);
|
||||||
}
|
}
|
||||||
|
@ -1254,9 +1255,8 @@ primary : literal
|
||||||
}
|
}
|
||||||
| kCLASS cname superclass
|
| kCLASS cname superclass
|
||||||
{
|
{
|
||||||
if (cur_mid || in_single)
|
if (in_def || in_single)
|
||||||
yyerror("class definition in method body");
|
yyerror("class definition in method body");
|
||||||
|
|
||||||
class_nest++;
|
class_nest++;
|
||||||
cref_push();
|
cref_push();
|
||||||
local_push();
|
local_push();
|
||||||
|
@ -1273,22 +1273,30 @@ primary : literal
|
||||||
}
|
}
|
||||||
| kCLASS tLSHFT expr term
|
| kCLASS tLSHFT expr term
|
||||||
{
|
{
|
||||||
|
$<num>$ = in_single;
|
||||||
|
in_single = 0;
|
||||||
class_nest++;
|
class_nest++;
|
||||||
cref_push();
|
cref_push();
|
||||||
local_push();
|
local_push();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
$<num>$ = in_def;
|
||||||
|
in_def = 0;
|
||||||
|
}
|
||||||
compstmt
|
compstmt
|
||||||
kEND
|
kEND
|
||||||
{
|
{
|
||||||
$$ = NEW_SCLASS($3, $6);
|
$$ = NEW_SCLASS($3, $7);
|
||||||
fixpos($$, $3);
|
fixpos($$, $3);
|
||||||
local_pop();
|
local_pop();
|
||||||
cref_pop();
|
cref_pop();
|
||||||
class_nest--;
|
class_nest--;
|
||||||
|
in_single = $<num>5;
|
||||||
|
in_def = $<num>6;
|
||||||
}
|
}
|
||||||
| kMODULE cname
|
| kMODULE cname
|
||||||
{
|
{
|
||||||
if (cur_mid || in_single)
|
if (in_def || in_single)
|
||||||
yyerror("module definition in method body");
|
yyerror("module definition in method body");
|
||||||
class_nest++;
|
class_nest++;
|
||||||
cref_push();
|
cref_push();
|
||||||
|
@ -1306,9 +1314,11 @@ primary : literal
|
||||||
}
|
}
|
||||||
| kDEF fname
|
| kDEF fname
|
||||||
{
|
{
|
||||||
if (cur_mid || in_single)
|
if (in_def || in_single)
|
||||||
yyerror("nested method definition");
|
yyerror("nested method definition");
|
||||||
|
$<id>$ = cur_mid;
|
||||||
cur_mid = $2;
|
cur_mid = $2;
|
||||||
|
in_def++;
|
||||||
local_push();
|
local_push();
|
||||||
}
|
}
|
||||||
f_arglist
|
f_arglist
|
||||||
|
@ -1330,7 +1340,8 @@ primary : literal
|
||||||
if (is_attrset_id($2)) $$->nd_noex = NOEX_PUBLIC;
|
if (is_attrset_id($2)) $$->nd_noex = NOEX_PUBLIC;
|
||||||
fixpos($$, $4);
|
fixpos($$, $4);
|
||||||
local_pop();
|
local_pop();
|
||||||
cur_mid = 0;
|
in_def--;
|
||||||
|
cur_mid = $<id>3;
|
||||||
}
|
}
|
||||||
| kDEF singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
|
| kDEF singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
|
||||||
{
|
{
|
||||||
|
@ -1463,14 +1474,14 @@ method_call : operation paren_args
|
||||||
}
|
}
|
||||||
| kSUPER paren_args
|
| kSUPER paren_args
|
||||||
{
|
{
|
||||||
if (!compile_for_eval && !cur_mid &&
|
if (!compile_for_eval && !in_def &&
|
||||||
!in_single && !in_defined)
|
!in_single && !in_defined)
|
||||||
yyerror("super called outside of method");
|
yyerror("super called outside of method");
|
||||||
$$ = new_super($2);
|
$$ = new_super($2);
|
||||||
}
|
}
|
||||||
| kSUPER
|
| kSUPER
|
||||||
{
|
{
|
||||||
if (!compile_for_eval && !cur_mid &&
|
if (!compile_for_eval && !in_def &&
|
||||||
!in_single && !in_defined)
|
!in_single && !in_defined)
|
||||||
yyerror("super called outside of method");
|
yyerror("super called outside of method");
|
||||||
$$ = NEW_ZSUPER();
|
$$ = NEW_ZSUPER();
|
||||||
|
@ -1975,6 +1986,7 @@ yycompile(f, line)
|
||||||
cond_stack = 0;
|
cond_stack = 0;
|
||||||
class_nest = 0;
|
class_nest = 0;
|
||||||
in_single = 0;
|
in_single = 0;
|
||||||
|
in_def = 0;
|
||||||
cur_mid = 0;
|
cur_mid = 0;
|
||||||
|
|
||||||
if (n == 0) node = ruby_eval_tree;
|
if (n == 0) node = ruby_eval_tree;
|
||||||
|
@ -3393,8 +3405,7 @@ yylex()
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
case '{':
|
case '{':
|
||||||
if (lex_state != EXPR_END &&
|
if (lex_state != EXPR_END && lex_state != EXPR_ARG)
|
||||||
lex_state != EXPR_ARG)
|
|
||||||
c = tLBRACE;
|
c = tLBRACE;
|
||||||
lex_state = EXPR_BEG;
|
lex_state = EXPR_BEG;
|
||||||
return c;
|
return c;
|
||||||
|
@ -4123,7 +4134,7 @@ assignable(id, val)
|
||||||
return NEW_IASGN(id, val);
|
return NEW_IASGN(id, val);
|
||||||
}
|
}
|
||||||
else if (is_const_id(id)) {
|
else if (is_const_id(id)) {
|
||||||
if (cur_mid || in_single)
|
if (in_def || in_single)
|
||||||
yyerror("dynamic constant assignment");
|
yyerror("dynamic constant assignment");
|
||||||
return NEW_CDECL(id, val);
|
return NEW_CDECL(id, val);
|
||||||
}
|
}
|
||||||
|
|
3
regex.c
3
regex.c
|
@ -3461,7 +3461,8 @@ re_search(bufp, string, size, startpos, range, regs)
|
||||||
#define PREV_IS_A_LETTER(d) ((current_mbctype == MBCTYPE_SJIS)? \
|
#define PREV_IS_A_LETTER(d) ((current_mbctype == MBCTYPE_SJIS)? \
|
||||||
IS_A_LETTER((d)-(!AT_STRINGS_BEG((d)-1)&& \
|
IS_A_LETTER((d)-(!AT_STRINGS_BEG((d)-1)&& \
|
||||||
ismbchar((d)[-2])?2:1)): \
|
ismbchar((d)[-2])?2:1)): \
|
||||||
((d)[-1] >= 0x80 || IS_A_LETTER((d)-1)))
|
((current_mbctype && ((d)[-1] >= 0x80)) || \
|
||||||
|
IS_A_LETTER((d)-1)))
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_regs(regs, num_regs)
|
init_regs(regs, num_regs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue