diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index db37ffb42..a46149ce4 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -119,11 +119,15 @@ impl ContextWrapper { match guard.as_ref() { Some(ref ctx) => Ok(ctxfn(ctx)), None => { - unsafe { self.error("context not open") }; + eprintln!("context not open"); Err(()) } } } + + fn is_open(&self) -> bool { + self.inner.read().unwrap().is_some() + } } #[no_mangle] @@ -143,6 +147,7 @@ pub unsafe extern "C" fn dc_context_new( os_name, inner: RwLock::new(None), }; + Box::into_raw(Box::new(ffi_ctx)) } @@ -217,11 +222,7 @@ pub unsafe extern "C" fn dc_is_open(context: *mut dc_context_t) -> libc::c_int { return 0; } let ffi_context = &*context; - let inner_guard = ffi_context.inner.read().unwrap(); - match *inner_guard { - Some(_) => 1, - None => 0, - } + ffi_context.is_open() as libc::c_int } #[no_mangle] @@ -389,6 +390,8 @@ pub unsafe extern "C" fn dc_is_configured(context: *mut dc_context_t) -> libc::c #[no_mangle] pub unsafe extern "C" fn dc_context_run(context: *mut dc_context_t, cb: Option) { + eprintln!("dc_context_run"); + if context.is_null() { eprintln!("ignoring careless call to dc_run()"); return; @@ -396,9 +399,11 @@ pub unsafe extern "C" fn dc_context_run(context: *mut dc_context_t, cb: Option