bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 3/3] forkpty, openpty: prefer glibc's const-safe prototype


From: Eric Blake
Subject: [PATCH 3/3] forkpty, openpty: prefer glibc's const-safe prototype
Date: Thu, 18 Mar 2010 17:15:05 -0600

This silences a compiler warning for test-forkpty.c.

* lib/forkpty.c (rpl_forkpty): New file.
* lib/openpty.c (rpl_openpty): Likewise.
* modules/forkpty (Files): Distribute it.
* modules/openpty (Files): Likewise.
* m4/pty_h.m4 (gl_PTY_H_DEFAULTS): Add new witnesses.  Move decl
check...
* m4/forkpty.m4 (gl_FORKPTY, gl_OPENPTY): ...here.  Request
replacement for for non-const BSD signature.
* modules/pty (Makefile.am): Substitute witnesses.
* lib/pty.in.h (forkpty, openpty): Declare replacements.
* tests/test-forkpty.c: Update signature check.
* doc/glibc-functions/forkpty.texi (forkpty): Document the fix.
* doc/glibc-functions/openpty.texi (openpty): Likewise.

Signed-off-by: Eric Blake <address@hidden>
---

I'm _finally_ getting around to this one, which Bruno first
reported in December.

 ChangeLog                        |   15 +++++++
 doc/glibc-functions/forkpty.texi |    4 ++
 doc/glibc-functions/openpty.texi |    4 ++
 lib/forkpty.c                    |   35 +++++++++++++++++
 lib/openpty.c                    |   35 +++++++++++++++++
 lib/pty.in.h                     |   38 +++++++++++++++++++
 m4/forkpty.m4                    |   76 +++++++++++++++++++++++++++++++++++++-
 m4/pty_h.m4                      |   16 +------
 modules/forkpty                  |    1 +
 modules/openpty                  |    1 +
 modules/pty                      |    2 +
 tests/test-forkpty.c             |    8 ++--
 12 files changed, 217 insertions(+), 18 deletions(-)
 create mode 100644 lib/forkpty.c
 create mode 100644 lib/openpty.c

diff --git a/ChangeLog b/ChangeLog
index 5bdb71f..69c335c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2010-03-18  Eric Blake  <address@hidden>

+       forkpty, openpty: prefer glibc's const-safe prototype
+       * lib/forkpty.c (rpl_forkpty): New file.
+       * lib/openpty.c (rpl_openpty): Likewise.
+       * modules/forkpty (Files): Distribute it.
+       * modules/openpty (Files): Likewise.
+       * m4/pty_h.m4 (gl_PTY_H_DEFAULTS): Add new witnesses.  Move decl
+       check...
+       * m4/forkpty.m4 (gl_FORKPTY, gl_OPENPTY): ...here.  Request
+       replacement for for non-const BSD signature.
+       * modules/pty (Makefile.am): Substitute witnesses.
+       * lib/pty.in.h (forkpty, openpty): Declare replacements.
+       * tests/test-forkpty.c: Update signature check.
+       * doc/glibc-functions/forkpty.texi (forkpty): Document the fix.
+       * doc/glibc-functions/openpty.texi (openpty): Likewise.
+
        forkpty, openpty: split functions into new modules
        * modules/pty (Makefile.am): Substitute new witnesses.
        (Libraries): Move library detection...
diff --git a/doc/glibc-functions/forkpty.texi b/doc/glibc-functions/forkpty.texi
index 8a86511..aecc232 100644
--- a/doc/glibc-functions/forkpty.texi
+++ b/doc/glibc-functions/forkpty.texi
@@ -16,6 +16,10 @@ forkpty
 The function is declared in pty.h on Cygwin, Interix, OSF/1 4 and 5,
 and glibc.  It is declared in util.h on Mac OS X, OpenBSD and NetBSD.
 It is declared in libutil.h on FreeBSD.
