aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2022-10-15 13:10:09 -0700
committerDavid Tolnay <dtolnay@gmail.com>2022-10-15 14:17:26 -0700
commitd1afb26f4b3ee3a6729ba71c693727ac9e2f4e49 (patch)
tree7c2cdf0e83153289493cafca5ed52f5dcf14fb2a /src
parent5ab0a485cc243d83cd717de4301c3615fb012d0a (diff)
downloadcxx-d1afb26f4b3ee3a6729ba71c693727ac9e2f4e49.tar.gz
Factor out the Fail lambda from all trycatch calls
Diffstat (limited to 'src')
-rw-r--r--src/cxx.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/cxx.cc b/src/cxx.cc
index 1601a05a..c0e96d40 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -68,6 +68,9 @@ void cxxbridge1$slice$new(void *self, const void *ptr,
std::size_t len) noexcept;
void *cxxbridge1$slice$ptr(const void *self) noexcept;
std::size_t cxxbridge1$slice$len(const void *self) noexcept;
+
+// try/catch
+const char *cxxbridge1$exception(const char *, std::size_t len) noexcept;
} // extern "C"
namespace rust {
@@ -506,6 +509,13 @@ union MaybeUninit {
};
} // namespace
+namespace repr {
+struct PtrLen final {
+ void *ptr;
+ std::size_t len;
+};
+} // namespace repr
+
namespace detail {
// On some platforms size_t is the same C++ type as one of the sized integer
// types; on others it is a distinct type. Only in the latter case do we need to
@@ -519,6 +529,19 @@ using isize_if_unique =
typename std::conditional<std::is_same<rust::isize, int64_t>::value ||
std::is_same<rust::isize, int32_t>::value,
struct isize_ignore, rust::isize>::type;
+
+class Fail final {
+ repr::PtrLen &throw$;
+
+public:
+ Fail(repr::PtrLen &throw$) : throw$(throw$) {}
+ void operator()(const char *) noexcept;
+};
+
+void Fail::operator()(const char *catch$) noexcept {
+ throw$.len = std::strlen(catch$);
+ throw$.ptr = const_cast<char *>(cxxbridge1$exception(catch$, throw$.len));
+}
} // namespace detail
} // namespace cxxbridge1