[前][次][番号順一覧][スレッド一覧]

ruby-changes:43715

From: shyouhei <ko1@a...>
Date: Mon, 1 Aug 2016 16:24:01 +0900 (JST)
Subject: [ruby-changes:43715] shyouhei:r55788 (trunk): hide struct internal [Feature #9916]

shyouhei	2016-08-01 16:23:56 +0900 (Mon, 01 Aug 2016)

  New Revision: 55788

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55788

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/intern.h
    trunk/include/ruby/ruby.h
    trunk/internal.h
    trunk/struct.c
Index: struct.c
===================================================================
--- struct.c	(revision 55787)
+++ struct.c	(revision 55788)
@@ -617,9 +617,6 @@ rb_struct_new(VALUE klass, ...) https://github.com/ruby/ruby/blob/trunk/struct.c#L617
 }
 
 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) https://github.com/ruby/ruby/blob/trunk/struct.c#L1120
  *     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
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 55787)
+++ include/ruby/ruby.h	(revision 55788)
@@ -1178,38 +1178,10 @@ void *rb_check_typeddata(VALUE, const rb https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1178
 #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 { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1197
 #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) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L2016
 	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 };
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 55787)
+++ include/ruby/intern.h	(revision 55788)
@@ -884,6 +884,8 @@ VALUE rb_struct_aset(VALUE, VALUE, VALUE https://github.com/ruby/ruby/blob/trunk/include/ruby/intern.h#L884
 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, ...);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55787)
+++ ChangeLog	(revision 55788)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Aug  1 16:07:18 2016  URABE Shyouhei  <shyouhei@r...>
+
+	* 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@j...>
 
 	* object.c (rb_obj_clone2): Allow Object#clone to take freeze:
Index: internal.h
===================================================================
--- internal.h	(revision 55787)
+++ internal.h	(revision 55788)
@@ -576,6 +576,57 @@ struct RHash { https://github.com/ruby/ruby/blob/trunk/internal.h#L576
 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 {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]