changeset 13736:10928671f716

New module 'poll-h'. * lib/poll.in.h: Include c++defs.h and warn-on-use.h. (poll): Use modern idiom. * modules/poll-h: New file. * modules/poll (Files): Remove lib/poll.in.h. (Depends-on): Add poll-h. (configure.ac): Invoke gl_POLL_MODULE_INDICATOR. (Makefile.am): Move code for generation of poll.h to modules/poll-h. * m4/poll_h.m4: New file. * m4/poll.m4 (gl_FUNC_POLL): Require gl_POLL_H. Don't check for poll.h here. Don't set POLL_H here. Instead, set HAVE_POLL and REPLACE_POLL and invoke gl_REPLACE_POLL_H. * lib/poll.c: Use common idiom. * tests/test-poll.c: Likewise. * doc/posix-headers/poll.texi: Mention the poll-h module. Suggested by Eric Blake.
author Bruno Haible <bruno@clisp.org>
date Wed, 29 Sep 2010 01:00:17 +0200
parents d60025f91a0e
children 431ca47d77a1
files ChangeLog doc/posix-headers/poll.texi lib/poll.c lib/poll.in.h m4/poll.m4 m4/poll_h.m4 modules/poll modules/poll-h tests/test-poll.c
diffstat 9 files changed, 161 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2010-09-28  Bruno Haible  <bruno@clisp.org>
+
+	New module 'poll-h'.
+	* lib/poll.in.h: Include c++defs.h and warn-on-use.h.
+	(poll): Use modern idiom.
+	* modules/poll-h: New file.
+	* modules/poll (Files): Remove lib/poll.in.h.
+	(Depends-on): Add poll-h.
+	(configure.ac): Invoke gl_POLL_MODULE_INDICATOR.
+	(Makefile.am): Move code for generation of poll.h to modules/poll-h.
+	* m4/poll_h.m4: New file.
+	* m4/poll.m4 (gl_FUNC_POLL): Require gl_POLL_H. Don't check for poll.h
+	here. Don't set POLL_H here. Instead, set HAVE_POLL and REPLACE_POLL
+	and invoke gl_REPLACE_POLL_H.
+	* lib/poll.c: Use common idiom.
+	* tests/test-poll.c: Likewise.
+	* doc/posix-headers/poll.texi: Mention the poll-h module.
+	Suggested by Eric Blake.
+
 2010-09-26  Bruno Haible  <bruno@clisp.org>
 
 	sys_wait: Implement WSTOPSIG.
--- a/doc/posix-headers/poll.texi
+++ b/doc/posix-headers/poll.texi
@@ -3,7 +3,7 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/susv3xbd/poll.h.html}
 
-Gnulib module: poll
+Gnulib module: poll-h
 
 Portability problems fixed by Gnulib:
 @itemize
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -28,7 +28,10 @@
 #include <alloca.h>
 
 #include <sys/types.h>
-#include "poll.h"
+
+/* Specification.  */
+#include <poll.h>
+
 #include <errno.h>
 #include <limits.h>
 #include <assert.h>
--- a/lib/poll.in.h
+++ b/lib/poll.in.h
@@ -22,6 +22,12 @@
 #ifndef _GL_POLL_H
 #define _GL_POLL_H
 
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
 /* fake a poll(2) environment */
 #define POLLIN      0x0001      /* any readable data available   */
 #define POLLPRI     0x0002      /* OOB/Urgent readable data      */
@@ -43,11 +49,33 @@
 
 typedef unsigned long nfds_t;
 
-extern int poll (struct pollfd *pfd, nfds_t nfd, int timeout);
+#if @GNULIB_POLL@
+# if @REPLACE_POLL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef poll
+#   define poll rpl_poll
+#  endif
+_GL_FUNCDECL_RPL (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeout));
+_GL_CXXALIAS_RPL (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeout));
+# else
+#  if !@HAVE_POLL@
+_GL_FUNCDECL_SYS (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeout));
+#  endif
+_GL_CXXALIAS_SYS (poll, int, (struct pollfd *pfd, nfds_t nfd, int timeout));
+# endif
+_GL_CXXALIASWARN (poll);
+#elif defined GNULIB_POSIXCHECK
+# undef poll
+# if HAVE_RAW_DECL_POLL
+_GL_WARN_ON_USE (poll, "poll is unportable - "
+                 "use gnulib module poll for portability");
+# endif
+#endif
 
 /* Define INFTIM only if doing so conforms to POSIX.  */
 #if !defined (_POSIX_C_SOURCE) && !defined (_XOPEN_SOURCE)
 #define INFTIM (-1)
 #endif
 
+
 #endif /* _GL_POLL_H */
