@@ -237,7 +237,16 @@ impl MigrationTable {
237237 /// * `Some(position)` if `row` is valid.
238238 /// * `None` otherwise.
239239 pub fn left < M : Into < MigrationId > + Copy > ( & self , row : M ) -> Option < Position > {
240- sys:: tsk_column_access :: < Position , _ , _ , _ > ( row. into ( ) , self . as_ref ( ) . left , self . num_rows ( ) )
240+ assert ! ( self . num_rows( ) == 0 || !self . as_ref( ) . time. is_null( ) ) ;
241+ // SAFETY: either the column is empty or the pointer is not null,
242+ // in which case the correct lengths are from the low-level objects
243+ unsafe {
244+ sys:: tsk_column_access :: < Position , _ , _ , _ > (
245+ row. into ( ) ,
246+ self . as_ref ( ) . left ,
247+ self . num_rows ( ) ,
248+ )
249+ }
241250 }
242251
243252 /// Return the right coordinate for a given row.
@@ -247,11 +256,16 @@ impl MigrationTable {
247256 /// * `Some(positions)` if `row` is valid.
248257 /// * `None` otherwise.
249258 pub fn right < M : Into < MigrationId > + Copy > ( & self , row : M ) -> Option < Position > {
250- sys:: tsk_column_access :: < Position , _ , _ , _ > (
251- row. into ( ) ,
252- self . as_ref ( ) . right ,
253- self . num_rows ( ) ,
254- )
259+ assert ! ( self . num_rows( ) == 0 || !self . as_ref( ) . right. is_null( ) ) ;
260+ // SAFETY: either the column is empty or the pointer is not null,
261+ // in which case the correct lengths are from the low-level objects
262+ unsafe {
263+ sys:: tsk_column_access :: < Position , _ , _ , _ > (
264+ row. into ( ) ,
265+ self . as_ref ( ) . right ,
266+ self . num_rows ( ) ,
267+ )
268+ }
255269 }
256270
257271 /// Return the node for a given row.
@@ -261,7 +275,16 @@ impl MigrationTable {
261275 /// * `Some(node)` if `row` is valid.
262276 /// * `None` otherwise.
263277 pub fn node < M : Into < MigrationId > + Copy > ( & self , row : M ) -> Option < NodeId > {
264- sys:: tsk_column_access :: < NodeId , _ , _ , _ > ( row. into ( ) , self . as_ref ( ) . node , self . num_rows ( ) )
278+ assert ! ( self . num_rows( ) == 0 || !self . as_ref( ) . node. is_null( ) ) ;
279+ // SAFETY: either the column is empty or the pointer is not null,
280+ // in which case the correct lengths are from the low-level objects
281+ unsafe {
282+ sys:: tsk_column_access :: < NodeId , _ , _ , _ > (
283+ row. into ( ) ,
284+ self . as_ref ( ) . node ,
285+ self . num_rows ( ) ,
286+ )
287+ }
265288 }
266289
267290 /// Return the source population for a given row.
@@ -271,11 +294,16 @@ impl MigrationTable {
271294 /// * `Some(population)` if `row` is valid.
272295 /// * `None` otherwise.
273296 pub fn source < M : Into < MigrationId > + Copy > ( & self , row : M ) -> Option < PopulationId > {
274- sys:: tsk_column_access :: < PopulationId , _ , _ , _ > (
275- row. into ( ) ,
276- self . as_ref ( ) . source ,
277- self . num_rows ( ) ,
278- )
297+ assert ! ( self . num_rows( ) == 0 || !self . as_ref( ) . time. is_null( ) ) ;
298+ // SAFETY: either the column is empty or the pointer is not null,
299+ // in which case the correct lengths are from the low-level objects
300+ unsafe {
301+ sys:: tsk_column_access :: < PopulationId , _ , _ , _ > (
302+ row. into ( ) ,
303+ self . as_ref ( ) . source ,
304+ self . num_rows ( ) ,
305+ )
306+ }
279307 }
280308
281309 /// Return the destination population for a given row.
@@ -285,11 +313,16 @@ impl MigrationTable {
285313 /// * `Some(population)` if `row` is valid.
286314 /// * `None` otherwise.
287315 pub fn dest < M : Into < MigrationId > + Copy > ( & self , row : M ) -> Option < PopulationId > {
288- sys:: tsk_column_access :: < PopulationId , _ , _ , _ > (
289- row. into ( ) ,
290- self . as_ref ( ) . dest ,
291- self . num_rows ( ) ,
292- )
316+ assert ! ( self . num_rows( ) == 0 || !self . as_ref( ) . dest. is_null( ) ) ;
317+ // SAFETY: either the column is empty or the pointer is not null,
318+ // in which case the correct lengths are from the low-level objects
319+ unsafe {
320+ sys:: tsk_column_access :: < PopulationId , _ , _ , _ > (
321+ row. into ( ) ,
322+ self . as_ref ( ) . dest ,
323+ self . num_rows ( ) ,
324+ )
325+ }
293326 }
294327
295328 /// Return the time of the migration event for a given row.
@@ -299,7 +332,12 @@ impl MigrationTable {
299332 /// * `Some(time)` if `row` is valid.
300333 /// * `None` otherwise.
301334 pub fn time < M : Into < MigrationId > + Copy > ( & self , row : M ) -> Option < Time > {
302- sys:: tsk_column_access :: < Time , _ , _ , _ > ( row. into ( ) , self . as_ref ( ) . time , self . num_rows ( ) )
335+ assert ! ( self . num_rows( ) == 0 || !self . as_ref( ) . time. is_null( ) ) ;
336+ // SAFETY: either the column is empty or the pointer is not null,
337+ // in which case the correct lengths are from the low-level objects
338+ unsafe {
339+ sys:: tsk_column_access :: < Time , _ , _ , _ > ( row. into ( ) , self . as_ref ( ) . time , self . num_rows ( ) )
340+ }
303341 }
304342
305343 /// Retrieve decoded metadata for a `row`.
0 commit comments