address@hidden
+Some platforms declare the function without marking the last two
+parameters @code{const}.
+FreeBSD, Cygwin 1.7.1.
 @end itemize

 Portability problems not fixed by Gnulib:
diff --git a/doc/glibc-functions/openpty.texi b/doc/glibc-functions/openpty.texi
index 7eb528e..5eb57c3 100644
--- a/doc/glibc-functions/openpty.texi
+++ b/doc/glibc-functions/openpty.texi
@@ -16,6 +16,10 @@ openpty
 The function is declared in pty.h on Cygwin, Interix, OSF/1 4 and 5,
 and glibc.  It is declared in util.h on Mac OS X, OpenBSD and NetBSD.
 It is declared in libutil.h on FreeBSD.
address@hidden
+Some platforms declare the function without marking the last two
+parameters @code{const}.
+FreeBSD, Cygwin 1.7.1.
 @end itemize

 Portability problems not fixed by Gnulib:
diff --git a/lib/forkpty.c b/lib/forkpty.c
new file mode 100644
index 0000000..adbc3d5
--- /dev/null
+++ b/lib/forkpty.c
@@ -0,0 +1,35 @@
+/* Fork a child attached to a pseudo-terminal descriptor.
+   Copyright (C) 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <pty.h>
+
+#if HAVE_DECL_FORKPTY
+# undef forkpty
+int
+rpl_forkpty (int *amaster, char *name, struct termios const *termp,
+         struct winsize const *winp)
+{
+  /* Cast away const, for implementations with weaker prototypes.  */
+  return forkpty (amaster, name, (struct termios *) termp,
+                  (struct winsize *) winp);
+}
+#else
+# error forkpty has not been ported to your system; \
+  report this to address@hidden for help
+#endif
diff --git a/lib/openpty.c b/lib/openpty.c
new file mode 100644
index 0000000..e7eb46d
--- /dev/null
+++ b/lib/openpty.c
@@ -0,0 +1,35 @@
+/* Open a pseudo-terminal descriptor.
+   Copyright (C) 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <pty.h>
+
+#if HAVE_DECL_OPENPTY
+# undef openpty
+int
+rpl_openpty (int *amaster, int *aslave, char *name, struct termios const 
*termp,
+         struct winsize const *winp)
+{
+  /* Cast away const, for implementations with weaker prototypes.  */
+  return openpty (amaster, aslave, name, (struct termios *) termp,
+                  (struct winsize *) winp);
+}
+#else
+# error openpty has not been ported to your system; \
+  report this to address@hidden for help
+#endif
diff --git a/lib/pty.in.h b/lib/pty.in.h
index 7e90fcc..c61931c 100644
--- a/lib/pty.in.h
+++ b/lib/pty.in.h
@@ -45,6 +45,25 @@
 /* Declare overridden functions.  */

 #if @GNULIB_FORKPTY@
+# if @REPLACE_FORKPTY@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef forkpty
+#   define forkpty rpl_forkpty
+#  endif
+_GL_FUNCDECL_RPL (forkpty, int,
+                  (int *, char *, struct termios const *,
+                   struct winsize const *));
+_GL_CXXALIAS_RPL (forkpty, int,
+                  (int *, char *, struct termios const *,
+                   struct winsize const *));
+# else
+/* Need to cast, because on older glibc systems, the last two parameters
+   lacked const.  */
+_GL_CXXALIAS_SYS_CAST (forkpty, int,
+                       (int *, char *, struct termios const *,
+                        struct winsize const *));
+# endif
+_GL_CXXALIASWARN (forkpty);
 #elif defined GNULIB_POSIXCHECK
 # undef forkpty
 # if HAVE_RAW_DECL_FORKPTY
