public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4060] libstdc++: Implement C++26 native handles for file streams (P1759R6)
@ 2023-09-15 23:06 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-09-15 23:06 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:c4baeaecbbf7d0626d44ac0b69b3c8456dddb01a

commit r14-4060-gc4baeaecbbf7d0626d44ac0b69b3c8456dddb01a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Sep 15 13:43:43 2023 +0100

    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.

Diff:
---
 libstdc++-v3/acinclude.m4                          | 31 +++++++++++
 libstdc++-v3/config.h.in                           |  3 ++
 libstdc++-v3/config/abi/pre/gnu.ver                |  2 +
 libstdc++-v3/config/io/basic_file_stdio.cc         | 18 +++++++
 libstdc++-v3/config/io/basic_file_stdio.h          | 13 +++++
 libstdc++-v3/configure                             | 57 ++++++++++++++++++++
 libstdc++-v3/configure.ac                          |  3 ++
 libstdc++-v3/include/bits/version.def              |  9 ++++
 libstdc++-v3/include/bits/version.h                | 13 ++++-
 libstdc++-v3/include/std/fstream                   | 60 ++++++++++++++++++++++
 libstdc++-v3/src/c++11/Makefile.am                 | 21 +++++++-
 libstdc++-v3/src/c++11/Makefile.in                 | 40 +++++++++++----
 libstdc++-v3/src/{c++98 => c++11}/locale_init.cc   |  0
 libstdc++-v3/src/{c++98 => c++11}/localename.cc    |  0
 libstdc++-v3/src/c++98/Makefile.am                 | 22 ++------
 libstdc++-v3/src/c++98/Makefile.in                 | 39 +++++---------
 .../27_io/basic_filebuf/native_handle/version.cc   | 10 ++++
 .../27_io/basic_fstream/native_handle/char/1.cc    | 21 ++++++++
 .../27_io/basic_fstream/native_handle/wchar_t/1.cc | 21 ++++++++
 .../27_io/basic_ifstream/native_handle/char/1.cc   | 21 ++++++++
 .../basic_ifstream/native_handle/wchar_t/1.cc      | 21 ++++++++
 .../27_io/basic_ofstream/native_handle/char/1.cc   | 21 ++++++++
 .../basic_ofstream/native_handle/wchar_t/1.cc      | 21 ++++++++
 23 files changed, 411 insertions(+), 56 deletions(-)

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 34faa3c049f..d8f0ba1c3e2 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -5786,6 +5786,37 @@ AC_LANG_SAVE
   AC_LANG_RESTORE
 ])
 
+dnl
+dnl Check whether the Windows CRT function _get_osfhandle is available.
+dnl
+dnl Defines:
+dnl   _GLIBCXX_USE__GET_OSFHANDLE if _get_osfhandle is in <io.h> for Windows.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES], [
+AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+
+  AC_MSG_CHECKING([whether _get_osfhandle is defined in <io.h>])
+  AC_TRY_COMPILE([
+  #if defined(_WIN32) && !defined(__CYGWIN__)
+  # include <stdint.h>
+  # include <io.h>
+  #endif
+  ],[
+    FILE* file = 0;
+    int fd = fileno(file);
+    intptr_t crt_handle = _get_osfhandle(fd);
+    void* win32_handle = reinterpret_cast<void*>(crt_handle);
+  ], [ac_get_osfhandle=yes], [ac_get_osfhandle=no])
+  if test "$ac_objext" = yes; then
+    AC_DEFINE_UNQUOTED(_GLIBCXX_USE__GET_OSFHANDLE, 1,
+      [Define if _get_osfhandle should be used for filebuf::native_handle().])
+  fi
+  AC_MSG_RESULT($ac_get_osfhandle)
+
+  AC_LANG_RESTORE
+])
+
 # Macros from the top-level gcc directory.
 m4_include([../config/gc++filt.m4])
 m4_include([../config/tls.m4])
diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index 0abe62a98da..4af7339673c 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -1095,6 +1095,9 @@
 /* Defined if Sleep exists. */
 #undef _GLIBCXX_USE_WIN32_SLEEP
 
