diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-01 07:23:56 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-01 07:23:56 +0000 |
commit | 26f59b09fe3a1c2ec50145f7c3d5b425f48a7a32 (patch) | |
tree | d0237be78237736d42b3dc47d3797f80ce5d3351 /internal.h | |
parent | 0a86f7ff71f3da557d5e2e11c7bd637726b5d123 (diff) | |
download | ruby-26f59b09fe3a1c2ec50145f7c3d5b425f48a7a32.tar.gz |
hide struct internal [Feature #9916]
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'internal.h')
-rw-r--r-- | internal.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/internal.h b/internal.h index d92c0fc374..b013f84616 100644 --- a/internal.h +++ b/internal.h @@ -576,6 +576,57 @@ struct RHash { extern void ruby_init_setproctitle(int argc, char *argv[]); #endif +#define RSTRUCT_EMBED_LEN_MAX RSTRUCT_EMBED_LEN_MAX +#define RSTRUCT_EMBED_LEN_MASK RSTRUCT_EMBED_LEN_MASK +#define RSTRUCT_EMBED_LEN_SHIFT RSTRUCT_EMBED_LEN_SHIFT +enum { + RSTRUCT_EMBED_LEN_MAX = 3, + RSTRUCT_EMBED_LEN_MASK = (RUBY_FL_USER2|RUBY_FL_USER1), + RSTRUCT_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+1), + + RSTRUCT_ENUM_END +}; + +struct RStruct { + struct RBasic basic; + union { + struct { + long len; + const VALUE *ptr; + } heap; + const VALUE ary[RSTRUCT_EMBED_LEN_MAX]; + } as; +}; + +#undef RSTRUCT_LEN +#undef RSTRUCT_PTR +#undef RSTRUCT_SET +#undef RSTRUCT_GET +#define RSTRUCT_EMBED_LEN(st) \ + (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \ + (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) +#define RSTRUCT_LEN(st) rb_struct_len(st) +#define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st)) +#define RSTRUCT_CONST_PTR(st) rb_struct_const_ptr(st) +#define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_CONST_PTR(RB_OBJ_WB_UNPROTECT_FOR(STRUCT, 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)) + +static inline long +rb_struct_len(VALUE st) +{ + return (RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? + RSTRUCT_EMBED_LEN(st) : RSTRUCT(st)->as.heap.len; +} + +static inline const VALUE * +rb_struct_const_ptr(VALUE st) +{ + return FIX_CONST_VALUE_PTR((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? + RSTRUCT(st)->as.ary : RSTRUCT(st)->as.heap.ptr); +} + /* class.c */ struct rb_deprecated_classext_struct { |