Fix error causing dangling block

next
Sayan Nandan 1 year ago
parent 4eb2851cf9
commit e2112c8bc1
No known key found for this signature in database
GPG Key ID: 42EEDF4AE9D96B54

@ -110,6 +110,9 @@ impl PrimaryIndexKey {
dc.as_raw()
}
.dwordqn_load_qw_nw();
if cfg!(debug_assertions) && tag < TagUnique::Bin {
assert_eq!(b, mem::ZERO_BLOCK.as_ptr() as usize);
}
Self {
tag,
data: unsafe {
@ -131,6 +134,9 @@ impl PrimaryIndexKey {
}
fn __compute_vdata_offset(&self) -> [usize; 2] {
let (len, data) = self.data.dwordqn_load_qw_nw();
if cfg!(debug_assertions) && self.tag < TagUnique::Bin {
assert_eq!(data, mem::ZERO_BLOCK.as_ptr() as usize);
}
let actual_len = (len as usize) * (self.tag >= TagUnique::Bin) as usize;
[data, actual_len]
}

@ -32,7 +32,7 @@ use {
spec::{Dataspec1D, DataspecMeta1D},
tag::{CUTag, DataTag, TagClass},
},
mem::{DwordNN, DwordQN, NativeQword, WordIO},
mem::{DwordNN, DwordQN, NativeQword, SpecialPaddedWord, WordIO},
},
core::{fmt, mem, mem::ManuallyDrop, slice, str},
parking_lot::RwLock,
@ -49,7 +49,10 @@ impl Datacell {
pub fn new_bool(b: bool) -> Self {
unsafe {
// UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag
Self::new(CUTag::BOOL, DataRaw::word(WordIO::store(b)))
Self::new(
CUTag::BOOL,
DataRaw::word(SpecialPaddedWord::store(b).dword_promote()),
)
}
}
pub unsafe fn read_bool(&self) -> bool {
@ -68,7 +71,10 @@ impl Datacell {
pub fn new_uint(u: u64) -> Self {
unsafe {
// UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag
Self::new(CUTag::UINT, DataRaw::word(WordIO::store(u)))
Self::new(
CUTag::UINT,
DataRaw::word(SpecialPaddedWord::store(u).dword_promote()),
)
}
}
pub unsafe fn read_uint(&self) -> u64 {
@ -84,10 +90,13 @@ impl Datacell {
self.try_uint().unwrap()
}
// sint
pub fn new_sint(u: i64) -> Self {
pub fn new_sint(i: i64) -> Self {
unsafe {
// UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag
Self::new(CUTag::SINT, DataRaw::word(WordIO::store(u)))
Self::new(
CUTag::SINT,
DataRaw::word(SpecialPaddedWord::store(i).dword_promote()),
)
}
}
pub unsafe fn read_sint(&self) -> i64 {
@ -106,7 +115,10 @@ impl Datacell {
pub fn new_float(f: f64) -> Self {
unsafe {
// UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag
Self::new(CUTag::FLOAT, DataRaw::word(WordIO::store(f)))
Self::new(
CUTag::FLOAT,
DataRaw::word(SpecialPaddedWord::store(f).dword_promote()),
)
}
}
pub unsafe fn read_float(&self) -> f64 {

@ -35,7 +35,7 @@ mod tests;
pub use astr::AStr;
pub use uarray::UArray;
pub use vinline::VInline;
pub use word::{DwordNN, DwordQN, QwordNNNN, TwordNNN, WordIO};
pub use word::{DwordNN, DwordQN, QwordNNNN, TwordNNN, WordIO, ZERO_BLOCK};
// imports
use std::alloc::{self, Layout};

@ -24,8 +24,6 @@
*
*/
use std::mem::{self, ManuallyDrop};
#[macro_use]
mod macros;
pub mod compiler;
@ -41,7 +39,7 @@ use {
core::{
fmt::{self, Debug},
marker::PhantomData,
mem::MaybeUninit,
mem::{self, MaybeUninit},
ops::Deref,
},
std::process,
@ -52,11 +50,7 @@ pub const IS_ON_CI: bool = option_env!("CI").is_some();
const EXITCODE_ONE: i32 = 0x01;
pub fn bx_to_vec<T>(bx: Box<[T]>) -> Vec<T> {
let mut md = ManuallyDrop::new(bx);
// damn you, miri
let ptr = md.as_mut_ptr() as usize as *mut T;
let len = md.len();
unsafe { Vec::from_raw_parts(ptr, len, len) }
Vec::from(bx)
}
/// # Unsafe unwrapping

Loading…
Cancel
Save