File tree Expand file tree Collapse file tree 5 files changed +69
-1
lines changed Expand file tree Collapse file tree 5 files changed +69
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ pub mod ffi2 {
13
13
impl UniquePtr < D > { }
14
14
impl UniquePtr < E > { }
15
15
impl UniquePtr < F > { }
16
+ impl UniquePtr < G > { }
16
17
17
18
extern "C" {
18
19
include ! ( "tests/ffi/tests.h" ) ;
@@ -21,16 +22,23 @@ pub mod ffi2 {
21
22
type E = crate :: other:: E ;
22
23
#[ namespace ( namespace = F ) ]
23
24
type F = crate :: other:: f:: F ;
25
+ #[ namespace ( namespace = G ) ]
26
+ type G = crate :: other:: G ;
24
27
25
28
fn c_take_trivial_ptr ( d : UniquePtr < D > ) ;
26
29
fn c_take_trivial_ref ( d : & D ) ;
27
30
fn c_take_trivial ( d : D ) ;
31
+ fn c_take_trivial_ns_ptr ( g : UniquePtr < G > ) ;
32
+ fn c_take_trivial_ns_ref ( g : & G ) ;
33
+ fn c_take_trivial_ns ( g : G ) ;
28
34
fn c_take_opaque_ptr ( e : UniquePtr < E > ) ;
29
35
fn c_take_opaque_ref ( e : & E ) ;
30
36
fn c_take_opaque_ns_ptr ( e : UniquePtr < F > ) ;
31
37
fn c_take_opaque_ns_ref ( e : & F ) ;
32
38
fn c_return_trivial_ptr ( ) -> UniquePtr < D > ;
33
39
fn c_return_trivial ( ) -> D ;
40
+ fn c_return_trivial_ns_ptr ( ) -> UniquePtr < G > ;
41
+ fn c_return_trivial_ns ( ) -> G ;
34
42
fn c_return_opaque_ptr ( ) -> UniquePtr < E > ;
35
43
fn c_return_ns_opaque_ptr ( ) -> UniquePtr < F > ;
36
44
}
Original file line number Diff line number Diff line change @@ -41,6 +41,16 @@ mod other {
41
41
}
42
42
}
43
43
44
+ #[ repr( C ) ]
45
+ pub struct G {
46
+ pub g : u64 ,
47
+ }
48
+
49
+ unsafe impl ExternType for G {
50
+ type Id = type_id ! ( "G::G" ) ;
51
+ type Kind = Trivial ;
52
+ }
53
+
44
54
unsafe impl ExternType for D {
45
55
type Id = type_id ! ( "tests::D" ) ;
46
56
type Kind = Trivial ;
Original file line number Diff line number Diff line change @@ -466,12 +466,32 @@ void c_take_trivial_ref(const D& d) {
466
466
cxx_test_suite_set_correct ();
467
467
}
468
468
}
469
+
469
470
void c_take_trivial (D d) {
470
471
if (d.d == 30 ) {
471
472
cxx_test_suite_set_correct ();
472
473
}
473
474
}
474
475
476
+
477
+ void c_take_trivial_ns_ptr (std::unique_ptr<::G::G> g) {
478
+ if (g->g == 30 ) {
479
+ cxx_test_suite_set_correct ();
480
+ }
481
+ }
482
+
483
+ void c_take_trivial_ns_ref (const ::G::G& g) {
484
+ if (g.g == 30 ) {
485
+ cxx_test_suite_set_correct ();
486
+ }
487
+ }
488
+
489
+ void c_take_trivial_ns (::G::G g) {
490
+ if (g.g == 30 ) {
491
+ cxx_test_suite_set_correct ();
492
+ }
493
+ }
494
+
475
495
void c_take_opaque_ptr (std::unique_ptr<E> e) {
476
496
if (e->e == 40 ) {
477
497
cxx_test_suite_set_correct ();
@@ -496,7 +516,6 @@ void c_take_opaque_ns_ref(const ::F::F& f) {
496
516
}
497
517
}
498
518
499
-
500
519
std::unique_ptr<D> c_return_trivial_ptr () {
501
520
auto d = std::unique_ptr<D>(new D ());
502
521
d->d = 30 ;
@@ -509,6 +528,18 @@ D c_return_trivial() {
509
528
return d;
510
529
}
511
530
531
+ std::unique_ptr<::G::G> c_return_trivial_ns_ptr () {
532
+ auto g = std::unique_ptr<::G::G>(new ::G::G ());
533
+ g->g = 30 ;
534
+ return g;
535
+ }
536
+
537
+ ::G::G c_return_trivial_ns () {
538
+ ::G::G g;
539
+ g.g = 30 ;
540
+ return g;
541
+ }
542
+
512
543
std::unique_ptr<E> c_return_opaque_ptr () {
513
544
auto e = std::unique_ptr<E>(new E ());
514
545
e->e = 40 ;
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ namespace F {
19
19
};
20
20
}
21
21
22
+ namespace G {
23
+ struct G {
24
+ uint64_t g;
25
+ };
26
+ }
27
+
22
28
namespace tests {
23
29
24
30
struct R ;
@@ -143,12 +149,18 @@ const rust::Vec<uint8_t> &c_try_return_ref_rust_vec(const C &c);
143
149
void c_take_trivial_ptr (std::unique_ptr<D> d);
144
150
void c_take_trivial_ref (const D& d);
145
151
void c_take_trivial (D d);
152
+
153
+ void c_take_trivial_ns_ptr (std::unique_ptr<::G::G> g);
154
+ void c_take_trivial_ns_ref (const ::G::G& g);
155
+ void c_take_trivial_ns (::G::G g);
146
156
void c_take_opaque_ptr (std::unique_ptr<E> e);
147
157
void c_take_opaque_ns_ptr (std::unique_ptr<::F::F> f);
148
158
void c_take_opaque_ref (const E& e);
149
159
void c_take_opaque_ns_ref (const ::F::F& f);
150
160
std::unique_ptr<D> c_return_trivial_ptr ();
151
161
D c_return_trivial ();
162
+ std::unique_ptr<::G::G> c_return_trivial_ns_ptr ();
163
+ ::G::G c_return_trivial_ns ();
152
164
std::unique_ptr<E> c_return_opaque_ptr ();
153
165
std::unique_ptr<::F::F> c_return_ns_opaque_ptr ();
154
166
Original file line number Diff line number Diff line change @@ -223,6 +223,13 @@ fn test_extern_trivial() {
223
223
let d = ffi2:: c_return_trivial_ptr ( ) ;
224
224
check ! ( ffi2:: c_take_trivial_ptr( d) ) ;
225
225
cxx:: UniquePtr :: new ( ffi2:: D { d : 42 } ) ;
226
+
227
+ let g = ffi2:: c_return_trivial_ns ( ) ;
228
+ check ! ( ffi2:: c_take_trivial_ns_ref( & g) ) ;
229
+ check ! ( ffi2:: c_take_trivial_ns( g) ) ;
230
+ let g = ffi2:: c_return_trivial_ns_ptr ( ) ;
231
+ check ! ( ffi2:: c_take_trivial_ns_ptr( g) ) ;
232
+ cxx:: UniquePtr :: new ( ffi2:: G { g : 42 } ) ;
226
233
}
227
234
228
235
#[ test]
You can’t perform that action at this time.
0 commit comments