diff --git a/Cargo.lock b/Cargo.lock index be8e2cfa5..27230ad91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1091,9 +1091,9 @@ dependencies = [ [[package]] name = "moveit" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7d756ffe4e38013507d35bf726a93fcdae2cae043ab5ce477f13857a335030d" +checksum = "87d7335204cb6ef7bd647fa6db0be3e4d7aa25b5823a7aa030027ddf512cefba" dependencies = [ "cxx", ] diff --git a/Cargo.toml b/Cargo.toml index 5095a2379..180ec5c3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ resolver = "2" autocxx-macro = { path="macro", version="0.25.0" } cxx = "1.0.78" # ... also needed because expansion of type_id refers to ::cxx aquamarine = "0.1" # docs -moveit = { version = "0.5", features = [ "cxx" ] } +moveit = { version = "0.6", features = [ "cxx" ] } [workspace] members = ["parser", "engine", "gen/cmd", "gen/build", "macro", "demo", "tools/reduce", "tools/mdbook-preprocessor", "integration-tests"] @@ -39,3 +39,4 @@ exclude = ["examples/s2", "examples/steam-mini", "examples/subclass", "examples/ #cxx-gen = { path="../cxx/gen/lib" } #autocxx-bindgen = { path="../bindgen" } #moveit = { path="../moveit" } +#moveit = { git = "https://github.com/silvanshade/moveit", branch = "fix-deref-move-soundness-hole" } diff --git a/engine/src/conversion/codegen_rs/mod.rs b/engine/src/conversion/codegen_rs/mod.rs index 1dbc637ee..c22b73797 100644 --- a/engine/src/conversion/codegen_rs/mod.rs +++ b/engine/src/conversion/codegen_rs/mod.rs @@ -729,7 +729,7 @@ impl<'a> RsCodeGenerator<'a> { bindgen_mod_items.push(parse_quote! { impl autocxx::subclass::CppPeerConstructor<#cpp_id> for super::super::super::#id { fn make_peer(&mut self, peer_holder: autocxx::subclass::CppSubclassRustPeerHolder) -> cxx::UniquePtr<#cpp_path> { - use autocxx::moveit::EmplaceUnpinned; + use autocxx::moveit::Emplace; cxx::UniquePtr::emplace(#cpp_id :: new(peer_holder)) } } diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index cdeff6cc1..99ace357b 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -33,7 +33,7 @@ autocxx = { path = "..", version = "=0.25.0" } autocxx-engine = { version = "=0.25.0", path = "../engine", features = [ "build", ] } -moveit = { version = "0.5", features = [ "cxx" ] } +moveit = { version = "0.6", features = [ "cxx" ] } link-cplusplus = "1.0" tempfile = "3.4" indoc = "1.0" diff --git a/integration-tests/tests/integration_test.rs b/integration-tests/tests/integration_test.rs index 00b7153cb..55c47d456 100644 --- a/integration-tests/tests/integration_test.rs +++ b/integration-tests/tests/integration_test.rs @@ -9464,7 +9464,7 @@ fn test_uniqueptr_moveit() { }; "}; let rs = quote! { - use autocxx::moveit::EmplaceUnpinned; + use autocxx::moveit::Emplace; let mut up_obj = cxx::UniquePtr::emplace(ffi::A::new()); up_obj.as_mut().unwrap().set(42); assert_eq!(up_obj.get(), 42); @@ -9488,7 +9488,6 @@ fn test_various_emplacement() { }; "}; let rs = quote! { - use autocxx::moveit::EmplaceUnpinned; use autocxx::moveit::Emplace; let mut up_obj = cxx::UniquePtr::emplace(ffi::A::new()); up_obj.pin_mut().set(666); @@ -9552,7 +9551,7 @@ fn test_emplace_uses_overridden_new_and_delete() { assert!(ffi::was_delete_called()); ffi::reset_flags(); { - use autocxx::moveit::EmplaceUnpinned; + use autocxx::moveit::Emplace; let _ = cxx::UniquePtr::emplace(ffi::A::new()); } assert!(ffi::was_delete_called()); diff --git a/src/lib.rs b/src/lib.rs index c387d139f..43950c8bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -588,8 +588,8 @@ pub trait WithinBox { use cxx::kind::Trivial; use cxx::ExternType; +use moveit::Emplace; use moveit::MakeCppStorage; -use moveit::{Emplace, EmplaceUnpinned}; impl WithinUniquePtr for N where @@ -697,7 +697,6 @@ pub mod prelude { pub use moveit::moveit; pub use moveit::new::New; pub use moveit::Emplace; - pub use moveit::EmplaceUnpinned; } /// Re-export moveit for ease of consumers. diff --git a/src/value_param.rs b/src/value_param.rs index 1b7b5a910..7386d19fb 100644 --- a/src/value_param.rs +++ b/src/value_param.rs @@ -7,7 +7,7 @@ // except according to those terms. use cxx::{memory::UniquePtrTarget, UniquePtr}; -use moveit::{CopyNew, DerefMove, MoveNew, New}; +use moveit::{AsMove, CopyNew, MoveNew, New}; use std::{marker::PhantomPinned, mem::MaybeUninit, ops::Deref, pin::Pin}; /// A trait representing a parameter to a C++ function which is received @@ -192,22 +192,21 @@ where /// Explicitly force a value parameter to be taken using any type of [`crate::moveit::new::New`], /// i.e. a constructor. -pub fn as_new, T>(constructor: N) -> impl ValueParam { +pub fn as_new(constructor: N) -> impl ValueParam { ByNew(constructor) } /// Explicitly force a value parameter to be taken by copy. -pub fn as_copy, T>(ptr: P) -> impl ValueParam +pub fn as_copy(ptr: P) -> impl ValueParam where - T: CopyNew, + P::Target: CopyNew, { ByNew(crate::moveit::new::copy(ptr)) } /// Explicitly force a value parameter to be taken using C++ move semantics. -pub fn as_mov, T>(ptr: P) -> impl ValueParam +pub fn as_mov(ptr: P) -> impl ValueParam where - P: DerefMove, P::Target: MoveNew, { ByNew(crate::moveit::new::mov(ptr)) @@ -216,11 +215,8 @@ where #[doc(hidden)] pub struct ByNew(N); -unsafe impl ValueParam for ByNew -where - N: New, -{ - type StackStorage = MaybeUninit; +unsafe impl ValueParam for ByNew { + type StackStorage = MaybeUninit; unsafe fn populate_stack_space(self, mut stack: Pin<&mut Option>) { // Safety: we won't move/swap things within the pin. @@ -228,11 +224,11 @@ where *slot = Some(MaybeUninit::uninit()); self.0.new(Pin::new_unchecked(slot.as_mut().unwrap())) } - fn get_ptr(stack: Pin<&mut Self::StackStorage>) -> *mut T { - // Safety: it's OK to (briefly) create a reference to the T because we + fn get_ptr(stack: Pin<&mut Self::StackStorage>) -> *mut N::Output { + // Safety: it's OK to (briefly) create a reference to the N::Output because we // populated it within `populate_stack_space`. It's OK to unpack the pin // because we're not going to move the contents. - unsafe { Pin::into_inner_unchecked(stack).assume_init_mut() as *mut T } + unsafe { Pin::into_inner_unchecked(stack).assume_init_mut() as *mut N::Output } } fn do_drop(stack: Pin<&mut Self::StackStorage>) {