@@ -141,19 +141,35 @@ unsafe fn tsk_column_access<
141141 tsk_column_access_detail ( row, column, column_length) . map ( |v| v. into ( ) )
142142}
143143
144+ /// # SAFETY
145+ ///
146+ /// The safety requirements here are a bit fiddly.
147+ ///
148+ /// The hard case is when the columns contain data:
149+ ///
150+ /// * column and offset must both not be NULL
151+ /// * column_length and offset_length must both be
152+ /// the correct lengths for the input pointers
153+ /// * we return None if row < 0 or row > array length.
154+ /// * Thus, the requirement is that the two _lengths
155+ /// == 0 or (pointer both not NULL and the lengths are correct)
156+ ///
157+ /// When the lengths of each column are 0, we
158+ /// don't worry about anything else
144159fn tsk_ragged_column_access_detail < ' a , T > (
145160 row : usize ,
146161 column : & ' a [ T ] ,
147162 raw_offset : & ' a [ bindings:: tsk_size_t ] ,
148163) -> Option < & ' a [ T ] > {
149- if row >= column. len ( ) || raw_offset. is_empty ( ) {
164+ //if row < 0 || row as bindings::tsk_size_t > column_length || raw_offset.is_empty(){
165+ if row >= raw_offset. len ( ) || raw_offset. is_empty ( ) {
150166 None
151167 } else {
152168 let start = usize:: try_from ( raw_offset[ row] ) . ok ( ) ?;
153- let stop = if row < column . len ( ) {
169+ let stop = if row < raw_offset . len ( ) - 1 {
154170 usize:: try_from ( raw_offset[ row + 1 ] ) . ok ( ) ?
155171 } else {
156- raw_offset . len ( )
172+ column . len ( )
157173 } ;
158174 if start == stop {
159175 None
@@ -163,6 +179,9 @@ fn tsk_ragged_column_access_detail<'a, T>(
163179 }
164180}
165181
182+ // SAFETY: see tsk_ragged_column_access_detail
183+ // We further erquire that a pointer to a T can
184+ // be safely cast to a pointer to an O.
166185fn tsk_ragged_column_access < ' a , O , R : Into < bindings:: tsk_id_t > > (
167186 row : R ,
168187 column : & ' a [ O ] ,
@@ -171,6 +190,12 @@ fn tsk_ragged_column_access<'a, O, R: Into<bindings::tsk_id_t>>(
171190 let row = row. into ( ) ;
172191 let row = usize:: try_from ( row) . ok ( ) ?;
173192 tsk_ragged_column_access_detail ( row, column, raw_offset)
193+ //unsafe {
194+ // tsk_ragged_column_access_detail(row, column, column_length, offset, offset_length)
195+ // // If the safety requirements of tsk_ragged_column_access_detail are upheld,
196+ // // then we have received a valid pointer + length from which to make a slice
197+ // .map(|(p, n)| std::slice::from_raw_parts(p.cast::<O>(), n))
198+ //}
174199}
175200
176201/// # SAFETY
0 commit comments