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

ruby-changes:33094

From: nobu <ko1@a...>
Date: Tue, 25 Feb 2014 16:00:15 +0900 (JST)
Subject: [ruby-changes:33094] nobu:r45173 (trunk): configure.in, win32/Makefile.sub: PACKED_STRUCT with VC

nobu	2014-02-25 16:00:10 +0900 (Tue, 25 Feb 2014)

  New Revision: 45173

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

  Log:
    configure.in, win32/Makefile.sub: PACKED_STRUCT with VC
    
    * configure.in (PACKED_STRUCT): check VC pragma too, and make
      function-style macro.
    
    * win32/Makefile.sub (PACKED_STRUCT): enable with VC.

  Modified files:
    trunk/configure.in
    trunk/time.c
    trunk/timev.h
    trunk/win32/Makefile.sub
Index: time.c
===================================================================
--- time.c	(revision 45172)
+++ time.c	(revision 45173)
@@ -1740,12 +1740,12 @@ localtimew(wideval_t timew, struct vtm * https://github.com/ruby/ruby/blob/trunk/time.c#L1740
     return result;
 }
 
-struct time_object {
+PACKED_STRUCT_UNALIGNED(struct time_object {
     wideval_t timew; /* time_t value * TIME_SCALE.  possibly Rational. */
     struct vtm vtm;
     uint8_t gmt:3; /* 0:utc 1:localtime 2:fixoff 3:init */
     uint8_t tm_got:1;
-} PACKED_STRUCT_UNALIGNED;
+});
 
 #define GetTimeval(obj, tobj) ((tobj) = get_timeval(obj))
 #define GetNewTimeval(obj, tobj) ((tobj) = get_new_timeval(obj))
Index: configure.in
===================================================================
--- configure.in	(revision 45172)
+++ configure.in	(revision 45173)
@@ -1273,17 +1273,24 @@ RUBY_CHECK_SIZEOF(time_t, [long "long lo https://github.com/ruby/ruby/blob/trunk/configure.in#L1273
 RUBY_CHECK_SIZEOF(clock_t, [], [], [@%:@include <time.h>])
 
 AC_CACHE_CHECK(packed struct attribute, rb_cv_packed_struct,
-  [AC_TRY_COMPILE([struct { int a; } __attribute__((packed));], [],
-  [rb_cv_packed_struct=yes], [rb_cv_packed_struct=no])])
-if test "$rb_cv_packed_struct" = yes; then
-  AC_DEFINE_UNQUOTED(PACKED_STRUCT, __attribute__((packed)))
-  AS_CASE(["$target_cpu"],
-    [x86*|i?86|x64], [AC_DEFINE_UNQUOTED(PACKED_STRUCT_UNALIGNED, PACKED_STRUCT)],
-    [AC_DEFINE_UNQUOTED(PACKED_STRUCT_UNALIGNED,)])
+    [rb_cv_packed_struct=no
+    for mac in \
+	"__pragma(pack(push, 1)) x __pragma(pack(pop))" \
+	"x __attribute__((packed))" \
+	; do
+	AC_TRY_COMPILE([@%:@define PACKED_STRUCT(x) $mac
+			PACKED_STRUCT(struct { int a; });], [],
+		[rb_cv_packed_struct=$mac; break])
+    done])
+packed_struct_unaligned=x
+if test "$rb_cv_packed_struct" != no; then
+    AC_DEFINE_UNQUOTED([PACKED_STRUCT(x)], [$rb_cv_packed_struct])
+    AS_CASE(["$target_cpu"],
+	    [x86*|i?86|x64], [packed_struct_unaligned='PACKED_STRUCT(x)'])
 else
-  AC_DEFINE_UNQUOTED(PACKED_STRUCT,)
-  AC_DEFINE_UNQUOTED(PACKED_STRUCT_UNALIGNED,)
+    AC_DEFINE_UNQUOTED([PACKED_STRUCT(x)], x)
 fi
+AC_DEFINE_UNQUOTED(PACKED_STRUCT_UNALIGNED(x), $packed_struct_unaligned)
 
 AC_DEFUN([RUBY_CHECK_PRINTF_PREFIX], [
 AC_CACHE_CHECK([for printf prefix for $1], [rb_cv_pri_prefix_]AS_TR_SH($1),[
Index: win32/Makefile.sub
===================================================================
--- win32/Makefile.sub	(revision 45172)
+++ win32/Makefile.sub	(revision 45173)
@@ -570,8 +570,12 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/ https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L570
 !if $(MSC_VER) >= 1500
 #define RUBY_FUNCTION_NAME_STRING __FUNCTION__
 !endif
-#define PACKED_STRUCT
-#define PACKED_STRUCT_UNALIGNED
+#define PACKED_STRUCT(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
+!if "$(ARCH)" == "x86" || "$(ARCH)" == "x64" || "$(ARCH)" == "ia64"
+#define PACKED_STRUCT_UNALIGNED(x) PACKED_STRUCT(x)
+!else
+#define PACKED_STRUCT_UNALIGNED(x) x
+!endif
 #define RUBY_EXTERN extern __declspec(dllimport)
 #define HAVE_DECL_SYS_NERR 1
 #define HAVE_LIMITS_H 1
Index: timev.h
===================================================================
--- timev.h	(revision 45172)
+++ timev.h	(revision 45173)
@@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/timev.h#L1
 #ifndef RUBY_TIMEV_H
 #define RUBY_TIMEV_H
 
-struct vtm {
+PACKED_STRUCT_UNALIGNED(struct vtm {
     VALUE year; /* 2000 for example.  Integer. */
     VALUE subsecx; /* 0 <= subsecx < TIME_SCALE.  possibly Rational. */
     VALUE utc_offset; /* -3600 as -01:00 for example.  possibly Rational. */
@@ -14,7 +14,7 @@ struct vtm { https://github.com/ruby/ruby/blob/trunk/timev.h#L14
     uint8_t sec:6; /* 0..60 */
     uint8_t wday:3; /* 0:Sunday, 1:Monday, ..., 6:Saturday 7:init */
     uint8_t isdst:2; /* 0:StandardTime 1:DayLightSavingTime 3:init */
-} PACKED_STRUCT_UNALIGNED;
+});
 
 #define TIME_SCALE 1000000000
 

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

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