+/* Define if _get_osfhandle should be used for filebuf::native_handle(). */
+#undef _GLIBCXX_USE__GET_OSFHANDLE
+
 /* Define to 1 if a verbose library is built, or 0 otherwise. */
 #undef _GLIBCXX_VERBOSE
 
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index a2e5f3b4e74..15b50d51251 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 7b1729a798f..a33b53b3b27 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 29bd6531940..7b735654adb 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
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 9ac6771372c..13fc03b2a3f 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -73906,6 +73906,63 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
+# For __basic_file::native_handle()
+
+
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether _get_osfhandle is defined in <io.h>" >&5
+$as_echo_n "checking whether _get_osfhandle is defined in <io.h>... " >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+  #if defined(_WIN32) && !defined(__CYGWIN__)
+  # include <stdint.h>
+  # include <io.h>
+  #endif
+
+int
+main ()
+{
+
+    FILE* file = 0;
+    int fd = fileno(file);
+    intptr_t crt_handle = _get_osfhandle(fd);
+    void* win32_handle = reinterpret_cast<void*>(crt_handle);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_get_osfhandle=yes
+else
+  ac_get_osfhandle=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  if test "$ac_objext" = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define _GLIBCXX_USE__GET_OSFHANDLE 1
+_ACEOF
+
+  fi
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_get_osfhandle" >&5
+$as_echo "$ac_get_osfhandle" >&6; }
+
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
 # Define documentation rules conditionally.
 
 # See if makeinfo has been installed and is modern enough
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index fc0f2522027..b3991ccab48 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -553,6 +553,9 @@ GLIBCXX_CHECK_ALIGNAS_CACHELINE
 # For using init_priority in ios_init.cc
 GLIBCXX_CHECK_INIT_PRIORITY
 
+# For __basic_file::native_handle()
+GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES
+
 # Define documentation rules conditionally.
 
 # See if makeinfo has been installed and is modern enough
diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def
index b7d17c91c34..6252f5478e0 100644
--- a/libstdc++-v3/include/bits/version.def
+++ b/libstdc++-v3/include/bits/version.def
@@ -1598,6 +1598,15 @@ ftms = {
   };
 };
 
+ftms = {
+  name = fstream_native_handle;
+  values = {
+    v = 202306;
+    cxxmin = 26;
+    hosted = yes;
+  };
+};
+
 ftms = {
   name = ratio;
   values = {
diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h
index 82adda221c2..782198acc0c 100644
--- a/libstdc++-v3/include/bits/version.h
+++ b/libstdc++-v3/include/bits/version.h
@@ -1956,6 +1956,17 @@
 #undef __glibcxx_want_string_resize_and_overwrite
 
 // from version.def line 1602
+#if !defined(__cpp_lib_fstream_native_handle)
+# if (__cplusplus >  202302L) && _GLIBCXX_HOSTED
+#  define __glibcxx_fstream_native_handle 202306L
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_fstream_native_handle)
+#   define __cpp_lib_fstream_native_handle 202306L
+#  endif
+# endif
+#endif /* !defined(__cpp_lib_fstream_native_handle) && defined(__glibcxx_want_fstream_native_handle) */
+#undef __glibcxx_want_fstream_native_handle
+
+// from version.def line 1611
 #if !defined(__cpp_lib_ratio)
 # if (__cplusplus >  202302L)
 #  define __glibcxx_ratio 202306L
@@ -1966,7 +1977,7 @@
 #endif /* !defined(__cpp_lib_ratio) && defined(__glibcxx_want_ratio) */
 #undef __glibcxx_want_ratio
 
-// from version.def line 1610
+// from version.def line 1619
 #if !defined(__cpp_lib_to_string)
 # if (__cplusplus >  202302L) && _GLIBCXX_HOSTED && (__glibcxx_to_chars)
 #  define __glibcxx_to_string 202306L
diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream
index 3dff4e5e74e..f68fffc39bd 100644
--- a/libstdc++-v3/include/std/fstream
+++ b/libstdc++-v3/include/std/fstream
@@ -46,6 +46,9 @@
 #include <string>             // For std::string overloads.
 #endif
 
+#define __glibcxx_want_fstream_native_handle
+#include <bits/version.h>
+
 // This can be overridden by the target's os_defines.h
 #ifndef _GLIBCXX_BUFSIZ
 # define _GLIBCXX_BUFSIZ BUFSIZ
@@ -367,6 +370,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       __filebuf_type*
       close();
 
+#if __cpp_lib_fstream_native_handle // C++ >= 26
+      /**
+       *  @brief The platform-specific file handle type.
+       *
+       *  The type is `int` for POSIX platforms that use file descriptors,
+       *  or `HANDLE` for Windows, or `FILE*` if the library was configured
+       *  with `--enable-cstdio=stdio_pure`.
+       *
+       *  @since C++26
+       */
+      using native_handle_type = typename __file_type::native_handle_type;
+
+      /**
+       *  @brief Return the platform-specific native handle for the file.
+       *  @pre `is_open()` is true.
+       *  @return The native file handle associated with `*this`.
+       *
+       *  The handle is invalidated when this filebuf is closed or destroyed.
+       *
+       *  @since C++26
+       */
+      [[__gnu__::__always_inline__]]
+      native_handle_type
+      native_handle() const noexcept
+      {
+	__glibcxx_assert(is_open());
+	return _M_file.native_handle();
+      }
+#endif
+
     protected:
       void
       _M_allocate_internal_buffer();
@@ -739,6 +772,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	if (!_M_filebuf.close())
 	  this->setstate(ios_base::failbit);
       }
