-
Notifications
You must be signed in to change notification settings - Fork 373
! return type function in struct was not emited and support ! type completely. #779
Copy link
Copy link
Closed
Description
I noted that #548 and have a similar issue.
Create a library crate firstly:
cargo new --lib exampleThen, 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.hNow, 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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels