Skip to content

Commit

Permalink
insert_via_serialize_bsatn: fix nested mut borrow bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jan 2, 2025
1 parent 5df4fc2 commit 2ed6ef4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/core/src/db/datastore/locking_tx_datastore/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![forbid(unsafe_op_in_unsafe_fn)]
#![deny(unsafe_op_in_unsafe_fn)]

pub mod committed_state;
pub mod datastore;
Expand Down
7 changes: 6 additions & 1 deletion crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
error::{IndexError, SequenceError, TableError},
execution_context::ExecutionContext,
};
use core::cell::RefCell;
use core::ops::RangeBounds;
use core::{iter, ops::Bound};
use smallvec::SmallVec;
Expand Down Expand Up @@ -1165,7 +1166,11 @@ impl MutTxId {
table_id: TableId,
row: &T,
) -> Result<(ColList, RowRefInsertion<'a>)> {
with_sys_table_buf(|buf| {
thread_local! {
static BUF: RefCell<Vec<u8>> = const { RefCell::new(Vec::new()) };
}
BUF.with_borrow_mut(|buf| {
buf.clear();
to_writer(buf, row).unwrap();
self.insert::<true>(table_id, buf)
})
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/db/datastore/system_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ pub(crate) fn with_sys_table_buf<R>(run: impl FnOnce(&mut Vec<u8>) -> R) -> R {
})
}

/// Read a value from a system table via BSatn.
/// Read a value from a system table via BSATN.
fn read_via_bsatn<T: DeserializeOwned>(row: RowRef<'_>) -> Result<T, DBError> {
with_sys_table_buf(|buf| Ok(row.read_via_bsatn::<T>(buf)?))
}
Expand Down

0 comments on commit 2ed6ef4

Please sign in to comment.