Skip to content

Commit 17b4bb9

Browse files
authored
fix (#1192)
- Fix function name in allocation adapters - Correct find_last return value for bidirectional iterators - Use proper iterator operations for forward iterators - Fix template parameters and length calculations in crypto hash
1 parent 405cd9b commit 17b4bb9

5 files changed

Lines changed: 17 additions & 12 deletions

File tree

include/fast_io_core_impl/allocation/adapters.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inline constexpr ::std::size_t allocator_compute_aligned_total_size_impl(::std::
5353

5454
inline void *allocator_adjust_ptr_to_aligned_impl(void *p, ::std::size_t alignment) noexcept
5555
{
56-
void *aligned_ptr{reinterpret_cast<void *>((reinterpret_cast<::std::size_t>(p) + alignment) & (0 - alignment))};
56+
void *aligned_ptr{reinterpret_cast<void *>((reinterpret_cast<::std::uintptr_t>(p) + alignment) & (0 - alignment))};
5757
reinterpret_cast<void **>(aligned_ptr)[-1] = p;
5858
return aligned_ptr;
5959
}
@@ -1253,7 +1253,7 @@ class typed_generic_allocator_adapter
12531253
}
12541254
else
12551255
{
1256-
auto newres{alloc::allocate_zero_aligned_at_least(alignof(T), n * sizeof(T))};
1256+
auto newres{alloc::allocate_aligned_zero_at_least(alignof(T), n * sizeof(T))};
12571257
return {reinterpret_cast<T *>(newres.ptr), newres.count / sizeof(T)};
12581258
}
12591259
}

include/fast_io_core_impl/char_category/char_category.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,9 @@ inline constexpr bool is_c_halfwidth(char_type ch) noexcept
18591859
using unsigned_char_type = ::std::make_unsigned_t<char_type>;
18601860
if constexpr (sizeof(char_type) < sizeof(char32_t))
18611861
{
1862-
return ch;
1862+
constexpr unsigned_char_type halfwidth_exclaimation_mark_val{u8'!'};
1863+
constexpr unsigned_char_type num{94};
1864+
return static_cast<unsigned_char_type>(ch - halfwidth_exclaimation_mark_val) < num;
18631865
}
18641866
else if constexpr (!::std::same_as<char_type, char32_t> && sizeof(char_type) == sizeof(char32_t))
18651867
{
@@ -1891,7 +1893,9 @@ inline constexpr bool is_c_fullwidth(char_type ch) noexcept
18911893
using unsigned_char_type = ::std::make_unsigned_t<char_type>;
18921894
if constexpr (sizeof(char_type) < sizeof(char32_t))
18931895
{
1894-
return ch;
1896+
constexpr unsigned_char_type fullwidth_exclaimation_mark_val{0xFF01};
1897+
constexpr unsigned_char_type num{94};
1898+
return static_cast<unsigned_char_type>(ch - fullwidth_exclaimation_mark_val) < num;
18951899
}
18961900
else if constexpr (!::std::same_as<char_type, char32_t> && sizeof(char_type) == sizeof(char32_t))
18971901
{

include/fast_io_core_impl/freestanding/algorithm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,13 @@ inline constexpr ForwardIt lower_bound(ForwardIt first, ForwardIt last, T const
532532
{
533533
ForwardIt it;
534534
typename ::std::iterator_traits<ForwardIt>::difference_type count, step;
535-
count = last - first;
535+
count = ::std::distance(first, last);
536536

537537
while (count > 0)
538538
{
539539
it = first;
540540
step = count / 2;
541-
it += step;
541+
::std::advance(it, step);
542542

543543
if (comp(*it, value))
544544
{
@@ -735,7 +735,7 @@ template <::std::input_iterator ForwardIt>
735735
inline constexpr void uninitialized_default_construct_n(ForwardIt first, ::std::size_t n) noexcept(
736736
::std::is_nothrow_default_constructible_v<typename ::std::iterator_traits<ForwardIt>::value_type>)
737737
{
738-
::fast_io::freestanding::uninitialized_default_construct(first, first + n);
738+
::fast_io::freestanding::uninitialized_default_construct(first, ::std::next(first, n));
739739
}
740740

741741
template <::std::input_iterator ForwardIt, typename T>
@@ -771,7 +771,7 @@ template <::std::input_iterator ForwardIt, typename T>
771771
inline constexpr void uninitialized_fill_n(ForwardIt first, ::std::size_t n, T const &x) noexcept(
772772
::std::is_nothrow_copy_constructible_v<typename ::std::iterator_traits<ForwardIt>::value_type>)
773773
{
774-
::fast_io::freestanding::uninitialized_fill(first, first + n, x);
774+
::fast_io::freestanding::uninitialized_fill(first, ::std::next(first, n), x);
775775
}
776776

777777
template <::std::forward_iterator ForwardIt>

include/fast_io_core_impl/freestanding/bytes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ inline constexpr ::std::byte *nonoverlapped_bytes_copy(::std::byte const *first,
137137
}
138138

139139
template <typename T>
140+
requires(::std::is_trivially_copyable_v<T>) // make sure the type is trivially copyable for safely using memcpy
140141
inline constexpr ::std::byte const *type_punning_from_bytes(::std::byte const *__restrict first,
141142
T &__restrict t) noexcept
142143
{
@@ -164,7 +165,7 @@ inline constexpr ::std::byte const *type_punning_from_bytes(::std::byte const *_
164165
}
165166

166167
template <::std::size_t n, typename T>
167-
requires(n <= sizeof(T))
168+
requires(n <= sizeof(T) && ::std::is_trivially_copyable_v<T>)
168169
inline constexpr ::std::byte *type_punning_to_bytes_n(T const &__restrict first, ::std::byte *__restrict dest) noexcept
169170
{
170171
if constexpr (n != 0)

include/fast_io_core_impl/integers/crypto_hash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ inline constexpr hash_compress_t<digest_format::upper, ctx> hash_compress_upper(
281281
else
282282
{
283283
return {reinterpret_cast<::std::byte const *>(::std::ranges::data(t)),
284-
static_cast<::std::size_t>(::std::ranges::size(t)) * sizeof(T)};
284+
static_cast<::std::size_t>(::std::ranges::size(t)) * sizeof(::std::ranges::range_value_t<T>)};
285285
}
286286
}
287287

@@ -478,7 +478,7 @@ inline constexpr char_type *prv_srv_hash_compress_df_impl(char_type *iter, ::std
478478
::std::byte buffer[digest_size];
479479
auto ret{cal_hash_internal_impl<T>(base, len, buffer)};
480480
return ::fast_io::details::copy_to_hash_df_commom_impl < d ==
481-
::fast_io::manipulators::digest_format::upper > (buffer, iter, static_cast<::std::size_t>(ret - buffer));
481+
::fast_io::manipulators::digest_format::upper > (iter, buffer, static_cast<::std::size_t>(ret - buffer));
482482
}
483483
else
484484
{
@@ -512,7 +512,7 @@ inline constexpr char_type *prv_srv_hash_compress_df_impl(char_type *iter, ::std
512512
::std::byte buffer[digest_size];
513513
cal_hash_internal<T>(base, len, buffer);
514514
return ::fast_io::details::copy_to_hash_df_commom_impl < d ==
515-
::fast_io::manipulators::digest_format::upper > (buffer, iter, digest_size);
515+
::fast_io::manipulators::digest_format::upper > (iter, buffer, digest_size);
516516
}
517517
else
518518
{

0 commit comments

Comments
 (0)