From d740adf8bd9c250d197f1d3b3e5d3344ccac8a47 Mon Sep 17 00:00:00 2001 From: MacroModel Date: Wed, 25 Jun 2025 04:58:26 +0800 Subject: [PATCH 1/7] fix --- .../fast_io_core_impl/allocation/adapters.h | 22 ++++++------ .../fast_io_core_impl/allocation/c_malloc.h | 3 +- .../allocation/linux_kernel.h | 2 +- .../allocation/mimalloc_driver.h | 2 +- .../allocation/nt_rtlheapalloc.h | 5 ++- .../allocation/win32_heapalloc.h | 2 +- .../allocation/wincrt_malloc_dbg.h | 2 +- include/fast_io_core_impl/bitops/rtz.h | 1 + include/fast_io_core_impl/buffer_view.h | 2 +- .../char_category/char_category_traits.h | 2 +- .../fast_io_core_impl/char_category/impl.h | 2 +- include/fast_io_core_impl/codecvt/general.h | 9 +++-- .../fast_io_core_impl/concat/concat_buffer.h | 4 +++ .../fast_io_core_impl/concat/concat_general.h | 2 +- .../fast_io_core_impl/dynamic_output_buffer.h | 22 ++++++++++-- include/fast_io_core_impl/enums/flock.h | 2 +- include/fast_io_core_impl/error.h | 2 +- .../freestanding/algorithm.h | 8 +++-- .../freestanding/allocator.h | 5 +-- .../integers/sto/sto_contiguous.h | 8 ++--- include/fast_io_core_impl/intrinsics.h | 34 +++++++------------ include/fast_io_core_impl/intrinsics/carry.h | 4 ++- .../fast_io_core_impl/intrinsics/udivmod.h | 2 ++ include/fast_io_core_impl/intrinsics/umul.h | 3 +- include/fast_io_core_impl/io_lockable.h | 12 +++---- include/fast_io_core_impl/iso/isos.h | 5 +-- .../fast_io_core_impl/local_new_array_ptr.h | 9 ++++- include/fast_io_core_impl/operations/common.h | 5 +-- include/fast_io_core_impl/simd/gcc_clang.h | 2 +- include/fast_io_core_impl/simd/generic.h | 4 +-- .../simd/generic_operations.h | 22 ++++++------ include/fast_io_core_impl/socket/addrscn.h | 9 +++-- include/fast_io_crypto/hash/md5.h | 2 +- .../hash/md5_sha_hash_context.h | 2 +- .../fast_io_crypto/padding/pkcs7_padding.h | 7 +++- include/fast_io_crypto/platforms/nt_bcrypt.h | 3 +- include/fast_io_driver/install_path/argv0.h | 2 +- .../fast_io_driver/install_path/argv0_null.h | 2 +- include/fast_io_driver/install_path/linux.h | 2 +- include/fast_io_driver/install_path/nt.h | 2 +- include/fast_io_driver/install_path/null.h | 4 +-- .../fast_io_driver/install_path/win32_9xa.h | 2 +- include/fast_io_driver/python/pyobject.h | 4 +-- include/fast_io_dsal/impl/deque.h | 2 ++ include/fast_io_dsal/impl/forward_list.h | 1 + .../io_buffer/io_buffer.h | 2 ++ .../scanners/line_scanner.h | 9 +++++ .../api_encoding_converter/nt.h | 3 ++ .../api_encoding_converter/posix.h | 3 ++ include/fast_io_hosted/filesystem/nt.h | 6 ++-- include/fast_io_hosted/io_file.h | 2 ++ include/fast_io_hosted/platforms/nt_mapping.h | 6 ++-- .../process/ipc/win32/alpc_nt.h | 34 ++++++------------- .../fast_io_hosted/process/process/arg_env.h | 18 +++------- include/fast_io_hosted/process/process/nt.h | 14 +++----- .../process/process/temp_array_scoped.h | 1 + .../fast_io_hosted/timeutil/posix_timezone.h | 1 + include/fast_io_legacy_impl/c/impl.h | 4 +-- include/fast_io_legacy_impl/c/wincrt.h | 9 +++++ include/fast_io_unit/string_impl/concat.h | 2 +- 60 files changed, 209 insertions(+), 158 deletions(-) diff --git a/include/fast_io_core_impl/allocation/adapters.h b/include/fast_io_core_impl/allocation/adapters.h index 11df94928..4aee0f405 100644 --- a/include/fast_io_core_impl/allocation/adapters.h +++ b/include/fast_io_core_impl/allocation/adapters.h @@ -288,11 +288,11 @@ class generic_allocator_adapter } else if constexpr (::fast_io::details::has_reallocate_aligned_impl) { - return allocator_type::reallocate_aligned_n(p, default_alignment, n); + return allocator_type::reallocate_aligned(p, default_alignment, n); } else if constexpr (::fast_io::details::has_reallocate_aligned_at_least_impl) { - return allocator_type::reallocate_aligned_n_at_least(p, default_alignment, n).ptr; + return allocator_type::reallocate_aligned_at_least(p, oldn, default_alignment, n).ptr; } else if constexpr (::fast_io::details::has_reallocate_zero_impl) { @@ -304,11 +304,11 @@ class generic_allocator_adapter } else if constexpr (::fast_io::details::has_reallocate_aligned_zero_impl) { - return allocator_type::reallocate_aligned_zero_n(p, default_alignment, n); + return allocator_type::reallocate_aligned_zero_n(p, oldn, default_alignment, n); } else if constexpr (::fast_io::details::has_reallocate_aligned_zero_at_least_impl) { - return allocator_type::reallocate_aligned_zero_n_at_least(p, default_alignment, n).ptr; + return allocator_type::reallocate_aligned_zero_n_at_least(p, oldn, default_alignment, n).ptr; } else { @@ -683,7 +683,7 @@ class generic_allocator_adapter } else if constexpr (::fast_io::details::has_reallocate_aligned_zero_n_impl) { - return allocator_type::reallocate_aligned_zero_n(p, alignment, n).ptr; + return allocator_type::reallocate_aligned_zero_n(p, oldn, alignment, n).ptr; } else { @@ -981,7 +981,7 @@ class generic_allocator_adapter { if constexpr (::fast_io::details::has_reallocate_aligned_n_at_least_impl) { - return allocator_type::reallocate_aligned_n_at_least(p, alignment, n); + return allocator_type::reallocate_aligned_n_at_least(p, oldn, alignment, n); } else if constexpr (::fast_io::details::has_reallocate_aligned_at_least_impl) { @@ -989,7 +989,7 @@ class generic_allocator_adapter } else if constexpr (::fast_io::details::has_reallocate_aligned_zero_n_at_least_impl) { - return allocator_type::reallocate_aligned_zero_n_at_least(p, alignment, n); + return allocator_type::reallocate_aligned_zero_n_at_least(p, oldn, alignment, n); } else if constexpr (::fast_io::details::has_reallocate_aligned_zero_at_least_impl) { @@ -997,7 +997,7 @@ class generic_allocator_adapter } else if constexpr (::fast_io::details::has_reallocate_aligned_impl) { - return allocator_type::reallocate_aligned_n(p, alignment, n); + return allocator_type::reallocate_aligned_n(p, oldn, alignment, n); } else if constexpr (::fast_io::details::has_reallocate_aligned_impl) { @@ -1005,7 +1005,7 @@ class generic_allocator_adapter } else if constexpr (::fast_io::details::has_reallocate_aligned_zero_n_impl) { - return allocator_type::reallocate_aligned_zero_n(p, alignment, n); + return allocator_type::reallocate_aligned_zero_n(p, oldn, alignment, n); } else if constexpr (::fast_io::details::has_reallocate_aligned_zero_impl) { @@ -1046,11 +1046,11 @@ class generic_allocator_adapter { if constexpr (::fast_io::details::has_reallocate_aligned_zero_n_at_least_impl) { - return allocator_type::reallocate_aligned_zero_n_at_least(p, alignment, n); + return allocator_type::reallocate_aligned_zero_n_at_least(p, oldn, alignment, n); } else if constexpr (::fast_io::details::has_reallocate_aligned_zero_n_impl) { - return {allocator_type::reallocate_aligned_zero_n(p, alignment, n), n}; + return {allocator_type::reallocate_aligned_zero_n(p, oldn, alignment, n), n}; } else { diff --git a/include/fast_io_core_impl/allocation/c_malloc.h b/include/fast_io_core_impl/allocation/c_malloc.h index c77b868d5..1337a65d2 100644 --- a/include/fast_io_core_impl/allocation/c_malloc.h +++ b/include/fast_io_core_impl/allocation/c_malloc.h @@ -204,8 +204,9 @@ class c_malloc_allocator { return; } + #if FAST_IO_HAS_BUILTIN(__builtin_free) - __builtin_free + __builtin_free #else ::std::free #endif diff --git a/include/fast_io_core_impl/allocation/linux_kernel.h b/include/fast_io_core_impl/allocation/linux_kernel.h index 21fe77e97..39663582a 100644 --- a/include/fast_io_core_impl/allocation/linux_kernel.h +++ b/include/fast_io_core_impl/allocation/linux_kernel.h @@ -60,7 +60,7 @@ class linux_kmalloc_allocator } static inline void deallocate(void *p) noexcept { - if (p == nullptr) + if (p == nullptr) [[unlikely]] { return; } diff --git a/include/fast_io_core_impl/allocation/mimalloc_driver.h b/include/fast_io_core_impl/allocation/mimalloc_driver.h index 0be7934e9..d74b0d0e6 100644 --- a/include/fast_io_core_impl/allocation/mimalloc_driver.h +++ b/include/fast_io_core_impl/allocation/mimalloc_driver.h @@ -343,7 +343,7 @@ class mimalloc_allocator inline static void deallocate_aligned(void *p, ::std::size_t alignment) noexcept { - if (p == nullptr) + if (p == nullptr) [[unlikely]] { return; } diff --git a/include/fast_io_core_impl/allocation/nt_rtlheapalloc.h b/include/fast_io_core_impl/allocation/nt_rtlheapalloc.h index c6d52a18d..80ca4a833 100644 --- a/include/fast_io_core_impl/allocation/nt_rtlheapalloc.h +++ b/include/fast_io_core_impl/allocation/nt_rtlheapalloc.h @@ -19,6 +19,9 @@ inline void *nt_rtlallocate_heap_handle_common_impl(void *heaphandle, ::std::siz } auto p{::fast_io::win32::nt::RtlAllocateHeap(heaphandle, flag, n)}; if (p == nullptr) +#if __has_cpp_attribute(unlikely) + [[unlikely]] +#endif { ::fast_io::fast_terminate(); } @@ -108,7 +111,7 @@ class nt_rtlallocateheap_allocator } static inline void deallocate(void *addr) noexcept { - if (addr == nullptr) + if (addr == nullptr) [[unlikely]] { return; } diff --git a/include/fast_io_core_impl/allocation/win32_heapalloc.h b/include/fast_io_core_impl/allocation/win32_heapalloc.h index f6506bede..82596bee6 100644 --- a/include/fast_io_core_impl/allocation/win32_heapalloc.h +++ b/include/fast_io_core_impl/allocation/win32_heapalloc.h @@ -164,7 +164,7 @@ class win32_heapalloc_allocator } static inline void deallocate(void *addr) noexcept { - if (addr == nullptr) + if (addr == nullptr) [[unlikely]] { return; } diff --git a/include/fast_io_core_impl/allocation/wincrt_malloc_dbg.h b/include/fast_io_core_impl/allocation/wincrt_malloc_dbg.h index d3872f998..204f28179 100644 --- a/include/fast_io_core_impl/allocation/wincrt_malloc_dbg.h +++ b/include/fast_io_core_impl/allocation/wincrt_malloc_dbg.h @@ -58,7 +58,7 @@ class wincrt_malloc_dbg_allocator } static inline void deallocate(void *p) noexcept { - if (p == nullptr) + if (p == nullptr) [[unlikely]] { return; } diff --git a/include/fast_io_core_impl/bitops/rtz.h b/include/fast_io_core_impl/bitops/rtz.h index 5a4b051b6..ad59bc9e9 100644 --- a/include/fast_io_core_impl/bitops/rtz.h +++ b/include/fast_io_core_impl/bitops/rtz.h @@ -118,6 +118,7 @@ inline constexpr ::fast_io::bitops::rtz_result rtz_impl(T n) noexcept s += b; n = b ? r : n; + /// @todo error? constexpr ::std::uint_least32_t d1{42949673u}; r = ::std::rotr(static_cast(n * d1), 2); b = r < d1; diff --git a/include/fast_io_core_impl/buffer_view.h b/include/fast_io_core_impl/buffer_view.h index b1d20c0d4..596485754 100644 --- a/include/fast_io_core_impl/buffer_view.h +++ b/include/fast_io_core_impl/buffer_view.h @@ -15,7 +15,7 @@ struct basic_ibuffer_view template <::std::contiguous_iterator Iter> requires ::std::same_as<::std::remove_cvref_t<::std::iter_value_t>, char_type> inline constexpr basic_ibuffer_view(Iter first, Iter last) noexcept - : begin_ptr{::std::to_address(first)}, curr_ptr{begin_ptr}, end_ptr{curr_ptr + (last - first)} + : begin_ptr{::std::to_address(first)}, curr_ptr{begin_ptr}, end_ptr{::std::to_address(last)} { } template <::std::ranges::contiguous_range rg> diff --git a/include/fast_io_core_impl/char_category/char_category_traits.h b/include/fast_io_core_impl/char_category/char_category_traits.h index c3648db56..4a9a04a97 100644 --- a/include/fast_io_core_impl/char_category/char_category_traits.h +++ b/include/fast_io_core_impl/char_category/char_category_traits.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once namespace fast_io::char_category { diff --git a/include/fast_io_core_impl/char_category/impl.h b/include/fast_io_core_impl/char_category/impl.h index 8647826fa..1b780a22d 100644 --- a/include/fast_io_core_impl/char_category/impl.h +++ b/include/fast_io_core_impl/char_category/impl.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "char_category.h" #include "char_category_traits.h" diff --git a/include/fast_io_core_impl/codecvt/general.h b/include/fast_io_core_impl/codecvt/general.h index f554c77e9..575df15e5 100644 --- a/include/fast_io_core_impl/codecvt/general.h +++ b/include/fast_io_core_impl/codecvt/general.h @@ -159,7 +159,8 @@ general_code_cvt(src_char_type const *src_first, src_char_type const *src_last, } else { - *dst = static_cast(0xFDFF0000); + constexpr dest_char_type val{byte_swap(static_cast(0xFFFD))}; + *dst = val; } ++dst; } @@ -410,7 +411,8 @@ inline constexpr dest_char_type *general_code_cvt(state_type &__restrict state, } else { - *dst = static_cast(0xFDFF0000); + constexpr dest_char_type val{byte_swap(static_cast(0xFFFD))}; + *dst = val; } ++dst; } @@ -535,7 +537,8 @@ inline constexpr dest_char_type *general_code_cvt_full(src_char_type const *src_ } else { - *new_dst = static_cast(0xFDFF0000); + constexpr dest_char_type val{byte_swap(static_cast(0xFFFD))}; + *new_dst = val; } ++new_dst; } diff --git a/include/fast_io_core_impl/concat/concat_buffer.h b/include/fast_io_core_impl/concat/concat_buffer.h index 0a4d3c11b..8a137e7e3 100644 --- a/include/fast_io_core_impl/concat/concat_buffer.h +++ b/include/fast_io_core_impl/concat/concat_buffer.h @@ -25,6 +25,10 @@ struct basic_concat_buffer if (buffer_begin != stack_buffer) [[unlikely]] { deallocate_iobuf_space(buffer_begin, static_cast<::std::size_t>(buffer_end - buffer_begin)); + + buffer_begin = stack_buffer; + buffer_curr = stack_buffer; + buffer_end = stack_buffer + buffer_size; } } }; diff --git a/include/fast_io_core_impl/concat/concat_general.h b/include/fast_io_core_impl/concat/concat_general.h index eecaad720..42231adeb 100644 --- a/include/fast_io_core_impl/concat/concat_general.h +++ b/include/fast_io_core_impl/concat/concat_general.h @@ -139,7 +139,7 @@ inline constexpr T basic_general_concat_decay_impl_precise(T &str, Arg arg) constexpr ::std::size_t local_cap{strlike_sso_size(io_strlike_type)}; if (local_cap < precise_size_with_line) { - strlike_reserve(io_strlike_type, str, local_cap); + strlike_reserve(io_strlike_type, str, precise_size_with_line); } auto first{strlike_begin(io_strlike_type, str)}; print_reserve_precise_define(io_reserve_type, first, precise_size, arg); diff --git a/include/fast_io_core_impl/dynamic_output_buffer.h b/include/fast_io_core_impl/dynamic_output_buffer.h index 879fa944b..356557d2a 100644 --- a/include/fast_io_core_impl/dynamic_output_buffer.h +++ b/include/fast_io_core_impl/dynamic_output_buffer.h @@ -30,6 +30,7 @@ class basic_generic_dynamic_output_buffer { typed_allocator::deallocate_n(begin_ptr, buffer_size); } + begin_ptr = nullptr; } } }; @@ -86,12 +87,14 @@ write_all_overflow_define_impl(basic_generic_dynamic_output_buffer inline constexpr bool is_domain(error e) noexcept { - constexpr ::std::size_t v{error_domain_define(error_type)}; + constexpr ::std::size_t v{domain_define(error_type)}; return v == e.domain; } diff --git a/include/fast_io_core_impl/freestanding/algorithm.h b/include/fast_io_core_impl/freestanding/algorithm.h index e235170bf..1780fd28d 100644 --- a/include/fast_io_core_impl/freestanding/algorithm.h +++ b/include/fast_io_core_impl/freestanding/algorithm.h @@ -123,6 +123,10 @@ inline constexpr output_iter copy(input_iter first, input_iter last, output_iter { *result = static_cast<::std::byte>(*first); } + else + { + *result = *first; + } ++first; ++result; } @@ -407,8 +411,8 @@ inline constexpr output_iter my_copy(input_iter first, input_iter second, output ::std::is_trivially_copyable_v && (::std::same_as || (::std::integral && ::std::integral && - sizeof(::std::is_trivially_copyable_v) == - sizeof(::std::is_trivially_copyable_v)))) + ::std::is_trivially_copyable_v == + ::std::is_trivially_copyable_v))) { my_copy_n(first, static_cast<::std::size_t>(second - first), result); return result + (second - first); diff --git a/include/fast_io_core_impl/freestanding/allocator.h b/include/fast_io_core_impl/freestanding/allocator.h index 97210edd4..5647c6d6c 100644 --- a/include/fast_io_core_impl/freestanding/allocator.h +++ b/include/fast_io_core_impl/freestanding/allocator.h @@ -14,7 +14,7 @@ struct allocator __builtin_trap(); } #if FAST_IO_HAS_BUILTIN(__builtin_operator_new) - return static_cast(__builtin_operator_new(n * sizeof(T))); + return static_cast(__builtin_operator_new(n * sizeof(T))); #else __builtin_trap(); return nullptr; @@ -23,8 +23,9 @@ struct allocator inline constexpr void deallocate([[maybe_unused]] T *ptr, [[maybe_unused]] ::std::size_t n) noexcept { #if FAST_IO_HAS_BUILTIN(__builtin_operator_delete) - __builtin_operator_delete(ptr, sizeof(T) * n); + __builtin_operator_delete(ptr, sizeof(T) * n); #endif + ptr = nullptr; } }; diff --git a/include/fast_io_core_impl/integers/sto/sto_contiguous.h b/include/fast_io_core_impl/integers/sto/sto_contiguous.h index 943036f9e..e0a9c1fb9 100644 --- a/include/fast_io_core_impl/integers/sto/sto_contiguous.h +++ b/include/fast_io_core_impl/integers/sto/sto_contiguous.h @@ -64,9 +64,9 @@ inline constexpr bool char_digit_to_literal(my_make_unsigned_t &ch) n unsigned_char_type ch3(ch); ch3 -= 0x81; unsigned_char_type ch4(ch); - ch2 -= 0xD1; + ch4 -= 0xD1; unsigned_char_type ch5(ch); - ch3 -= 0x91; + ch5 -= 0x91; ch -= 0xF0; if (ch4 < mns) { @@ -207,9 +207,9 @@ inline constexpr bool char_is_digit(my_make_unsigned_t ch) noexcept unsigned_char_type ch3(ch); ch3 -= 0x81; unsigned_char_type ch4(ch); - ch2 -= 0xD1; + ch4 -= 0xD1; unsigned_char_type ch5(ch); - ch3 -= 0x91; + ch5 -= 0x91; ch -= 0xF0; return (ch4 < mns) | (ch5 < mns) | (ch2 < mns) | (ch3 < 9) | (ch < 10u); } diff --git a/include/fast_io_core_impl/intrinsics.h b/include/fast_io_core_impl/intrinsics.h index 64dbe733a..1f53a7eea 100644 --- a/include/fast_io_core_impl/intrinsics.h +++ b/include/fast_io_core_impl/intrinsics.h @@ -22,15 +22,9 @@ inline #if __cpp_lib_bit_cast >= 201806L if (__builtin_is_constant_evaluated()) { - if (dest == nullptr || src == nullptr || sizeof(T1) != sizeof(T2) || bytes % sizeof(T1) != 0) + if (dest == nullptr || src == nullptr || sizeof(T1) != sizeof(T2) || bytes % sizeof(T1) != 0) [[unlikely]] { -#if FAST_IO_HAS_BUILTIN(__builtin_trap) - __builtin_trap(); -#elif FAST_IO_HAS_BUILTIN(__builtin_abort) - __builtin_abort(); -#else - ::std::abort(); -#endif + fast_terminate(); } ::std::size_t n{bytes / sizeof(T1)}; for (::std::size_t i{}; i != n; ++i) @@ -41,11 +35,7 @@ inline else #endif { -#if FAST_IO_HAS_BUILTIN(__builtin_memcpy) - __builtin_memcpy(dest, src, bytes); -#else - memcpy(dest, src, bytes); -#endif + ::fast_io::freestanding::my_memcpy(dest, src, bytes); } } @@ -743,11 +733,11 @@ inline constexpr ::std::size_t add_or_overflow_die(::std::size_t a, ::std::size_ } return size; } -#elif FAST_IO_HAS_BUILTIN(__builtin_add_overflow) && FAST_IO_HAS_BUILTIN(__builtin_trap) +#elif FAST_IO_HAS_BUILTIN(__builtin_add_overflow) ::std::size_t size; if (__builtin_add_overflow(a, b, __builtin_addressof(size))) [[unlikely]] { - __builtin_trap(); + fast_terminate(); } return size; #else @@ -783,20 +773,20 @@ inline constexpr ::std::size_t mul_or_overflow_die(::std::size_t a, ::std::size_ __debugbreak(); } return a * b; -#elif FAST_IO_HAS_BUILTIN(__builtin_mul_overflow) && FAST_IO_HAS_BUILTIN(__builtin_trap) +#elif FAST_IO_HAS_BUILTIN(__builtin_mul_overflow) ::std::size_t size; if (__builtin_mul_overflow(a, b, __builtin_addressof(size))) [[unlikely]] { - __builtin_trap(); + fast_terminate(); } return size; #else - ::std::size_t size{a + b}; - if (size < a) [[unlikely]] + ::std::size_t const max{SIZE_MAX / b}; + if (max < a) [[unlikely]] { fast_terminate(); } - return size; + return a * b; #endif } @@ -862,10 +852,10 @@ inline constexpr ::std::size_t cal_allocation_size_or_die(::std::size_t size) no __debugbreak(); } return size * sizeof(T); -#elif FAST_IO_HAS_BUILTIN(__builtin_mul_overflow) && FAST_IO_HAS_BUILTIN(__builtin_trap) +#elif FAST_IO_HAS_BUILTIN(__builtin_mul_overflow) if (__builtin_mul_overflow(size, sizeof(T), __builtin_addressof(size))) [[unlikely]] { - __builtin_trap(); + fast_terminate(); } return size; #else diff --git a/include/fast_io_core_impl/intrinsics/carry.h b/include/fast_io_core_impl/intrinsics/carry.h index 5a5da23ac..5f8083771 100644 --- a/include/fast_io_core_impl/intrinsics/carry.h +++ b/include/fast_io_core_impl/intrinsics/carry.h @@ -160,7 +160,9 @@ inline constexpr T subc(T a, T b, bool carryin, bool &carryout) noexcept } b = a - b; carryout = a < b; - a = b - carryin; + // b is a-b but does not handle the result of the abdication, + // at which point a can be reused for subsequent abdication underflow judgments + a = b - static_cast(carryin); carryout |= b < a; return a; } diff --git a/include/fast_io_core_impl/intrinsics/udivmod.h b/include/fast_io_core_impl/intrinsics/udivmod.h index fb1632c6a..2f2264e3c 100644 --- a/include/fast_io_core_impl/intrinsics/udivmod.h +++ b/include/fast_io_core_impl/intrinsics/udivmod.h @@ -131,6 +131,7 @@ inline constexpr T shiftleft(T low, T high, unsigned shift) noexcept return high; } unsigned lowshifter{n_udword_bits - shift}; + // users should avoid shift ub on their own return (high << shift) | (low >> lowshifter); } @@ -156,6 +157,7 @@ inline constexpr T shiftright(T low, T high, unsigned shift) noexcept return low; } unsigned lowshifter{n_udword_bits - shift}; + // users should avoid shift ub on their own return (high << lowshifter) | (low >> shift); } diff --git a/include/fast_io_core_impl/intrinsics/umul.h b/include/fast_io_core_impl/intrinsics/umul.h index 29147a75b..b0f976adb 100644 --- a/include/fast_io_core_impl/intrinsics/umul.h +++ b/include/fast_io_core_impl/intrinsics/umul.h @@ -65,6 +65,7 @@ inline constexpr T pack_generic(U low, U high) noexcept inline constexpr ::fast_io::intrinsics::ul64x2 pack_ul64(::std::uint_least64_t low, ::std::uint_least64_t high) noexcept { + // This is a full 128-bit number that requires a size end-order conversion if constexpr (::std::endian::native == ::std::endian::big) { return {high, low}; @@ -422,7 +423,7 @@ inline constexpr T umul(U a, T b, U &high) noexcept else { T h; - T low{::fast_io::intrinsics::msvc::x86::_umul128(a, b, __builtin_addressof(high))}; + T low{::fast_io::intrinsics::msvc::x86::_umul128(a, b, __builtin_addressof(h))}; high = static_cast(h); return low; } diff --git a/include/fast_io_core_impl/io_lockable.h b/include/fast_io_core_impl/io_lockable.h index 63e55c597..3ac9418c6 100644 --- a/include/fast_io_core_impl/io_lockable.h +++ b/include/fast_io_core_impl/io_lockable.h @@ -90,11 +90,8 @@ struct heap_typed_allocate_guard } inline constexpr void clear() noexcept { - if (this->ptr) [[likely]] - { - typed_allocator_type::deallocate_n(this->ptr, 1); - this->ptr = nullptr; - } + typed_allocator_type::deallocate_n(this->ptr, 1); + this->ptr = nullptr; } inline constexpr ~heap_typed_allocate_guard() { @@ -166,11 +163,12 @@ struct basic_general_mutex_movable private: inline constexpr void destroy() noexcept { - if (pmutex) + if (this->pmutex) [[likely]] { ::std::destroy_at(this->pmutex); - ::fast_io::typed_generic_allocator_adapter::deallocate_n(pmutex, 1); } + ::fast_io::typed_generic_allocator_adapter::deallocate_n(this->pmutex, 1); + this->pmutex = nullptr; } public: diff --git a/include/fast_io_core_impl/iso/isos.h b/include/fast_io_core_impl/iso/isos.h index 7ebea981c..dc0e51729 100644 --- a/include/fast_io_core_impl/iso/isos.h +++ b/include/fast_io_core_impl/iso/isos.h @@ -38,11 +38,12 @@ inline constexpr ::std::uint_least64_t cal_uint_least64_d10_max() noexcept template inline constexpr auto cal_uint_least64_d10_all_table() noexcept { + static_assert(::std::numeric_limits::digits10 > 1); ::fast_io::freestanding::array::digits10> array; if constexpr (reverse) { array.back() = 1; - for (::std::size_t i{array.size() - 1}; i--;) + for (::std::size_t i{array.size() - 1u}; i--;) { array[i] = array[i + 1] * 10u; } @@ -50,7 +51,7 @@ inline constexpr auto cal_uint_least64_d10_all_table() noexcept else { array.front() = 1; - for (::std::size_t i{1}, sz{array.size()}; i != sz; ++i) + for (::std::size_t i{}, sz{array.size() - 1u}; i != sz; ++i) { array[i + 1] = array[i] * 10u; } diff --git a/include/fast_io_core_impl/local_new_array_ptr.h b/include/fast_io_core_impl/local_new_array_ptr.h index 8a46a0cf1..a2728300c 100644 --- a/include/fast_io_core_impl/local_new_array_ptr.h +++ b/include/fast_io_core_impl/local_new_array_ptr.h @@ -24,6 +24,7 @@ inline void deallocate_with_secure_clear(void *ptr, [[maybe_unused]] ::std::size { secure_clear(ptr, buffer_bytes); } + if constexpr (allocator::has_deallocate) { allocator::deallocate(ptr); @@ -50,6 +51,7 @@ inline constexpr void deallocate_iobuf_space(char_type *ptr, [[maybe_unused]] :: { secure_clear(ptr, buffer_size * sizeof(char_type)); } + if constexpr (typed_allocator::has_deallocate) { typed_allocator::deallocate(ptr); @@ -107,7 +109,12 @@ struct buffer_alloc_arr_ptr #endif ~buffer_alloc_arr_ptr() { - deallocate_iobuf_space(ptr, size); + if (ptr) [[likely]] + { + deallocate_iobuf_space(ptr, size); + ptr = nullptr; + } + size = 0; } }; diff --git a/include/fast_io_core_impl/operations/common.h b/include/fast_io_core_impl/operations/common.h index ae95ba316..b48ff750d 100644 --- a/include/fast_io_core_impl/operations/common.h +++ b/include/fast_io_core_impl/operations/common.h @@ -38,12 +38,13 @@ template <::std::unsigned_integral U, typename T> inline constexpr ::fast_io::details::basic_scatter_total_size_overflow_result find_scatter_total_size_overflow_impl(basic_io_scatter_t const *base, U len) noexcept { - constexpr U mx{static_cast<::std::size_t>(::std::numeric_limits<::std::make_signed_t>::max())}; + constexpr U mx{static_cast<::std::size_t>(::std::numeric_limits::max())}; U total{}; auto i{base}, e{base + len}; for (; i != e; ++i) { - if (static_cast(static_cast<::std::size_t>(mx - i->len)) < total) [[unlikely]] + /// @todo mx ~= max / 2, mx - i.len may underflow. I'm guessing the author meant to check for overflow. + if (static_cast(static_cast<::std::size_t>(mx) - static_cast<::std::size_t>(i->len)) < total) [[unlikely]] { break; } diff --git a/include/fast_io_core_impl/simd/gcc_clang.h b/include/fast_io_core_impl/simd/gcc_clang.h index b3344c0bc..c8f0e4f1b 100644 --- a/include/fast_io_core_impl/simd/gcc_clang.h +++ b/include/fast_io_core_impl/simd/gcc_clang.h @@ -197,7 +197,7 @@ struct simd_vector } inline constexpr simd_vector &operator>>=(simd_vector const &other) noexcept { - value <<= other.value; + value >>= other.value; return *this; } diff --git a/include/fast_io_core_impl/simd/generic.h b/include/fast_io_core_impl/simd/generic.h index 96f5e09ee..18002f48e 100644 --- a/include/fast_io_core_impl/simd/generic.h +++ b/include/fast_io_core_impl/simd/generic.h @@ -252,13 +252,13 @@ struct } else if constexpr (sizeof(T) == 4) { - uint32x4_t temp_vec = __builtin_bit_cast(uint32x4_t, *this); + poly8x16_t temp_vec = __builtin_bit_cast(poly8x16_t, *this); temp_vec = vrev32q_p8(temp_vec); *this = __builtin_bit_cast(simd_vector, temp_vec); } else if constexpr (sizeof(T) == 2) { - uint16x8_t temp_vec = __builtin_bit_cast(uint16x8_t, *this); + poly8x16_t temp_vec = __builtin_bit_cast(poly8x16_t, *this); temp_vec = vrev16q_p8(temp_vec); *this = __builtin_bit_cast(simd_vector, temp_vec); } diff --git a/include/fast_io_core_impl/simd/generic_operations.h b/include/fast_io_core_impl/simd/generic_operations.h index 4c48dd68b..bf0327828 100644 --- a/include/fast_io_core_impl/simd/generic_operations.h +++ b/include/fast_io_core_impl/simd/generic_operations.h @@ -632,7 +632,7 @@ wrap_sub_common(::fast_io::intrinsics::simd_vector const &a, { float64x2_t amm = __builtin_bit_cast(float64x2_t, a); float64x2_t bmm = __builtin_bit_cast(float64x2_t, b); - return __builtin_bit_cast(vec_type, vsubq_f32(amm, bmm)); + return __builtin_bit_cast(vec_type, vsubq_f64(amm, bmm)); } #endif } @@ -913,8 +913,8 @@ inline constexpr simd_vector operator*(simd_vector const &a, simd_ve { if constexpr (sizeof(T) == 1) { - int8x8_t amm = __builtin_bit_cast(int8x16_t, a); - int8x8_t bmm = __builtin_bit_cast(int8x16_t, b); + int8x8_t amm = __builtin_bit_cast(int8x8_t, a); + int8x8_t bmm = __builtin_bit_cast(int8x8_t, b); return __builtin_bit_cast(vec_type, vmul_s8(amm, bmm)); } else if constexpr (sizeof(T) == 2) @@ -1266,25 +1266,25 @@ inline constexpr simd_vector operator&(simd_vector const &a, simd_ve { uint8x8_t amm = __builtin_bit_cast(uint8x8_t, a); uint8x8_t bmm = __builtin_bit_cast(uint8x8_t, b); - return __builtin_bit_cast(vec_type, vand_s8(amm, bmm)); + return __builtin_bit_cast(vec_type, vand_u8(amm, bmm)); } else if constexpr (sizeof(T) == 2) { uint16x4_t amm = __builtin_bit_cast(uint16x4_t, a); uint16x4_t bmm = __builtin_bit_cast(uint16x4_t, b); - return __builtin_bit_cast(vec_type, vand_s16(amm, bmm)); + return __builtin_bit_cast(vec_type, vand_u16(amm, bmm)); } else if constexpr (sizeof(T) == 4) { uint32x2_t amm = __builtin_bit_cast(uint32x2_t, a); uint32x2_t bmm = __builtin_bit_cast(uint32x2_t, b); - return __builtin_bit_cast(vec_type, vand_s32(amm, bmm)); + return __builtin_bit_cast(vec_type, vand_u32(amm, bmm)); } else if constexpr (sizeof(T) == 8) { uint64x1_t amm = __builtin_bit_cast(uint64x1_t, a); uint64x1_t bmm = __builtin_bit_cast(uint64x1_t, b); - return __builtin_bit_cast(vec_type, vand_s64(amm, bmm)); + return __builtin_bit_cast(vec_type, vand_u64(amm, bmm)); } } else if constexpr (sizeof(vec_type) == 16) @@ -1293,25 +1293,25 @@ inline constexpr simd_vector operator&(simd_vector const &a, simd_ve { uint8x16_t amm = __builtin_bit_cast(uint8x16_t, a); uint8x16_t bmm = __builtin_bit_cast(uint8x16_t, b); - return __builtin_bit_cast(vec_type, vandq_s8(amm, bmm)); + return __builtin_bit_cast(vec_type, vandq_u8(amm, bmm)); } else if constexpr (sizeof(T) == 2) { uint16x8_t amm = __builtin_bit_cast(uint16x8_t, a); uint16x8_t bmm = __builtin_bit_cast(uint16x8_t, b); - return __builtin_bit_cast(vec_type, vandq_s16(amm, bmm)); + return __builtin_bit_cast(vec_type, vandq_u16(amm, bmm)); } else if constexpr (sizeof(T) == 4) { uint32x4_t amm = __builtin_bit_cast(uint32x4_t, a); uint32x4_t bmm = __builtin_bit_cast(uint32x4_t, b); - return __builtin_bit_cast(vec_type, vandq_s32(amm, bmm)); + return __builtin_bit_cast(vec_type, vandq_u32(amm, bmm)); } else if constexpr (sizeof(T) == 8) { uint64x2_t amm = __builtin_bit_cast(uint64x2_t, a); uint64x2_t bmm = __builtin_bit_cast(uint64x2_t, b); - return __builtin_bit_cast(vec_type, vandq_s64(amm, bmm)); + return __builtin_bit_cast(vec_type, vandq_u64(amm, bmm)); } } } diff --git a/include/fast_io_core_impl/socket/addrscn.h b/include/fast_io_core_impl/socket/addrscn.h index 9858cc996..9da2a1261 100644 --- a/include/fast_io_core_impl/socket/addrscn.h +++ b/include/fast_io_core_impl/socket/addrscn.h @@ -23,6 +23,7 @@ enum class scan_integral_context_phase : ::std::uint_least8_t; template struct ip_scan_state_t { + /// @todo forgot? // TODO: to find out why +1 is needed here static inline constexpr auto max_size{ ::fast_io::details::print_integer_reserved_size_cache<10, false, false, ::std::uint_least16_t> + 1}; @@ -30,8 +31,8 @@ struct ip_scan_state_t scan_integral_context_phase integer_phase{}; ::std::uint_least8_t size{}; phase_t ip_phase{}; - static inline constexpr ::std::uint_least8_t port_mark = -1; - static inline constexpr ::std::uint_least8_t port = -2; + static inline constexpr ::std::uint_least8_t port_mark = static_cast<::std::uint_least8_t>(-1); + static inline constexpr ::std::uint_least8_t port = static_cast<::std::uint_least8_t>(-2); }; template <::std::integral char_type> using ipv4_scan_state_t = ip_scan_state_t; @@ -532,6 +533,7 @@ scn_cnt_define_in6addr_shorten_impl(char_type const *begin, char_type const *end return {begin, parse_code::invalid}; } // TODO + /// @todo forgot? } else [[unlikely]] { @@ -734,6 +736,7 @@ scan_contiguous_define(io_reserve_type_t) { + /// @todo forgot? // return ::fast_io::details::prtrsv_ipv6_define_impl(iter, val.reference); @@ -741,6 +744,7 @@ scan_contiguous_define(io_reserve_type_t) { + /// @todo forgot? // return ::fast_io::details::prtrsv_ip_address_define_impl(iter, val.reference); @@ -748,6 +752,7 @@ scan_contiguous_define(io_reserve_type_t(iter, val.reference); diff --git a/include/fast_io_crypto/hash/md5.h b/include/fast_io_crypto/hash/md5.h index a146a9ee2..701ab398a 100644 --- a/include/fast_io_crypto/hash/md5.h +++ b/include/fast_io_crypto/hash/md5.h @@ -106,7 +106,7 @@ inline x[j] = (::std::to_integer<::std::uint_least32_t>(*dj)) | (::std::to_integer<::std::uint_least32_t>(dj[1]) << 8) | (::std::to_integer<::std::uint_least32_t>(dj[2]) << 16) | - ::std::to_integer<::std::uint_least32_t>(dj[3] << 24); + (::std::to_integer<::std::uint_least32_t>(dj[3]) << 24); } uu(a, b, c, d, x[0], 7, 0xd76aa478u); uu(d, a, b, c, x[1], 12, 0xe8c7b756u); diff --git a/include/fast_io_crypto/hash/md5_sha_hash_context.h b/include/fast_io_crypto/hash/md5_sha_hash_context.h index 7c6ebe0ad..ac2ef3497 100644 --- a/include/fast_io_crypto/hash/md5_sha_hash_context.h +++ b/include/fast_io_crypto/hash/md5_sha_hash_context.h @@ -213,7 +213,7 @@ inline v = ::fast_io::byte_swap(v); } ::fast_io::freestanding::array<::std::byte, usz> va{ - ::fast_io::bit_cast<::fast_io::freestanding::array<::std::byte, usz>>(digest[i])}; + ::fast_io::bit_cast<::fast_io::freestanding::array<::std::byte, usz>>(v)}; ptr = ::fast_io::freestanding::nonoverlapped_bytes_copy_n(va.data(), usz, ptr); } } diff --git a/include/fast_io_crypto/padding/pkcs7_padding.h b/include/fast_io_crypto/padding/pkcs7_padding.h index 35f869b63..8114a58d8 100644 --- a/include/fast_io_crypto/padding/pkcs7_padding.h +++ b/include/fast_io_crypto/padding/pkcs7_padding.h @@ -5,14 +5,19 @@ namespace fast_io::crypto { template <::std::size_t block_size> + requires(block_size > static_cast<::std::size_t>(0u)) struct pkcs7_padding { inline constexpr auto operator()(::std::span<::std::byte const> inp, ::std::size_t remaining_length) { + if (remaining_length >= block_size) [[unlikely]] + { + ::fast_io::fast_terminate(); + } ::std::byte pad(static_cast<::std::byte>(static_cast<::std::uint_least8_t>(remaining_length & 0xFF))); ::fast_io::freestanding::array<::std::byte, block_size> text{}; details::my_copy(inp.begin(), inp.end(), text.data()); - for (::std::size_t i(block_size - 1); i >= block_size - remaining_length; --i) + for (::std::size_t i(block_size - static_cast<::std::size_t>(1u)); i >= block_size - remaining_length; --i) { text[i] = pad; } diff --git a/include/fast_io_crypto/platforms/nt_bcrypt.h b/include/fast_io_crypto/platforms/nt_bcrypt.h index c31afc37d..a24dc785f 100644 --- a/include/fast_io_crypto/platforms/nt_bcrypt.h +++ b/include/fast_io_crypto/platforms/nt_bcrypt.h @@ -35,10 +35,11 @@ class nt_bcrypt_hash_file inline nt_bcrypt_hash_file &operator=(nt_bcrypt_hash_file const &) = delete; inline ~nt_bcrypt_hash_file() { - if (digest_buffer) + if (digest_buffer) [[likely]] { ::fast_io::details::deallocate_with_secure_clear(digest_buffer, bcrypt_size); } + digest_buffer = nullptr; if (this->hashHandle) { ::fast_io::win32::BCryptDestroyHash(this->hashHandle); diff --git a/include/fast_io_driver/install_path/argv0.h b/include/fast_io_driver/install_path/argv0.h index 73391a7fb..5bd457b17 100644 --- a/include/fast_io_driver/install_path/argv0.h +++ b/include/fast_io_driver/install_path/argv0.h @@ -124,4 +124,4 @@ inline ::fast_io::install_path get_module_install_path_from_argv0(char const *ar } // end else } -} // namespace uwvm::path +} // namespace fast_io::details diff --git a/include/fast_io_driver/install_path/argv0_null.h b/include/fast_io_driver/install_path/argv0_null.h index 8cca36f28..bbe0493c6 100644 --- a/include/fast_io_driver/install_path/argv0_null.h +++ b/include/fast_io_driver/install_path/argv0_null.h @@ -10,4 +10,4 @@ inline ::fast_io::install_path get_module_install_path_from_argv0([[maybe_unused { throw_win32_error(0); } -} // namespace uwvm::path +} // namespace fast_io::details diff --git a/include/fast_io_driver/install_path/linux.h b/include/fast_io_driver/install_path/linux.h index 708e76843..2fc1be12b 100644 --- a/include/fast_io_driver/install_path/linux.h +++ b/include/fast_io_driver/install_path/linux.h @@ -58,4 +58,4 @@ inline ::fast_io::install_path get_module_install_path() ret.module_name.erase(begin, curr); return ret; } -} // namespace uwvm::path +} // namespace fast_io::details diff --git a/include/fast_io_driver/install_path/nt.h b/include/fast_io_driver/install_path/nt.h index f3c0b2b4f..a583487ea 100644 --- a/include/fast_io_driver/install_path/nt.h +++ b/include/fast_io_driver/install_path/nt.h @@ -37,4 +37,4 @@ inline ::fast_io::install_path get_module_install_path() ret.module_name.erase(begin, curr); return ret; } -} // namespace uwvm::path +} // namespace fast_io::details diff --git a/include/fast_io_driver/install_path/null.h b/include/fast_io_driver/install_path/null.h index 9a0195ac9..f2809bb2a 100644 --- a/include/fast_io_driver/install_path/null.h +++ b/include/fast_io_driver/install_path/null.h @@ -1,6 +1,6 @@ #pragma once -namespace uwvm::path +namespace fast_io::details { #if __has_cpp_attribute(__gnu__::__cold__) [[__gnu__::__cold__]] @@ -13,4 +13,4 @@ inline void get_module_install_path() { throw_posix_error(); } -} // namespace uwvm::path +} // namespace fast_io::details diff --git a/include/fast_io_driver/install_path/win32_9xa.h b/include/fast_io_driver/install_path/win32_9xa.h index a9265be93..afbd11a09 100644 --- a/include/fast_io_driver/install_path/win32_9xa.h +++ b/include/fast_io_driver/install_path/win32_9xa.h @@ -39,4 +39,4 @@ inline ::fast_io::install_path get_module_install_path() ret.module_name.erase(begin, curr); return ret; } -} // namespace uwvm::path +} // namespace fast_io::details diff --git a/include/fast_io_driver/python/pyobject.h b/include/fast_io_driver/python/pyobject.h index 292068786..4be4b1343 100644 --- a/include/fast_io_driver/python/pyobject.h +++ b/include/fast_io_driver/python/pyobject.h @@ -80,7 +80,7 @@ inline PyObject *pyunicode_asencodedstring_model_impl(PyObject *self, char const inline PyObject *pyunicode_asencodedstring_impl(PyObject *self, char const *name, char const *value) noexcept { - if (self == nullptr) + if (self == nullptr) [[unlikely]] { return nullptr; } @@ -141,7 +141,7 @@ class pyobject_file : public pyobject_io_observer } pyobject_file &operator=(pyobject_file &&pob) noexcept { - if (__builtin_addressof(pob) == this) + if (__builtin_addressof(pob) == this) [[unlikely]] { return *this; } diff --git a/include/fast_io_dsal/impl/deque.h b/include/fast_io_dsal/impl/deque.h index 9568a4abc..b2c0753a9 100644 --- a/include/fast_io_dsal/impl/deque.h +++ b/include/fast_io_dsal/impl/deque.h @@ -285,6 +285,8 @@ inline constexpr void deque_destroy_controller(controllerblocktype *controllerpt ::std::size_t n{static_cast<::std::size_t>(controller.controller_after_ptr - controller.controller_start_ptr) * sizeof(void *)}; allocator::deallocate_n(controller.controller_start_ptr, n); } + + controller.controller_start_ptr = nullptr; } template diff --git a/include/fast_io_dsal/impl/forward_list.h b/include/fast_io_dsal/impl/forward_list.h index 254d87719..0ab50ef77 100644 --- a/include/fast_io_dsal/impl/forward_list.h +++ b/include/fast_io_dsal/impl/forward_list.h @@ -388,6 +388,7 @@ class forward_list else { typed_allocator_type::deallocate(ptr, 1); + ptr = nullptr; } } }; diff --git a/include/fast_io_freestanding_impl/io_buffer/io_buffer.h b/include/fast_io_freestanding_impl/io_buffer/io_buffer.h index 82035b4f7..7305b0146 100644 --- a/include/fast_io_freestanding_impl/io_buffer/io_buffer.h +++ b/include/fast_io_freestanding_impl/io_buffer/io_buffer.h @@ -123,6 +123,8 @@ class basic_io_buffer inline constexpr ~basic_io_buffer() { ::fast_io::details::destroy_basic_io_buffer(*this); + input_buffer = {}; + output_buffer = {}; } }; diff --git a/include/fast_io_freestanding_impl/scanners/line_scanner.h b/include/fast_io_freestanding_impl/scanners/line_scanner.h index 62e9e568e..689dd6e0a 100644 --- a/include/fast_io_freestanding_impl/scanners/line_scanner.h +++ b/include/fast_io_freestanding_impl/scanners/line_scanner.h @@ -33,11 +33,16 @@ struct basic_line_scanner_buffer this->curr_ptr = other.curr_ptr; this->end_ptr = other.end_ptr; other.end_ptr = other.curr_ptr = other.begin_ptr = nullptr; + return *this; } inline constexpr ~buffer_type() { ::fast_io::details::deallocate_iobuf_space( this->begin_ptr, static_cast<::std::size_t>(this->end_ptr - this->begin_ptr)); + + this->begin_ptr = nullptr; + this->curr_ptr = nullptr; + this->end_ptr = nullptr; } }; buffer_type buffer; @@ -81,6 +86,10 @@ inline constexpr void copy_to_next_line_buffer_internal_impl(basic_line_scanner_ { auto bg_ptr{buf.buffer.begin_ptr}; ::std::size_t const elements{static_cast<::std::size_t>(buf.buffer.curr_ptr - bg_ptr)}; + if (elements > SIZE_MAX - sz) [[unlikely]] + { + ::fast_io::fast_terminate(); + } ::std::size_t const elementswithnewbuff{elements + sz}; ::std::size_t const old_capacity{static_cast<::std::size_t>(buf.buffer.end_ptr - bg_ptr)}; constexpr ::std::size_t szmx{::std::numeric_limits<::std::size_t>::max() / sizeof(char_type)}; diff --git a/include/fast_io_hosted/api_encoding_converter/nt.h b/include/fast_io_hosted/api_encoding_converter/nt.h index e41aa4652..d55be15ae 100644 --- a/include/fast_io_hosted/api_encoding_converter/nt.h +++ b/include/fast_io_hosted/api_encoding_converter/nt.h @@ -67,6 +67,9 @@ struct basic_nt_api_encoding_converter ~basic_nt_api_encoding_converter() { details::deallocate_iobuf_space(buffer_data, buffer_capacity + 1); + + buffer_data = nullptr; + buffer_data_end = nullptr; } }; #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(__WINE__) diff --git a/include/fast_io_hosted/api_encoding_converter/posix.h b/include/fast_io_hosted/api_encoding_converter/posix.h index b4d27f7d9..8741c3b7c 100644 --- a/include/fast_io_hosted/api_encoding_converter/posix.h +++ b/include/fast_io_hosted/api_encoding_converter/posix.h @@ -63,6 +63,9 @@ struct basic_posix_api_encoding_converter ~basic_posix_api_encoding_converter() { details::deallocate_iobuf_space(buffer_data, buffer_capacity + 1); + + buffer_data = nullptr; + buffer_data_end = nullptr; } }; diff --git a/include/fast_io_hosted/filesystem/nt.h b/include/fast_io_hosted/filesystem/nt.h index 8654c7a06..547a21d75 100644 --- a/include/fast_io_hosted/filesystem/nt.h +++ b/include/fast_io_hosted/filesystem/nt.h @@ -47,10 +47,8 @@ struct nt_dirent_space_guard } inline ~nt_dirent_space_guard() { - if (ptr) - { - typed_generic_allocator_adapter::deallocate_n(ptr, 1); - } + typed_generic_allocator_adapter::deallocate_n(ptr, 1); + ptr = nullptr; } }; diff --git a/include/fast_io_hosted/io_file.h b/include/fast_io_hosted/io_file.h index 28942189e..496779a15 100644 --- a/include/fast_io_hosted/io_file.h +++ b/include/fast_io_hosted/io_file.h @@ -269,6 +269,7 @@ struct biobd_allocate_guard { using typedallocator = typed_generic_allocator_adapter; typedallocator::deallocate_n(ptr, 1); + ptr = nullptr; } }; @@ -330,6 +331,7 @@ class basic_general_io_file : public basic_general_io_io_observerhandle; + this->handle = nullptr; } }; diff --git a/include/fast_io_hosted/platforms/nt_mapping.h b/include/fast_io_hosted/platforms/nt_mapping.h index 7b82b11c2..77be2ddc5 100644 --- a/include/fast_io_hosted/platforms/nt_mapping.h +++ b/include/fast_io_hosted/platforms/nt_mapping.h @@ -239,6 +239,7 @@ class nt_family_memory_map_file if (this->address_begin) [[likely]] { void *current_process_handle{reinterpret_cast(static_cast<::std::ptrdiff_t>(-1))}; + // When destructuring, you shouldn't have to deal with return values like close. ::fast_io::win32::nt::nt_unmap_view_of_section(current_process_handle, this->address_begin); } @@ -252,10 +253,10 @@ class nt_family_memory_map_file if (this->address_begin) [[likely]] { void *current_process_handle{reinterpret_cast(static_cast<::std::ptrdiff_t>(-1))}; - auto ret{::fast_io::win32::nt::nt_unmap_view_of_section < family == ::fast_io::nt_family::zw > (current_process_handle, this->address_begin)}; + auto ret{::fast_io::win32::nt::nt_unmap_view_of_section(current_process_handle, this->address_begin)}; this->address_end = this->address_begin = nullptr; - if (ret) + if (ret) [[unlikely]] { throw_nt_error(ret); } @@ -266,6 +267,7 @@ class nt_family_memory_map_file if (this->address_begin) [[likely]] { void *current_process_handle{reinterpret_cast(static_cast<::std::ptrdiff_t>(-1))}; + // When destructuring, you shouldn't have to deal with return values like close. ::fast_io::win32::nt::nt_unmap_view_of_section(current_process_handle, this->address_begin); } 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 d6c310a31..13cca9416 100644 --- a/include/fast_io_hosted/process/ipc/win32/alpc_nt.h +++ b/include/fast_io_hosted/process/ipc/win32/alpc_nt.h @@ -109,11 +109,8 @@ struct nt_alpc_message_attribute_guard inline void close() { - if (message_attribute) - { - alpc_message_alloc::deallocate(message_attribute); - message_attribute = nullptr; - } + alpc_message_alloc::deallocate(message_attribute); + message_attribute = nullptr; } }; @@ -176,10 +173,8 @@ struct nt_alpc_handle FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE port_handle = other.port_handle; other.port_handle = nullptr; - if (message_attribute) - { - alpc_message_alloc::deallocate(message_attribute); - } + alpc_message_alloc::deallocate(message_attribute); + message_attribute = other.message_attribute; other.message_attribute = nullptr; @@ -219,11 +214,8 @@ struct nt_alpc_handle FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE port_handle = nullptr; } - if (message_attribute) - { - alpc_message_alloc::deallocate(message_attribute); - message_attribute = nullptr; - } + alpc_message_alloc::deallocate(message_attribute); + message_attribute = nullptr; view_begin = nullptr; @@ -262,11 +254,8 @@ struct nt_alpc_handle FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE port_handle = nullptr; } - if (message_attribute) - { - alpc_message_alloc::deallocate(message_attribute); - message_attribute = nullptr; - } + alpc_message_alloc::deallocate(message_attribute); + message_attribute = nullptr; view_begin = nullptr; @@ -297,11 +286,8 @@ struct nt_ipc_alpc_thread_local_heap_allocate_guard }; inline constexpr void clear() noexcept { - if (ptr) [[likely]] - { - alloc::deallocate(ptr); - ptr = nullptr; - } + alloc::deallocate(ptr); + ptr = nullptr; } }; diff --git a/include/fast_io_hosted/process/process/arg_env.h b/include/fast_io_hosted/process/process/arg_env.h index b01d9acf1..a2342d094 100644 --- a/include/fast_io_hosted/process/process/arg_env.h +++ b/include/fast_io_hosted/process/process/arg_env.h @@ -288,10 +288,7 @@ struct cstr_guard FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE return *this; } - if (cstr) - { - Alloc::deallocate(cstr); - } + Alloc::deallocate(cstr); ::std::size_t str_size{::fast_io::cstr_len(others.cstr)}; cstr = Alloc::allocate(str_size + 1); @@ -312,21 +309,16 @@ struct cstr_guard FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE return *this; } - if (cstr) - { - Alloc::deallocate(cstr); - } + Alloc::deallocate(cstr); + cstr = others.cstr; others.cstr = nullptr; } inline constexpr ~cstr_guard() { - if (cstr) - { - Alloc::deallocate(cstr); - cstr = nullptr; - } + Alloc::deallocate(cstr); + cstr = nullptr; } }; diff --git a/include/fast_io_hosted/process/process/nt.h b/include/fast_io_hosted/process/process/nt.h index 451860aa6..60358259c 100644 --- a/include/fast_io_hosted/process/process/nt.h +++ b/include/fast_io_hosted/process/process/nt.h @@ -75,11 +75,8 @@ struct nt_process_rtl_guard } inline constexpr void clear() noexcept { - if (rtl_up) [[likely]] - { - ::fast_io::win32::nt::RtlDestroyProcessParameters(rtl_up); - rtl_up = nullptr; - } + ::fast_io::win32::nt::RtlDestroyProcessParameters(rtl_up); + rtl_up = nullptr; } }; @@ -100,11 +97,8 @@ struct nt_process_thread_local_heap_allocate_guard }; inline constexpr void clear() noexcept { - if (ptr) [[likely]] - { - alloc::deallocate(ptr); - ptr = nullptr; - } + alloc::deallocate(ptr); + ptr = nullptr; } }; diff --git a/include/fast_io_hosted/process/process/temp_array_scoped.h b/include/fast_io_hosted/process/process/temp_array_scoped.h index 779f888e0..7645d068a 100644 --- a/include/fast_io_hosted/process/process/temp_array_scoped.h +++ b/include/fast_io_hosted/process/process/temp_array_scoped.h @@ -24,6 +24,7 @@ struct temp_array_scoped_ptr ~temp_array_scoped_ptr() { Alloc::deallocate(ptr); + ptr = nullptr; } inline constexpr T *release() noexcept { diff --git a/include/fast_io_hosted/timeutil/posix_timezone.h b/include/fast_io_hosted/timeutil/posix_timezone.h index cccb55f91..f1f37f1d1 100644 --- a/include/fast_io_hosted/timeutil/posix_timezone.h +++ b/include/fast_io_hosted/timeutil/posix_timezone.h @@ -34,6 +34,7 @@ struct posix_timezone_name { ::fast_io::typed_generic_allocator_adapter<::fast_io::generic_allocator_adapter<::fast_io::c_malloc_allocator>, char8_t>::deallocate(ptr); + ptr = nullptr; } }; diff --git a/include/fast_io_legacy_impl/c/impl.h b/include/fast_io_legacy_impl/c/impl.h index 0c6a1f63b..c0b5b4614 100644 --- a/include/fast_io_legacy_impl/c/impl.h +++ b/include/fast_io_legacy_impl/c/impl.h @@ -77,7 +77,7 @@ From microsoft's document. _fdopen only supports static_cast(open_mode::app) | static_cast(open_mode::text): case static_cast(open_mode::in) | static_cast(open_mode::app) | static_cast(open_mode::text): - return "\x77\x2b"; + return "\x61\x2b"; // binary support @@ -144,7 +144,7 @@ From microsoft's document. _fdopen only supports static_cast(open_mode::app) | static_cast(open_mode::text): case static_cast(open_mode::in) | static_cast(open_mode::app) | static_cast(open_mode::text): - return L"\x77\x2b"; + return L"\x61\x2b"; // binary support diff --git a/include/fast_io_legacy_impl/c/wincrt.h b/include/fast_io_legacy_impl/c/wincrt.h index 0cd88d702..db84770b7 100644 --- a/include/fast_io_legacy_impl/c/wincrt.h +++ b/include/fast_io_legacy_impl/c/wincrt.h @@ -213,8 +213,17 @@ inline void wincrt_fp_write_cold_impl(FILE *__restrict fp, char const *first, ch crt_iobuf *fpp{reinterpret_cast(fp)}; if (fpp->_base == nullptr) { + if (auto const fd{fpp->_file}; fd == ::fast_io::posix_stderr_number) + { + // https://github.com/huangqinjin/ucrt/blob/d6e817a4cc90f6f1fe54f8a0aa4af4fff0bb647d/stdio/_sftbuf.cpp#L34 + // Here, a buffer is forced to be added to stdout + ::fast_io::details::posix_write_bytes_impl(fd, reinterpret_cast<::std::byte const *>(first), reinterpret_cast<::std::byte const *>(last)); + } + else + { wincrt_fp_write_cold_malloc_case_impl(fp, first, diff); } + } else { wincrt_fp_write_cold_normal_case_impl(fp, first, diff); diff --git a/include/fast_io_unit/string_impl/concat.h b/include/fast_io_unit/string_impl/concat.h index 774efcffe..855d95a36 100644 --- a/include/fast_io_unit/string_impl/concat.h +++ b/include/fast_io_unit/string_impl/concat.h @@ -136,7 +136,7 @@ template } else { - static_assert(type_error, "some types are not printable, so we cannot concatln ::std::wstring"); + static_assert(type_error, "some types are not printable, so we cannot concatln ::std::string"); return {}; } } From a0995dcb92b9e13179308469204c9bf4025e28a1 Mon Sep 17 00:00:00 2001 From: MacroModel Date: Wed, 25 Jun 2025 05:01:31 +0800 Subject: [PATCH 2/7] fix --- include/fast_io_core_impl/allocation/adapters.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/fast_io_core_impl/allocation/adapters.h b/include/fast_io_core_impl/allocation/adapters.h index 4aee0f405..d4e9b36fb 100644 --- a/include/fast_io_core_impl/allocation/adapters.h +++ b/include/fast_io_core_impl/allocation/adapters.h @@ -286,13 +286,13 @@ class generic_allocator_adapter { return allocator_type::reallocate_at_least(p, n).ptr; } - else if constexpr (::fast_io::details::has_reallocate_aligned_impl) + else if constexpr (::fast_io::details::has_reallocate_aligned_n_impl) { - return allocator_type::reallocate_aligned(p, default_alignment, n); + return allocator_type::reallocate_aligned_n(p, oldn, default_alignment, n); } - else if constexpr (::fast_io::details::has_reallocate_aligned_at_least_impl) + else if constexpr (::fast_io::details::has_reallocate_aligned_n_at_least_impl) { - return allocator_type::reallocate_aligned_at_least(p, oldn, default_alignment, n).ptr; + return allocator_type::reallocate_aligned_n_at_least(p, oldn, default_alignment, n).ptr; } else if constexpr (::fast_io::details::has_reallocate_zero_impl) { From 060b0ada1498be7780aaef6c0fb9ef538851269b Mon Sep 17 00:00:00 2001 From: MacroModel Date: Wed, 25 Jun 2025 05:06:22 +0800 Subject: [PATCH 3/7] f --- include/fast_io_hosted/process/process/nt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fast_io_hosted/process/process/nt.h b/include/fast_io_hosted/process/process/nt.h index 60358259c..cec2698ba 100644 --- a/include/fast_io_hosted/process/process/nt.h +++ b/include/fast_io_hosted/process/process/nt.h @@ -69,11 +69,11 @@ struct nt_process_rtl_guard : rtl_up{r} {}; nt_process_rtl_guard(nt_process_rtl_guard const &) = delete; nt_process_rtl_guard &operator=(nt_process_rtl_guard const &) = delete; - inline constexpr ~nt_process_rtl_guard() + inline ~nt_process_rtl_guard() { clear(); } - inline constexpr void clear() noexcept + inline void clear() noexcept { ::fast_io::win32::nt::RtlDestroyProcessParameters(rtl_up); rtl_up = nullptr; From f31cfbff36c60470a7c9c3cc11855d2c072ef3ad Mon Sep 17 00:00:00 2001 From: MacroModel Date: Wed, 25 Jun 2025 13:14:46 +0800 Subject: [PATCH 4/7] fix --- include/fast_io_core_impl/bitops/rtz.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fast_io_core_impl/bitops/rtz.h b/include/fast_io_core_impl/bitops/rtz.h index ad59bc9e9..5f8fe3757 100644 --- a/include/fast_io_core_impl/bitops/rtz.h +++ b/include/fast_io_core_impl/bitops/rtz.h @@ -118,7 +118,7 @@ inline constexpr ::fast_io::bitops::rtz_result rtz_impl(T n) noexcept s += b; n = b ? r : n; - /// @todo error? + // c1 == d1 == 42949673u constexpr ::std::uint_least32_t d1{42949673u}; r = ::std::rotr(static_cast(n * d1), 2); b = r < d1; @@ -202,4 +202,4 @@ inline constexpr ::fast_io::bitops::rtz_result rtz(T n) noexcept return ::fast_io::bitops::details::rtz_impl(n); } -} // namespace fast_io::bitops \ No newline at end of file +} // namespace fast_io::bitops From 557263cf832be8ed75d96b142833cd180f3fd219 Mon Sep 17 00:00:00 2001 From: MacroModel Date: Wed, 25 Jun 2025 16:34:53 +0800 Subject: [PATCH 5/7] fix --- include/fast_io_core_impl/bitops/rtz.h | 2 +- include/fast_io_core_impl/codecvt/general.h | 1 + .../fast_io_core_impl/dynamic_output_buffer.h | 3 +-- include/fast_io_crypto/platforms/nt_bcrypt.h | 7 +++--- include/fast_io_driver/mangling.h | 2 ++ .../io_buffer/io_buffer.h | 2 -- .../scanners/line_scanner.h | 4 ---- include/fast_io_hosted/async_coro.h | 8 +++---- include/fast_io_hosted/auto_indent.h | 6 ++--- include/fast_io_hosted/dbg/nt_dbg.h | 12 ++++++++-- include/fast_io_hosted/dll/win32.h | 2 ++ .../file_loaders/allocation_file_loader.h | 7 ++++++ include/fast_io_hosted/filesystem/nt.h | 3 +-- include/fast_io_hosted/filesystem/posix.h | 2 +- include/fast_io_hosted/io_file.h | 6 ++--- .../fast_io_hosted/mmap/allocation_options.h | 8 +++---- include/fast_io_hosted/mmap/posix_options.h | 4 +++- include/fast_io_hosted/mmap/win32_options.h | 3 ++- .../fast_io_hosted/platforms/linux/aarch64.h | 16 ++++++------- .../fast_io_hosted/platforms/linux/amd64.h | 18 +++++++------- include/fast_io_hosted/platforms/nt/nt_api.h | 8 +++---- include/fast_io_hosted/platforms/nt/nt_path.h | 10 -------- include/fast_io_hosted/platforms/nt/nt_zw.h | 24 +++++++++---------- .../fast_io_hosted/platforms/posix/common.h | 4 ++-- include/fast_io_hosted/platforms/posix/seek.h | 6 ++--- .../fast_io_hosted/platforms/posix_mapping.h | 2 +- include/fast_io_hosted/platforms/win32.h | 4 ---- include/fast_io_hosted/platforms/win32/apis.h | 6 ++--- .../platforms/win32/msvc_linker_32.h | 6 ++--- .../platforms/win32/msvc_linker_32_i686.h | 6 ++--- .../platforms/win32/msvc_linker_64.h | 6 ++--- .../platforms/win32/msvc_linker_arm64ec.h | 20 ++++++++-------- .../fast_io_hosted/platforms/win32_mapping.h | 2 +- .../platforms/win32_network/socket_file.h | 10 ++++++++ .../platforms/win32_network/win32_9xa_dns.h | 2 +- .../process/ipc/win32/alpc_nt.h | 2 -- .../process/ipc/win32/named_pipe_win32.h | 2 -- .../fast_io_hosted/process/process/arg_env.h | 1 - include/fast_io_hosted/process/process/nt.h | 3 --- .../fast_io_hosted/process/process/posix.h | 1 - .../fast_io_hosted/process/process/win32.h | 5 +--- .../fast_io_hosted/timeutil/posix_timezone.h | 7 +++--- include/fast_io_hosted/timeutil/time.h | 6 ++--- .../white_hole/bsd_arc4random.h | 16 ++++++++++++- .../white_hole/linux_getrandom.h | 4 ++-- .../white_hole/rtl_gen_random.h | 2 +- .../white_hole/wasi_random_get.h | 2 +- .../fast_io_hosted/white_hole/white_hole.h | 10 ++++---- .../white_hole/win32_crypt_gen_random.h | 3 ++- .../filebuf/fp_hack/common.h | 5 +--- 50 files changed, 154 insertions(+), 147 deletions(-) diff --git a/include/fast_io_core_impl/bitops/rtz.h b/include/fast_io_core_impl/bitops/rtz.h index 5f8fe3757..51c5fbec5 100644 --- a/include/fast_io_core_impl/bitops/rtz.h +++ b/include/fast_io_core_impl/bitops/rtz.h @@ -202,4 +202,4 @@ inline constexpr ::fast_io::bitops::rtz_result rtz(T n) noexcept return ::fast_io::bitops::details::rtz_impl(n); } -} // namespace fast_io::bitops +} // namespace fast_io::bitops \ No newline at end of file diff --git a/include/fast_io_core_impl/codecvt/general.h b/include/fast_io_core_impl/codecvt/general.h index 575df15e5..20ae86048 100644 --- a/include/fast_io_core_impl/codecvt/general.h +++ b/include/fast_io_core_impl/codecvt/general.h @@ -518,6 +518,7 @@ template (src_encoding); diff --git a/include/fast_io_core_impl/dynamic_output_buffer.h b/include/fast_io_core_impl/dynamic_output_buffer.h index 356557d2a..c35d5a263 100644 --- a/include/fast_io_core_impl/dynamic_output_buffer.h +++ b/include/fast_io_core_impl/dynamic_output_buffer.h @@ -19,7 +19,7 @@ class basic_generic_dynamic_output_buffer inline constexpr ~basic_generic_dynamic_output_buffer() { - if (begin_ptr && begin_ptr != buffer) + if (begin_ptr != buffer) { using typed_allocator = typed_generic_allocator_adapter; if constexpr (typed_allocator::has_deallocate) @@ -30,7 +30,6 @@ class basic_generic_dynamic_output_buffer { typed_allocator::deallocate_n(begin_ptr, buffer_size); } - begin_ptr = nullptr; } } }; diff --git a/include/fast_io_crypto/platforms/nt_bcrypt.h b/include/fast_io_crypto/platforms/nt_bcrypt.h index a24dc785f..0f2278c46 100644 --- a/include/fast_io_crypto/platforms/nt_bcrypt.h +++ b/include/fast_io_crypto/platforms/nt_bcrypt.h @@ -39,12 +39,11 @@ class nt_bcrypt_hash_file { ::fast_io::details::deallocate_with_secure_clear(digest_buffer, bcrypt_size); } - digest_buffer = nullptr; - if (this->hashHandle) + if (this->hashHandle) [[likely]] { ::fast_io::win32::BCryptDestroyHash(this->hashHandle); } - if (this->phAlgorithm) + if (this->phAlgorithm) [[likely]] { ::fast_io::win32::BCryptCloseAlgorithmProvider(this->phAlgorithm, 0u); } @@ -82,7 +81,7 @@ struct bcrypt_algo_guard inline bcrypt_algo_guard &operator=(bcrypt_algo_guard const &) = delete; inline ~bcrypt_algo_guard() { - if (this->phalgo) + if (this->phalgo) [[likely]] { ::fast_io::win32::BCryptCloseAlgorithmProvider(this->phalgo, 0u); } diff --git a/include/fast_io_driver/mangling.h b/include/fast_io_driver/mangling.h index aafff09cb..749b543c6 100644 --- a/include/fast_io_driver/mangling.h +++ b/include/fast_io_driver/mangling.h @@ -89,6 +89,8 @@ struct cxa_demangle ~cxa_demangle() { free(buffer); + buffer = nullptr; + length = static_cast<::std::size_t>(0u); } }; diff --git a/include/fast_io_freestanding_impl/io_buffer/io_buffer.h b/include/fast_io_freestanding_impl/io_buffer/io_buffer.h index 7305b0146..82035b4f7 100644 --- a/include/fast_io_freestanding_impl/io_buffer/io_buffer.h +++ b/include/fast_io_freestanding_impl/io_buffer/io_buffer.h @@ -123,8 +123,6 @@ class basic_io_buffer inline constexpr ~basic_io_buffer() { ::fast_io::details::destroy_basic_io_buffer(*this); - input_buffer = {}; - output_buffer = {}; } }; diff --git a/include/fast_io_freestanding_impl/scanners/line_scanner.h b/include/fast_io_freestanding_impl/scanners/line_scanner.h index 689dd6e0a..3a23bcb7e 100644 --- a/include/fast_io_freestanding_impl/scanners/line_scanner.h +++ b/include/fast_io_freestanding_impl/scanners/line_scanner.h @@ -39,10 +39,6 @@ struct basic_line_scanner_buffer { ::fast_io::details::deallocate_iobuf_space( this->begin_ptr, static_cast<::std::size_t>(this->end_ptr - this->begin_ptr)); - - this->begin_ptr = nullptr; - this->curr_ptr = nullptr; - this->end_ptr = nullptr; } }; buffer_type buffer; diff --git a/include/fast_io_hosted/async_coro.h b/include/fast_io_hosted/async_coro.h index 1dda14730..076985228 100644 --- a/include/fast_io_hosted/async_coro.h +++ b/include/fast_io_hosted/async_coro.h @@ -65,11 +65,11 @@ class async_io_coroutine }); if constexpr (write) { - async_read_callback(scheduler, stream, first, last, overlapped, offset); + async_write_callback(scheduler, stream, first, last, overlapped, offset); } else { - async_write_callback(scheduler, stream, first, last, overlapped, offset); + async_read_callback(scheduler, stream, first, last, overlapped, offset); } } }; @@ -108,11 +108,11 @@ class async_scatter_io_coroutine }); if constexpr (write) { - async_scatter_read_callback(scheduler, stream, scatters, overlapped, offset); + async_scatter_write_callback(scheduler, stream, scatters, overlapped, offset); } else { - async_scatter_write_callback(scheduler, stream, scatters, overlapped, offset); + async_scatter_read_callback(scheduler, stream, scatters, overlapped, offset); } } }; diff --git a/include/fast_io_hosted/auto_indent.h b/include/fast_io_hosted/auto_indent.h index 822d3ab72..517a4b50b 100644 --- a/include/fast_io_hosted/auto_indent.h +++ b/include/fast_io_hosted/auto_indent.h @@ -4,18 +4,18 @@ namespace fast_io { template <::std::ranges::contiguous_range rg, - typename containe = ::fast_io::containers::vector<::std::size_t, ::fast_io::native_thread_local_allocator>> + typename container = ::fast_io::containers::vector<::std::size_t, ::fast_io::native_thread_local_allocator>> requires ::std::integral<::std::ranges::range_value_t> inline constexpr auto auto_indent(rg &&r) { if constexpr (::std::is_array_v<::std::remove_cvref_t>) { - return ::fast_io::details::calculate_auto_width_result( + return ::fast_io::details::calculate_auto_width_result( ::std::ranges::data(r), ::std::ranges::data(r) + (::std::ranges::size(r) - 1)); } else { - return ::fast_io::details::calculate_auto_width_result( + return ::fast_io::details::calculate_auto_width_result( ::std::ranges::data(r), ::std::ranges::data(r) + ::std::ranges::size(r)); } } diff --git a/include/fast_io_hosted/dbg/nt_dbg.h b/include/fast_io_hosted/dbg/nt_dbg.h index fc8f10dbd..75d26885e 100644 --- a/include/fast_io_hosted/dbg/nt_dbg.h +++ b/include/fast_io_hosted/dbg/nt_dbg.h @@ -34,12 +34,12 @@ inline constexpr ::std::size_t calculate_nt_dbg_fmt_string_size() noexcept { if constexpr (iswide) { - static_assert((SIZE_MAX - 1 / 3) > n); + static_assert(((SIZE_MAX - 1) / 3) > n); return 3 * n + 1; //%wZ } else { - static_assert((SIZE_MAX - 1 / 2) > n); + static_assert(((SIZE_MAX - 1) / 2) > n); return 2 * n + 1; //%Z } } @@ -94,9 +94,13 @@ inline void nt_fmt_dbg_forward([[maybe_unused]] nt_dbg_carrier carr, char8_t con --arg; void const *arg_n_ptr{arg->base}; ::std::size_t arg_n_len{arg->len}; + /// @todo In the Windows NT debugging implementation, string lengths are silently truncated and UINT_LEAST16_MAX does not issue any error indications or warnings to the caller, which may result in incomplete debugging output. if (UINT_LEAST16_MAX < arg_n_len) { + ::fast_io::fast_terminate(); +#if 0 arg_n_len = UINT_LEAST16_MAX; +#endif } ::std::uint_least16_t const u16argnlen{static_cast<::std::uint_least16_t>(arg_n_len)}; ::fast_io::win32::nt::ansi_string astr{u16argnlen, u16argnlen, @@ -112,9 +116,13 @@ template inline void nt_dbg_write_impl([[maybe_unused]] nt_dbg_carrier carr, char const *first, char const *last) noexcept { ::std::size_t arg_n_len{static_cast<::std::size_t>(last - first)}; + /// @todo In the Windows NT debugging implementation, string lengths are silently truncated and UINT_LEAST16_MAX does not issue any error indications or warnings to the caller, which may result in incomplete debugging output. if (UINT_LEAST16_MAX < arg_n_len) { + ::fast_io::fast_terminate(); +#if 0 arg_n_len = UINT_LEAST16_MAX; +#endif } ::std::uint_least16_t const u16argnlen{static_cast<::std::uint_least16_t>(arg_n_len)}; ::fast_io::win32::nt::ansi_string astr{u16argnlen, u16argnlen, const_cast(first)}; diff --git a/include/fast_io_hosted/dll/win32.h b/include/fast_io_hosted/dll/win32.h index 866d5f62e..b7049c056 100644 --- a/include/fast_io_hosted/dll/win32.h +++ b/include/fast_io_hosted/dll/win32.h @@ -249,6 +249,7 @@ struct is_zero_default_constructible> template inline void *dll_load_symbol(win32_family_dll_io_observer pdliob, T const &symbol) { + /// @todo Exported symbol names need to be matched and not transcoded return ::fast_io::posix_api_common(symbol, ::fast_io::details::win32_dll_load_impl_context{pdliob.hmodule}); } @@ -256,6 +257,7 @@ template pdliob, T const &symbol, [[maybe_unused]] T1 const &) { + /// @todo Exported symbol names need to be matched and not transcoded return ::fast_io::posix_api_common(symbol, ::fast_io::details::win32_dll_load_impl_context{pdliob.hmodule}); } diff --git a/include/fast_io_hosted/file_loaders/allocation_file_loader.h b/include/fast_io_hosted/file_loaders/allocation_file_loader.h index 253224245..0f9912c06 100644 --- a/include/fast_io_hosted/file_loaders/allocation_file_loader.h +++ b/include/fast_io_hosted/file_loaders/allocation_file_loader.h @@ -294,6 +294,13 @@ class allocation_file_loader } inline allocation_file_loader &operator=(allocation_file_loader &&__restrict other) noexcept { + if (__builtin_addressof(other) == this) [[unlikely]] + { + return *this; + } + + ::fast_io::details::close_allocation_file_loader_impl(fd, address_begin, address_end); + // There is no need to check the 'this' pointer as there are no side effects address_begin = other.address_begin; address_end = other.address_end; diff --git a/include/fast_io_hosted/filesystem/nt.h b/include/fast_io_hosted/filesystem/nt.h index 547a21d75..2b75369d3 100644 --- a/include/fast_io_hosted/filesystem/nt.h +++ b/include/fast_io_hosted/filesystem/nt.h @@ -22,7 +22,7 @@ struct nt_dirent void *d_handle{}; file_type d_type{}; ::std::uint_least64_t d_ino{}; - char16_t native_d_name[0x2001]; + char16_t native_d_name[0x2001]; // max ntfs filename length ::std::size_t native_d_namlen{}; char8_t u8d_name[0x8004]; ::std::size_t u8d_namlen{}; @@ -48,7 +48,6 @@ struct nt_dirent_space_guard inline ~nt_dirent_space_guard() { typed_generic_allocator_adapter::deallocate_n(ptr, 1); - ptr = nullptr; } }; diff --git a/include/fast_io_hosted/filesystem/posix.h b/include/fast_io_hosted/filesystem/posix.h index 319be7862..19776fad0 100644 --- a/include/fast_io_hosted/filesystem/posix.h +++ b/include/fast_io_hosted/filesystem/posix.h @@ -309,7 +309,7 @@ inline posix_directory_iterator &operator++(posix_directory_iterator &pdit) /* To fix: avoid setting errno */ - errno = 0; + errno = 0; // [tls] auto entry{readdir(pdit.dirp)}; auto en{errno}; if (entry == nullptr && en) diff --git a/include/fast_io_hosted/io_file.h b/include/fast_io_hosted/io_file.h index 496779a15..d6d8d7015 100644 --- a/include/fast_io_hosted/io_file.h +++ b/include/fast_io_hosted/io_file.h @@ -115,7 +115,7 @@ class basic_io_io_derived : public basic_io_io_base ::fast_io::operations::decay::defines::writable) { return ::fast_io::operations::decay::scatter_write_some_decay( - ::fast_io::operations::input_stream_ref(value), base, n); + ::fast_io::operations::output_stream_ref(value), base, n); } else { @@ -138,7 +138,7 @@ class basic_io_io_derived : public basic_io_io_base ::fast_io::operations::decay::defines::pwritable) { return ::fast_io::operations::decay::scatter_pwrite_some_decay( - ::fast_io::operations::input_stream_ref(value), base, n, off); + ::fast_io::operations::output_stream_ref(value), base, n, off); } else { @@ -269,7 +269,6 @@ struct biobd_allocate_guard { using typedallocator = typed_generic_allocator_adapter; typedallocator::deallocate_n(ptr, 1); - ptr = nullptr; } }; @@ -331,7 +330,6 @@ class basic_general_io_file : public basic_general_io_io_observerhandle; - this->handle = nullptr; } }; diff --git a/include/fast_io_hosted/mmap/allocation_options.h b/include/fast_io_hosted/mmap/allocation_options.h index 9bdea8ceb..80a4b44e9 100644 --- a/include/fast_io_hosted/mmap/allocation_options.h +++ b/include/fast_io_hosted/mmap/allocation_options.h @@ -9,12 +9,12 @@ struct allocation_mmap_options inline explicit constexpr allocation_mmap_options() noexcept = default; inline constexpr allocation_mmap_options(::fast_io::mmap_prot, ::fast_io::mmap_flags flagsv) noexcept { - int exclusiveflags{static_cast(flagsv & ::fast_io::mmap_flags::map_type)}; - if (exclusiveflags == 3) + ::std::uint_least32_t exclusiveflags{static_cast<::std::uint_least32_t>(flagsv & ::fast_io::mmap_flags::map_type)}; + if (exclusiveflags == 3u) { - exclusiveflags = 1; + exclusiveflags = 1u; } - if (exclusiveflags == 1) + if (exclusiveflags == 1u) { this->write_back = true; } diff --git a/include/fast_io_hosted/mmap/posix_options.h b/include/fast_io_hosted/mmap/posix_options.h index 22cd0cdca..7c2d16eaf 100644 --- a/include/fast_io_hosted/mmap/posix_options.h +++ b/include/fast_io_hosted/mmap/posix_options.h @@ -21,7 +21,9 @@ struct posix_mmap_options { if ((flagsv & ::fast_io::mmap_flags::map_uninitialized) == ::fast_io::mmap_flags::map_uninitialized) { - flags -= 0x4000000; + // 0x4000000u on pdp11 is ul, on pdp11 mask is all poped + constexpr unsigned mask{~static_cast(0x4000000u)}; + flags = staic_cast(staic_cast(flags) & mask); } } #endif diff --git a/include/fast_io_hosted/mmap/win32_options.h b/include/fast_io_hosted/mmap/win32_options.h index d7c516253..9833d1d2d 100644 --- a/include/fast_io_hosted/mmap/win32_options.h +++ b/include/fast_io_hosted/mmap/win32_options.h @@ -82,7 +82,7 @@ struct win32_mmap_options if ((protv & ::fast_io::mmap_prot::prot_read) == ::fast_io::mmap_prot::prot_read && (protv & ::fast_io::mmap_prot::prot_write) == ::fast_io::mmap_prot::prot_write) { - dwDesiredAccesstemp |= 0x00000004 /*FILE_MAP_ALL_ACCESS*/; + dwDesiredAccesstemp |= 0x000F001F /*FILE_MAP_ALL_ACCESS*/; } else { @@ -95,6 +95,7 @@ struct win32_mmap_options dwDesiredAccesstemp |= 0x00000004 /*FILE_MAP_READ*/; } } + if ((flagsv & ::fast_io::mmap_flags::map_hugetlb) == ::fast_io::mmap_flags::map_hugetlb) { flprotecttemp |= 0x80000000; diff --git a/include/fast_io_hosted/platforms/linux/aarch64.h b/include/fast_io_hosted/platforms/linux/aarch64.h index 134f65ba9..f2458f5ca 100644 --- a/include/fast_io_hosted/platforms/linux/aarch64.h +++ b/include/fast_io_hosted/platforms/linux/aarch64.h @@ -3,7 +3,7 @@ namespace fast_io { -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call() noexcept { @@ -13,7 +13,7 @@ inline return_value_type system_call() noexcept return static_cast(x0); } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1) noexcept { @@ -23,7 +23,7 @@ inline return_value_type system_call(auto p1) noexcept return static_cast(x0); } -template <::std::size_t syscall_number> +template <::std::uint_least64_t syscall_number> inline void system_call_no_return(auto p1) noexcept { register ::std::uint_least64_t x8 __asm__("x8") = syscall_number; @@ -32,7 +32,7 @@ inline void system_call_no_return(auto p1) noexcept __builtin_unreachable(); } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2) noexcept { @@ -43,7 +43,7 @@ inline return_value_type system_call(auto p1, auto p2) noexcept return static_cast(x0); } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2, auto p3) noexcept { @@ -55,7 +55,7 @@ inline return_value_type system_call(auto p1, auto p2, auto p3) noexcept return static_cast(x0); } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4) noexcept { @@ -68,7 +68,7 @@ inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4) noexcep return static_cast(x0); } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5) noexcept { @@ -82,7 +82,7 @@ inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5 return static_cast(x0); } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5, auto p6) noexcept { diff --git a/include/fast_io_hosted/platforms/linux/amd64.h b/include/fast_io_hosted/platforms/linux/amd64.h index c20773390..5994ab9d0 100644 --- a/include/fast_io_hosted/platforms/linux/amd64.h +++ b/include/fast_io_hosted/platforms/linux/amd64.h @@ -4,7 +4,7 @@ namespace fast_io { -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call() noexcept { @@ -17,7 +17,7 @@ inline return_value_type system_call() noexcept return ret; } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1) noexcept { @@ -30,10 +30,10 @@ inline return_value_type system_call(auto p1) noexcept return ret; } -template <::std::size_t syscall_number> +template <::std::uint_least64_t syscall_number> inline void system_call_no_return(auto p1) noexcept { - ::std::size_t ret; + ::std::uint_least64_t ret; __asm__ __volatile__("syscall" : "=a"(ret) // EDI RSI RDX @@ -42,7 +42,7 @@ inline void system_call_no_return(auto p1) noexcept __builtin_unreachable(); } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2) noexcept { @@ -55,7 +55,7 @@ inline return_value_type system_call(auto p1, auto p2) noexcept return ret; } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2, auto p3) noexcept { @@ -68,7 +68,7 @@ inline return_value_type system_call(auto p1, auto p2, auto p3) noexcept return ret; } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4) noexcept { @@ -82,7 +82,7 @@ inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4) noexcep return ret; } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5) noexcept { @@ -97,7 +97,7 @@ inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5 return ret; } -template <::std::size_t syscall_number, ::std::signed_integral return_value_type> +template <::std::uint_least64_t syscall_number, ::std::signed_integral return_value_type> requires(1 < sizeof(return_value_type)) inline return_value_type system_call(auto p1, auto p2, auto p3, auto p4, auto p5, auto p6) noexcept { diff --git a/include/fast_io_hosted/platforms/nt/nt_api.h b/include/fast_io_hosted/platforms/nt/nt_api.h index e647ff468..db64c1de3 100644 --- a/include/fast_io_hosted/platforms/nt/nt_api.h +++ b/include/fast_io_hosted/platforms/nt/nt_api.h @@ -16,8 +16,8 @@ FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtQueryInformationPro FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwQueryInformationProcess(void *__restrict, ::fast_io::win32::nt::process_information_class, void *, ::std::uint_least32_t, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(ZwQueryInformationProcess, 20); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtWriteFile(void *, void *, ::fast_io::win32::nt::pio_apc_routine, void *, ::fast_io::win32::nt::io_status_block *, void const *, ::std::uint_least32_t, ::std::int_least64_t *, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(NtWriteFile, 36); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwWriteFile(void *, void *, ::fast_io::win32::nt::pio_apc_routine, void *, ::fast_io::win32::nt::io_status_block *, void const *, ::std::uint_least32_t, ::std::int_least64_t *, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(ZwWriteFile, 36); -FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtReadFile(void *, void *, ::fast_io::win32::nt::pio_apc_routine, void *, ::fast_io::win32::nt::io_status_block *, void const *, ::std::uint_least32_t, ::std::int_least64_t *, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(NtReadFile, 36); -FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwReadFile(void *, void *, ::fast_io::win32::nt::pio_apc_routine, void *, ::fast_io::win32::nt::io_status_block *, void const *, ::std::uint_least32_t, ::std::int_least64_t *, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(ZwReadFile, 36); +FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtReadFile(void *, void *, ::fast_io::win32::nt::pio_apc_routine, void *, ::fast_io::win32::nt::io_status_block *, void *, ::std::uint_least32_t, ::std::int_least64_t *, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(NtReadFile, 36); +FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwReadFile(void *, void *, ::fast_io::win32::nt::pio_apc_routine, void *, ::fast_io::win32::nt::io_status_block *, void *, ::std::uint_least32_t, ::std::int_least64_t *, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(ZwReadFile, 36); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtQueryObject(void *, ::fast_io::win32::nt::object_information_class, void *, ::std::uint_least32_t, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(NtQueryObject, 20); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwQueryObject(void *, ::fast_io::win32::nt::object_information_class, void *, ::std::uint_least32_t, ::std::uint_least32_t *) noexcept FAST_IO_WINSTDCALL_RENAME(ZwQueryObject, 20); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtQueryDirectoryFile(void *, void *, ::fast_io::win32::nt::pio_apc_routine, void *, ::fast_io::win32::nt::io_status_block *, void *, ::std::uint_least32_t, ::fast_io::win32::nt::file_information_class, int, ::fast_io::win32::nt::unicode_string *, int) noexcept FAST_IO_WINSTDCALL_RENAME(NtQueryDirectoryFile, 44); @@ -84,8 +84,8 @@ FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwQuerySystemInformat FAST_IO_DLLIMPORT void FAST_IO_WINSTDCALL RtlAcquireSRWLockExclusive(void *) noexcept FAST_IO_WINSTDCALL_RENAME(RtlAcquireSRWLockExclusive, 4); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL RtlTryAcquireSRWLockExclusive(void *) noexcept FAST_IO_WINSTDCALL_RENAME(RtlTryAcquireSRWLockExclusive, 4); FAST_IO_DLLIMPORT void FAST_IO_WINSTDCALL RtlReleaseSRWLockExclusive(void *) noexcept FAST_IO_WINSTDCALL_RENAME(RtlReleaseSRWLockExclusive, 4); -FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtQueryVolumeInformationFile(void *__restrict, io_status_block *__restrict, void *__restrict, ::std::uint_least32_t, ::fast_io::win32::nt::fs_information_class) noexcept FAST_IO_WINSTDCALL_RENAME(NtQueryVolumeInformationFile, 20); -FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwQueryVolumeInformationFile(void *__restrict, io_status_block *__restrict, void *__restrict, ::std::uint_least32_t, ::fast_io::win32::nt::fs_information_class) noexcept FAST_IO_WINSTDCALL_RENAME(ZwQueryVolumeInformationFile, 20); +FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtQueryVolumeInformationFile(void *__restrict, ::fast_io::win32::nt::io_status_block *__restrict, void *__restrict, ::std::uint_least32_t, ::fast_io::win32::nt::fs_information_class) noexcept FAST_IO_WINSTDCALL_RENAME(NtQueryVolumeInformationFile, 20); +FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwQueryVolumeInformationFile(void *__restrict, ::fast_io::win32::nt::io_status_block *__restrict, void *__restrict, ::std::uint_least32_t, ::fast_io::win32::nt::fs_information_class) noexcept FAST_IO_WINSTDCALL_RENAME(ZwQueryVolumeInformationFile, 20); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtFsControlFile(void *__restrict, void *__restrict, ::fast_io::win32::nt::pio_apc_routine *__restrict, void *, ::fast_io::win32::nt::io_status_block *, ::std::uint_least32_t, void *, ::std::uint_least32_t, void *, ::std::uint_least32_t) noexcept FAST_IO_WINSTDCALL_RENAME(NtFsControlFile, 40); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL ZwFsControlFile(void *__restrict, void *__restrict, ::fast_io::win32::nt::pio_apc_routine *__restrict, void *, ::fast_io::win32::nt::io_status_block *, ::std::uint_least32_t, void *, ::std::uint_least32_t, void *, ::std::uint_least32_t) noexcept FAST_IO_WINSTDCALL_RENAME(ZwFsControlFile, 40); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL NtCreateNamedPipeFile(void **__restrict, ::std::uint_least32_t, ::fast_io::win32::nt::object_attributes *__restrict, ::fast_io::win32::nt::io_status_block *__restrict, ::std::uint_least32_t, ::std::uint_least32_t, ::std::uint_least32_t, ::std::uint_least32_t, ::std::uint_least32_t, ::std::uint_least32_t, ::std::uint_least32_t, ::std::uint_least32_t, ::std::uint_least32_t, ::std::int_least64_t *) noexcept FAST_IO_WINSTDCALL_RENAME(NtCreateNamedPipeFile, 56); diff --git a/include/fast_io_hosted/platforms/nt/nt_path.h b/include/fast_io_hosted/platforms/nt/nt_path.h index f7da26c71..4e8368885 100644 --- a/include/fast_io_hosted/platforms/nt/nt_path.h +++ b/include/fast_io_hosted/platforms/nt/nt_path.h @@ -4,11 +4,6 @@ namespace fast_io::win32::nt::details { inline ::std::uint_least16_t nt_filename_bytes_check(::std::size_t bytes) { - if constexpr (sizeof(bytes) < sizeof(::std::uint_least16_t)) // sizeof(::std::size_t) can never be smaller than - // sizeof(::std::uint_least16_t) - { - return static_cast<::std::uint_least16_t>(bytes); - } constexpr ::std::size_t max_value{static_cast<::std::size_t>(::std::numeric_limits<::std::uint_least16_t>::max())}; if (max_value < bytes) { @@ -19,11 +14,6 @@ inline ::std::uint_least16_t nt_filename_bytes_check(::std::size_t bytes) inline ::std::uint_least16_t strlen_to_nt_filename_bytes(::std::size_t str_sz) { - if constexpr (sizeof(str_sz) < sizeof(::std::uint_least16_t)) // sizeof(::std::size_t) can never be smaller than - // sizeof(::std::uint_least16_t) - { - return static_cast<::std::uint_least16_t>(static_cast<::std::uint_least16_t>(str_sz) << 1u); - } constexpr ::std::size_t max_value{static_cast<::std::size_t>(::std::numeric_limits<::std::uint_least16_t>::max() >> 1u)}; if (max_value < str_sz) { diff --git a/include/fast_io_hosted/platforms/nt/nt_zw.h b/include/fast_io_hosted/platforms/nt/nt_zw.h index 88171e150..272ec9d20 100644 --- a/include/fast_io_hosted/platforms/nt/nt_zw.h +++ b/include/fast_io_hosted/platforms/nt/nt_zw.h @@ -204,11 +204,11 @@ inline ::std::uint_least32_t nt_create_process(Args... args) noexcept { if constexpr (zw) { - return ::fast_io::win32::nt::NtCreateProcess(args...); + return ::fast_io::win32::nt::ZwCreateProcess(args...); } else { - return ::fast_io::win32::nt::ZwCreateProcess(args...); + return ::fast_io::win32::nt::NtCreateProcess(args...); } } @@ -232,11 +232,11 @@ inline ::std::uint_least32_t nt_resume_thread(Args... args) noexcept { if constexpr (zw) { - return ZwResumeThread(args...); + return ::fast_io::win32::nt::ZwResumeThread(args...); } else { - return NtResumeThread(args...); + return ::fast_io::win32::nt::NtResumeThread(args...); } } @@ -246,11 +246,11 @@ inline ::std::uint_least32_t nt_lock_file(Args... args) noexcept { if constexpr (zw) { - return ZwLockFile(args...); + return ::fast_io::win32::nt::ZwLockFile(args...); } else { - return NtLockFile(args...); + return ::fast_io::win32::nt::NtLockFile(args...); } } @@ -260,11 +260,11 @@ inline ::std::uint_least32_t nt_unlock_file(Args... args) noexcept { if constexpr (zw) { - return ZwUnlockFile(args...); + return ::fast_io::win32::nt::ZwUnlockFile(args...); } else { - return NtUnlockFile(args...); + return ::fast_io::win32::nt::NtUnlockFile(args...); } } @@ -274,11 +274,11 @@ inline ::std::uint_least32_t nt_flush_buffers_file(Args... args) noexcept { if constexpr (zw) { - return ZwFlushBuffersFile(args...); + return ::fast_io::win32::nt::ZwFlushBuffersFile(args...); } else { - return NtFlushBuffersFile(args...); + return ::fast_io::win32::nt::NtFlushBuffersFile(args...); } } @@ -288,11 +288,11 @@ inline ::std::uint_least32_t nt_flush_buffers_file_ex(Args... args) noexcept { if constexpr (zw) { - return ZwFlushBuffersFileEx(args...); + return ::fast_io::win32::nt::ZwFlushBuffersFileEx(args...); } else { - return NtFlushBuffersFileEx(args...); + return ::fast_io::win32::nt::NtFlushBuffersFileEx(args...); } } diff --git a/include/fast_io_hosted/platforms/posix/common.h b/include/fast_io_hosted/platforms/posix/common.h index bc9880b2f..26af1e1e8 100644 --- a/include/fast_io_hosted/platforms/posix/common.h +++ b/include/fast_io_hosted/platforms/posix/common.h @@ -58,7 +58,7 @@ extern unsigned my_dos_write(int, void const *, unsigned, unsigned *) noexcept _ inline ::std::byte *posix_dos_read_bytes_impl(int fd, ::std::byte *first, ::std::byte *last) { unsigned ret; - if (::fast_io::details::my_dos_read(fd, first, ::fast_io::details::read_write_bytes_compute(first, last), __builtin_addressof(ret))) + if (my_dos_read(fd, first, ::fast_io::details::read_write_bytes_compute(first, last), __builtin_addressof(ret))) { throw_posix_error(); } @@ -68,7 +68,7 @@ inline ::std::byte *posix_dos_read_bytes_impl(int fd, ::std::byte *first, ::std: inline ::std::byte const *posix_dos_write_bytes_impl(int fd, ::std::byte const *first, ::std::byte const *last) { unsigned ret; - if (::fast_io::details::my_dos_write(fd, first, ::fast_io::details::read_write_bytes_compute(first, last), __builtin_addressof(ret))) + if (my_dos_write(fd, first, ::fast_io::details::read_write_bytes_compute(first, last), __builtin_addressof(ret))) { throw_posix_error(); } diff --git a/include/fast_io_hosted/platforms/posix/seek.h b/include/fast_io_hosted/platforms/posix/seek.h index b92e417fb..86f53801b 100644 --- a/include/fast_io_hosted/platforms/posix/seek.h +++ b/include/fast_io_hosted/platforms/posix/seek.h @@ -27,9 +27,9 @@ inline ::fast_io::intfpos_t posix_seek_impl(int fd, ::fast_io::intfpos_t offset, { ::std::uint_least64_t result{}; ::std::uint_least64_t offset64_val{ - static_cast<::std::uint_least64_t>(static_cast<::fast_io::intfpos_t>(offset))}; - auto ret{system_call<__NR_llseek, int>(fd, static_cast<::std::uint_least32_t>(offset >> 32u), - static_cast<::std::uint_least32_t>(offset), __builtin_addressof(result), + static_cast<::std::uint_least64_t>(offset)}; + auto ret{system_call<__NR_llseek, int>(fd, static_cast<::std::uint_least32_t>(offset64_val >> 32u), + static_cast<::std::uint_least32_t>(offset64_val), __builtin_addressof(result), static_cast(s))}; system_call_throw_error(ret); return static_cast<::fast_io::intfpos_t>(static_cast<::std::uint_least64_t>(result)); diff --git a/include/fast_io_hosted/platforms/posix_mapping.h b/include/fast_io_hosted/platforms/posix_mapping.h index f4bc48078..4f745a373 100644 --- a/include/fast_io_hosted/platforms/posix_mapping.h +++ b/include/fast_io_hosted/platforms/posix_mapping.h @@ -139,7 +139,7 @@ inline constexpr posix_file_map_attribute to_posix_file_map_attribute(file_map_a case file_map_attribute::execute_read: return posix_file_map_attribute::execute | posix_file_map_attribute::read; case file_map_attribute::execute_read_write: - return posix_file_map_attribute::execute | posix_file_map_attribute::read; + return posix_file_map_attribute::execute | posix_file_map_attribute::read | posix_file_map_attribute::write; case file_map_attribute::execute_write_copy: return posix_file_map_attribute::execute | posix_file_map_attribute::write; case file_map_attribute::read_only: diff --git a/include/fast_io_hosted/platforms/win32.h b/include/fast_io_hosted/platforms/win32.h index 2a1c4af9f..b77415065 100644 --- a/include/fast_io_hosted/platforms/win32.h +++ b/include/fast_io_hosted/platforms/win32.h @@ -905,7 +905,6 @@ struct win32_file_factory FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE if (handle) [[likely]] { ::fast_io::win32::CloseHandle(handle); - handle = nullptr; } } }; @@ -1513,7 +1512,6 @@ class basic_win32_family_file FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE : public if (*this) [[likely]] { ::fast_io::win32::CloseHandle(this->handle); - this->handle = nullptr; } } }; @@ -1543,7 +1541,6 @@ struct handle_guard if (h) [[likely]] { ::fast_io::win32::CloseHandle(h); - h = nullptr; } }; inline constexpr void clear() noexcept @@ -1569,7 +1566,6 @@ struct map_guard if (map) [[likely]] { ::fast_io::win32::UnmapViewOfFile(map); - map = nullptr; } }; inline constexpr void clear() noexcept diff --git a/include/fast_io_hosted/platforms/win32/apis.h b/include/fast_io_hosted/platforms/win32/apis.h index e13323a3e..194086e43 100644 --- a/include/fast_io_hosted/platforms/win32/apis.h +++ b/include/fast_io_hosted/platforms/win32/apis.h @@ -18,7 +18,7 @@ FAST_IO_DLLIMPORT void *FAST_IO_WINSTDCALL MapViewOfFile(void *, ::std::uint_lea FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL SetEndOfFile(void *) noexcept FAST_IO_WINSTDCALL_RENAME(SetEndOfFile, 4); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL UnmapViewOfFile(void const *) noexcept FAST_IO_WINSTDCALL_RENAME(UnmapViewOfFile, 4); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WriteFile(void *, void const *, ::std::uint_least32_t, ::std::uint_least32_t *, ::fast_io::win32::overlapped *) noexcept FAST_IO_WINSTDCALL_RENAME(WriteFile, 20); -FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL ReadFile(void *, void const *, ::std::uint_least32_t, ::std::uint_least32_t *, ::fast_io::win32::overlapped *) noexcept FAST_IO_WINSTDCALL_RENAME(ReadFile, 20); +FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL ReadFile(void *, void *, ::std::uint_least32_t, ::std::uint_least32_t *, ::fast_io::win32::overlapped *) noexcept FAST_IO_WINSTDCALL_RENAME(ReadFile, 20); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL SetFilePointer(void *, ::std::int_least32_t, ::std::int_least32_t *, ::std::uint_least32_t) noexcept FAST_IO_WINSTDCALL_RENAME(SetFilePointer, 16); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL SetFilePointerEx(void *, ::std::int_least64_t, ::std::int_least64_t *, ::std::uint_least32_t) noexcept FAST_IO_WINSTDCALL_RENAME(SetFilePointerEx, 20); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL DuplicateHandle(void *, void *, void *, void **, ::std::uint_least32_t, int, ::std::uint_least32_t) noexcept FAST_IO_WINSTDCALL_RENAME(DuplicateHandle, 28); @@ -74,7 +74,7 @@ FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL TryEnterCriticalSection(void *) noexcep FAST_IO_DLLIMPORT void FAST_IO_WINSTDCALL LeaveCriticalSection(void *) noexcept FAST_IO_WINSTDCALL_RENAME(LeaveCriticalSection, 4); FAST_IO_DLLIMPORT void FAST_IO_WINSTDCALL DeleteCriticalSection(void *) noexcept FAST_IO_WINSTDCALL_RENAME(DeleteCriticalSection, 4); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WSADuplicateSocketA(void *, ::std::uint_least32_t, ::fast_io::win32::wsaprotocol_infoa *) noexcept FAST_IO_WINSTDCALL_RENAME(WSADuplicateSocketA, 12); -FAST_IO_DLLIMPORT void FAST_IO_WINSTDCALL WSADuplicateSocketW(void *, ::std::uint_least32_t, ::fast_io::win32::wsaprotocol_infow *) noexcept FAST_IO_WINSTDCALL_RENAME(WSADuplicateSocketW, 12); +FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WSADuplicateSocketW(void *, ::std::uint_least32_t, ::fast_io::win32::wsaprotocol_infow *) noexcept FAST_IO_WINSTDCALL_RENAME(WSADuplicateSocketW, 12); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WSACleanup() noexcept FAST_IO_WINSTDCALL_RENAME(WSACleanup, 0); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WSAStartup(::std::uint_least32_t, ::fast_io::win32::wsadata *) noexcept FAST_IO_WINSTDCALL_RENAME(WSAStartup, 8); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WSAGetLastError() noexcept FAST_IO_WINSTDCALL_RENAME(WSAGetLastError, 0); @@ -95,7 +95,7 @@ FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WSARecv(::std::size_t, ::fast_io::win32 FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WSARecvFrom(::std::size_t, ::fast_io::win32::wsabuf *, ::std::uint_least32_t, ::std::uint_least32_t *, ::std::uint_least32_t *, void *, int *, ::fast_io::win32::overlapped *, ::fast_io::win32::lpwsaoverlapped_completion_routine) noexcept FAST_IO_WINSTDCALL_RENAME(WSARecvFrom, 36); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL connect(::std::size_t, void const *, int) noexcept FAST_IO_WINSTDCALL_RENAME(connect, 12); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL WSAConnect(::std::size_t, void const *, int, ::fast_io::win32::wsabuf *, ::fast_io::win32::wsabuf *, ::fast_io::win32::qualityofservice *, ::fast_io::win32::qualityofservice *) noexcept FAST_IO_WINSTDCALL_RENAME(WSAConnect, 28); -FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL shutdown(::std::size_t, void const *, int) noexcept FAST_IO_WINSTDCALL_RENAME(shutdown, 12); +FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL shutdown(::std::size_t, int) noexcept FAST_IO_WINSTDCALL_RENAME(shutdown, 8); FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL GetCurrentProcessId() noexcept FAST_IO_WINSTDCALL_RENAME(GetCurrentProcessId, 0); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL FlushFileBuffers(void *) noexcept FAST_IO_WINSTDCALL_RENAME(FlushFileBuffers, 4); FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL GetQueuedCompletionStatus(void *, ::std::uint_least32_t *, ::std::size_t *, ::fast_io::win32::overlapped *, ::std::uint_least32_t) noexcept FAST_IO_WINSTDCALL_RENAME(GetQueuedCompletionStatus, 20); diff --git a/include/fast_io_hosted/platforms/win32/msvc_linker_32.h b/include/fast_io_hosted/platforms/win32/msvc_linker_32.h index 477580d5e..ec35e783d 100644 --- a/include/fast_io_hosted/platforms/win32/msvc_linker_32.h +++ b/include/fast_io_hosted/platforms/win32/msvc_linker_32.h @@ -15,7 +15,7 @@ #pragma comment(linker,"/alternatename:__imp_?SetEndOfFile@win32@fast_io@@YAHPAX@Z=__imp_SetEndOfFile") #pragma comment(linker,"/alternatename:__imp_?UnmapViewOfFile@win32@fast_io@@YAHPBX@Z=__imp_UnmapViewOfFile") #pragma comment(linker,"/alternatename:__imp_?WriteFile@win32@fast_io@@YAHPAXPBXIPAIPAUoverlapped@12@@Z=__imp_WriteFile") -#pragma comment(linker,"/alternatename:__imp_?ReadFile@win32@fast_io@@YAHPAXPBXIPAIPAUoverlapped@12@@Z=__imp_ReadFile") +#pragma comment(linker,"/alternatename:__imp_?ReadFile@win32@fast_io@@YAHPAX0IPAIPAUoverlapped@12@@Z") #pragma comment(linker,"/alternatename:__imp_?SetFilePointer@win32@fast_io@@YAIPAXHPAHI@Z=__imp_SetFilePointer") #pragma comment(linker,"/alternatename:__imp_?SetFilePointerEx@win32@fast_io@@YAHPAX_JPA_JI@Z=__imp_SetFilePointerEx") #pragma comment(linker,"/alternatename:__imp_?DuplicateHandle@win32@fast_io@@YAHPAX00PAPAXIHI@Z=__imp_DuplicateHandle") @@ -177,8 +177,8 @@ #pragma comment(linker,"/alternatename:__imp_?ZwQueryInformationProcess@nt@win32@fast_io@@YAIPIAXW4process_information_class@123@PAXIPAI@Z=__imp_ZwQueryInformationProcess") #pragma comment(linker,"/alternatename:__imp_?NtWriteFile@nt@win32@fast_io@@YAIPAX0P6AX0PAUio_status_block@123@I@_E01PBXIPA_JPAI@Z=__imp_NtWriteFile") #pragma comment(linker,"/alternatename:__imp_?ZwWriteFile@nt@win32@fast_io@@YAIPAX0P6AX0PAUio_status_block@123@I@_E01PBXIPA_JPAI@Z=__imp_ZwWriteFile") -#pragma comment(linker,"/alternatename:__imp_?NtReadFile@nt@win32@fast_io@@YAIPAX0P6AX0PAUio_status_block@123@I@_E01PBXIPA_JPAI@Z=__imp_NtReadFile") -#pragma comment(linker,"/alternatename:__imp_?ZwReadFile@nt@win32@fast_io@@YAIPAX0P6AX0PAUio_status_block@123@I@_E01PBXIPA_JPAI@Z=__imp_ZwReadFile") +#pragma comment(linker,"/alternatename:__imp_?NtReadFile@nt@win32@fast_io@@YAIPAX0P6AX0PAUio_status_block@123@I@_E010IPA_JPAI@Z=__imp_NtReadFile") +#pragma comment(linker,"/alternatename:__imp_?ZwReadFile@nt@win32@fast_io@@YAIPAX0P6AX0PAUio_status_block@123@I@_E010IPA_JPAI@Z=__imp_ZwReadFile") #pragma comment(linker,"/alternatename:__imp_?NtQueryObject@nt@win32@fast_io@@YAIPAXW4object_information_class@123@0IPAI@Z=__imp_NtQueryObject") #pragma comment(linker,"/alternatename:__imp_?ZwQueryObject@nt@win32@fast_io@@YAIPAXW4object_information_class@123@0IPAI@Z=__imp_ZwQueryObject") #pragma comment(linker,"/alternatename:__imp_?NtQueryDirectoryFile@nt@win32@fast_io@@YAIPAX0P6AX0PAUio_status_block@123@I@_E010IW4file_information_class@123@HPAUunicode_string@123@H@Z=__imp_NtQueryDirectoryFile") diff --git a/include/fast_io_hosted/platforms/win32/msvc_linker_32_i686.h b/include/fast_io_hosted/platforms/win32/msvc_linker_32_i686.h index b32bfcb45..7359ccd70 100644 --- a/include/fast_io_hosted/platforms/win32/msvc_linker_32_i686.h +++ b/include/fast_io_hosted/platforms/win32/msvc_linker_32_i686.h @@ -15,7 +15,7 @@ #pragma comment(linker,"/alternatename:__imp_?SetEndOfFile@win32@fast_io@@YGHPAX@Z=__imp__SetEndOfFile@4") #pragma comment(linker,"/alternatename:__imp_?UnmapViewOfFile@win32@fast_io@@YGHPBX@Z=__imp__UnmapViewOfFile@4") #pragma comment(linker,"/alternatename:__imp_?WriteFile@win32@fast_io@@YGHPAXPBXIPAIPAUoverlapped@12@@Z=__imp__WriteFile@20") -#pragma comment(linker,"/alternatename:__imp_?ReadFile@win32@fast_io@@YGHPAXPBXIPAIPAUoverlapped@12@@Z=__imp__ReadFile@20") +#pragma comment(linker,"/alternatename:__imp_?ReadFile@win32@fast_io@@YGHPAX0IPAIPAUoverlapped@12@@Z=__imp__ReadFile@20") #pragma comment(linker,"/alternatename:__imp_?SetFilePointer@win32@fast_io@@YGIPAXHPAHI@Z=__imp__SetFilePointer@16") #pragma comment(linker,"/alternatename:__imp_?SetFilePointerEx@win32@fast_io@@YGHPAX_JPA_JI@Z=__imp__SetFilePointerEx@20") #pragma comment(linker,"/alternatename:__imp_?DuplicateHandle@win32@fast_io@@YGHPAX00PAPAXIHI@Z=__imp__DuplicateHandle@28") @@ -177,8 +177,8 @@ #pragma comment(linker,"/alternatename:__imp_?ZwQueryInformationProcess@nt@win32@fast_io@@YGIPIAXW4process_information_class@123@PAXIPAI@Z=__imp__ZwQueryInformationProcess@20") #pragma comment(linker,"/alternatename:__imp_?NtWriteFile@nt@win32@fast_io@@YGIPAX0P6AX0PAUio_status_block@123@I@_E01PBXIPA_JPAI@Z=__imp__NtWriteFile@36") #pragma comment(linker,"/alternatename:__imp_?ZwWriteFile@nt@win32@fast_io@@YGIPAX0P6AX0PAUio_status_block@123@I@_E01PBXIPA_JPAI@Z=__imp__ZwWriteFile@36") -#pragma comment(linker,"/alternatename:__imp_?NtReadFile@nt@win32@fast_io@@YGIPAX0P6AX0PAUio_status_block@123@I@_E01PBXIPA_JPAI@Z=__imp__NtReadFile@36") -#pragma comment(linker,"/alternatename:__imp_?ZwReadFile@nt@win32@fast_io@@YGIPAX0P6AX0PAUio_status_block@123@I@_E01PBXIPA_JPAI@Z=__imp__ZwReadFile@36") +#pragma comment(linker,"/alternatename:__imp_?NtReadFile@nt@win32@fast_io@@YGIPAX0P6AX0PAUio_status_block@123@I@_E010IPA_JPAI@Z=__imp__NtReadFile@36") +#pragma comment(linker,"/alternatename:__imp_?ZwReadFile@nt@win32@fast_io@@YGIPAX0P6AX0PAUio_status_block@123@I@_E010IPA_JPAI@Z=__imp__ZwReadFile@36") #pragma comment(linker,"/alternatename:__imp_?NtQueryObject@nt@win32@fast_io@@YGIPAXW4object_information_class@123@0IPAI@Z=__imp__NtQueryObject@20") #pragma comment(linker,"/alternatename:__imp_?ZwQueryObject@nt@win32@fast_io@@YGIPAXW4object_information_class@123@0IPAI@Z=__imp__ZwQueryObject@20") #pragma comment(linker,"/alternatename:__imp_?NtQueryDirectoryFile@nt@win32@fast_io@@YGIPAX0P6AX0PAUio_status_block@123@I@_E010IW4file_information_class@123@HPAUunicode_string@123@H@Z=__imp__NtQueryDirectoryFile@44") diff --git a/include/fast_io_hosted/platforms/win32/msvc_linker_64.h b/include/fast_io_hosted/platforms/win32/msvc_linker_64.h index 54bf9a05b..06e31714a 100644 --- a/include/fast_io_hosted/platforms/win32/msvc_linker_64.h +++ b/include/fast_io_hosted/platforms/win32/msvc_linker_64.h @@ -15,7 +15,7 @@ #pragma comment(linker,"/alternatename:__imp_?SetEndOfFile@win32@fast_io@@YAHPEAX@Z=__imp_SetEndOfFile") #pragma comment(linker,"/alternatename:__imp_?UnmapViewOfFile@win32@fast_io@@YAHPEBX@Z=__imp_UnmapViewOfFile") #pragma comment(linker,"/alternatename:__imp_?WriteFile@win32@fast_io@@YAHPEAXPEBXIPEAIPEAUoverlapped@12@@Z=__imp_WriteFile") -#pragma comment(linker,"/alternatename:__imp_?ReadFile@win32@fast_io@@YAHPEAXPEBXIPEAIPEAUoverlapped@12@@Z=__imp_ReadFile") +#pragma comment(linker,"/alternatename:__imp_?ReadFile@win32@fast_io@@YAHPEAX0IPEAIPEAUoverlapped@12@@Z=__imp_ReadFile") #pragma comment(linker,"/alternatename:__imp_?SetFilePointer@win32@fast_io@@YAIPEAXHPEAHI@Z=__imp_SetFilePointer") #pragma comment(linker,"/alternatename:__imp_?SetFilePointerEx@win32@fast_io@@YAHPEAX_JPEA_JI@Z=__imp_SetFilePointerEx") #pragma comment(linker,"/alternatename:__imp_?DuplicateHandle@win32@fast_io@@YAHPEAX00PEAPEAXIHI@Z=__imp_DuplicateHandle") @@ -177,8 +177,8 @@ #pragma comment(linker,"/alternatename:__imp_?ZwQueryInformationProcess@nt@win32@fast_io@@YAIPEIAXW4process_information_class@123@PEAXIPEAI@Z=__imp_ZwQueryInformationProcess") #pragma comment(linker,"/alternatename:__imp_?NtWriteFile@nt@win32@fast_io@@YAIPEAX0P6AX0PEAUio_status_block@123@I@_E01PEBXIPEA_JPEAI@Z=__imp_NtWriteFile") #pragma comment(linker,"/alternatename:__imp_?ZwWriteFile@nt@win32@fast_io@@YAIPEAX0P6AX0PEAUio_status_block@123@I@_E01PEBXIPEA_JPEAI@Z=__imp_ZwWriteFile") -#pragma comment(linker,"/alternatename:__imp_?NtReadFile@nt@win32@fast_io@@YAIPEAX0P6AX0PEAUio_status_block@123@I@_E01PEBXIPEA_JPEAI@Z=__imp_NtReadFile") -#pragma comment(linker,"/alternatename:__imp_?ZwReadFile@nt@win32@fast_io@@YAIPEAX0P6AX0PEAUio_status_block@123@I@_E01PEBXIPEA_JPEAI@Z=__imp_ZwReadFile") +#pragma comment(linker,"/alternatename:__imp_?NtReadFile@nt@win32@fast_io@@YAIPEAX0P6AX0PEAUio_status_block@123@I@_E010IPEA_JPEAI@Z=__imp_NtReadFile") +#pragma comment(linker,"/alternatename:__imp_?ZwReadFile@nt@win32@fast_io@@YAIPEAX0P6AX0PEAUio_status_block@123@I@_E010IPEA_JPEAI@Z=__imp_ZwReadFile") #pragma comment(linker,"/alternatename:__imp_?NtQueryObject@nt@win32@fast_io@@YAIPEAXW4object_information_class@123@0IPEAI@Z=__imp_NtQueryObject") #pragma comment(linker,"/alternatename:__imp_?ZwQueryObject@nt@win32@fast_io@@YAIPEAXW4object_information_class@123@0IPEAI@Z=__imp_ZwQueryObject") #pragma comment(linker,"/alternatename:__imp_?NtQueryDirectoryFile@nt@win32@fast_io@@YAIPEAX0P6AX0PEAUio_status_block@123@I@_E010IW4file_information_class@123@HPEAUunicode_string@123@H@Z=__imp_NtQueryDirectoryFile") diff --git a/include/fast_io_hosted/platforms/win32/msvc_linker_arm64ec.h b/include/fast_io_hosted/platforms/win32/msvc_linker_arm64ec.h index 8074cb835..4a21c5eee 100644 --- a/include/fast_io_hosted/platforms/win32/msvc_linker_arm64ec.h +++ b/include/fast_io_hosted/platforms/win32/msvc_linker_arm64ec.h @@ -15,7 +15,7 @@ #pragma comment(linker,"/alternatename:?SetEndOfFile$exit_thunk@win32@fast_io@@$$hYAHPEAX@Z=#SetEndOfFile") #pragma comment(linker,"/alternatename:?UnmapViewOfFile$exit_thunk@win32@fast_io@@$$hYAHPEBX@Z=#UnmapViewOfFile") #pragma comment(linker,"/alternatename:?WriteFile$exit_thunk@win32@fast_io@@$$hYAHPEAXPEBXIPEAIPEAUoverlapped@12@@Z=#WriteFile") -#pragma comment(linker,"/alternatename:?ReadFile$exit_thunk@win32@fast_io@@$$hYAHPEAXPEBXIPEAIPEAUoverlapped@12@@Z=#ReadFile") +#pragma comment(linker,"/alternatename:?ReadFile$exit_thunk@win32@fast_io@@$$hYAHPEAX0IPEAIPEAUoverlapped@12@@Z=#ReadFile") #pragma comment(linker,"/alternatename:?SetFilePointer$exit_thunk@win32@fast_io@@$$hYAIPEAXHPEAHI@Z=#SetFilePointer") #pragma comment(linker,"/alternatename:?SetFilePointerEx$exit_thunk@win32@fast_io@@$$hYAHPEAX_JPEA_JI@Z=#SetFilePointerEx") #pragma comment(linker,"/alternatename:?DuplicateHandle$exit_thunk@win32@fast_io@@$$hYAHPEAX00PEAPEAXIHI@Z=#DuplicateHandle") @@ -161,10 +161,10 @@ #pragma comment(linker,"/alternatename:?LookupPrivilegeValueA$exit_thunk@win32@fast_io@@$$hYAHPEIBD0PEA_J@Z=#LookupPrivilegeValueA") #pragma comment(linker,"/alternatename:?LookupPrivilegeValueW$exit_thunk@win32@fast_io@@$$hYAHPEIB_S0PEA_J@Z=#LookupPrivilegeValueW") #pragma comment(linker,"/alternatename:?CreateThread$exit_thunk@win32@fast_io@@$$hYAPEAXPEAUsecurity_attributes@12@_KP6AIPEAX@Z2IPEAI@Z=#CreateThread") -#pragma comment(linker,"/alternatename:?CommandLineToArgvW@win32@fast_io@@YAPEAPEA_SPEB_SPEAH@Z=#CommandLineToArgvW") -#pragma comment(linker,"/alternatename:?LocalFree@win32@fast_io@@YAPEAXPEAX@Z=#LocalFree") -#pragma comment(linker,"/alternatename:?PrefetchVirtualMemory@win32@fast_io@@$$hYAHPEAX_KPEAUwin32_memory_range_entry@12@I@Z=#PrefetchVirtualMemory") -#pragma comment(linker,"/alternatename:?SetConsoleTextAttribute@win32@fast_io@@$$hYAHPEAXH@Z=#SetConsoleTextAttribute") +#pragma comment(linker,"/alternatename:?CommandLineToArgvW$exit_thunk@win32@fast_io@@YAPEAPEA_SPEB_SPEAH@Z=#CommandLineToArgvW") +#pragma comment(linker,"/alternatename:?LocalFree$exit_thunk@win32@fast_io@@YAPEAXPEAX@Z=#LocalFree") +#pragma comment(linker,"/alternatename:?PrefetchVirtualMemory$exit_thunk@win32@fast_io@@$$hYAHPEAX_KPEAUwin32_memory_range_entry@12@I@Z=#PrefetchVirtualMemory") +#pragma comment(linker,"/alternatename:?SetConsoleTextAttribute$exit_thunk@win32@fast_io@@$$hYAHPEAXH@Z=#SetConsoleTextAttribute") // NT #pragma comment(linker,"/alternatename:?rtl_nt_status_to_dos_error$exit_thunk@nt@win32@fast_io@@$$hYAII@Z=#RtlNtStatusToDosError") #pragma comment(linker,"/alternatename:?NtClose$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX@Z=#NtClose") @@ -177,8 +177,8 @@ #pragma comment(linker,"/alternatename:?ZwQueryInformationProcess$exit_thunk@nt@win32@fast_io@@$$hYAIPEIAXW4process_information_class@123@PEAXIPEAI@Z=#ZwQueryInformationProcess") #pragma comment(linker,"/alternatename:?NtWriteFile$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX0P6AX0PEAUio_status_block@123@I@_E01PEBXIPEA_JPEAI@Z=#NtWriteFile") #pragma comment(linker,"/alternatename:?ZwWriteFile$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX0P6AX0PEAUio_status_block@123@I@_E01PEBXIPEA_JPEAI@Z=#ZwWriteFile") -#pragma comment(linker,"/alternatename:?NtReadFile$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX0P6AX0PEAUio_status_block@123@I@_E01PEBXIPEA_JPEAI@Z=#NtReadFile") -#pragma comment(linker,"/alternatename:?ZwReadFile$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX0P6AX0PEAUio_status_block@123@I@_E01PEBXIPEA_JPEAI@Z=#ZwReadFile") +#pragma comment(linker,"/alternatename:?NtReadFile$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX0P6AX0PEAUio_status_block@123@I@_E010IPEA_JPEAI@Z=#NtReadFile") +#pragma comment(linker,"/alternatename:?ZwReadFile$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX0P6AX0PEAUio_status_block@123@I@_E010IPEA_JPEAI@Z=#ZwReadFile") #pragma comment(linker,"/alternatename:?NtQueryObject$exit_thunk@nt@win32@fast_io@@$$hYAIPEAXW4object_information_class@123@0IPEAI@Z=#NtQueryObject") #pragma comment(linker,"/alternatename:?ZwQueryObject$exit_thunk@nt@win32@fast_io@@$$hYAIPEAXW4object_information_class@123@0IPEAI@Z=#ZwQueryObject") #pragma comment(linker,"/alternatename:?NtQueryDirectoryFile$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX0P6AX0PEAUio_status_block@123@I@_E010IW4file_information_class@123@HPEAUunicode_string@123@H@Z=#NtQueryDirectoryFile") @@ -297,9 +297,9 @@ #pragma comment(linker,"/alternatename:?ZwDeviceIoControlFile$exit_thunk@nt@win32@fast_io@@$$hYAIPEAX0PEAP6AX0PEAUio_status_block@123@I@_E01I0I0I@Z=#ZwDeviceIoControlFile") #pragma comment(linker,"/alternatename:?RtlAcquirePrivilege$exit_thunk@nt@win32@fast_io@@$$hYAIPEAW4privileges@123@IIPEAPEAX@Z=#RtlAcquirePrivilege") #pragma comment(linker,"/alternatename:?RtlReleasePrivilege$exit_thunk@nt@win32@fast_io@@$$hYAXPEAX@Z=#RtlReleasePrivilege") -#pragma comment(linker,"/alternatename:?RtlQueryEnvironmentVariable_U@nt@win32@fast_io@@$$hYAIPEAXPEAUunicode_string@123@1@Z=#RtlQueryEnvironmentVariable_U") -#pragma comment(linker,"/alternatename:?NtSetInformationVirtualMemory@nt@win32@fast_io@@$$hYAIPEAXW4virtual_memory_information_class@123@_KPEAUmemory_range_entry@123@0I@Z=#NtSetInformationVirtualMemory") -#pragma comment(linker,"/alternatename:?ZwSetInformationVirtualMemory@nt@win32@fast_io@@$$hYAIPEAXW4virtual_memory_information_class@123@_KPEAUmemory_range_entry@123@0I@Z=#ZwSetInformationVirtualMemory") +#pragma comment(linker,"/alternatename:?RtlQueryEnvironmentVariable_U$exit_thunk@nt@win32@fast_io@@$$hYAIPEAXPEAUunicode_string@123@1@Z=#RtlQueryEnvironmentVariable_U") +#pragma comment(linker,"/alternatename:?NtSetInformationVirtualMemory$exit_thunk@nt@win32@fast_io@@$$hYAIPEAXW4virtual_memory_information_class@123@_KPEAUmemory_range_entry@123@0I@Z=#NtSetInformationVirtualMemory") +#pragma comment(linker,"/alternatename:?ZwSetInformationVirtualMemory$exit_thunk@nt@win32@fast_io@@$$hYAIPEAXW4virtual_memory_information_class@123@_KPEAUmemory_range_entry@123@0I@Z=#ZwSetInformationVirtualMemory") // msvc #pragma comment(linker,"/alternatename:?msvc__RTtypeid@msvc@fast_io@@$$hYAPEAXPEAX@Z=#__RTtypeid") // clang-format on diff --git a/include/fast_io_hosted/platforms/win32_mapping.h b/include/fast_io_hosted/platforms/win32_mapping.h index 1e17ba118..22ef80e37 100644 --- a/include/fast_io_hosted/platforms/win32_mapping.h +++ b/include/fast_io_hosted/platforms/win32_mapping.h @@ -58,7 +58,7 @@ inline constexpr win32_file_map_attribute to_win32_file_map_attribute(file_map_a case file_map_attribute::execute_read: return win32_file_map_attribute::execute | win32_file_map_attribute::read; case file_map_attribute::execute_read_write: - return win32_file_map_attribute::execute | win32_file_map_attribute::read; + return win32_file_map_attribute::execute | win32_file_map_attribute::read | win32_file_map_attribute::write; case file_map_attribute::execute_write_copy: return win32_file_map_attribute::execute | win32_file_map_attribute::write | win32_file_map_attribute::copy; case file_map_attribute::read_only: diff --git a/include/fast_io_hosted/platforms/win32_network/socket_file.h b/include/fast_io_hosted/platforms/win32_network/socket_file.h index 47e1ce9cf..7132fc9e7 100644 --- a/include/fast_io_hosted/platforms/win32_network/socket_file.h +++ b/include/fast_io_hosted/platforms/win32_network/socket_file.h @@ -104,6 +104,11 @@ inline ::std::size_t posix_accept_win32_socket_impl(::std::size_t hsocket, void inline ::std::ptrdiff_t posix_recvfrom_win32_socket_impl(::std::size_t hsocket, void *buf, ::std::size_t len, int flags, void *src_addr, int *addrlen) { + if (len > INT_MAX) + { + throw_win32_error(static_cast<::std::uint_least32_t>(87u)); + } + auto soc{::fast_io::win32::recvfrom(hsocket, reinterpret_cast(buf), static_cast(len), flags, src_addr, addrlen)}; if (soc == -1) { @@ -114,6 +119,11 @@ inline ::std::ptrdiff_t posix_recvfrom_win32_socket_impl(::std::size_t hsocket, inline ::std::ptrdiff_t posix_sendto_win32_socket_impl(::std::size_t hsocket, void const *msg, ::std::size_t len, int flags, void const *to, int tolen) { + if (len > INT_MAX) + { + throw_win32_error(static_cast<::std::uint_least32_t>(87u)); + } + auto soc{::fast_io::win32::sendto(hsocket, reinterpret_cast(msg), static_cast(len), flags, to, tolen)}; if (soc == -1) diff --git a/include/fast_io_hosted/platforms/win32_network/win32_9xa_dns.h b/include/fast_io_hosted/platforms/win32_network/win32_9xa_dns.h index fcd5d9799..eb8cabb61 100644 --- a/include/fast_io_hosted/platforms/win32_network/win32_9xa_dns.h +++ b/include/fast_io_hosted/platforms/win32_network/win32_9xa_dns.h @@ -152,7 +152,7 @@ inline constexpr ::std::default_sentinel_t cend(win32_9xa_dns_io_observer) noexc inline constexpr bool operator==(win32_9xa_dns_iterator a, ::std::default_sentinel_t) noexcept { - return a.res == nullptr || (a.res->h_addr_list[a.pos] == nullptr); + return a.res == nullptr || a.res->h_addr_list == nullptr || a.res->h_addr_list[a.pos] == nullptr; } inline constexpr bool operator!=(win32_9xa_dns_iterator a, ::std::default_sentinel_t b) noexcept { 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 13cca9416..73b7b6594 100644 --- a/include/fast_io_hosted/process/ipc/win32/alpc_nt.h +++ b/include/fast_io_hosted/process/ipc/win32/alpc_nt.h @@ -1137,7 +1137,6 @@ class basic_nt_family_alpc_ipc_server FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE { this->handle->close_noexcept(); tls_native_handle_rmptr_type_alloc::deallocate_n(this->handle, 1); - this->handle = nullptr; // POSIX standard says we should never call close(2) again even close syscall fails } } }; @@ -1242,7 +1241,6 @@ class basic_nt_family_alpc_ipc_client FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE { this->handle->close_noexcept(); tls_native_handle_rmptr_type_alloc::deallocate_n(this->handle, 1); - this->handle = nullptr; // POSIX standard says we should never call close(2) again even close syscall fails } } }; diff --git a/include/fast_io_hosted/process/ipc/win32/named_pipe_win32.h b/include/fast_io_hosted/process/ipc/win32/named_pipe_win32.h index 06a3013dd..1acd8aa09 100644 --- a/include/fast_io_hosted/process/ipc/win32/named_pipe_win32.h +++ b/include/fast_io_hosted/process/ipc/win32/named_pipe_win32.h @@ -493,7 +493,6 @@ class basic_win32_family_named_pipe_ipc_server FAST_IO_TRIVIALLY_RELOCATABLE_IF_ if (*this) [[likely]] { ::fast_io::win32::CloseHandle(this->handle); - this->handle = nullptr; } } }; @@ -593,7 +592,6 @@ class basic_win32_family_named_pipe_ipc_client FAST_IO_TRIVIALLY_RELOCATABLE_IF_ if (*this) [[likely]] { ::fast_io::win32::CloseHandle(this->handle); - this->handle = nullptr; } } }; diff --git a/include/fast_io_hosted/process/process/arg_env.h b/include/fast_io_hosted/process/process/arg_env.h index a2342d094..3039c9e00 100644 --- a/include/fast_io_hosted/process/process/arg_env.h +++ b/include/fast_io_hosted/process/process/arg_env.h @@ -318,7 +318,6 @@ struct cstr_guard FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE inline constexpr ~cstr_guard() { Alloc::deallocate(cstr); - cstr = nullptr; } }; diff --git a/include/fast_io_hosted/process/process/nt.h b/include/fast_io_hosted/process/process/nt.h index cec2698ba..a4748f032 100644 --- a/include/fast_io_hosted/process/process/nt.h +++ b/include/fast_io_hosted/process/process/nt.h @@ -13,12 +13,10 @@ inline void close_nt_user_process_information_not_null(nt_user_process_informati if (hnt_user_process_info.hthread) [[likely]] { ::fast_io::win32::nt::nt_close(hnt_user_process_info.hthread); - hnt_user_process_info.hthread = nullptr; } if (hnt_user_process_info.hprocess) [[likely]] { ::fast_io::win32::nt::nt_close(hnt_user_process_info.hprocess); - hnt_user_process_info.hprocess = nullptr; } } template @@ -896,7 +894,6 @@ class nt_family_process FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE : public nt_fa inline ~nt_family_process() { win32::nt::details::close_nt_user_process_information_and_wait(this->hnt_user_process_info); - this->hnt_user_process_info = {}; } }; diff --git a/include/fast_io_hosted/process/process/posix.h b/include/fast_io_hosted/process/process/posix.h index 6d7c7bb6a..2b9b72b94 100644 --- a/include/fast_io_hosted/process/process/posix.h +++ b/include/fast_io_hosted/process/process/posix.h @@ -701,7 +701,6 @@ class posix_process : public posix_process_observer inline ~posix_process() { ::fast_io::details::posix_waitpid_noexcept(this->pid); - this->pid = -1; } }; diff --git a/include/fast_io_hosted/process/process/win32.h b/include/fast_io_hosted/process/process/win32.h index 02f6bd419..42a6b18ad 100644 --- a/include/fast_io_hosted/process/process/win32.h +++ b/include/fast_io_hosted/process/process/win32.h @@ -16,12 +16,10 @@ inline void close_win32_user_process_information_not_null(win32_user_process_inf if (hnt_user_process_info.hthread) [[likely]] { ::fast_io::win32::CloseHandle(hnt_user_process_info.hthread); - hnt_user_process_info.hthread = nullptr; } if (hnt_user_process_info.hprocess) [[likely]] { ::fast_io::win32::CloseHandle(hnt_user_process_info.hprocess); - hnt_user_process_info.hprocess = nullptr; } } @@ -730,7 +728,7 @@ inline win32_wait_status wait(win32_family_process_observer ppob) noexce ::std::uint_least32_t exit_code{}; if (!::fast_io::win32::GetExitCodeProcess(ppob.hnt_user_process_info.hprocess, __builtin_addressof(exit_code))) { - throw_win32_error(status); + throw_win32_error(); } @@ -837,7 +835,6 @@ class win32_family_process FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE : public wi inline ~win32_family_process() { win32::details::close_win32_user_process_information_and_wait(this->hnt_user_process_info); - this->hnt_user_process_info = {}; } }; diff --git a/include/fast_io_hosted/timeutil/posix_timezone.h b/include/fast_io_hosted/timeutil/posix_timezone.h index f1f37f1d1..015439ff8 100644 --- a/include/fast_io_hosted/timeutil/posix_timezone.h +++ b/include/fast_io_hosted/timeutil/posix_timezone.h @@ -34,7 +34,6 @@ struct posix_timezone_name { ::fast_io::typed_generic_allocator_adapter<::fast_io::generic_allocator_adapter<::fast_io::c_malloc_allocator>, char8_t>::deallocate(ptr); - ptr = nullptr; } }; @@ -55,7 +54,7 @@ inline posix_timezone_name posix_localtimezone_impl() noexcept { struct stat st; int ret{::fast_io::posix::libc_lstat(u8"/etc/localtime", __builtin_addressof(st))}; - if (ret == -1) + if (ret == -1) [[unlikely]] { return {}; } @@ -76,11 +75,11 @@ inline posix_timezone_name posix_localtimezone_impl() noexcept nm.ptr = bufptr; nm.n = static_cast<::std::size_t>(static_cast(st.st_size)); ::std::ptrdiff_t symret{::fast_io::posix::libc_readlink(u8"/etc/localtime", bufptr, real_size)}; - if (ret == -1 || static_cast<::std::size_t>(symret) != real_size || real_size <= localtimezoneinfo_string_len) + if (symret == -1 || static_cast<::std::size_t>(symret) != real_size || real_size <= localtimezoneinfo_string_len) [[unlikely]] { return {}; } - if (__builtin_memcmp(localtimezoneinfo, bufptr, localtimezoneinfo_string_len) != 0) + if (__builtin_memcmp(localtimezoneinfo, bufptr, localtimezoneinfo_string_len) != 0) [[unlikely]] { return {}; } diff --git a/include/fast_io_hosted/timeutil/time.h b/include/fast_io_hosted/timeutil/time.h index 2fc913d9d..98f5bfc8b 100644 --- a/include/fast_io_hosted/timeutil/time.h +++ b/include/fast_io_hosted/timeutil/time.h @@ -646,7 +646,7 @@ inline unix_timestamp posix_clock_gettime([[maybe_unused]] posix_clock_id pclk_i struct timespec res; auto clk{details::posix_clock_id_to_native_value(pclk_id)}; // vdso - if (::fast_io::posix::libc_clock_gettime(clk, __builtin_addressof(res)) < 0) + if (::fast_io::posix::libc_clock_gettime(clk, __builtin_addressof(res)) != 0) { throw_posix_error(); } @@ -1109,7 +1109,7 @@ inline void posix_clock_settime([[maybe_unused]] posix_clock_id pclk_id, [[maybe #ifdef __linux__ system_call_throw_error(system_call<__NR_clock_settime, int>(clk, __builtin_addressof(res))); #else - if (::fast_io::posix::libc_clock_settime(clk, __builtin_addressof(res)) < 0) + if (::fast_io::posix::libc_clock_settime(clk, __builtin_addressof(res)) != 0) { throw_posix_error(); } @@ -1178,7 +1178,7 @@ inline [[nodiscard]] bool posix_clock_sleep_abstime(posix_clock_id pclk_id,unix_ inline void posix_clock_sleep_abstime_complete(posix_clock_id pclk_id,unix_timestamp timestamp) { constexpr ::std::uint_least64_t mul_factor{uint_least64_subseconds_per_second/1000000000u}; - struct timespec timestamp_spec{static_cast<::std::time_t>(timestamp.seconds),static_cast(timestamp.subseconds/mul_factor)} + struct timespec timestamp_spec{static_cast<::std::time_t>(timestamp.seconds),static_cast(timestamp.subseconds/mul_factor)}; for(;;) { auto ret{::fast_io::noexcept_call(::clock_nanosleep,pclk_id,TIMER_ABSTIME,__builtin_addressof(timestamp_spec),nullptr)}; diff --git a/include/fast_io_hosted/white_hole/bsd_arc4random.h b/include/fast_io_hosted/white_hole/bsd_arc4random.h index 33b09bda2..2b74304e2 100644 --- a/include/fast_io_hosted/white_hole/bsd_arc4random.h +++ b/include/fast_io_hosted/white_hole/bsd_arc4random.h @@ -47,6 +47,20 @@ inline void read_all_bytes_underflow_define(basic_bsd_arc4random, ::s namespace details { + +inline ::std::byte *posix_getrandom_read_some_bytes_define_impl(unsigned flags, ::std::byte *first, ::std::byte *last) +{ + ::std::size_t sz{static_cast<::std::size_t>(last - first)}; + + auto ret{noexcept_call(::getrandom, first, sz, flags)}; + if (ret < 0) + { + throw_posix_error(); + } + + return first + ret; +} + [[__gnu__::__weak__]] extern void glibc_arc4random_buf(void *, size_t) noexcept __asm__("arc4random_buf"); @@ -55,7 +69,7 @@ inline ::std::byte *bsd_arc4random_read_some_bytes_define_impl(::std::byte *firs constexpr auto *glibc_arc4random_bufptr{::fast_io::details::glibc_arc4random_buf}; if (glibc_arc4random_bufptr == nullptr) { - return ::fast_io::details::linux_getrandom_read_some_bytes_define_impl(0, first, last); + return posix_getrandom_read_some_bytes_define_impl(0, first, last); } else { diff --git a/include/fast_io_hosted/white_hole/linux_getrandom.h b/include/fast_io_hosted/white_hole/linux_getrandom.h index 71ae142f0..f52090f3a 100644 --- a/include/fast_io_hosted/white_hole/linux_getrandom.h +++ b/include/fast_io_hosted/white_hole/linux_getrandom.h @@ -1,5 +1,5 @@ #pragma once -#if !(defined(__linux__) && defined(__NR_getrandom)) && __has_include() +#if !(defined(__linux__) && defined(__NR_getrandom)) && !__has_include() #include #endif @@ -31,7 +31,7 @@ inline ::std::byte *linux_getrandom_read_some_bytes_define_impl(unsigned flags, auto ret{system_call<__NR_getrandom, ::std::ptrdiff_t>(first, sz, flags)}; system_call_throw_error(ret); #else - auto ret{noexcept_call(getrandom, first, sz, flags)}; + auto ret{noexcept_call(::getrandom, first, sz, flags)}; if (ret < 0) { throw_posix_error(); diff --git a/include/fast_io_hosted/white_hole/rtl_gen_random.h b/include/fast_io_hosted/white_hole/rtl_gen_random.h index c7f24d940..5112ac98c 100644 --- a/include/fast_io_hosted/white_hole/rtl_gen_random.h +++ b/include/fast_io_hosted/white_hole/rtl_gen_random.h @@ -46,7 +46,7 @@ inline ::std::byte *rtl_gen_random_some_impl(::std::byte *first, ::std::byte *la } if (!::fast_io::win32::SystemFunction036(first, static_cast<::std::uint_least32_t>(toreadthisround))) { - return first; + throw_win32_error(); } first += toreadthisround; } diff --git a/include/fast_io_hosted/white_hole/wasi_random_get.h b/include/fast_io_hosted/white_hole/wasi_random_get.h index 2ba6915c2..d76bff0f6 100644 --- a/include/fast_io_hosted/white_hole/wasi_random_get.h +++ b/include/fast_io_hosted/white_hole/wasi_random_get.h @@ -37,7 +37,7 @@ inline ::std::byte *wasi_random_get_some_impl(::std::byte *first, ::std::byte *l static_cast<__wasi_size_t>(toreadthisround))}; if (ret) { - return first; + throw_posix_error(ret); } first += toreadthisround; } diff --git a/include/fast_io_hosted/white_hole/white_hole.h b/include/fast_io_hosted/white_hole/white_hole.h index 42d62d446..cd80ed290 100644 --- a/include/fast_io_hosted/white_hole/white_hole.h +++ b/include/fast_io_hosted/white_hole/white_hole.h @@ -10,7 +10,7 @@ namespace fast_io::details { template -concept has_entroy_method_impl = requires(T &&handle) { +concept has_entropy_method_impl = requires(T &&handle) { { random_entropy(handle) } -> ::std::convertible_to; }; @@ -46,12 +46,12 @@ inline int my_random_entropy(int fd) noexcept if (system_call<__NR_ioctl, ::std::ptrdiff_t>(fd, static_cast<::std::uint_least32_t>(u8'R') << 8u, __builtin_addressof(ent)) != 0) { - return 0.0; + return 0; } #else if (::fast_io::posix::ioctl(fd, RNDGETENTCNT, __builtin_addressof(ent)) != 0) { - return 0.0; + return 0; } #endif return ent; @@ -130,7 +130,7 @@ struct basic_white_hole_engine } inline constexpr double entropy() const noexcept { - if constexpr (::fast_io::details::has_entroy_method_impl) + if constexpr (::fast_io::details::has_entropy_method_impl) { auto v{random_entropy(handle)}; constexpr ::std::size_t mx_value{static_cast<::std::size_t>(::std::numeric_limits<::std::size_t>::digits)}; @@ -155,7 +155,7 @@ struct basic_white_hole_engine auto currptr{ibuffer_curr(instmref)}, edptr{ibuffer_end(instmref)}; ::std::size_t diff{static_cast<::std::size_t>(edptr - currptr)}; constexpr ::std::size_t objsz{sizeof(result_type)}; - if (diff <= objsz) + if (diff < objsz) #if __has_cpp_attribute(unlikely) [[unlikely]] #endif diff --git a/include/fast_io_hosted/white_hole/win32_crypt_gen_random.h b/include/fast_io_hosted/white_hole/win32_crypt_gen_random.h index d0e3976c0..bcc394bc5 100644 --- a/include/fast_io_hosted/white_hole/win32_crypt_gen_random.h +++ b/include/fast_io_hosted/white_hole/win32_crypt_gen_random.h @@ -142,11 +142,12 @@ class basic_win32_family_crypt_gen_random_file : public basic_win32_crypt_gen_ra inline ~basic_win32_family_crypt_gen_random_file() { - if (!this->hprov) [[likely]] + if (this->hprov) [[likely]] { ::fast_io::win32::CryptReleaseContext(this->hprov, 0); } } + inline void close() { if (this->hprov) [[likely]] diff --git a/include/fast_io_legacy_impl/filebuf/fp_hack/common.h b/include/fast_io_legacy_impl/filebuf/fp_hack/common.h index 3a1ce84a0..cd3b23ed4 100644 --- a/include/fast_io_legacy_impl/filebuf/fp_hack/common.h +++ b/include/fast_io_legacy_impl/filebuf/fp_hack/common.h @@ -54,10 +54,7 @@ struct filebuf_guard inline ~filebuf_guard() { - if (new_filebuf) - { - delete new_filebuf; - } + delete new_filebuf; } inline constexpr filebuf_type *release() noexcept { From 0a02b2bf397351a68ba222b85ff844c5cffe17da Mon Sep 17 00:00:00 2001 From: MacroModel Date: Wed, 25 Jun 2025 17:08:19 +0800 Subject: [PATCH 6/7] fix --- include/fast_io_core_impl/concat/concat_buffer.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/fast_io_core_impl/concat/concat_buffer.h b/include/fast_io_core_impl/concat/concat_buffer.h index 8a137e7e3..0a4d3c11b 100644 --- a/include/fast_io_core_impl/concat/concat_buffer.h +++ b/include/fast_io_core_impl/concat/concat_buffer.h @@ -25,10 +25,6 @@ struct basic_concat_buffer if (buffer_begin != stack_buffer) [[unlikely]] { deallocate_iobuf_space(buffer_begin, static_cast<::std::size_t>(buffer_end - buffer_begin)); - - buffer_begin = stack_buffer; - buffer_curr = stack_buffer; - buffer_end = stack_buffer + buffer_size; } } }; From c65aa81ec823598f6f139e4f7907b44667f13748 Mon Sep 17 00:00:00 2001 From: MacroModel Date: Wed, 25 Jun 2025 17:46:07 +0800 Subject: [PATCH 7/7] fix --- include/fast_io_hosted/dbg/nt_dbg.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/fast_io_hosted/dbg/nt_dbg.h b/include/fast_io_hosted/dbg/nt_dbg.h index 75d26885e..bd3219313 100644 --- a/include/fast_io_hosted/dbg/nt_dbg.h +++ b/include/fast_io_hosted/dbg/nt_dbg.h @@ -97,10 +97,7 @@ inline void nt_fmt_dbg_forward([[maybe_unused]] nt_dbg_carrier carr, char8_t con /// @todo In the Windows NT debugging implementation, string lengths are silently truncated and UINT_LEAST16_MAX does not issue any error indications or warnings to the caller, which may result in incomplete debugging output. if (UINT_LEAST16_MAX < arg_n_len) { - ::fast_io::fast_terminate(); -#if 0 arg_n_len = UINT_LEAST16_MAX; -#endif } ::std::uint_least16_t const u16argnlen{static_cast<::std::uint_least16_t>(arg_n_len)}; ::fast_io::win32::nt::ansi_string astr{u16argnlen, u16argnlen, @@ -119,10 +116,7 @@ inline void nt_dbg_write_impl([[maybe_unused]] nt_dbg_carrier carr, char const * /// @todo In the Windows NT debugging implementation, string lengths are silently truncated and UINT_LEAST16_MAX does not issue any error indications or warnings to the caller, which may result in incomplete debugging output. if (UINT_LEAST16_MAX < arg_n_len) { - ::fast_io::fast_terminate(); -#if 0 arg_n_len = UINT_LEAST16_MAX; -#endif } ::std::uint_least16_t const u16argnlen{static_cast<::std::uint_least16_t>(arg_n_len)}; ::fast_io::win32::nt::ansi_string astr{u16argnlen, u16argnlen, const_cast(first)};