Skip to content

Commit 87eee28

Browse files
authored
Bug fix (#1189)
* Fix the function calls in the memory allocation adapter * Fix the missing semicolon * Fix the return value * Fix the memory allocation logic to ensure that the correct exact size is reserved * Add branch in the copy function * Fix the type comparison in the algorithm * Fix the require condition * Fix the types in the functions and correct the parameter order * Fix the operator from left-shift to right-shift * Fix some problems
1 parent 8ba32f9 commit 87eee28

File tree

12 files changed

+32
-25
lines changed

12 files changed

+32
-25
lines changed

include/fast_io_core_impl/allocation/adapters.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class generic_allocator_adapter
129129
{
130130
return allocator_type::allocate(n);
131131
}
132-
else if constexpr (::fast_io::details::has_allocate_aligned_at_least_impl<alloc>)
132+
else if constexpr (::fast_io::details::has_allocate_at_least_impl<alloc>)
133133
{
134134
return allocator_type::allocate_at_least(n).ptr;
135135
}
@@ -141,7 +141,7 @@ class generic_allocator_adapter
141141
{
142142
return allocator_type::allocate_zero(n);
143143
}
144-
else if constexpr (::fast_io::details::has_allocate_aligned_at_least_impl<alloc>)
144+
else if constexpr (::fast_io::details::has_allocate_zero_at_least_impl<alloc>)
145145
{
146146
return allocator_type::allocate_zero_at_least(n).ptr;
147147
}
@@ -1211,7 +1211,7 @@ class typed_generic_allocator_adapter
12111211
}
12121212
else
12131213
{
1214-
return static_cast<T *>(alloc::allocate_aligned(n * sizeof(T), alignof(T)));
1214+
return static_cast<T *>(alloc::allocate_aligned(alignof(T), n * sizeof(T)));
12151215
}
12161216
}
12171217

@@ -1248,7 +1248,7 @@ class typed_generic_allocator_adapter
12481248
}
12491249
else
12501250
{
1251-
auto newres{alloc::allocate_aligned_at_least(n * sizeof(T), alignof(T))};
1251+
auto newres{alloc::allocate_aligned_at_least(alignof(T), n * sizeof(T))};
12521252
return {reinterpret_cast<T *>(newres.ptr), newres.count / sizeof(T)};
12531253
}
12541254
}
@@ -1274,7 +1274,7 @@ class typed_generic_allocator_adapter
12741274
}
12751275
else
12761276
{
1277-
return static_cast<T *>(alloc::allocate_zero_aligned(n * sizeof(T), alignof(T)));
1277+
return static_cast<T *>(alloc::allocate_zero_aligned(alignof(T), n * sizeof(T)));
12781278
}
12791279
}
12801280

@@ -1311,7 +1311,7 @@ class typed_generic_allocator_adapter
13111311
}
13121312
else
13131313
{
1314-
auto newres{alloc::allocate_zero_aligned_at_least(n * sizeof(T), alignof(T))};
1314+
auto newres{alloc::allocate_zero_aligned_at_least(alignof(T), n * sizeof(T))};
13151315
return {reinterpret_cast<T *>(newres.ptr), newres.count / sizeof(T)};
13161316
}
13171317
}
@@ -1339,7 +1339,7 @@ class typed_generic_allocator_adapter
13391339
}
13401340
else
13411341
{
1342-
return static_cast<T *>(alloc::reallocate_aligned(ptr, n * sizeof(T), alignof(T)));
1342+
return static_cast<T *>(alloc::reallocate_aligned(ptr, alignof(T), n * sizeof(T)));
13431343
}
13441344
}
13451345

@@ -1365,7 +1365,7 @@ class typed_generic_allocator_adapter
13651365
}
13661366
else
13671367
{
1368-
auto newres{alloc::reallocate_aligned_zero_at_least(ptr, n * sizeof(T), alignof(T))};
1368+
auto newres{alloc::reallocate_aligned_zero_at_least(ptr, alignof(T), n * sizeof(T))};
13691369
return {reinterpret_cast<T *>(newres.ptr), newres.count / sizeof(T)};
13701370
}
13711371
}

