Skip to content

Commit

Permalink
configure.in, win32/Makefile.sub: PACKED_STRUCT with VC
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Feb 25, 2014
1 parent 7af1261 commit df9199d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
25 changes: 16 additions & 9 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -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),[
Expand Down
4 changes: 2 additions & 2 deletions time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions timev.h
Original file line number Diff line number Diff line change
@@ -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. */
Expand All @@ -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

Expand Down
8 changes: 6 additions & 2 deletions win32/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df9199d

Please sign in to comment.