From 6a1101f23ea403a8825c2f361508eeb85878b011 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 21 Jun 2013 11:22:18 +0000 Subject: * include/ruby/ruby.h: support write barrier protection for T_STRUCT. Introduce the following C APIs: * RSTRUCT_RAWPTR(st) returns pointer (do WB on your risk). The type of returned pointer is (const VALUE *). * RSTRUCT_GET(st, idx) returns idx-th value of struct. * RSTRUCT_SET(st, idx, v) set idx-th value by v with WB. And * RSTRUCT_PTR(st) returns pointer with shady operation. The type of returned pointer is (VALUE *). * struct.c, re.c, gc.c, marshal.c: rewrite with above APIs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- range.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'range.c') diff --git a/range.c b/range.c index 6d6a52873e..280c333dc2 100644 --- a/range.c +++ b/range.c @@ -27,7 +27,12 @@ static ID id_cmp, id_succ, id_beg, id_end, id_excl, id_integer_p, id_div; #define RANGE_EXCL(r) (RSTRUCT(r)->as.ary[2]) #define EXCL(r) RTEST(RANGE_EXCL(r)) -#define SET_EXCL(r,v) (RSTRUCT(r)->as.ary[2] = (v) ? Qtrue : Qfalse) +static inline VALUE +SET_EXCL(VALUE r, VALUE v) +{ + RSTRUCT_SET(r, 2, v); + return v ? Qtrue : Qfalse; +} static VALUE range_failed(void) @@ -59,8 +64,8 @@ range_init(VALUE range, VALUE beg, VALUE end, int exclude_end) } SET_EXCL(range, exclude_end); - RSTRUCT(range)->as.ary[0] = beg; - RSTRUCT(range)->as.ary[1] = end; + RSTRUCT_SET(range, 0, beg); + RSTRUCT_SET(range, 1, end); } VALUE @@ -1228,9 +1233,9 @@ range_loader(VALUE range, VALUE obj) rb_raise(rb_eTypeError, "not a dumped range object"); } - RSTRUCT(range)->as.ary[0] = rb_ivar_get(obj, id_beg); - RSTRUCT(range)->as.ary[1] = rb_ivar_get(obj, id_end); - RSTRUCT(range)->as.ary[2] = rb_ivar_get(obj, id_excl); + RSTRUCT_SET(range, 0, rb_ivar_get(obj, id_beg)); + RSTRUCT_SET(range, 1, rb_ivar_get(obj, id_end)); + RSTRUCT_SET(range, 2, rb_ivar_get(obj, id_excl)); return range; } -- cgit v1.2.3