From e2114642ae0b70aaf9b2036fbf26245106aa22e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 14 Apr 2024 21:39:23 -0400 Subject: [PATCH] parser: Treat omitted ABI in extern block as "C". As per https://doc.rust-lang.org/reference/items/external-blocks.html#abi Closes #709 --- src/bindgen/parser.rs | 2 +- tests/expectations/extern.c | 2 ++ tests/expectations/extern.compat.c | 2 ++ tests/expectations/extern.cpp | 2 ++ tests/expectations/extern.pyx | 2 ++ tests/expectations/extern_both.c | 2 ++ tests/expectations/extern_both.compat.c | 2 ++ tests/expectations/extern_tag.c | 2 ++ tests/expectations/extern_tag.compat.c | 2 ++ tests/expectations/extern_tag.pyx | 2 ++ tests/rust/extern.rs | 4 ++++ 11 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/bindgen/parser.rs b/src/bindgen/parser.rs index ddc3672a8..c418e9d2a 100644 --- a/src/bindgen/parser.rs +++ b/src/bindgen/parser.rs @@ -600,7 +600,7 @@ impl Parse { mod_cfg: Option<&Cfg>, item: &syn::ItemForeignMod, ) { - if !item.abi.is_c() { + if !item.abi.is_c() && !item.abi.is_omitted() { info!("Skip {} - (extern block must be extern C).", crate_name); return; } diff --git a/tests/expectations/extern.c b/tests/expectations/extern.c index 6fe9f5bdb..70b2a3be9 100644 --- a/tests/expectations/extern.c +++ b/tests/expectations/extern.c @@ -11,3 +11,5 @@ typedef struct { extern int32_t foo(void); extern void bar(Normal a); + +extern int32_t baz(void); diff --git a/tests/expectations/extern.compat.c b/tests/expectations/extern.compat.c index 4f4129ad5..7cf348439 100644 --- a/tests/expectations/extern.compat.c +++ b/tests/expectations/extern.compat.c @@ -16,6 +16,8 @@ extern int32_t foo(void); extern void bar(Normal a); +extern int32_t baz(void); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/tests/expectations/extern.cpp b/tests/expectations/extern.cpp index 15294c05c..ecdea3c11 100644 --- a/tests/expectations/extern.cpp +++ b/tests/expectations/extern.cpp @@ -15,4 +15,6 @@ extern int32_t foo(); extern void bar(Normal a); +extern int32_t baz(); + } // extern "C" diff --git a/tests/expectations/extern.pyx b/tests/expectations/extern.pyx index dca17ac8f..51b05833c 100644 --- a/tests/expectations/extern.pyx +++ b/tests/expectations/extern.pyx @@ -13,3 +13,5 @@ cdef extern from *: extern int32_t foo(); extern void bar(Normal a); + + extern int32_t baz(); diff --git a/tests/expectations/extern_both.c b/tests/expectations/extern_both.c index 026661a64..56aad04ef 100644 --- a/tests/expectations/extern_both.c +++ b/tests/expectations/extern_both.c @@ -11,3 +11,5 @@ typedef struct Normal { extern int32_t foo(void); extern void bar(struct Normal a); + +extern int32_t baz(void); diff --git a/tests/expectations/extern_both.compat.c b/tests/expectations/extern_both.compat.c index 3c49da31e..dff58551d 100644 --- a/tests/expectations/extern_both.compat.c +++ b/tests/expectations/extern_both.compat.c @@ -16,6 +16,8 @@ extern int32_t foo(void); extern void bar(struct Normal a); +extern int32_t baz(void); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/tests/expectations/extern_tag.c b/tests/expectations/extern_tag.c index 5a88d1a22..e70c271a2 100644 --- a/tests/expectations/extern_tag.c +++ b/tests/expectations/extern_tag.c @@ -11,3 +11,5 @@ struct Normal { extern int32_t foo(void); extern void bar(struct Normal a); + +extern int32_t baz(void); diff --git a/tests/expectations/extern_tag.compat.c b/tests/expectations/extern_tag.compat.c index 3ca162513..a2d9ea961 100644 --- a/tests/expectations/extern_tag.compat.c +++ b/tests/expectations/extern_tag.compat.c @@ -16,6 +16,8 @@ extern int32_t foo(void); extern void bar(struct Normal a); +extern int32_t baz(void); + #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/tests/expectations/extern_tag.pyx b/tests/expectations/extern_tag.pyx index 9cb7214a4..f62773325 100644 --- a/tests/expectations/extern_tag.pyx +++ b/tests/expectations/extern_tag.pyx @@ -13,3 +13,5 @@ cdef extern from *: extern int32_t foo(); extern void bar(Normal a); + + extern int32_t baz(); diff --git a/tests/rust/extern.rs b/tests/rust/extern.rs index 3bd83d17f..e9a93920e 100644 --- a/tests/rust/extern.rs +++ b/tests/rust/extern.rs @@ -9,3 +9,7 @@ extern "C" { fn bar(a: Normal); } + +extern { + fn baz() -> i32; +}