Skip to content

Commit 29ee97d

Browse files
committed
Fix: Fix buffer ownership for mmap
1 parent 3d072ad commit 29ee97d

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "minarrow"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2024"
55
authors = ['Peter G. Bower']
66
build = "build.rs"

src/structs/bitmask.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ impl Bitmask {
170170
!self.all_set()
171171
}
172172

173+
/// Creates an owned copy of the bitmask.
174+
/// Always creates a fresh owned copy, even if already owned.
175+
#[inline]
176+
pub fn to_owned_copy(&self) -> Self {
177+
let owned_bits = self.bits.to_owned_copy();
178+
Bitmask {
179+
bits: owned_bits,
180+
len: self.len,
181+
}
182+
}
183+
173184
/// Returns bit *idx*.
174185
/// - If `idx ≥ self.len` but still inside the physical buffer, returns `false`.
175186
/// Panics only when `idx` exceeds the physical capacity.
@@ -720,6 +731,7 @@ impl Display for Bitmask {
720731
}
721732
}
722733

734+
723735
#[cfg(test)]
724736
mod tests {
725737
use super::*;

src/structs/buffer.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,19 @@ impl<T> Buffer<T> {
358358
pub fn is_shared(&self) -> bool {
359359
matches!(self.storage, Storage::Shared { .. })
360360
}
361+
362+
/// Creates an owned copy of the buffer data.
363+
/// If the buffer is already owned, this clones the data.
364+
/// If the buffer is shared, this copies the data into a new owned Vec64.
365+
#[inline]
366+
pub fn to_owned_copy(&self) -> Self
367+
where
368+
T: Clone,
369+
{
370+
// Always create a fresh owned copy
371+
let vec: Vec64<T> = self.as_ref().iter().cloned().collect();
372+
Buffer::from_vec64(vec)
373+
}
361374
}
362375

363376
impl<T: Clone> Buffer<T> {
@@ -593,6 +606,7 @@ impl<T: Display> Display for Buffer<T> {
593606
}
594607
}
595608

609+
596610
// SAFETY: Shared buffers are read-only and `Arc` ensures memory is valid.
597611
// `Owned` is already `Send + Sync` via `Vec64<T>`.
598612
unsafe impl<T: Sync> Sync for Buffer<T> {}

0 commit comments

Comments
 (0)