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 --- struct.c | 126 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 61 insertions(+), 65 deletions(-) (limited to 'struct.c') diff --git a/struct.c b/struct.c index 4356f0013f..dbfd406f72 100644 --- a/struct.c +++ b/struct.c @@ -89,17 +89,15 @@ rb_struct_members_m(VALUE obj) VALUE rb_struct_getmember(VALUE obj, ID id) { - VALUE members, slot, *ptr, *ptr_members; + VALUE members, slot; long i, len; - ptr = RSTRUCT_PTR(obj); members = rb_struct_members(obj); - ptr_members = RARRAY_PTR(members); slot = ID2SYM(id); len = RARRAY_LEN(members); for (i=0; i argc) { - rb_mem_clear(RSTRUCT_PTR(self)+argc, n-argc); + rb_mem_clear((VALUE *)RSTRUCT_RAWPTR(self)+argc, n-argc); } return Qnil; } @@ -414,18 +412,18 @@ static VALUE struct_alloc(VALUE klass) { long n; - NEWOBJ_OF(st, struct RStruct, klass, T_STRUCT); + NEWOBJ_OF(st, struct RStruct, klass, T_STRUCT | (RGENGC_WB_PROTECTED_STRUCT ? FL_WB_PROTECTED : 0)); n = num_members(klass); if (0 < n && n <= RSTRUCT_EMBED_LEN_MAX) { RBASIC(st)->flags &= ~RSTRUCT_EMBED_LEN_MASK; RBASIC(st)->flags |= n << RSTRUCT_EMBED_LEN_SHIFT; - rb_mem_clear(st->as.ary, n); + rb_mem_clear((VALUE *)st->as.ary, n); } else { st->as.heap.ptr = ALLOC_N(VALUE, n); - rb_mem_clear(st->as.heap.ptr, n); + rb_mem_clear((VALUE *)st->as.heap.ptr, n); st->as.heap.len = n; } @@ -488,7 +486,7 @@ rb_struct_each(VALUE s) RETURN_SIZED_ENUMERATOR(s, 0, 0, rb_struct_size); for (i=0; i"); OBJ_INFECT(str, s); @@ -604,7 +600,7 @@ rb_struct_inspect(VALUE s) static VALUE rb_struct_to_a(VALUE s) { - return rb_ary_new4(RSTRUCT_LEN(s), RSTRUCT_PTR(s)); + return rb_ary_new4(RSTRUCT_LEN(s), RSTRUCT_RAWPTR(s)); } /* @@ -626,7 +622,7 @@ rb_struct_to_h(VALUE s) long i; for (i=0; i