diff --git a/src/bindgen/bindings.rs b/src/bindgen/bindings.rs index ee05761..495d128 100644 --- a/src/bindgen/bindings.rs +++ b/src/bindgen/bindings.rs @@ -126,6 +126,10 @@ impl Bindings { self.write_headers(&mut out); } + if self.config.language == Language::Cxx { + self.open_namespaces(&mut out); + } + for constant in &self.constants { if constant.ty.is_primitive_or_ptr_primitive() { out.new_line_if_not_start(); @@ -134,9 +138,6 @@ impl Bindings { } } - if self.config.language == Language::Cxx { - self.open_namespaces(&mut out); - } for item in &self.items { if item .deref() diff --git a/tests/expectations/both/namespace_constant.c b/tests/expectations/both/namespace_constant.c new file mode 100644 index 0000000..90538df --- /dev/null +++ b/tests/expectations/both/namespace_constant.c @@ -0,0 +1,13 @@ +#include +#include +#include + +#define FOO 10 + +#define ZOM 3.14 + +typedef struct Foo { + int32_t x[FOO]; +} Foo; + +void root(Foo x); diff --git a/tests/expectations/both/namespaces_constant.c b/tests/expectations/both/namespaces_constant.c new file mode 100644 index 0000000..90538df --- /dev/null +++ b/tests/expectations/both/namespaces_constant.c @@ -0,0 +1,13 @@ +#include +#include +#include + +#define FOO 10 + +#define ZOM 3.14 + +typedef struct Foo { + int32_t x[FOO]; +} Foo; + +void root(Foo x); diff --git a/tests/expectations/namespace_constant.c b/tests/expectations/namespace_constant.c new file mode 100644 index 0000000..5858773 --- /dev/null +++ b/tests/expectations/namespace_constant.c @@ -0,0 +1,13 @@ +#include +#include +#include + +#define FOO 10 + +#define ZOM 3.14 + +typedef struct { + int32_t x[FOO]; +} Foo; + +void root(Foo x); diff --git a/tests/expectations/namespace_constant.cpp b/tests/expectations/namespace_constant.cpp new file mode 100644 index 0000000..df5e4e0 --- /dev/null +++ b/tests/expectations/namespace_constant.cpp @@ -0,0 +1,20 @@ +#include +#include + +namespace constants { + +static const int32_t FOO = 10; + +static const float ZOM = 3.14; + +struct Foo { + int32_t x[FOO]; +}; + +extern "C" { + +void root(Foo x); + +} // extern "C" + +} // namespace constants diff --git a/tests/expectations/namespaces_constant.c b/tests/expectations/namespaces_constant.c new file mode 100644 index 0000000..5858773 --- /dev/null +++ b/tests/expectations/namespaces_constant.c @@ -0,0 +1,13 @@ +#include +#include +#include + +#define FOO 10 + +#define ZOM 3.14 + +typedef struct { + int32_t x[FOO]; +} Foo; + +void root(Foo x); diff --git a/tests/expectations/namespaces_constant.cpp b/tests/expectations/namespaces_constant.cpp new file mode 100644 index 0000000..5cdf532 --- /dev/null +++ b/tests/expectations/namespaces_constant.cpp @@ -0,0 +1,22 @@ +#include +#include + +namespace constants { +namespace test { + +static const int32_t FOO = 10; + +static const float ZOM = 3.14; + +struct Foo { + int32_t x[FOO]; +}; + +extern "C" { + +void root(Foo x); + +} // extern "C" + +} // namespace test +} // namespace constants diff --git a/tests/expectations/tag/namespace_constant.c b/tests/expectations/tag/namespace_constant.c new file mode 100644 index 0000000..8def269 --- /dev/null +++ b/tests/expectations/tag/namespace_constant.c @@ -0,0 +1,13 @@ +#include +#include +#include + +#define FOO 10 + +#define ZOM 3.14 + +struct Foo { + int32_t x[FOO]; +}; + +void root(struct Foo x); diff --git a/tests/expectations/tag/namespaces_constant.c b/tests/expectations/tag/namespaces_constant.c new file mode 100644 index 0000000..8def269 --- /dev/null +++ b/tests/expectations/tag/namespaces_constant.c @@ -0,0 +1,13 @@ +#include +#include +#include + +#define FOO 10 + +#define ZOM 3.14 + +struct Foo { + int32_t x[FOO]; +}; + +void root(struct Foo x); diff --git a/tests/rust/namespace_constant.rs b/tests/rust/namespace_constant.rs new file mode 100644 index 0000000..ee67081 --- /dev/null +++ b/tests/rust/namespace_constant.rs @@ -0,0 +1,11 @@ +const FOO: i32 = 10; +const BAR: &'static str = "hello world"; +const ZOM: f32 = 3.14; + +#[repr(C)] +struct Foo { + x: [i32; FOO], +} + +#[no_mangle] +pub extern "C" fn root(x: Foo) { } diff --git a/tests/rust/namespace_constant.toml b/tests/rust/namespace_constant.toml new file mode 100644 index 0000000..1b9d94e --- /dev/null +++ b/tests/rust/namespace_constant.toml @@ -0,0 +1 @@ +namespace = "constants" diff --git a/tests/rust/namespaces_constant.rs b/tests/rust/namespaces_constant.rs new file mode 100644 index 0000000..ee67081 --- /dev/null +++ b/tests/rust/namespaces_constant.rs @@ -0,0 +1,11 @@ +const FOO: i32 = 10; +const BAR: &'static str = "hello world"; +const ZOM: f32 = 3.14; + +#[repr(C)] +struct Foo { + x: [i32; FOO], +} + +#[no_mangle] +pub extern "C" fn root(x: Foo) { } diff --git a/tests/rust/namespaces_constant.toml b/tests/rust/namespaces_constant.toml new file mode 100644 index 0000000..7601ad3 --- /dev/null +++ b/tests/rust/namespaces_constant.toml @@ -0,0 +1 @@ +namespaces = ["constants", "test"]