Bump namespace to 04

This commit is contained in:
David Tolnay 2020-09-01 23:00:38 -07:00
parent 84f8cf9738
commit 591dcb647d
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
17 changed files with 176 additions and 176 deletions

View File

@ -3,7 +3,7 @@ name = "cxx"
version = "0.3.9" # remember to update html_root_url
authors = ["David Tolnay <dtolnay@gmail.com>"]
edition = "2018"
links = "cxxbridge03"
links = "cxxbridge04"
license = "MIT OR Apache-2.0"
description = "Safe interop between Rust and C++"
repository = "https://github.com/dtolnay/cxx"

View File

@ -4,7 +4,7 @@ fn main() {
.cpp(true)
.cpp_link_stdlib(None) // linked via link-cplusplus crate
.flag_if_supported(cxxbridge_flags::STD)
.compile("cxxbridge03");
.compile("cxxbridge04");
println!("cargo:rerun-if-changed=src/cxx.cc");
println!("cargo:rerun-if-changed=include/cxx.h");
println!("cargo:rustc-cfg=built_with_cargo");

View File

@ -21,7 +21,7 @@ fn test_cpp() {
let output = std::str::from_utf8(&output.implementation).unwrap();
// To avoid continual breakage we won't test every byte.
// Let's look for the major features.
assert!(output.contains("void cxxbridge03$do_cpp_thing(::rust::Str::Repr foo)"));
assert!(output.contains("void cxxbridge04$do_cpp_thing(::rust::Str::Repr foo)"));
}
#[test]
@ -34,5 +34,5 @@ fn test_annotation() {
};
let output = generate_from_string(CPP_EXAMPLE, &opts).unwrap();
let output = std::str::from_utf8(&output.implementation).unwrap();
assert!(output.contains("ANNOTATION void cxxbridge03$do_cpp_thing(::rust::Str::Repr foo)"));
assert!(output.contains("ANNOTATION void cxxbridge04$do_cpp_thing(::rust::Str::Repr foo)"));
}

View File

