diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | build.rs | 2 | ||||
-rw-r--r-- | gen/build/src/lib.rs | 2 | ||||
-rw-r--r-- | gen/src/builtin.rs | 28 | ||||
-rw-r--r-- | gen/src/write.rs | 96 | ||||
-rw-r--r-- | include/cxx.h | 90 | ||||
-rw-r--r-- | macro/src/expand.rs | 10 | ||||
-rw-r--r-- | src/cxx.cc | 128 | ||||
-rw-r--r-- | src/cxx_string.rs | 10 | ||||
-rw-r--r-- | src/cxx_vector.rs | 14 | ||||
-rw-r--r-- | src/result.rs | 2 | ||||
-rw-r--r-- | src/symbols/exception.rs | 2 | ||||
-rw-r--r-- | src/symbols/rust_str.rs | 2 | ||||
-rw-r--r-- | src/symbols/rust_string.rs | 12 | ||||
-rw-r--r-- | src/symbols/rust_vec.rs | 14 | ||||
-rw-r--r-- | src/unique_ptr.rs | 10 | ||||
-rw-r--r-- | syntax/mangle.rs | 2 | ||||
-rw-r--r-- | syntax/symbol.rs | 2 | ||||
-rw-r--r-- | tests/cxx_gen.rs | 4 |
19 files changed, 212 insertions, 220 deletions
@@ -3,7 +3,7 @@ name = "cxx" version = "0.5.10" # remember to update html_root_url authors = ["David Tolnay <dtolnay@gmail.com>"] edition = "2018" -links = "cxxbridge05" +links = "cxxbridge1" license = "MIT OR Apache-2.0" description = "Safe interop between Rust and C++" repository = "https://github.com/dtolnay/cxx" @@ -8,7 +8,7 @@ fn main() { .cpp(true) .cpp_link_stdlib(None) // linked via link-cplusplus crate .flag_if_supported(cxxbridge_flags::STD) - .compile("cxxbridge05"); + .compile("cxxbridge1"); println!("cargo:rerun-if-changed=src/cxx.cc"); println!("cargo:rerun-if-changed=include/cxx.h"); diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs index d2a04587..b290058f 100644 --- a/gen/build/src/lib.rs +++ b/gen/build/src/lib.rs @@ -357,7 +357,7 @@ fn make_include_dir(prj: &Project) -> Result<PathBuf> { let include_dir = prj.out_dir.join("cxxbridge").join("include"); let cxx_h = include_dir.join("rust").join("cxx.h"); let ref shared_cxx_h = prj.shared_dir.join("rust").join("cxx.h"); - if let Some(ref original) = env::var_os("DEP_CXXBRIDGE05_HEADER") { + if let Some(ref original) = env::var_os("DEP_CXXBRIDGE1_HEADER") { out::symlink_file(original, cxx_h)?; out::symlink_file(original, shared_cxx_h)?; } else { diff --git a/gen/src/builtin.rs b/gen/src/builtin.rs index 41d037a8..9c5f4fd7 100644 --- a/gen/src/builtin.rs +++ b/gen/src/builtin.rs @@ -92,10 +92,10 @@ pub(super) fn write(out: &mut OutFile) { } out.begin_block(Block::Namespace("rust")); - out.begin_block(Block::InlineNamespace("cxxbridge05")); + out.begin_block(Block::InlineNamespace("cxxbridge1")); writeln!(out, "// #include \"rust/cxx.h\""); - ifndef::write(out, builtin.panic, "CXXBRIDGE05_PANIC"); + ifndef::write(out, builtin.panic, "CXXBRIDGE1_PANIC"); if builtin.rust_string { out.next_section(); @@ -109,16 +109,16 @@ pub(super) fn write(out: &mut OutFile) { out.end_block(Block::AnonymousNamespace); } - ifndef::write(out, builtin.rust_string, "CXXBRIDGE05_RUST_STRING"); - ifndef::write(out, builtin.rust_str, "CXXBRIDGE05_RUST_STR"); - ifndef::write(out, builtin.rust_slice, "CXXBRIDGE05_RUST_SLICE"); - ifndef::write(out, builtin.rust_box, "CXXBRIDGE05_RUST_BOX"); - ifndef::write(out, builtin.unsafe_bitcopy, "CXXBRIDGE05_RUST_BITCOPY"); - ifndef::write(out, builtin.rust_vec, "CXXBRIDGE05_RUST_VEC"); - ifndef::write(out, builtin.rust_fn, "CXXBRIDGE05_RUST_FN"); - ifndef::write(out, builtin.rust_error, "CXXBRIDGE05_RUST_ERROR"); - ifndef::write(out, builtin.rust_isize, "CXXBRIDGE05_RUST_ISIZE"); - ifndef::write(out, builtin.relocatable, "CXXBRIDGE05_RELOCATABLE"); + ifndef::write(out, builtin.rust_string, "CXXBRIDGE1_RUST_STRING"); + ifndef::write(out, builtin.rust_str, "CXXBRIDGE1_RUST_STR"); + ifndef::write(out, builtin.rust_slice, "CXXBRIDGE1_RUST_SLICE"); + ifndef::write(out, builtin.rust_box, "CXXBRIDGE1_RUST_BOX"); + ifndef::write(out, builtin.unsafe_bitcopy, "CXXBRIDGE1_RUST_BITCOPY"); + ifndef::write(out, builtin.rust_vec, "CXXBRIDGE1_RUST_VEC"); + ifndef::write(out, builtin.rust_fn, "CXXBRIDGE1_RUST_FN"); + ifndef::write(out, builtin.rust_error, "CXXBRIDGE1_RUST_ERROR"); + ifndef::write(out, builtin.rust_isize, "CXXBRIDGE1_RUST_ISIZE"); + ifndef::write(out, builtin.relocatable, "CXXBRIDGE1_RELOCATABLE"); if builtin.manually_drop { out.next_section(); @@ -221,7 +221,7 @@ pub(super) fn write(out: &mut OutFile) { } out.end_block(Block::AnonymousNamespace); - out.end_block(Block::InlineNamespace("cxxbridge05")); + out.end_block(Block::InlineNamespace("cxxbridge1")); if builtin.trycatch { out.begin_block(Block::Namespace("behavior")); @@ -252,7 +252,7 @@ pub(super) fn write(out: &mut OutFile) { out.begin_block(Block::ExternC); writeln!( out, - "const char *cxxbridge05$exception(const char *, size_t);", + "const char *cxxbridge1$exception(const char *, size_t);", ); out.end_block(Block::ExternC); } diff --git a/gen/src/write.rs b/gen/src/write.rs index a014e63d..71d61633 100644 --- a/gen/src/write.rs +++ b/gen/src/write.rs @@ -179,7 +179,7 @@ fn pick_includes_and_builtins(out: &mut OutFile, apis: &[Api]) { fn write_struct<'a>(out: &mut OutFile<'a>, strct: &'a Struct, methods: &[&ExternFn]) { out.set_namespace(&strct.name.namespace); - let guard = format!("CXXBRIDGE05_STRUCT_{}", strct.name.to_symbol()); + let guard = format!("CXXBRIDGE1_STRUCT_{}", strct.name.to_symbol()); writeln!(out, "#ifndef {}", guard); writeln!(out, "#define {}", guard); for line in strct.doc.to_string().lines() { @@ -225,7 +225,7 @@ fn write_struct_with_methods<'a>( methods: &[&ExternFn], ) { out.set_namespace(&ety.name.namespace); - let guard = format!("CXXBRIDGE05_STRUCT_{}", ety.name.to_symbol()); + let guard = format!("CXXBRIDGE1_STRUCT_{}", ety.name.to_symbol()); writeln!(out, "#ifndef {}", guard); writeln!(out, "#define {}", guard); for line in ety.doc.to_string().lines() { @@ -251,7 +251,7 @@ fn write_struct_with_methods<'a>( fn write_enum<'a>(out: &mut OutFile<'a>, enm: &'a Enum) { out.set_namespace(&enm.name.namespace); - let guard = format!("CXXBRIDGE05_ENUM_{}", enm.name.to_symbol()); + let guard = format!("CXXBRIDGE1_ENUM_{}", enm.name.to_symbol()); writeln!(out, "#ifndef {}", guard); writeln!(out, "#define {}", guard); for line in enm.doc.to_string().lines() { @@ -501,7 +501,7 @@ fn write_cxx_function_shim<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) { writeln!(out, " throw$.len = ::std::strlen(catch$);"); writeln!( out, - " throw$.ptr = ::cxxbridge05$exception(catch$, throw$.len);", + " throw$.ptr = ::cxxbridge1$exception(catch$, throw$.len);", ); writeln!(out, " }});"); writeln!(out, " return throw$;"); @@ -1012,7 +1012,7 @@ fn write_generic_instantiations(out: &mut OutFile) { out.end_block(Block::ExternC); out.begin_block(Block::Namespace("rust")); - out.begin_block(Block::InlineNamespace("cxxbridge05")); + out.begin_block(Block::InlineNamespace("cxxbridge1")); for ty in out.types { if let Type::RustBox(ty) = ty { if let Type::Ident(inner) = &ty.inner { @@ -1026,7 +1026,7 @@ fn write_generic_instantiations(out: &mut OutFile) { } } } - out.end_block(Block::InlineNamespace("cxxbridge05")); + out.end_block(Block::InlineNamespace("cxxbridge1")); out.end_block(Block::Namespace("rust")); } @@ -1034,19 +1034,19 @@ fn write_rust_box_extern(out: &mut OutFile, ident: &Pair) { let inner = ident.to_fully_qualified(); let instance = ident.to_symbol(); - writeln!(out, "#ifndef CXXBRIDGE05_RUST_BOX_{}", instance); - writeln!(out, "#define CXXBRIDGE05_RUST_BOX_{}", instance); + writeln!(out, "#ifndef CXXBRIDGE1_RUST_BOX_{}", instance); + writeln!(out, "#define CXXBRIDGE1_RUST_BOX_{}", instance); writeln!( out, - "void cxxbridge05$box${}$uninit(::rust::Box<{}> *ptr) noexcept;", + "void cxxbridge1$box${}$uninit(::rust::Box<{}> *ptr) noexcept;", instance, inner, ); writeln!( out, - "void cxxbridge05$box${}$drop(::rust::Box<{}> *ptr) noexcept;", + "void cxxbridge1$box${}$drop(::rust::Box<{}> *ptr) noexcept;", instance, inner, ); - writeln!(out, "#endif // CXXBRIDGE05_RUST_BOX_{}", instance); + writeln!(out, "#endif // CXXBRIDGE1_RUST_BOX_{}", instance); } fn write_rust_vec_extern(out: &mut OutFile, element: &ResolvableName) { @@ -1054,44 +1054,44 @@ fn write_rust_vec_extern(out: &mut OutFile, element: &ResolvableName) { let inner = to_typename(&element, out.types); let instance = to_mangled(&element, out.types); - writeln!(out, "#ifndef CXXBRIDGE05_RUST_VEC_{}", instance); - writeln!(out, "#define CXXBRIDGE05_RUST_VEC_{}", instance); + writeln!(out, "#ifndef CXXBRIDGE1_RUST_VEC_{}", instance); + writeln!(out, "#define CXXBRIDGE1_RUST_VEC_{}", instance); writeln!( out, - "void cxxbridge05$rust_vec${}$new(const ::rust::Vec<{}> *ptr) noexcept;", + "void cxxbridge1$rust_vec${}$new(const ::rust::Vec<{}> *ptr) noexcept;", instance, inner, ); writeln!( out, - "void cxxbridge05$rust_vec${}$drop(::rust::Vec<{}> *ptr) noexcept;", + "void cxxbridge1$rust_vec${}$drop(::rust::Vec<{}> *ptr) noexcept;", instance, inner, ); writeln!( out, - "size_t cxxbridge05$rust_vec${}$len(const ::rust::Vec<{}> *ptr) noexcept;", + "size_t cxxbridge1$rust_vec${}$len(const ::rust::Vec<{}> *ptr) noexcept;", instance, inner, ); writeln!( out, - "const {} *cxxbridge05$rust_vec${}$data(const ::rust::Vec<{0}> *ptr) noexcept;", + "const {} *cxxbridge1$rust_vec${}$data(const ::rust::Vec<{0}> *ptr) noexcept;", inner, instance, ); writeln!( out, - "void cxxbridge05$rust_vec${}$reserve_total(::rust::Vec<{}> *ptr, size_t cap) noexcept;", + "void cxxbridge1$rust_vec${}$reserve_total(::rust::Vec<{}> *ptr, size_t cap) noexcept;", instance, inner, ); writeln!( out, - "void cxxbridge05$rust_vec${}$set_len(::rust::Vec<{}> *ptr, size_t len) noexcept;", + "void cxxbridge1$rust_vec${}$set_len(::rust::Vec<{}> *ptr, size_t len) noexcept;", instance, inner, ); writeln!( out, - "size_t cxxbridge05$rust_vec${}$stride() noexcept;", + "size_t cxxbridge1$rust_vec${}$stride() noexcept;", instance, ); - writeln!(out, "#endif // CXXBRIDGE05_RUST_VEC_{}", instance); + writeln!(out, "#endif // CXXBRIDGE1_RUST_VEC_{}", instance); } fn write_rust_box_impl(out: &mut OutFile, ident: &Pair) { @@ -1100,12 +1100,12 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Pair) { writeln!(out, "template <>"); writeln!(out, "void Box<{}>::uninit() noexcept {{", inner); - writeln!(out, " cxxbridge05$box${}$uninit(this);", instance); + writeln!(out, " cxxbridge1$box${}$uninit(this);", instance); writeln!(out, "}}"); writeln!(out, "template <>"); writeln!(out, "void Box<{}>::drop() noexcept {{", inner); - writeln!(out, " cxxbridge05$box${}$drop(this);", instance); + writeln!(out, " cxxbridge1$box${}$drop(this);", instance); writeln!(out, "}}"); } @@ -1116,30 +1116,22 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &ResolvableName) { writeln!(out, "template <>"); writeln!(out, "Vec<{}>::Vec() noexcept {{", inner); - writeln!(out, " cxxbridge05$rust_vec${}$new(this);", instance); + writeln!(out, " cxxbridge1$rust_vec${}$new(this);", instance); writeln!(out, "}}"); writeln!(out, "template <>"); writeln!(out, "void Vec<{}>::drop() noexcept {{", inner); - writeln!( - out, - " return cxxbridge05$rust_vec${}$drop(this);", - instance, - ); + writeln!(out, " return cxxbridge1$rust_vec${}$drop(this);", instance); writeln!(out, "}}"); writeln!(out, "template <>"); writeln!(out, "size_t Vec<{}>::size() const noexcept {{", inner); - writeln!(out, " return cxxbridge05$rust_vec${}$len(this);", instance); + writeln!(out, " return cxxbridge1$rust_vec${}$len(this);", instance); writeln!(out, "}}"); writeln!(out, "template <>"); writeln!(out, "const {} *Vec<{0}>::data() const noexcept {{", inner); - writeln!( - out, - " return cxxbridge05$rust_vec${}$data(this);", - instance, - ); + writeln!(out, " return cxxbridge1$rust_vec${}$data(this);", instance); writeln!(out, "}}"); writeln!(out, "template <>"); @@ -1150,7 +1142,7 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &ResolvableName) { ); writeln!( out, - " return cxxbridge05$rust_vec${}$reserve_total(this, cap);", + " return cxxbridge1$rust_vec${}$reserve_total(this, cap);", instance, ); writeln!(out, "}}"); @@ -1159,14 +1151,14 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &ResolvableName) { writeln!(out, "void Vec<{}>::set_len(size_t len) noexcept {{", inner); writeln!( out, - " return cxxbridge05$rust_vec${}$set_len(this, len);", + " return cxxbridge1$rust_vec${}$set_len(this, len);", instance, ); writeln!(out, "}}"); writeln!(out, "template <>"); writeln!(out, "size_t Vec<{}>::stride() noexcept {{", inner); - writeln!(out, " return cxxbridge05$rust_vec${}$stride();", instance); + writeln!(out, " return cxxbridge1$rust_vec${}$stride();", instance); writeln!(out, "}}"); } @@ -1174,12 +1166,12 @@ fn write_unique_ptr(out: &mut OutFile, ident: &ResolvableName) { let ty = Type::Ident(ident.clone()); let instance = to_mangled(&ty, out.types); - writeln!(out, "#ifndef CXXBRIDGE05_UNIQUE_PTR_{}", instance); - writeln!(out, "#define CXXBRIDGE05_UNIQUE_PTR_{}", instance); + writeln!(out, "#ifndef CXXBRIDGE1_UNIQUE_PTR_{}", instance); + writeln!(out, "#define CXXBRIDGE1_UNIQUE_PTR_{}", instance); write_unique_ptr_common(out, &ty); - writeln!(out, "#endif // CXXBRIDGE05_UNIQUE_PTR_{}", instance); + writeln!(out, "#endif // CXXBRIDGE1_UNIQUE_PTR_{}", instance); } // Shared by UniquePtr<T> and UniquePtr<CxxVector<T>>. @@ -1213,7 +1205,7 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: &Type) { ); writeln!( out, - "void cxxbridge05$unique_ptr${}$null(::std::unique_ptr<{}> *ptr) noexcept {{", + "void cxxbridge1$unique_ptr${}$null(::std::unique_ptr<{}> *ptr) noexcept {{", instance, inner, ); writeln!(out, " new (ptr) ::std::unique_ptr<{}>();", inner); @@ -1221,7 +1213,7 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: &Type) { if can_construct_from_value { writeln!( out, - "void cxxbridge05$unique_ptr${}$new(::std::unique_ptr<{}> *ptr, {} *value) noexcept {{", + "void cxxbridge1$unique_ptr${}$new(::std::unique_ptr<{}> *ptr, {} *value) noexcept {{", instance, inner, inner, ); writeln!( @@ -1233,28 +1225,28 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: &Type) { } writeln!( out, - "void cxxbridge05$unique_ptr${}$raw(::std::unique_ptr<{}> *ptr, {} *raw) noexcept {{", + "void cxxbridge1$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 {} *cxxbridge05$unique_ptr${}$get(const ::std::unique_ptr<{}>& ptr) noexcept {{", + "const {} *cxxbridge1$unique_ptr${}$get(const ::std::unique_ptr<{}>& ptr) noexcept {{", inner, instance, inner, ); writeln!(out, " return ptr.get();"); writeln!(out, "}}"); writeln!( out, - "{} *cxxbridge05$unique_ptr${}$release(::std::unique_ptr<{}>& ptr) noexcept {{", + "{} *cxxbridge1$unique_ptr${}$release(::std::unique_ptr<{}>& ptr) noexcept {{", inner, instance, inner, ); writeln!(out, " return ptr.release();"); writeln!(out, "}}"); writeln!( out, - "void cxxbridge05$unique_ptr${}$drop(::std::unique_ptr<{}> *ptr) noexcept {{", + "void cxxbridge1$unique_ptr${}$drop(::std::unique_ptr<{}> *ptr) noexcept {{", instance, inner, ); writeln!(out, " ptr->~unique_ptr();"); @@ -1266,18 +1258,18 @@ fn write_cxx_vector(out: &mut OutFile, vector_ty: &Type, element: &ResolvableNam let inner = to_typename(&element, out.types); let instance = to_mangled(&element, out.types); - writeln!(out, "#ifndef CXXBRIDGE05_VECTOR_{}", instance); - writeln!(out, "#define CXXBRIDGE05_VECTOR_{}", instance); + writeln!(out, "#ifndef CXXBRIDGE1_VECTOR_{}", instance); + writeln!(out, "#define CXXBRIDGE1_VECTOR_{}", instance); writeln!( out, - "size_t cxxbridge05$std$vector${}$size(const ::std::vector<{}> &s) noexcept {{", + "size_t cxxbridge1$std$vector${}$size(const ::std::vector<{}> &s) noexcept {{", instance, inner, ); writeln!(out, " return s.size();"); writeln!(out, "}}"); writeln!( out, - "const {} *cxxbridge05$std$vector${}$get_unchecked(const ::std::vector<{}> &s, size_t pos) noexcept {{", + "const {} *cxxbridge1$std$vector${}$get_unchecked(const ::std::vector<{}> &s, size_t pos) noexcept {{", inner, instance, inner, ); writeln!(out, " return &s[pos];"); @@ -1285,5 +1277,5 @@ fn write_cxx_vector(out: &mut OutFile, vector_ty: &Type, element: &ResolvableNam write_unique_ptr_common(out, vector_ty); - writeln!(out, "#endif // CXXBRIDGE05_VECTOR_{}", instance); + writeln!(out, "#endif // CXXBRIDGE1_VECTOR_{}", instance); } diff --git a/include/cxx.h b/include/cxx.h index 3c843304..24a52928 100644 --- a/include/cxx.h +++ b/include/cxx.h @@ -15,7 +15,7 @@ #endif namespace rust { -inline namespace cxxbridge05 { +inline namespace cxxbridge1 { struct unsafe_bitcopy_t; @@ -24,8 +24,8 @@ template <typename T> class impl; } -#ifndef CXXBRIDGE05_RUST_STRING -#define CXXBRIDGE05_RUST_STRING +#ifndef CXXBRIDGE1_RUST_STRING +#define CXXBRIDGE1_RUST_STRING class String final { public: String() noexcept; @@ -54,9 +54,9 @@ private: // Size and alignment statically verified by rust_string.rs. std::array<uintptr_t, 3> repr; }; -#endif // CXXBRIDGE05_RUST_STRING +#endif // CXXBRIDGE1_RUST_STRING -#ifndef CXXBRIDGE05_RUST_STR +#ifndef CXXBRIDGE1_RUST_STR class Str final { public: Str() noexcept; @@ -85,9 +85,9 @@ private: const char *ptr; size_t len; }; -#endif // CXXBRIDGE05_RUST_STR +#endif // CXXBRIDGE1_RUST_STR -#ifndef CXXBRIDGE05_RUST_SLICE +#ifndef CXXBRIDGE1_RUST_SLICE template <typename T> class Slice final { static_assert(std::is_const<T>::value, @@ -114,9 +114,9 @@ private: T *ptr; size_t len; }; -#endif // CXXBRIDGE05_RUST_SLICE +#endif // CXXBRIDGE1_RUST_SLICE -#ifndef CXXBRIDGE05_RUST_BOX +#ifndef CXXBRIDGE1_RUST_BOX template <typename T> class Box final { public: @@ -155,9 +155,9 @@ private: void drop() noexcept; T *ptr; }; -#endif // CXXBRIDGE05_RUST_BOX +#endif // CXXBRIDGE1_RUST_BOX -#ifndef CXXBRIDGE05_RUST_VEC +#ifndef CXXBRIDGE1_RUST_VEC template <typename T> class Vec final { public: @@ -224,9 +224,9 @@ private: // Size and alignment statically verified by rust_vec.rs. std::array<uintptr_t, 3> repr; }; -#endif // CXXBRIDGE05_RUST_VEC +#endif // CXXBRIDGE1_RUST_VEC -#ifndef CXXBRIDGE05_RUST_FN +#ifndef CXXBRIDGE1_RUST_FN template <typename Signature, bool Throws = false> class Fn; @@ -243,10 +243,10 @@ private: template <typename Signature> using TryFn = Fn<Signature, true>; -#endif // CXXBRIDGE05_RUST_FN +#endif // CXXBRIDGE1_RUST_FN -#ifndef CXXBRIDGE05_RUST_ERROR -#define CXXBRIDGE05_RUST_ERROR +#ifndef CXXBRIDGE1_RUST_ERROR +#define CXXBRIDGE1_RUST_ERROR class Error final : public std::exception { public: Error(const Error &); @@ -264,16 +264,16 @@ private: const char *msg; size_t len; }; -#endif // CXXBRIDGE05_RUST_ERROR +#endif // CXXBRIDGE1_RUST_ERROR -#ifndef CXXBRIDGE05_RUST_ISIZE -#define CXXBRIDGE05_RUST_ISIZE +#ifndef CXXBRIDGE1_RUST_ISIZE +#define CXXBRIDGE1_RUST_ISIZE #if defined(_WIN32) using isize = SSIZE_T; #else using isize = ssize_t; #endif -#endif // CXXBRIDGE05_RUST_ISIZE +#endif // CXXBRIDGE1_RUST_ISIZE std::ostream &operator<<(std::ostream &, const String &); std::ostream &operator<<(std::ostream &, const Str &); @@ -321,14 +321,14 @@ using is_relocatable = IsRelocatable<T>; //////////////////////////////////////////////////////////////////////////////// /// end public API, begin implementation details -#ifndef CXXBRIDGE05_PANIC -#define CXXBRIDGE05_PANIC +#ifndef CXXBRIDGE1_PANIC +#define CXXBRIDGE1_PANIC template <typename Exception> void panic [[noreturn]] (const char *msg); -#endif // CXXBRIDGE05_PANIC +#endif // CXXBRIDGE1_PANIC -#ifndef CXXBRIDGE05_RUST_FN -#define CXXBRIDGE05_RUST_FN +#ifndef CXXBRIDGE1_RUST_FN +#define CXXBRIDGE1_RUST_FN template <typename Ret, typename... Args, bool Throws> Ret Fn<Ret(Args...), Throws>::operator()(Args... args) const noexcept(!Throws) { return (*this->trampoline)(std::move(args)..., this->fn); @@ -338,28 +338,28 @@ template <typename Ret, typename... Args, bool Throws> Fn<Ret(Args...), Throws> Fn<Ret(Args...), Throws>::operator*() const noexcept { return *this; } -#endif // CXXBRIDGE05_RUST_FN +#endif // CXXBRIDGE1_RUST_FN -#ifndef CXXBRIDGE05_RUST_BITCOPY -#define CXXBRIDGE05_RUST_BITCOPY +#ifndef CXXBRIDGE1_RUST_BITCOPY +#define CXXBRIDGE1_RUST_BITCOPY struct unsafe_bitcopy_t final { explicit unsafe_bitcopy_t() = default; }; constexpr unsafe_bitcopy_t unsafe_bitcopy{}; -#endif // CXXBRIDGE05_RUST_BITCOPY +#endif // CXXBRIDGE1_RUST_BITCOPY -#ifndef CXXBRIDGE05_RUST_STR -#define CXXBRIDGE05_RUST_STR +#ifndef CXXBRIDGE1_RUST_STR +#define CXXBRIDGE1_RUST_STR inline const char *Str::data() const noexcept { return this->ptr; } inline size_t Str::size() const noexcept { return this->len; } inline size_t Str::length() const noexcept { return this->len; } -#endif // CXXBRIDGE05_RUST_STR +#endif // CXXBRIDGE1_RUST_STR -#ifndef CXXBRIDGE05_RUST_SLICE -#define CXXBRIDGE05_RUST_SLICE +#ifndef CXXBRIDGE1_RUST_SLICE +#define CXXBRIDGE1_RUST_SLICE template <typename T> Slice<T>::Slice() noexcept : ptr(reinterpret_cast<T *>(this)), len(0) {} @@ -380,10 +380,10 @@ template <typename T> size_t Slice<T>::length() const noexcept { return this->len; } -#endif // CXXBRIDGE05_RUST_SLICE +#endif // CXXBRIDGE1_RUST_SLICE -#ifndef CXXBRIDGE05_RUST_BOX -#define CXXBRIDGE05_RUST_BOX +#ifndef CXXBRIDGE1_RUST_BOX +#define CXXBRIDGE1_RUST_BOX template <typename T> Box<T>::Box(const Box &other) : Box(*other) {} @@ -479,10 +479,10 @@ T *Box<T>::into_raw() noexcept { template <typename T> Box<T>::Box() noexcept {} -#endif // CXXBRIDGE05_RUST_BOX +#endif // CXXBRIDGE1_RUST_BOX -#ifndef CXXBRIDGE05_RUST_VEC -#define CXXBRIDGE05_RUST_VEC +#ifndef CXXBRIDGE1_RUST_VEC +#define CXXBRIDGE1_RUST_VEC template <typename T> Vec<T>::Vec(Vec &&other) noexcept { this->repr = other.repr; @@ -618,10 +618,10 @@ 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 // CXXBRIDGE05_RUST_VEC +#endif // CXXBRIDGE1_RUST_VEC -#ifndef CXXBRIDGE05_RELOCATABLE -#define CXXBRIDGE05_RELOCATABLE +#ifndef CXXBRIDGE1_RELOCATABLE +#define CXXBRIDGE1_RELOCATABLE namespace detail { template <typename... Ts> struct make_void { @@ -655,7 +655,7 @@ struct IsRelocatable std::integral_constant< bool, std::is_trivially_move_constructible<T>::value && std::is_trivially_destructible<T>::value>>::type {}; -#endif // CXXBRIDGE05_RELOCATABLE +#endif // CXXBRIDGE1_RELOCATABLE -} // namespace cxxbridge05 +} // namespace cxxbridge1 } // namespace rust diff --git a/macro/src/expand.rs b/macro/src/expand.rs index 36ba6f28..f29c4cc1 100644 --- a/macro/src/expand.rs +++ b/macro/src/expand.rs @@ -796,7 +796,7 @@ fn type_id(name: &Pair) -> TokenStream { } fn expand_rust_box(ident: &ResolvableName, types: &Types) -> TokenStream { - let link_prefix = format!("cxxbridge05$box${}$", types.resolve(ident).to_symbol()); + let link_prefix = format!("cxxbridge1$box${}$", types.resolve(ident).to_symbol()); let link_uninit = format!("{}uninit", link_prefix); let link_drop = format!("{}drop", link_prefix); @@ -825,7 +825,7 @@ fn expand_rust_box(ident: &ResolvableName, types: &Types) -> TokenStream { } fn expand_rust_vec(elem: &ResolvableName, types: &Types) -> TokenStream { - let link_prefix = format!("cxxbridge05$rust_vec${}$", elem.to_symbol(types)); + let link_prefix = format!("cxxbridge1$rust_vec${}$", elem.to_symbol(types)); let link_new = format!("{}new", link_prefix); let link_drop = format!("{}drop", link_prefix); let link_len = format!("{}len", link_prefix); @@ -889,7 +889,7 @@ fn expand_unique_ptr( explicit_impl: Option<&Impl>, ) -> TokenStream { let name = ident.rust.to_string(); - let prefix = format!("cxxbridge05$unique_ptr${}$", ident.to_symbol(types)); + let prefix = format!("cxxbridge1$unique_ptr${}$", ident.to_symbol(types)); let link_null = format!("{}null", prefix); let link_new = format!("{}new", prefix); let link_raw = format!("{}raw", prefix); @@ -973,11 +973,11 @@ fn expand_cxx_vector( ) -> TokenStream { let _ = explicit_impl; let name = elem.rust.to_string(); - let prefix = format!("cxxbridge05$std$vector${}$", elem.to_symbol(types)); + let prefix = format!("cxxbridge1$std$vector${}$", elem.to_symbol(types)); let link_size = format!("{}size", prefix); let link_get_unchecked = format!("{}get_unchecked", prefix); let unique_ptr_prefix = format!( - "cxxbridge05$unique_ptr$std$vector${}$", + "cxxbridge1$unique_ptr$std$vector${}$", elem.to_symbol(types) ); let link_unique_ptr_null = format!("{}null", unique_ptr_prefix); @@ -9,45 +9,45 @@ #include <vector> extern "C" { -void cxxbridge05$cxx_string$init(std::string *s, const uint8_t *ptr, - size_t len) noexcept { +void cxxbridge1$cxx_string$init(std::string *s, const uint8_t *ptr, + size_t len) noexcept { new (s) std::string(reinterpret_cast<const char *>(ptr), len); } -void cxxbridge05$cxx_string$destroy(std::string *s) noexcept { +void cxxbridge1$cxx_string$destroy(std::string *s) noexcept { using std::string; s->~string(); } -const char *cxxbridge05$cxx_string$data(const std::string &s) noexcept { +const char *cxxbridge1$cxx_string$data(const std::string &s) noexcept { return s.data(); } -size_t cxxbridge05$cxx_string$length(const std::string &s) noexcept { +size_t cxxbridge1$cxx_string$length(const std::string &s) noexcept { return s.length(); } -void cxxbridge05$cxx_string$push(std::string &s, const uint8_t *ptr, - size_t len) noexcept { +void cxxbridge1$cxx_string$push(std::string &s, const uint8_t *ptr, + size_t len) noexcept { s.append(reinterpret_cast<const char *>(ptr), len); } // rust::String -void cxxbridge05$string$new(rust::String *self) noexcept; -void cxxbridge05$string$clone(rust::String *self, - const rust::String &other) noexcept; -bool cxxbridge05$string$from(rust::String *self, const char *ptr, - size_t len) noexcept; -void cxxbridge05$string$drop(rust::String *self) noexcept; -const char *cxxbridge05$string$ptr(const rust::String *self) noexcept; -size_t cxxbridge05$string$len(const rust::String *self) noexcept; +void cxxbridge1$string$new(rust::String *self) noexcept; +void cxxbridge1$string$clone(rust::String *self, + const rust::String &other) noexcept; +bool cxxbridge1$string$from(rust::String *self, const char *ptr, + size_t len) noexcept; +void cxxbridge1$string$drop(rust::String *self) noexcept; +const char *cxxbridge1$string$ptr(const rust::String *self) noexcept; +size_t cxxbridge1$string$len(const rust::String *self) noexcept; // rust::Str -bool cxxbridge05$str$valid(const char *ptr, size_t len) noexcept; +bool cxxbridge1$str$valid(const char *ptr, size_t len) noexcept; } // extern "C" namespace rust { -inline namespace cxxbridge05 { +inline namespace cxxbridge1 { template <typename Exception> void panic [[noreturn]] (const char *msg) { @@ -61,21 +61,21 @@ void panic [[noreturn]] (const char *msg) { template void panic<std::out_of_range>[[noreturn]] (const char *msg); -String::String() noexcept { cxxbridge05$string$new(this); } +String::String() noexcept { cxxbridge1$string$new(this); } String::String(const String &other) noexcept { - cxxbridge05$string$clone(this, other); + cxxbridge1$string$clone(this, other); } String::String(String &&other) noexcept { this->repr = other.repr; - cxxbridge05$string$new(&other); + cxxbridge1$string$new(&other); } -String::~String() noexcept { cxxbridge05$string$drop(this); } +String::~String() noexcept { cxxbridge1$string$drop(this); } static void initString(String *self, const char *s, size_t len) { - if (!cxxbridge05$string$from(self, s, len)) { + if (!cxxbridge1$string$from(self, s, len)) { panic<std::invalid_argument>("data for rust::String is not utf-8"); } } @@ -96,17 +96,17 @@ String::String(const char *s, size_t len) { String &String::operator=(const String &other) noexcept { if (this != &other) { - cxxbridge05$string$drop(this); - cxxbridge05$string$clone(this, other); + cxxbridge1$string$drop(this); + cxxbridge1$string$clone(this, other); } return *this; } String &String::operator=(String &&other) noexcept { if (this != &other) { - cxxbridge05$string$drop(this); + cxxbridge1$string$drop(this); this->repr = other.repr; - cxxbridge05$string$new(&other); + cxxbridge1$string$new(&other); } return *this; } @@ -116,12 +116,12 @@ String::operator std::string() const { } const char *String::data() const noexcept { - return cxxbridge05$string$ptr(this); + return cxxbridge1$string$ptr(this); } -size_t String::size() const noexcept { return cxxbridge05$string$len(this); } +size_t String::size() const noexcept { return cxxbridge1$string$len(this); } -size_t String::length() const noexcept { return cxxbridge05$string$len(this); } +size_t String::length() const noexcept { return cxxbridge1$string$len(this); } String::String(unsafe_bitcopy_t, const String &bits) noexcept : repr(bits.repr) {} @@ -134,7 +134,7 @@ std::ostream &operator<<(std::ostream &os, const String &s) { Str::Str() noexcept : ptr(reinterpret_cast<const char *>(1)), len(0) {} static void initStr(const char *ptr, size_t len) { - if (!cxxbridge05$str$valid(ptr, len)) { + if (!cxxbridge1$str$valid(ptr, len)) { panic<std::invalid_argument>("data for rust::Str is not utf-8"); } } @@ -171,7 +171,7 @@ static_assert(std::is_trivially_copy_assignable<Str>::value, static_assert(std::is_trivially_destructible<Str>::value, "trivial ~Str()"); extern "C" { -const char *cxxbridge05$error(const char *ptr, size_t len) { +const char *cxxbridge1$error(const char *ptr, size_t len) { char *copy = new char[len]; std::strncpy(copy, ptr, len); return copy; @@ -179,7 +179,7 @@ const char *cxxbridge05$error(const char *ptr, size_t len) { } // extern "C" Error::Error(const Error &other) - : std::exception(other), msg(cxxbridge05$error(other.msg, other.len)), + : std::exception(other), msg(cxxbridge1$error(other.msg, other.len)), len(other.len) {} Error::Error(Error &&other) noexcept @@ -195,7 +195,7 @@ Error &Error::operator=(const Error &other) { std::exception::operator=(other); delete[] this->msg; this->msg = nullptr; - this->msg = cxxbridge05$error(other.msg, other.len); + this->msg = cxxbridge1$error(other.msg, other.len); this->len = other.len; } return *this; @@ -214,27 +214,27 @@ Error &Error::operator=(Error &&other) noexcept { const char *Error::what() const noexcept { return this->msg; } -} // namespace cxxbridge05 +} // namespace cxxbridge1 } // namespace rust extern "C" { -void cxxbridge05$unique_ptr$std$string$null( +void cxxbridge1$unique_ptr$std$string$null( std::unique_ptr<std::string> *ptr) noexcept { new (ptr) std::unique_ptr<std::string>(); } -void cxxbridge05$unique_ptr$std$string$raw(std::unique_ptr<std::string> *ptr, - std::string *raw) noexcept { +void cxxbridge1$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 *cxxbridge05$unique_ptr$std$string$get( +const std::string *cxxbridge1$unique_ptr$std$string$get( const std::unique_ptr<std::string> &ptr) noexcept { return ptr.get(); } -std::string *cxxbridge05$unique_ptr$std$string$release( +std::string *cxxbridge1$unique_ptr$std$string$release( std::unique_ptr<std::string> &ptr) noexcept { return ptr.release(); } -void cxxbridge05$unique_ptr$std$string$drop( +void cxxbridge1$unique_ptr$std$string$drop( std::unique_ptr<std::string> *ptr) noexcept { ptr->~unique_ptr(); } @@ -246,81 +246,81 @@ static_assert(sizeof(std::string) <= 8 * sizeof(void *), "unexpectedly large std::string size"); #define STD_VECTOR_OPS(RUST_TYPE, CXX_TYPE) \ - size_t cxxbridge05$std$vector$##RUST_TYPE##$size( \ + size_t cxxbridge1$std$vector$##RUST_TYPE##$size( \ const std::vector<CXX_TYPE> &s) noexcept { \ return s.size(); \ } \ - const CXX_TYPE *cxxbridge05$std$vector$##RUST_TYPE##$get_unchecked( \ + const CXX_TYPE *cxxbridge1$std$vector$##RUST_TYPE##$get_unchecked( \ const std::vector<CXX_TYPE> &s, size_t pos) noexcept { \ return &s[pos]; \ } \ - void cxxbridge05$unique_ptr$std$vector$##RUST_TYPE##$null( \ + void cxxbridge1$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 cxxbridge05$unique_ptr$std$vector$##RUST_TYPE##$raw( \ + void cxxbridge1$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> \ - *cxxbridge05$unique_ptr$std$vector$##RUST_TYPE##$get( \ + *cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$get( \ const std::unique_ptr<std::vector<CXX_TYPE>> &ptr) noexcept { \ return ptr.get(); \ } \ std::vector<CXX_TYPE> \ - *cxxbridge05$unique_ptr$std$vector$##RUST_TYPE##$release( \ + *cxxbridge1$unique_ptr$std$vector$##RUST_TYPE##$release( \ std::unique_ptr<std::vector<CXX_TYPE>> &ptr) noexcept { \ return ptr.release(); \ } \ - void cxxbridge05$unique_ptr$std$vector$##RUST_TYPE##$drop( \ + void cxxbridge1$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 cxxbridge05$rust_vec$##RUST_TYPE##$new( \ + void cxxbridge1$rust_vec$##RUST_TYPE##$new( \ rust::Vec<CXX_TYPE> *ptr) noexcept; \ - void cxxbridge05$rust_vec$##RUST_TYPE##$drop( \ + void cxxbridge1$rust_vec$##RUST_TYPE##$drop( \ rust::Vec<CXX_TYPE> *ptr) noexcept; \ - size_t cxxbridge05$rust_vec$##RUST_TYPE##$len( \ + size_t cxxbridge1$rust_vec$##RUST_TYPE##$len( \ const rust::Vec<CXX_TYPE> *ptr) noexcept; \ - const CXX_TYPE *cxxbridge05$rust_vec$##RUST_TYPE##$data( \ + const CXX_TYPE *cxxbridge1$rust_vec$##RUST_TYPE##$data( \ const rust::Vec<CXX_TYPE> *ptr) noexcept; \ - void cxxbridge05$rust_vec$##RUST_TYPE##$reserve_total( \ + void cxxbridge1$rust_vec$##RUST_TYPE##$reserve_total( \ rust::Vec<CXX_TYPE> *ptr, size_t cap) noexcept; \ - void cxxbridge05$rust_vec$##RUST_TYPE##$set_len(rust::Vec<CXX_TYPE> *ptr, \ - size_t len) noexcept; \ - size_t cxxbridge05$rust_vec$##RUST_TYPE##$stride() noexcept; + void cxxbridge1$rust_vec$##RUST_TYPE##$set_len(rust::Vec<CXX_TYPE> *ptr, \ + size_t len) noexcept; \ + size_t cxxbridge1$rust_vec$##RUST_TYPE##$stride() noexcept; #define RUST_VEC_OPS(RUST_TYPE, CXX_TYPE) \ template <> \ Vec<CXX_TYPE>::Vec() noexcept { \ - cxxbridge05$rust_vec$##RUST_TYPE##$new(this); \ + cxxbridge1$rust_vec$##RUST_TYPE##$new(this); \ } \ template <> \ void Vec<CXX_TYPE>::drop() noexcept { \ - return cxxbridge05$rust_vec$##RUST_TYPE##$drop(this); \ + return cxxbridge1$rust_vec$##RUST_TYPE##$drop(this); \ } \ template <> \ size_t Vec<CXX_TYPE>::size() const noexcept { \ - return cxxbridge05$rust_vec$##RUST_TYPE##$len(this); \ + return cxxbridge1$rust_vec$##RUST_TYPE##$len(this); \ } \ template <> \ const CXX_TYPE *Vec<CXX_TYPE>::data() const noexcept { \ - return cxxbridge05$rust_vec$##RUST_TYPE##$data(this); \ + return cxxbridge1$rust_vec$##RUST_TYPE##$data(this); \ } \ template <> \ void Vec<CXX_TYPE>::reserve_total(size_t cap) noexcept { \ - cxxbridge05$rust_vec$##RUST_TYPE##$reserve_total(this, cap); \ + cxxbridge1$rust_vec$##RUST_TYPE##$reserve_total(this, cap); \ } \ template <> \ void Vec<CXX_TYPE>::set_len(size_t len) noexcept { \ - cxxbridge05$rust_vec$##RUST_TYPE##$set_len(this, len); \ + cxxbridge1$rust_vec$##RUST_TYPE##$set_len(this, len); \ } \ template <> \ size_t Vec<CXX_TYPE>::stride() noexcept { \ - return cxxbridge05$rust_vec$##RUST_TYPE##$stride(); \ + return cxxbridge1$rust_vec$##RUST_TYPE##$stride(); \ } // Usize and isize are the same type as one of the below. @@ -353,7 +353,7 @@ FOR_EACH_RUST_VEC(RUST_VEC_EXTERNS) } // extern "C" namespace rust { -inline namespace cxxbridge05 { +inline namespace cxxbridge1 { FOR_EACH_RUST_VEC(RUST_VEC_OPS) -} // namespace cxxbridge05 +} // namespace cxxbridge1 } // namespace rust diff --git a/src/cxx_string.rs b/src/cxx_string.rs index 7a66b47d..a2bd72bb 100644 --- a/src/cxx_string.rs +++ b/src/cxx_string.rs @@ -9,15 +9,15 @@ use core::slice; use core::str::{self, Utf8Error}; extern "C" { - #[link_name = "cxxbridge05$cxx_string$init"] + #[link_name = "cxxbridge1$cxx_string$init"] fn string_init(this: &mut MaybeUninit<CxxString>, ptr: *const u8, len: usize); - #[link_name = "cxxbridge05$cxx_string$destroy"] + #[link_name = "cxxbridge1$cxx_string$destroy"] fn string_destroy(this: &mut MaybeUninit<CxxString>); - #[link_name = "cxxbridge05$cxx_string$data"] + #[link_name = "cxxbridge1$cxx_string$data"] fn string_data(this: &CxxString) -> *const u8; - #[link_name = "cxxbridge05$cxx_string$length"] + #[link_name = "cxxbridge1$cxx_string$length"] fn string_length(this: &CxxString) -> usize; - #[link_name = "cxxbridge05$cxx_string$push"] + #[link_name = "cxxbridge1$cxx_string$push"] fn string_push(this: Pin<&mut CxxString>, ptr: *const u8, len: usize); } diff --git a/src/cxx_vector.rs b/src/cxx_vector.rs index e495a971..d1611dbd 100644 --- a/src/cxx_vector.rs +++ b/src/cxx_vector.rs @@ -163,7 +163,7 @@ macro_rules! impl_vector_element { fn __vector_size(v: &CxxVector<$ty>) -> usize { extern "C" { attr! { - #[link_name = concat!("cxxbridge05$std$vector$", $segment, "$size")] + #[link_name = concat!("cxxbridge1$std$vector$", $segment, "$size")] fn __vector_size(_: &CxxVector<$ty>) -> usize; } } @@ -172,7 +172,7 @@ macro_rules! impl_vector_element { unsafe fn __get_unchecked(v: &CxxVector<$ty>, pos: usize) -> *const $ty { extern "C" { attr! { - #[link_name = concat!("cxxbridge05$std$vector$", $segment, "$get_unchecked")] + #[link_name = concat!("cxxbridge1$std$vector$", $segment, "$get_unchecked")] fn __get_unchecked(_: &CxxVector<$ty>, _: usize) -> *const $ty; } } @@ -181,7 +181,7 @@ macro_rules! impl_vector_element { fn __unique_ptr_null() -> *mut c_void { extern "C" { attr! { - #[link_name = concat!("cxxbridge05$unique_ptr$std$vector$", $segment, "$null")] + #[link_name = concat!("cxxbridge1$unique_ptr$std$vector$", $segment, "$null")] fn __unique_ptr_null(this: *mut *mut c_void); } } @@ -192,7 +192,7 @@ macro_rules! impl_vector_element { unsafe fn __unique_ptr_raw(raw: *mut CxxVector<Self>) -> *mut c_void { extern "C" { attr! { - #[link_name = concat!("cxxbridge05$unique_ptr$std$vector$", $segment, "$raw")] + #[link_name = concat!("cxxbridge1$unique_ptr$std$vector$", $segment, "$raw")] fn __unique_ptr_raw(this: *mut *mut c_void, raw: *mut CxxVector<$ty>); } } @@ -203,7 +203,7 @@ macro_rules! impl_vector_element { unsafe fn __unique_ptr_get(repr: *mut c_void) -> *const CxxVector<Self> { extern "C" { attr! { - #[link_name = concat!("cxxbridge05$unique_ptr$std$vector$", $segment, "$get")] + #[link_name = concat!("cxxbridge1$unique_ptr$std$vector$", $segment, "$get")] fn __unique_ptr_get(this: *const *mut c_void) -> *const CxxVector<$ty>; } } @@ -212,7 +212,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!("cxxbridge05$unique_ptr$std$vector$", $segment, "$release")] + #[link_name = concat!("cxxbridge1$unique_ptr$std$vector$", $segment, "$release")] fn __unique_ptr_release(this: *mut *mut c_void) -> *mut CxxVector<$ty>; } } @@ -221,7 +221,7 @@ macro_rules! impl_vector_element { unsafe fn __unique_ptr_drop(mut repr: *mut c_void) { extern "C" { attr! { - #[link_name = concat!("cxxbridge05$unique_ptr$std$vector$", $segment, "$drop")] + #[link_name = concat!("cxxbridge1$unique_ptr$std$vector$", $segment, "$drop")] fn __unique_ptr_drop(this: *mut *mut c_void); } } diff --git a/src/result.rs b/src/result.rs index fcced769..29c5d679 100644 --- a/src/result.rs +++ b/src/result.rs @@ -34,7 +34,7 @@ unsafe fn to_c_error(msg: String) -> Result { let len = msg.len(); extern "C" { - #[link_name = "cxxbridge05$error"] + #[link_name = "cxxbridge1$error"] fn error(ptr: *const u8, len: usize) -> *const u8; } diff --git a/src/symbols/exception.rs b/src/symbols/exception.rs index b408f255..0c1bb876 100644 --- a/src/symbols/exception.rs +++ b/src/symbols/exception.rs @@ -2,7 +2,7 @@ use alloc::boxed::Box; use alloc::string::String; use core::slice; -#[export_name = "cxxbridge05$exception"] +#[export_name = "cxxbridge1$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(); diff --git a/src/symbols/rust_str.rs b/src/symbols/rust_str.rs index b6553818..041147d2 100644 --- a/src/symbols/rust_str.rs +++ b/src/symbols/rust_str.rs @@ -1,7 +1,7 @@ use core::slice; use core::str; -#[export_name = "cxxbridge05$str$valid"] +#[export_name = "cxxbridge1$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() diff --git a/src/symbols/rust_string.rs b/src/symbols/rust_string.rs index e5ab9eaa..944aec44 100644 --- a/src/symbols/rust_string.rs +++ b/src/symbols/rust_string.rs @@ -5,17 +5,17 @@ use core::ptr; use core::slice; use core::str; -#[export_name = "cxxbridge05$string$new"] +#[export_name = "cxxbridge1$string$new"] unsafe extern "C" fn string_new(this: &mut MaybeUninit<String>) { ptr::write(this.as_mut_ptr(), String::new()); } -#[export_name = "cxxbridge05$string$clone"] +#[export_name = "cxxbridge1$string$clone"] unsafe extern "C" fn string_clone(this: &mut MaybeUninit<String>, other: &String) { ptr::write(this.as_mut_ptr(), other.clone()); } -#[export_name = "cxxbridge05$string$from"] +#[export_name = "cxxbridge1$string$from"] unsafe extern "C" fn string_from( this: &mut MaybeUninit<String>, ptr: *const u8, @@ -31,17 +31,17 @@ unsafe extern "C" fn string_from( } } -#[export_name = "cxxbridge05$string$drop"] +#[export_name = "cxxbridge1$string$drop"] unsafe extern "C" fn string_drop(this: &mut ManuallyDrop<String>) { ManuallyDrop::drop(this); } -#[export_name = "cxxbridge05$string$ptr"] +#[export_name = "cxxbridge1$string$ptr"] unsafe extern "C" fn string_ptr(this: &String) -> *const u8 { this.as_ptr() } -#[export_name = "cxxbridge05$string$len"] +#[export_name = "cxxbridge1$string$len"] unsafe extern "C" fn string_len(this: &String) -> usize { this.len() } diff --git a/src/symbols/rust_vec.rs b/src/symbols/rust_vec.rs index 90fbc542..df6dec6d 100644 --- a/src/symbols/rust_vec.rs +++ b/src/symbols/rust_vec.rs @@ -11,43 +11,43 @@ macro_rules! rust_vec_shims { const _: () = { attr! { - #[export_name = concat!("cxxbridge05$rust_vec$", $segment, "$new")] + #[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$new")] unsafe extern "C" fn __new(this: *mut RustVec<$ty>) { ptr::write(this, RustVec { repr: Vec::new() }); } } attr! { - #[export_name = concat!("cxxbridge05$rust_vec$", $segment, "$drop")] + #[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$drop")] unsafe extern "C" fn __drop(this: *mut RustVec<$ty>) { ptr::drop_in_place(this); } } attr! { - #[export_name = concat!("cxxbridge05$rust_vec$", $segment, "$len")] + #[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$len")] unsafe extern "C" fn __len(this: *const RustVec<$ty>) -> usize { (*this).repr.len() } } attr! { - #[export_name = concat!("cxxbridge05$rust_vec$", $segment, "$data")] + #[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$data")] unsafe extern "C" fn __data(this: *const RustVec<$ty>) -> *const $ty { (*this).repr.as_ptr() } } attr! { - #[export_name = concat!("cxxbridge05$rust_vec$", $segment, "$reserve_total")] + #[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$reserve_total")] unsafe extern "C" fn __reserve_total(this: *mut RustVec<$ty>, cap: usize) { (*this).reserve_total(cap); } } attr! { - #[export_name = concat!("cxxbridge05$rust_vec$", $segment, "$set_len")] + #[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$set_len")] unsafe extern "C" fn __set_len(this: *mut RustVec<$ty>, len: usize) { (*this).repr.set_len(len); } } attr! { - #[export_name = concat!("cxxbridge05$rust_vec$", $segment, "$stride")] + #[export_name = concat!("cxxbridge1$rust_vec$", $segment, "$stride")] unsafe extern "C" fn __stride() -> usize { mem::size_of::<$ty>() } diff --git a/src/unique_ptr.rs b/src/unique_ptr.rs index baba32e3..c4d436ef 100644 --- a/src/unique_ptr.rs +++ b/src/unique_ptr.rs @@ -171,15 +171,15 @@ pub unsafe trait UniquePtrTarget { } extern "C" { - #[link_name = "cxxbridge05$unique_ptr$std$string$null"] + #[link_name = "cxxbridge1$unique_ptr$std$string$null"] fn unique_ptr_std_string_null(this: *mut *mut c_void); - #[link_name = "cxxbridge05$unique_ptr$std$string$raw"] + #[link_name = "cxxbridge1$unique_ptr$std$string$raw"] fn unique_ptr_std_string_raw(this: *mut *mut c_void, raw: *mut CxxString); - #[link_name = "cxxbridge05$unique_ptr$std$string$get"] + #[link_name = "cxxbridge1$unique_ptr$std$string$get"] fn unique_ptr_std_string_get(this: *const *mut c_void) -> *const CxxString; - #[link_name = "cxxbridge05$unique_ptr$std$string$release"] + #[link_name = "cxxbridge1$unique_ptr$std$string$release"] fn unique_ptr_std_string_release(this: *mut *mut c_void) -> *mut CxxString; - #[link_name = "cxxbridge05$unique_ptr$std$string$drop"] + #[link_name = "cxxbridge1$unique_ptr$std$string$drop"] fn unique_ptr_std_string_drop(this: *mut *mut c_void); } diff --git a/syntax/mangle.rs b/syntax/mangle.rs index cc5115a9..84e33989 100644 --- a/syntax/mangle.rs +++ b/syntax/mangle.rs @@ -2,7 +2,7 @@ use crate::syntax::symbol::{self, Symbol}; use crate::syntax::{ExternFn, Types}; use proc_macro2::Ident; -const CXXBRIDGE: &str = "cxxbridge05"; +const CXXBRIDGE: &str = "cxxbridge1"; macro_rules! join { ($($segment:expr),*) => { diff --git a/syntax/symbol.rs b/syntax/symbol.rs index 253f57dc..9a0a4a1e 100644 --- a/syntax/symbol.rs +++ b/syntax/symbol.rs @@ -5,7 +5,7 @@ use quote::ToTokens; use std::fmt::{self, Display, Write}; // A mangled symbol consisting of segments separated by '$'. -// For example: cxxbridge05$string$new +// For example: cxxbridge1$string$new pub struct Symbol(String); impl Display for Symbol { diff --git a/tests/cxx_gen.rs b/tests/cxx_gen.rs index a0c9ff49..d33092c7 100644 --- a/tests/cxx_gen.rs +++ b/tests/cxx_gen.rs @@ -20,7 +20,7 @@ fn test_extern_c_function() { let output = str::from_utf8(&generated.implementation).unwrap(); // To avoid continual breakage we won't test every byte. // Let's look for the major features. - assert!(output.contains("void cxxbridge05$do_cpp_thing(::rust::repr::PtrLen foo)")); + assert!(output.contains("void cxxbridge1$do_cpp_thing(::rust::repr::PtrLen foo)")); } #[test] @@ -30,5 +30,5 @@ fn test_impl_annotation() { let source = BRIDGE0.parse().unwrap(); let generated = generate_header_and_cc(source, &opt).unwrap(); let output = str::from_utf8(&generated.implementation).unwrap(); - assert!(output.contains("ANNOTATION void cxxbridge05$do_cpp_thing(::rust::repr::PtrLen foo)")); + assert!(output.contains("ANNOTATION void cxxbridge1$do_cpp_thing(::rust::repr::PtrLen foo)")); } |