Fix cloned rsx double drop (#2839)

* Implement Rc generational pointers

* Clean up error handling a bit

* start adding tests

* Simplify a few types

* Separate Rc and normal generational boxes

* Add tests for rc drop and read

* Move over the pointer instead of the data in ReadOnlySignal props

* Fix panic on ref drop and release mode builds

* final rc signal cleanup

* use rc generational boxes for event handlers as well

* add a regression test for read only signal cloning

* merge main

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2024-10-14 09:23:09 -07:00
1 parent 20d146d9bd
commit baf5a95cae
19 files changed
+905 -250

No files matched your search

+16 -3
View File
@@ -71,6 +71,19 @@ impl<T: 'static, S: Storage<T>> CopyValue<T, S> {
Self::new_with_caller(value, std::panic::Location::caller())
}
/// Create a new CopyValue without an owner. This will leak memory if you don't manually drop it.
pub fn leak_with_caller(value: T, caller: &'static std::panic::Location<'static>) -> Self {
Self {
value: GenerationalBox::leak(value, caller),
origin_scope: current_scope_id().expect("in a virtual dom"),
}
}
/// Point to another copy value
pub fn point_to(&mut self, other: Self) -> BorrowResult {
self.value.point_to(other.value)
}
pub(crate) fn new_with_caller(
value: T,
caller: &'static std::panic::Location<'static>,
@@ -78,7 +91,7 @@ impl<T: 'static, S: Storage<T>> CopyValue<T, S> {
let owner = current_owner();
Self {
value: owner.insert_with_caller(value, caller),
value: owner.insert_rc_with_caller(value, caller),
origin_scope: current_scope_id().expect("in a virtual dom"),
}
}
@@ -99,13 +112,13 @@ impl<T: 'static, S: Storage<T>> CopyValue<T, S> {
let owner = scope.owner();
Self {
value: owner.insert_with_caller(value, caller),
value: owner.insert_rc_with_caller(value, caller),
origin_scope: scope,
}
}
/// Manually drop the value in the CopyValue, invalidating the value in the process.
pub fn manually_drop(&self) -> Option<T> {
pub fn manually_drop(&self) {
self.value.manually_drop()
}