ruby-changes:12335
From: wyhaines <ko1@a...>
Date: Sat, 11 Jul 2009 03:32:16 +0900 (JST)
Subject: [ruby-changes:12335] Ruby:r24030 (ruby_1_8_6): Fix method scoping bug.
wyhaines 2009-07-11 03:31:58 +0900 (Sat, 11 Jul 2009) New Revision: 24030 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24030 Log: Fix method scoping bug. Modified files: branches/ruby_1_8_6/ChangeLog branches/ruby_1_8_6/eval.c branches/ruby_1_8_6/gc.c branches/ruby_1_8_6/test/ruby/test_proc.rb branches/ruby_1_8_6/version.h Index: ruby_1_8_6/ChangeLog =================================================================== --- ruby_1_8_6/ChangeLog (revision 24029) +++ ruby_1_8_6/ChangeLog (revision 24030) @@ -2,6 +2,8 @@ * file.c: Added FCNTL inclusion to fix a compile error with solaris (backport from r22812) + * gc.c: Fixed Backport #1322 [ruby-core:23050], backport of r23257; Fixes a define_method scope bug. + Thu Jul 9 11:22:00 2009 Kirk Haines <khaines@r...> * gc.c: Add a check for DATA_PTR(obj) to run_final as a stopgap fix for debilitating segfaults. Index: ruby_1_8_6/version.h =================================================================== --- ruby_1_8_6/version.h (revision 24029) +++ ruby_1_8_6/version.h (revision 24030) @@ -2,7 +2,7 @@ #define RUBY_RELEASE_DATE "2009-06-08" #define RUBY_VERSION_CODE 186 #define RUBY_RELEASE_CODE 20090608 -#define RUBY_PATCHLEVEL 377 +#define RUBY_PATCHLEVEL 378 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 8 Index: ruby_1_8_6/test/ruby/test_proc.rb =================================================================== --- ruby_1_8_6/test/ruby/test_proc.rb (revision 24029) +++ ruby_1_8_6/test/ruby/test_proc.rb (revision 24030) @@ -86,4 +86,15 @@ b = lambda {} assert_not_equal(a, b) end + + def test_define_method_scope + a = 1 + c = Class.new + c.send(:define_method, :x) do |*| + lambda {a = 2}.call + end + c.new.x(nil) + assert_equal(2, a, '[ruby-core:23050]') + end + end Index: ruby_1_8_6/eval.c =================================================================== --- ruby_1_8_6/eval.c (revision 24029) +++ ruby_1_8_6/eval.c (revision 24030) @@ -8647,7 +8647,7 @@ OBJSETUP(scope, tmp, T_SCOPE); scope->local_tbl = _block.scope->local_tbl; scope->local_vars = _block.scope->local_vars; - scope->flags |= SCOPE_CLONE; + scope->flags |= SCOPE_CLONE | (_block.scope->flags & SCOPE_MALLOC); _block.scope = scope; } /* modify current frame */ Index: ruby_1_8_6/gc.c =================================================================== --- ruby_1_8_6/gc.c (revision 24029) +++ ruby_1_8_6/gc.c (revision 24030) @@ -1316,7 +1316,7 @@ VALUE *vars = RANY(obj)->as.scope.local_vars-1; if (!(RANY(obj)->as.scope.flags & SCOPE_CLONE) && vars[0] == 0) RUBY_CRITICAL(free(RANY(obj)->as.scope.local_tbl)); - if (RANY(obj)->as.scope.flags & SCOPE_MALLOC) + if ((RANY(obj)->as.scope.flags & (SCOPE_MALLOC|SCOPE_CLONE)) == SCOPE_MALLOC) RUBY_CRITICAL(free(vars)); } break; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/