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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-02-25 07:00:10 +00:00
Родитель 7af1261dc8
Коммит df9199d468
4 изменённых файлов: 26 добавлений и 15 удалений

Просмотреть файл

@ -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),[

4
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))

Просмотреть файл

@ -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

Просмотреть файл

@ -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