1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
akr 2007-09-10 06:25:40 +00:00
parent b3fc59837a
commit 4261abb230
3 changed files with 10 additions and 6 deletions

View file

@ -1,3 +1,7 @@
Mon Sep 10 15:22:24 2007 Tanaka Akira <akr@fsij.org>
* range.c: represent initialized state using EXCL instead of FL_USER3.
Mon Sep 10 13:44:37 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_cycle): avoid infinite loop for empty array.

View file

@ -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;
}

View file

@ -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