@@ -57,7 +57,7 @@ pub fn bridge(namespace: &Namespace, ffi: ItemMod) -> Result<TokenStream> {
5757 } else if let Type :: UniquePtr ( ptr) = ty {
5858 if let Type :: Ident ( ident) = & ptr. inner {
5959 if Atom :: from ( ident) . is_none ( ) {
60- expanded. extend ( expand_unique_ptr ( namespace, ident) ) ;
60+ expanded. extend ( expand_unique_ptr ( namespace, ident, types ) ) ;
6161 }
6262 }
6363 }
@@ -474,7 +474,7 @@ fn expand_rust_box(namespace: &Namespace, ident: &Ident) -> TokenStream {
474474 }
475475}
476476
477- fn expand_unique_ptr ( namespace : & Namespace , ident : & Ident ) -> TokenStream {
477+ fn expand_unique_ptr ( namespace : & Namespace , ident : & Ident , types : & Types ) -> TokenStream {
478478 let prefix = format ! ( "cxxbridge02$unique_ptr${}{}$" , namespace, ident) ;
479479 let link_null = format ! ( "{}null" , prefix) ;
480480 let link_new = format ! ( "{}new" , prefix) ;
@@ -483,6 +483,22 @@ fn expand_unique_ptr(namespace: &Namespace, ident: &Ident) -> TokenStream {
483483 let link_release = format ! ( "{}release" , prefix) ;
484484 let link_drop = format ! ( "{}drop" , prefix) ;
485485
486+ let new_method = if types. structs . contains_key ( ident) {
487+ Some ( quote ! {
488+ fn __new( mut value: Self ) -> * mut :: std:: ffi:: c_void {
489+ extern "C" {
490+ #[ link_name = #link_new]
491+ fn __new( this: * mut * mut :: std:: ffi:: c_void, value: * mut #ident) ;
492+ }
493+ let mut repr = :: std:: ptr:: null_mut:: <:: std:: ffi:: c_void>( ) ;
494+ unsafe { __new( & mut repr, & mut value) }
495+ repr
496+ }
497+ } )
498+ } else {
499+ None
500+ } ;
501+
486502 quote ! {
487503 unsafe impl :: cxx:: private:: UniquePtrTarget for #ident {
488504 fn __null( ) -> * mut :: std:: ffi:: c_void {
@@ -494,15 +510,7 @@ fn expand_unique_ptr(namespace: &Namespace, ident: &Ident) -> TokenStream {
494510 unsafe { __null( & mut repr) }
495511 repr
496512 }
497- fn __new( mut value: Self ) -> * mut :: std:: ffi:: c_void {
498- extern "C" {
499- #[ link_name = #link_new]
500- fn __new( this: * mut * mut :: std:: ffi:: c_void, value: * mut #ident) ;
501- }
502- let mut repr = :: std:: ptr:: null_mut:: <:: std:: ffi:: c_void>( ) ;
503- unsafe { __new( & mut repr, & mut value) }
504- repr
505- }
513+ #new_method
506514 unsafe fn __raw( raw: * mut Self ) -> * mut :: std:: ffi:: c_void {
507515 extern "C" {
508516 #[ link_name = #link_raw]
0 commit comments