@@ -63,28 +63,46 @@ fn maybe_convert_trait_impl<W: std::io::Write>(w: &mut W, trait_path: &syn::Path
63
63
if let Some ( t) = types. maybe_resolve_path ( & trait_path, None ) {
64
64
let for_obj;
65
65
let full_obj_path;
66
+ let mut has_inner = false ;
66
67
if let syn:: Type :: Path ( ref p) = for_ty {
67
68
if let Some ( ident) = p. path . get_ident ( ) {
68
- let s = types. maybe_resolve_ident ( ident) . unwrap ( ) ;
69
- if !types. crate_types . opaques . get ( & s) . is_some ( ) { return ; }
70
-
71
69
for_obj = format ! ( "{}" , ident) ;
72
70
full_obj_path = for_obj. clone ( ) ;
71
+ has_inner = types. c_type_has_inner_from_path ( & types. resolve_path ( & p. path , None ) ) ;
73
72
} else { return ; }
74
73
} else {
75
- return ;
74
+ // We assume that anything that isn't a Path is somehow a generic that ends up in our
75
+ // derived-types module.
76
+ let mut for_obj_vec = Vec :: new ( ) ;
77
+ types. write_c_type ( & mut for_obj_vec, for_ty, None , false ) ;
78
+ full_obj_path = String :: from_utf8 ( for_obj_vec) . unwrap ( ) ;
79
+ assert ! ( full_obj_path. starts_with( TypeResolver :: generated_container_path( ) ) ) ;
80
+ for_obj = full_obj_path[ TypeResolver :: generated_container_path ( ) . len ( ) + 2 ..] . into ( ) ;
76
81
}
77
82
78
83
match & t as & str {
79
84
"util::ser::Writeable" => {
80
85
writeln ! ( w, "#[no_mangle]" ) . unwrap ( ) ;
81
86
writeln ! ( w, "pub extern \" C\" fn {}_write(obj: *const {}) -> crate::c_types::derived::CVec_u8Z {{" , for_obj, full_obj_path) . unwrap ( ) ;
82
- writeln ! ( w, "\t crate::c_types::serialize_obj(unsafe {{ &(*(*obj).inner) }})" ) . unwrap ( ) ;
83
- writeln ! ( w, "}}" ) . unwrap ( ) ;
84
- writeln ! ( w, "#[no_mangle]" ) . unwrap ( ) ;
85
- writeln ! ( w, "pub(crate) extern \" C\" fn {}_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {{" , for_obj) . unwrap ( ) ;
86
- writeln ! ( w, "\t crate::c_types::serialize_obj(unsafe {{ &*(obj as *const native{}) }})" , for_obj) . unwrap ( ) ;
87
+
88
+ let ref_type = syn:: Type :: Reference ( syn:: TypeReference {
89
+ and_token : syn:: Token !( & ) ( Span :: call_site ( ) ) , lifetime : None , mutability : None ,
90
+ elem : Box :: new ( for_ty. clone ( ) ) } ) ;
91
+ assert ! ( !types. write_from_c_conversion_new_var( w, & syn:: Ident :: new( "obj" , Span :: call_site( ) ) , & ref_type, None ) ) ;
92
+
93
+ write ! ( w, "\t crate::c_types::serialize_obj(" ) . unwrap ( ) ;
94
+ types. write_from_c_conversion_prefix ( w, & ref_type, None ) ;
95
+ write ! ( w, "unsafe {{ &*obj }}" ) . unwrap ( ) ;
96
+ types. write_from_c_conversion_suffix ( w, & ref_type, None ) ;
97
+ writeln ! ( w, ")" ) . unwrap ( ) ;
98
+
87
99
writeln ! ( w, "}}" ) . unwrap ( ) ;
100
+ if has_inner {
101
+ writeln ! ( w, "#[no_mangle]" ) . unwrap ( ) ;
102
+ writeln ! ( w, "pub(crate) extern \" C\" fn {}_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {{" , for_obj) . unwrap ( ) ;
103
+ writeln ! ( w, "\t crate::c_types::serialize_obj(unsafe {{ &*(obj as *const native{}) }})" , for_obj) . unwrap ( ) ;
104
+ writeln ! ( w, "}}" ) . unwrap ( ) ;
105
+ }
88
106
} ,
89
107
"util::ser::Readable" => {
90
108
// Create the Result<Object, DecodeError> syn::Type
0 commit comments