libstdc++: Override BUFSIZ for Windows targets [PR 94268]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 28 Oct 2020 13:19:21 +0000 (13:19 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 28 Oct 2020 13:19:21 +0000 (13:19 +0000)
This replaces uses of BUFSIZ with a new _GLIBCXX_BUFSIZ macro that can
be overridden in target-specific config headers.

That allows the mingw and mingw-w64 targets to override it, because
BUFSIZ is apparently defined to 512, resulting in poor performance. The
MSVCRT stdio apparently uses 4096, so we use that too.

libstdc++-v3/ChangeLog:

PR libstdc++/94268
* config/os/mingw32-w64/os_defines.h (_GLIBCXX_BUFSIZ):
Define.
* config/os/mingw32/os_defines.h (_GLIBCXX_BUFSIZ):
Define.
* include/bits/fstream.tcc: Use _GLIBCXX_BUFSIZ instead
of BUFSIZ.
* include/ext/stdio_filebuf.h: Likewise.
* include/std/fstream (_GLIBCXX_BUFSIZ): Define.

libstdc++-v3/config/os/mingw32-w64/os_defines.h
libstdc++-v3/config/os/mingw32/os_defines.h
libstdc++-v3/include/bits/fstream.tcc
libstdc++-v3/include/ext/stdio_filebuf.h
libstdc++-v3/include/std/fstream

index e535f6c2b8567720ed192edebf7eb808ce8112ba..39bdedd19e97ca594532a6201e4f8f673945bbd5 100644 (file)
@@ -90,4 +90,7 @@
 
 #define _GLIBCXX_USE_CRT_RAND_S 1
 
+// See libstdc++/94268
+#define _GLIBCXX_BUFSIZ 4096
+
 #endif
index 1fee89c49f55103466579be926d7c9ef5f0a5bca..9d2f2bda660c459fa04edbb11d87828ee59637c0 100644 (file)
@@ -78,4 +78,7 @@
 // See libstdc++/59807
 #define _GTHREAD_USE_MUTEX_INIT_FUNC 1
 
+// See libstdc++/94268
+#define _GLIBCXX_BUFSIZ 4096
+
 #endif
index 81d00c4d3187a037c1106e6c3b221141169593a7..a4ebbb84fe7376f3fa727a7eaa3b928c72a71d8d 100644 (file)
@@ -80,7 +80,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     basic_filebuf<_CharT, _Traits>::
     basic_filebuf() : __streambuf_type(), _M_lock(), _M_file(&_M_lock),
     _M_mode(ios_base::openmode(0)), _M_state_beg(), _M_state_cur(),
-    _M_state_last(), _M_buf(0), _M_buf_size(BUFSIZ),
+    _M_state_last(), _M_buf(0), _M_buf_size(_GLIBCXX_BUFSIZ),
     _M_buf_allocated(false), _M_reading(false), _M_writing(false), _M_pback(), 
     _M_pback_cur_save(0), _M_pback_end_save(0), _M_pback_init(false),
     _M_codecvt(0), _M_ext_buf(0), _M_ext_buf_size(0), _M_ext_next(0),
index fb95bec73503bf4e1b449ddfb1e2320854431c47..3b297285ad3e81fe3fe74b0b0f507aba63faf16d 100644 (file)
@@ -75,7 +75,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  closed when the stdio_filebuf is closed/destroyed.
       */
       stdio_filebuf(int __fd, std::ios_base::openmode __mode,
-                   size_t __size = static_cast<size_t>(BUFSIZ));
+                   size_t __size = static_cast<size_t>(_GLIBCXX_BUFSIZ));
 
       /**
        *  @param  __f  An open @c FILE*.
@@ -88,7 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  stdio_filebuf is closed/destroyed.
       */
       stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode,
-                   size_t __size = static_cast<size_t>(BUFSIZ));
+                   size_t __size = static_cast<size_t>(_GLIBCXX_BUFSIZ));
 
       /**
        *  Closes the external data stream if the file descriptor constructor
index efc99d1e5a5d4c28e12bf8cf5a9ee0a2b33fdfe4..d884a15be41b8f4a6a52f572069de09c9885f46c 100644 (file)
 #include <string>             // For std::string overloads.
 #endif
 
+// This can be overridden by the target's os_defines.h
+#ifndef _GLIBCXX_BUFSIZ
+# define _GLIBCXX_BUFSIZ BUFSIZ
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION