+2014-01-23 Eric Blake <eblake@redhat.com>
+
+ pthread: work around winpthread header pollution on mingw
+ * lib/time.in.h: Move pthread workarounds...
+ * lib/pthread.in.h: ...here.
+ * m4/pthread.m4 (gl_PTHREAD_CHECK): Also build pthread.h when we
+ detect macro pollution on mingw.
+ * doc/posix-headers/pthread.texi (pthread.h): Document the problems.
+
2014-01-22 Paul Eggert <eggert@cs.ucla.edu>
qacl: check for fchmod
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html}
-Gnulib module: ---
+Gnulib module: pthread
Portability problems fixed by Gnulib:
@itemize
+@item
+This header pollutes the namespace with some broken macro
+implementations for various functions such as @code{strtok_r} and
+@code{gmtime_r}:
+mingw 3.0.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
-This header file is missing on some platforms:
-Minix 3.1.8, mingw, MSVC 9, BeOS.
+This header file is missing on some platforms; the replacement does
+not offer threads, so much as lightweight stubs that make conditional
+compilation easier for fallbacks to single-threaded programs.
+Minix 3.1.8, mingw 2.x, MSVC 9, BeOS.
@end itemize
#include <stdlib.h>
#undef __need_system_stdlib_h
+
+/* The pthreads-win32 <pthread.h> defines a couple of broken macros. */
+#undef asctime_r
+#undef ctime_r
+#undef gmtime_r
+#undef localtime_r
+#undef rand_r
+#undef strtok_r
+
#include <errno.h>
#include <sched.h>
#include <sys/types.h>
/* 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). Stock Mingw does not define it, but the
- pthreads-win32 library defines it in <pthread.h>. */
+ (e.g., FreeBSD circa 1997). Stock Mingw prior to 3.0 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>
-/* The pthreads-win32 <pthread.h> also defines a couple of broken macros. */
-# undef asctime_r
-# undef ctime_r
-# undef gmtime_r
-# undef localtime_r
-# undef rand_r
-# undef strtok_r
# else
# ifdef __cplusplus
-# pthread.m4 serial 7
+# pthread.m4 serial 8
dnl Copyright (C) 2009-2014 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
gl_CHECK_NEXT_HEADERS([pthread.h])
if test $ac_cv_header_pthread_h = yes; then
HAVE_PTHREAD_H=1
+ # mingw 3.0 uses winpthreads which installs broken macros via <pthread.h>
+ AC_CACHE_CHECK([whether <pthread.h> pollutes the namespace],
+ [gl_cv_header_pthread_h_pollution],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <pthread.h>
+ #ifdef strtok_r
+ #error
+ break me
+ #endif
+ ]])],
+ [gl_cv_header_pthread_h_pollution=no],
+ [gl_cv_header_pthread_h_pollution=yes])])
else
HAVE_PTHREAD_H=0
fi
test $ac_cv_type_pthread_spinlock_t != yes; then
PTHREAD_H='pthread.h'
AC_LIBOBJ([pthread])
+ elif test $gl_cv_header_pthread_h_pollution = yes; then
+ PTHREAD_H=pthread.h
else
PTHREAD_H=
fi