I noted that #548 and have a similar issue.
Create a library crate firstly:
Then, add them in lib.rs:
#[repr(C)]
pub struct Example {
pub f: extern "C" fn(usize, usize) -> !,
}
#[no_mangle]
pub extern "C" fn add_itr(f: *const Example, a: usize, b: usize) -> ! {
unsafe {
((*f).f)(a, b)
}
}
#[no_mangle]
pub extern "C" fn add() -> ! {
loop{}
}
And run this command in your terminal:
cbindgen --crate example --output example.h
Now, please see example.h, the output is that:
#include ...
// notes here!!
struct Example;
extern "C" {
void add_itr(const Example *f, uintptr_t a, uintptr_t b);
void add();
} // extern "C"
The function which has ! return type was be ignored, but the other one add was emited successfully.
I think that we can add similar behavior to the structure, like emitting to void(*f)(size_t, size_t). And for the Nerver type, may be believe that C functions void(*)( ... some params ...) will never return is a good idea.
For more cases, about a C function pointer with Never return type, I noted that the following code can not be emited to C header:
// lib.rs
#[no_mangle]
pub extern "C" fn add(f: extern "C" fn() -> !) -> ! {
f()
}
I think it's the key of this issue.
Could we possibly solve it?
I noted that #548 and have a similar issue.
Create a library crate firstly:
Then, add them in
lib.rs:And run this command in your terminal:
Now, please see
example.h, the output is that:The function which has
!return type was be ignored, but the other oneaddwas emited successfully.I think that we can add similar behavior to the structure, like emitting to
void(*f)(size_t, size_t). And for theNervertype, may be believe that C functionsvoid(*)( ... some params ...)will never return is a good idea.For more cases, about a C function pointer with
Neverreturn type, I noted that the following code can not be emited to C header:I think it's the key of this issue.
Could we possibly solve it?