[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
poll-h: new module
From: |
Bruno Haible |
Subject: |
poll-h: new module |
Date: |
Wed, 29 Sep 2010 01:04:19 +0200 |
User-agent: |
KMail/1.9.9 |
Eric Blake wrote:
> modern style favors splitting
> replacement headers into separate modules from like-named functions
> (that is, we need a new module poll-h if you want a working poll.h
> [pollfd, nfds_t, and the various POLL macros] that can be used for
> GNULIB_POSIXCHECK conformance and when you don't tickle the portability
> limitations of native poll(); and poll [which depends on poll-h] if you
> also need the gnulib fixes for the function).
Good point. We did not do the distinction in the past between 'poll'
and 'poll-h' because it was deemed unnecessary. But for using GNULIB_POSIXCHECK
it is necessary, as you say.
This patch splits the module.
2010-09-28 Bruno Haible <address@hidden>
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.
=============================== modules/poll-h ===============================
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 address@hidden $@ && \
{ 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; \
} > address@hidden && \
mv -f address@hidden $@
MOSTLYCLEANFILES += poll.h poll.h-t
Include:
<poll.h>
License:
LGPLv2+
Maintainer:
Paolo Bonzini, Bruno Haible
================================ m4/poll_h.m4 ================================
# 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])
])
==============================================================================
--- doc/posix-headers/poll.texi.orig Wed Sep 29 00:59:46 2010
+++ doc/posix-headers/poll.texi Tue Sep 28 23:30:01 2010
@@ -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
--- lib/poll.c.orig Wed Sep 29 00:59:46 2010
+++ lib/poll.c Tue Sep 28 23:18:20 2010
@@ -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>
--- lib/poll.in.h.orig Wed Sep 29 00:59:46 2010
+++ lib/poll.in.h Wed Sep 29 00:49:26 2010
@@ -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 address@hidden@
+_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 */
--- m4/poll.m4.orig Wed Sep 29 00:59:46 2010
+++ m4/poll.m4 Wed Sep 29 00:11:10 2010
@@ -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
- 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.
--- modules/poll.orig Wed Sep 29 00:59:46 2010
+++ modules/poll Tue Sep 28 23:51:15 2010
@@ -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 address@hidden $@ && \
- { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
- cat $(srcdir)/poll.in.h; \
- } > address@hidden && \
- mv -f address@hidden $@
-MOSTLYCLEANFILES += poll.h poll.h-t
Include:
<poll.h>
--- tests/test-poll.c.orig Wed Sep 29 00:59:46 2010
+++ tests/test-poll.c Tue Sep 28 23:40:34 2010
@@ -19,6 +19,7 @@
#include <config.h>
+/* Specification. */
#include <poll.h>
#include "signature.h"