From 6d2e56ce7c3e7e53745105ed2d1011e522bcbbbe Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 19 Mar 2002 09:03:11 +0000 Subject: * re.c (rb_reg_search): should clear last_match if pos is out of string range. * string.c (rb_str_index_m): ditto. * string.c (rb_str_rindex): ditto. * class.c (rb_define_class): should handle autoload. * class.c (rb_define_module): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 15 +++++++++++++++ class.c | 6 ++++++ doc/NEWS | 8 ++++++++ error.c | 8 ++++---- eval.c | 4 ++-- parse.y | 30 +++++++++++++++++++++--------- re.c | 5 ++++- sample/test.rb | 12 ++++++++++++ string.c | 14 ++++++++++++-- version.h | 4 ++-- 10 files changed, 86 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b0807fa8a..ff24f8fab8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -63,6 +63,15 @@ Sat Mar 16 22:43:53 2002 WATANABE Hirofumi * missing/fileblocks.c: add for autoconf. +Sat Mar 16 15:30:40 2002 Yukihiro Matsumoto + + * re.c (rb_reg_search): should clear last_match if pos is out of + string range. + + * string.c (rb_str_index_m): ditto. + + * string.c (rb_str_rindex): ditto. + Sat Mar 16 09:04:58 2002 Koji Arai * enum.c (enum_inject): use the first iterated element as the @@ -96,6 +105,12 @@ Thu Mar 14 22:17:45 2002 Nobuyoshi Nakada * ext/iconv: imported. +Thu Mar 14 16:42:37 2002 Yukihiro Matsumoto + + * class.c (rb_define_class): should handle autoload. + + * class.c (rb_define_module): ditto. + Thu Mar 14 16:18:12 2002 WATANABE Hirofumi * configure.in: autoconf 2.53 support. use AC_LIBOBJ. diff --git a/class.c b/class.c index e0445cd934..26b2ba7f28 100644 --- a/class.c +++ b/class.c @@ -184,6 +184,9 @@ rb_define_class(name, super) ID id; id = rb_intern(name); + if (rb_autoload_defined(id)) { + rb_autoload_load(id); + } if (rb_const_defined(rb_cObject, id)) { klass = rb_const_get(rb_cObject, id); if (TYPE(klass) != T_CLASS) { @@ -270,6 +273,9 @@ rb_define_module(name) ID id; id = rb_intern(name); + if (rb_autoload_defined(id)) { + rb_autoload_load(id); + } if (rb_const_defined(rb_cObject, id)) { module = rb_const_get(rb_cObject, id); if (TYPE(module) == T_MODULE) diff --git a/doc/NEWS b/doc/NEWS index 3fedf52c3c..ca0b2c29d6 100644 --- a/doc/NEWS +++ b/doc/NEWS @@ -1,3 +1,11 @@ +: IO + + 64bit off_t support by Janathan Baker. + +: abort() + + optional terminate message argument. + : iconv module Imported. Wrapper library of (({iconv})). diff --git a/error.c b/error.c index b6c330748d..e52f2e91c7 100644 --- a/error.c +++ b/error.c @@ -434,14 +434,14 @@ rb_name_error(id, fmt, va_alist) } static VALUE -name_name(self) +name_err_name(self) VALUE self; { return rb_iv_get(self, "name"); } static VALUE -nometh_args(self) +nometh_err_args(self) VALUE self; { return rb_iv_get(self, "args"); @@ -633,9 +633,9 @@ Init_Exception() rb_eIndexError = rb_define_class("IndexError", rb_eStandardError); rb_eRangeError = rb_define_class("RangeError", rb_eStandardError); rb_eNameError = rb_define_class("NameError", rb_eStandardError); - rb_define_method(rb_eNameError, "name", name_name, 0); + rb_define_method(rb_eNameError, "name", name_err_name, 0); rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError); - rb_define_method(rb_eNoMethodError, "args", nometh_args, 0); + rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0); rb_eScriptError = rb_define_class("ScriptError", rb_eException); rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError); diff --git a/eval.c b/eval.c index e2166b862d..5e2131ebed 100644 --- a/eval.c +++ b/eval.c @@ -698,7 +698,7 @@ dvar_asgn_internal(id, value, curr) } } -static void +static inline void dvar_asgn(id, value) ID id; VALUE value; @@ -706,7 +706,7 @@ dvar_asgn(id, value) dvar_asgn_internal(id, value, 0); } -static void +static inline void dvar_asgn_curr(id, value) ID id; VALUE value; diff --git a/parse.y b/parse.y index 5cd2011053..01eef2ed0c 100644 --- a/parse.y +++ b/parse.y @@ -394,7 +394,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem if (in_def || in_single) { yyerror("BEGIN in method"); } - local_push(); + local_push(0); } '{' compstmt '}' { @@ -1382,7 +1382,7 @@ primary : literal if (in_def || in_single) yyerror("class definition in method body"); class_nest++; - local_push(); + local_push(0); $$ = ruby_sourceline; } compstmt @@ -1403,7 +1403,7 @@ primary : literal $$ = in_single; in_single = 0; class_nest++; - local_push(); + local_push(0); } compstmt kEND @@ -1420,7 +1420,7 @@ primary : literal if (in_def || in_single) yyerror("module definition in method body"); class_nest++; - local_push(); + local_push(0); $$ = ruby_sourceline; } compstmt @@ -1438,7 +1438,7 @@ primary : literal $$ = cur_mid; cur_mid = $2; in_def++; - local_push(); + local_push(0); } f_arglist compstmt @@ -1465,7 +1465,7 @@ primary : literal | kDEF singleton dot_or_colon {lex_state = EXPR_FNAME;} fname { in_single++; - local_push(); + local_push(0); lex_state = EXPR_END; /* force for args */ } f_arglist @@ -4927,11 +4927,13 @@ static struct local_vars { int nofree; int cnt; int dlev; + struct RVarmap* dyna_vars; struct local_vars *prev; } *lvtbl; static void -local_push() +local_push(top) + int top; { struct local_vars *local; @@ -4941,7 +4943,13 @@ local_push() local->cnt = 0; local->tbl = 0; local->dlev = 0; + local->dyna_vars = ruby_dyna_vars; lvtbl = local; + if (!top) { + /* preserve reference for GC, but link should be cut. */ + rb_dvar_push(0, (VALUE)ruby_dyna_vars); + ruby_dyna_vars->next = 0; + } } static void @@ -4953,6 +4961,7 @@ local_pop() if (!lvtbl->nofree) free(lvtbl->tbl); else lvtbl->tbl[0] = lvtbl->cnt; } + ruby_dyna_vars = lvtbl->dyna_vars; free(lvtbl); lvtbl = local; } @@ -5012,10 +5021,12 @@ local_id(id) return Qfalse; } +static VALUE last_dyna_vars = 0; + static void top_local_init() { - local_push(); + local_push(1); lvtbl->cnt = ruby_scope->local_tbl?ruby_scope->local_tbl[0]:0; if (lvtbl->cnt > 0) { lvtbl->tbl = ALLOC_N(ID, lvtbl->cnt+3); @@ -5176,7 +5187,8 @@ Init_sym() { sym_tbl = st_init_strtable_with_size(200); sym_rev_tbl = st_init_numtable_with_size(200); - rb_global_variable((VALUE*)&lex_lastline); + rb_global_variable(&lex_lastline); + rb_global_variable(&last_dyna_vars); } static ID last_id = LAST_TOKEN; diff --git a/re.c b/re.c index 99759c93d9..67ee4dfc1b 100644 --- a/re.c +++ b/re.c @@ -613,7 +613,10 @@ rb_reg_search(re, str, pos, reverse) static struct re_registers regs; int range; - if (pos > RSTRING(str)->len) return -1; + if (pos > RSTRING(str)->len || pos < 0) { + rb_backref_set(Qnil); + return -1; + } rb_reg_check(re); if (may_need_recompile) rb_reg_prepare_re(re); diff --git a/sample/test.rb b/sample/test.rb index 82b159a7b7..b20712019d 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -999,6 +999,18 @@ proc{ }.call test_ok(!defined?(iii)) # out of scope +loop{iii=5; test_ok(eval("defined? iii")); break} +loop {|iii| + iii = 10 + def dyna_var_check + loop { + test_ok(!defined?(iii)) + break + } + end + dyna_var_check + break +} $x=0 $proc.call(5) $proc2.call diff --git a/string.c b/string.c index 41d697bce0..72a1783aa8 100644 --- a/string.c +++ b/string.c @@ -887,7 +887,12 @@ rb_str_index_m(argc, argv, str) } if (pos < 0) { pos += RSTRING(str)->len; - if (pos < 0) return Qnil; + if (pos < 0) { + if (TYPE(sub) == T_REGEXP) { + rb_backref_set(Qnil); + } + return Qnil; + } } switch (TYPE(sub)) { @@ -936,7 +941,12 @@ rb_str_rindex(argc, argv, str) pos = NUM2INT(position); if (pos < 0) { pos += RSTRING(str)->len; - if (pos < 0) return Qnil; + if (pos < 0) { + if (TYPE(sub) == T_REGEXP) { + rb_backref_set(Qnil); + } + return Qnil; + } } if (pos > RSTRING(str)->len) pos = RSTRING(str)->len; } diff --git a/version.h b/version.h index 91930acc61..9227cae8cd 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.7.2" -#define RUBY_RELEASE_DATE "2002-03-18" +#define RUBY_RELEASE_DATE "2002-03-19" #define RUBY_VERSION_CODE 172 -#define RUBY_RELEASE_CODE 20020318 +#define RUBY_RELEASE_CODE 20020319 -- cgit v1.2.3