Skip to content

Commit e9f5daf

Browse files
committed
Refactor thread start routine declaration and improve error handling in POSIX headers
- Updated `thread_start_routine` in both NT and Win32 headers to include `FAST_IO_WINSTDCALL` for better calling convention compatibility. - Enhanced error handling in `get_module_install_path_from_argv0` by checking for a null environment path and throwing an appropriate error. - Improved readability by initializing pointers to empty and using consistent formatting in the `argv0.h` file. - Adjusted conditional compilation checks in `posix.h` for clearer handling of open mode flags.
1 parent 13e051d commit e9f5daf

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

include/fast_io_driver/install_path/argv0.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ inline ::fast_io::install_path get_module_install_path_from_argv0(char const *ar
6666
::fast_io::noexcept_call(::strncat, newpath2, path_separator_as_string, PATH_MAX + 256);
6767
::fast_io::noexcept_call(::strncat, newpath2, argv0, PATH_MAX + 256);
6868
[[maybe_unused]] auto const unused2{::fast_io::noexcept_call(::realpath, newpath2, newpath)};
69-
if (auto status{::fast_io::noexcept_call(::access, newpath, F_OK)};!status)
69+
if (auto status{::fast_io::noexcept_call(::access, newpath, F_OK)}; !status)
7070
{
7171
newpath[PATH_MAX - 1] = 0;
7272
ret.module_name = ::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt_os_c_str(newpath));
@@ -91,10 +91,17 @@ inline ::fast_io::install_path get_module_install_path_from_argv0(char const *ar
9191
}
9292
else
9393
{
94-
char *saveptr;
95-
char *pathitem;
96-
char *save_path{::fast_io::noexcept_call(::getenv, "PATH")};
97-
for (pathitem = ::fast_io::noexcept_call(::strtok_r, save_path, path_list_separator, &saveptr); pathitem;
94+
char *saveptr{};
95+
char *pathitem{};
96+
char const *env_path{::fast_io::noexcept_call(::getenv, "PATH")};
97+
if (!env_path) [[unlikely]]
98+
{
99+
throw_posix_error(EINVAL);
100+
}
101+
char pathbuf[PATH_MAX + 256 + 1]{};
102+
::fast_io::noexcept_call(::strncpy, pathbuf, env_path, PATH_MAX + 256);
103+
104+
for (pathitem = ::fast_io::noexcept_call(::strtok_r, pathbuf, path_list_separator, &saveptr); pathitem;
98105
pathitem = ::fast_io::noexcept_call(::strtok_r, nullptr, path_list_separator, &saveptr))
99106
{
100107
::fast_io::noexcept_call(::strncpy, newpath2, pathitem, PATH_MAX + 256);

include/fast_io_hosted/platforms/posix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ inline constexpr int calculate_posix_open_mode(open_mode value) noexcept
194194
if ((value & open_mode::inherit) == open_mode::none)
195195
#ifdef O_CLOEXEC
196196
mode |= O_CLOEXEC;
197-
#elif _O_NOINHERIT
197+
#elif defined(_O_NOINHERIT)
198198
mode |= _O_NOINHERIT;
199199
#endif
200200
#ifdef O_BINARY

include/fast_io_hosted/threads/thread/nt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class nt_thread_start_routine_tuple_allocate_guard
3838
};
3939

4040
template <typename Tuple, ::std::size_t... Is>
41-
constexpr ::std::uint_least32_t thread_start_routine(void *args) noexcept(noexcept(
41+
constexpr ::std::uint_least32_t FAST_IO_WINSTDCALL thread_start_routine(void *args) noexcept(noexcept(
4242
::std::invoke(::fast_io::get<Is>(*reinterpret_cast<Tuple *>(args))...)))
4343
{
4444
[[maybe_unused]] ::fast_io::win32::nt::details::nt_thread_start_routine_tuple_allocate_guard _(args);

include/fast_io_hosted/threads/thread/win32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class win32_thread_start_routine_tuple_allocate_guard
3838
};
3939

4040
template <typename Tuple, ::std::size_t... Is>
41-
constexpr ::std::uint_least32_t thread_start_routine(void *args) noexcept(noexcept(
41+
constexpr ::std::uint_least32_t FAST_IO_WINSTDCALL thread_start_routine(void *args) noexcept(noexcept(
4242
::std::invoke(::fast_io::get<Is>(*reinterpret_cast<Tuple *>(args))...)))
4343
{
4444
[[maybe_unused]] ::fast_io::win32::details::win32_thread_start_routine_tuple_allocate_guard _(args);

0 commit comments

Comments
 (0)