mirror of
https://github.com/topjohnwu/cxx.git
synced 2025-02-23 17:40:53 +00:00
Enable UniquePtr::new for enums
This commit is contained in:
parent
4f52dabfa3
commit
15609ab97b
@ -1212,6 +1212,7 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: &Type) {
|
||||
// for Opaque types because the 'new' method is not implemented.
|
||||
Type::Ident(ident) => {
|
||||
out.types.structs.contains_key(&ident.rust)
|
||||
|| out.types.enums.contains_key(&ident.rust)
|
||||
|| out.types.aliases.contains_key(&ident.rust)
|
||||
}
|
||||
_ => false,
|
||||
|
@ -909,22 +909,24 @@ fn expand_unique_ptr(
|
||||
let link_release = format!("{}release", prefix);
|
||||
let link_drop = format!("{}drop", prefix);
|
||||
|
||||
let new_method =
|
||||
if types.structs.contains_key(&ident.rust) || types.aliases.contains_key(&ident.rust) {
|
||||
Some(quote! {
|
||||
fn __new(mut value: Self) -> *mut ::std::ffi::c_void {
|
||||
extern "C" {
|
||||
#[link_name = #link_new]
|
||||
fn __new(this: *mut *mut ::std::ffi::c_void, value: *mut #ident);
|
||||
}
|
||||
let mut repr = ::std::ptr::null_mut::<::std::ffi::c_void>();
|
||||
unsafe { __new(&mut repr, &mut value) }
|
||||
repr
|
||||
let can_construct_from_value = types.structs.contains_key(&ident.rust)
|
||||
|| types.enums.contains_key(&ident.rust)
|
||||
|| types.aliases.contains_key(&ident.rust);
|
||||
let new_method = if can_construct_from_value {
|
||||
Some(quote! {
|
||||
fn __new(mut value: Self) -> *mut ::std::ffi::c_void {
|
||||
extern "C" {
|
||||
#[link_name = #link_new]
|
||||
fn __new(this: *mut *mut ::std::ffi::c_void, value: *mut #ident);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut repr = ::std::ptr::null_mut::<::std::ffi::c_void>();
|
||||
unsafe { __new(&mut repr, &mut value) }
|
||||
repr
|
||||
}
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let begin_span =
|
||||
explicit_impl.map_or_else(Span::call_site, |explicit| explicit.impl_token.span);
|
||||
|
Loading…
x
Reference in New Issue
Block a user