Tests for namespaced extern trivial types
diff --git a/tests/ffi/extra.rs b/tests/ffi/extra.rs
index 1faf375..0921724 100644
--- a/tests/ffi/extra.rs
+++ b/tests/ffi/extra.rs
@@ -13,6 +13,7 @@
impl UniquePtr<D> {}
impl UniquePtr<E> {}
impl UniquePtr<F> {}
+ impl UniquePtr<G> {}
extern "C" {
include!("tests/ffi/tests.h");
@@ -21,16 +22,23 @@
type E = crate::other::E;
#[namespace (namespace = F)]
type F = crate::other::f::F;
+ #[namespace (namespace = G)]
+ type G = crate::other::G;
fn c_take_trivial_ptr(d: UniquePtr<D>);
fn c_take_trivial_ref(d: &D);
fn c_take_trivial(d: D);
+ fn c_take_trivial_ns_ptr(g: UniquePtr<G>);
+ fn c_take_trivial_ns_ref(g: &G);
+ fn c_take_trivial_ns(g: G);
fn c_take_opaque_ptr(e: UniquePtr<E>);
fn c_take_opaque_ref(e: &E);
fn c_take_opaque_ns_ptr(e: UniquePtr<F>);
fn c_take_opaque_ns_ref(e: &F);
fn c_return_trivial_ptr() -> UniquePtr<D>;
fn c_return_trivial() -> D;
+ fn c_return_trivial_ns_ptr() -> UniquePtr<G>;
+ fn c_return_trivial_ns() -> G;
fn c_return_opaque_ptr() -> UniquePtr<E>;
fn c_return_ns_opaque_ptr() -> UniquePtr<F>;
}
diff --git a/tests/ffi/lib.rs b/tests/ffi/lib.rs
index f25fd2a..1cd92f9 100644
--- a/tests/ffi/lib.rs
+++ b/tests/ffi/lib.rs
@@ -41,6 +41,16 @@
}
}
+ #[repr(C)]
+ pub struct G {
+ pub g: u64,
+ }
+
+ unsafe impl ExternType for G {
+ type Id = type_id!("G::G");
+ type Kind = Trivial;
+ }
+
unsafe impl ExternType for D {
type Id = type_id!("tests::D");
type Kind = Trivial;
diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc
index db51435..017cb82 100644
--- a/tests/ffi/tests.cc
+++ b/tests/ffi/tests.cc
@@ -466,12 +466,32 @@
cxx_test_suite_set_correct();
}
}
+
void c_take_trivial(D d) {
if (d.d == 30) {
cxx_test_suite_set_correct();
}
}
+
+void c_take_trivial_ns_ptr(std::unique_ptr<::G::G> g) {
+ if (g->g == 30) {
+ cxx_test_suite_set_correct();
+ }
+}
+
+void c_take_trivial_ns_ref(const ::G::G& g) {
+ if (g.g == 30) {
+ cxx_test_suite_set_correct();
+ }
+}
+
+void c_take_trivial_ns(::G::G g) {
+ if (g.g == 30) {
+ cxx_test_suite_set_correct();
+ }
+}
+
void c_take_opaque_ptr(std::unique_ptr<E> e) {
if (e->e == 40) {
cxx_test_suite_set_correct();
@@ -496,7 +516,6 @@
}
}
-
std::unique_ptr<D> c_return_trivial_ptr() {
auto d = std::unique_ptr<D>(new D());
d->d = 30;
@@ -509,6 +528,18 @@
return d;
}
+std::unique_ptr<::G::G> c_return_trivial_ns_ptr() {
+ auto g = std::unique_ptr<::G::G>(new ::G::G());
+ g->g = 30;
+ return g;
+}
+
+::G::G c_return_trivial_ns() {
+ ::G::G g;
+ g.g = 30;
+ return g;
+}
+
std::unique_ptr<E> c_return_opaque_ptr() {
auto e = std::unique_ptr<E>(new E());
e->e = 40;
diff --git a/tests/ffi/tests.h b/tests/ffi/tests.h
index 4bdf69e..7f62672 100644
--- a/tests/ffi/tests.h
+++ b/tests/ffi/tests.h
@@ -19,6 +19,12 @@
};
}
+namespace G {
+ struct G {
+ uint64_t g;
+ };
+}
+
namespace tests {
struct R;
@@ -143,12 +149,18 @@
void c_take_trivial_ptr(std::unique_ptr<D> d);
void c_take_trivial_ref(const D& d);
void c_take_trivial(D d);
+
+void c_take_trivial_ns_ptr(std::unique_ptr<::G::G> g);
+void c_take_trivial_ns_ref(const ::G::G& g);
+void c_take_trivial_ns(::G::G g);
void c_take_opaque_ptr(std::unique_ptr<E> e);
void c_take_opaque_ns_ptr(std::unique_ptr<::F::F> f);
void c_take_opaque_ref(const E& e);
void c_take_opaque_ns_ref(const ::F::F& f);
std::unique_ptr<D> c_return_trivial_ptr();
D c_return_trivial();
+std::unique_ptr<::G::G> c_return_trivial_ns_ptr();
+::G::G c_return_trivial_ns();
std::unique_ptr<E> c_return_opaque_ptr();
std::unique_ptr<::F::F> c_return_ns_opaque_ptr();