From de511595692f27dd4f132d752d74af00c1b813aa Mon Sep 17 00:00:00 2001 From: "Urabe, Shyouhei" Date: Sat, 7 Jun 2014 20:58:41 +0900 Subject: [PATCH] * include/ruby/ruby.h (struct RStruct): no longer. * internal.h (struct RStruct): moved here. * struct.c (rb_struct_ptr): a compensation function for the lack of RSTRUCT_PTR. But now that we have RSTRUCT_GET/SET, that must not be used anyway. I mark this deprecated. Dont use it. Signed-off-by: Urabe, Shyouhei --- ChangeLog | 10 ++++++++++ include/ruby/intern.h | 2 ++ include/ruby/ruby.h | 32 ++++---------------------------- internal.h | 36 ++++++++++++++++++++++++++++++++++++ struct.c | 11 +++++++---- 5 files changed, 59 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 154eaf1..53e7dda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Sat Jun 7 20:43:42 2014 URABE Shyouhei + + * include/ruby/ruby.h (struct RStruct): no longer. + + * internal.h (struct RStruct): moved here. + + * struct.c (rb_struct_ptr): a compensation function for the lack + of RSTRUCT_PTR. But now that we have RSTRUCT_GET/SET, that must + not be used anyway. I mark this deprecated. Dont use it. + Sat Jun 7 18:15:33 2014 Benoit Daloze * numeric.c (bit_coerce): remove constant parameter `err' diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 387f000..d8321e0 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -835,6 +835,8 @@ VALUE rb_struct_aset(VALUE, VALUE, VALUE); VALUE rb_struct_getmember(VALUE, ID); VALUE rb_struct_s_members(VALUE); VALUE rb_struct_members(VALUE); +VALUE rb_struct_size(VALUE s); +DEPRECATED(VALUE const* rb_struct_ptr(VALUE s)); VALUE rb_struct_alloc_noinit(VALUE); VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t, ...); VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc, ...); diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 7c7cb67..499cb2b 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1040,33 +1040,10 @@ void *rb_check_typeddata(VALUE, const rb_data_type_t *); (sval) = (type*)rb_check_typeddata((obj), (data_type)); \ } while (0) -#define RSTRUCT_EMBED_LEN_MAX 3 -struct RStruct { - struct RBasic basic; - union { - struct { - long len; - const VALUE *ptr; - } heap; - const VALUE ary[RSTRUCT_EMBED_LEN_MAX]; - } as; -}; -#define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1) -#define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1) -#define RSTRUCT_LEN(st) \ - ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ - (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \ - (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \ - RSTRUCT(st)->as.heap.len) -#define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st)) -#define RSTRUCT_CONST_PTR(st) \ - ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ - RSTRUCT(st)->as.ary : \ - RSTRUCT(st)->as.heap.ptr) -#define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_CONST_PTR(RGENGC_WB_PROTECTED_STRUCT ? OBJ_WB_UNPROTECT((VALUE)st) : (VALUE)st)) - -#define RSTRUCT_SET(st, idx, v) RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[idx], (v)) -#define RSTRUCT_GET(st, idx) (RSTRUCT_CONST_PTR(st)[idx]) +#define RSTRUCT_LEN(st) rb_struct_size(st) +#define RSTRUCT_PTR(st) rb_struct_ptr(st) +#define RSTRUCT_SET(st, idx, v) rb_struct_aset(st, INT2NUM(idx), (v)) +#define RSTRUCT_GET(st, idx) rb_struct_aref(st, INT2NUM(idx)) #define RBIGNUM_SIGN(b) (FIX2LONG(rb_big_cmp((b), INT2FIX(0))) >= 0) #define RBIGNUM_POSITIVE_P(b) (FIX2LONG(rb_big_cmp((b), INT2FIX(0))) >= 0) @@ -1084,7 +1061,6 @@ struct RStruct { #define RHASH(obj) (R_CAST(RHash)(obj)) #define RDATA(obj) (R_CAST(RData)(obj)) #define RTYPEDDATA(obj) (R_CAST(RTypedData)(obj)) -#define RSTRUCT(obj) (R_CAST(RStruct)(obj)) #define RFILE(obj) (R_CAST(RFile)(obj)) #define RCOMPLEX(obj) (R_CAST(RComplex)(obj)) diff --git a/internal.h b/internal.h index 2c1c6a3..c9077e9 100644 --- a/internal.h +++ b/internal.h @@ -420,6 +420,42 @@ struct RSymbol { #define RSYMBOL(obj) (R_CAST(RSymbol)(obj)) +#define RSTRUCT_EMBED_LEN_MAX 3 +struct RStruct { + struct RBasic basic; + union { + struct { + long len; + const VALUE *ptr; + } heap; + const VALUE ary[RSTRUCT_EMBED_LEN_MAX]; + } as; +}; +#ifdef RSTRUCT_SET +#undef RSTRUCT_LEN +#undef RSTRUCT_PTR +#undef RSTRUCT_SET +#undef RSTRUCT_GET +#endif +#define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1) +#define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1) +#define RSTRUCT_LEN(st) \ + ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ + (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \ + (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \ + RSTRUCT(st)->as.heap.len) +#define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st)) +#define RSTRUCT_CONST_PTR(st) \ + ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ + RSTRUCT(st)->as.ary : \ + RSTRUCT(st)->as.heap.ptr) +#define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_CONST_PTR(RGENGC_WB_PROTECTED_STRUCT ? OBJ_WB_UNPROTECT((VALUE)st) : (VALUE)st)) + +#define RSTRUCT_SET(st, idx, v) RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[idx], (v)) +#define RSTRUCT_GET(st, idx) (RSTRUCT_CONST_PTR(st)[idx]) + +#define RSTRUCT(obj) (R_CAST(RStruct)(obj)) + /* class.c */ void rb_class_subclass_add(VALUE super, VALUE klass); void rb_class_remove_from_super_subclasses(VALUE); diff --git a/struct.c b/struct.c index 0afc0a9..5981b6b 100644 --- a/struct.c +++ b/struct.c @@ -515,9 +515,6 @@ rb_struct_new(VALUE klass, ...) } static VALUE -rb_struct_size(VALUE s); - -static VALUE struct_enum_size(VALUE s, VALUE args, VALUE eobj) { return rb_struct_size(s); @@ -1032,12 +1029,18 @@ rb_struct_eql(VALUE s, VALUE s2) * joe.length #=> 3 */ -static VALUE +VALUE rb_struct_size(VALUE s) { return LONG2FIX(RSTRUCT_LEN(s)); } +VALUE const* +rb_struct_ptr(VALUE s) +{ + return RSTRUCT_CONST_PTR(s); +} + /* * A Struct is a convenient way to bundle a number of attributes together, * using accessor methods, without having to write an explicit class. -- 1.9.1