Skip to content
Open

Next #1217

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0e8e82d
Refactor tuple element access in fast_io_dsal
MacroModel Nov 7, 2025
6315171
Add tuple application utility and size retrieval in fast_io_dsal
MacroModel Nov 7, 2025
13e051d
Refactor error handling and improve function signatures across platfo…
MacroModel Nov 7, 2025
e9f5daf
Refactor thread start routine declaration and improve error handling …
MacroModel Nov 7, 2025
c986bc1
Refactor `get` function signatures in tuple.h for improved type deduc…
MacroModel Nov 7, 2025
8102ddc
f
MacroModel Nov 7, 2025
d88268e
Enhance error handling and improve path resolution in module installa…
MacroModel Nov 7, 2025
c5c1b52
Enhance Android logger functionality with noexcept specifier
MacroModel Nov 7, 2025
d10b547
Enhance error handling and improve function signatures across platfor…
MacroModel Nov 7, 2025
f36b409
Enhance POSIX and Win32 platform headers with improved error handling…
MacroModel Nov 7, 2025
ef50242
f
MacroModel Nov 7, 2025
4a73261
f2
MacroModel Nov 7, 2025
039820d
f3
MacroModel Nov 7, 2025
85eba53
Refactor timestamp handling in nt_family_clock_settime for improved t…
MacroModel Nov 7, 2025
6eac407
Update Win32 linker headers to correct function signatures and improv…
MacroModel Nov 8, 2025
3c03843
Refactor append methods in process argument and environment structure…
MacroModel Nov 8, 2025
26a99a4
Fix path resizing logic in POSIX process header for accurate string l…
MacroModel Nov 8, 2025
7aebe7d
Add posix_vfork option and refactor process execution methods for POSIX
MacroModel Nov 8, 2025
e70856c
Refactor process execution logic in posix.h to improve clarity and ma…
MacroModel Nov 8, 2025
be06549
Update vfork_and_execveat function to include unused parameter for pr…
MacroModel Nov 8, 2025
58aa2c7
Enhance process_mode enumeration and update posix_execveat function
MacroModel Nov 8, 2025
5c27a0c
Refactor process creation logic in nt.h and update process_mode options
MacroModel Nov 8, 2025
21fd346
nt_process_args
MacroModel Nov 8, 2025
c74a312
Enhance argument handling in nt_6x_process_create_impl by adding quot…
MacroModel Nov 8, 2025
d0349bc
Refactor environment handling in posix_process_args for improved clarity
MacroModel Nov 8, 2025
579529b
Fix argument initialization in args_envs.cc by updating process argum…
MacroModel Nov 8, 2025
9f3788a
Refactor posix namespace in arg_env.h to improve environment variable…
MacroModel Nov 8, 2025
f9b88b6
f
MacroModel Nov 8, 2025
4de5251
f
MacroModel Nov 9, 2025
06a3f1d
Update process argument handling in process.cc and nt.h
MacroModel Nov 9, 2025
6c17ce4
Add args_with_argv0_t structure and update process constructors
MacroModel Nov 9, 2025
bf2fe18
Refactor process constructors in nt.h, posix.h, and win32.h to standa…
MacroModel Nov 9, 2025
eff1c0d
Refactor argument handling in win32.h for consistency and clarity
MacroModel Nov 9, 2025
dd37570
Refactor error handling and object duplication in win32.h
MacroModel Nov 9, 2025
3fa5be6
f
MacroModel Nov 9, 2025
9ee1807
k
MacroModel Nov 10, 2025
c2b58ba
Refactor thread implementation in nt.h and impl.h for clarity and con…
MacroModel Nov 10, 2025
81f7d3c
fix thread
MacroModel Nov 10, 2025
a72ea6c
Enhance thread handling and error management in nt and win32 headers
MacroModel Nov 10, 2025
10b0ee1
Update RtlCreateUserThread signatures across linker headers for consi…
MacroModel Nov 10, 2025
726cfe2
Add documentation comment to thread_start_routine in win32.h
MacroModel Nov 10, 2025
e2f16ca
t1
MacroModel Nov 10, 2025
8bc184e
Refactor threading implementation for POSIX and Windows
MacroModel Nov 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions examples/0035.process/args_envs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ int main(int argc, char **argv)

