Skip to content

Commit 81e3259

Browse files
authored
fix (#1203)
1 parent 31070d2 commit 81e3259

File tree

13 files changed

+66
-32
lines changed

13 files changed

+66
-32
lines changed

include/fast_io_core_impl/operations/readimpl/pbasis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ inline constexpr void pread_all_cold_impl(instmtype insm, typename instmtype::in
253253
{
254254
auto oldoff{::fast_io::operations::decay::input_stream_seek_decay(insm, 0, ::fast_io::seekdir::cur)};
255255
::fast_io::operations::decay::input_stream_seek_decay(insm, off, ::fast_io::seekdir::beg);
256-
::fast_io::details::read_all_bytes_impl(insm, first, last);
256+
::fast_io::details::read_all_bytes_impl(insm, reinterpret_cast<::std::byte *>(first), reinterpret_cast<::std::byte *>(last));
257257
::fast_io::operations::decay::input_stream_seek_decay(insm, oldoff, ::fast_io::seekdir::beg);
258258
}
259259
else if constexpr (::fast_io::operations::decay::defines::has_input_or_io_stream_seek_bytes_define<instmtype> &&
260260
(::fast_io::operations::decay::defines::has_any_of_read_bytes_operations<instmtype>))
261261
{
262262
auto oldoff{::fast_io::operations::decay::input_stream_seek_bytes_decay(insm, 0, ::fast_io::seekdir::cur)};
263263
::fast_io::operations::decay::input_stream_seek_bytes_decay(insm, off, ::fast_io::seekdir::beg);
264-
::fast_io::details::read_all_bytes_impl(insm, first, last);
264+
::fast_io::details::read_all_bytes_impl(insm, reinterpret_cast<::std::byte *>(first), reinterpret_cast<::std::byte *>(last));
265265
::fast_io::operations::decay::input_stream_seek_bytes_decay(insm, oldoff, ::fast_io::seekdir::beg);
266266
}
267267
}

include/fast_io_core_impl/operations/writeimpl/pbasis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ inline constexpr void pwrite_all_cold_impl(outstmtype outsm, typename outstmtype
262262
{
263263
auto oldoff{::fast_io::operations::decay::output_stream_seek_decay(outsm, 0, ::fast_io::seekdir::cur)};
264264
::fast_io::operations::decay::output_stream_seek_decay(outsm, off, ::fast_io::seekdir::beg);
265-
::fast_io::details::write_all_bytes_impl(outsm, first, last);
265+
::fast_io::details::write_all_bytes_impl(outsm, reinterpret_cast<::std::byte const *>(first), reinterpret_cast<::std::byte const *>(last));
266266
::fast_io::operations::decay::output_stream_seek_decay(outsm, oldoff, ::fast_io::seekdir::beg);
267267
}
268268
else if constexpr (::fast_io::operations::decay::defines::has_output_or_io_stream_seek_bytes_define<outstmtype> &&
@@ -275,7 +275,7 @@ inline constexpr void pwrite_all_cold_impl(outstmtype outsm, typename outstmtype
275275
{
276276
auto oldoff{::fast_io::operations::decay::output_stream_seek_bytes_decay(outsm, 0, ::fast_io::seekdir::cur)};
277277
::fast_io::operations::decay::output_stream_seek_bytes_decay(outsm, off, ::fast_io::seekdir::beg);
278-
::fast_io::details::write_all_bytes_impl(outsm, first, last);
278+
::fast_io::details::write_all_bytes_impl(outsm, reinterpret_cast<::std::byte const *>(first), reinterpret_cast<::std::byte const *>(last));
279279
::fast_io::operations::decay::output_stream_seek_bytes_decay(outsm, oldoff, ::fast_io::seekdir::beg);
280280
}
281281
}

include/fast_io_dsal/impl/string.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
524524
this->assign_impl(other.imp.begin_ptr, static_cast<::std::size_t>(other.imp.curr_ptr - other.imp.begin_ptr));
525525
return *this;
526526
}
527+
inline constexpr basic_string& operator=(string_view_type const &other) noexcept
528+
{
529+
this->assign(other);
530+
return *this;
531+
}
527532

528533
private:
529534
#if __has_cpp_attribute(__gnu__::__cold__)

include/fast_io_freestanding_impl/generator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class generator_promise
4545
#ifdef __cpp_exceptions
4646
ex_ptr = ::std::current_exception();
4747
#else
48-
::std::terminate();
48+
::fast_io::fast_terminate();
4949
#endif
5050
}
5151
inline constexpr void return_void() noexcept

include/fast_io_hosted/async_coro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct task
2121
}
2222
inline void unhandled_exception()
2323
{
24-
::std::terminate();
24+
::fast_io::fast_terminate();
2525
}
2626
inline constexpr void return_void()
2727
{}

