Limit exposing rwlock API on GNU/Linux. master
authorNIIBE Yutaka <gniibe@fsij.org>
Wed, 15 May 2019 00:43:38 +0000 (09:43 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Wed, 15 May 2019 00:43:38 +0000 (09:43 +0900)
* configure.ac (INSERT_EXPOSE_RWLOCK_API): New.
* src/npth.h.in: Use INSERT_EXPOSE_RWLOCK_API.
* tests/Makefile.am (AM_CPPFLAGS): Remove _POSIX_C_SOURCE.

--

Npth has rwlock implementation and offers its API.  It uses Pthread's
rwlock API if available.

On GNU/Linux, Pthread's rwlock API is only exposed when using newer
POSIX API.  Because of this, we had -D_POSIX_C_SOURCE=200112L for our
test programs (for the case using c99 executable, where the API is not
exposed).

This suggests that using Npth requires newer POSIX API.  It's not the
case, actually.

The right solution here is to limit exposing nPth's rwlock API, when
older API is selected, just like Pthread's rwlock API.  Then, Npth can
be used for building program with older API.

Also, by removing -D_POSIX_C_SOURCE=200112L, it fixes build breakage
on Solaris 11.

GnuPG-bug-id: 4491
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
configure.ac
src/npth.h.in
tests/Makefile.am

index 23718d6..8090448 100644 (file)
@@ -284,6 +284,16 @@ if test x"$ac_cv_type_pthread_rwlock_t" = xno; then
 fi
 AC_SUBST(INSERT_NO_RWLOCK)
 
+case "${host}" in
+    *-*-linux*|*-*-gnu*)
+        INSERT_EXPOSE_RWLOCK_API="define _NPTH_EXPOSE_RWLOCK_API (defined(__USE_UNIX98) || defined(__USE_XOPEN2K))"
+        ;;
+    *)
+        INSERT_EXPOSE_RWLOCK_API="define _NPTH_EXPOSE_RWLOCK_API 1"
+        ;;
+esac
+AC_SUBST(INSERT_EXPOSE_RWLOCK_API)
+
 AC_CHECK_FUNCS([select pselect gettimeofday])
 
 npth_LIBSOCKET
index 1901ded..ea325c1 100644 (file)
@@ -60,6 +60,7 @@
 #define _NPTH_NO_RWLOCK 1
 #endif
 #endif
+#@INSERT_EXPOSE_RWLOCK_API@
 
 #ifdef __cplusplus
 extern "C" {
@@ -216,6 +217,7 @@ int npth_mutex_timedlock(npth_mutex_t *mutex, const struct timespec *abstime);
 
 #define npth_mutex_unlock pthread_mutex_unlock
 
+#if _NPTH_EXPOSE_RWLOCK_API
 #ifdef _NPTH_NO_RWLOCK
 
 typedef int npth_rwlockattr_t;
@@ -285,6 +287,7 @@ int npth_rwlock_timedwrlock (npth_rwlock_t *rwlock,
 #define npth_rwlock_unlock  pthread_rwlock_unlock
 
 #endif /* !_NPTH_NO_RWLOCK */
+#endif
 
 
 typedef pthread_cond_t npth_cond_t;
index 8092a3c..8dc681d 100644 (file)
 
 TESTS = t-mutex t-thread
 
-# We explicitly require POSIX.1-2001 so that pthread_rwlock_t is
-# available when build with c99.
 if HAVE_W32_SYSTEM
 AM_CPPFLAGS = -I$(top_srcdir)/w32
 AM_LDFLAGS =
 LDADD = ../w32/libnpth.la $(LIB_CLOCK_GETTIME)
 else
-AM_CPPFLAGS = -I../src -D_POSIX_C_SOURCE=200112L
+AM_CPPFLAGS = -I../src
 AM_LDFLAGS =
 LDADD = ../src/libnpth.la $(LIBSOCKET) $(LIB_CLOCK_GETTIME)
 TESTS += t-fork