Skip to content

Commit

Permalink
pass NullUpdateHandler when C wrapper receives null
Browse files Browse the repository at this point in the history
  • Loading branch information
Remy Wang authored and ryzhyk committed Jul 16, 2019
1 parent 5c0f67a commit 249472e
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions rust/template/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,20 @@ pub extern "C" fn ddlog_run(
cb_arg: libc::uintptr_t,
print_err: Option<extern "C" fn(msg: *const raw::c_char)>) -> *const HDDlog
{
extern "C" fn no_op(_arg: libc::uintptr_t,
_table: libc::size_t,
_rec: *const record::Record,
_pol: bool) {};

let callback = if let Some(f) = cb { f } else { no_op };

Arc::into_raw(Arc::new(
HDDlog::do_run(workers as usize,
do_store,
ExternCUpdateHandler::new(callback, cb_arg),
print_err)))

if let Some(f) = cb {
Arc::into_raw(Arc::new(
HDDlog::do_run(workers as usize,
do_store,
ExternCUpdateHandler::new(f, cb_arg),
print_err)))
} else {
Arc::into_raw(Arc::new(
HDDlog::do_run(workers as usize,
do_store,
NullUpdateHandler::new(),
print_err)))
}
}

#[no_mangle]
Expand Down

0 comments on commit 249472e

Please sign in to comment.