::fast_io::native_process p{
::fast_io::mnp::os_c_str(argv[1]),
{"char",
L"wchar Double\"quotation\"marks",
u8"u8",
u"u16",
U"u32",
114514,
115145.1919810,
::fast_io::concat_fast_io("This ", 1, "s ", ::fast_io::mnp::code_cvt_os_c_str(u8"just "), "a parameter")},
::fast_io::native_process_args{"char",
L"wchar Double\"quotation\"marks",
u8"u8",
u"u16",
U"u32",
114514,
115145.1919810,
::fast_io::concat_fast_io("This ", 1, "s ", ::fast_io::mnp::code_cvt_os_c_str(u8"just "), "a parameter")},
{"env1",
L"env2",
3,
Expand Down
2 changes: 1 addition & 1 deletion examples/0035.process/pipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(int argc, char **argv)
::fast_io::iobuf_pipe pipe_err;
::fast_io::native_process p{
::fast_io::mnp::os_c_str(argv[1]),
{},
::fast_io::native_process_args{},
{},
{::fast_io::posix_dev_null(), pipe_out.handle, pipe_err.handle},
::fast_io::process_mode::none};
Expand Down
2 changes: 1 addition & 1 deletion examples/0035.process/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main(int argc, char **argv)
::fast_io::io::perr("Usage: ", ::fast_io::mnp::os_c_str(*argv), " <exe>\n");
return 1;
}
::fast_io::native_process p{::fast_io::mnp::os_c_str(argv[1]), {}, {}, {.in = fast_io::in(), .out = fast_io::out(), .err = fast_io::err()}, ::fast_io::process_mode::none};
::fast_io::native_process p{::fast_io::mnp::os_c_str(argv[1]), ::fast_io::native_process_args{}, {}, {.in = fast_io::in(), .out = fast_io::out(), .err = fast_io::err()}, ::fast_io::process_mode::none};
auto ec{wait(p)};
::fast_io::io::perrln(::fast_io::mnp::os_c_str(*argv), " -> Exit code: ", static_cast<int>(ec.wait_loc));
}
10 changes: 6 additions & 4 deletions examples/0040.thread/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

