@@ -5,26 +5,19 @@ use libc::pthread_getattr_np as get_attr;
55
66pub unsafe fn guess_os_stack_limit ( ) -> Option < usize > {
77 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 ( ( ) ) ?;
119 let mut stackaddr = std:: ptr:: null_mut ( ) ;
1210 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 ( ( ) ) ?;
1912 Some ( stackaddr as usize )
2013}
2114
22- struct PthreadAttr ( std :: mem :: MaybeUninit < libc:: pthread_attr_t > ) ;
15+ struct PthreadAttr ( libc:: pthread_attr_t ) ;
2316
2417impl Drop for PthreadAttr {
2518 fn drop ( & mut self ) {
2619 unsafe {
27- let ret = libc:: pthread_attr_destroy ( self . 0 . as_mut_ptr ( ) ) ;
20+ let ret = libc:: pthread_attr_destroy ( & mut self . 0 ) ;
2821 if ret != 0 {
2922 let err = std:: io:: Error :: last_os_error ( ) ;
3023 panic ! (
@@ -36,23 +29,12 @@ impl Drop for PthreadAttr {
3629 }
3730}
3831
39- fn handle_pthread_err ( ret : libc:: c_int ) -> Option < ( ) > {
40- if ret != 0 {
41- return None ;
42- }
43- Some ( ( ) )
44- }
45-
4632impl PthreadAttr {
4733 unsafe fn new ( ) -> Option < Self > {
4834 let mut attr = std:: mem:: MaybeUninit :: < libc:: pthread_attr_t > :: uninit ( ) ;
4935 if libc:: pthread_attr_init ( attr. as_mut_ptr ( ) ) != 0 {
5036 return None ;
5137 }
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 ( ) ) )
5739 }
5840}
0 commit comments