Skip to content
Merged

fix #1203

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/fast_io_core_impl/operations/readimpl/pbasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ 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<instmtype> &&
(::fast_io::operations::decay::defines::has_any_of_read_bytes_operations<instmtype>))
{
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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_core_impl/operations/writeimpl/pbasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<outstmtype> &&
Expand All @@ -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);
}
}
Expand Down
5 changes: 5 additions & 0 deletions include/fast_io_dsal/impl/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_freestanding_impl/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_hosted/async_coro.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct task
}
inline void unhandled_exception()
{
::std::terminate();
::fast_io::fast_terminate();
}
inline constexpr void return_void()
{}
Expand Down
10 changes: 6 additions & 4 deletions include/fast_io_hosted/file_loaders/nt_file_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<family>(::fast_io::io_kernel, t, om, pm)};
Expand All @@ -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<family>(::fast_io::io_kernel, ent, t, om, pm)};
Expand Down Expand Up @@ -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{
Expand All @@ -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<family>(options, ::fast_io::io_kernel, ent, t,
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_hosted/filesystem/nt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 26 additions & 11 deletions include/fast_io_hosted/filesystem/win32_9xa.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct win32_9xa_dirent

inline constexpr ~win32_9xa_dirent()
{
if (file_struct) [[likely]]
if (file_struct && file_struct != reinterpret_cast<void*>(-1)) [[likely]]
{
::fast_io::win32::FindClose(file_struct);
}
Expand All @@ -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<char const *>(entry.find_path.c_str()), __builtin_addressof(wfda));
if (entry.file_struct == reinterpret_cast<void*>(-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<void*>(-1) ||
::fast_io::win32::FindNextFileA(entry.file_struct, __builtin_addressof(wfda)) == 0) [[unlikely]]
{
return false;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<void*>(-1))
{
::fast_io::win32::FindClose(this->file_struct);
}
}
dirf = ::std::move(other.dirf);
this->file_struct = other.file_struct;
Expand All @@ -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<void*>(-1)) [[likely]]
{
::fast_io::win32::FindClose(file_struct);
}
Expand Down Expand Up @@ -353,14 +362,19 @@ inline basic_win32_9xa_recursive_directory_iterator<StackType> &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;
}
}
Expand Down Expand Up @@ -405,10 +419,11 @@ begin(basic_win32_9xa_recursive_directory_generator<StackType> &prg) noexcept
basic_win32_9xa_recursive_directory_iterator<StackType> 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()};
Expand Down
10 changes: 8 additions & 2 deletions include/fast_io_hosted/platforms/nt.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ template <nt_family family>
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<family>(handle, first, last,
__builtin_addressof(offs));
Expand Down Expand Up @@ -574,6 +577,9 @@ template <nt_family family>
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<family>(handle, first, last,
__builtin_addressof(offs));
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
12 changes: 9 additions & 3 deletions include/fast_io_hosted/platforms/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1378,22 +1384,22 @@ 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<perms>(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<perms>(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())}
{
}

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<perms>(436))
inline explicit win32_9xa_dir_file(T const &filename, [[maybe_unused]] open_mode om = open_mode::directory, [[maybe_unused]] perms pm = static_cast<perms>(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<perms>(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<perms>(436))
: win32_9xa_dir_io_observer{
::fast_io::win32::details::win32_9xa_create_dir_file_at_impl(nate.handle, filename)}
{
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_hosted/process/ipc/win32/alpc_nt.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ inline void *nt_family_create_alpc_ipc_server_port_impl(nt_alpc_char_type const
us.Buffer = const_cast<char16_t *>(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);
Expand Down Expand Up @@ -701,7 +701,7 @@ inline void *nt_family_ipc_alpc_client_connect_impl(nt_alpc_char_type const *ser
us.Buffer = const_cast<char16_t *>(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;
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_hosted/threads/thread/nt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<zw>(this->handle_)};
if (status) [[unlikely]]
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_hosted/threads/thread/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
{
Expand Down