Skip to content

Commit

Permalink
Don't skip #[no_mangle] fn's without extern "C"
Browse files Browse the repository at this point in the history
The C ABI is the default for extern fn's.
  • Loading branch information
eqrion committed Sep 27, 2017
1 parent 6551eea commit e0ec983
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
11 changes: 11 additions & 0 deletions compile-tests/extern-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[no_mangle]
extern "C" fn first()
{ }

#[no_mangle]
extern fn second()
{ }

#[no_mangle]
fn third()
{ }
11 changes: 8 additions & 3 deletions src/bindgen/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl LibraryBuilder {
return;
}

if item.is_no_mangle() && abi.is_c() {
if item.is_no_mangle() && (abi.is_omitted() || abi.is_c()) {
match Function::load(item.ident.to_string(),
decl,
false,
Expand All @@ -247,8 +247,13 @@ impl LibraryBuilder {
},
}
} else {
if item.is_no_mangle() != abi.is_c() {
warn!("skip {}::{} - (not both `no_mangle` and `extern \"C\"`)",
if (abi.is_omitted() || abi.is_c()) && !item.is_no_mangle() {
warn!("skip {}::{} - (`extern` but not `no_mangle`)",
crate_name,
&item.ident);
}
if abi.is_some() && !(abi.is_omitted() || abi.is_c()) {
warn!("skip {}::{} - (non `extern \"C\"`)",
crate_name,
&item.ident);
}
Expand Down
7 changes: 7 additions & 0 deletions src/bindgen/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,23 @@ impl SynItemHelpers for syn::Field {
/// Helper function for accessing Abi information
pub trait SynAbiHelpers {
fn is_c(&self) -> bool;
fn is_omitted(&self) -> bool;
}

impl SynAbiHelpers for Option<syn::Abi> {
fn is_c(&self) -> bool {
self == &Some(syn::Abi::Named(String::from("C")))
}
fn is_omitted(&self) -> bool {
self == &Some(syn::Abi::Rust)
}
}

impl SynAbiHelpers for syn::Abi {
fn is_c(&self) -> bool {
self == &syn::Abi::Named(String::from("C"))
}
fn is_omitted(&self) -> bool {
self == &syn::Abi::Rust
}
}

0 comments on commit e0ec983

Please sign in to comment.