File tree 5 files changed +24
-13
lines changed
5 files changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -11,17 +11,18 @@ use super::bindings::tsk_table_collection_free;
11
11
use super :: bindings:: tsk_table_collection_init;
12
12
use super :: bindings:: tsk_table_collection_t;
13
13
use super :: tskbox:: TskBox ;
14
+ use super :: Error ;
14
15
15
16
pub struct TableCollection ( TskBox < tsk_table_collection_t > ) ;
16
17
17
18
impl TableCollection {
18
- pub fn new ( sequence_length : f64 ) -> Self {
19
+ pub fn new ( sequence_length : f64 ) -> Result < Self , Error > {
19
20
let mut tsk = TskBox :: new (
20
21
|tc : * mut tsk_table_collection_t | unsafe { tsk_table_collection_init ( tc, 0 ) } ,
21
22
tsk_table_collection_free,
22
- ) ;
23
+ ) ? ;
23
24
tsk. as_mut ( ) . sequence_length = sequence_length;
24
- Self ( tsk)
25
+ Ok ( Self ( tsk) )
25
26
}
26
27
27
28
// # Safety
Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ macro_rules! basic_llowningtable_impl {
49
49
let table = super :: tskbox:: TskBox :: new(
50
50
|x: * mut super :: bindings:: $tsktable| unsafe { super :: bindings:: $init( x, 0 ) } ,
51
51
super :: bindings:: $free,
52
- ) ;
52
+ )
53
+ . unwrap( ) ;
53
54
Self ( table)
54
55
}
55
56
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ impl<'treeseq> LLTree<'treeseq> {
21
21
super :: bindings:: tsk_tree_init ( x, treeseq. as_ref ( ) , flags. bits ( ) )
22
22
} ,
23
23
super :: bindings:: tsk_tree_free,
24
- ) ;
24
+ ) ? ;
25
25
// Gotta ask Jerome about this one--why isn't this handled in tsk_tree_init??
26
26
if !flags. contains ( TreeFlags :: NO_SAMPLE_COUNTS ) {
27
27
// SAFETY: nobody is null here.
Original file line number Diff line number Diff line change 1
1
use std:: ptr:: NonNull ;
2
2
3
+ use super :: Error ;
4
+
3
5
#[ derive( Debug ) ]
4
6
pub struct TskBox < T > {
5
7
tsk : NonNull < T > ,
@@ -19,11 +21,15 @@ impl<T> TskBox<T> {
19
21
pub fn new < F : Fn ( * mut T ) -> i32 > (
20
22
init : F ,
21
23
teardown : unsafe extern "C" fn ( * mut T ) -> i32 ,
22
- ) -> Self {
24
+ ) -> Result < Self , Error > {
23
25
// SAFETY: we will initialize it next
24
26
let mut uninit = unsafe { Self :: new_uninit ( teardown) } ;
25
- let _ = init ( uninit. as_mut ( ) ) ;
26
- uninit
27
+ let rv = init ( uninit. as_mut ( ) ) ;
28
+ if rv < 0 {
29
+ Err ( Error :: Code ( rv) )
30
+ } else {
31
+ Ok ( uninit)
32
+ }
27
33
}
28
34
29
35
// # Safety
@@ -136,7 +142,8 @@ fn test_miri() {
136
142
0
137
143
} ,
138
144
teardown_x,
139
- ) ;
145
+ )
146
+ . unwrap ( ) ;
140
147
141
148
let _ = unsafe { TskBox :: new_borrowed ( & b) } ;
142
149
@@ -161,7 +168,8 @@ fn test_into_raw_miri() {
161
168
0
162
169
} ,
163
170
teardown_x,
164
- ) ;
171
+ )
172
+ . unwrap ( ) ;
165
173
166
174
let p = unsafe { b. into_raw ( ) } ;
167
175
@@ -187,6 +195,7 @@ fn test_table_collection_tskbox_shared_ptr() {
187
195
super :: bindings:: tsk_table_collection_init ( t, flags)
188
196
} ,
189
197
super :: bindings:: tsk_table_collection_free,
190
- ) ;
198
+ )
199
+ . unwrap ( ) ;
191
200
let _ = unsafe { TskBox :: new_borrowed ( & tables) } ;
192
201
}
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ impl TableCollection {
80
80
expected : "sequence_length >= 0.0" . to_string ( ) ,
81
81
} ) ;
82
82
}
83
- let mut inner = LLTableCollection :: new ( sequence_length. into ( ) ) ;
83
+ let mut inner = LLTableCollection :: new ( sequence_length. into ( ) ) ? ;
84
84
let views = crate :: table_views:: TableViews :: new_from_ll_table_collection ( & mut inner) ?;
85
85
Ok ( Self {
86
86
inner,
@@ -101,7 +101,7 @@ impl TableCollection {
101
101
102
102
pub ( crate ) fn into_raw ( self ) -> Result < * mut ll_bindings:: tsk_table_collection_t , TskitError > {
103
103
let mut tables = self ;
104
- let mut temp = crate :: sys:: TableCollection :: new ( 1. ) ;
104
+ let mut temp = crate :: sys:: TableCollection :: new ( 1. ) ? ;
105
105
std:: mem:: swap ( & mut temp, & mut tables. inner ) ;
106
106
let ptr = temp. as_mut_ptr ( ) ;
107
107
std:: mem:: forget ( temp) ;
You can’t perform that action at this time.
0 commit comments