Feature #9916 ยป opaque-RStruct.patch
| ChangeLog | ||
|---|---|---|
| Sat Jun  7 20:43:42 2014  URABE Shyouhei  <shyouhei@ruby-lang.org> | ||
| 	* 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  <eregontp@gmail.com> | ||
| 	* numeric.c (bit_coerce): remove constant parameter `err' | ||
| include/ruby/intern.h | ||
|---|---|---|
| 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, ...); | ||
| include/ruby/ruby.h | ||
|---|---|---|
|     (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) | ||
| ... | ... | |
| #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)) | ||
| internal.h | ||
|---|---|---|
| #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); | ||
| struct.c | ||
|---|---|---|
| } | ||
| static VALUE | ||
| rb_struct_size(VALUE s); | ||
| static VALUE | ||
| struct_enum_size(VALUE s, VALUE args, VALUE eobj) | ||
| { | ||
|     return rb_struct_size(s); | ||
| ... | ... | |
|  *     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. | ||