Handle incomplete external array constants

This adds a new special case for constants like:
```c
extern const char some_static_string[];
```
so `bindgen` emits a `static` instead of a `static mut` for them.
This commit is contained in:
Christian Poveda
2022-10-07 12:08:52 -05:00
committed by Emilio Cobos Álvarez
parent ad20d325df
commit 7a5876cdf7
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ pub struct Baz {
}
extern "C" {
#[link_name = "\u{1}_ZN3Baz3FOOE"]
pub static mut Baz_FOO: [Bar; 0usize];
pub static Baz_FOO: [Bar; 0usize];
}
#[test]
fn bindgen_test_layout_Baz() {
+2 -1
View File
@@ -285,7 +285,8 @@ impl ClangSubItemParser for Var {
// TODO(emilio): do we have to special-case constant arrays in
// some other places?
let is_const = ty.is_const() ||
(ty.kind() == CXType_ConstantArray &&
([CXType_ConstantArray, CXType_IncompleteArray]
.contains(&ty.kind()) &&
ty.elem_type()
.map_or(false, |element| element.is_const()));