summaryrefslogtreecommitdiffstats
path: root/ffi/src
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-16 17:08:29 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-16 17:08:29 +0100
commitd480a7f2a94e4074d1c37b706b123a491a201d4f (patch)
treec0a68d354f811fdc29edb27a9e5bf53728853478 /ffi/src
parent4477f74b07070bdd95a228cd4b97dd5f9fb70aaf (diff)
ffi: Store raw pointers to errors in the Context.
Diffstat (limited to 'ffi/src')
-rw-r--r--ffi/src/core.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/ffi/src/core.rs b/ffi/src/core.rs
index 05cd1279..ae614ed4 100644
--- a/ffi/src/core.rs
+++ b/ffi/src/core.rs
@@ -56,16 +56,21 @@ use sequoia_core::Config;
#[doc(hidden)]
pub struct Context {
pub(crate) c: core::Context,
- e: Option<failure::Error>,
+ e: *mut failure::Error,
}
impl Context {
fn new(c: core::Context) -> Self {
- Context{c: c, e: None}
+ Context{c: c, e: ptr::null_mut()}
}
pub(crate) fn set_error(&mut self, e: failure::Error) {
- self.e = Some(e);
+ if ! self.e.is_null() {
+ unsafe {
+ drop(Box::from_raw(self.e));
+ }
+ }
+ self.e = box_raw!(e);
}
}
@@ -76,7 +81,7 @@ impl Context {
pub extern "system" fn sq_context_last_error(ctx: *mut Context)
-> *mut failure::Error {
let ctx = ffi_param_ref_mut!(ctx);
- maybe_box_raw!(ctx.e.take())
+ ::std::mem::replace(&mut ctx.e, ptr::null_mut())
}
/// Creates a Context with reasonable defaults.