include/fast_io_hosted/file_loaders/nt_file_loader.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
153153
address_end = ret.address_end;
154154
}
155155
template <::fast_io::constructible_to_os_c_str T>
156-
inline explicit nt_family_file_loader(::fast_io::io_kernel_t, T const &t, ::fast_io::open_mode om,
156+
inline explicit nt_family_file_loader(::fast_io::io_kernel_t, T const &t,
157+
::fast_io::open_mode om = ::fast_io::open_mode::in,
157158
::fast_io::perms pm = static_cast<::fast_io::perms>(436))
158159
{
159160
auto ret{::fast_io::win32::nt::details::nt_load_file_impl<family>(::fast_io::io_kernel, t, om, pm)};
@@ -162,7 +163,7 @@ class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
162163
}
163164
template <::fast_io::constructible_to_os_c_str T>
164165
inline explicit nt_family_file_loader(::fast_io::io_kernel_t, ::fast_io::nt_at_entry ent, T const &t,
165-
::fast_io::open_mode om,
166+
::fast_io::open_mode om = ::fast_io::open_mode::in,
166167
::fast_io::perms pm = static_cast<::fast_io::perms>(436))
167168
{
168169
auto ret{::fast_io::win32::nt::details::nt_load_file_impl<family>(::fast_io::io_kernel, ent, t, om, pm)};
@@ -204,7 +205,7 @@ class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
204205
}
205206
template <::fast_io::constructible_to_os_c_str T>
206207
inline explicit nt_family_file_loader(nt_mmap_options const &options, ::fast_io::io_kernel_t, T const &t,
207-
::fast_io::open_mode om,
208+
::fast_io::open_mode om = ::fast_io::open_mode::in,
208209
::fast_io::perms pm = static_cast<::fast_io::perms>(436))
209210
{
210211
auto ret{
@@ -214,7 +215,8 @@ class nt_family_file_loader FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
214215
}
215216
template <::fast_io::constructible_to_os_c_str T>
216217
inline explicit nt_family_file_loader(nt_mmap_options const &options, ::fast_io::io_kernel_t,
217-
::fast_io::nt_at_entry ent, T const &t, ::fast_io::open_mode om,
218+
::fast_io::nt_at_entry ent, T const &t,
219+
::fast_io::open_mode om = ::fast_io::open_mode::in,
218220
::fast_io::perms pm = static_cast<::fast_io::perms>(436))
219221
{
220222
auto ret{::fast_io::win32::nt::details::nt_load_file_options_impl<family>(options, ::fast_io::io_kernel, ent, t,

include/fast_io_hosted/filesystem/nt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ u8filename(nt_directory_entry pioe) noexcept
218218
return {ent.u8d_name, ent.u8d_namlen};
219219
}
220220

221-
inline constexpr ::std::uint_least64_t inode_ul64(nt_directory_entry) noexcept
221+
inline constexpr ::std::uint_least64_t inode_ul64(nt_directory_entry pioe) noexcept
222222
{
223-
return 0;
223+
return pioe.entry->d_ino;
224224
}
225225

226226
inline constexpr file_type type(nt_directory_entry pioe) noexcept

include/fast_io_hosted/filesystem/win32_9xa.h

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct win32_9xa_dirent
1414

1515
inline constexpr ~win32_9xa_dirent()
1616
{
17-
if (file_struct) [[likely]]
17+
if (file_struct && file_struct != reinterpret_cast<void*>(-1)) [[likely]]
1818
{
1919
::fast_io::win32::FindClose(file_struct);
2020
}
@@ -30,10 +30,16 @@ inline bool set_win32_9xa_dirent(win32_9xa_dirent &entry, bool start)
3030
{
3131
entry.find_path = ::fast_io::win32::details::concat_win32_9xa_dir_handle_path_str(::fast_io::mnp::code_cvt(entry.d_handle.path), u8"\\*");
3232
entry.file_struct = ::fast_io::win32::FindFirstFileA(reinterpret_cast<char const *>(entry.find_path.c_str()), __builtin_addressof(wfda));
33+
if (entry.file_struct == reinterpret_cast<void*>(-1)) [[unlikely]]
34+
{
35+
entry.file_struct = nullptr;
36+
return false;
37+
}
3338
}
3439
else
3540
{
36-
if (::fast_io::win32::FindNextFileA(entry.file_struct, __builtin_addressof(wfda)) == 0) [[unlikely]]
41+
if (entry.file_struct == nullptr || entry.file_struct == reinterpret_cast<void*>(-1) ||
42+
::fast_io::win32::FindNextFileA(entry.file_struct, __builtin_addressof(wfda)) == 0) [[unlikely]]
3743
{
3844
return false;
3945
}
@@ -207,8 +213,8 @@ struct basic_win32_9xa_directory_generator
207213

208214
inline win32_9xa_family_directory_iterator begin(basic_win32_9xa_directory_generator &pdg)
209215
{
210-
win32::details::set_win32_9xa_dirent_first(pdg.entry);
211-
return {__builtin_addressof(pdg.entry), false};
216+
bool ok{win32::details::set_win32_9xa_dirent_first(pdg.entry)};
217+
return {__builtin_addressof(pdg.entry), !ok};
212218
}
213219

214220
inline ::std::default_sentinel_t end(basic_win32_9xa_directory_generator const &) noexcept
@@ -303,7 +309,10 @@ struct win32_9xa_dir_file_stack_type
303309

304310
if (this->file_struct) [[likely]]
305311
{
306-
::fast_io::win32::FindClose(this->file_struct);
312+
if (this->file_struct != reinterpret_cast<void*>(-1))
313+
{
314+
::fast_io::win32::FindClose(this->file_struct);
315+
}
307316
}
308317
dirf = ::std::move(other.dirf);
309318
this->file_struct = other.file_struct;
@@ -314,7 +323,7 @@ struct win32_9xa_dir_file_stack_type
314323

315324
inline ~win32_9xa_dir_file_stack_type()
316325
{
317-
if (file_struct) [[likely]]
326+
if (file_struct && file_struct != reinterpret_cast<void*>(-1)) [[likely]]
318327
{
319328
::fast_io::win32::FindClose(file_struct);
320329
}
@@ -353,14 +362,19 @@ inline basic_win32_9xa_recursive_directory_iterator<StackType> &operator++(basic
353362
prdit.entry->file_struct = back.file_struct;
354363
if (back.file_struct == nullptr)
355364
{
356-
win32::details::set_win32_9xa_dirent_first(*prdit.entry);
365+
bool ok{win32::details::set_win32_9xa_dirent_first(*prdit.entry)};
357366
back.file_struct = prdit.entry->file_struct;
367+
if (!ok)
368+
{
369+
prdit.finish = true;
370+
prdit.stack.pop_back();
371+
continue;
372+
}
358373
}
359-
if (!win32::details::win32_9xa_dirent_next(*prdit.entry))
374+
else if (!win32::details::win32_9xa_dirent_next(*prdit.entry))
360375
{
361376
prdit.finish = true;
362377
prdit.stack.pop_back();
363-
364378
continue;
365379
}
366380
}
@@ -405,10 +419,11 @@ begin(basic_win32_9xa_recursive_directory_generator<StackType> &prg) noexcept
405419
basic_win32_9xa_recursive_directory_iterator<StackType> prdit{prg.root_handle, __builtin_addressof(prg.entry)};
406420

407421
prdit.entry->d_handle = prg.root_handle;
408-
bool finish{win32::details::set_win32_9xa_dirent_first(*prdit.entry)};
422+
bool ok{win32::details::set_win32_9xa_dirent_first(*prdit.entry)};
409423
prdit.root_file_struct = prdit.entry->file_struct;
424+
prdit.finish = !ok;
410425

411-
if (finish && prdit.entry->d_type == file_type::directory)
426+
if (ok && prdit.entry->d_type == file_type::directory)
412427
{
413428
auto &ent{*prdit.entry};
414429
char8_t const *native_d_name_ptr{ent.filename.c_str()};

include/fast_io_hosted/platforms/nt.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ template <nt_family family>
543543
inline ::std::byte *nt_pread_some_bytes_impl(void *__restrict handle, ::std::byte *first, ::std::byte *last,
544544
::fast_io::intfpos_t off)
545545
{
546+
// The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows,
547+
// the functions will advance the position by the number of bytes written or read after each write/read operation.
548+
546549
::std::int_least64_t offs{nt_calculate_offset_impl(off)};
547550
return ::fast_io::win32::nt::details::nt_read_pread_some_bytes_common_impl<family>(handle, first, last,
548551
__builtin_addressof(offs));
@@ -574,6 +577,9 @@ template <nt_family family>
574577
inline ::std::byte const *nt_pwrite_some_bytes_impl(void *__restrict handle, ::std::byte const *first,
575578
::std::byte const *last, ::fast_io::intfpos_t off)
576579
{
580+
// The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows,
581+
// the functions will advance the position by the number of bytes written or read after each write/read operation.
582+
577583
::std::int_least64_t offs{nt_calculate_offset_impl(off)};
578584
return ::fast_io::win32::nt::details::nt_write_pwrite_some_bytes_common_impl<family>(handle, first, last,
579585
__builtin_addressof(offs));
@@ -827,7 +833,7 @@ inline nt_file_position_status nt_get_file_position_impl(void *__restrict handle
827833
::fast_io::win32::nt::file_information_class::FilePositionInformation)};
828834
if (status)
829835
{
830-
return {status};
836+
return {.status = status, .file_position = 0u};
831837
}
832838
file_position += fps;
833839
}
@@ -841,7 +847,7 @@ inline nt_file_position_status nt_get_file_position_impl(void *__restrict handle
841847
::fast_io::win32::nt::file_information_class::FileStandardInformation)};
842848
if (status)
843849
{
844-
return {status};
850+
return {.status = status, .file_position = 0u};
845851
}
846852
file_position += fsi.end_of_file;
847853
}

include/fast_io_hosted/platforms/win32.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,9 @@ inline ::std::byte *win32_read_some_bytes_impl(void *__restrict handle, ::std::b
783783
inline ::std::byte *win32_ntw_pread_some_bytes_impl(void *__restrict handle, ::std::byte *first, ::std::byte *last,
784784
::fast_io::intfpos_t off)
785785
{
786+
// The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows,
787+
// the functions will advance the position by the number of bytes written or read after each write/read operation.
788+
786789
// The use of overlapped behavior is not supported in Windows 95.
787790
::fast_io::win32::overlapped overlap{};
788791
::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, :
813816
inline ::std::byte const *win32_ntw_pwrite_some_bytes_impl(void *__restrict handle, ::std::byte const *first,
814817
::std::byte const *last, ::fast_io::intfpos_t off)
815818
{
819+
// The difference between P-series functions in Windows synchronization mode and POSIX is that under Windows,
820+
// the functions will advance the position by the number of bytes written or read after each write/read operation.
821+
816822
// The use of overlapped behavior is not supported in Windows 95.
817823
::fast_io::win32::overlapped overlap{};
818824
::fast_io::win32::details::win32_calculate_offset_impl(handle, overlap, off);
@@ -1378,22 +1384,22 @@ class win32_9xa_dir_file : public win32_9xa_dir_io_observer
13781384

13791385
inline explicit constexpr win32_9xa_dir_file(decltype(nullptr)) noexcept = delete;
13801386

1381-
inline explicit win32_9xa_dir_file(win32_9xa_fs_dirent fsdirent, [[maybe_unused]] open_mode om, [[maybe_unused]] perms pm = static_cast<perms>(436))
1387+
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))
13821388
: win32_9xa_dir_io_observer{
13831389
::fast_io::win32::details::win32_9xa_create_dir_file_at_fs_dirent_impl(
13841390
fsdirent.handle, fsdirent.filename.c_str(), fsdirent.filename.size())}
13851391
{
13861392
}
13871393

13881394
template <::fast_io::constructible_to_os_c_str T>
1389-
inline explicit win32_9xa_dir_file(T const &filename, [[maybe_unused]] open_mode om, [[maybe_unused]] perms pm = static_cast<perms>(436))
1395+
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))
13901396
: win32_9xa_dir_io_observer{
13911397
::fast_io::win32::details::win32_9xa_create_dir_file_impl(filename)}
13921398
{
13931399
}
13941400

13951401
template <::fast_io::constructible_to_os_c_str T>
1396-
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))
1402+
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))
13971403
: win32_9xa_dir_io_observer{
13981404
::fast_io::win32::details::win32_9xa_create_dir_file_at_impl(nate.handle, filename)}
13991405
{

0 commit comments

Comments
 (0)