bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] pipe-posix: new module


From: Bruno Haible
Subject: Re: [PATCH] pipe-posix: new module
Date: Sat, 11 Dec 2010 03:03:38 +0100
User-agent: KMail/1.9.9

Hi Eric,

> since it is just a #define rather than a replacement function, it
> fails the POSIX aspect of being able to pass a function pointer to
> pipe around

And it also fails the signature test in C++ mode: When I add these lines

*** tests/test-unistd-c++.cc.orig       Sat Dec 11 02:47:25 2010
--- tests/test-unistd-c++.cc    Sat Dec 11 02:34:46 2010
***************
*** 129,134 ****
--- 129,138 ----
  SIGNATURE_CHECK (GNULIB_NAMESPACE::lseek, off_t, (int, off_t, int));
  #endif
  
+ #if GNULIB_TEST_PIPE
+ SIGNATURE_CHECK (GNULIB_NAMESPACE::pipe, int, (int[2]));
+ #endif
+ 
  #if GNULIB_TEST_PIPE2
  SIGNATURE_CHECK (GNULIB_NAMESPACE::pipe2, int, (int[2], int));
  #endif

then create a testdir like this:

$ ./gnulib-tool --create-testdir --dir=/home/bruno/data/tmp/testdir4 
--with-tests --with-c++-tests pipe-posix

then on mingw I get a build failure:

test-unistd-c++.cc:133: error: `pipe' is not a member of `gnulib'
test-unistd-c++.cc:133: warning: 'signature_check133' defined but not used
make[4]: *** [test-unistd-c++.o] Error 1

It's the same situation as with waitpid() in September.

This fixes it.


2010-12-10  Bruno Haible  <address@hidden>

        pipe-posix: Make it work in C++ mode.
        * lib/unistd.in.h: Don't include <io.h>, <fcntl.h> for pipe.
        (pipe): Use common idiom, not a macro definition.
        * lib/pipe.c: New file.
        * m4/pipe.m4: New file.
        * modules/pipe-posix (Description): Enhance.
        (Files): Add lib/pipe.c, m4/pipe.m4.
        (configure.ac): Invoke gl_FUNC_PIPE.
        * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize HAVE_PIPE.
        * modules/unistd (Makefile.am): Substitute HAVE_PIPE.
        * tests/test-unistd-c++.cc: Check the signature of pipe.

================================= lib/pipe.c =================================
/* Create a pipe.
   Copyright (C) 2009-2010 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

#include <config.h>

/* Specification.  */
#include <unistd.h>

#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Native Woe32 API.  */

/* Get _pipe().  */
# include <io.h>

/* Get _O_BINARY.  */
# include <fcntl.h>

int
pipe (int fd[2])
{
  return _pipe (fd, 4096, _O_BINARY);
}

#else

# error "This platform lacks a pipe function, and Gnulib doesn't provide a 
replacement. This is a bug in Gnulib."

#endif
================================= m4/pipe.m4 =================================
# pipe.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.

AC_DEFUN([gl_FUNC_PIPE],
[
  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])

  AC_CHECK_FUNCS_ONCE([pipe])
  if test $ac_cv_func_pipe != yes; then
    HAVE_PIPE=0
    AC_LIBOBJ([pipe])
  fi
])
==============================================================================
--- lib/unistd.in.h.orig        Sat Dec 11 02:55:30 2010
+++ lib/unistd.in.h     Sat Dec 11 02:19:32 2010
@@ -82,14 +82,10 @@
 # include <stdlib.h>
 #endif
 
-/* mingw declares getcwd in <io.h>, not in <unistd.h>.  It also provides
-   _pipe in <io.h>, but that requires _O_BINARY from <fcntl.h>.  */
-#if ((@GNULIB_GETCWD@ || @GNULIB_PIPE@ || defined GNULIB_POSIXCHECK) \
+/* mingw declares getcwd in <io.h>, not in <unistd.h>.  */
+#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
 # include <io.h>
-# if @GNULIB_PIPE@
-#  include <fcntl.h>
-# endif
 #endif
 
 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.  */
@@ -980,14 +976,22 @@
 /* Create a pipe, defaulting to O_BINARY mode.
    Store the read-end as fd[0] and the write-end as fd[1].
    Return 0 upon success, or -1 with errno set upon failure.  */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-#  define pipe(fd) _pipe (fd, 4096, _O_BINARY)
+# if @HAVE_PIPE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define pipe rpl_pipe
+#  endif
+_GL_FUNCDECL_RPL (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (pipe, int, (int fd[2]));
+# else
+_GL_FUNCDECL_SYS (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_SYS (pipe, int, (int fd[2]));
 # endif
+_GL_CXXALIASWARN (pipe);
 #elif defined GNULIB_POSIXCHECK
 # undef pipe
 # if HAVE_RAW_DECL_PIPE
 _GL_WARN_ON_USE (pipe, "pipe is unportable - "
-                 "use gnulib module pipe for portability");
+                 "use gnulib module pipe-posix for portability");
 # endif
 #endif
 
--- m4/unistd_h.m4.orig Sat Dec 11 02:55:30 2010
+++ m4/unistd_h.m4      Sat Dec 11 02:20:23 2010
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 48
+# unistd_h.m4 serial 49
 dnl Copyright (C) 2006-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,
@@ -113,6 +113,7 @@
   HAVE_LCHOWN=1;          AC_SUBST([HAVE_LCHOWN])
   HAVE_LINK=1;            AC_SUBST([HAVE_LINK])
   HAVE_LINKAT=1;          AC_SUBST([HAVE_LINKAT])
+  HAVE_PIPE=1;            AC_SUBST([HAVE_PIPE])
   HAVE_PIPE2=1;           AC_SUBST([HAVE_PIPE2])
   HAVE_PREAD=1;           AC_SUBST([HAVE_PREAD])
   HAVE_PWRITE=1;          AC_SUBST([HAVE_PWRITE])
--- modules/pipe-posix.orig     Sat Dec 11 02:55:30 2010
+++ modules/pipe-posix  Sat Dec 11 02:37:33 2010
@@ -1,13 +1,15 @@
 Description:
-Creation of a pipe.
+pipe() function: Creation of a pipe.
 
 Files:
+lib/pipe.c
+m4/pipe.m4
 
 Depends-on:
 unistd
 
 configure.ac:
-AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+gl_FUNC_PIPE
 gl_UNISTD_MODULE_INDICATOR([pipe])
 
 Makefile.am:
--- modules/unistd.orig Sat Dec 11 02:55:30 2010
+++ modules/unistd      Sat Dec 11 02:20:39 2010
@@ -87,6 +87,7 @@
              -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
              -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
              -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \
+             -e 's|@''HAVE_PIPE''@|$(HAVE_PIPE)|g' \
              -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \
              -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \
              -e 's|@''HAVE_PWRITE''@|$(HAVE_PWRITE)|g' \
--- tests/test-unistd-c++.cc.orig       Sat Dec 11 02:55:30 2010
+++ tests/test-unistd-c++.cc    Sat Dec 11 02:22:20 2010
@@ -129,6 +129,10 @@
 SIGNATURE_CHECK (GNULIB_NAMESPACE::lseek, off_t, (int, off_t, int));
 #endif
 
+#if GNULIB_TEST_PIPE
+SIGNATURE_CHECK (GNULIB_NAMESPACE::pipe, int, (int[2]));
+#endif
+
 #if GNULIB_TEST_PIPE2
 SIGNATURE_CHECK (GNULIB_NAMESPACE::pipe2, int, (int[2], int));
 #endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]