include/fast_io_core_impl/allocation/custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace fast_io
66
class custom_global_allocator;
77

88
#if defined(FAST_IO_DISABLE_CUSTOM_THREAD_LOCAL_ALLOCATOR)
9-
using custom_thread_local_allocator = custom_global_allocator
9+
using custom_thread_local_allocator = custom_global_allocator;
1010
#else
1111
class custom_thread_local_allocator;
1212
#endif

include/fast_io_core_impl/concat/concat_general.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ inline constexpr T basic_general_concat_decay_impl_precise(T& str,Arg arg)
8686
++precise_size_with_line;
8787
constexpr std::size_t local_cap{strlike_sso_size(io_strlike_type<ch_type,T>)};
8888
if(local_cap<precise_size_with_line)
89-
strlike_reserve(io_strlike_type<ch_type,T>,str,local_cap);
89+
strlike_reserve(io_strlike_type<ch_type,T>,str,precise_size_with_line);
9090
auto first{strlike_begin(io_strlike_type<ch_type,T>,str)};
9191
print_reserve_precise_define(io_reserve_type<ch_type,Arg>,first,precise_size,arg);
9292
auto ptr{first+precise_size};

include/fast_io_core_impl/concepts/type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct basic_message_hdr
3535
int flags; /* Flags (unused) */
3636
inline operator basic_message_hdr<void>() const noexcept requires(!std::same_as<T,void>)
3737
{
38-
return {name,namelen*sizeof(T),iov,iovlen*sizeof(T),control,controllen,flags};
38+
return {name,namelen,iov,iovlen,control,controllen,flags};
3939
}
4040
};
4141

include/fast_io_core_impl/dynamic_io_buffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ inline constexpr void dynamic_io_buffer_write_impl_unhappy(dynamic_io_buffer<::s
116116
template<std::integral ch_type>
117117
inline constexpr void oreserve(dynamic_io_buffer<ch_type>& ob,std::size_t new_capacity) noexcept
118118
{
119-
if(static_cast<std::size_t>(ob.buffer_end-ob.buffer_begin)<=new_capacity)
119+
if(static_cast<std::size_t>(ob.buffer_end-ob.buffer_begin)>=new_capacity) // return if enough space
120120
return;
121121
details::dynamic_io_buffer_oreallocate_impl(ob,new_capacity);
122122
}
@@ -159,7 +159,7 @@ inline constexpr void write(dynamic_io_buffer<ch_type>& ob,Iter first,Iter last)
159159
details::dynamic_io_buffer_write_impl_unhappy(ob,first,diff);
160160
return;
161161
}
162-
ob.buffer_curr=details::non_overlapped_copy(first,last,ob.buffer_begin);
162+
ob.buffer_curr=details::non_overlapped_copy(first,last,ob.buffer_curr); // copy to buffer_curr, not buffer_begin
163163
}
164164
}
165165

