@@ -5,26 +5,19 @@ use libc::pthread_getattr_np as get_attr;
5
5
6
6
pub unsafe fn guess_os_stack_limit ( ) -> Option < usize > {
7
7
let mut attr = PthreadAttr :: new ( ) ?;
8
-
9
- handle_pthread_err ( get_attr ( libc:: pthread_self ( ) , attr. as_mut_ptr ( ) ) ) ?;
10
-
8
+ ( get_attr ( libc:: pthread_self ( ) , & mut attr. 0 ) == 0 ) . then_some ( ( ) ) ?;
11
9
let mut stackaddr = std:: ptr:: null_mut ( ) ;
12
10
let mut stacksize = 0 ;
13
- handle_pthread_err ( libc:: pthread_attr_getstack (
14
- attr. as_mut_ptr ( ) ,
15
- & mut stackaddr,
16
- & mut stacksize,
17
- ) ) ?;
18
-
11
+ ( libc:: pthread_attr_getstack ( & attr. 0 , & mut stackaddr, & mut stacksize) == 0 ) . then_some ( ( ) ) ?;
19
12
Some ( stackaddr as usize )
20
13
}
21
14
22
- struct PthreadAttr ( std :: mem :: MaybeUninit < libc:: pthread_attr_t > ) ;
15
+ struct PthreadAttr ( libc:: pthread_attr_t ) ;
23
16
24
17
impl Drop for PthreadAttr {
25
18
fn drop ( & mut self ) {
26
19
unsafe {
27
- let ret = libc:: pthread_attr_destroy ( self . 0 . as_mut_ptr ( ) ) ;
20
+ let ret = libc:: pthread_attr_destroy ( & mut self . 0 ) ;
28
21
if ret != 0 {
29
22
let err = std:: io:: Error :: last_os_error ( ) ;
30
23
panic ! (
@@ -36,23 +29,12 @@ impl Drop for PthreadAttr {
36
29
}
37
30
}
38
31
39
- fn handle_pthread_err ( ret : libc:: c_int ) -> Option < ( ) > {
40
- if ret != 0 {
41
- return None ;
42
- }
43
- Some ( ( ) )
44
- }
45
-
46
32
impl PthreadAttr {
47
33
unsafe fn new ( ) -> Option < Self > {
48
34
let mut attr = std:: mem:: MaybeUninit :: < libc:: pthread_attr_t > :: uninit ( ) ;
49
35
if libc:: pthread_attr_init ( attr. as_mut_ptr ( ) ) != 0 {
50
36
return None ;
51
37
}
52
- Some ( PthreadAttr ( attr) )
53
- }
54
-
55
- fn as_mut_ptr ( & mut self ) -> * mut libc:: pthread_attr_t {
56
- self . 0 . as_mut_ptr ( )
38
+ Some ( PthreadAttr ( attr. assume_init ( ) ) )
57
39
}
58
40
}
0 commit comments