Skip to content

Commit

Permalink
Add test of anyhow::Error in ffi signature
Browse files Browse the repository at this point in the history
Currently:

    warning: `extern` fn uses type `anyhow::Error`, which is not FFI-safe
     --> tests/test_ffi.rs:6:32
      |
    6 | pub extern "C" fn anyhow1(err: anyhow::Error) {
      |                                ^^^^^^^^^^^^^ not FFI-safe
      |
    note: the lint level is defined here
     --> tests/test_ffi.rs:1:26
      |
    1 | #![warn(improper_ctypes, improper_ctypes_definitions)]
      |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
      = note: this struct has unspecified layout

    warning: `extern` fn uses type `Option<anyhow::Error>`, which is not FFI-safe
      --> tests/test_ffi.rs:16:32
       |
    16 | pub extern "C" fn anyhow3() -> Option<anyhow::Error> {
       |                                ^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
       |
       = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
       = note: enum has no representation hint
  • Loading branch information
dtolnay committed Dec 18, 2020
1 parent 2a82468 commit 0a218a8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/test_ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![warn(improper_ctypes, improper_ctypes_definitions)]

use anyhow::anyhow;

#[no_mangle]
pub extern "C" fn anyhow1(err: anyhow::Error) {
println!("{:?}", err);
}

#[no_mangle]
pub extern "C" fn anyhow2(err: &mut Option<anyhow::Error>) {
*err = Some(anyhow!("ffi error"));
}

#[no_mangle]
pub extern "C" fn anyhow3() -> Option<anyhow::Error> {
Some(anyhow!("ffi error"))
}

0 comments on commit 0a218a8

Please sign in to comment.