summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-21 11:22:18 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-21 11:22:18 +0000
commit6a1101f23ea403a8825c2f361508eeb85878b011 (patch)
tree89d04376f051f7aa2062fb9c1a46313b2ed22b49 /range.c
parentc54a1abde3753fe94176ef959342a5972eae0e73 (diff)
* 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
Diffstat (limited to 'range.c')
-rw-r--r--range.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/range.c b/range.c
index 6d6a528..280c333 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;
}