Skip to content

Commit

Permalink
Actual last round of fixes to enable working with C++ exceptions glob…
Browse files Browse the repository at this point in the history
…ally disabled.

Should close #156.
  • Loading branch information
ned14 committed Feb 2, 2025
1 parent f1c330b commit bb2264e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 28 deletions.
4 changes: 1 addition & 3 deletions .ci.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ ctest_start("Experimental")
#ctest_update()
message(STATUS "NOTE: CTEST_CONFIGURE_OPTIONS are '${CTEST_CONFIGURE_OPTIONS}'")
ctest_configure(OPTIONS "${CTEST_CONFIGURE_OPTIONS}")
if(NOT "$ENV{CXX}" MATCHES "g\\+\\+") ## Avoid ICE for header only build in GCC
ctest_build(TARGET _hl)
endif()
ctest_build(TARGET _hl)
ctest_build(TARGET _dl)
ctest_build(TARGET _sl)
set(retval 0)
Expand Down
8 changes: 2 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,13 @@ if(NOT llfio_IS_DEPENDENCY AND (NOT DEFINED BUILD_TESTING OR BUILD_TESTING))
if(testtarget MATCHES "llfio_hl--(.+)$")
set(testname ${CMAKE_MATCH_1})
if(TRUE)
get_target_property(testsource ${testtarget} SOURCES)
get_target_property(testsource ${testtarget} SOURCES)
set(target_name "llfio_hl--${testname}-noexcept")
add_executable(${target_name} "${testsource}")
if(NOT first_test_target_noexcept)
set(first_test_target_noexcept ${target_name})
elseif(${target_name} MATCHES "coroutines")
set_target_properties(${target_name} PROPERTIES DISABLE_PRECOMPILE_HEADERS On)
elseif(COMMAND target_precompile_headers)
target_precompile_headers(${target_name} REUSE_FROM ${first_test_target_noexcept})
endif()
set_target_properties(${target_name} PROPERTIES DISABLE_PRECOMPILE_HEADERS On)
target_link_libraries(${target_name} PRIVATE kerneltest::hl)
add_dependencies(_hl ${target_name})
list(APPEND noexcept_tests ${target_name})
Expand All @@ -496,7 +493,6 @@ if(NOT llfio_IS_DEPENDENCY AND (NOT DEFINED BUILD_TESTING OR BUILD_TESTING))
target_compile_options(${target_name} PRIVATE /wd4530 /wd4577)
# target_compile_options(${target_name} PRIVATE /permissive-) # test bug report #142
endif()
target_compile_definitions(${target_name} PRIVATE SYSTEM_ERROR2_NOT_POSIX=1 "SYSTEM_ERROR2_FATAL=::abort()")
target_link_libraries(${target_name} PRIVATE llfio::hl)
set_target_properties(${target_name} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
Expand Down
6 changes: 3 additions & 3 deletions include/llfio/revision.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time
#define LLFIO_PREVIOUS_COMMIT_REF 9f177f7efca5759943481a7529b3dccaecc320d9
#define LLFIO_PREVIOUS_COMMIT_DATE "2025-01-28 12:31:08 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 9f177f7e
#define LLFIO_PREVIOUS_COMMIT_REF f1c330b0dc70ba344a606264e0997cd080faacfa
#define LLFIO_PREVIOUS_COMMIT_DATE "2025-01-29 12:48:45 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE f1c330b0
7 changes: 5 additions & 2 deletions include/llfio/v2.0/algorithm/handle_adapter/cached_parent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ namespace algorithm
*/
template <class T> LLFIO_REQUIRES(sizeof(construct<T>) > 0) class LLFIO_DECL cached_parent_handle_adapter : public T
{
static_assert(sizeof(construct<T>) > 0, "Type T must be registered with the construct<T> framework so cached_parent_handle_adapter<T> knows how to construct it"); // NOLINT
static_assert(sizeof(construct<T>) > 0,
"Type T must be registered with the construct<T> framework so cached_parent_handle_adapter<T> knows how to construct it"); // NOLINT

public:
//! The handle type being adapted
Expand Down Expand Up @@ -162,6 +163,7 @@ namespace algorithm
{
return error_from_exception();
}
abort();
}
LLFIO_HEADERS_ONLY_VIRTUAL_SPEC
result<void> unlink(deadline d = std::chrono::seconds(30)) noexcept override
Expand All @@ -178,7 +180,7 @@ namespace algorithm
This function works via the `construct<T>()` free function framework for which your `handle`
implementation must have registered its construction details.
*/
template <class T, class... Args> inline result<cached_parent_handle_adapter<T>> cache_parent(Args &&... args) noexcept
template <class T, class... Args> inline result<cached_parent_handle_adapter<T>> cache_parent(Args &&...args) noexcept
{
construct<T> constructor{std::forward<Args>(args)...};
OUTCOME_TRY(auto &&h, constructor());
Expand Down Expand Up @@ -209,6 +211,7 @@ template <class T> struct construct<algorithm::cached_parent_handle_adapter<T>>
{
return error_from_exception();
}
abort();
}
};

Expand Down
2 changes: 2 additions & 0 deletions include/llfio/v2.0/detail/impl/posix/file_handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ result<std::vector<file_handle::extent_pair>> file_handle::extents() const noexc
{
return error_from_exception();
}
abort();
}