@ -230,7 +230,7 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
}
out.begin_block("namespace rust");
out.begin_block("inline namespace cxxbridge03");
out.begin_block("inline namespace cxxbridge04");
if needs_rust_string
|| needs_rust_str
@ -253,15 +253,15 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
writeln!(out, "struct unsafe_bitcopy_t;");
}
include::write(out, needs_rust_string, "CXXBRIDGE03_RUST_STRING");
include::write(out, needs_rust_str, "CXXBRIDGE03_RUST_STR");
include::write(out, needs_rust_slice, "CXXBRIDGE03_RUST_SLICE");
include::write(out, needs_rust_box, "CXXBRIDGE03_RUST_BOX");
include::write(out, needs_rust_vec, "CXXBRIDGE03_RUST_VEC");
include::write(out, needs_rust_fn, "CXXBRIDGE03_RUST_FN");
include::write(out, needs_rust_error, "CXXBRIDGE03_RUST_ERROR");
include::write(out, needs_rust_isize, "CXXBRIDGE03_RUST_ISIZE");
include::write(out, needs_unsafe_bitcopy, "CXXBRIDGE03_RUST_BITCOPY");
include::write(out, needs_rust_string, "CXXBRIDGE04_RUST_STRING");
include::write(out, needs_rust_str, "CXXBRIDGE04_RUST_STR");
include::write(out, needs_rust_slice, "CXXBRIDGE04_RUST_SLICE");
include::write(out, needs_rust_box, "CXXBRIDGE04_RUST_BOX");
include::write(out, needs_rust_vec, "CXXBRIDGE04_RUST_VEC");
include::write(out, needs_rust_fn, "CXXBRIDGE04_RUST_FN");
include::write(out, needs_rust_error, "CXXBRIDGE04_RUST_ERROR");
include::write(out, needs_rust_isize, "CXXBRIDGE04_RUST_ISIZE");
include::write(out, needs_unsafe_bitcopy, "CXXBRIDGE04_RUST_BITCOPY");
if needs_manually_drop {
out.next_section();
@ -287,7 +287,7 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
writeln!(out, "}};");
}
out.end_block("namespace cxxbridge03");
out.end_block("namespace cxxbridge04");
if needs_trycatch {
out.begin_block("namespace behavior");
@ -316,7 +316,7 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
}
fn write_struct(out: &mut OutFile, strct: &Struct) {
let guard = format!("CXXBRIDGE03_STRUCT_{}{}", out.namespace, strct.ident);
let guard = format!("CXXBRIDGE04_STRUCT_{}{}", out.namespace, strct.ident);
writeln!(out, "#ifndef {}", guard);
writeln!(out, "#define {}", guard);
for line in strct.doc.to_string().lines() {
@ -341,7 +341,7 @@ fn write_struct_using(out: &mut OutFile, ident: &Ident) {
}
fn write_struct_with_methods(out: &mut OutFile, ety: &ExternType, methods: &[&ExternFn]) {
let guard = format!("CXXBRIDGE03_STRUCT_{}{}", out.namespace, ety.ident);
let guard = format!("CXXBRIDGE04_STRUCT_{}{}", out.namespace, ety.ident);
writeln!(out, "#ifndef {}", guard);
writeln!(out, "#define {}", guard);
for line in ety.doc.to_string().lines() {
@ -362,7 +362,7 @@ fn write_struct_with_methods(out: &mut OutFile, ety: &ExternType, methods: &[&Ex
}
fn write_enum(out: &mut OutFile, enm: &Enum) {
let guard = format!("CXXBRIDGE03_ENUM_{}{}", out.namespace, enm.ident);
let guard = format!("CXXBRIDGE04_ENUM_{}{}", out.namespace, enm.ident);
writeln!(out, "#ifndef {}", guard);
writeln!(out, "#define {}", guard);
for line in enm.doc.to_string().lines() {
@ -408,7 +408,7 @@ fn write_exception_glue(out: &mut OutFile, apis: &[Api]) {
out.next_section();
writeln!(
out,
"const char *cxxbridge03$exception(const char *, size_t);",
"const char *cxxbridge04$exception(const char *, size_t);",
);
}
}
@ -553,7 +553,7 @@ fn write_cxx_function_shim(
writeln!(out, " throw$.len = ::std::strlen(catch$);");
writeln!(
out,
" throw$.ptr = cxxbridge03$exception(catch$, throw$.len);",
" throw$.ptr = cxxbridge04$exception(catch$, throw$.len);",
);
writeln!(out, " }});");
writeln!(out, " return throw$;");
@ -1026,7 +1026,7 @@ fn write_generic_instantiations(out: &mut OutFile, types: &Types) {
out.end_block("extern \"C\"");
out.begin_block("namespace rust");
out.begin_block("inline namespace cxxbridge03");
out.begin_block("inline namespace cxxbridge04");
for ty in types {
if let Type::RustBox(ty) = ty {
if let Type::Ident(inner) = &ty.inner {
@ -1040,7 +1040,7 @@ fn write_generic_instantiations(out: &mut OutFile, types: &Types) {
}
}
}
out.end_block("namespace cxxbridge03");
out.end_block("namespace cxxbridge04");
out.end_block("namespace rust");
}
@ -1053,19 +1053,19 @@ fn write_rust_box_extern(out: &mut OutFile, ident: &Ident) {
inner += &ident.to_string();
let instance = inner.replace("::", "$");
writeln!(out, "#ifndef CXXBRIDGE03_RUST_BOX_{}", instance);
writeln!(out, "#define CXXBRIDGE03_RUST_BOX_{}", instance);
writeln!(out, "#ifndef CXXBRIDGE04_RUST_BOX_{}", instance);
writeln!(out, "#define CXXBRIDGE04_RUST_BOX_{}", instance);
writeln!(
out,
"void cxxbridge03$box${}$uninit(::rust::Box<{}> *ptr) noexcept;",
"void cxxbridge04$box${}$uninit(::rust::Box<{}> *ptr) noexcept;",
instance, inner,
);
writeln!(
out,
"void cxxbridge03$box${}$drop(::rust::Box<{}> *ptr) noexcept;",
"void cxxbridge04$box${}$drop(::rust::Box<{}> *ptr) noexcept;",
instance, inner,
);
writeln!(out, "#endif // CXXBRIDGE03_RUST_BOX_{}", instance);
writeln!(out, "#endif // CXXBRIDGE04_RUST_BOX_{}", instance);
}
fn write_rust_vec_extern(out: &mut OutFile, element: &Ident) {
@ -1073,34 +1073,34 @@ fn write_rust_vec_extern(out: &mut OutFile, element: &Ident) {
let inner = to_typename(&out.namespace, &element);
let instance = to_mangled(&out.namespace, &element);
writeln!(out, "#ifndef CXXBRIDGE03_RUST_VEC_{}", instance);
writeln!(out, "#define CXXBRIDGE03_RUST_VEC_{}", instance);
writeln!(out, "#ifndef CXXBRIDGE04_RUST_VEC_{}", instance);
writeln!(out, "#define CXXBRIDGE04_RUST_VEC_{}", instance);
writeln!(
out,
"void cxxbridge03$rust_vec${}$new(const ::rust::Vec<{}> *ptr) noexcept;",
"void cxxbridge04$rust_vec${}$new(const ::rust::Vec<{}> *ptr) noexcept;",
instance, inner,
);
writeln!(
out,
"void cxxbridge03$rust_vec${}$drop(::rust::Vec<{}> *ptr) noexcept;",
"void cxxbridge04$rust_vec${}$drop(::rust::Vec<{}> *ptr) noexcept;",
instance, inner,
);
writeln!(
out,
"size_t cxxbridge03$rust_vec${}$len(const ::rust::Vec<{}> *ptr) noexcept;",
"size_t cxxbridge04$rust_vec${}$len(const ::rust::Vec<{}> *ptr) noexcept;",
instance, inner,
);
writeln!(
out,
"const {} *cxxbridge03$rust_vec${}$data(const ::rust::Vec<{0}> *ptr) noexcept;",
"const {} *cxxbridge04$rust_vec${}$data(const ::rust::Vec<{0}> *ptr) noexcept;",
inner, instance,
);
writeln!(
out,
"size_t cxxbridge03$rust_vec${}$stride() noexcept;",
"size_t cxxbridge04$rust_vec${}$stride() noexcept;",
instance,
);
writeln!(out, "#endif // CXXBRIDGE03_RUST_VEC_{}", instance);
writeln!(out, "#endif // CXXBRIDGE04_RUST_VEC_{}", instance);
}
fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
@ -1114,12 +1114,12 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Ident) {
writeln!(out, "template <>");
writeln!(out, "void Box<{}>::uninit() noexcept {{", inner);
writeln!(out, " cxxbridge03$box${}$uninit(this);", instance);
writeln!(out, " cxxbridge04$box${}$uninit(this);", instance);
writeln!(out, "}}");
writeln!(out, "template <>");
writeln!(out, "void Box<{}>::drop() noexcept {{", inner);
writeln!(out, " cxxbridge03$box${}$drop(this);", instance);
writeln!(out, " cxxbridge04$box${}$drop(this);", instance);
writeln!(out, "}}");
}
@ -1130,35 +1130,35 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &Ident) {
writeln!(out, "template <>");
writeln!(out, "Vec<{}>::Vec() noexcept {{", inner);
writeln!(out, " cxxbridge03$rust_vec${}$new(this);", instance);
writeln!(out, " cxxbridge04$rust_vec${}$new(this);", instance);
writeln!(out, "}}");
writeln!(out, "template <>");
writeln!(out, "void Vec<{}>::drop() noexcept {{", inner);
writeln!(
out,
" return cxxbridge03$rust_vec${}$drop(this);",
" return cxxbridge04$rust_vec${}$drop(this);",
instance,
);
writeln!(out, "}}");
writeln!(out, "template <>");
writeln!(out, "size_t Vec<{}>::size() const noexcept {{", inner);
writeln!(out, " return cxxbridge03$rust_vec${}$len(this);", instance);
writeln!(out, " return cxxbridge04$rust_vec${}$len(this);", instance);
writeln!(out, "}}");
writeln!(out, "template <>");
writeln!(out, "const {} *Vec<{0}>::data() const noexcept {{", inner);
writeln!(
out,
" return cxxbridge03$rust_vec${}$data(this);",
" return cxxbridge04$rust_vec${}$data(this);",
instance,
);
writeln!(out, "}}");
writeln!(out, "template <>");
writeln!(out, "size_t Vec<{}>::stride() noexcept {{", inner);
writeln!(out, " return cxxbridge03$rust_vec${}$stride();", instance);
writeln!(out, " return cxxbridge04$rust_vec${}$stride();", instance);
writeln!(out, "}}");
}
@ -1166,12 +1166,12 @@ fn write_unique_ptr(out: &mut OutFile, ident: &Ident, types: &Types) {
let ty = Type::Ident(ident.clone());
let instance = to_mangled(&out.namespace, &ty);
writeln!(out, "#ifndef CXXBRIDGE03_UNIQUE_PTR_{}", instance);
writeln!(out, "#define CXXBRIDGE03_UNIQUE_PTR_{}", instance);
writeln!(out, "#ifndef CXXBRIDGE04_UNIQUE_PTR_{}", instance);
writeln!(out, "#define CXXBRIDGE04_UNIQUE_PTR_{}", instance);
write_unique_ptr_common(out, &ty, types);
writeln!(out, "#endif // CXXBRIDGE03_UNIQUE_PTR_{}", instance);
writeln!(out, "#endif // CXXBRIDGE04_UNIQUE_PTR_{}", instance);
}
// Shared by UniquePtr<T> and UniquePtr<CxxVector<T>>.
@ -1198,7 +1198,7 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: &Type, types: &Types) {
);
writeln!(
out,
"void cxxbridge03$unique_ptr${}$null(::std::unique_ptr<{}> *ptr) noexcept {{",
"void cxxbridge04$unique_ptr${}$null(::std::unique_ptr<{}> *ptr) noexcept {{",
instance, inner,
);
writeln!(out, " new (ptr) ::std::unique_ptr<{}>();", inner);
@ -1206,7 +1206,7 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: &Type, types: &Types) {
if can_construct_from_value {
writeln!(
out,
"void cxxbridge03$unique_ptr${}$new(::std::unique_ptr<{}> *ptr, {} *value) noexcept {{",
"void cxxbridge04$unique_ptr${}$new(::std::unique_ptr<{}> *ptr, {} *value) noexcept {{",
instance, inner, inner,
);
writeln!(
@ -1218,28 +1218,28 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: &Type, types: &Types) {
}
writeln!(
out,
"void cxxbridge03$unique_ptr${}$raw(::std::unique_ptr<{}> *ptr, {} *raw) noexcept {{",
"void cxxbridge04$unique_ptr${}$raw(::std::unique_ptr<{}> *ptr, {} *raw) noexcept {{",
instance, inner, inner,
);
writeln!(out, " new (ptr) ::std::unique_ptr<{}>(raw);", inner);
writeln!(out, "}}");
writeln!(
out,
"const {} *cxxbridge03$unique_ptr${}$get(const ::std::unique_ptr<{}>& ptr) noexcept {{",
"const {} *cxxbridge04$unique_ptr${}$get(const ::std::unique_ptr<{}>& ptr) noexcept {{",
inner, instance, inner,
);
writeln!(out, " return ptr.get();");
writeln!(out, "}}");
writeln!(
out,
"{} *cxxbridge03$unique_ptr${}$release(::std::unique_ptr<{}>& ptr) noexcept {{",
"{} *cxxbridge04$unique_ptr${}$release(::std::unique_ptr<{}>& ptr) noexcept {{",
inner, instance, inner,
);
writeln!(out, " return ptr.release();");
writeln!(out, "}}");
writeln!(
out,
"void cxxbridge03$unique_ptr${}$drop(::std::unique_ptr<{}> *ptr) noexcept {{",
"void cxxbridge04$unique_ptr${}$drop(::std::unique_ptr<{}> *ptr) noexcept {{",
instance, inner,
);
writeln!(out, " ptr->~unique_ptr();");
@ -1251,18 +1251,18 @@ fn write_cxx_vector(out: &mut OutFile, vector_ty: &Type, element: &Ident, types:
let inner = to_typename(&out.namespace, &element);
let instance = to_mangled(&out.namespace, &element);
writeln!(out, "#ifndef CXXBRIDGE03_VECTOR_{}", instance);
writeln!(out, "#define CXXBRIDGE03_VECTOR_{}", instance);
writeln!(out, "#ifndef CXXBRIDGE04_VECTOR_{}", instance);
writeln!(out, "#define CXXBRIDGE04_VECTOR_{}", instance);
writeln!(
out,
"size_t cxxbridge03$std$vector${}$size(const ::std::vector<{}> &s) noexcept {{",
"size_t cxxbridge04$std$vector${}$size(const ::std::vector<{}> &s) noexcept {{",
instance, inner,
);
writeln!(out, " return s.size();");
writeln!(out, "}}");
writeln!(
out,
"const {} *cxxbridge03$std$vector${}$get_unchecked(const ::std::vector<{}> &s, size_t pos) noexcept {{",
"const {} *cxxbridge04$std$vector${}$get_unchecked(const ::std::vector<{}> &s, size_t pos) noexcept {{",
inner, instance, inner,
);
writeln!(out, " return &s[pos];");
@ -1270,5 +1270,5 @@ fn write_cxx_vector(out: &mut OutFile, vector_ty: &Type, element: &Ident, types:
write_unique_ptr_common(out, vector_ty, types);
writeln!(out, "#endif // CXXBRIDGE03_VECTOR_{}", instance);
writeln!(out, "#endif // CXXBRIDGE04_VECTOR_{}", instance);
}

View File

@ -15,12 +15,12 @@
#endif
namespace rust {
inline namespace cxxbridge03 {
inline namespace cxxbridge04 {
struct unsafe_bitcopy_t;
#ifndef CXXBRIDGE03_RUST_STRING
#define CXXBRIDGE03_RUST_STRING
#ifndef CXXBRIDGE04_RUST_STRING
#define CXXBRIDGE04_RUST_STRING
class String final {
public:
String() noexcept;
@ -49,10 +49,10 @@ private:
// Size and alignment statically verified by rust_string.rs.
std::array<uintptr_t, 3> repr;
};
#endif // CXXBRIDGE03_RUST_STRING
#endif // CXXBRIDGE04_RUST_STRING
#ifndef CXXBRIDGE03_RUST_STR
#define CXXBRIDGE03_RUST_STR
#ifndef CXXBRIDGE04_RUST_STR
#define CXXBRIDGE04_RUST_STR
class Str final {
public:
Str() noexcept;
@ -86,9 +86,9 @@ public:
private:
Repr repr;
};
#endif // CXXBRIDGE03_RUST_STR
#endif // CXXBRIDGE04_RUST_STR
#ifndef CXXBRIDGE03_RUST_SLICE
#ifndef CXXBRIDGE04_RUST_SLICE
template <typename T>
class Slice final {
public:
@ -117,9 +117,9 @@ public:
private:
Repr repr;
};
#endif // CXXBRIDGE03_RUST_SLICE
#endif // CXXBRIDGE04_RUST_SLICE
#ifndef CXXBRIDGE03_RUST_BOX
#ifndef CXXBRIDGE04_RUST_BOX
template <typename T>
class Box final {
public:
@ -158,9 +158,9 @@ private:
void drop() noexcept;
T *ptr;
};
#endif // CXXBRIDGE03_RUST_BOX
#endif // CXXBRIDGE04_RUST_BOX
#ifndef CXXBRIDGE03_RUST_VEC
#ifndef CXXBRIDGE04_RUST_VEC
template <typename T>
class Vec final {
public:
@ -218,10 +218,10 @@ private:
// Size and alignment statically verified by rust_vec.rs.
std::array<uintptr_t, 3> repr;
};
#endif // CXXBRIDGE03_RUST_VEC
#endif // CXXBRIDGE04_RUST_VEC
#ifndef CXXBRIDGE03_RUST_FN
#define CXXBRIDGE03_RUST_FN
#ifndef CXXBRIDGE04_RUST_FN
#define CXXBRIDGE04_RUST_FN
template <typename Signature, bool Throws = false>
class Fn;
@ -238,10 +238,10 @@ private:
template <typename Signature>
using TryFn = Fn<Signature, true>;
#endif // CXXBRIDGE03_RUST_FN
#endif // CXXBRIDGE04_RUST_FN
#ifndef CXXBRIDGE03_RUST_ERROR
#define CXXBRIDGE03_RUST_ERROR
#ifndef CXXBRIDGE04_RUST_ERROR
#define CXXBRIDGE04_RUST_ERROR
class Error final : std::exception {
public:
Error(const Error &);
@ -253,16 +253,16 @@ public:
private:
Str::Repr msg;
};
#endif // CXXBRIDGE03_RUST_ERROR
#endif // CXXBRIDGE04_RUST_ERROR
#ifndef CXXBRIDGE03_RUST_ISIZE
#define CXXBRIDGE03_RUST_ISIZE
#ifndef CXXBRIDGE04_RUST_ISIZE
#define CXXBRIDGE04_RUST_ISIZE
#if defined(_WIN32)
using isize = SSIZE_T;
#else
using isize = ssize_t;
#endif
#endif // CXXBRIDGE03_RUST_ISIZE
#endif // CXXBRIDGE04_RUST_ISIZE
std::ostream &operator<<(std::ostream &, const String &);
std::ostream &operator<<(std::ostream &, const Str &);
@ -296,17 +296,17 @@ Fn<Ret(Args...), Throws> Fn<Ret(Args...), Throws>::operator*() const noexcept {
return *this;
}
#ifndef CXXBRIDGE03_RUST_BITCOPY
#define CXXBRIDGE03_RUST_BITCOPY
#ifndef CXXBRIDGE04_RUST_BITCOPY
#define CXXBRIDGE04_RUST_BITCOPY
struct unsafe_bitcopy_t {
explicit unsafe_bitcopy_t() = default;
};
constexpr unsafe_bitcopy_t unsafe_bitcopy{};
#endif // CXXBRIDGE03_RUST_BITCOPY
#endif // CXXBRIDGE04_RUST_BITCOPY
#ifndef CXXBRIDGE03_RUST_SLICE
#define CXXBRIDGE03_RUST_SLICE
#ifndef CXXBRIDGE04_RUST_SLICE
#define CXXBRIDGE04_RUST_SLICE
template <typename T>
Slice<T>::Slice() noexcept : repr(Repr{reinterpret_cast<const T *>(this), 0}) {}
@ -344,10 +344,10 @@ template <typename T>
Slice<T>::operator Repr() noexcept {
return this->repr;
}
#endif // CXXBRIDGE03_RUST_SLICE
#endif // CXXBRIDGE04_RUST_SLICE
#ifndef CXXBRIDGE03_RUST_BOX
#define CXXBRIDGE03_RUST_BOX
#ifndef CXXBRIDGE04_RUST_BOX
#define CXXBRIDGE04_RUST_BOX
template <typename T>
Box<T>::Box(const Box &other) : Box(*other) {}
@ -443,10 +443,10 @@ T *Box<T>::into_raw() noexcept {
template <typename T>
Box<T>::Box() noexcept {}
#endif // CXXBRIDGE03_RUST_BOX
#endif // CXXBRIDGE04_RUST_BOX
#ifndef CXXBRIDGE03_RUST_VEC
#define CXXBRIDGE03_RUST_VEC
#ifndef CXXBRIDGE04_RUST_VEC
#define CXXBRIDGE04_RUST_VEC
template <typename T>
Vec<T>::Vec(Vec &&other) noexcept {
this->repr = other.repr;
@ -551,7 +551,7 @@ typename Vec<T>::const_iterator Vec<T>::end() const noexcept {
// Internal API only intended for the cxxbridge code generator.
template <typename T>
Vec<T>::Vec(unsafe_bitcopy_t, const Vec &bits) noexcept : repr(bits.repr) {}
#endif // CXXBRIDGE03_RUST_VEC
#endif // CXXBRIDGE04_RUST_VEC
} // namespace cxxbridge03
} // namespace cxxbridge04
} // namespace rust

View File

@ -689,7 +689,7 @@ fn type_id(namespace: &Namespace, ident: &Ident) -> TokenStream {
}
fn expand_rust_box(namespace: &Namespace, ident: &Ident) -> TokenStream {
let link_prefix = format!("cxxbridge03$box${}{}$", namespace, ident);
let link_prefix = format!("cxxbridge04$box${}{}$", namespace, ident);
let link_uninit = format!("{}uninit", link_prefix);
let link_drop = format!("{}drop", link_prefix);
@ -718,7 +718,7 @@ fn expand_rust_box(namespace: &Namespace, ident: &Ident) -> TokenStream {
}
fn expand_rust_vec(namespace: &Namespace, elem: &Ident) -> TokenStream {
let link_prefix = format!("cxxbridge03$rust_vec${}{}$", namespace, elem);
let link_prefix = format!("cxxbridge04$rust_vec${}{}$", namespace, elem);
let link_new = format!("{}new", link_prefix);
let link_drop = format!("{}drop", link_prefix);
let link_len = format!("{}len", link_prefix);
@ -764,7 +764,7 @@ fn expand_rust_vec(namespace: &Namespace, elem: &Ident) -> TokenStream {
fn expand_unique_ptr(namespace: &Namespace, ident: &Ident, types: &Types) -> TokenStream {
let name = ident.to_string();
let prefix = format!("cxxbridge03$unique_ptr${}{}$", namespace, ident);
let prefix = format!("cxxbridge04$unique_ptr${}{}$", namespace, ident);
let link_null = format!("{}null", prefix);
let link_new = format!("{}new", prefix);
let link_raw = format!("{}raw", prefix);
@ -837,10 +837,10 @@ fn expand_unique_ptr(namespace: &Namespace, ident: &Ident, types: &Types) -> Tok
fn expand_cxx_vector(namespace: &Namespace, elem: &Ident) -> TokenStream {
let name = elem.to_string();
let prefix = format!("cxxbridge03$std$vector${}{}$", namespace, elem);
let prefix = format!("cxxbridge04$std$vector${}{}$", namespace, elem);
let link_size = format!("{}size", prefix);
let link_get_unchecked = format!("{}get_unchecked", prefix);
let unique_ptr_prefix = format!("cxxbridge03$unique_ptr$std$vector${}{}$", namespace, elem);
let unique_ptr_prefix = format!("cxxbridge04$unique_ptr$std$vector${}{}$", namespace, elem);
let link_unique_ptr_null = format!("{}null", unique_ptr_prefix);
let link_unique_ptr_raw = format!("{}raw", unique_ptr_prefix);
let link_unique_ptr_get = format!("{}get", unique_ptr_prefix);

View File

@ -7,30 +7,30 @@
#include <vector>
extern "C" {
const char *cxxbridge03$cxx_string$data(const std::string &s) noexcept {
const char *cxxbridge04$cxx_string$data(const std::string &s) noexcept {
return s.data();
}
size_t cxxbridge03$cxx_string$length(const std::string &s) noexcept {
size_t cxxbridge04$cxx_string$length(const std::string &s) noexcept {
return s.length();
}
// rust::String
void cxxbridge03$string$new(rust::String *self) noexcept;
void cxxbridge03$string$clone(rust::String *self,
void cxxbridge04$string$new(rust::String *self) noexcept;
void cxxbridge04$string$clone(rust::String *self,
const rust::String &other) noexcept;
bool cxxbridge03$string$from(rust::String *self, const char *ptr,
bool cxxbridge04$string$from(rust::String *self, const char *ptr,
size_t len) noexcept;
void cxxbridge03$string$drop(rust::String *self) noexcept;
const char *cxxbridge03$string$ptr(const rust::String *self) noexcept;
size_t cxxbridge03$string$len(const rust::String *self) noexcept;
void cxxbridge04$string$drop(rust::String *self) noexcept;
const char *cxxbridge04$string$ptr(const rust::String *self) noexcept;
size_t cxxbridge04$string$len(const rust::String *self) noexcept;
// rust::Str
bool cxxbridge03$str$valid(const char *ptr, size_t len) noexcept;
bool cxxbridge04$str$valid(const char *ptr, size_t len) noexcept;
} // extern "C"
namespace rust {
inline namespace cxxbridge03 {
inline namespace cxxbridge04 {
template <typename Exception>
void panic [[noreturn]] (const char *msg) {
@ -44,42 +44,42 @@ void panic [[noreturn]] (const char *msg) {
template void panic<std::out_of_range>[[noreturn]] (const char *msg);
String::String() noexcept { cxxbridge03$string$new(this); }
String::String() noexcept { cxxbridge04$string$new(this); }
String::String(const String &other) noexcept {
cxxbridge03$string$clone(this, other);
cxxbridge04$string$clone(this, other);
}
String::String(String &&other) noexcept {
this->repr = other.repr;
cxxbridge03$string$new(&other);
cxxbridge04$string$new(&other);
}
String::~String() noexcept { cxxbridge03$string$drop(this); }
String::~String() noexcept { cxxbridge04$string$drop(this); }
String::String(const std::string &s) : String(s.data(), s.length()) {}
String::String(const char *s) : String(s, std::strlen(s)) {}
String::String(const char *s, size_t len) {
if (!cxxbridge03$string$from(this, s, len)) {
if (!cxxbridge04$string$from(this, s, len)) {
panic<std::invalid_argument>("data for rust::String is not utf-8");
}
}
String &String::operator=(const String &other) noexcept {
if (this != &other) {
cxxbridge03$string$drop(this);
cxxbridge03$string$clone(this, other);
cxxbridge04$string$drop(this);
cxxbridge04$string$clone(this, other);
}
return *this;
}
String &String::operator=(String &&other) noexcept {
if (this != &other) {
cxxbridge03$string$drop(this);
cxxbridge04$string$drop(this);
this->repr = other.repr;
cxxbridge03$string$new(&other);
cxxbridge04$string$new(&other);
}
return *this;
}
@ -89,12 +89,12 @@ String::operator std::string() const {
}
const char *String::data() const noexcept {
return cxxbridge03$string$ptr(this);
return cxxbridge04$string$ptr(this);
}
size_t String::size() const noexcept { return cxxbridge03$string$len(this); }
size_t String::size() const noexcept { return cxxbridge04$string$len(this); }
size_t String::length() const noexcept { return cxxbridge03$string$len(this); }
size_t String::length() const noexcept { return cxxbridge04$string$len(this); }
String::String(unsafe_bitcopy_t, const String &bits) noexcept
: repr(bits.repr) {}
@ -113,7 +113,7 @@ Str::Str(const std::string &s) : Str(s.data(), s.length()) {}
Str::Str(const char *s) : Str(s, std::strlen(s)) {}
Str::Str(const char *s, size_t len) : repr(Repr{s, len}) {
if (!cxxbridge03$str$valid(this->repr.ptr, this->repr.len)) {
if (!cxxbridge04$str$valid(this->repr.ptr, this->repr.len)) {
panic<std::invalid_argument>("data for rust::Str is not utf-8");
}
}
@ -143,7 +143,7 @@ std::ostream &operator<<(std::ostream &os, const Str &s) {
}
extern "C" {
const char *cxxbridge03$error(const char *ptr, size_t len) {
const char *cxxbridge04$error(const char *ptr, size_t len) {
char *copy = new char[len];
strncpy(copy, ptr, len);
return copy;
@ -153,7 +153,7 @@ const char *cxxbridge03$error(const char *ptr, size_t len) {
Error::Error(Str::Repr msg) noexcept : msg(msg) {}
Error::Error(const Error &other) {
this->msg.ptr = cxxbridge03$error(other.msg.ptr, other.msg.len);
this->msg.ptr = cxxbridge04$error(other.msg.ptr, other.msg.len);
this->msg.len = other.msg.len;
}
@ -168,96 +168,96 @@ Error::~Error() noexcept { delete[] this->msg.ptr; }
const char *Error::what() const noexcept { return this->msg.ptr; }
} // namespace cxxbridge03
} // namespace cxxbridge04
} // namespace rust
extern "C" {
void cxxbridge03$unique_ptr$std$string$null(
void cxxbridge04$unique_ptr$std$string$null(
std::unique_ptr<std::string> *ptr) noexcept {
new (ptr) std::unique_ptr<std::string>();
}
void cxxbridge03$unique_ptr$std$string$raw(std::unique_ptr<std::string> *ptr,
void cxxbridge04$unique_ptr$std$string$raw(std::unique_ptr<std::string> *ptr,
std::string *raw) noexcept {
new (ptr) std::unique_ptr<std::string>(raw);
}
const std::string *cxxbridge03$unique_ptr$std$string$get(
const std::string *cxxbridge04$unique_ptr$std$string$get(
const std::unique_ptr<std::string> &ptr) noexcept {
return ptr.get();
}
std::string *cxxbridge03$unique_ptr$std$string$release(
std::string *cxxbridge04$unique_ptr$std$string$release(
std::unique_ptr<std::string> &ptr) noexcept {
return ptr.release();
}
void cxxbridge03$unique_ptr$std$string$drop(
void cxxbridge04$unique_ptr$std$string$drop(
std::unique_ptr<std::string> *ptr) noexcept {
ptr->~unique_ptr();
}
} // extern "C"
#define STD_VECTOR_OPS(RUST_TYPE, CXX_TYPE) \
size_t cxxbridge03$std$vector$##RUST_TYPE##$size( \
size_t cxxbridge04$std$vector$##RUST_TYPE##$size( \
const std::vector<CXX_TYPE> &s) noexcept { \
return s.size(); \
} \
const CXX_TYPE *cxxbridge03$std$vector$##RUST_TYPE##$get_unchecked( \
const CXX_TYPE *cxxbridge04$std$vector$##RUST_TYPE##$get_unchecked( \
const std::vector<CXX_TYPE> &s, size_t pos) noexcept { \
return &s[pos]; \
} \
void cxxbridge03$unique_ptr$std$vector$##RUST_TYPE##$null( \
void cxxbridge04$unique_ptr$std$vector$##RUST_TYPE##$null( \
std::unique_ptr<std::vector<CXX_TYPE>> *ptr) noexcept { \
new (ptr) std::unique_ptr<std::vector<CXX_TYPE>>(); \
} \
void cxxbridge03$unique_ptr$std$vector$##RUST_TYPE##$raw( \
void cxxbridge04$unique_ptr$std$vector$##RUST_TYPE##$raw( \
std::unique_ptr<std::vector<CXX_TYPE>> *ptr, \
std::vector<CXX_TYPE> *raw) noexcept { \
new (ptr) std::unique_ptr<std::vector<CXX_TYPE>>(raw); \
} \
const std::vector<CXX_TYPE> \
*cxxbridge03$unique_ptr$std$vector$##RUST_TYPE##$get( \
*cxxbridge04$unique_ptr$std$vector$##RUST_TYPE##$get( \
const std::unique_ptr<std::vector<CXX_TYPE>> &ptr) noexcept { \
return ptr.get(); \
} \
std::vector<CXX_TYPE> \
*cxxbridge03$unique_ptr$std$vector$##RUST_TYPE##$release( \
*cxxbridge04$unique_ptr$std$vector$##RUST_TYPE##$release( \
std::unique_ptr<std::vector<CXX_TYPE>> &ptr) noexcept { \
return ptr.release(); \
} \
void cxxbridge03$unique_ptr$std$vector$##RUST_TYPE##$drop( \
void cxxbridge04$unique_ptr$std$vector$##RUST_TYPE##$drop( \
std::unique_ptr<std::vector<CXX_TYPE>> *ptr) noexcept { \
ptr->~unique_ptr(); \
}
#define RUST_VEC_EXTERNS(RUST_TYPE, CXX_TYPE) \
void cxxbridge03$rust_vec$##RUST_TYPE##$new( \
void cxxbridge04$rust_vec$##RUST_TYPE##$new( \
rust::Vec<CXX_TYPE> *ptr) noexcept; \
void cxxbridge03$rust_vec$##RUST_TYPE##$drop( \
void cxxbridge04$rust_vec$##RUST_TYPE##$drop( \
rust::Vec<CXX_TYPE> *ptr) noexcept; \
size_t cxxbridge03$rust_vec$##RUST_TYPE##$len( \
size_t cxxbridge04$rust_vec$##RUST_TYPE##$len( \
const rust::Vec<CXX_TYPE> *ptr) noexcept; \
const CXX_TYPE *cxxbridge03$rust_vec$##RUST_TYPE##$data( \
const CXX_TYPE *cxxbridge04$rust_vec$##RUST_TYPE##$data( \
const rust::Vec<CXX_TYPE> *ptr) noexcept; \
size_t cxxbridge03$rust_vec$##RUST_TYPE##$stride() noexcept;
size_t cxxbridge04$rust_vec$##RUST_TYPE##$stride() noexcept;
#define RUST_VEC_OPS(RUST_TYPE, CXX_TYPE) \
template <> \
Vec<CXX_TYPE>::Vec() noexcept { \
cxxbridge03$rust_vec$##RUST_TYPE##$new(this); \
cxxbridge04$rust_vec$##RUST_TYPE##$new(this); \
} \
template <> \
void Vec<CXX_TYPE>::drop() noexcept { \
return cxxbridge03$rust_vec$##RUST_TYPE##$drop(this); \
return cxxbridge04$rust_vec$##RUST_TYPE##$drop(this); \
} \
template <> \
size_t Vec<CXX_TYPE>::size() const noexcept { \
return cxxbridge03$rust_vec$##RUST_TYPE##$len(this); \
return cxxbridge04$rust_vec$##RUST_TYPE##$len(this); \
} \
template <> \
const CXX_TYPE *Vec<CXX_TYPE>::data() const noexcept { \
return cxxbridge03$rust_vec$##RUST_TYPE##$data(this); \
return cxxbridge04$rust_vec$##RUST_TYPE##$data(this); \
} \
template <> \
size_t Vec<CXX_TYPE>::stride() noexcept { \
return cxxbridge03$rust_vec$##RUST_TYPE##$stride(); \
return cxxbridge04$rust_vec$##RUST_TYPE##$stride(); \
}
// Usize and isize are the same type as one of the below.
@ -290,7 +290,7 @@ FOR_EACH_RUST_VEC(RUST_VEC_EXTERNS)
} // extern "C"
namespace rust {
inline namespace cxxbridge03 {
inline namespace cxxbridge04 {
FOR_EACH_RUST_VEC(RUST_VEC_OPS)
} // namespace cxxbridge03
} // namespace cxxbridge04
} // namespace rust

View File

@ -4,9 +4,9 @@ use std::slice;
use std::str::{self, Utf8Error};
extern "C" {
#[link_name = "cxxbridge03$cxx_string$data"]
#[link_name = "cxxbridge04$cxx_string$data"]
fn string_data(_: &CxxString) -> *const u8;
#[link_name = "cxxbridge03$cxx_string$length"]
#[link_name = "cxxbridge04$cxx_string$length"]
fn string_length(_: &CxxString) -> usize;
}

View File

@ -139,7 +139,7 @@ macro_rules! impl_vector_element {
fn __vector_size(v: &CxxVector<$ty>) -> usize {
extern "C" {
attr! {
#[link_name = concat!("cxxbridge03$std$vector$", $segment, "$size")]
#[link_name = concat!("cxxbridge04$std$vector$", $segment, "$size")]
fn __vector_size(_: &CxxVector<$ty>) -> usize;
}
}
@ -148,7 +148,7 @@ macro_rules! impl_vector_element {
unsafe fn __get_unchecked(v: &CxxVector<$ty>, pos: usize) -> &$ty {
extern "C" {
attr! {
#[link_name = concat!("cxxbridge03$std$vector$", $segment, "$get_unchecked")]
#[link_name = concat!("cxxbridge04$std$vector$", $segment, "$get_unchecked")]
fn __get_unchecked(_: &CxxVector<$ty>, _: usize) -> *const $ty;
}
}
@ -157,7 +157,7 @@ macro_rules! impl_vector_element {
fn __unique_ptr_null() -> *mut c_void {
extern "C" {
attr! {
#[link_name = concat!("cxxbridge03$unique_ptr$std$vector$", $segment, "$null")]
#[link_name = concat!("cxxbridge04$unique_ptr$std$vector$", $segment, "$null")]
fn __unique_ptr_null(this: *mut *mut c_void);
}
}
@ -168,7 +168,7 @@ macro_rules! impl_vector_element {
unsafe fn __unique_ptr_raw(raw: *mut CxxVector<Self>) -> *mut c_void {
extern "C" {
attr! {
#[link_name = concat!("cxxbridge03$unique_ptr$std$vector$", $segment, "$raw")]
#[link_name = concat!("cxxbridge04$unique_ptr$std$vector$", $segment, "$raw")]
fn __unique_ptr_raw(this: *mut *mut c_void, raw: *mut CxxVector<$ty>);
}
}
@ -179,7 +179,7 @@ macro_rules! impl_vector_element {
unsafe fn __unique_ptr_get(repr: *mut c_void) -> *const CxxVector<Self> {
extern "C" {
attr! {
#[link_name = concat!("cxxbridge03$unique_ptr$std$vector$", $segment, "$get")]
#[link_name = concat!("cxxbridge04$unique_ptr$std$vector$", $segment, "$get")]
fn __unique_ptr_get(this: *const *mut c_void) -> *const CxxVector<$ty>;
}
}
@ -188,7 +188,7 @@ macro_rules! impl_vector_element {
unsafe fn __unique_ptr_release(mut repr: *mut c_void) -> *mut CxxVector<Self> {
extern "C" {
attr! {
#[link_name = concat!("cxxbridge03$unique_ptr$std$vector$", $segment, "$release")]
#[link_name = concat!("cxxbridge04$unique_ptr$std$vector$", $segment, "$release")]
fn __unique_ptr_release(this: *mut *mut c_void) -> *mut CxxVector<$ty>;
}
}
@ -197,7 +197,7 @@ macro_rules! impl_vector_element {
unsafe fn __unique_ptr_drop(mut repr: *mut c_void) {
extern "C" {
attr! {
#[link_name = concat!("cxxbridge03$unique_ptr$std$vector$", $segment, "$drop")]
#[link_name = concat!("cxxbridge04$unique_ptr$std$vector$", $segment, "$drop")]
fn __unique_ptr_drop(this: *mut *mut c_void);
}
}

View File

@ -32,7 +32,7 @@ unsafe fn to_c_error(msg: String) -> Result {
let len = msg.len();
extern "C" {
#[link_name = "cxxbridge03$error"]
#[link_name = "cxxbridge04$error"]
fn error(ptr: *const u8, len: usize) -> *const u8;
}

View File

@ -1,6 +1,6 @@
use std::slice;
#[export_name = "cxxbridge03$exception"]
#[export_name = "cxxbridge04$exception"]
unsafe extern "C" fn exception(ptr: *const u8, len: usize) -> *const u8 {
let slice = slice::from_raw_parts(ptr, len);
let boxed = String::from_utf8_lossy(slice).into_owned().into_boxed_str();

View File

@ -1,7 +1,7 @@
use std::slice;
use std::str;
#[export_name = "cxxbridge03$str$valid"]
#[export_name = "cxxbridge04$str$valid"]
unsafe extern "C" fn str_valid(ptr: *const u8, len: usize) -> bool {
let slice = slice::from_raw_parts(ptr, len);
str::from_utf8(slice).is_ok()

View File

@ -8,17 +8,17 @@ pub(crate) struct RustString {
repr: String,
}
#[export_name = "cxxbridge03$string$new"]
#[export_name = "cxxbridge04$string$new"]
unsafe extern "C" fn string_new(this: &mut MaybeUninit<String>) {
ptr::write(this.as_mut_ptr(), String::new());
}
#[export_name = "cxxbridge03$string$clone"]
#[export_name = "cxxbridge04$string$clone"]
unsafe extern "C" fn string_clone(this: &mut MaybeUninit<String>, other: &String) {
ptr::write(this.as_mut_ptr(), other.clone());
}
#[export_name = "cxxbridge03$string$from"]
#[export_name = "cxxbridge04$string$from"]
unsafe extern "C" fn string_from(
this: &mut MaybeUninit<String>,
ptr: *const u8,
@ -34,17 +34,17 @@ unsafe extern "C" fn string_from(
}
}
#[export_name = "cxxbridge03$string$drop"]
#[export_name = "cxxbridge04$string$drop"]
unsafe extern "C" fn string_drop(this: &mut ManuallyDrop<String>) {
ManuallyDrop::drop(this);
}
#[export_name = "cxxbridge03$string$ptr"]
#[export_name = "cxxbridge04$string$ptr"]
unsafe extern "C" fn string_ptr(this: &String) -> *const u8 {
this.as_ptr()
}
#[export_name = "cxxbridge03$string$len"]
#[export_name = "cxxbridge04$string$len"]
unsafe extern "C" fn string_len(this: &String) -> usize {
this.len()
}

View File

@ -21,31 +21,31 @@ macro_rules! rust_vec_shims {
const _: () = {
attr! {
#[export_name = concat!("cxxbridge03$rust_vec$", $segment, "$new")]
#[export_name = concat!("cxxbridge04$rust_vec$", $segment, "$new")]
unsafe extern "C" fn __new(this: *mut RustVec<$ty>) {
ptr::write(this, RustVec { repr: Vec::new() });
}
}
attr! {
#[export_name = concat!("cxxbridge03$rust_vec$", $segment, "$drop")]
#[export_name = concat!("cxxbridge04$rust_vec$", $segment, "$drop")]
unsafe extern "C" fn __drop(this: *mut RustVec<$ty>) {
ptr::drop_in_place(this);
}
}
attr! {
#[export_name = concat!("cxxbridge03$rust_vec$", $segment, "$len")]
#[export_name = concat!("cxxbridge04$rust_vec$", $segment, "$len")]
unsafe extern "C" fn __len(this: *const RustVec<$ty>) -> usize {
(*this).repr.len()
}
}
attr! {
#[export_name = concat!("cxxbridge03$rust_vec$", $segment, "$data")]
#[export_name = concat!("cxxbridge04$rust_vec$", $segment, "$data")]
unsafe extern "C" fn __data(this: *const RustVec<$ty>) -> *const $ty {
(*this).repr.as_ptr()
}
}
attr! {
#[export_name = concat!("cxxbridge03$rust_vec$", $segment, "$stride")]
#[export_name = concat!("cxxbridge04$rust_vec$", $segment, "$stride")]
unsafe extern "C" fn __stride() -> usize {
mem::size_of::<$ty>()
}

View File

@ -174,15 +174,15 @@ pub unsafe trait UniquePtrTarget {
}
extern "C" {
#[link_name = "cxxbridge03$unique_ptr$std$string$null"]
#[link_name = "cxxbridge04$unique_ptr$std$string$null"]
fn unique_ptr_std_string_null(this: *mut *mut c_void);
#[link_name = "cxxbridge03$unique_ptr$std$string$raw"]
#[link_name = "cxxbridge04$unique_ptr$std$string$raw"]
fn unique_ptr_std_string_raw(this: *mut *mut c_void, raw: *mut CxxString);
#[link_name = "cxxbridge03$unique_ptr$std$string$get"]
#[link_name = "cxxbridge04$unique_ptr$std$string$get"]
fn unique_ptr_std_string_get(this: *const *mut c_void) -> *const CxxString;
#[link_name = "cxxbridge03$unique_ptr$std$string$release"]
#[link_name = "cxxbridge04$unique_ptr$std$string$release"]
fn unique_ptr_std_string_release(this: *mut *mut c_void) -> *mut CxxString;
#[link_name = "cxxbridge03$unique_ptr$std$string$drop"]
#[link_name = "cxxbridge04$unique_ptr$std$string$drop"]
fn unique_ptr_std_string_drop(this: *mut *mut c_void);
}

View File

@ -3,7 +3,7 @@ use crate::syntax::symbol::{self, Symbol};
use crate::syntax::ExternFn;
use proc_macro2::Ident;
const CXXBRIDGE: &str = "cxxbridge03";
const CXXBRIDGE: &str = "cxxbridge04";
macro_rules! join {
($($segment:expr),*) => {

View File

@ -4,7 +4,7 @@ use quote::ToTokens;
use std::fmt::{self, Display, Write};
// A mangled symbol consisting of segments separated by '$'.
// For example: cxxbridge03$string$new
// For example: cxxbridge04$string$new
pub struct Symbol(String);
impl Display for Symbol {