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

ruby-changes:49959

From: normal <ko1@a...>
Date: Sun, 28 Jan 2018 06:04:46 +0900 (JST)
Subject: [ruby-changes:49959] normal:r62077 (trunk): internal.h: add BITFIELD macro to aid C99 users

normal	2018-01-28 06:04:42 +0900 (Sun, 28 Jan 2018)

  New Revision: 62077

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

  Log:
    internal.h: add BITFIELD macro to aid C99 users
    
    I plan to use this macro to pack other enums in the VM.
    
    * internal.h: add BITFIELD macro
    * method.h: use BITFIELD for rb_method_visibility_t
      [ruby-core:85074] [Misc #14395]

  Modified files:
    trunk/internal.h
    trunk/method.h
Index: method.h
===================================================================
--- method.h	(revision 62076)
+++ method.h	(revision 62077)
@@ -32,16 +32,10 @@ typedef enum { https://github.com/ruby/ruby/blob/trunk/method.h#L32
     METHOD_VISI_MASK = 0x03
 } rb_method_visibility_t;
 
-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
-#define bits_t rb_method_visibility_t
-#else
-#define bits_t unsigned int
-#endif
 typedef struct rb_scope_visi_struct {
-    bits_t method_visi : 3;
+    BITFIELD(rb_method_visibility_t) method_visi : 3;
     unsigned int module_func : 1;
 } rb_scope_visibility_t;
-#undef bits_t
 
 /*! CREF (Class REFerence) */
 typedef struct rb_cref_struct {
Index: internal.h
===================================================================
--- internal.h	(revision 62076)
+++ internal.h	(revision 62077)
@@ -2066,6 +2066,19 @@ rb_obj_builtin_type(VALUE obj) https://github.com/ruby/ruby/blob/trunk/internal.h#L2066
 # define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
 #endif
 
+/*
+ * For declaring bitfields out of non-unsigned int types:
+ *   struct date {
+ *      BITFIELD(enum months) month:4;
+ *      ...
+ *   };
+ */
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+# define BITFIELD(type) type
+#else
+# define BITFIELD(type) unsigned int
+#endif
+
 #if defined(__cplusplus)
 #if 0
 { /* satisfy cc-mode */

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

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