summaryrefslogtreecommitdiffstats
path: root/ffi/src
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-16 17:32:30 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-16 17:32:30 +0100
commit7244f9e566f95b105d4cc411edb00f1fe3874dc6 (patch)
treee88c7f5591b53e0798d435fbf152d98abea092ff /ffi/src
parentd480a7f2a94e4074d1c37b706b123a491a201d4f (diff)
ffi: Add new error-pointer-based error handling.
- Express existing context-based error handling using the new set of macros.
Diffstat (limited to 'ffi/src')
-rw-r--r--ffi/src/core.rs4
-rw-r--r--ffi/src/lib.rs18
2 files changed, 20 insertions, 2 deletions
diff --git a/ffi/src/core.rs b/ffi/src/core.rs
index ae614ed4..d1b74437 100644
--- a/ffi/src/core.rs
+++ b/ffi/src/core.rs
@@ -64,6 +64,10 @@ impl Context {
Context{c: c, e: ptr::null_mut()}
}
+ pub(crate) fn errp(&mut self) -> &mut *mut failure::Error {
+ &mut self.e
+ }
+
pub(crate) fn set_error(&mut self, e: failure::Error) {
if ! self.e.is_null() {
unsafe {
diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs
index 2085521c..f7202cc7 100644
--- a/ffi/src/lib.rs
+++ b/ffi/src/lib.rs
@@ -265,6 +265,16 @@ macro_rules! ffi_return_maybe_string {
/// to store complex errors.
macro_rules! ffi_make_fry_from_ctx {
($ctx:ident) => {
+ ffi_make_fry_from_errp!(Some($ctx.errp()))
+ }
+}
+
+/* Error handling with implicit error return argument. */
+
+/// Emits local macros for error handling that use the given context
+/// to store complex errors.
+macro_rules! ffi_make_fry_from_errp {
+ ($errp:expr) => {
/// Like try! for ffi glue.
///
/// Evaluates the given expression. On success, evaluate to
@@ -277,7 +287,9 @@ macro_rules! ffi_make_fry_from_ctx {
Ok(_) => Status::Success,
Err(e) => {
let status = Status::from(&e);
- $ctx.set_error(e);
+ if let Some(errp) = $errp {
+ *errp = box_raw!(e);
+ }
status
},
}
@@ -294,7 +306,9 @@ macro_rules! ffi_make_fry_from_ctx {
match $expr {
Ok(v) => v,
Err(e) => {
- $ctx.set_error(e);
+ if let Some(errp) = $errp {
+ *errp = box_raw!(e);
+ }
return $or;
},
}