result<file_handle::extent_pair> file_handle::clone_extents_to(file_handle::extent_pair extent, byte_io_handle &dest_, byte_io_handle::extent_type destoffset,
Expand Down Expand Up @@ -1031,6 +1032,7 @@ result<file_handle::extent_type> file_handle::zero(file_handle::extent_pair exte
{
return error_from_exception();
}
abort();
}

LLFIO_V2_NAMESPACE_END
7 changes: 5 additions & 2 deletions include/llfio/v2.0/detail/impl/posix/handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ result<handle::path_type> handle::current_path() const noexcept
ret.resize(32769);
char *out = const_cast<char *>(ret.data());
// Yes, this API is instant memory corruption. Thank you Apple.
if(-1 == fcntl(_v.fd, F_GETPATH, out)) {
if(-1 == fcntl(_v.fd, F_GETPATH, out))
{
// Newer Mac OS usefully returns ENOENT if the file is deleted,
// rather than the previous path
if(ENOENT == errno) {
if(ENOENT == errno)
{
ret.clear();
return ret;
}
Expand Down Expand Up @@ -134,6 +136,7 @@ result<handle::path_type> handle::current_path() const noexcept
{
return error_from_exception();
}
abort();
}

result<void> handle::close() noexcept
Expand Down
13 changes: 7 additions & 6 deletions include/llfio/v2.0/detail/impl/posix/symlink_handle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<void> symlink_handle::_create_symlink(con
{
return error_from_exception();
}
abort();
}

result<symlink_handle> symlink_handle::reopen(mode mode_, deadline d) const noexcept
Expand Down Expand Up @@ -330,13 +331,13 @@ LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<symlink_handle> symlink_handle::symlink(c
}
else
#if !LLFIO_SYMLINK_HANDLE_IS_FAKED // always take a dirh if faking the handle for race safety
if(!path_parent.empty())
if(!path_parent.empty())
#endif
{
// If faking the symlink, write this directly into the member variable cache
OUTCOME_TRY(*dirh, path_handle::path(base, path_parent.empty() ? "." : path_parent));
dirhfd = dirh->native_handle().fd;
}
{
// If faking the symlink, write this directly into the member variable cache
OUTCOME_TRY(*dirh, path_handle::path(base, path_parent.empty() ? "." : path_parent));
dirhfd = dirh->native_handle().fd;
}
}
LLFIO_EXCEPTION_CATCH_ALL
{
Expand Down
18 changes: 13 additions & 5 deletions include/llfio/v2.0/status_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ as that (a) enables safe header only LLFIO on Windows (b) produces better codege
// Bring in status code utility
#include "outcome/experimental/coroutine_support.hpp"
#if !OUTCOME_USE_SYSTEM_STATUS_CODE && __has_include("outcome/experimental/status-code/include/status-code/system_code_from_exception.hpp")
#ifdef __cpp_exceptions
#include "outcome/experimental/status-code/include/status-code/system_code_from_exception.hpp"
#endif
#else
#ifdef __cpp_exceptions
#include <status-code/system_code_from_exception.hpp>
#endif
#endif
#if !defined(LLFIO_ENABLE_COROUTINES) && defined(OUTCOME_FOUND_COROUTINE_HEADER)
#define LLFIO_ENABLE_COROUTINES 1
#endif
Expand Down Expand Up @@ -309,11 +313,11 @@ using file_io_error = SYSTEM_ERROR2_NAMESPACE::erased_errored_status_code<detail
template <class T> using result = OUTCOME_V2_NAMESPACE::experimental::status_result<T, file_io_error>;
#else
template <class T> using result = OUTCOME_V2_NAMESPACE::experimental::status_result<T, file_io_error, OUTCOME_V2_NAMESPACE::policy::terminate>;
inline error_info error_from_exception(std::exception_ptr && = std::current_exception(),
std::error_code = std::make_error_code(std::errc::resource_unavailable_try_again)) noexcept
{
abort(); // should never be called
}
// inline std::error_code error_from_exception(std::exception_ptr && = std::current_exception(),
// std::error_code = std::make_error_code(std::errc::resource_unavailable_try_again)) noexcept
//{
// abort(); // should never be called
// }
#endif
using OUTCOME_V2_NAMESPACE::failure;
using OUTCOME_V2_NAMESPACE::in_place_type;
Expand Down Expand Up @@ -379,8 +383,12 @@ namespace detail
inline file_io_error error_from_exception(std::exception_ptr &&ep = std::current_exception(),
SYSTEM_ERROR2_NAMESPACE::system_code not_matched = errc::resource_unavailable_try_again) noexcept
{
#ifdef __cpp_exceptions
return SYSTEM_ERROR2_NAMESPACE::system_code_from_exception(static_cast<std::exception_ptr &&>(ep),
static_cast<SYSTEM_ERROR2_NAMESPACE::system_code &&>(not_matched));
#else
abort();
#endif
}

LLFIO_V2_NAMESPACE_END
Expand Down
2 changes: 1 addition & 1 deletion test/tests/issue0102.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Distributed under the Boost Software License, Version 1.0.

static inline void TestIssue0102()
{
#if !LLFIO_EXPERIMENTAL_STATUS_CODE
#if !LLFIO_EXPERIMENTAL_STATUS_CODE || !defined(__cpp_exceptions)
return;
#else
namespace llfio = LLFIO_V2_NAMESPACE;
Expand Down

0 comments on commit bb2264e

Please sign in to comment.