+
+#if __cpp_lib_fstream_native_handle // C++ >= 26
+      using native_handle_type = typename __filebuf_type::native_handle_type;
+
+      [[__gnu__::__always_inline__]]
+      native_handle_type
+      native_handle() const noexcept
+      { return _M_filebuf.native_handle(); }
+#endif
     };
 
 
@@ -1002,6 +1044,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	if (!_M_filebuf.close())
 	  this->setstate(ios_base::failbit);
       }
+
+#if __cpp_lib_fstream_native_handle // C++ >= 26
+      using native_handle_type = typename __filebuf_type::native_handle_type;
+
+      [[__gnu__::__always_inline__]]
+      native_handle_type
+      native_handle() const noexcept
+      { return _M_filebuf.native_handle(); }
+#endif
     };
 
 
@@ -1262,6 +1313,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	if (!_M_filebuf.close())
 	  this->setstate(ios_base::failbit);
       }
+
+#if __cpp_lib_fstream_native_handle // C++ >= 26
+      using native_handle_type = typename __filebuf_type::native_handle_type;
+
+      [[__gnu__::__always_inline__]]
+      native_handle_type
+      native_handle() const noexcept
+      { return _M_filebuf.native_handle(); }
+#endif
     };
 
 #if __cplusplus >= 201103L
diff --git a/libstdc++-v3/src/c++11/Makefile.am b/libstdc++-v3/src/c++11/Makefile.am
index e7495dcccef..9cddb978928 100644
--- a/libstdc++-v3/src/c++11/Makefile.am
+++ b/libstdc++-v3/src/c++11/Makefile.am
@@ -39,6 +39,14 @@ ctype_configure_char.cc: ${glibcxx_srcdir}/$(OS_INC_SRCDIR)/ctype_configure_char
 ctype_members.cc: ${glibcxx_srcdir}/$(CCTYPE_CC)
 	$(LN_S) ${glibcxx_srcdir}/$(CCTYPE_CC) . || true
 
+# Source files linked in via configuration/make substitution for a
+# particular host, but with ad hoc naming rules.
+host_sources_extra = \
+	basic_file.cc
+
+basic_file.cc: ${glibcxx_srcdir}/$(BASIC_FILE_CC)
+	$(LN_S) ${glibcxx_srcdir}/$(BASIC_FILE_CC) ./$@ || true
+
 if ENABLE_DUAL_ABI
 cxx11_abi_sources = \
 	cow-locale_init.cc \
@@ -71,6 +79,8 @@ sources = \
 	hashtable_c++0x.cc \
 	ios.cc \
 	ios_errcat.cc \