int main()
{
#ifdef _WIN32 // temporaryly disable this example on rest platforms
auto t = ::fast_io::thread{[](int param)
auto t = ::fast_io::native_thread{[](int param)
#if __cpp_static_call_operator >= 2020207L
static
#endif
Expand All @@ -16,6 +15,8 @@ int main()
#else
::fast_io::println("the child thread id is: ", ::fast_io::mnp::pointervw(::fast_io::this_thread::get_id()));
#endif
#else
::fast_io::println("the child thread id is: ", ::fast_io::this_thread::get_id());
#endif
// ::fflush(stdout);
::fast_io::this_thread::sleep_for(::std::chrono::seconds{1});
Expand All @@ -29,8 +30,9 @@ int main()
#else
::fast_io::println("the parent thread id is: ", ::fast_io::mnp::pointervw(::fast_io::this_thread::get_id()));
#endif
#else
::fast_io::println("the parent thread id is: ", ::fast_io::this_thread::get_id());
#endif

return 0;
#endif

}
5 changes: 5 additions & 0 deletions include/fast_io_core_impl/buffer_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ struct basic_obuffer_view
{
return static_cast<::std::size_t>(end_ptr - begin_ptr);
}

inline constexpr bool empty() const noexcept
{
return begin_ptr == curr_ptr;
}
};

template <::std::integral char_type>
Expand Down
98 changes: 71 additions & 27 deletions include/fast_io_driver/install_path/argv0.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <limits.h>
#include <stdlib.h>
#include <cstring>
#include <unistd.h>

#ifndef PATH_MAX
#define PATH_MAX 4096
Expand All @@ -20,7 +21,7 @@ inline ::fast_io::install_path get_module_install_path_from_argv0(char const *ar
{
if (!argv0) [[unlikely]]
{
throw_posix_error();
throw_posix_error(EINVAL);
}

::fast_io::install_path ret;
Expand All @@ -36,10 +37,13 @@ inline ::fast_io::install_path get_module_install_path_from_argv0(char const *ar
char path_list_separator[8] = ":"; // could be ":; "
if (argv0[0] == path_separator)
{
[[maybe_unused]] auto const unused1{::fast_io::noexcept_call(realpath, argv0, newpath)};
if (auto status{::fast_io::noexcept_call(access, newpath, F_OK)}; !status)
char *rp{::fast_io::noexcept_call(::realpath, argv0, newpath)};
if (!rp) [[unlikely]]
{
throw_posix_error();
}
if (::fast_io::noexcept_call(::access, newpath, F_OK) == 0)
{
newpath[PATH_MAX - 1] = 0;
ret.module_name = ::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt_os_c_str(newpath));
auto const begin{strlike_begin(::fast_io::io_strlike_type<char8_t, ::fast_io::u8string>, ret.module_name)};
auto curr{strlike_curr(::fast_io::io_strlike_type<char8_t, ::fast_io::u8string>, ret.module_name)};
Expand All @@ -57,18 +61,39 @@ inline ::fast_io::install_path get_module_install_path_from_argv0(char const *ar
}
else
{
throw_posix_error(status);
throw_posix_error();
}
}
else if (__builtin_strchr(argv0, static_cast<int>(path_separator)))
{
[[maybe_unused]] auto const unused1{::fast_io::noexcept_call(getcwd, newpath2, PATH_MAX)};
::fast_io::noexcept_call(strncat, newpath2, path_separator_as_string, PATH_MAX + 256);
::fast_io::noexcept_call(strncat, newpath2, argv0, PATH_MAX + 256);
[[maybe_unused]] auto const unused2{::fast_io::noexcept_call(realpath, newpath2, newpath)};
if (auto status{::fast_io::noexcept_call(access, newpath, F_OK)};!status)
if (!::fast_io::noexcept_call(::getcwd, newpath2, PATH_MAX)) [[unlikely]]
{
throw_posix_error();
}
{
auto const used1{::std::strlen(newpath2)};
if (used1 + 1 >= sizeof(newpath2)) [[unlikely]]
{
throw_posix_error(ERANGE);
}
::fast_io::noexcept_call(::strncat, newpath2, path_separator_as_string, sizeof(newpath2) - used1 - 1);
}
{
auto const used2{::std::strlen(newpath2)};
auto const add2{::std::strlen(argv0)};
if (used2 + add2 >= sizeof(newpath2)) [[unlikely]]
{
throw_posix_error(ERANGE);
}
::fast_io::noexcept_call(::strncat, newpath2, argv0, sizeof(newpath2) - used2 - 1);
}
char *rp2{::fast_io::noexcept_call(::realpath, newpath2, newpath)};
if (!rp2) [[unlikely]]
{
throw_posix_error();
}
if (::fast_io::noexcept_call(::access, newpath, F_OK) == 0)
{
newpath[PATH_MAX - 1] = 0;
ret.module_name = ::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt_os_c_str(newpath));
auto const begin{strlike_begin(::fast_io::io_strlike_type<char8_t, ::fast_io::u8string>, ret.module_name)};
auto curr{strlike_curr(::fast_io::io_strlike_type<char8_t, ::fast_io::u8string>, ret.module_name)};
Expand All @@ -84,26 +109,45 @@ inline ::fast_io::install_path get_module_install_path_from_argv0(char const *ar
ret.module_name.erase(begin, curr);
return ret;
}
else
{
throw_posix_error(status);
}
throw_posix_error();
}
else
{
char *saveptr;
char *pathitem;
char *save_path{::fast_io::noexcept_call(getenv, "PATH")};
for (pathitem = ::fast_io::noexcept_call(strtok_r, save_path, path_list_separator, &saveptr); pathitem;
pathitem = ::fast_io::noexcept_call(strtok_r, nullptr, path_list_separator, &saveptr))
char *saveptr{};
char *pathitem{};
char const *env_path{::fast_io::noexcept_call(::getenv, "PATH")};
if (!env_path) [[unlikely]]
{
throw_posix_error(EINVAL);
}
char pathbuf[PATH_MAX + 256 + 1]{};
::fast_io::noexcept_call(::strncpy, pathbuf, env_path, PATH_MAX + 256);
pathbuf[PATH_MAX + 256] = 0;

for (pathitem = ::fast_io::noexcept_call(::strtok_r, pathbuf, path_list_separator, &saveptr); pathitem;
pathitem = ::fast_io::noexcept_call(::strtok_r, nullptr, path_list_separator, &saveptr))
{
::fast_io::noexcept_call(strncpy, newpath2, pathitem, PATH_MAX + 256);
::fast_io::noexcept_call(strncat, newpath2, path_separator_as_string, PATH_MAX + 256);
::fast_io::noexcept_call(strncat, newpath2, argv0, PATH_MAX + 256);
[[maybe_unused]] auto const unused1{::realpath(newpath2, newpath)};
if (!::fast_io::noexcept_call(access, newpath, F_OK))
::fast_io::noexcept_call(::strncpy, newpath2, pathitem, PATH_MAX + 256);
{
auto const used1{::std::strlen(newpath2)};
if (used1 + 1 >= sizeof(newpath2)) [[unlikely]]
{
continue;
}
::fast_io::noexcept_call(::strncat, newpath2, path_separator_as_string, sizeof(newpath2) - used1 - 1);
}
{
auto const used2{::std::strlen(newpath2)};
auto const add2{::std::strlen(argv0)};
if (used2 + add2 >= sizeof(newpath2)) [[unlikely]]
{
continue;
}
::fast_io::noexcept_call(::strncat, newpath2, argv0, sizeof(newpath2) - used2 - 1);
}
char *rp{::fast_io::noexcept_call(::realpath, newpath2, newpath)};
if (rp && ::fast_io::noexcept_call(::access, newpath, F_OK) == 0)
{
newpath[PATH_MAX - 1] = 0;
ret.module_name = ::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt_os_c_str(newpath));
auto const begin{strlike_begin(::fast_io::io_strlike_type<char8_t, ::fast_io::u8string>, ret.module_name)};
auto curr{strlike_curr(::fast_io::io_strlike_type<char8_t, ::fast_io::u8string>, ret.module_name)};
Expand All @@ -120,7 +164,7 @@ inline ::fast_io::install_path get_module_install_path_from_argv0(char const *ar
return ret;
}
} // end for
throw_posix_error();
throw_posix_error(EINVAL);

} // end else
}
Expand Down
6 changes: 3 additions & 3 deletions include/fast_io_driver/install_path/bsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ inline ::fast_io::install_path get_module_install_path()
#endif
::std::size_t size{PATH_MAX};

if (auto status{::fast_io::noexcept_call(::sysctl, mib, 4, buffer1, __builtin_addressof(size), nullptr, 0)}; !status) [[unlikely]]
if (auto status{::fast_io::noexcept_call(::sysctl, mib, 4, buffer1, __builtin_addressof(size), nullptr, 0)}; status == -1) [[unlikely]]
{
throw_posix_error(status);
throw_posix_error();
}

resolved = ::fast_io::noexcept_call(::realpath, buffer1, buffer2);

if (!resolved) [[unlikely]]
{
throw_posix_error(resolved);
throw_posix_error();
}

::fast_io::install_path ret;
Expand Down
9 changes: 8 additions & 1 deletion include/fast_io_driver/install_path/darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ inline ::fast_io::install_path get_module_install_path()
::std::uint_least32_t size{PATH_MAX};
if (::fast_io::noexcept_call(::_NSGetExecutablePath, buffer, __builtin_addressof(size)) == -1) [[unlikely]]
{
throw_posix_error();
if (size > PATH_MAX)
{
throw_posix_error(ERANGE);
}
else
{
throw_posix_error(EINVAL);
}
}
char buffer2[PATH_MAX + 1];
char *resolved{::fast_io::noexcept_call(::realpath, buffer, buffer2)};
Expand Down
11 changes: 9 additions & 2 deletions include/fast_io_driver/install_path/linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ namespace fast_io::details
#endif
inline ::fast_io::install_path get_module_install_path()
{
char buffer[PATH_MAX + 1];
constexpr ::std::size_t path_max{::std::max<::std::size_t>(PATH_MAX, 4096u)};

char buffer[path_max + 1];
::fast_io::install_path ret;

using my_ssize_t = ::std::make_signed_t<::std::size_t>;
#if defined(__linux__) && defined(__NR_readlink)
auto resolved{::fast_io::system_call<__NR_readlink, int>("/proc/self/exe", buffer, PATH_MAX)};
auto resolved{::fast_io::system_call<__NR_readlink, my_ssize_t>("/proc/self/exe", buffer, path_max)};
system_call_throw_error(resolved);
if (static_cast<::std::size_t>(resolved) >= path_max)
{
throw_posix_error(ERANGE);
}
buffer[resolved] = '\0';
ret.module_name = ::fast_io::u8concat_fast_io(::fast_io::mnp::code_cvt(::fast_io::mnp::os_c_str_with_known_size(buffer, resolved)));
#else
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_driver/install_path/null.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace fast_io::details
[[noreturn]]
inline void get_module_install_path()
{
throw_posix_error();
throw_posix_error(ENOTSUP);
}
} // namespace fast_io::details
2 changes: 1 addition & 1 deletion include/fast_io_driver/install_path/openbsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ inline ::fast_io::install_path get_module_install_path()

if (size > PATH_MAX) [[unlikely]]
{
throw_posix_error();
throw_posix_error(ERANGE);
}

if (::fast_io::noexcept_call(::sysctl, mib, 4, argv, __builtin_addressof(size), nullptr, 0) != 0) [[unlikely]]
Expand Down
8 changes: 8 additions & 0 deletions include/fast_io_dsal/impl/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,14 @@ class basic_string FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
{
this->append_impl(other.data(), other.size());
}
inline constexpr void append(char_type const *begin, char_type const *end) noexcept
{
this->append_impl(begin, static_cast<::std::size_t>(end - begin));
}
inline constexpr void append(char_type const *otherptr, size_type othern) noexcept
{
this->append_impl(otherptr, othern);
}

inline constexpr void clear() noexcept
{
Expand Down
Loading