-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: sys::TskBox<T> now requires that T implement a private trai…
…t. (#573) This change prevents TskBox from being used outside of the crate, which is a big safety improvement. The new trait bound also simplifies several internal implementation details.
- Loading branch information
Showing
8 changed files
with
156 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![macro_use] | ||
|
||
macro_rules! impl_tskteardown { | ||
($tsk: ty, $teardown: expr) => { | ||
impl super::TskTeardown for $tsk { | ||
unsafe fn teardown(&mut self) -> i32 { | ||
$teardown(self as _) | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
impl_tskteardown!( | ||
super::bindings::tsk_table_collection_t, | ||
super::bindings::tsk_table_collection_free | ||
); | ||
impl_tskteardown!(super::bindings::tsk_tree_t, super::bindings::tsk_tree_free); | ||
|
||
impl_tskteardown!( | ||
super::bindings::tsk_edge_table_t, | ||
super::bindings::tsk_edge_table_free | ||
); | ||
impl_tskteardown!( | ||
super::bindings::tsk_node_table_t, | ||
super::bindings::tsk_node_table_free | ||
); | ||
impl_tskteardown!( | ||
super::bindings::tsk_site_table_t, | ||
super::bindings::tsk_site_table_free | ||
); | ||
impl_tskteardown!( | ||
super::bindings::tsk_mutation_table_t, | ||
super::bindings::tsk_mutation_table_free | ||
); | ||
impl_tskteardown!( | ||
super::bindings::tsk_individual_table_t, | ||
super::bindings::tsk_individual_table_free | ||
); | ||
impl_tskteardown!( | ||
super::bindings::tsk_population_table_t, | ||
super::bindings::tsk_population_table_free | ||
); | ||
impl_tskteardown!( | ||
super::bindings::tsk_provenance_table_t, | ||
super::bindings::tsk_provenance_table_free | ||
); | ||
impl_tskteardown!( | ||
super::bindings::tsk_migration_table_t, | ||
super::bindings::tsk_migration_table_free | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// For a type `tsk_foo_t`, this trait abstracts | ||
/// out the functionality of `tsk_foo_free` | ||
/// | ||
/// # Note | ||
/// | ||
/// This trait should NEVER be part of the public API. | ||
pub trait TskTeardown { | ||
/// # Safety | ||
/// | ||
/// Implementations must abide by the expectations | ||
/// of `tsk_foo_free` and C's `free`. | ||
unsafe fn teardown(&mut self) -> i32; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.