+	locale_init.cc \
+	localename.cc \
 	mutex.cc \
 	random.cc \
 	regex.cc  \
@@ -79,7 +89,8 @@ sources = \
 	system_error.cc \
 	thread.cc \
 	${cxx11_abi_sources} \
-	${host_sources}
+	${host_sources} \
+	${host_sources_extra}
 
 if ENABLE_DUAL_ABI
 extra_string_inst_sources = \
@@ -147,6 +158,14 @@ limits.lo: limits.cc
 	$(LTCXXCOMPILE) -fchar8_t -c $<
 limits.o: limits.cc
 	$(CXXCOMPILE) -fchar8_t -c $<
+locale_init.lo: locale_init.cc
+	$(LTCXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
+locale_init.o: locale_init.cc
+	$(CXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
+localename.lo: localename.cc
+	$(LTCXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
+localename.o: localename.cc
+	$(CXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
 
 if ENABLE_DUAL_ABI
 # Rewrite the type info for __ios_failure.
diff --git a/libstdc++-v3/src/c++11/Makefile.in b/libstdc++-v3/src/c++11/Makefile.in
index a10e05977bc..e6d37c5464c 100644
--- a/libstdc++-v3/src/c++11/Makefile.in
+++ b/libstdc++-v3/src/c++11/Makefile.in
@@ -127,20 +127,22 @@ am__objects_1 = limits.lo placeholders.lo
 @ENABLE_DUAL_ABI_TRUE@	cxx11-ios_failure.lo \
 @ENABLE_DUAL_ABI_TRUE@	cxx11-shim_facets.lo cxx11-stdexcept.lo
 am__objects_3 = ctype_configure_char.lo ctype_members.lo
-am__objects_4 = assert_fail.lo chrono.lo codecvt.lo \
+am__objects_4 = basic_file.lo
+am__objects_5 = assert_fail.lo chrono.lo codecvt.lo \
 	condition_variable.lo cow-stdexcept.lo ctype.lo debug.lo \
 	functexcept.lo functional.lo futex.lo future.lo hash_c++0x.lo \
-	hashtable_c++0x.lo ios.lo ios_errcat.lo mutex.lo random.lo \
-	regex.lo shared_ptr.lo snprintf_lite.lo system_error.lo \
-	thread.lo $(am__objects_2) $(am__objects_3)
-@ENABLE_DUAL_ABI_TRUE@am__objects_5 = cow-fstream-inst.lo \
+	hashtable_c++0x.lo ios.lo ios_errcat.lo locale_init.lo \
+	localename.lo mutex.lo random.lo regex.lo shared_ptr.lo \
+	snprintf_lite.lo system_error.lo thread.lo $(am__objects_2) \
+	$(am__objects_3) $(am__objects_4)
+@ENABLE_DUAL_ABI_TRUE@am__objects_6 = cow-fstream-inst.lo \
 @ENABLE_DUAL_ABI_TRUE@	cow-sstream-inst.lo cow-string-inst.lo \
 @ENABLE_DUAL_ABI_TRUE@	cow-string-io-inst.lo \
 @ENABLE_DUAL_ABI_TRUE@	cow-wstring-inst.lo \
 @ENABLE_DUAL_ABI_TRUE@	cow-wstring-io-inst.lo \
 @ENABLE_DUAL_ABI_TRUE@	cxx11-locale-inst.lo \
 @ENABLE_DUAL_ABI_TRUE@	cxx11-wlocale-inst.lo sso_string.lo
-@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_6 = $(am__objects_5) \
+@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_7 = $(am__objects_6) \
 @ENABLE_EXTERN_TEMPLATE_TRUE@	ext11-inst.lo fstream-inst.lo \
 @ENABLE_EXTERN_TEMPLATE_TRUE@	ios-inst.lo iostream-inst.lo \
 @ENABLE_EXTERN_TEMPLATE_TRUE@	istream-inst.lo locale-inst.lo \
@@ -152,8 +154,8 @@ am__objects_4 = assert_fail.lo chrono.lo codecvt.lo \
 @GLIBCXX_HOSTED_FALSE@am_libc__11convenience_la_OBJECTS =  \
 @GLIBCXX_HOSTED_FALSE@	$(am__objects_1)
 @GLIBCXX_HOSTED_TRUE@am_libc__11convenience_la_OBJECTS =  \
-@GLIBCXX_HOSTED_TRUE@	$(am__objects_1) $(am__objects_4) \
-@GLIBCXX_HOSTED_TRUE@	$(am__objects_6)
+@GLIBCXX_HOSTED_TRUE@	$(am__objects_1) $(am__objects_5) \
+@GLIBCXX_HOSTED_TRUE@	$(am__objects_7)
 libc__11convenience_la_OBJECTS = $(am_libc__11convenience_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -461,6 +463,12 @@ host_sources = \
 	ctype_configure_char.cc \
 	ctype_members.cc
 
+
+# Source files linked in via configuration/make substitution for a
+# particular host, but with ad hoc naming rules.
+host_sources_extra = \
+	basic_file.cc
+
 @ENABLE_DUAL_ABI_FALSE@cxx11_abi_sources = 
 @ENABLE_DUAL_ABI_TRUE@cxx11_abi_sources = \
 @ENABLE_DUAL_ABI_TRUE@	cow-locale_init.cc \
@@ -490,6 +498,8 @@ sources = \
 	hashtable_c++0x.cc \
 	ios.cc \
 	ios_errcat.cc \
+	locale_init.cc \
+	localename.cc \
 	mutex.cc \
 	random.cc \
 	regex.cc  \
@@ -498,7 +508,8 @@ sources = \
 	system_error.cc \
 	thread.cc \
 	${cxx11_abi_sources} \
-	${host_sources}
+	${host_sources} \
+	${host_sources_extra}
 
 @ENABLE_DUAL_ABI_FALSE@extra_string_inst_sources = 
 @ENABLE_DUAL_ABI_TRUE@extra_string_inst_sources = \
@@ -854,6 +865,9 @@ ctype_configure_char.cc: ${glibcxx_srcdir}/$(OS_INC_SRCDIR)/ctype_configure_char
 ctype_members.cc: ${glibcxx_srcdir}/$(CCTYPE_CC)
 	$(LN_S) ${glibcxx_srcdir}/$(CCTYPE_CC) . || true
 
+basic_file.cc: ${glibcxx_srcdir}/$(BASIC_FILE_CC)
+	$(LN_S) ${glibcxx_srcdir}/$(BASIC_FILE_CC) ./$@ || true
+
 vpath % $(top_srcdir)/src/c++11
 
 # Use special rules for the hashtable.cc file so that all
@@ -872,6 +886,14 @@ limits.lo: limits.cc
 	$(LTCXXCOMPILE) -fchar8_t -c $<
 limits.o: limits.cc
 	$(CXXCOMPILE) -fchar8_t -c $<
+locale_init.lo: locale_init.cc
+	$(LTCXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
+locale_init.o: locale_init.cc
+	$(CXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
+localename.lo: localename.cc
+	$(LTCXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
+localename.o: localename.cc
+	$(CXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
 
 @ENABLE_DUAL_ABI_TRUE@cxx11-ios_failure-lt.s: cxx11-ios_failure.cc
 @ENABLE_DUAL_ABI_TRUE@	$(LTCXXCOMPILE) -gno-as-loc-support -S $< -o tmp-cxx11-ios_failure-lt.s
diff --git a/libstdc++-v3/src/c++98/locale_init.cc b/libstdc++-v3/src/c++11/locale_init.cc
similarity index 100%
rename from libstdc++-v3/src/c++98/locale_init.cc
rename to libstdc++-v3/src/c++11/locale_init.cc
diff --git a/libstdc++-v3/src/c++98/localename.cc b/libstdc++-v3/src/c++11/localename.cc
similarity index 100%
rename from libstdc++-v3/src/c++98/localename.cc
rename to libstdc++-v3/src/c++11/localename.cc
diff --git a/libstdc++-v3/src/c++98/Makefile.am b/libstdc++-v3/src/c++98/Makefile.am
index 284ffda3443..72be2d2d2ea 100644
--- a/libstdc++-v3/src/c++98/Makefile.am
+++ b/libstdc++-v3/src/c++98/Makefile.am
@@ -81,15 +81,11 @@ endif
 # Source files linked in via configuration/make substitution for a
 # particular host, but with ad hoc naming rules.
 host_sources_extra = \
-	basic_file.cc c++locale.cc \
-	${inst_sources} ${parallel_sources}
+	c++locale.cc
 
 c++locale.cc: ${glibcxx_srcdir}/$(CLOCALE_CC)
 	$(LN_S) ${glibcxx_srcdir}/$(CLOCALE_CC) ./$@ || true
 
-basic_file.cc: ${glibcxx_srcdir}/$(BASIC_FILE_CC)
-	$(LN_S) ${glibcxx_srcdir}/$(BASIC_FILE_CC) ./$@ || true
-
 if ENABLE_DUAL_ABI
 cxx11_abi_sources = \
 	cow-istream-string.cc
@@ -130,9 +126,7 @@ sources = \
 	list_associated.cc \
 	list_associated-2.cc \
 	locale.cc \
-	locale_init.cc \
 	locale_facets.cc \
-	localename.cc \
 	math_stubs_float.cc \
 	math_stubs_long_double.cc \
 	stdexcept.cc \
@@ -144,7 +138,9 @@ sources = \
 	valarray.cc \
 	${cxx11_abi_sources} \
 	${host_sources} \
-	${host_sources_extra}
+	${host_sources_extra} \
+	${inst_sources} \
+	${parallel_sources}
 
 vpath % $(top_srcdir)/src/c++98
 
@@ -181,16 +177,6 @@ numeric_members_cow.o: numeric_members_cow.cc
 	$(CXXCOMPILE) $(GLIBCXX_ABI_FLAGS) -fimplicit-templates -c $<
 endif
 
-# XXX TODO move locale_init.cc and localename.cc to src/c++11
-locale_init.lo: locale_init.cc
-	$(LTCXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
-locale_init.o: locale_init.cc
-	$(CXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
-localename.lo: localename.cc
-	$(LTCXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
-localename.o: localename.cc
-	$(CXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
-
 # Use special rules for the deprecated source files so that they find
 # deprecated include files.
 GLIBCXX_INCLUDE_DIR=$(glibcxx_builddir)/include
diff --git a/libstdc++-v3/src/c++98/Makefile.in b/libstdc++-v3/src/c++98/Makefile.in
index a100df77a6d..95e909b1049 100644
--- a/libstdc++-v3/src/c++98/Makefile.in
+++ b/libstdc++-v3/src/c++98/Makefile.in
@@ -129,21 +129,20 @@ libc__98convenience_la_LIBADD =
 am__objects_3 = $(am__objects_2) codecvt_members.lo collate_members.lo \
 	messages_members.lo monetary_members.lo numeric_members.lo \
 	time_members.lo
-@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_4 = allocator-inst.lo \
+am__objects_4 = c++locale.lo
+@ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_5 = allocator-inst.lo \
 @ENABLE_EXTERN_TEMPLATE_TRUE@	concept-inst.lo ext-inst.lo \
 @ENABLE_EXTERN_TEMPLATE_TRUE@	misc-inst.lo
-am__objects_5 = parallel_settings.lo
-am__objects_6 = basic_file.lo c++locale.lo $(am__objects_4) \
-	$(am__objects_5)
+am__objects_6 = parallel_settings.lo
 am__objects_7 = bitmap_allocator.lo pool_allocator.lo mt_allocator.lo \
 	codecvt.lo complex_io.lo globals_io.lo hash_tr1.lo \
 	hashtable_tr1.lo ios_failure.lo ios_init.lo ios_locale.lo \
 	list.lo list-aux.lo list-aux-2.lo list_associated.lo \
-	list_associated-2.lo locale.lo locale_init.lo locale_facets.lo \
-	localename.lo math_stubs_float.lo math_stubs_long_double.lo \
-	stdexcept.lo strstream.lo tree.lo istream.lo istream-string.lo \
-	streambuf.lo valarray.lo $(am__objects_1) $(am__objects_3) \
-	$(am__objects_6)
+	list_associated-2.lo locale.lo locale_facets.lo \
+	math_stubs_float.lo math_stubs_long_double.lo stdexcept.lo \
+	strstream.lo tree.lo istream.lo istream-string.lo streambuf.lo \
+	valarray.lo $(am__objects_1) $(am__objects_3) $(am__objects_4) \
+	$(am__objects_5) $(am__objects_6)
 @GLIBCXX_HOSTED_TRUE@am_libc__98convenience_la_OBJECTS =  \
 @GLIBCXX_HOSTED_TRUE@	$(am__objects_7)
 libc__98convenience_la_OBJECTS = $(am_libc__98convenience_la_OBJECTS)
@@ -468,8 +467,7 @@ host_sources = \
 # Source files linked in via configuration/make substitution for a
 # particular host, but with ad hoc naming rules.
 host_sources_extra = \
-	basic_file.cc c++locale.cc \
-	${inst_sources} ${parallel_sources}
+	c++locale.cc
 
 @ENABLE_DUAL_ABI_FALSE@cxx11_abi_sources = 
 @ENABLE_DUAL_ABI_TRUE@cxx11_abi_sources = \
@@ -506,9 +504,7 @@ sources = \
 	list_associated.cc \
 	list_associated-2.cc \
 	locale.cc \
-	locale_init.cc \
 	locale_facets.cc \
-	localename.cc \
 	math_stubs_float.cc \
 	math_stubs_long_double.cc \
 	stdexcept.cc \
@@ -520,7 +516,9 @@ sources = \
 	valarray.cc \
 	${cxx11_abi_sources} \
 	${host_sources} \
-	${host_sources_extra}
+	${host_sources_extra} \
+	${inst_sources} \
+	${parallel_sources}
 
 @GLIBCXX_HOSTED_FALSE@libc__98convenience_la_SOURCES = 
 @GLIBCXX_HOSTED_TRUE@libc__98convenience_la_SOURCES = $(sources)
@@ -871,9 +869,6 @@ time_members.cc: ${glibcxx_srcdir}/$(CTIME_CC)
 c++locale.cc: ${glibcxx_srcdir}/$(CLOCALE_CC)
 	$(LN_S) ${glibcxx_srcdir}/$(CLOCALE_CC) ./$@ || true
 
-basic_file.cc: ${glibcxx_srcdir}/$(BASIC_FILE_CC)
-	$(LN_S) ${glibcxx_srcdir}/$(BASIC_FILE_CC) ./$@ || true
-
 vpath % $(top_srcdir)/src/c++98
 
 # Use special rules to compile with -fimplicit-templates.
@@ -898,16 +893,6 @@ c++locale.o: c++locale.cc
 @ENABLE_DUAL_ABI_TRUE@	$(LTCXXCOMPILE) $(GLIBCXX_ABI_FLAGS) -fimplicit-templates -c $<
 @ENABLE_DUAL_ABI_TRUE@numeric_members_cow.o: numeric_members_cow.cc
 @ENABLE_DUAL_ABI_TRUE@	$(CXXCOMPILE) $(GLIBCXX_ABI_FLAGS) -fimplicit-templates -c $<
-
-# XXX TODO move locale_init.cc and localename.cc to src/c++11
-locale_init.lo: locale_init.cc
-	$(LTCXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
-locale_init.o: locale_init.cc
-	$(CXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
-localename.lo: localename.cc
-	$(LTCXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
-localename.o: localename.cc
-	$(CXXCOMPILE) -std=gnu++11 -fchar8_t -c $<
 strstream.lo: strstream.cc
 	$(LTCXXCOMPILE) -I$(GLIBCXX_INCLUDE_DIR)/backward -Wno-deprecated -c $<
 strstream.o: strstream.cc
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/version.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/version.cc
new file mode 100644
index 00000000000..46c400d12ce
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/native_handle/version.cc
@@ -0,0 +1,10 @@
+// { dg-do preprocess { target c++26 } }
+// { dg-require-effective-target hosted }
+
+#include <version>
+
+#ifndef __cpp_lib_fstream_native_handle
+# error "Feature-test macro for fstream_native_handle missing in <version>"
+#elif __cpp_lib_fstream_native_handle != 202306L
+# error "Feature-test macro for fstream_native_handle has wrong value in <version>"
+#endif
diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/native_handle/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/native_handle/char/1.cc
new file mode 100644
index 00000000000..a0e6557186b
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_fstream/native_handle/char/1.cc
@@ -0,0 +1,21 @@
+// { dg-options "-fno-inline" }
+// { dg-do run { target c++26 } }
+// { dg-additional-files "filebuf_members-1.txt" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  static_assert( std::is_same_v<std::filebuf::native_handle_type,
+				std::fstream::native_handle_type> );
+  std::fstream f;
+  f.open("filebuf_members-1.txt", std::ios::in);
+  VERIFY( f.native_handle() == f.rdbuf()->native_handle() );
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/native_handle/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/native_handle/wchar_t/1.cc
new file mode 100644
index 00000000000..fe9395c15bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_fstream/native_handle/wchar_t/1.cc
@@ -0,0 +1,21 @@
+// { dg-options "-fno-inline" }
+// { dg-do run { target c++26 } }
+// { dg-additional-files "filebuf_members-1.txt" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  static_assert( std::is_same_v<std::wfilebuf::native_handle_type,
+				std::wfstream::native_handle_type> );
+  std::wfstream f;
+  f.open("filebuf_members-1.txt", std::wios::in);
+  VERIFY( f.native_handle() == f.rdbuf()->native_handle() );
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/native_handle/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/native_handle/char/1.cc
new file mode 100644
index 00000000000..9eb477bb571
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/native_handle/char/1.cc
@@ -0,0 +1,21 @@
+// { dg-options "-fno-inline" }
+// { dg-do run { target c++26 } }
+// { dg-additional-files "filebuf_members-1.txt" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  static_assert( std::is_same_v<std::filebuf::native_handle_type,
+				std::ifstream::native_handle_type> );
+  std::ifstream f;
+  f.open("filebuf_members-1.txt");
+  VERIFY( f.native_handle() == f.rdbuf()->native_handle() );
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/native_handle/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/native_handle/wchar_t/1.cc
new file mode 100644
index 00000000000..a4680ae31eb
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/native_handle/wchar_t/1.cc
@@ -0,0 +1,21 @@
+// { dg-options "-fno-inline" }
+// { dg-do run { target c++26 } }
+// { dg-additional-files "filebuf_members-1.txt" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  static_assert( std::is_same_v<std::wfilebuf::native_handle_type,
+				std::wifstream::native_handle_type> );
+  std::wifstream f;
+  f.open("filebuf_members-1.txt");
+  VERIFY( f.native_handle() == f.rdbuf()->native_handle() );
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/native_handle/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/native_handle/char/1.cc
new file mode 100644
index 00000000000..38aea6fa72d
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/native_handle/char/1.cc
@@ -0,0 +1,21 @@
+// { dg-options "-fno-inline" }
+// { dg-do run { target c++26 } }
+// { dg-additional-files "filebuf_members-1.txt" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  static_assert( std::is_same_v<std::filebuf::native_handle_type,
+				std::ofstream::native_handle_type> );
+  std::ofstream f;
+  f.open("filebuf_members-1.txt");
+  VERIFY( f.native_handle() == f.rdbuf()->native_handle() );
+}
+
+int main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/native_handle/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/native_handle/wchar_t/1.cc
new file mode 100644
index 00000000000..dcc72e96164
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/native_handle/wchar_t/1.cc
@@ -0,0 +1,21 @@
+// { dg-options "-fno-inline" }
+// { dg-do run { target c++26 } }
+// { dg-additional-files "filebuf_members-1.txt" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  static_assert( std::is_same_v<std::wfilebuf::native_handle_type,
+				std::wofstream::native_handle_type> );
+  std::wofstream f;
+  f.open("filebuf_members-1.txt");
+  VERIFY( f.native_handle() == f.rdbuf()->native_handle() );
+}
+
+int main()
+{
+  test01();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-15 23:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-15 23:06 [gcc r14-4060] libstdc++: Implement C++26 native handles for file streams (P1759R6) Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).