[PATCH] Portability fixes

Joerg Sonnenberger joerg at britannica.bec.de
Thu Jan 24 12:21:59 PST 2008


Hi all,
the attached patches deal with a number of issues:
- defining and undefining _POSIX_SOURCE is evil, it has side-effects
behond the just included header. pkgsrc hasn't hit issues with this and
is getting modular Xorg testing on a number of platforms.
- use real configure checks for a number of reentrant functions.

This patches has been tested at least on DragonFly, NetBSD, HP-UX and
AIX.

Joerg
-------------- next part --------------
$NetBSD: patch-aa,v 1.4 2006/12/30 11:50:11 joerg Exp $

--- Xos_r.h.in.orig	2006-09-20 19:59:42.000000000 +0200
+++ Xos_r.h.in
@@ -76,13 +76,7 @@ in this Software without prior written a
 # include <X11/Xfuncs.h>
 
 # ifndef X_NOT_POSIX
-#  ifdef _POSIX_SOURCE
-#   include <limits.h>
-#  else
-#   define _POSIX_SOURCE
-#   include <limits.h>
-#   undef _POSIX_SOURCE
-#  endif
+#  include <limits.h>
 #  ifndef LINE_MAX
 #   define X_LINE_MAX 2048
 #  else
@@ -188,6 +182,13 @@ extern void XtProcessUnlock(
 #  endif
 # endif
 
+#undef _XOS_R_H_MTSAFE_DIRENTAPI
+#undef _XOS_R_H_MTSAFE_NETDBAPI
+#undef _XOS_R_H_MTSAFE_PWDAPI
+#undef _XOS_R_H_MTSAFE_UNISTDAPI
+#undef _XOS_R_H_MTSAFE_STRINGAPI
+#undef _XOS_R_H_MTSAFE_TIMEAPI
+#undef _XOS_R_H_MTSAFE_GRPAPI
 #endif /* !defined WIN32 */
 
 /*
@@ -226,7 +227,7 @@ extern void XtProcessUnlock(
 
 #if defined(X_INCLUDE_PWD_H) && !defined(_XOS_INCLUDED_PWD_H)
 # include <pwd.h>
-# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_PWDAPI)
+# if defined(_XOS_R_H_MTSAFE_PWDAPI)
 #  define XOS_USE_MTSAFE_PWDAPI 1
 # endif
 #endif
@@ -330,7 +331,7 @@ static __inline__ void _Xpw_copyPasswd(_
   (_Xos_processUnlock), \
   (p).pwp )
 
-#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(__APPLE__)
+#elif !defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(__APPLE__) && !defined(__NetBSD__)
 /* SVR4 threads, AIX 4.2.0 and earlier and OSF/1 3.2 and earlier pthreads */
 # define X_NEEDS_PWPARAMS
 typedef struct {
@@ -410,7 +411,7 @@ typedef int _Xgetpwret;
 #if defined(X_INCLUDE_NETDB_H) && !defined(_XOS_INCLUDED_NETDB_H) \
     && !defined(WIN32)
 # include <netdb.h>
-# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_NETDBAPI)
+# if defined(_XOS_R_H_MTSAFE_NETDBAPI)
 #  define XOS_USE_MTSAFE_NETDBAPI 1
 # endif
 #endif
@@ -573,7 +574,7 @@ typedef int _Xgetservbynameparams; /* du
 #   define dirent direct
 #  endif
 # endif
-# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_DIRENTAPI)
+# if defined(_XOS_R_H_MTSAFE_DIRENTAPI)
 #  define XOS_USE_MTSAFE_DIRENTAPI 1
 # endif
 #endif
@@ -656,15 +657,8 @@ extern int _Preaddir_r(DIR *, struct dir
 /* Pre-POSIX API, returns non-NULL on success. */
 #  define _XReaddir(d,p)	(readdir_r((d), &(p).dir_entry))
 # else
-/* We have no idea what is going on.  Fake it all using process locks. */
-#  define _XReaddir(d,p)	\
-    ( (_Xos_processLock),						\
-      (((p).result = readdir((d))) ?					\
-       (memcpy(&((p).dir_entry), (p).result, (p).result->d_reclen),	\
-	((p).result = &(p).dir_entry), 0) :				\
-       0),								\
-      (_Xos_processUnlock),						\
-      (p).result )
+#  define _XReaddir(d,p)						\
+    (readdir_r((d), &((p).dir_entry), &((p).result)) ? NULL : (p).result)
 # endif
 #endif /* X_INCLUDE_DIRENT_H */
 
@@ -691,7 +685,7 @@ extern int _Preaddir_r(DIR *, struct dir
 
 #if defined(X_INCLUDE_UNISTD_H) && !defined(_XOS_INCLUDED_UNISTD_H)
 /* <unistd.h> already included by <X11/Xos.h> */
-# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_UNISTDAPI)
+# if defined(_XOS_R_H__MTSAFE_UNISTDAPI)
 #  define XOS_USE_MTSAFE_UNISTDAPI 1
 # endif
 #endif
@@ -831,7 +825,7 @@ typedef struct {
 
 #if defined(X_INCLUDE_STRING_H) && !defined(_XOS_INCLUDED_STRING_H)
 /* <string.h> has already been included by <X11/Xos.h> */
-# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_STRINGAPI)
+# if defined(_XOS_R_H_MTSAFE_STRINGAPI)
 #  define XOS_USE_MTSAFE_STRINGAPI 1
 # endif
 #endif
@@ -883,7 +877,7 @@ typedef char * _Xstrtokparams;
 
 #if defined(X_INCLUDE_TIME_H) && !defined(_XOS_INCLUDED_TIME_H)
 # include <time.h>
-# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_TIMEAPI)
+# if defined(_XOS_R_H_MTSAFE_TIMEAPI)
 #  define XOS_USE_MTSAFE_TIMEAPI 1
 # endif
 #endif
@@ -1046,7 +1040,7 @@ typedef struct tm _Xltimeparams;
 
 #if defined(X_INCLUDE_GRP_H) && !defined(_XOS_INCLUDED_GRP_H)
 # include <grp.h>
-# if defined(XUSE_MTSAFE_API) || defined(XUSE_MTSAFE_GRPAPI)
+# if defined(_XOS_R_H_MTSAFE_GRPAPI)
 #  define XOS_USE_MTSAFE_GRPAPI 1
 # endif
 #endif
-------------- next part --------------
$NetBSD: patch-ab,v 1.2 2006/12/15 19:11:48 joerg Exp $

--- configure.ac.orig	2006-11-02 08:17:10.000000000 +0000
+++ configure.ac
@@ -4,6 +4,7 @@ AM_INIT_AUTOMAKE([foreign dist-bzip2])
 
 AC_CONFIG_HEADER([do-not-use-config.h])
 AC_CONFIG_HEADER([Xfuncproto.h])
+AC_CONFIG_HEADER([Xos_r.h])
 
 AC_CANONICAL_HOST
 
@@ -170,6 +171,15 @@ if test "x$WIDEPROTO" = xno; then
 	AC_DEFINE(NARROWPROTO, [], [Narrow prototypes])
 fi
 
+# Handle Xos_r.h
+AC_CHECK_FUNC(readdir_r, [AC_DEFINE(_XOS_R_H_MTSAFE_DIRENTAPI,[],[Assume has readdir_r and friends from dirent.h])],)
+AC_CHECK_FUNC(getgrgid_r, [AC_DEFINE(_XOS_R_H_MTSAFE_GRPAPI,[],[Assume has getgrgid_r and friends from grp.h])],)
+AC_CHECK_FUNC(getpwuid_r, [AC_DEFINE(_XOS_R_H_MTSAFE_PWDAPI,[],[Assume has getpwuid_r and friends from pwd.h])],)
+AC_CHECK_FUNC(gethostbyname_r, [AC_DEFINE(_XOS_R_H_MTSAFE_NETDBAPI,[],[Assume has gethostbyname_r and friends from netdb.h])],)
+AC_CHECK_FUNC(strtok_r, [AC_DEFINE(_XOS_R_H_MTSAFE_STRINGAPI,[],[Assume has strtok_r from string.h])],)
+AC_CHECK_FUNC(gmtime_r, [AC_DEFINE(_XOS_R_H_MTSAFE_TIMEAPI,[],[Assume has gmtime_r and friends from time.h])],)
+AC_CHECK_FUNC(ttyname_r, [AC_DEFINE(_XOS_R_H_MTSAFE_UNISTDAPI,[],[Assume has ttyname_r and friends from unistd.h])],)
+
 XORG_RELEASE_VERSION
 
 AC_OUTPUT([Makefile


More information about the xorg mailing list