--- a/m4/poll.m4
+++ b/m4/poll.m4
@@ -1,4 +1,4 @@
-# poll.m4 serial 9
+# poll.m4 serial 10
 dnl Copyright (c) 2003, 2005, 2006, 2007, 2009, 2010 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -7,8 +7,9 @@
 
 AC_DEFUN([gl_FUNC_POLL],
 [
-  AC_CHECK_HEADERS([poll.h])
+  AC_REQUIRE([gl_POLL_H])
   if test "$ac_cv_header_poll_h" = no; then
+    ac_cv_func_poll=no
     gl_cv_func_poll=no
   else
     AC_CHECK_FUNC([poll],
@@ -51,18 +52,22 @@
 #endif
 ], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
   fi
-  if test $gl_cv_func_poll = yes; then
+  if test $gl_cv_func_poll != yes; then
+    AC_CHECK_FUNC([poll], [ac_cv_func_poll=yes], [ac_cv_func_poll=no])
+    if test $ac_cv_func_poll = no; then
+      HAVE_POLL=0
+    else
+      REPLACE_POLL=1
+    fi
+  fi
+  if test $HAVE_POLL = 0 || $REPLACE_POLL = 1; then
+    gl_REPLACE_POLL_H
+    AC_LIBOBJ([poll])
+    gl_PREREQ_POLL
+  else
     AC_DEFINE([HAVE_POLL], [1],
       [Define to 1 if you have the 'poll' function and it works.])
-    POLL_H=
-  else
-    AC_LIBOBJ([poll])
-    AC_DEFINE([poll], [rpl_poll],
-      [Define to poll if the replacement function should be used.])
-    gl_PREREQ_POLL
-    POLL_H=poll.h
   fi
-  AC_SUBST([POLL_H])
 ])
 
 # Prerequisites of lib/poll.c.
new file mode 100644
--- /dev/null
+++ b/m4/poll_h.m4
@@ -0,0 +1,49 @@
+# poll_h.m4 serial 1
+dnl Copyright (C) 2010 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Bruno Haible.
+
+AC_DEFUN([gl_POLL_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_POLL_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([poll.h])
+  if test $ac_cv_header_poll_h != yes; then
+    gl_REPLACE_POLL_H
+  fi
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[#include <poll.h>]],
+    [poll])
+])
+
+dnl Unconditionally enables the replacement of <poll.h>.
+AC_DEFUN([gl_REPLACE_POLL_H],
+[
+  AC_REQUIRE([gl_POLL_H_DEFAULTS])
+  POLL_H='poll.h'
+])
+
+AC_DEFUN([gl_POLL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_POLL_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_POLL_H_DEFAULTS],
+[
+  GNULIB_POLL=0;        AC_SUBST([GNULIB_POLL])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  POLL_H='';            AC_SUBST([POLL_H])
+  HAVE_POLL=1;          AC_SUBST([HAVE_POLL])
+  REPLACE_POLL=0;       AC_SUBST([REPLACE_POLL])
+])
--- a/modules/poll
+++ b/modules/poll
@@ -3,10 +3,10 @@
 
 Files:
 lib/poll.c
-lib/poll.in.h
 m4/poll.m4
 
 Depends-on:
+poll-h
 alloca
 select
 sys_select
@@ -15,19 +15,9 @@
 
 configure.ac:
 gl_FUNC_POLL
+gl_POLL_MODULE_INDICATOR([poll])
 
 Makefile.am:
-BUILT_SOURCES += $(POLL_H)
-
-# We need the following in order to create <poll.h> when the system
-# doesn't have one.
-poll.h: poll.in.h
-	$(AM_V_GEN)rm -f $@-t $@ && \
-	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-	  cat $(srcdir)/poll.in.h; \
-	} > $@-t && \
-	mv -f $@-t $@
-MOSTLYCLEANFILES += poll.h poll.h-t
 
 Include:
 <poll.h>
new file mode 100644
--- /dev/null
+++ b/modules/poll-h
@@ -0,0 +1,40 @@
+Description:
+A POSIX-like <poll.h>.
+
+Files:
+lib/poll.in.h
+m4/poll_h.m4
+
+Depends-on:
+c++defs
+warn-on-use
+
+configure.ac:
+gl_POLL_H
+
+Makefile.am:
+BUILT_SOURCES += $(POLL_H)
+
+# We need the following in order to create <poll.h> when the system
+# doesn't have one.
+poll.h: poll.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''GNULIB_POLL''@|$(GNULIB_POLL)|g' \
+	      -e 's|@''HAVE_POLL''@|$(HAVE_POLL)|g' \
+	      -e 's|@''REPLACE_POLL''@|$(REPLACE_POLL)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/poll.in.h; \
+	} > $@-t && \
+	mv -f $@-t $@
+MOSTLYCLEANFILES += poll.h poll.h-t
+
+Include:
+<poll.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Paolo Bonzini, Bruno Haible
--- a/tests/test-poll.c
+++ b/tests/test-poll.c
@@ -19,6 +19,7 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <poll.h>
 
 #include "signature.h"