From 4261abb2305320ac2a335fed5460adafc265f0bd Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 10 Sep 2007 06:25:40 +0000 Subject: [PATCH] * range.c: represent initialized state using EXCL instead of FL_USER3. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ range.c | 7 +------ test/ruby/test_range.rb | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 440d70f729..c462ede0e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Sep 10 15:22:24 2007 Tanaka Akira + + * range.c: represent initialized state using EXCL instead of FL_USER3. + Mon Sep 10 13:44:37 2007 Yukihiro Matsumoto * array.c (rb_ary_cycle): avoid infinite loop for empty array. diff --git a/range.c b/range.c index f5a8d15f5d..079ed6bf6c 100644 --- a/range.c +++ b/range.c @@ -22,8 +22,6 @@ static ID id_cmp, id_succ, id_beg, id_end, id_excl; #define EXCL(r) RTEST(RANGE_EXCL(r)) #define SET_EXCL(r,v) (RSTRUCT(r)->as.ary[2] = (v) ? Qtrue : Qfalse) -#define FL_INITIALIZED FL_USER3 - static VALUE range_alloc(VALUE klass) { @@ -37,8 +35,6 @@ range_alloc(VALUE klass) RBASIC(r)->flags |= n << RSTRUCT_EMBED_LEN_SHIFT; rb_mem_clear(r->as.ary, n); - RBASIC(r)->flags &= ~FL_INITIALIZED; - return (VALUE)r; } @@ -101,10 +97,9 @@ range_initialize(int argc, VALUE *argv, VALUE range) rb_scan_args(argc, argv, "21", &beg, &end, &flags); /* Ranges are immutable, so that they should be initialized only once. */ - if (RBASIC(range)->flags & FL_INITIALIZED) { + if (RANGE_EXCL(range) != Qnil) { rb_name_error(rb_intern("initialize"), "`initialize' called twice"); } - RBASIC(range)->flags |= FL_INITIALIZED; range_init(range, beg, end, RTEST(flags)); return Qnil; } diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index 030aeb977b..847e261f97 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -59,4 +59,9 @@ class TestRange < Test::Unit::TestCase assert_equal(0, (0..0).max) assert_equal(nil, (0...0).max) end + + def test_initialize_twice + r = eval("1..2") + assert_raise(NameError) { r.instance_eval { initialize 3, 4 } } + end end