diff options
author | Christian Poveda <christian.poveda@ferrous-systems.com> | 2022-10-07 12:08:52 -0500 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2022-10-16 20:23:34 +0200 |
commit | 17dd0931306977abd13c90532d35b86237fcd7a7 (patch) | |
tree | 925970fe111799ed32acbad7b856efd10c4085fe | |
parent | 626797bf6c0e2602a8d5a53dae078be9b94c179c (diff) |
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.
-rw-r--r-- | bindgen-tests/tests/expectations/tests/var-tracing.rs | 2 | ||||
-rw-r--r-- | bindgen/ir/var.rs | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/bindgen-tests/tests/expectations/tests/var-tracing.rs b/bindgen-tests/tests/expectations/tests/var-tracing.rs index 4280802e..37fdd951 100644 --- a/bindgen-tests/tests/expectations/tests/var-tracing.rs +++ b/bindgen-tests/tests/expectations/tests/var-tracing.rs @@ -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() { diff --git a/bindgen/ir/var.rs b/bindgen/ir/var.rs index eecca4df..daaad8c5 100644 --- a/bindgen/ir/var.rs +++ b/bindgen/ir/var.rs @@ -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())); |