diff --git a/libcxx/include/__new/new_handler.h b/libcxx/include/__new/new_handler.h index 05f4e846c3ef9..8f93578da9f9c 100644 --- a/libcxx/include/__new/new_handler.h +++ b/libcxx/include/__new/new_handler.h @@ -15,14 +15,10 @@ # pragma GCC system_header #endif -#if defined(_LIBCPP_ABI_VCRUNTIME) -# include -#else _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD typedef void (*new_handler)(); _LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT; _LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT; _LIBCPP_END_UNVERSIONED_NAMESPACE_STD -#endif // _LIBCPP_ABI_VCRUNTIME #endif // _LIBCPP___NEW_NEW_HANDLER_H diff --git a/libcxx/modules/std.compat/ctime.inc b/libcxx/modules/std.compat/ctime.inc index eba8234a08969..dbaf76fe6363d 100644 --- a/libcxx/modules/std.compat/ctime.inc +++ b/libcxx/modules/std.compat/ctime.inc @@ -14,15 +14,57 @@ export { using ::timespec _LIBCPP_USING_IF_EXISTS; using ::tm _LIBCPP_USING_IF_EXISTS; - using ::asctime _LIBCPP_USING_IF_EXISTS; using ::clock _LIBCPP_USING_IF_EXISTS; + using ::strftime _LIBCPP_USING_IF_EXISTS; + +#ifndef _LIBCPP_ABI_VCRUNTIME using ::ctime _LIBCPP_USING_IF_EXISTS; using ::difftime _LIBCPP_USING_IF_EXISTS; using ::gmtime _LIBCPP_USING_IF_EXISTS; using ::localtime _LIBCPP_USING_IF_EXISTS; using ::mktime _LIBCPP_USING_IF_EXISTS; - using ::strftime _LIBCPP_USING_IF_EXISTS; using ::time _LIBCPP_USING_IF_EXISTS; using ::timespec_get _LIBCPP_USING_IF_EXISTS; +#endif + +// A workaround for UCRT because it defines these functions +// as static and that causes the error "internal linkage cannot be exported" +#ifdef _LIBCPP_ABI_VCRUNTIME + + template + inline char* __CRTDECL ctime(_In_ time_t const* const _Time) noexcept { + return _ctime64(_Time); + } + + template + inline double __CRTDECL difftime(_In_ time_t const _Time1, _In_ time_t const _Time2) noexcept { + return _difftime64(_Time1, _Time2); + } + + template + inline tm* __CRTDECL gmtime(_In_ time_t const* const _Time) noexcept { + return _gmtime64(_Time); + } + + template + inline tm* __CRTDECL localtime(_In_ time_t const* const _Time) noexcept { + return _localtime64(_Time); + } + + template + inline time_t __CRTDECL mktime(_Inout_ tm* const _Tm) noexcept { + return _mktime64(_Tm); + } + + template + inline time_t __CRTDECL time(_Out_opt_ time_t* const _Time) noexcept { + return _time64(_Time); + } + + template + inline int __CRTDECL timespec_get(_Out_ timespec* const _Ts, _In_ int const _Base) noexcept { + return _timespec64_get(reinterpret_cast<_timespec64*>(_Ts), _Base); + } +#endif } // export diff --git a/libcxx/modules/std/ctime.inc b/libcxx/modules/std/ctime.inc index 5bfa61917e5f2..4caa9d3e33d36 100644 --- a/libcxx/modules/std/ctime.inc +++ b/libcxx/modules/std/ctime.inc @@ -17,12 +17,55 @@ export namespace std { using std::asctime _LIBCPP_USING_IF_EXISTS; using std::clock _LIBCPP_USING_IF_EXISTS; + using std::strftime _LIBCPP_USING_IF_EXISTS; + +#ifndef _LIBCPP_ABI_VCRUNTIME using std::ctime _LIBCPP_USING_IF_EXISTS; using std::difftime _LIBCPP_USING_IF_EXISTS; using std::gmtime _LIBCPP_USING_IF_EXISTS; using std::localtime _LIBCPP_USING_IF_EXISTS; using std::mktime _LIBCPP_USING_IF_EXISTS; - using std::strftime _LIBCPP_USING_IF_EXISTS; using std::time _LIBCPP_USING_IF_EXISTS; using std::timespec_get _LIBCPP_USING_IF_EXISTS; +#endif + +// A workaround for UCRT because it defines these functions +// as static and that causes the error "internal linkage cannot be exported" +#ifdef _LIBCPP_ABI_VCRUNTIME + + template + inline char* __CRTDECL ctime(_In_ time_t const* const _Time) noexcept { + return _ctime64(_Time); + } + + template + inline double __CRTDECL difftime(_In_ time_t const _Time1, _In_ time_t const _Time2) noexcept { + return _difftime64(_Time1, _Time2); + } + + template + inline tm* __CRTDECL gmtime(_In_ time_t const* const _Time) noexcept { + return _gmtime64(_Time); + } + + template + inline tm* __CRTDECL localtime(_In_ time_t const* const _Time) noexcept { + return _localtime64(_Time); + } + + template + inline time_t __CRTDECL mktime(_Inout_ tm* const _Tm) noexcept { + return _mktime64(_Tm); + } + + template + inline time_t __CRTDECL time(_Out_opt_ time_t* const _Time) noexcept { + return _time64(_Time); + } + + template + inline int __CRTDECL timespec_get(_Out_ timespec* const _Ts, _In_ int const _Base) noexcept { + return _timespec64_get(reinterpret_cast<_timespec64*>(_Ts), _Base); + } +#endif } // namespace std diff --git a/libcxx/src/new_handler.cpp b/libcxx/src/new_handler.cpp index 49c21d85f5908..5124cb501c938 100644 --- a/libcxx/src/new_handler.cpp +++ b/libcxx/src/new_handler.cpp @@ -11,9 +11,7 @@ #include "include/atomic_support.h" #if defined(_LIBCPP_ABI_MICROSOFT) -# if !defined(_LIBCPP_ABI_VCRUNTIME) -# define _LIBPCPP_DEFINE_NEW_HANDLER -# endif +# define _LIBPCPP_DEFINE_NEW_HANDLER #elif defined(LIBCXX_BUILDING_LIBCXXABI) // nothing to do, we use the one from libc++abi #elif defined(LIBCXXRT) diff --git a/libcxx/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/get_new_handler.pass.cpp b/libcxx/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/get_new_handler.pass.cpp index c5725bde6e6c3..2c0081703760e 100644 --- a/libcxx/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/get_new_handler.pass.cpp +++ b/libcxx/test/std/language.support/support.dynamic/alloc.errors/set.new.handler/get_new_handler.pass.cpp @@ -8,12 +8,6 @@ // test get_new_handler -// FIXME: When libc++ is linked against vcruntime (i.e. the default config in -// MSVC mode), the declarations of std::set_new_handler and std::get_new_handler -// are provided by vcruntime/UCRT's new.h. However, that header actually only -// declares set_new_handler - it's missing a declaration of get_new_handler. - -// XFAIL: msvc && stdlib=libc++ #include #include diff --git a/libcxx/utils/generate_libcxx_cppm_in.py b/libcxx/utils/generate_libcxx_cppm_in.py index 39076a61b55b8..4e0d39289f33e 100644 --- a/libcxx/utils/generate_libcxx_cppm_in.py +++ b/libcxx/utils/generate_libcxx_cppm_in.py @@ -9,11 +9,19 @@ import os.path import sys -from libcxx.header_information import module_c_headers, module_headers, header_restrictions, headers_not_available, libcxx_root +from libcxx.header_information import ( + module_c_headers, + module_headers, + header_restrictions, + headers_not_available, + libcxx_root, +) def write_file(module): - with open(libcxx_root / "modules" / f"{module}.cppm.in", "w") as module_cpp_in: + with open( + libcxx_root / "modules" / f"{module}.cppm.in", "w", encoding="utf-8" + ) as module_cpp_in: module_cpp_in.write( """\ // -*- C++ -*- @@ -25,6 +33,7 @@ def write_file(module): // //===----------------------------------------------------------------------===// + // WARNING, this entire header is generated by // utils/generate_libcxx_cppm_in.py // DO NOT MODIFY!