Skip to content

Commit 51457ff

Browse files
committed
start to hack the innards
1 parent 831c449 commit 51457ff

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

src/sys/table_collection.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ impl TableCollection {
1414
tsk.as_mut().sequence_length = sequence_length;
1515
Self(tsk)
1616
}
17+
18+
pub fn as_ptr(&self) -> *const tsk_table_collection_t {
19+
self.0.as_ptr()
20+
}
21+
22+
pub fn as_mut_ptr(&self) -> *mut tsk_table_collection_t {
23+
self.0.as_mut_ptr()
24+
}
1725
}

src/table_collection.rs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::vec;
33

44
use crate::error::TskitError;
55
use crate::sys::bindings as ll_bindings;
6+
use crate::sys::TableCollection as LLTableCollection;
67
use crate::types::Bookmark;
78
use crate::IndividualTableSortOptions;
89
use crate::Position;
@@ -54,18 +55,11 @@ use mbox::MBox;
5455
/// ```
5556
///
5657
pub struct TableCollection {
57-
inner: MBox<ll_bindings::tsk_table_collection_t>,
58+
inner: LLTableCollection,
5859
idmap: Vec<NodeId>,
5960
views: crate::table_views::TableViews,
6061
}
6162

62-
impl Drop for TableCollection {
63-
fn drop(&mut self) {
64-
let rv = unsafe { tsk_table_collection_free(self.as_mut_ptr()) };
65-
assert_eq!(rv, 0);
66-
}
67-
}
68-
6963
/// Returns a pointer to an uninitialized tsk_table_collection_t
7064
pub(crate) fn uninit_table_collection() -> MBox<ll_bindings::tsk_table_collection_t> {
7165
let temp = unsafe {
@@ -101,26 +95,12 @@ impl TableCollection {
10195
expected: "sequence_length >= 0.0".to_string(),
10296
});
10397
}
104-
let mut mbox = uninit_table_collection();
105-
let rv = unsafe { ll_bindings::tsk_table_collection_init(&mut *mbox, 0) };
106-
if rv < 0 {
107-
return Err(crate::error::TskitError::ErrorCode { code: rv });
108-
}
109-
let views = crate::table_views::TableViews::new_from_mbox_table_collection(&mut mbox)?;
110-
// AHA?
111-
assert!(std::ptr::eq(
112-
&mbox.as_ref().edges as *const ll_bindings::tsk_edge_table_t,
113-
views.edges().as_ref() as *const ll_bindings::tsk_edge_table_t
114-
));
115-
let mut tables = Self {
116-
inner: mbox,
98+
let inner = LLTableCollection::new(sequence_length.into());
99+
Ok(Self{
100+
inner,
117101
idmap: vec![],
118-
views,
119-
};
120-
unsafe {
121-
(*tables.as_mut_ptr()).sequence_length = f64::from(sequence_length);
122-
}
123-
Ok(tables)
102+
view: TableViews:
103+
})
124104
}
125105

126106
/// # Safety
@@ -1279,11 +1259,11 @@ impl TableCollection {
12791259

12801260
/// Pointer to the low-level C type.
12811261
pub fn as_ptr(&self) -> *const ll_bindings::tsk_table_collection_t {
1282-
&*self.inner
1262+
self.inner.as_ptr()
12831263
}
12841264

12851265
/// Mutable pointer to the low-level C type.
12861266
pub fn as_mut_ptr(&mut self) -> *mut ll_bindings::tsk_table_collection_t {
1287-
&mut *self.inner
1267+
self.inner.as_mut_ptr()
12881268
}
12891269
}

0 commit comments

Comments
 (0)