Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/batch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::alloc::collections::BinaryHeap;
use crate::alloc::{
alloc::{alloc, dealloc},
collections::BinaryHeap,
};
use core::{
any::{type_name, TypeId},
fmt,
Expand Down Expand Up @@ -124,10 +127,16 @@ impl Drop for ColumnBatchBuilder {
for ty in archetype.types() {
let fill = *self.fill.get_mut(&ty.id()).unwrap().get_mut();
unsafe {
let scratch = alloc(ty.layout());
let base = archetype.get_dynamic(ty.id(), 0, 0).unwrap();
for i in 0..fill {
base.as_ptr().add(i as usize).drop_in_place()
scratch.copy_from_nonoverlapping(
base.as_ptr().add(i as usize),
ty.layout().size(),
);
ty.drop(scratch);
}
dealloc(scratch, ty.layout());
}
}
}
Expand Down Expand Up @@ -241,4 +250,23 @@ mod tests {
let _a = builder.writer::<usize>().unwrap();
let _b = builder.writer::<usize>().unwrap();
}

#[test]
#[cfg(feature = "std")]
fn dropping_builder_drops_elements() {
use std::sync::Arc;

let mut types = ColumnBatchType::new();
types.add::<Arc<()>>();
let builder = types.into_batch(1);
let value = Arc::new(());
builder
.writer::<Arc<()>>()
.unwrap()
.push(value.clone())
.unwrap();
assert_eq!(Arc::strong_count(&value), 2);
drop(builder);
assert_eq!(Arc::strong_count(&value), 1);
}
}
Loading