Skip to content

Commit

Permalink
start to hack the innards
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Oct 10, 2023
1 parent 83fc86c commit 6ad9655
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
8 changes: 8 additions & 0 deletions src/sys/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ impl TableCollection {
tsk.as_mut().sequence_length = sequence_length;
Self(tsk)
}

pub fn as_ptr(&self) -> *const tsk_table_collection_t {
self.0.as_ptr()
}

pub fn as_mut_ptr(&self) -> *mut tsk_table_collection_t {
self.0.as_mut_ptr()
}
}
38 changes: 9 additions & 29 deletions src/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::vec;

use crate::error::TskitError;
use crate::sys::bindings as ll_bindings;
use crate::sys::TableCollection as LLTableCollection;
use crate::types::Bookmark;
use crate::IndividualTableSortOptions;
use crate::Position;
Expand Down Expand Up @@ -54,18 +55,11 @@ use mbox::MBox;
/// ```
///
pub struct TableCollection {
inner: MBox<ll_bindings::tsk_table_collection_t>,
inner: LLTableCollection,
idmap: Vec<NodeId>,
views: crate::table_views::TableViews,
}

impl Drop for TableCollection {
fn drop(&mut self) {
let rv = unsafe { tsk_table_collection_free(self.as_mut_ptr()) };
assert_eq!(rv, 0);
}
}

/// Returns a pointer to an uninitialized tsk_table_collection_t
pub(crate) fn uninit_table_collection() -> MBox<ll_bindings::tsk_table_collection_t> {
let temp = unsafe {
Expand Down Expand Up @@ -101,26 +95,12 @@ impl TableCollection {
expected: "sequence_length >= 0.0".to_string(),
});
}
let mut mbox = uninit_table_collection();
let rv = unsafe { ll_bindings::tsk_table_collection_init(&mut *mbox, 0) };
if rv < 0 {
return Err(crate::error::TskitError::ErrorCode { code: rv });
}
let views = crate::table_views::TableViews::new_from_mbox_table_collection(&mut mbox)?;
// AHA?
assert!(std::ptr::eq(
&mbox.as_ref().edges as *const ll_bindings::tsk_edge_table_t,
views.edges().as_ref() as *const ll_bindings::tsk_edge_table_t
));
let mut tables = Self {
inner: mbox,
let inner = LLTableCollection::new(sequence_length.into());
Ok(Self{
inner,
idmap: vec![],
views,
};
unsafe {
(*tables.as_mut_ptr()).sequence_length = f64::from(sequence_length);
}
Ok(tables)
view: TableViews:

Check failure on line 102 in src/table_collection.rs

View workflow job for this annotation

GitHub Actions / Test (Miri)

expected one of `!`, `,`, `.`, `::`, `?`, `{`, `}`, or an operator, found `:`

Check failure on line 102 in src/table_collection.rs

View workflow job for this annotation

GitHub Actions / Test (Miri)

struct `table_collection::TableCollection` has no field named `view`
})
}

/// # Safety
Expand Down Expand Up @@ -1279,11 +1259,11 @@ impl TableCollection {

/// Pointer to the low-level C type.
pub fn as_ptr(&self) -> *const ll_bindings::tsk_table_collection_t {
&*self.inner
self.inner.as_ptr()
}

/// Mutable pointer to the low-level C type.
pub fn as_mut_ptr(&mut self) -> *mut ll_bindings::tsk_table_collection_t {
&mut *self.inner
self.inner.as_mut_ptr()
}
}

0 comments on commit 6ad9655

Please sign in to comment.