summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in25
-rw-r--r--time.c4
-rw-r--r--timev.h4
-rw-r--r--win32/Makefile.sub8
4 files changed, 26 insertions, 15 deletions
diff --git a/configure.in b/configure.in
index bdb22f0318..f13f550be7 100644
--- a/configure.in
+++ b/configure.in
@@ -1273,17 +1273,24 @@ RUBY_CHECK_SIZEOF(time_t, [long "long long"], [], [@%:@include <time.h>])
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),[
diff --git a/time.c b/time.c
index acd589a8fc..1539feb587 100644
--- a/time.c
+++ b/time.c
@@ -1740,12 +1740,12 @@ localtimew(wideval_t timew, struct vtm *result)
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))
diff --git a/timev.h b/timev.h
index bedf9a174a..3947477630 100644
--- a/timev.h
+++ b/timev.h
@@ -1,7 +1,7 @@
#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 {
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
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index 03cf78110d..dd3514b348 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -570,8 +570,12 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
!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