File tree Expand file tree Collapse file tree 5 files changed +56
-0
lines changed Expand file tree Collapse file tree 5 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 12
12
pub mod ffi2 {
13
13
impl UniquePtr < D > { }
14
14
impl UniquePtr < E > { }
15
+ impl UniquePtr < F > { }
15
16
16
17
extern "C" {
17
18
include ! ( "tests/ffi/tests.h" ) ;
18
19
19
20
type D = crate :: other:: D ;
20
21
type E = crate :: other:: E ;
22
+ #[ namespace ( namespace = F ) ]
23
+ type F = crate :: other:: f:: F ;
21
24
22
25
fn c_take_trivial_ptr ( d : UniquePtr < D > ) ;
23
26
fn c_take_trivial_ref ( d : & D ) ;
24
27
fn c_take_trivial ( d : D ) ;
25
28
fn c_take_opaque_ptr ( e : UniquePtr < E > ) ;
26
29
fn c_take_opaque_ref ( e : & E ) ;
30
+ fn c_take_opaque_ns_ptr ( e : UniquePtr < F > ) ;
31
+ fn c_take_opaque_ns_ref ( e : & F ) ;
27
32
fn c_return_trivial_ptr ( ) -> UniquePtr < D > ;
28
33
fn c_return_trivial ( ) -> D ;
29
34
fn c_return_opaque_ptr ( ) -> UniquePtr < E > ;
35
+ fn c_return_ns_opaque_ptr ( ) -> UniquePtr < F > ;
30
36
}
31
37
}
Original file line number Diff line number Diff line change @@ -25,6 +25,22 @@ mod other {
25
25
e_str : CxxString ,
26
26
}
27
27
28
+ pub mod f {
29
+ use cxx:: kind:: Opaque ;
30
+ use cxx:: { type_id, CxxString , ExternType } ;
31
+
32
+ #[ repr( C ) ]
33
+ pub struct F {
34
+ e : u64 ,
35
+ e_str : CxxString ,
36
+ }
37
+
38
+ unsafe impl ExternType for F {
39
+ type Id = type_id ! ( "F::F" ) ;
40
+ type Kind = Opaque ;
41
+ }
42
+ }
43
+
28
44
unsafe impl ExternType for D {
29
45
type Id = type_id ! ( "tests::D" ) ;
30
46
type Kind = Trivial ;
Original file line number Diff line number Diff line change @@ -478,12 +478,25 @@ void c_take_opaque_ptr(std::unique_ptr<E> e) {
478
478
}
479
479
}
480
480
481
+ void c_take_opaque_ns_ptr (std::unique_ptr<::F::F> f) {
482
+ if (f->f == 40 ) {
483
+ cxx_test_suite_set_correct ();
484
+ }
485
+ }
486
+
481
487
void c_take_opaque_ref (const E& e) {
482
488
if (e.e == 40 && e.e_str == " hello" ) {
483
489
cxx_test_suite_set_correct ();
484
490
}
485
491
}
486
492
493
+ void c_take_opaque_ns_ref (const ::F::F& f) {
494
+ if (f.f == 40 && f.f_str == " hello" ) {
495
+ cxx_test_suite_set_correct ();
496
+ }
497
+ }
498
+
499
+
487
500
std::unique_ptr<D> c_return_trivial_ptr () {
488
501
auto d = std::unique_ptr<D>(new D ());
489
502
d->d = 30 ;
@@ -503,6 +516,13 @@ std::unique_ptr<E> c_return_opaque_ptr() {
503
516
return e;
504
517
}
505
518
519
+ std::unique_ptr<::F::F> c_return_ns_opaque_ptr () {
520
+ auto f = std::unique_ptr<::F::F>(new ::F::F ());
521
+ f->f = 40 ;
522
+ f->f_str = std::string (" hello" );
523
+ return f;
524
+ }
525
+
506
526
extern " C" const char *cxx_run_test () noexcept {
507
527
#define STRINGIFY (x ) #x
508
528
#define TOSTRING (x ) STRINGIFY(x)
Original file line number Diff line number Diff line change @@ -12,6 +12,13 @@ namespace A {
12
12
} // namespace B
13
13
} // namespace A
14
14
15
+ namespace F {
16
+ struct F {
17
+ uint64_t f;
18
+ std::string f_str;
19
+ };
20
+ }
21
+
15
22
namespace tests {
16
23
17
24
struct R ;
@@ -137,10 +144,13 @@ void c_take_trivial_ptr(std::unique_ptr<D> d);
137
144
void c_take_trivial_ref (const D& d);
138
145
void c_take_trivial (D d);
139
146
void c_take_opaque_ptr (std::unique_ptr<E> e);
147
+ void c_take_opaque_ns_ptr (std::unique_ptr<::F::F> f);
140
148
void c_take_opaque_ref (const E& e);
149
+ void c_take_opaque_ns_ref (const ::F::F& f);
141
150
std::unique_ptr<D> c_return_trivial_ptr ();
142
151
D c_return_trivial ();
143
152
std::unique_ptr<E> c_return_opaque_ptr ();
153
+ std::unique_ptr<::F::F> c_return_ns_opaque_ptr ();
144
154
145
155
rust::String cOverloadedFunction (int32_t x);
146
156
rust::String cOverloadedFunction (rust::Str x);
Original file line number Diff line number Diff line change @@ -230,4 +230,8 @@ fn test_extern_opaque() {
230
230
let e = ffi2:: c_return_opaque_ptr ( ) ;
231
231
check ! ( ffi2:: c_take_opaque_ref( e. as_ref( ) . unwrap( ) ) ) ;
232
232
check ! ( ffi2:: c_take_opaque_ptr( e) ) ;
233
+
234
+ let f = ffi2:: c_return_ns_opaque_ptr ( ) ;
235
+ check ! ( ffi2:: c_take_opaque_ns_ref( f. as_ref( ) . unwrap( ) ) ) ;
236
+ check ! ( ffi2:: c_take_opaque_ns_ptr( f) ) ;
233
237
}
You can’t perform that action at this time.
0 commit comments