aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/config
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-09-15 13:43:43 +0100
committerJonathan Wakely <jwakely@redhat.com>2023-09-15 21:57:41 +0100
commitc4baeaecbbf7d0626d44ac0b69b3c8456dddb01a (patch)
tree1b921a92b810e0e0ddf455ab9456d9726347db3d /libstdc++-v3/config
parenta923c52920d2f5c6cbd486f465dc4aec2d1f9544 (diff)
downloadgcc-c4baeaecbbf7d0626d44ac0b69b3c8456dddb01a.zip
gcc-c4baeaecbbf7d0626d44ac0b69b3c8456dddb01a.tar.gz
gcc-c4baeaecbbf7d0626d44ac0b69b3c8456dddb01a.tar.bz2
libstdc++: Implement C++26 native handles for file streams (P1759R6)
The new __basic_file::native_handle() function can be added for C++11 and above, because the names "native_handle" and "native_handle_type" are already reserved since C++11. Exporting those symbols from the shared library does no harm, even if the feature gets dropped before the C++23 standard is final. The new member functions of std::fstream etc. are only declared for C++26 and so are not instantiated in src/c++11/fstream-inst.cc. Declare them with the always_inline attribute so that no symbol definitions are needed in the library (we can change this later when C++26 support is less experimental). libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES): New macro. * config.h.in: Regenerate. * config/abi/pre/gnu.ver (GLIBCXX_3.4.32): Export new basic_filebuf members. * config/io/basic_file_stdio.cc (__basic_file::native_handle): Define new function. * config/io/basic_file_stdio.h (__basic_file::native_handle): Declare new function. * configure: Regenerate. * configure.ac: Use GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES. * include/bits/version.def (fstream_native_handles): New macro. * include/bits/version.h: Regenerate. * include/std/fstream (basic_filebuf::native_handle) (basic_fstream::native_handle, basic_ifstream::native_handle) (basic_ofstream::native_handle): New functions. * src/c++11/Makefile.am: Move compilation of basic_file.cc, locale_init.cc and localename.cc to here. * src/c++11/Makefile.in: Regenerate. * src/c++98/locale_init.cc: Moved to... * src/c++11/locale_init.cc: ...here. * src/c++98/localename.cc: Moved to... * src/c++11/localename.cc: ...here. * src/c++98/Makefile.am: Remove basic_file.cc, locale_init.cc and localename.cc from here. * src/c++98/Makefile.in: Regenerate. * testsuite/27_io/basic_filebuf/native_handle/version.cc: New test. * testsuite/27_io/basic_fstream/native_handle/char/1.cc: New test. * testsuite/27_io/basic_fstream/native_handle/wchar_t/1.cc: New test. * testsuite/27_io/basic_ifstream/native_handle/char/1.cc: New test. * testsuite/27_io/basic_ifstream/native_handle/wchar_t/1.cc: New test. * testsuite/27_io/basic_ofstream/native_handle/char/1.cc: New test. * testsuite/27_io/basic_ofstream/native_handle/wchar_t/1.cc: New test.
Diffstat (limited to 'libstdc++-v3/config')
-rw-r--r--libstdc++-v3/config/abi/pre/gnu.ver2
-rw-r--r--libstdc++-v3/config/io/basic_file_stdio.cc18
-rw-r--r--libstdc++-v3/config/io/basic_file_stdio.h13
3 files changed, 33 insertions, 0 deletions
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index a2e5f3b..15b50d5 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -2519,6 +2519,8 @@ GLIBCXX_3.4.31 {
GLIBCXX_3.4.32 {
_ZSt21ios_base_library_initv;
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE11_S_allocateERS3_[jmy];
+ # std::basic_file<>::native_handle()
+ _ZNKSt12__basic_fileI[cw]E13native_handleEv;
} GLIBCXX_3.4.31;
# Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc b/libstdc++-v3/config/io/basic_file_stdio.cc
index 7b1729a..a33b53b 100644
--- a/libstdc++-v3/config/io/basic_file_stdio.cc
+++ b/libstdc++-v3/config/io/basic_file_stdio.cc
@@ -66,6 +66,11 @@
#include <limits> // For <off_t>::max() and min() and <streamsize>::max()
+#if _GLIBCXX_USE__GET_OSFHANDLE
+# include <stdint.h> // For intptr_t
+# include <io.h> // For _get_osfhandle
+#endif
+
namespace
{
// Map ios_base::openmode flags to a string for use in fopen().
@@ -460,6 +465,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return 0;
}
+ __basic_file<char>::native_handle_type
+ __basic_file<char>::native_handle() const noexcept
+ {
+#ifdef _GLIBCXX_USE_STDIO_PURE
+ return _M_cfile;
+#elif _GLIBCXX_USE__GET_OSFHANDLE
+ const intptr_t handle = _M_cfile ? _get_osfhandle(fileno(_M_cfile)) : -1;
+ return reinterpret_cast<native_handle>(handle);
+#else
+ return fileno(_M_cfile);
+#endif
+ }
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
diff --git a/libstdc++-v3/config/io/basic_file_stdio.h b/libstdc++-v3/config/io/basic_file_stdio.h
index 29bd653..7b735654 100644
--- a/libstdc++-v3/config/io/basic_file_stdio.h
+++ b/libstdc++-v3/config/io/basic_file_stdio.h
@@ -127,6 +127,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
streamsize
showmanyc();
+
+#if __cplusplus >= 201103L
+#ifdef _GLIBCXX_USE_STDIO_PURE
+ using native_handle_type = __c_file*; // FILE*
+#elif _GLIBCXX_USE__GET_OSFHANDLE
+ using native_handle_type = void*; // HANDLE
+#else
+ using native_handle_type = int; // POSIX file descriptor
+#endif
+
+ native_handle_type
+ native_handle() const noexcept;
+#endif
};
_GLIBCXX_END_NAMESPACE_VERSION