mirror of
https://github.com/topjohnwu/cxx.git
synced 2024-11-23 11:59:46 +00:00
Remove unique_ptr from name of std::vector<>::new symbol
This commit is contained in:
parent
4213e928ff
commit
2ff5e37af4
@ -1904,6 +1904,15 @@ fn write_cxx_vector(out: &mut OutFile, key: NamedImplKey) {
|
||||
out.include.utility = true;
|
||||
out.builtin.destroy = true;
|
||||
|
||||
begin_function_definition(out);
|
||||
writeln!(
|
||||
out,
|
||||
"::std::vector<{}> *cxxbridge1$std$vector${}$new() noexcept {{",
|
||||
inner, instance,
|
||||
);
|
||||
writeln!(out, " return new ::std::vector<{}>();", inner);
|
||||
writeln!(out, "}}");
|
||||
|
||||
begin_function_definition(out);
|
||||
writeln!(
|
||||
out,
|
||||
@ -1944,20 +1953,6 @@ fn write_cxx_vector(out: &mut OutFile, key: NamedImplKey) {
|
||||
writeln!(out, "}}");
|
||||
}
|
||||
|
||||
let ty = UniquePtr::CxxVector(element);
|
||||
|
||||
out.include.memory = true;
|
||||
write_unique_ptr_common(out, ty);
|
||||
|
||||
let inner = ty.to_typename(out.types);
|
||||
let instance = ty.to_mangled(out.types);
|
||||
|
||||
begin_function_definition(out);
|
||||
writeln!(
|
||||
out,
|
||||
"{} *cxxbridge1$unique_ptr${}$new() noexcept {{",
|
||||
inner, instance,
|
||||
);
|
||||
writeln!(out, " return new {}();", inner);
|
||||
writeln!(out, "}}");
|
||||
write_unique_ptr_common(out, UniquePtr::CxxVector(element));
|
||||
}
|
||||
|
@ -1613,6 +1613,7 @@ fn expand_cxx_vector(
|
||||
let name = elem.to_string();
|
||||
let resolve = types.resolve(elem);
|
||||
let prefix = format!("cxxbridge1$std$vector${}$", resolve.name.to_symbol());
|
||||
let link_new = format!("{}new", prefix);
|
||||
let link_size = format!("{}size", prefix);
|
||||
let link_get_unchecked = format!("{}get_unchecked", prefix);
|
||||
let link_push_back = format!("{}push_back", prefix);
|
||||
@ -1622,7 +1623,6 @@ fn expand_cxx_vector(
|
||||
resolve.name.to_symbol(),
|
||||
);
|
||||
let link_unique_ptr_null = format!("{}null", unique_ptr_prefix);
|
||||
let link_unique_ptr_new = format!("{}new", unique_ptr_prefix);
|
||||
let link_unique_ptr_raw = format!("{}raw", unique_ptr_prefix);
|
||||
let link_unique_ptr_get = format!("{}get", unique_ptr_prefix);
|
||||
let link_unique_ptr_release = format!("{}release", unique_ptr_prefix);
|
||||
@ -1673,6 +1673,13 @@ fn expand_cxx_vector(
|
||||
fn __typename(f: &mut ::cxx::core::fmt::Formatter<'_>) -> ::cxx::core::fmt::Result {
|
||||
f.write_str(#name)
|
||||
}
|
||||
fn __vector_new() -> *mut ::cxx::CxxVector<Self> {
|
||||
extern "C" {
|
||||
#[link_name = #link_new]
|
||||
fn __vector_new #impl_generics() -> *mut ::cxx::CxxVector<#elem #ty_generics>;
|
||||
}
|
||||
unsafe { __vector_new() }
|
||||
}
|
||||
fn __vector_size(v: &::cxx::CxxVector<Self>) -> usize {
|
||||
extern "C" {
|
||||
#[link_name = #link_size]
|
||||
@ -1700,13 +1707,6 @@ fn expand_cxx_vector(
|
||||
unsafe { __unique_ptr_null(&mut repr) }
|
||||
repr
|
||||
}
|
||||
fn __unique_ptr_new() -> *mut ::cxx::CxxVector<Self> {
|
||||
extern "C" {
|
||||
#[link_name = #link_unique_ptr_new]
|
||||
fn __unique_ptr_new #impl_generics() -> *mut ::cxx::CxxVector<#elem #ty_generics>;
|
||||
}
|
||||
unsafe { __unique_ptr_new() }
|
||||
}
|
||||
unsafe fn __unique_ptr_raw(raw: *mut ::cxx::CxxVector<Self>) -> ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void> {
|
||||
extern "C" {
|
||||
#[link_name = #link_unique_ptr_raw]
|
||||
|
@ -593,6 +593,9 @@ static_assert(sizeof(std::string) <= kMaxExpectedWordsInString * sizeof(void *),
|
||||
} // namespace
|
||||
|
||||
#define STD_VECTOR_OPS(RUST_TYPE, CXX_TYPE) \
|
||||
std::vector<CXX_TYPE> *cxxbridge1$std$vector$##RUST_TYPE##$new() noexcept { \
|
||||
return new std::vector<CXX_TYPE>(); \
|
||||
} \
|
||||
std::size_t cxxbridge1$std$vector$##RUST_TYPE##$size( \
|
||||
const std::vector<CXX_TYPE> &s) noexcept { \
|
||||
return s.size(); \
|
||||
@ -605,10 +608,6 @@ static_assert(sizeof(std::string) <= kMaxExpectedWordsInString * sizeof(void *),
|
||||
std::unique_ptr<std::vector<CXX_TYPE>> *ptr) noexcept { \
|
||||
new (ptr) std::unique_ptr<std::vector<CXX_TYPE>>(); \
|
||||
} \
|
||||
std::vector<CXX_TYPE> \
|
||||
*cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$new() noexcept { \
|
||||
return new std::vector<CXX_TYPE>(); \
|
||||
} \
|
||||
void cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$raw( \
|
||||
std::unique_ptr<std::vector<CXX_TYPE>> *ptr, \
|
||||
std::vector<CXX_TYPE> *raw) noexcept { \
|
||||
|
@ -41,7 +41,7 @@ where
|
||||
///
|
||||
/// The C++ vector is default constructed.
|
||||
pub fn new() -> UniquePtr<Self> {
|
||||
unsafe { UniquePtr::from_raw(T::__unique_ptr_new()) }
|
||||
unsafe { UniquePtr::from_raw(T::__vector_new()) }
|
||||
}
|
||||
|
||||
/// Returns the number of elements in the vector.
|
||||
@ -342,6 +342,8 @@ pub unsafe trait VectorElement: Sized {
|
||||
#[doc(hidden)]
|
||||
fn __typename(f: &mut fmt::Formatter) -> fmt::Result;
|
||||
#[doc(hidden)]
|
||||
fn __vector_new() -> *mut CxxVector<Self>;
|
||||
#[doc(hidden)]
|
||||
fn __vector_size(v: &CxxVector<Self>) -> usize;
|
||||
#[doc(hidden)]
|
||||
unsafe fn __get_unchecked(v: *mut CxxVector<Self>, pos: usize) -> *mut Self;
|
||||
@ -364,8 +366,6 @@ pub unsafe trait VectorElement: Sized {
|
||||
#[doc(hidden)]
|
||||
fn __unique_ptr_null() -> MaybeUninit<*mut c_void>;
|
||||
#[doc(hidden)]
|
||||
fn __unique_ptr_new() -> *mut CxxVector<Self>;
|
||||
#[doc(hidden)]
|
||||
unsafe fn __unique_ptr_raw(raw: *mut CxxVector<Self>) -> MaybeUninit<*mut c_void>;
|
||||
#[doc(hidden)]
|
||||
unsafe fn __unique_ptr_get(repr: MaybeUninit<*mut c_void>) -> *const CxxVector<Self>;
|
||||
@ -408,6 +408,15 @@ macro_rules! impl_vector_element {
|
||||
fn __typename(f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str($name)
|
||||
}
|
||||
fn __vector_new() -> *mut CxxVector<Self> {
|
||||
extern "C" {
|
||||
attr! {
|
||||
#[link_name = concat!("cxxbridge1$std$vector$", $segment, "$new")]
|
||||
fn __vector_new() -> *mut CxxVector<$ty>;
|
||||
}
|
||||
}
|
||||
unsafe { __vector_new() }
|
||||
}
|
||||
fn __vector_size(v: &CxxVector<$ty>) -> usize {
|
||||
extern "C" {
|
||||
attr! {
|
||||
@ -438,15 +447,6 @@ macro_rules! impl_vector_element {
|
||||
unsafe { __unique_ptr_null(&mut repr) }
|
||||
repr
|
||||
}
|
||||
fn __unique_ptr_new() -> *mut CxxVector<Self> {
|
||||
extern "C" {
|
||||
attr! {
|
||||
#[link_name = concat!("cxxbridge1$unique_ptr$std$vector$", $segment, "$new")]
|
||||
fn __unique_ptr_new() -> *mut CxxVector<$ty>;
|
||||
}
|
||||
}
|
||||
unsafe { __unique_ptr_new() }
|
||||
}
|
||||
unsafe fn __unique_ptr_raw(raw: *mut CxxVector<Self>) -> MaybeUninit<*mut c_void> {
|
||||
extern "C" {
|
||||
attr! {
|
||||
|
Loading…
Reference in New Issue
Block a user