Skip to content

Commit b83b5a8

Browse files
committed
start to unclutter low-level macros
1 parent 4c2c949 commit b83b5a8

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ mod node_table;
9292
mod population_table;
9393
pub mod prelude;
9494
mod site_table;
95+
mod sys;
9596
mod table_collection;
9697
mod table_iterator;
9798
pub mod table_views;

src/node_table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::ptr::NonNull;
22

33
use crate::bindings as ll_bindings;
44
use crate::metadata;
5+
use crate::sys;
56
use crate::NodeFlags;
67
use crate::SizeType;
78
use crate::Time;
@@ -195,7 +196,7 @@ impl NodeTable {
195196
/// # }
196197
/// ```
197198
pub fn time<N: Into<NodeId> + Copy>(&self, row: N) -> Option<Time> {
198-
unsafe_tsk_column_access!(row.into(), 0, self.num_rows(), self.as_ref(), time, Time)
199+
sys::tsk_column_access::<Time, _, _, _>(row.into(), self.as_ref().time, self.num_rows())
199200
}
200201

201202
/// Return the ``flags`` value from row ``row`` of the table.

src/sys.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::bindings;
2+
3+
pub fn tsk_column_access<
4+
O: From<T>,
5+
R: Into<bindings::tsk_id_t>,
6+
L: Into<bindings::tsk_size_t>,
7+
T: Copy,
8+
>(
9+
row: R,
10+
column: *const T,
11+
column_length: L,
12+
) -> Option<O> {
13+
let row = row.into();
14+
let column_length = column_length.into();
15+
if row < 0 || (row as crate::tsk_size_t) >= column_length {
16+
None
17+
} else {
18+
assert!(!column.is_null());
19+
// SAFETY: pointer is not null.
20+
// column_length is assumed to come directly
21+
// from a table.
22+
Some(unsafe { *column.offset(row as isize) }.into())
23+
}
24+
}

0 commit comments

Comments
 (0)