@@ -54,6 +73,25 @@ _GL_WARN_ON_USE (forkpty, "forkpty is not declared 
consistently - "
 #endif

 #if @GNULIB_OPENPTY@
+# if @REPLACE_OPENPTY@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef openpty
+#   define openpty rpl_openpty
+#  endif
+_GL_FUNCDECL_RPL (openpty, int,
+                  (int *, int *, char *, struct termios const *,
+                   struct winsize const *));
+_GL_CXXALIAS_RPL (openpty, int,
+                  (int *, int *, char *, struct termios const *,
+                   struct winsize const *));
+# else
+/* Need to cast, because on older glibc systems, the last two parameters
+   lacked const.  */
+_GL_CXXALIAS_SYS_CAST (openpty, int,
+                       (int *, int *, char *, struct termios const *,
+                        struct winsize const *));
+# endif
+_GL_CXXALIASWARN (openpty);
 #elif defined GNULIB_POSIXCHECK
 # undef openpty
 # if HAVE_RAW_DECL_OPENPTY
diff --git a/m4/forkpty.m4 b/m4/forkpty.m4
index 38b51b7..f1da918 100644
--- a/m4/forkpty.m4
+++ b/m4/forkpty.m4
@@ -1,4 +1,4 @@
-# forkpty.m4 serial 1
+# forkpty.m4 serial 2
 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,
@@ -23,9 +23,83 @@ AC_DEFUN([gl_PTY_LIB],
 AC_DEFUN([gl_FORKPTY],
 [
   AC_REQUIRE([gl_PTY_LIB])
+  AC_REQUIRE([gl_PTY])
+
+  AC_CHECK_DECLS([forkpty],,, [[
+#if HAVE_UTIL_H
+# include <util.h>
+#endif
+#if HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+]])
+  if test $ac_cv_have_decl_forkpty = no; then
+    AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
+  fi
+
+  dnl Prefer glibc's const-safe prototype, if available.
+  AC_CACHE_CHECK([for const-safe forkpty signature],
+    [gl_cv_func_forkpty_const],
+    [AC_COMPILE_IFELSE(
+      [AC_LANG_PROGRAM([[
+#if HAVE_PTY_H
+# include <pty.h>
+#endif
+#if HAVE_UTIL_H
+# include <util.h>
+#endif
+#if HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+      ]], [[
+        int forkpty (int *, char *, struct termios const *,
+                     struct winsize const *);
+      ]])],
+      [gl_cv_func_forkpty_const=yes], [gl_cv_func_forkpty_const=no])])
+  if test $gl_cv_func_forkpty_const != yes; then
+    REPLACE_FORKPTY=1
+    AC_LIBOBJ([forkpty])
+  fi
 ])

 AC_DEFUN([gl_OPENPTY],
 [
   AC_REQUIRE([gl_PTY_LIB])
+  AC_REQUIRE([gl_PTY])
+
+  AC_CHECK_DECLS([openpty],,, [[
+#if HAVE_UTIL_H
+# include <util.h>
+#endif
+#if HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+]])
+  if test $ac_cv_have_decl_openpty = no; then
+    AC_MSG_WARN([[Cannot find openpty, build will likely fail]])
+  fi
+
+  dnl Prefer glibc's const-safe prototype, if available.
+  AC_CACHE_CHECK([for const-safe openpty signature],
+    [gl_cv_func_openpty_const],
+    [AC_COMPILE_IFELSE(
+      [AC_LANG_PROGRAM([[
+#if HAVE_PTY_H
+# include <pty.h>
+#endif
+#if HAVE_UTIL_H
+# include <util.h>
+#endif
+#if HAVE_LIBUTIL_H
+# include <libutil.h>
+#endif
+      ]], [[
+        int openpty (int *, int *, char *, struct termios const *,
+                     struct winsize const *);
+      ]])],
+      [gl_cv_func_openpty_const=yes], [gl_cv_func_openpty_const=no])])
+  if test $gl_cv_func_openpty_const != yes; then
+    REPLACE_OPENPTY=1
+    AC_LIBOBJ([openpty])
+  fi
 ])
diff --git a/m4/pty_h.m4 b/m4/pty_h.m4
index 9e41dcd..529ba56 100644
--- a/m4/pty_h.m4
+++ b/m4/pty_h.m4
@@ -1,4 +1,4 @@
-# pty_h.m4 serial 3
+# pty_h.m4 serial 4
 dnl Copyright (C) 2009, 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,
@@ -22,18 +22,6 @@ AC_DEFUN_ONCE([gl_PTY],
     if test $ac_cv_header_libutil_h = yes; then
       HAVE_LIBUTIL_H=1
     fi
-    dnl FIXME - move this into forkpty module, when replacement is provided
-    AC_CHECK_DECLS([forkpty],,, [[
-#if HAVE_UTIL_H
-# include <util.h>
-#endif
-#if HAVE_LIBUTIL_H
-# include <libutil.h>
-#endif
-]])
-    if test $ac_cv_have_decl_forkpty = no; then
-      AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
-    fi
   else # Have <pty.h>, assume forkpty is declared there.
     HAVE_PTY_H=1
   fi
@@ -72,4 +60,6 @@ AC_DEFUN([gl_PTY_H_DEFAULTS],
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_UTIL_H=0;        AC_SUBST([HAVE_UTIL_H])
   HAVE_LIBUTIL_H=0;     AC_SUBST([HAVE_LIBUTIL_H])
+  REPLACE_FORKPTY=0;    AC_SUBST([REPLACE_FORKPTY])
+  REPLACE_OPENPTY=0;    AC_SUBST([REPLACE_OPENPTY])
 ])
diff --git a/modules/forkpty b/modules/forkpty
index 52dbc49..0c0a531 100644
--- a/modules/forkpty
+++ b/modules/forkpty
@@ -2,6 +2,7 @@ Description:
 Provide the forkpty() function.

 Files:
+lib/forkpty.c
 m4/forkpty.m4

 Depends-on:
diff --git a/modules/openpty b/modules/openpty
index 2a019a5..6e0cda5 100644
--- a/modules/openpty
+++ b/modules/openpty
@@ -2,6 +2,7 @@ Description:
 Provide the openpty() function.

 Files:
+lib/openpty.c
 m4/forkpty.m4

 Depends-on:
diff --git a/modules/pty b/modules/pty
index 8ea7ed3..9020a1a 100644
--- a/modules/pty
+++ b/modules/pty
@@ -29,6 +29,8 @@ pty.h: pty.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
              -e 's|@''GNULIB_OPENPTY''@|$(GNULIB_OPENPTY)|g' \
              -e 's|@''HAVE_UTIL_H''@|$(HAVE_UTIL_H)|g' \
              -e 's|@''HAVE_LIBUTIL_H''@|$(HAVE_LIBUTIL_H)|g' \
+             -e 's|@''REPLACE_FORKPTY''@|$(REPLACE_FORKPTY)|g' \
+             -e 's|@''REPLACE_OPENPTY''@|$(REPLACE_OPENPTY)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
              < $(srcdir)/pty.in.h; \
diff --git a/tests/test-forkpty.c b/tests/test-forkpty.c
index 72e126b..dbd82bb 100644
--- a/tests/test-forkpty.c
+++ b/tests/test-forkpty.c
@@ -21,10 +21,10 @@
 #include <pty.h>

 #include "signature.h"
-SIGNATURE_CHECK (forkpty, int, (int *, char *, struct termios *,
-                                struct winsize *));
-SIGNATURE_CHECK (openpty, int, (int *, int *, char *, struct termios *,
-                                struct winsize *));
+SIGNATURE_CHECK (forkpty, int, (int *, char *, struct termios const *,
+                                struct winsize const *));
+SIGNATURE_CHECK (openpty, int, (int *, int *, char *, struct termios const *,
+                                struct winsize const *));

 #include <stdio.h>

-- 
1.6.6.1





reply via email to

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