Skip to content

refactor: remove unsafe label from fn that is now safe #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 2 additions & 12 deletions src/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,7 @@ impl TableCollection {
})
}

/// # Safety
///
/// It is possible that the mbox's inner pointer has not be run through
/// tsk_table_collection_init, meaning that it is in an uninitialized state.
/// Or, it may be initialized and about to be used in a part of the C API
/// requiring an uninitialized table collection.
/// Consult the C API docs before using!
pub(crate) unsafe fn new_from_ll(lltables: LLTableCollection) -> Result<Self, TskitError> {
pub(crate) fn new_from_ll(lltables: LLTableCollection) -> Result<Self, TskitError> {
let mut inner = lltables;
let views = crate::table_views::TableViews::new_from_ll_table_collection(&mut inner)?;
Ok(Self {
Expand Down Expand Up @@ -748,10 +741,7 @@ impl TableCollection {
/// Return a "deep" copy of the tables.
pub fn deepcopy(&self) -> Result<TableCollection, TskitError> {
let (rv, inner) = self.inner.copy();

// SAFETY: we just initialized it.
// The C API doesn't free NULL pointers.
let tables = unsafe { TableCollection::new_from_ll(inner) }?;
let tables = TableCollection::new_from_ll(inner)?;
handle_tsk_return_value!(rv, tables)
}

Expand Down
4 changes: 1 addition & 3 deletions src/trees/treeseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ impl TreeSequence {
ll_bindings::tsk_table_collection_copy((*self.as_ptr()).tables, inner.as_mut_ptr(), 0)
};

// SAFETY: we just initialized it.
// The C API doesn't free NULL pointers.
handle_tsk_return_value!(rv, unsafe { TableCollection::new_from_ll(inner)? })
handle_tsk_return_value!(rv, TableCollection::new_from_ll(inner)?)
}

/// Create an iterator over trees.
Expand Down