* 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:
parent
b3fc59837a
commit
4261abb230
@ -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>
|
Mon Sep 10 13:44:37 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* array.c (rb_ary_cycle): avoid infinite loop for empty array.
|
* array.c (rb_ary_cycle): avoid infinite loop for empty array.
|
||||||
|
7
range.c
7
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 EXCL(r) RTEST(RANGE_EXCL(r))
|
||||||
#define SET_EXCL(r,v) (RSTRUCT(r)->as.ary[2] = (v) ? Qtrue : Qfalse)
|
#define SET_EXCL(r,v) (RSTRUCT(r)->as.ary[2] = (v) ? Qtrue : Qfalse)
|
||||||
|
|
||||||
#define FL_INITIALIZED FL_USER3
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
range_alloc(VALUE klass)
|
range_alloc(VALUE klass)
|
||||||
{
|
{
|
||||||
@ -37,8 +35,6 @@ range_alloc(VALUE klass)
|
|||||||
RBASIC(r)->flags |= n << RSTRUCT_EMBED_LEN_SHIFT;
|
RBASIC(r)->flags |= n << RSTRUCT_EMBED_LEN_SHIFT;
|
||||||
rb_mem_clear(r->as.ary, n);
|
rb_mem_clear(r->as.ary, n);
|
||||||
|
|
||||||
RBASIC(r)->flags &= ~FL_INITIALIZED;
|
|
||||||
|
|
||||||
return (VALUE)r;
|
return (VALUE)r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,10 +97,9 @@ range_initialize(int argc, VALUE *argv, VALUE range)
|
|||||||
|
|
||||||
rb_scan_args(argc, argv, "21", &beg, &end, &flags);
|
rb_scan_args(argc, argv, "21", &beg, &end, &flags);
|
||||||
/* Ranges are immutable, so that they should be initialized only once. */
|
/* 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");
|
rb_name_error(rb_intern("initialize"), "`initialize' called twice");
|
||||||
}
|
}
|
||||||
RBASIC(range)->flags |= FL_INITIALIZED;
|
|
||||||
range_init(range, beg, end, RTEST(flags));
|
range_init(range, beg, end, RTEST(flags));
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,9 @@ class TestRange < Test::Unit::TestCase
|
|||||||
assert_equal(0, (0..0).max)
|
assert_equal(0, (0..0).max)
|
||||||
assert_equal(nil, (0...0).max)
|
assert_equal(nil, (0...0).max)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_initialize_twice
|
||||||
|
r = eval("1..2")
|
||||||
|
assert_raise(NameError) { r.instance_eval { initialize 3, 4 } }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user