Skip to content

Commit 6baaf60

Browse files
committed
cool
1 parent 0b27e30 commit 6baaf60

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

src/table_collection.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,24 @@ impl TableCollection {
100100
/// ```
101101
pub fn new<P: Into<Position>>(sequence_length: P) -> Result<Self, TskitError> {
102102
let mut inner = LLTableCollection::new(sequence_length.into().into())?;
103-
let edges = crate::EdgeTable::new_from_table(inner.edges_mut())?;
104-
let nodes = crate::NodeTable::new_from_table(inner.nodes_mut())?;
105-
let sites = crate::SiteTable::new_from_table(inner.sites_mut())?;
106-
let mutations = crate::MutationTable::new_from_table(inner.mutations_mut())?;
107-
let individuals = crate::IndividualTable::new_from_table(inner.individuals_mut())?;
108-
let populations = crate::PopulationTable::new_from_table(inner.populations_mut())?;
109-
let migrations = crate::MigrationTable::new_from_table(inner.migrations_mut())?;
103+
// SAFETY: all the casts to *mut Foo are coming in via an implicit
104+
// cast from &mut Foo, which means that the ptr cannot be NULL.
105+
// Further, successful creation of LLTableCollection means
106+
// that tables are initialized.
107+
// Finally, none of these variables will be pub directly other than
108+
// by reference.
109+
let edges = unsafe { crate::EdgeTable::new_from_table(inner.edges_mut())? };
110+
let nodes = unsafe { crate::NodeTable::new_from_table(inner.nodes_mut())? };
111+
let sites = unsafe { crate::SiteTable::new_from_table(inner.sites_mut())? };
112+
let mutations = unsafe { crate::MutationTable::new_from_table(inner.mutations_mut())? };
113+
let individuals =
114+
unsafe { crate::IndividualTable::new_from_table(inner.individuals_mut())? };
115+
let populations =
116+
unsafe { crate::PopulationTable::new_from_table(inner.populations_mut())? };
117+
let migrations = unsafe { crate::MigrationTable::new_from_table(inner.migrations_mut())? };
110118
#[cfg(feature = "provenance")]
111119
let provenances =
112-
crate::provenance::ProvenanceTable::new_from_table(inner.provenances_mut())?;
120+
unsafe { crate::provenance::ProvenanceTable::new_from_table(inner.provenances_mut())? };
113121
Ok(Self {
114122
inner,
115123
idmap: vec![],
@@ -127,16 +135,24 @@ impl TableCollection {
127135

128136
pub(crate) fn new_from_ll(lltables: LLTableCollection) -> Result<Self, TskitError> {
129137
let mut inner = lltables;
130-
let edges = crate::EdgeTable::new_from_table(inner.edges_mut())?;
131-
let nodes = crate::NodeTable::new_from_table(inner.nodes_mut())?;
132-
let sites = crate::SiteTable::new_from_table(inner.sites_mut())?;
133-
let mutations = crate::MutationTable::new_from_table(inner.mutations_mut())?;
134-
let individuals = crate::IndividualTable::new_from_table(inner.individuals_mut())?;
135-
let populations = crate::PopulationTable::new_from_table(inner.populations_mut())?;
136-
let migrations = crate::MigrationTable::new_from_table(inner.migrations_mut())?;
138+
// SAFETY: all the casts to *mut Foo are coming in via an implicit
139+
// cast from &mut Foo, which means that the ptr cannot be NULL.
140+
// Further, successful creation of LLTableCollection means
141+
// that tables are initialized.
142+
// Finally, none of these variables will be pub directly other than
143+
// by reference.
144+
let edges = unsafe { crate::EdgeTable::new_from_table(inner.edges_mut())? };
145+
let nodes = unsafe { crate::NodeTable::new_from_table(inner.nodes_mut())? };
146+
let sites = unsafe { crate::SiteTable::new_from_table(inner.sites_mut())? };
147+
let mutations = unsafe { crate::MutationTable::new_from_table(inner.mutations_mut())? };
148+
let individuals =
149+
unsafe { crate::IndividualTable::new_from_table(inner.individuals_mut())? };
150+
let populations =
151+
unsafe { crate::PopulationTable::new_from_table(inner.populations_mut())? };
152+
let migrations = unsafe { crate::MigrationTable::new_from_table(inner.migrations_mut())? };
137153
#[cfg(feature = "provenance")]
138154
let provenances =
139-
crate::provenance::ProvenanceTable::new_from_table(inner.provenances_mut())?;
155+
unsafe { crate::provenance::ProvenanceTable::new_from_table(inner.provenances_mut())? };
140156
Ok(Self {
141157
inner,
142158
idmap: vec![],

0 commit comments

Comments
 (0)