Skip to content

Commit a88cecc

Browse files
committed
complete replacement
1 parent d8cb01d commit a88cecc

File tree

3 files changed

+9
-47
lines changed

3 files changed

+9
-47
lines changed

src/_macros.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,6 @@ macro_rules! panic_on_tskit_error {
2727
};
2828
}
2929

30-
macro_rules! unsafe_tsk_column_access {
31-
($i: expr, $lo: expr, $hi: expr, $owner: expr, $array: ident) => {{
32-
let x = $crate::tsk_id_t::from($i);
33-
if x < $lo || (x as $crate::tsk_size_t) >= $hi {
34-
None
35-
} else {
36-
debug_assert!(!($owner).$array.is_null());
37-
if !$owner.$array.is_null() {
38-
// SAFETY: array is not null
39-
// and we did our best effort
40-
// on bounds checking
41-
Some(unsafe { *$owner.$array.offset(x as isize) })
42-
} else {
43-
None
44-
}
45-
}
46-
}};
47-
($i: expr, $lo: expr, $hi: expr, $owner: expr, $array: ident, $output_id_type: ty) => {{
48-
let x = $crate::tsk_id_t::from($i);
49-
if x < $lo || (x as $crate::tsk_size_t) >= $hi {
50-
None
51-
} else {
52-
debug_assert!(!($owner).$array.is_null());
53-
if !$owner.$array.is_null() {
54-
// SAFETY: array is not null
55-
// and we did our best effort
56-
// on bounds checking
57-
unsafe { Some(<$output_id_type>::from(*($owner.$array.offset(x as isize)))) }
58-
} else {
59-
None
60-
}
61-
}
62-
}};
63-
}
64-
6530
macro_rules! unsafe_tsk_ragged_column_access {
6631
($i: expr, $lo: expr, $hi: expr, $owner: expr, $array: ident, $offset_array: ident, $offset_array_len: ident, $output_id_type: ty) => {{
6732
let i = $crate::SizeType::try_from($i).ok()?;

src/migration_table.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,7 @@ impl MigrationTable {
262262
/// * `Some(time)` if `row` is valid.
263263
/// * `None` otherwise.
264264
pub fn time<M: Into<MigrationId> + Copy>(&self, row: M) -> Option<Time> {
265-
sys::tsk_column_access::<Time, _, _, _>(
266-
row.into(),
267-
self.as_ref().time,
268-
self.num_rows(),
269-
)
265+
sys::tsk_column_access::<Time, _, _, _>(row.into(), self.as_ref().time, self.num_rows())
270266
}
271267

272268
/// Retrieve decoded metadata for a `row`.

src/tree_interface.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::bindings as ll_bindings;
2+
use crate::sys;
23
use crate::tsk_id_t;
34
use crate::tsk_size_t;
45
use crate::NodeId;
@@ -297,15 +298,15 @@ impl TreeInterface {
297298
fn left_sample<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId> {
298299
// SAFETY: internal pointer cannot be NULL
299300
let ptr = unsafe { *self.as_ptr() };
300-
unsafe_tsk_column_access!(u.into(), 0, self.num_nodes, ptr, left_sample, NodeId)
301+
sys::tsk_column_access::<NodeId, _, _, _>(u.into(), ptr.left_sample, self.num_nodes)
301302
}
302303

303304
// error if we are not tracking samples,
304305
// Ok(None) if u is out of range
305306
fn right_sample<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId> {
306307
// SAFETY: internal pointer cannot be NULL
307308
let ptr = unsafe { *self.as_ptr() };
308-
unsafe_tsk_column_access!(u.into(), 0, self.num_nodes, ptr, right_sample, NodeId)
309+
sys::tsk_column_access::<NodeId, _, _, _>(u.into(), ptr.right_sample, self.num_nodes)
309310
}
310311

311312
/// Return the `[left, right)` coordinates of the tree.
@@ -330,7 +331,7 @@ impl TreeInterface {
330331
pub fn parent<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId> {
331332
// SAFETY: internal pointer cannot be NULL
332333
let ptr = unsafe { *self.as_ptr() };
333-
unsafe_tsk_column_access!(u.into(), 0, self.array_len, ptr, parent, NodeId)
334+
sys::tsk_column_access::<NodeId, _, _, _>(u.into(), ptr.parent, self.array_len)
334335
}
335336

336337
/// Get the left child of node `u`.
@@ -339,7 +340,7 @@ impl TreeInterface {
339340
pub fn left_child<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId> {
340341
// SAFETY: internal pointer cannot be NULL
341342
let ptr = unsafe { *self.as_ptr() };
342-
unsafe_tsk_column_access!(u.into(), 0, self.array_len, ptr, left_child, NodeId)
343+
sys::tsk_column_access::<NodeId, _, _, _>(u.into(), ptr.left_child, self.array_len)
343344
}
344345

345346
/// Get the right child of node `u`.
@@ -348,7 +349,7 @@ impl TreeInterface {
348349
pub fn right_child<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId> {
349350
// SAFETY: internal pointer cannot be NULL
350351
let ptr = unsafe { *self.as_ptr() };
351-
unsafe_tsk_column_access!(u.into(), 0, self.array_len, ptr, right_child, NodeId)
352+
sys::tsk_column_access::<NodeId, _, _, _>(u.into(), ptr.right_child, self.array_len)
352353
}
353354

354355
/// Get the left sib of node `u`.
@@ -357,7 +358,7 @@ impl TreeInterface {
357358
pub fn left_sib<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId> {
358359
// SAFETY: internal pointer cannot be NULL
359360
let ptr = unsafe { *self.as_ptr() };
360-
unsafe_tsk_column_access!(u.into(), 0, self.array_len, ptr, left_sib, NodeId)
361+
sys::tsk_column_access::<NodeId, _, _, _>(u.into(), ptr.left_sib, self.array_len)
361362
}
362363

363364
/// Get the right sib of node `u`.
@@ -366,7 +367,7 @@ impl TreeInterface {
366367
pub fn right_sib<N: Into<NodeId> + Copy>(&self, u: N) -> Option<NodeId> {
367368
// SAFETY: internal pointer cannot be NULL
368369
let ptr = unsafe { *self.as_ptr() };
369-
unsafe_tsk_column_access!(u.into(), 0, self.array_len, ptr, right_sib, NodeId)
370+
sys::tsk_column_access::<NodeId, _, _, _>(u.into(), ptr.right_sib, self.array_len)
370371
}
371372

372373
/// Obtain the list of samples for the current tree/tree sequence

0 commit comments

Comments
 (0)