aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--include/ruby/intern.h2
-rw-r--r--include/ruby/ruby.h51
-rw-r--r--internal.h51
-rw-r--r--struct.c11
5 files changed, 74 insertions, 51 deletions
diff --git a/ChangeLog b/ChangeLog
index 2071f1a0a6..aa194c599e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Mon Aug 1 16:07:18 2016 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.
+
Mon Aug 1 14:50:06 2016 Jeremy Evans <code@jeremyevans.net>
* object.c (rb_obj_clone2): Allow Object#clone to take freeze:
diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index c6520d8443..48608f32c3 100644
--- a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -884,6 +884,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(const VALUE *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 583b338d7e..634fe60c51 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1178,38 +1178,10 @@ void *rb_check_typeddata(VALUE, const rb_data_type_t *);
#define TypedData_Get_Struct(obj,type,data_type,sval) \
((sval) = (type*)rb_check_typeddata((obj), (data_type)))
-#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;
-};
-
-#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_LEN(st) rb_struct_size(st)
+#define RSTRUCT_PTR(st) rb_struct_const_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)
@@ -1225,7 +1197,6 @@ struct RStruct {
#define RARRAY(obj) (R_CAST(RArray)(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 FL_SINGLETON RUBY_FL_SINGLETON
@@ -2045,20 +2016,6 @@ rb_array_const_ptr(VALUE a)
RARRAY(a)->as.ary : RARRAY(a)->as.heap.ptr);
}
-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);
-}
-
#if defined(EXTLIB) && defined(USE_DLN_A_OUT)
/* hook for external modules */
static char *dln_libs_to_be_linked[] = { EXTLIB, 0 };
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 {
diff --git a/struct.c b/struct.c
index a4cab45945..150ca20a39 100644
--- a/struct.c
+++ b/struct.c
@@ -617,9 +617,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);
@@ -1123,12 +1120,18 @@ rb_struct_eql(VALUE s, VALUE s2)
* joe.length #=> 3
*/
-static VALUE
+VALUE
rb_struct_size(VALUE s)
{
return LONG2FIX(RSTRUCT_LEN(s));
}
+const VALUE*
+rb_struct_ptr(VALUE s)
+{
+ return RSTRUCT_CONST_PTR(s);
+}
+
/*
* call-seq:
* struct.dig(key, ...) -> object