Skip to content

Commit 06325bb

Browse files
committed
Don't use NULL values for extern "C" fn in the C API
1 parent cb98c0c commit 06325bb

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/for_c/tokenizer.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ use libc::{c_void, c_int, size_t};
2525

2626
#[repr(C)]
2727
pub struct h5e_token_ops {
28-
do_doctype: extern "C" fn(user: *mut c_void, name: h5e_buf,
29-
public: h5e_buf, system: h5e_buf, force_quirks: c_int),
30-
31-
do_start_tag: extern "C" fn(user: *mut c_void, name: h5e_buf,
32-
self_closing: c_int, num_attrs: size_t),
33-
34-
do_tag_attr: extern "C" fn(user: *mut c_void, name: h5e_buf, value: h5e_buf),
35-
do_end_tag: extern "C" fn(user: *mut c_void, name: h5e_buf),
36-
do_comment: extern "C" fn(user: *mut c_void, text: h5e_buf),
37-
do_chars: extern "C" fn(user: *mut c_void, text: h5e_buf),
38-
do_null_char: extern "C" fn(user: *mut c_void),
39-
do_eof: extern "C" fn(user: *mut c_void),
40-
do_error: extern "C" fn(user: *mut c_void, message: h5e_buf),
28+
do_doctype: Option<extern "C" fn(user: *mut c_void, name: h5e_buf,
29+
public: h5e_buf, system: h5e_buf, force_quirks: c_int)>,
30+
31+
do_start_tag: Option<extern "C" fn(user: *mut c_void, name: h5e_buf,
32+
self_closing: c_int, num_attrs: size_t)>,
33+
34+
do_tag_attr: Option<extern "C" fn(user: *mut c_void, name: h5e_buf, value: h5e_buf)>,
35+
do_end_tag: Option<extern "C" fn(user: *mut c_void, name: h5e_buf)>,
36+
do_comment: Option<extern "C" fn(user: *mut c_void, text: h5e_buf)>,
37+
do_chars: Option<extern "C" fn(user: *mut c_void, text: h5e_buf)>,
38+
do_null_char: Option<extern "C" fn(user: *mut c_void)>,
39+
do_eof: Option<extern "C" fn(user: *mut c_void)>,
40+
do_error: Option<extern "C" fn(user: *mut c_void, message: h5e_buf)>,
4141
}
4242

4343
#[repr(C)]
@@ -50,8 +50,9 @@ impl TokenSink for h5e_token_sink {
5050
fn process_token(&mut self, token: Token) {
5151
macro_rules! call ( ($name:ident $(, $arg:expr)*) => (
5252
unsafe {
53-
if !((*self.ops).$name as *const ()).is_null() {
54-
((*(self.ops)).$name)(self.user $(, $arg)*);
53+
match (*self.ops).$name {
54+
None => (),
55+
Some(f) => f(self.user $(, $arg)*),
5556
}
5657
}
5758
))

0 commit comments

Comments
 (0)