[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] time: work with mingw + pthreads-win32 library
From: |
Eric Blake |
Subject: |
[PATCH] time: work with mingw + pthreads-win32 library |
Date: |
Wed, 2 Jun 2010 14:02:51 -0600 |
When using the pthreads-win32 library with mingw, struct timespec
is available in <pthread.h>. Meanwhile, that header has some
rather buggy macros for localtime_r and gmtime_r that interfere
with proper gnulib replacement header actions.
Tested in a cross-compilation environment: Fedora 13 with mingw32-gcc
and mingw32-pthreads installed.
* m4/time_h.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Set new variable
if timespec is defined only in pthread.h.
* modules/time (Makefile.am): Substitute it.
Signed-off-by: Eric Blake <address@hidden>
---
This patch was sufficient to get libvirt cross-compiling again on
my system. There's certainly some better cleanups that could
be done, like modernizing the declaration of rpl_localtime to
occur only in the .in.h replacement header and not AC_DEFINE'd
in the .m4 files, but those can be separate. Committing this:
ChangeLog | 7 +++++++
lib/time.in.h | 7 ++++++-
m4/time_h.m4 | 19 ++++++++++++++++++-
modules/time | 1 +
4 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1a40e69..a72e170 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-06-02 Eric Blake <address@hidden>
+
+ time: work with mingw + pthreads-win32 library
+ * m4/time_h.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Set new variable
+ if timespec is defined only in pthread.h.
+ * modules/time (Makefile.am): Substitute it.
+
2010-05-31 Bruno Haible <address@hidden>
Avoid expanding two macros in the wrong order.
diff --git a/lib/time.in.h b/lib/time.in.h
index 9831444..6d2b818 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -48,10 +48,13 @@
/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
Or they define it with the wrong member names or define it in <sys/time.h>
- (e.g., FreeBSD circa 1997). */
+ (e.g., FreeBSD circa 1997). Stock Mingw does not define it, but the
+ pthreads-win32 library defines it in <pthread.h>. */
# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
# include <sys/time.h>
+# elif @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
+# include <pthread.h>
# else
# ifdef __cplusplus
@@ -128,6 +131,7 @@ _GL_CXXALIAS_RPL (localtime_r, struct tm *, (time_t const
*restrict __timer,
struct tm *restrict __result));
# else
# if ! @HAVE_LOCALTIME_R@
+# undef localtime_r
_GL_FUNCDECL_SYS (localtime_r, struct tm *, (time_t const *restrict __timer,
struct tm *restrict __result)
_GL_ARG_NONNULL ((1, 2)));
@@ -148,6 +152,7 @@ _GL_CXXALIAS_RPL (gmtime_r, struct tm *, (time_t const
*restrict __timer,
struct tm *restrict __result));
# else
# if ! @HAVE_LOCALTIME_R@
+# undef gmtime_r
_GL_FUNCDECL_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer,
struct tm *restrict __result)
_GL_ARG_NONNULL ((1, 2)));
diff --git a/m4/time_h.m4 b/m4/time_h.m4
index b88ba94..a45a10a 100644
--- a/m4/time_h.m4
+++ b/m4/time_h.m4
@@ -2,6 +2,8 @@
# Copyright (C) 2000-2001, 2003-2007, 2009-2010 Free Software Foundation, Inc.
+# serial 2
+
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -24,7 +26,7 @@ AC_DEFUN([gl_HEADER_TIME_H_BODY],
])
dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
-dnl in time.h or sys/time.h.
+dnl in time.h, sys/time.h, or pthread.h.
AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
[
@@ -41,6 +43,7 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
TIME_H_DEFINES_STRUCT_TIMESPEC=0
SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
+ PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
TIME_H_DEFINES_STRUCT_TIMESPEC=1
else
@@ -55,10 +58,24 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
[gl_cv_sys_struct_timespec_in_sys_time_h=no])])
if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
+ else
+ AC_CACHE_CHECK([for struct timespec in <pthread.h>],
+ [gl_cv_sys_struct_timespec_in_pthread_h],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <pthread.h>
+ ]],
+ [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
+ [gl_cv_sys_struct_timespec_in_pthread_h=yes],
+ [gl_cv_sys_struct_timespec_in_pthread_h=no])])
+ if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
+ PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
+ fi
fi
fi
AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
+ AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
])
AC_DEFUN([gl_TIME_MODULE_INDICATOR],
diff --git a/modules/time b/modules/time
index 52336ed..22ddd0f 100644
--- a/modules/time
+++ b/modules/time
@@ -40,6 +40,7 @@ time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H)
$(WARN_ON_USE_H)
-e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
-e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
-e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
+ -e
's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g'
\
-e
's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g'
\
-e
's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
-e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
--
1.7.0.1