New module 'poll-h'.
authorBruno Haible <bruno@clisp.org>
Tue, 28 Sep 2010 23:00:17 +0000 (01:00 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 28 Sep 2010 23:00:17 +0000 (01:00 +0200)
* 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.

ChangeLog
doc/posix-headers/poll.texi
lib/poll.c
lib/poll.in.h
m4/poll.m4
m4/poll_h.m4 [new file with mode: 0644]
modules/poll
modules/poll-h [new file with mode: 0644]
tests/test-poll.c

index f23c1c4..0e18d7a 100644 (file)
--- 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.
index 89b9568..27d129e 100644 (file)
@@ -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
index 7c52cb6..a001c19 100644 (file)
 #include <alloca.h>
 
 #include <sys/types.h>
-#include "poll.h"
+
+/* Specification.  */
+#include <poll.h>
+
 #include <errno.h>
 #include <limits.h>
 #include <assert.h>
index b7aa59d..e7f211b 100644 (file)
 #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 @@ struct pollfd
 
 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 */
index 3a7c186..9cb02d5 100644 (file)
@@ -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 @@ dnl with or without modifications, as long as this notice is preserved.
 
 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 @@ This is MacOSX or AIX
 #endif
 ], [gl_cv_func_poll=no], [gl_cv_func_poll=yes])])])
   fi
-  if test $gl_cv_func_poll = yes; then
-    AC_DEFINE([HAVE_POLL], [1],
-      [Define to 1 if you have the 'poll' function and it works.])
-    POLL_H=
-  else
+  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])
-    AC_DEFINE([poll], [rpl_poll],
-      [Define to poll if the replacement function should be used.])
     gl_PREREQ_POLL
-    POLL_H=poll.h
+  else
+    AC_DEFINE([HAVE_POLL], [1],
+      [Define to 1 if you have the 'poll' function and it works.])
   fi
-  AC_SUBST([POLL_H])
 ])
 
 # Prerequisites of lib/poll.c.
diff --git a/m4/poll_h.m4 b/m4/poll_h.m4
new file mode 100644 (file)
index 0000000..6f04168
--- /dev/null
@@ -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])
+])
index 64c1de5..8690271 100644 (file)
@@ -3,10 +3,10 @@ poll() function: wait for some event on a set of file descriptors.
 
 Files:
 lib/poll.c
-lib/poll.in.h
 m4/poll.m4
 
 Depends-on:
+poll-h
 alloca
 select
 sys_select
@@ -15,19 +15,9 @@ errno
 
 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>
diff --git a/modules/poll-h b/modules/poll-h
new file mode 100644 (file)
index 0000000..e71649f
--- /dev/null
@@ -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
index 7488090..9abe28c 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <poll.h>
 
 #include "signature.h"