Skip to content

Commit

Permalink
Remove the need for C++ exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Arastais committed Jan 21, 2025
1 parent 5256014 commit ef90bd3
Show file tree
Hide file tree
Showing 49 changed files with 239 additions and 215 deletions.
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 ccd234d05eb6611ffc686aabc781f93e0a1c3349
#define LLFIO_PREVIOUS_COMMIT_DATE "2024-12-21 16:36:10 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE ccd234d0
#define LLFIO_PREVIOUS_COMMIT_REF 39587fdce8abecbe931c9c24db53f8b7672633e8
#define LLFIO_PREVIOUS_COMMIT_DATE "2025-01-21 00:52:41 +00:00"
#define LLFIO_PREVIOUS_COMMIT_UNIQUE 39587fdc
12 changes: 6 additions & 6 deletions include/llfio/v2.0/algorithm/contents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace algorithm

static std::shared_ptr<contents_type> _thread_contents(_state_type *state) noexcept
{
try
LLFIO_TRY
{
static thread_local std::weak_ptr<contents_type> mycontents;
auto ret = mycontents.lock();
Expand All @@ -103,7 +103,7 @@ namespace algorithm
state->all_thread_contents.push_back(ret);
return ret;
}
catch(...)
LLFIO_CATCH(...)
{
return {};
}
Expand All @@ -116,7 +116,7 @@ namespace algorithm
*/
virtual result<void> post_enumeration(void *data, const directory_handle &dirh, directory_handle::buffers_type &contents, size_t depth) noexcept
{
try
LLFIO_TRY
{
auto *state = (_state_type *) data;
(void) depth;
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace algorithm
}
return success();
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand All @@ -183,7 +183,7 @@ namespace algorithm
*/
virtual result<size_t> finished(void *data, result<size_t> result) noexcept
{
try
LLFIO_TRY
{
auto *state = (_state_type *) data;
state->contents.clear();
Expand All @@ -201,7 +201,7 @@ namespace algorithm
state->all_thread_contents.clear();
return result;
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand Down
4 changes: 2 additions & 2 deletions include/llfio/v2.0/algorithm/difference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace algorithm
//! This override implements the summary
virtual result<void> post_enumeration(void *data, const directory_handle &dirh, directory_handle::buffers_type &contents, size_t depth) noexcept override
{
try
LLFIO_TRY
{
auto *state = (comparison_summary *) data;
comparison_summary acc;
Expand All @@ -81,7 +81,7 @@ namespace algorithm
state->operator+=(acc);
return success();
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand Down
12 changes: 6 additions & 6 deletions include/llfio/v2.0/algorithm/handle_adapter/cached_parent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ namespace algorithm
OUTCOME_TRYV(adapted_handle_type::relink(base, newpath, atomic_replace, d));
_sph.reset();
_leafname.clear();
try
LLFIO_TRY
{
auto r = detail::get_cached_path_handle(base, newpath);
_sph = std::move(r.first);
_leafname = std::move(r.second);
return success();
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand All @@ -182,11 +182,11 @@ namespace algorithm
{
construct<T> constructor{std::forward<Args>(args)...};
OUTCOME_TRY(auto &&h, constructor());
try
LLFIO_TRY
{
return cached_parent_handle_adapter<T>(std::move(h), constructor.base, constructor._path);
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand All @@ -201,11 +201,11 @@ template <class T> struct construct<algorithm::cached_parent_handle_adapter<T>>
result<algorithm::cached_parent_handle_adapter<T>> operator()() const noexcept
{
OUTCOME_TRY(auto &&h, args());
try
LLFIO_TRY
{
return algorithm::cached_parent_handle_adapter<T>(std::move(h), args.base, args._path);
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand Down
4 changes: 2 additions & 2 deletions include/llfio/v2.0/algorithm/shared_fs_mutex/memory_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace algorithm
static result<memory_map> fs_mutex_map(const path_handle &base, path_view lockfile) noexcept
{
LLFIO_LOG_FUNCTION_CALL(0);
try
LLFIO_TRY
{
OUTCOME_TRY(auto &&ret, file_handle::file(base, lockfile, file_handle::mode::write, file_handle::creation::if_needed, file_handle::caching::reads));
file_handle temph;
Expand Down Expand Up @@ -263,7 +263,7 @@ namespace algorithm
lockinuse = std::move(lockinuse2); // releases exclusive lock on all three offsets
return memory_map(std::move(ret), std::move(temph), std::move(lockinuse.value()), std::move(hmap), std::move(temphmap));
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand Down
4 changes: 2 additions & 2 deletions include/llfio/v2.0/algorithm/summarize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ namespace algorithm
//! This override implements the summary
virtual result<void> post_enumeration(void *data, const directory_handle &dirh, directory_handle::buffers_type &contents, size_t depth) noexcept override
{
try
LLFIO_TRY
{
auto *state = (traversal_summary *) data;
traversal_summary acc;
Expand All @@ -248,7 +248,7 @@ namespace algorithm
state->operator+=(acc);
return success();
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand Down
10 changes: 5 additions & 5 deletions include/llfio/v2.0/algorithm/trivial_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ namespace algorithm
{
if(i >= size())
{
throw std::out_of_range("bounds exceeded"); // NOLINT
LLFIO_THROW std::out_of_range("bounds exceeded"); // NOLINT
}
return _begin[i];
}
Expand All @@ -257,7 +257,7 @@ namespace algorithm
{
if(i >= size())
{
throw std::out_of_range("bounds exceeded"); // NOLINT
LLFIO_THROW std::out_of_range("bounds exceeded"); // NOLINT
}
return _begin[i];
}
Expand Down Expand Up @@ -314,7 +314,7 @@ namespace algorithm
{
if(n > max_size())
{
throw std::length_error("Max size exceeded"); // NOLINT
LLFIO_THROW std::length_error("Max size exceeded"); // NOLINT
}
size_type current_size = size();
size_type bytes = n * sizeof(value_type);
Expand Down Expand Up @@ -435,11 +435,11 @@ namespace algorithm
// Trivially copyable, so memmove
memmove(pos._v + 1, pos._v, (_end - pos._v) * sizeof(value_type));
// BUT complex constructors may throw!
try
LLFIO_TRY
{
new(pos._v) value_type(std::forward<Args>(args)...);
}
catch(...)
LLFIO_CATCH(...)
{
memmove(pos._v, pos._v + 1, (_end - pos._v) * sizeof(value_type));
throw;
Expand Down
17 changes: 14 additions & 3 deletions include/llfio/v2.0/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ Distributed under the Boost Software License, Version 1.0.
#include "quickcpplib/cpp_feature.h"

#ifndef STANDARDESE_IS_IN_THE_HOUSE
#ifndef __cpp_exceptions
#error LLFIO needs C++ exceptions to be turned on
#endif
#ifndef __cpp_alias_templates
#error LLFIO needs template alias support in the compiler
#endif
Expand Down Expand Up @@ -166,6 +163,20 @@ Distributed under the Boost Software License, Version 1.0.
#error LLFIO needs an implementation of the Filesystem TS in the standard library
#endif
#endif
#ifndef __cpp_exceptions
#define LLFIO_TRY if (true)
#define LLFIO_CATCH(x) if (false)
#define LLFIO_CATCH_SPECIFIC_BEGIN(x) (void)([&](x) {
#define LLFIO_CATCH_SPECIFIC_END });
#define LLFIO_THROW
#else
// Else proceed normally.
#define LLFIO_TRY try
#define LLFIO_CATCH(e) catch(e)
#define LLFIO_CATCH_SPECIFIC_BEGIN(e) LLFIO_CATCH(e) {
#define LLFIO_CATCH_SPECIFIC_END }
#define LLFIO_THROW throw
#endif
#endif


Expand Down
2 changes: 1 addition & 1 deletion include/llfio/v2.0/deadline.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct LLFIO_DEADLINE_NAME
{
if(steady)
{
throw std::invalid_argument("Not a UTC deadline!"); // NOLINT
LLFIO_THROW std::invalid_argument("Not a UTC deadline!"); // NOLINT
}
std::chrono::system_clock::time_point tp(std::chrono::system_clock::from_time_t(utc.tv_sec));
tp += std::chrono::duration_cast<std::chrono::system_clock::duration>(std::chrono::nanoseconds(utc.tv_nsec));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace algorithm
}
LLFIO_HEADERS_ONLY_MEMFUNC_SPEC result<filesystem::path> cached_path_handle::current_path(const filesystem::path &append) noexcept
{
try
LLFIO_TRY
{
auto ret = h.current_path();
auto &map = cached_path_handle_map();
Expand All @@ -65,7 +65,7 @@ namespace algorithm
}
return _lastpath / append;
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand Down
8 changes: 4 additions & 4 deletions include/llfio/v2.0/detail/impl/clone.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace algorithm
bool preserve_timestamps, bool force_copy_now, file_handle::creation creation,
deadline d) noexcept
{
try
LLFIO_TRY
{
LLFIO_LOG_FUNCTION_CALL(&src);
filesystem::path destleaf_;
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace algorithm
failed = false;
return copied.length;
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand All @@ -113,7 +113,7 @@ namespace algorithm
LLFIO_HEADERS_ONLY_FUNC_SPEC result<bool> relink_or_clone_copy_unlink(file_handle &src, const path_handle &destdir, path_view destleaf, bool atomic_replace,
bool preserve_timestamps, bool force_copy_now, deadline d) noexcept
{
try
LLFIO_TRY
{
LLFIO_LOG_FUNCTION_CALL(&src);
filesystem::path destleaf_;
Expand Down Expand Up @@ -229,7 +229,7 @@ namespace algorithm
OUTCOME_TRY(src._replace_handle(std::move(desth)));
return true;
}
catch(...)
LLFIO_CATCH(...)
{
return error_from_exception();
}
Expand Down
Loading

0 comments on commit ef90bd3

Please sign in to comment.