bug-gnulib
[Top][All Lists]
Advanced

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

tmpfile on mingw


From: Bruno Haible
Subject: tmpfile on mingw
Date: Sun, 4 Apr 2010 14:37:24 +0100
User-agent: KMail/1.9.9

On mingw, one of the unit tests suggested by John Eaton fails:

  g++-3 -mno-cygwin -DHAVE_CONFIG_H -I.  -I. -I. -I.. -I./.. -I../gllib 
-I./../gllib -I/usr/local/mingw/include -Wall   -MT test-stdio-c++2.o -MD -MP 
-MF .deps/test-stdio-c++2.Tpo -c -o test-stdio-c++2.o test-stdio-c++2.cc
  In file included from test-stdio-c++2.cc:20:
  /usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/cstdio:137: error: `::tmpfile' 
has not been declared
  make[4]: *** [test-stdio-c++2.o] Error 1

This error does not occur if "#include <cstdio>" is used without gnulib.

The reason is that <cstdio> does a

  using ::tmpfile;

but gnulib has renamed that function to rpl_tmpfile, already before the system
headers were included. This fixes it:


2010-04-04  Bruno Haible  <address@hidden>

        tmpfile: Fix C++ test error on mingw.
        * lib/stdio.in.h (tmpfile): New declaration.
        * m4/tmpfile.m4 (gl_TMPFILE): Require gl_STDIO_H_DEFAULTS. Set
        REPLACE_TMPFILE instead of defining tmpfile as a macro in config.h.
        * modules/tmpfile (Depends-on): Add stdio.
        (configure.ac): Invoke gl_STDIO_MODULE_INDICATOR.
        * m4/stdio_h.m4 (gl_STDIO_H): Also check whether tmpfile is declared.
        (gl_STDIO_H_DEFAULTS): Initialize GNULIB_TMPFILE and REPLACE_TMPFILE.
        * modules/stdio (Makefile.am): Substitute GNULIB_TMPFILE and
        REPLACE_TMPFILE.
        * tests/test-stdio-c++.cc (tmpfile): Verify signature.

--- lib/stdio.in.h.orig Sun Apr  4 15:31:07 2010
+++ lib/stdio.in.h      Sun Apr  4 15:20:14 2010
@@ -838,6 +838,25 @@
                  "POSIX compliance");
 #endif
 
+#if @GNULIB_TMPFILE@
+# if @REPLACE_TMPFILE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define tmpfile rpl_tmpfile
+#  endif
+_GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
+_GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
+# else
+_GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
+# endif
+_GL_CXXALIASWARN (tmpfile);
+#elif defined GNULIB_POSIXCHECK
+# undef tmpfile
+# if HAVE_RAW_DECL_TMPFILE
+_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - "
+                 "use gnulib module tmpfile for portability");
+# endif
+#endif
+
 #if @GNULIB_VASPRINTF@
 /* Write formatted output to a string dynamically allocated with malloc().
    If the memory allocation succeeds, store the address of the string in
--- m4/stdio_h.m4.orig  Sun Apr  4 15:31:07 2010
+++ m4/stdio_h.m4       Sun Apr  4 15:22:49 2010
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 29
+# stdio_h.m4 serial 30
 dnl Copyright (C) 2007-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,
@@ -37,7 +37,7 @@
   dnl guaranteed by C89.
   gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
     ]], [dprintf fpurge fseeko ftello getdelim getline popen renameat
-    snprintf vdprintf vsnprintf])
+    snprintf tmpfile vdprintf vsnprintf])
 ])
 
 AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
@@ -83,6 +83,7 @@
   GNULIB_SNPRINTF=0;             AC_SUBST([GNULIB_SNPRINTF])
   GNULIB_SPRINTF_POSIX=0;        AC_SUBST([GNULIB_SPRINTF_POSIX])
   GNULIB_STDIO_H_SIGPIPE=0;      AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
+  GNULIB_TMPFILE=0;              AC_SUBST([GNULIB_TMPFILE])
   GNULIB_VASPRINTF=0;            AC_SUBST([GNULIB_VASPRINTF])
   GNULIB_VDPRINTF=0;             AC_SUBST([GNULIB_VDPRINTF])
   GNULIB_VFPRINTF=0;             AC_SUBST([GNULIB_VFPRINTF])
@@ -127,6 +128,7 @@
   REPLACE_SNPRINTF=0;            AC_SUBST([REPLACE_SNPRINTF])
   REPLACE_SPRINTF=0;             AC_SUBST([REPLACE_SPRINTF])
   REPLACE_STDIO_WRITE_FUNCS=0;   AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
+  REPLACE_TMPFILE=0;             AC_SUBST([REPLACE_TMPFILE])
   REPLACE_VASPRINTF=0;           AC_SUBST([REPLACE_VASPRINTF])
   REPLACE_VDPRINTF=0;            AC_SUBST([REPLACE_VDPRINTF])
   REPLACE_VFPRINTF=0;            AC_SUBST([REPLACE_VFPRINTF])
--- m4/tmpfile.m4.orig  Sun Apr  4 15:31:07 2010
+++ m4/tmpfile.m4       Sun Apr  4 15:31:04 2010
@@ -1,5 +1,4 @@
-# Check whether to use a replacement tmpfile() function.
-
+# tmpfile.m4 serial 1
 # Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -7,6 +6,8 @@
 
 # Written by Ben Pfaff.
 
+# Check whether to use a replacement tmpfile() function.
+
 # The native Windows tmpfile function always tries to put the temporary
 # file in the root directory.  (This behaviour is even documented in
 # Microsoft's documentation!)  This often fails for ordinary users who
@@ -18,6 +19,7 @@
 # just test for a Windows platform (excluding Cygwin).
 
 AC_DEFUN([gl_TMPFILE], [
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_CACHE_CHECK([whether tmpfile should be overridden],
     [gl_cv_func_tmpfile_unusable],
     [AC_EGREP_CPP([choke me], [
@@ -28,9 +30,8 @@
        [gl_cv_func_tmpfile_unusable=yes],
        [gl_cv_func_tmpfile_unusable=no])])
   if test $gl_cv_func_tmpfile_unusable = yes; then
+    REPLACE_TMPFILE=1
     AC_LIBOBJ([tmpfile])
-    AC_DEFINE([tmpfile], [rpl_tmpfile],
-      [Define to rpl_tmpfile if the replacement function should be used.])
     gl_PREREQ_TMPFILE
   fi
 ])
--- modules/stdio.orig  Sun Apr  4 15:31:07 2010
+++ modules/stdio       Sun Apr  4 15:22:00 2010
@@ -60,6 +60,7 @@
              -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
              -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \
              -e 's|@''GNULIB_STDIO_H_SIGPIPE''@|$(GNULIB_STDIO_H_SIGPIPE)|g' \
+             -e 's|@''GNULIB_TMPFILE''@|$(GNULIB_TMPFILE)|g' \
              -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
              -e 's|@''GNULIB_VDPRINTF''@|$(GNULIB_VDPRINTF)|g' \
              -e 's|@''GNULIB_VFPRINTF''@|$(GNULIB_VFPRINTF)|g' \
@@ -104,6 +105,7 @@
              -e 's|@''REPLACE_SNPRINTF''@|$(REPLACE_SNPRINTF)|g' \
              -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \
              -e 
's|@''REPLACE_STDIO_WRITE_FUNCS''@|$(REPLACE_STDIO_WRITE_FUNCS)|g' \
+             -e 's|@''REPLACE_TMPFILE''@|$(REPLACE_TMPFILE)|g' \
              -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
              -e 's|@''REPLACE_VDPRINTF''@|$(REPLACE_VDPRINTF)|g' \
              -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
--- modules/tmpfile.orig        Sun Apr  4 15:31:07 2010
+++ modules/tmpfile     Sun Apr  4 15:27:42 2010
@@ -6,12 +6,14 @@
 m4/tmpfile.m4
 
 Depends-on:
+stdio
 pathmax
 tempname
 tmpdir
 
 configure.ac:
 gl_TMPFILE
+gl_STDIO_MODULE_INDICATOR([tmpfile])
 
 Makefile.am:
 
--- tests/test-stdio-c++.cc.orig        Sun Apr  4 15:31:07 2010
+++ tests/test-stdio-c++.cc     Sun Apr  4 15:25:45 2010
@@ -149,6 +149,10 @@
 SIGNATURE_CHECK (GNULIB_NAMESPACE::sprintf, int, (char *, const char *, ...));
 #endif
 
+#if GNULIB_TEST_TMPFILE
+SIGNATURE_CHECK (GNULIB_NAMESPACE::tmpfile, FILE *, (void));
+#endif
+
 #if GNULIB_TEST_VASPRINTF
 SIGNATURE_CHECK (GNULIB_NAMESPACE::asprintf, int,
                  (char **, const char *, ...));




reply via email to

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