diff --git a/include/fast_io_core_impl/operations/readimpl/pbasis.h b/include/fast_io_core_impl/operations/readimpl/pbasis.h index 5084c187a..755c9bc5d 100644 --- a/include/fast_io_core_impl/operations/readimpl/pbasis.h +++ b/include/fast_io_core_impl/operations/readimpl/pbasis.h @@ -253,7 +253,7 @@ inline constexpr void pread_all_cold_impl(instmtype insm, typename instmtype::in { auto oldoff{::fast_io::operations::decay::input_stream_seek_decay(insm, 0, ::fast_io::seekdir::cur)}; ::fast_io::operations::decay::input_stream_seek_decay(insm, off, ::fast_io::seekdir::beg); - ::fast_io::details::read_all_bytes_impl(insm, first, last); + ::fast_io::details::read_all_bytes_impl(insm, reinterpret_cast<::std::byte *>(first), reinterpret_cast<::std::byte *>(last)); ::fast_io::operations::decay::input_stream_seek_decay(insm, oldoff, ::fast_io::seekdir::beg); } else if constexpr (::fast_io::operations::decay::defines::has_input_or_io_stream_seek_bytes_define && @@ -261,7 +261,7 @@ inline constexpr void pread_all_cold_impl(instmtype insm, typename instmtype::in { auto oldoff{::fast_io::operations::decay::input_stream_seek_bytes_decay(insm, 0, ::fast_io::seekdir::cur)}; ::fast_io::operations::decay::input_stream_seek_bytes_decay(insm, off, ::fast_io::seekdir::beg); - ::fast_io::details::read_all_bytes_impl(insm, first, last); + ::fast_io::details::read_all_bytes_impl(insm, reinterpret_cast<::std::byte *>(first), reinterpret_cast<::std::byte *>(last)); ::fast_io::operations::decay::input_stream_seek_bytes_decay(insm, oldoff, ::fast_io::seekdir::beg); } } diff --git a/include/fast_io_core_impl/operations/writeimpl/pbasis.h b/include/fast_io_core_impl/operations/writeimpl/pbasis.h index 6791bcd6d..ce522d8a0 100644 --- a/include/fast_io_core_impl/operations/writeimpl/pbasis.h +++ b/include/fast_io_core_impl/operations/writeimpl/pbasis.h @@ -262,7 +262,7 @@ inline constexpr void pwrite_all_cold_impl(outstmtype outsm, typename outstmtype { auto oldoff{::fast_io::operations::decay::output_stream_seek_decay(outsm, 0, ::fast_io::seekdir::cur)}; ::fast_io::operations::decay::output_stream_seek_decay(outsm, off, ::fast_io::seekdir::beg); - ::fast_io::details::write_all_bytes_impl(outsm, first, last); + ::fast_io::details::write_all_bytes_impl(outsm, reinterpret_cast<::std::byte const *>(first), reinterpret_cast<::std::byte const *>(last)); ::fast_io::operations::decay::output_stream_seek_decay(outsm, oldoff, ::fast_io::seekdir::beg); } else if constexpr (::fast_io::operations::decay::defines::has_output_or_io_stream_seek_bytes_define && @@ -275,7 +275,7 @@ inline constexpr void pwrite_all_cold_impl(outstmtype outsm, typename outstmtype { auto oldoff{::fast_io::operations::decay::output_stream_seek_bytes_decay(outsm, 0, ::fast_io::seekdir::cur)}; ::fast_io::operations::decay::output_stream_seek_bytes_decay(outsm, off, ::fast_io::seekdir::beg); - ::fast_io::details::write_all_bytes_impl(outsm, first, last); + ::fast_io::details::write_all_bytes_impl(outsm, reinterpret_cast<::std::byte const *>(first), reinterpret_cast<::std::byte const *>(last)); ::fast_io::operations::decay::output_stream_seek_bytes_decay(outsm, oldoff, ::fast_io::seekdir::beg); } } diff --git a/include/fast_io_dsal/impl/string.h b/include/fast_io_dsal/impl/string.h index 2430e6a5e..5f4eedf72 100644 --- a/include/fast_io_dsal/impl/string.h +++ b/include/fast_io_dsal/impl/string.h @@ -524,6 +524,11 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE this->assign_impl(other.imp.begin_ptr, static_cast<::std::size_t>(other.imp.curr_ptr - other.imp.begin_ptr)); return *this; } + inline constexpr basic_string& operator=(string_view_type const &other) noexcept + { + this->assign(other); + return *this; + } private: #if __has_cpp_attribute(__gnu__::__cold__) diff --git a/include/fast_io_freestanding_impl/generator.h b/include/fast_io_freestanding_impl/generator.h index e4bcadc49..166255465 100644 --- a/include/fast_io_freestanding_impl/generator.h +++ b/include/fast_io_freestanding_impl/generator.h @@ -45,7 +45,7 @@ class generator_promise #ifdef __cpp_exceptions ex_ptr = ::std::current_exception(); #else - ::std::terminate(); + ::fast_io::fast_terminate(); #endif } inline constexpr void return_void() noexcept diff --git a/include/fast_io_hosted/async_coro.h b/include/fast_io_hosted/async_coro.h index 076985228..bedcb5b91 100644 --- a/include/fast_io_hosted/async_coro.h +++ b/include/fast_io_hosted/async_coro.h @@ -21,7 +21,7 @@ struct task } inline void unhandled_exception() { - ::std::terminate(); + ::fast_io::fast_terminate(); } inline constexpr void return_void() {} diff --git a/include/fast_io_hosted/file_loaders/nt_file_loader.h b/include/fast_io_hosted/file_loaders/nt_file_loader.h index 49913ff07..d21df1877 100644 --- a/include/fast_io_hosted/file_loaders/nt_file_loader.h +++ b/include/fast_io_hosted/file_loaders/nt_file_loader.h @@ -153,7 +153,8 @@ class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE address_end = ret.address_end; } template <::fast_io::constructible_to_os_c_str T> - inline explicit nt_family_file_loader(::fast_io::io_kernel_t, T const &t, ::fast_io::open_mode om, + inline explicit nt_family_file_loader(::fast_io::io_kernel_t, T const &t, + ::fast_io::open_mode om = ::fast_io::open_mode::in, ::fast_io::perms pm = static_cast<::fast_io::perms>(436)) { auto ret{::fast_io::win32::nt::details::nt_load_file_impl(::fast_io::io_kernel, t, om, pm)}; @@ -162,7 +163,7 @@ class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE } template <::fast_io::constructible_to_os_c_str T> inline explicit nt_family_file_loader(::fast_io::io_kernel_t, ::fast_io::nt_at_entry ent, T const &t, - ::fast_io::open_mode om, + ::fast_io::open_mode om = ::fast_io::open_mode::in, ::fast_io::perms pm = static_cast<::fast_io::perms>(436)) { auto ret{::fast_io::win32::nt::details::nt_load_file_impl(::fast_io::io_kernel, ent, t, om, pm)}; @@ -204,7 +205,7 @@ class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE } template <::fast_io::constructible_to_os_c_str T> inline explicit nt_family_file_loader(nt_mmap_options const &options, ::fast_io::io_kernel_t, T const &t, - ::fast_io::open_mode om, + ::fast_io::open_mode om = ::fast_io::open_mode::in, ::fast_io::perms pm = static_cast<::fast_io::perms>(436)) { auto ret{ @@ -214,7 +215,8 @@ class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE } template <::fast_io::constructible_to_os_c_str T> inline explicit nt_family_file_loader(nt_mmap_options const &options, ::fast_io::io_kernel_t, - ::fast_io::nt_at_entry ent, T const &t, ::fast_io::open_mode om, + ::fast_io::nt_at_entry ent, T const &t, + ::fast_io::open_mode om = ::fast_io::open_mode::in, ::fast_io::perms pm = static_cast<::fast_io::perms>(436)) { auto ret{::fast_io::win32::nt::details::nt_load_file_options_impl(options, ::fast_io::io_kernel, ent, t, diff --git a/include/fast_io_hosted/filesystem/nt.h b/include/fast_io_hosted/filesystem/nt.h index 58a0cde6b..2b39b0706 100644 --- a/include/fast_io_hosted/filesystem/nt.h +++ b/include/fast_io_hosted/filesystem/nt.h @@ -218,9 +218,9 @@ u8filename(nt_directory_entry pioe) noexcept return {ent.u8d_name, ent.u8d_namlen}; } -inline constexpr ::std::uint_least64_t inode_ul64(nt_directory_entry) noexcept +inline constexpr ::std::uint_least64_t inode_ul64(nt_directory_entry pioe) noexcept { - return 0; + return pioe.entry->d_ino; } inline constexpr file_type type(nt_directory_entry pioe) noexcept diff --git a/include/fast_io_hosted/filesystem/win32_9xa.h b/include/fast_io_hosted/filesystem/win32_9xa.h index c86303966..95684bc4a 100644 --- a/include/fast_io_hosted/filesystem/win32_9xa.h +++ b/include/fast_io_hosted/filesystem/win32_9xa.h @@ -14,7 +14,7 @@ struct win32_9xa_dirent inline constexpr ~win32_9xa_dirent() { - if (file_struct) [[likely]] + if (file_struct && file_struct != reinterpret_cast(-1)) [[likely]] { ::fast_io::win32::FindClose(file_struct); } @@ -30,10 +30,16 @@ inline bool set_win32_9xa_dirent(win32_9xa_dirent &entry, bool start) { entry.find_path = ::fast_io::win32::details::concat_win32_9xa_dir_handle_path_str(::fast_io::mnp::code_cvt(entry.d_handle.path), u8"\\*"); entry.file_struct = ::fast_io::win32::FindFirstFileA(reinterpret_cast(entry.find_path.c_str()), __builtin_addressof(wfda)); + if (entry.file_struct == reinterpret_cast(-1)) [[unlikely]] + { + entry.file_struct = nullptr; + return false; + } } else { - if (::fast_io::win32::FindNextFileA(entry.file_struct, __builtin_addressof(wfda)) == 0) [[unlikely]] + if (entry.file_struct == nullptr || entry.file_struct == reinterpret_cast(-1) || + ::fast_io::win32::FindNextFileA(entry.file_struct, __builtin_addressof(wfda)) == 0) [[unlikely]] { return false; } @@ -207,8 +213,8 @@ struct basic_win32_9xa_directory_generator inline win32_9xa_family_directory_iterator begin(basic_win32_9xa_directory_generator &pdg) { - win32::details::set_win32_9xa_dirent_first(pdg.entry); - return {__builtin_addressof(pdg.entry), false}; + bool ok{win32::details::set_win32_9xa_dirent_first(pdg.entry)}; + return {__builtin_addressof(pdg.entry), !ok}; } inline ::std::default_sentinel_t end(basic_win32_9xa_directory_generator const &) noexcept @@ -303,7 +309,10 @@ struct win32_9xa_dir_file_stack_type if (this->file_struct) [[likely]] { - ::fast_io::win32::FindClose(this->file_struct); + if (this->file_struct != reinterpret_cast(-1)) + { + ::fast_io::win32::FindClose(this->file_struct); + } } dirf = ::std::move(other.dirf); this->file_struct = other.file_struct; @@ -314,7 +323,7 @@ struct win32_9xa_dir_file_stack_type inline ~win32_9xa_dir_file_stack_type() { - if (file_struct) [[likely]] + if (file_struct && file_struct != reinterpret_cast(-1)) [[likely]] { ::fast_io::win32::FindClose(file_struct); } @@ -353,14 +362,19 @@ inline basic_win32_9xa_recursive_directory_iterator &operator++(basic prdit.entry->file_struct = back.file_struct; if (back.file_struct == nullptr) { - win32::details::set_win32_9xa_dirent_first(*prdit.entry); + bool ok{win32::details::set_win32_9xa_dirent_first(*prdit.entry)}; back.file_struct = prdit.entry->file_struct; + if (!ok) + { + prdit.finish = true; + prdit.stack.pop_back(); + continue; + } } - if (!win32::details::win32_9xa_dirent_next(*prdit.entry)) + else if (!win32::details::win32_9xa_dirent_next(*prdit.entry)) { prdit.finish = true; prdit.stack.pop_back(); - continue; } } @@ -405,10 +419,11 @@ begin(basic_win32_9xa_recursive_directory_generator &prg) noexcept basic_win32_9xa_recursive_directory_iterator prdit{prg.root_handle, __builtin_addressof(prg.entry)}; prdit.entry->d_handle = prg.root_handle; - bool finish{win32::details::set_win32_9xa_dirent_first(*prdit.entry)}; + bool ok{win32::details::set_win32_9xa_dirent_first(*prdit.entry)}; prdit.root_file_struct = prdit.entry->file_struct; + prdit.finish = !ok; - if (finish && prdit.entry->d_type == file_type::directory) + if (ok && prdit.entry->d_type == file_type::directory) { auto &ent{*prdit.entry}; char8_t const *native_d_name_ptr{ent.filename.c_str()}; diff --git a/include/fast_io_hosted/platforms/nt.h b/include/fast_io_hosted/platforms/nt.h index 439e2e9bf..bb62a2624 100644 --- a/include/fast_io_hosted/platforms/nt.h +++ b/include/fast_io_hosted/platforms/nt.h @@ -543,6 +543,9 @@ template inline ::std::byte *nt_pread_some_bytes_impl(void *__restrict handle, ::std::byte *first, ::std::byte *last, ::fast_io::intfpos_t off) { + // The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows, + // the functions will advance the position by the number of bytes written or read after each write/read operation. + ::std::int_least64_t offs{nt_calculate_offset_impl(off)}; return ::fast_io::win32::nt::details::nt_read_pread_some_bytes_common_impl(handle, first, last, __builtin_addressof(offs)); @@ -574,6 +577,9 @@ template inline ::std::byte const *nt_pwrite_some_bytes_impl(void *__restrict handle, ::std::byte const *first, ::std::byte const *last, ::fast_io::intfpos_t off) { + // The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows, + // the functions will advance the position by the number of bytes written or read after each write/read operation. + ::std::int_least64_t offs{nt_calculate_offset_impl(off)}; return ::fast_io::win32::nt::details::nt_write_pwrite_some_bytes_common_impl(handle, first, last, __builtin_addressof(offs)); @@ -827,7 +833,7 @@ inline nt_file_position_status nt_get_file_position_impl(void *__restrict handle ::fast_io::win32::nt::file_information_class::FilePositionInformation)}; if (status) { - return {status}; + return {.status = status, .file_position = 0u}; } file_position += fps; } @@ -841,7 +847,7 @@ inline nt_file_position_status nt_get_file_position_impl(void *__restrict handle ::fast_io::win32::nt::file_information_class::FileStandardInformation)}; if (status) { - return {status}; + return {.status = status, .file_position = 0u}; } file_position += fsi.end_of_file; } diff --git a/include/fast_io_hosted/platforms/win32.h b/include/fast_io_hosted/platforms/win32.h index 2d28f064c..f10940d09 100644 --- a/include/fast_io_hosted/platforms/win32.h +++ b/include/fast_io_hosted/platforms/win32.h @@ -783,6 +783,9 @@ inline ::std::byte *win32_read_some_bytes_impl(void *__restrict handle, ::std::b inline ::std::byte *win32_ntw_pread_some_bytes_impl(void *__restrict handle, ::std::byte *first, ::std::byte *last, ::fast_io::intfpos_t off) { + // The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows, + // the functions will advance the position by the number of bytes written or read after each write/read operation. + // The use of overlapped behavior is not supported in Windows 95. ::fast_io::win32::overlapped overlap{}; ::fast_io::win32::details::win32_calculate_offset_impl(handle, overlap, off); @@ -813,6 +816,9 @@ inline ::std::byte const *win32_write_some_bytes_impl(void *__restrict handle, : inline ::std::byte const *win32_ntw_pwrite_some_bytes_impl(void *__restrict handle, ::std::byte const *first, ::std::byte const *last, ::fast_io::intfpos_t off) { + // The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows, + // the functions will advance the position by the number of bytes written or read after each write/read operation. + // The use of overlapped behavior is not supported in Windows 95. ::fast_io::win32::overlapped overlap{}; ::fast_io::win32::details::win32_calculate_offset_impl(handle, overlap, off); @@ -1378,7 +1384,7 @@ class win32_9xa_dir_file : public win32_9xa_dir_io_observer inline explicit constexpr win32_9xa_dir_file(decltype(nullptr)) noexcept = delete; - inline explicit win32_9xa_dir_file(win32_9xa_fs_dirent fsdirent, [[maybe_unused]] open_mode om, [[maybe_unused]] perms pm = static_cast(436)) + inline explicit win32_9xa_dir_file(win32_9xa_fs_dirent fsdirent, [[maybe_unused]] open_mode om = open_mode::directory, [[maybe_unused]] perms pm = static_cast(436)) : win32_9xa_dir_io_observer{ ::fast_io::win32::details::win32_9xa_create_dir_file_at_fs_dirent_impl( fsdirent.handle, fsdirent.filename.c_str(), fsdirent.filename.size())} @@ -1386,14 +1392,14 @@ class win32_9xa_dir_file : public win32_9xa_dir_io_observer } template <::fast_io::constructible_to_os_c_str T> - inline explicit win32_9xa_dir_file(T const &filename, [[maybe_unused]] open_mode om, [[maybe_unused]] perms pm = static_cast(436)) + inline explicit win32_9xa_dir_file(T const &filename, [[maybe_unused]] open_mode om = open_mode::directory, [[maybe_unused]] perms pm = static_cast(436)) : win32_9xa_dir_io_observer{ ::fast_io::win32::details::win32_9xa_create_dir_file_impl(filename)} { } template <::fast_io::constructible_to_os_c_str T> - inline explicit win32_9xa_dir_file(win32_9xa_at_entry nate, T const &filename, [[maybe_unused]] open_mode om, [[maybe_unused]] perms pm = static_cast(436)) + inline explicit win32_9xa_dir_file(win32_9xa_at_entry nate, T const &filename, [[maybe_unused]] open_mode om = open_mode::directory, [[maybe_unused]] perms pm = static_cast(436)) : win32_9xa_dir_io_observer{ ::fast_io::win32::details::win32_9xa_create_dir_file_at_impl(nate.handle, filename)} { diff --git a/include/fast_io_hosted/process/ipc/win32/alpc_nt.h b/include/fast_io_hosted/process/ipc/win32/alpc_nt.h index 73b7b6594..e02f7265a 100644 --- a/include/fast_io_hosted/process/ipc/win32/alpc_nt.h +++ b/include/fast_io_hosted/process/ipc/win32/alpc_nt.h @@ -308,7 +308,7 @@ inline void *nt_family_create_alpc_ipc_server_port_impl(nt_alpc_char_type const us.Buffer = const_cast(temp_ipc_name_tlc_str.c_str()); auto const temp_ipc_name_tlc_str_size_bytes{temp_ipc_name_tlc_str.size_bytes()}; us.Length = static_cast<::std::uint_least16_t>(temp_ipc_name_tlc_str_size_bytes); - us.MaximumLength = static_cast<::std::uint_least16_t>(temp_ipc_name_tlc_str_size_bytes + sizeof(char16_t)); + us.MaximumLength = ::fast_io::win32::nt::details::nt_filename_bytes_check(temp_ipc_name_tlc_str_size_bytes + sizeof(char16_t)); ::fast_io::win32::nt::object_attributes oa{}; oa.Length = sizeof(::fast_io::win32::nt::object_attributes); @@ -701,7 +701,7 @@ inline void *nt_family_ipc_alpc_client_connect_impl(nt_alpc_char_type const *ser us.Buffer = const_cast(temp_ipc_name_tlc_str.c_str()); auto const temp_ipc_name_tlc_str_size_bytes{temp_ipc_name_tlc_str.size_bytes()}; us.Length = static_cast<::std::uint_least16_t>(temp_ipc_name_tlc_str_size_bytes); - us.MaximumLength = static_cast<::std::uint_least16_t>(temp_ipc_name_tlc_str_size_bytes + sizeof(char16_t)); + us.MaximumLength = ::fast_io::win32::nt::details::nt_filename_bytes_check(temp_ipc_name_tlc_str_size_bytes + sizeof(char16_t)); ::fast_io::win32::nt::security_quality_of_service SecurityQos{}; SecurityQos.ImpersonationLevel = ::fast_io::win32::nt::security_impersonation_level::SecurityImpersonation; diff --git a/include/fast_io_hosted/threads/thread/nt.h b/include/fast_io_hosted/threads/thread/nt.h index 923b21f79..0e99dbd1d 100644 --- a/include/fast_io_hosted/threads/thread/nt.h +++ b/include/fast_io_hosted/threads/thread/nt.h @@ -128,7 +128,7 @@ class nt_thread { if (this->joinable()) [[unlikely]] { - ::std::terminate(); + ::fast_io::fast_terminate(); } auto status{::fast_io::win32::nt::nt_close(this->handle_)}; if (status) [[unlikely]] diff --git a/include/fast_io_hosted/threads/thread/win32.h b/include/fast_io_hosted/threads/thread/win32.h index 17bf17f70..68440c3b5 100644 --- a/include/fast_io_hosted/threads/thread/win32.h +++ b/include/fast_io_hosted/threads/thread/win32.h @@ -117,7 +117,7 @@ class win32_thread { if (this->joinable()) [[unlikely]] { - ::std::terminate(); + ::fast_io::fast_terminate(); } if (!::fast_io::win32::CloseHandle(this->handle_)) [[unlikely]] {