This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++ fixes for Windows swprintf


This patch fixes some libstdc++ and libstdc++ testsuite issues with
swprintf on Windows.

Windows swprintf and vswprintf have nonstandard prototypes, and
libstdc++ has _GLIBCXX_HAVE_BROKEN_VSWPRINTF to handle this in some
places.  This patch extends this to more places.

* Sufficiently recent MinGW headers do not declare swprintf and
  vswprintf at all if __STRICT_ANSI__ because of the nonstandard
  prototypes.  This causes programs including <cwchar> to break even
  when they don't use those functions, because of the header wishing
  to bring them into namespace std.  This patch adds appropriate
  conditionals to <cwchar>.

* Two tests directly use the swprintf function, and clearly won't work
  when it has the wrong prototype, while one tests its presence in
  namespace std; this patch conditions those tests accordingly.

Tested with cross to i686-mingw32.  OK to commit?

2009-07-24  Joseph Myers  <joseph@codesourcery.com>

	* include/c_global/cwchar (swprintf, vswprintf): Do not use if
	_GLIBCXX_HAVE_BROKEN_VSWPRINTF.
	* testsuite/lib/libstdc++.exp (check_v3_target_swprintf): New.
	* testsuite/lib/dg-options.exp (dg-require-swprintf): New.
	* testsuite/21_strings/headers/cwchar/functions_std.cc,
	testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc,
	testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc:
	Use dg-require-swprintf.

Index: libstdc++-v3/include/c_global/cwchar
===================================================================
--- libstdc++-v3/include/c_global/cwchar	(revision 150057)
+++ libstdc++-v3/include/c_global/cwchar	(working copy)
@@ -156,14 +156,18 @@
   using ::mbsrtowcs;
   using ::putwc;
   using ::putwchar;
+#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
   using ::swprintf;
+#endif
   using ::swscanf;
   using ::ungetwc;
   using ::vfwprintf;
 #if _GLIBCXX_HAVE_VFWSCANF
   using ::vfwscanf;
 #endif
+#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF
   using ::vswprintf;
+#endif
 #if _GLIBCXX_HAVE_VSWSCANF
   using ::vswscanf;
 #endif
Index: libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc	(revision 150057)
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc	(working copy)
@@ -1,4 +1,5 @@
 // { dg-options "-std=gnu++0x" }
+// { dg-require-swprintf "" }
 
 // Copyright (C) 2007, 2008, 2009 Free Software Foundation
 //
Index: libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc
===================================================================
--- libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc	(revision 150057)
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc	(working copy)
@@ -1,3 +1,5 @@
+// { dg-require-swprintf "" }
+
 // Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
Index: libstdc++-v3/testsuite/21_strings/headers/cwchar/functions_std.cc
===================================================================
--- libstdc++-v3/testsuite/21_strings/headers/cwchar/functions_std.cc	(revision 150057)
+++ libstdc++-v3/testsuite/21_strings/headers/cwchar/functions_std.cc	(working copy)
@@ -1,5 +1,6 @@
 // { dg-do compile }
 // { dg-require-c-std "" }
+// { dg-require-swprintf "" }
 
 // Copyright (C) 2007, 2009 Free Software Foundation, Inc.
 //
Index: libstdc++-v3/testsuite/lib/libstdc++.exp
===================================================================
--- libstdc++-v3/testsuite/lib/libstdc++.exp	(revision 150057)
+++ libstdc++-v3/testsuite/lib/libstdc++.exp	(working copy)
@@ -1374,3 +1374,61 @@
     verbose "check_v3_target_string_conversions: $et_string_conversions" 2
     return $et_string_conversions
 }
+
+proc check_v3_target_swprintf { } {
+    global cxxflags
+    global DEFAULT_CXXFLAGS
+    global et_swprintf
+
+    global tool
+
+    if { ![info exists et_swprintf_target_name] } {
+        set et_swprintf_target_name ""
+    }
+
+    # If the target has changed since we set the cached value, clear it.
+    set current_target [current_target_name]
+    if { $current_target != $et_swprintf_target_name } {
+        verbose "check_v3_target_swprintf: `$et_swprintf_target_name'" 2
+        set et_swprintf_target_name $current_target
+        if [info exists et_swprintf] {
+            verbose "check_v3_target_swprintf: removing cached result" 2
+            unset et_swprintf
+        }
+    }
+
+    if [info exists et_swprintf] {
+        verbose "check_v3_target_swprintf: using cached result" 2
+    } else {
+        set et_swprintf 0
+	
+	# Set up and compile a C++0x test program that depends
+        # on a standard swprintf function to be available.
+        set src swprintf[pid].cc
+        set exe swprintf[pid].exe
+
+        set f [open $src "w"]
+        puts $f "#include <bits/c++config.h>"
+        puts $f "int main()"
+        puts $f "#if !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)"
+        puts $f "{ return 0; }"
+        puts $f "#endif"
+        close $f
+
+        set cxxflags_saved $cxxflags
+        set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
+
+        set lines [v3_target_compile $src $exe executable ""]
+        set cxxflags $cxxflags_saved
+        file delete $src
+
+        if [string match "" $lines] {
+            # No error message, compilation succeeded.
+            set et_swprintf 1
+        } else {
+            verbose "check_v3_target_swprintf: compilation failed" 2
+        }
+    }
+    verbose "check_v3_target_swprintf: $et_swprintf" 2
+    return $et_swprintf
+}
Index: libstdc++-v3/testsuite/lib/dg-options.exp
===================================================================
--- libstdc++-v3/testsuite/lib/dg-options.exp	(revision 150057)
+++ libstdc++-v3/testsuite/lib/dg-options.exp	(working copy)
@@ -142,3 +142,12 @@
     }
     return
 }
+
+proc dg-require-swprintf { args } {
+    if { ![ check_v3_target_swprintf ] } {
+        upvar dg-do-what dg-do-what
+        set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+        return
+    }
+    return
+}

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]