From: Bruno Haible Date: Tue, 28 Sep 2010 23:00:17 +0000 (+0200) Subject: New module 'poll-h'. X-Git-Tag: v0.1~3751 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=11f1d3a976a737eb6ca30cf89e8b47c85bfe3d47;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index f23c1c4fc..0e18d7ab8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2010-09-28 Bruno Haible + + 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 sys_wait: Implement WSTOPSIG. diff --git a/doc/posix-headers/poll.texi b/doc/posix-headers/poll.texi index 89b95687a..27d129e5c 100644 --- 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 diff --git a/lib/poll.c b/lib/poll.c index 7c52cb6a2..a001c199a 100644 --- a/lib/poll.c +++ b/lib/poll.c @@ -28,7 +28,10 @@ #include #include -#include "poll.h" + +/* Specification. */ +#include + #include #include #include diff --git a/lib/poll.in.h b/lib/poll.in.h index b7aa59d97..e7f211bfc 100644 --- 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 @@ 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 */ diff --git a/m4/poll.m4 b/m4/poll.m4 index 3a7c186dc..9cb02d539 100644 --- 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 @@ 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 index 000000000..6f041689a --- /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]) +]) + +dnl Unconditionally enables the replacement of . +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]) +]) diff --git a/modules/poll b/modules/poll index 64c1de5c5..8690271e0 100644 --- a/modules/poll +++ b/modules/poll @@ -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 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: diff --git a/modules/poll-h b/modules/poll-h new file mode 100644 index 000000000..e71649f60 --- /dev/null +++ b/modules/poll-h @@ -0,0 +1,40 @@ +Description: +A POSIX-like . + +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 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: + + +License: +LGPLv2+ + +Maintainer: +Paolo Bonzini, Bruno Haible diff --git a/tests/test-poll.c b/tests/test-poll.c index 748809007..9abe28c96 100644 --- a/tests/test-poll.c +++ b/tests/test-poll.c @@ -19,6 +19,7 @@ #include +/* Specification. */ #include #include "signature.h"