Skip to content

Commit ea602ef

Browse files
authored
Next (#1197)
* Refactor memory unmapping functions to improve error handling - Renamed `sys_munmap` to `sys_munmap_nothrow` to indicate it does not throw errors. - Updated calls to `sys_munmap` in `posix_file_loader.h` to use the new `sys_munmap_nothrow` function for safer memory management. * Enhance algorithm and memory management interfaces - Changed `uninitialized_fill_n` to return `ForwardIt` instead of void for better usability. - Updated `close` and destructor in `posix_memory_map_file` to be `constexpr` for improved compile-time evaluation. - Added new environment string functions in Win32 API for better compatibility. - Standardized `#pragma once` across multiple thread header files for consistency.
1 parent b8e070a commit ea602ef

File tree

8 files changed

+13
-10
lines changed

8 files changed

+13
-10
lines changed

include/fast_io_core_impl/freestanding/algorithm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,10 @@ inline constexpr ForwardIt uninitialized_fill(ForwardIt first, ForwardIt last, T
768768
}
769769

770770
template <::std::input_iterator ForwardIt, typename T>
771-
inline constexpr void uninitialized_fill_n(ForwardIt first, ::std::size_t n, T const &x) noexcept(
771+
inline constexpr ForwardIt 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, ::std::next(first, n), x);
774+
return ::fast_io::freestanding::uninitialized_fill(first, ::std::next(first, n), x);
775775
}
776776

777777
template <::std::forward_iterator ForwardIt>

include/fast_io_hosted/platforms/posix_mapping.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class posix_memory_map_file
291291
{
292292
return address_begin[pos];
293293
}
294-
inline void close()
294+
inline constexpr void close()
295295
{
296296
if (this->address_begin != MAP_FAILED) [[likely]]
297297
{
@@ -300,7 +300,7 @@ class posix_memory_map_file
300300
system_call_throw_error(ret);
301301
}
302302
}
303-
inline ~posix_memory_map_file()
303+
inline constexpr ~posix_memory_map_file()
304304
{
305305
if (this->address_begin != MAP_FAILED) [[likely]]
306306
{

include/fast_io_hosted/platforms/win32/apis.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,8 @@ FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL PrefetchVirtualMemory(void *, ::std::si
170170
FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL SetConsoleTextAttribute(void *, ::std::int_least32_t) noexcept FAST_IO_WINSTDCALL_RENAME(SetConsoleTextAttribute, 8);
171171
FAST_IO_DLLIMPORT ::std::uint_least32_t FAST_IO_WINSTDCALL GetCurrentThreadId() noexcept FAST_IO_WINSTDCALL_RENAME(GetCurrentThreadId, 0);
172172
FAST_IO_DLLIMPORT void FAST_IO_WINSTDCALL Sleep(::std::uint_least32_t) noexcept FAST_IO_WINSTDCALL_RENAME(Sleep, 4);
173-
173+
FAST_IO_DLLIMPORT char16_t *FAST_IO_WINSTDCALL GetEnvironmentStringsW() noexcept FAST_IO_WINSTDCALL_RENAME(GetEnvironmentStringsW, 0);
174+
FAST_IO_DLLIMPORT char *FAST_IO_WINSTDCALL GetEnvironmentStringsA() noexcept FAST_IO_WINSTDCALL_RENAME(GetEnvironmentStringsA, 0);
175+
FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL FreeEnvironmentStringsW(char16_t*) noexcept FAST_IO_WINSTDCALL_RENAME(FreeEnvironmentStringsW, 4);
176+
FAST_IO_DLLIMPORT int FAST_IO_WINSTDCALL FreeEnvironmentStringsA(char*) noexcept FAST_IO_WINSTDCALL_RENAME(FreeEnvironmentStringsA, 4);
174177
} // namespace fast_io::win32

include/fast_io_hosted/threads/thread/c_malloc_guard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
namespace fast_io::details
44
{

include/fast_io_hosted/threads/thread/impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#if (defined(_WIN32) && !defined(__WINE__)) && !defined(__CYGWIN__)
44
#ifdef _WIN32_WINDOWS

include/fast_io_hosted/threads/thread/nt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include <chrono>
44
#include <ranges>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#pragma once
1+
#pragma once

include/fast_io_hosted/threads/thread/win32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include <chrono>
44
#include <ranges>

0 commit comments

Comments
 (0)