Avoid storing shared value inside shared value.

This commit is contained in:
Stephen Chung 2020-08-01 22:28:17 +08:00
parent cc53b21731
commit 1daf91df30

View File

@ -1347,7 +1347,11 @@ impl Engine {
// Normal assignment
ScopeEntryType::Normal if op.is_empty() => {
if cfg!(not(feature = "no_shared")) && lhs_ptr.is_shared() {
*lhs_ptr.write_lock::<Dynamic>().unwrap() = rhs_val;
*lhs_ptr.write_lock::<Dynamic>().unwrap() = if rhs_val.is_shared() {
rhs_val.clone_inner_data().unwrap()
} else {
rhs_val
};
} else {
*lhs_ptr = rhs_val;
}
@ -1368,19 +1372,16 @@ impl Engine {
.get_fn(hash_fn, false)
.or_else(|| self.packages.get_fn(hash_fn, false))
{
#[cfg(not(feature = "no_shared"))]
let mut lock_guard;
#[cfg(not(feature = "no_shared"))]
let lhs_ptr = if lhs_ptr.is_shared() {
lock_guard = Some(lhs_ptr.write_lock::<Dynamic>().unwrap());
lock_guard.as_deref_mut().unwrap()
} else {
lhs_ptr
};
if cfg!(not(feature = "no_shared")) && lhs_ptr.is_shared() {
let mut lock_guard = lhs_ptr.write_lock::<Dynamic>().unwrap();
let lhs_ptr_inner = lock_guard.deref_mut();
// Overriding exact implementation
func(self, lib, &mut [lhs_ptr_inner, &mut rhs_val])?;
} else {
// Overriding exact implementation
func(self, lib, &mut [lhs_ptr, &mut rhs_val])?;
}
} else if run_builtin_op_assignment(op, lhs_ptr, &rhs_val)?.is_none() {
// Not built in, map to `var = var op rhs`
let op = &op[..op.len() - 1]; // extract operator without =
@ -1396,7 +1397,11 @@ impl Engine {
.map_err(|err| err.new_position(*op_pos))?;
if cfg!(not(feature = "no_shared")) && lhs_ptr.is_shared() {
*lhs_ptr.write_lock::<Dynamic>().unwrap() = value;
*lhs_ptr.write_lock::<Dynamic>().unwrap() = if value.is_shared() {
value.clone_inner_data().unwrap()
} else {
value
};
} else {
*lhs_ptr = value;
}