fix: dont use self.error when it is not available

This commit is contained in:
dignifiedquire
2020-01-29 18:54:43 +01:00
parent 4498954918
commit 97afe582e1

View File

@@ -119,11 +119,15 @@ impl ContextWrapper {
match guard.as_ref() { match guard.as_ref() {
Some(ref ctx) => Ok(ctxfn(ctx)), Some(ref ctx) => Ok(ctxfn(ctx)),
None => { None => {
unsafe { self.error("context not open") }; eprintln!("context not open");
Err(()) Err(())
} }
} }
} }
fn is_open(&self) -> bool {
self.inner.read().unwrap().is_some()
}
} }
#[no_mangle] #[no_mangle]
@@ -143,6 +147,7 @@ pub unsafe extern "C" fn dc_context_new(
os_name, os_name,
inner: RwLock::new(None), inner: RwLock::new(None),
}; };
Box::into_raw(Box::new(ffi_ctx)) 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; return 0;
} }
let ffi_context = &*context; let ffi_context = &*context;
let inner_guard = ffi_context.inner.read().unwrap(); ffi_context.is_open() as libc::c_int
match *inner_guard {
Some(_) => 1,
None => 0,
}
} }
#[no_mangle] #[no_mangle]
@@ -389,6 +390,8 @@ pub unsafe extern "C" fn dc_is_configured(context: *mut dc_context_t) -> libc::c
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn dc_context_run(context: *mut dc_context_t, cb: Option<dc_callback_t>) { pub unsafe extern "C" fn dc_context_run(context: *mut dc_context_t, cb: Option<dc_callback_t>) {
eprintln!("dc_context_run");
if context.is_null() { if context.is_null() {
eprintln!("ignoring careless call to dc_run()"); eprintln!("ignoring careless call to dc_run()");
return; return;
@@ -396,9 +399,11 @@ pub unsafe extern "C" fn dc_context_run(context: *mut dc_context_t, cb: Option<d
let ffi_context = &*context; let ffi_context = &*context;
ffi_context ffi_context
.with_inner(|ctx| { .with_inner(|ctx| {
eprintln!("RUN");
ctx.run(|_ctx, event| { ctx.run(|_ctx, event| {
translate_cb(ffi_context, cb, event); translate_cb(ffi_context, cb, event);
}) });
eprintln!("RUN DONE");
}) })
.unwrap_or(()) .unwrap_or(())
} }
@@ -487,7 +492,13 @@ pub unsafe extern "C" fn dc_context_shutdown(context: *mut dc_context_t) {
return; return;
} }
let ffi_context = &*context; let ffi_context = &*context;
ffi_context.with_inner(|ctx| ctx.shutdown()).unwrap_or(()) ffi_context
.with_inner(|ctx| {
eprintln!("SHUTDOWN");
ctx.shutdown();
eprintln!("SHUTDOWN:DONE")
})
.unwrap_or(())
} }
#[no_mangle] #[no_mangle]