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

ruby-changes:28747

From: akr <ko1@a...>
Date: Fri, 17 May 2013 22:04:28 +0900 (JST)
Subject: [ruby-changes:28747] akr:r40799 (trunk): * ext/socket/ifaddr.c: Use unsigned LONG_LONG to represent flags

akr	2013-05-17 22:04:17 +0900 (Fri, 17 May 2013)

  New Revision: 40799

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40799

  Log:
    * ext/socket/ifaddr.c: Use unsigned LONG_LONG to represent flags
      because SunOS 5.11 (OpenIndiana) defines ifa_flags as uint64_t.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/ifaddr.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40798)
+++ ChangeLog	(revision 40799)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri May 17 22:02:15 2013  Tanaka Akira  <akr@f...>
+
+	* ext/socket/ifaddr.c: Use unsigned LONG_LONG to represent flags
+	  because SunOS 5.11 (OpenIndiana) defines ifa_flags as uint64_t.
+
 Fri May 17 21:47:00 2013  Zachary Scott  <zachary@z...>
 
 	* cont.c: Typo in constant MAX_MACHINE_STACK_CACHE from '..MAHINE..'
Index: ext/socket/ifaddr.c
===================================================================
--- ext/socket/ifaddr.c	(revision 40798)
+++ ext/socket/ifaddr.c	(revision 40799)
@@ -1,6 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ext/socket/ifaddr.c#L1
 #include "rubysocket.h"
 
 #ifdef HAVE_GETIFADDRS
+
+/*
+ * ifa_flags is usually unsigned int.
+ * However it is uint64_t on SunOS 5.11 (OpenIndiana).
+ */
+#ifdef HAVE_LONG_LONG
+typedef unsigned LONG_LONG ifa_flags_t;
+#define PRIxIFAFLAGS PRI_LL_PREFIX"x"
+#define IFAFLAGS2NUM(flags) ULL2NUM(flags)
+#else
+typedef unsigned int ifa_flags_t;
+#define PRIxIFAFLAGS "x"
+#define IFAFLAGS2NUM(flags) UINT2NUM(flags)
+#endif
+
 VALUE rb_cSockIfaddr;
 
 typedef struct rb_ifaddr_tag rb_ifaddr_t;
@@ -163,7 +178,7 @@ ifaddr_flags(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/ifaddr.c#L178
 {
     rb_ifaddr_t *rifaddr = get_ifaddr(self);
     struct ifaddrs *ifa = rifaddr->ifaddr;
-    return UINT2NUM(ifa->ifa_flags);
+    return IFAFLAGS2NUM(ifa->ifa_flags);
 }
 
 /*
@@ -239,11 +254,11 @@ ifaddr_dstaddr(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/ifaddr.c#L254
 }
 
 static void
-ifaddr_inspect_flags(unsigned int flags, VALUE result)
+ifaddr_inspect_flags(ifa_flags_t flags, VALUE result)
 {
     const char *sep = " ";
 #define INSPECT_BIT(bit, name) \
-    if (flags & (bit)) { rb_str_catf(result, "%s" name, sep); flags &= ~(bit); sep = ","; }
+    if (flags & (bit)) { rb_str_catf(result, "%s" name, sep); flags &= ~(ifa_flags_t)(bit); sep = ","; }
 #ifdef IFF_UP
     INSPECT_BIT(IFF_UP, "UP")
 #endif
@@ -303,7 +318,7 @@ ifaddr_inspect_flags(unsigned int flags, https://github.com/ruby/ruby/blob/trunk/ext/socket/ifaddr.c#L318
 #endif
 #undef INSPECT_BIT
     if (flags) {
-        rb_str_catf(result, "%s%#x", sep, flags);
+        rb_str_catf(result, "%s%#"PRIxIFAFLAGS, sep, flags);
     }
 }
 

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

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