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 --- include/ruby/ruby.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 32e7e196e7..f812e3146b 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -709,6 +709,9 @@ VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type); #ifndef RGENGC_WB_PROTECTED_HASH #define RGENGC_WB_PROTECTED_HASH 1 #endif +#ifndef RGENGC_WB_PROTECTED_STRUCT +#define RGENGC_WB_PROTECTED_STRUCT 1 +#endif #ifndef RGENGC_WB_PROTECTED_STRING #define RGENGC_WB_PROTECTED_STRING 1 #endif @@ -1109,9 +1112,9 @@ struct RStruct { union { struct { long len; - VALUE *ptr; + const VALUE *ptr; } heap; - VALUE ary[RSTRUCT_EMBED_LEN_MAX]; + const VALUE ary[RSTRUCT_EMBED_LEN_MAX]; } as; }; #define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1) @@ -1121,11 +1124,15 @@ struct RStruct { (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \ (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \ RSTRUCT(st)->as.heap.len) -#define RSTRUCT_PTR(st) \ - ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ - RSTRUCT(st)->as.ary : \ - RSTRUCT(st)->as.heap.ptr) #define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st)) +#define RSTRUCT_RAWPTR(st) \ + ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ + RSTRUCT(st)->as.ary : \ + RSTRUCT(st)->as.heap.ptr) +#define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_RAWPTR(RGENGC_WB_PROTECTED_STRUCT ? OBJ_WB_GIVEUP((VALUE)st) : (VALUE)st)) + +#define RSTRUCT_SET(st, idx, v) OBJ_WRITE(st, (VALUE *)&RSTRUCT_RAWPTR(st)[idx], v) +#define RSTRUCT_GET(st, idx) (RSTRUCT_RAWPTR(st)[idx]) #define RBIGNUM_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(BDIGIT))) struct RBignum { -- cgit v1.2.3