include/fast_io_core_impl/freestanding/algorithm.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ inline constexpr output_iter copy(input_iter first, input_iter last, output_iter
8282
{
8383
*result = static_cast<::std::byte>(*first);
8484
}
85+
else
86+
{
87+
*result = *first;
88+
}
8589
++first;
8690
++result;
8791
}
@@ -403,8 +407,7 @@ inline constexpr output_iter my_copy(input_iter first, input_iter second, output
403407
::std::is_trivially_copyable_v<output_value_type> &&
404408
(::std::same_as<input_value_type, output_value_type> ||
405409
(::std::integral<input_value_type> && ::std::integral<output_value_type> &&
406-
sizeof(::std::is_trivially_copyable_v<input_value_type>) ==
407-
sizeof(::std::is_trivially_copyable_v<output_value_type>))))
410+
sizeof(input_value_type) == sizeof(output_value_type))))
408411
{
409412
my_copy_n(first, static_cast<::std::size_t>(second - first), result);
410413
return result + (second - first);
@@ -486,7 +489,7 @@ inline constexpr bool my_compare_iter_n(input_iter first, ::std::size_t n, outpu
486489
(::std::integral<input_value_type> && ::std::integral<output_value_type> &&
487490
sizeof(input_value_type) == sizeof(output_value_type))))
488491
{
489-
return my_memcmp(::std::to_address(first), ::std::to_address(outier), n) == 0;
492+
return my_memcmp(::std::to_address(first), ::std::to_address(outier), sizeof(input_value_type) * n) == 0;
490493
}
491494
else
492495
{

include/fast_io_core_impl/freestanding/array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace fast_io::freestanding
44
{
55

66
template <typename T, ::std::size_t N>
7-
requires(sizeof(N) != 0)
7+
requires(N != 0)
88
struct array
99
{
1010
using value_type = T;

include/fast_io_core_impl/integers/crypto_hash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ inline constexpr hash_compress_t<digest_format::upper,ctx> hash_compress_upper(T
303303
}
304304
else
305305
{
306-
return {reinterpret_cast<std::byte const*>(::std::ranges::data(t)),static_cast<std::size_t>(::std::ranges::size(t))*sizeof(T)};
306+
return {reinterpret_cast<std::byte const*>(::std::ranges::data(t)),static_cast<std::size_t>(::std::ranges::size(t))*sizeof(::std::ranges::range_value_t<T>)};
307307
}
308308
}
309309

@@ -317,7 +317,7 @@ inline constexpr hash_compress_t<digest_format::raw_bytes,ctx> hash_compress_raw
317317
}
318318
else
319319
{
320-
return {reinterpret_cast<std::byte const*>(::std::ranges::data(t)),static_cast<std::size_t>(::std::ranges::size(t))*sizeof(T)};
320+
return {reinterpret_cast<std::byte const*>(::std::ranges::data(t)),static_cast<std::size_t>(::std::ranges::size(t))*sizeof(::std::ranges::range_value_t<T>)};
321321
}
322322
}
323323

@@ -511,7 +511,7 @@ inline constexpr char_type* prv_srv_hash_compress_df_impl(char_type* iter,std::b
511511
{
512512
std::byte buffer[digest_size];
513513
auto ret{cal_hash_internal_impl<T>(base,len,buffer)};
514-
return ::fast_io::details::copy_to_hash_df_commom_impl<d==::fast_io::manipulators::digest_format::upper>(buffer,iter,static_cast<std::size_t>(ret-buffer));
514+
return ::fast_io::details::copy_to_hash_df_commom_impl<d==::fast_io::manipulators::digest_format::upper>(iter,buffer,static_cast<std::size_t>(ret-buffer));
515515
}
516516
else
517517
#endif

include/fast_io_core_impl/simd/gcc_clang.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct simd_vector
191191
}
192192
inline constexpr simd_vector<T,N>& operator>>=(simd_vector<T,N> const& other) noexcept
193193
{
194-
value<<=other.value;
194+
value>>=other.value;
195195
return *this;
196196
}
197197

include/fast_io_hosted/filesystem/nt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ struct basic_nt_family_recursive_directory_generator
357357
constexpr basic_nt_family_recursive_directory_generator(basic_nt_family_recursive_directory_generator&& __restrict other) noexcept:root_handle(other.root_handle),entry(other.entry)
358358
{
359359
other.root_handle=nullptr;
360-
entry=nullptr;
360+
other.entry=nullptr;
361361
}
362362
constexpr basic_nt_family_recursive_directory_generator& operator=(basic_nt_family_recursive_directory_generator&& __restrict other) noexcept
363363
{

0 commit comments

Comments
 (0)