File tree 8 files changed +26
-21
lines changed
8 files changed +26
-21
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
63
63
pub unsafe fn panic ( data : Box < dyn Any + Send > ) -> u32 {
64
64
let sz = mem:: size_of_val ( & data) ;
65
65
let exception = __cxa_allocate_exception ( sz) ;
66
- if exception == ptr :: null_mut ( ) {
66
+ if exception. is_null ( ) {
67
67
return uw:: _URC_FATAL_PHASE1_ERROR as u32 ;
68
68
}
69
69
ptr:: write ( exception as * mut _ , data) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ use crate::io;
6
6
use crate :: marker:: PhantomData ;
7
7
use crate :: memchr;
8
8
use crate :: path:: { self , PathBuf } ;
9
- use crate :: ptr;
10
9
use crate :: str;
11
10
use crate :: sync:: Mutex ;
12
11
use crate :: sys:: hermit:: abi;
@@ -77,13 +76,17 @@ pub fn init_environment(env: *const *const i8) {
77
76
unsafe {
78
77
ENV = Some ( Mutex :: new ( HashMap :: new ( ) ) ) ;
79
78
79
+ if env. is_null ( ) {
80
+ return ;
81
+ }
82
+
80
83
let mut guard = ENV . as_ref ( ) . unwrap ( ) . lock ( ) . unwrap ( ) ;
81
84
let mut environ = env;
82
- while environ != ptr :: null ( ) && * environ != ptr :: null ( ) {
85
+ while ! ( * environ) . is_null ( ) {
83
86
if let Some ( ( key, value) ) = parse ( CStr :: from_ptr ( * environ) . to_bytes ( ) ) {
84
87
guard. insert ( key, value) ;
85
88
}
86
- environ = environ. offset ( 1 ) ;
89
+ environ = environ. add ( 1 ) ;
87
90
}
88
91
}
89
92
Original file line number Diff line number Diff line change @@ -18,14 +18,14 @@ static KEYS_LOCK: Mutex = Mutex::new();
18
18
static mut LOCALS : * mut BTreeMap < Key , * mut u8 > = ptr:: null_mut ( ) ;
19
19
20
20
unsafe fn keys ( ) -> & ' static mut BTreeMap < Key , Option < Dtor > > {
21
- if KEYS == ptr :: null_mut ( ) {
21
+ if KEYS . is_null ( ) {
22
22
KEYS = Box :: into_raw ( Box :: new ( BTreeMap :: new ( ) ) ) ;
23
23
}
24
24
& mut * KEYS
25
25
}
26
26
27
27
unsafe fn locals ( ) -> & ' static mut BTreeMap < Key , * mut u8 > {
28
- if LOCALS == ptr :: null_mut ( ) {
28
+ if LOCALS . is_null ( ) {
29
29
LOCALS = Box :: into_raw ( Box :: new ( BTreeMap :: new ( ) ) ) ;
30
30
}
31
31
& mut * LOCALS
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ impl<'a> Drop for ActiveTls<'a> {
70
70
any_non_null_dtor = false ;
71
71
for ( value, dtor) in TLS_KEY_IN_USE . iter ( ) . filter_map ( & value_with_destructor) {
72
72
let value = value. replace ( ptr:: null_mut ( ) ) ;
73
- if value != ptr :: null_mut ( ) {
73
+ if !value . is_null ( ) {
74
74
any_non_null_dtor = true ;
75
75
unsafe { dtor ( value) }
76
76
}
Original file line number Diff line number Diff line change @@ -480,11 +480,13 @@ pub fn env() -> Env {
480
480
let _guard = env_lock ( ) ;
481
481
let mut environ = * environ ( ) ;
482
482
let mut result = Vec :: new ( ) ;
483
- while environ != ptr:: null ( ) && * environ != ptr:: null ( ) {
484
- if let Some ( key_value) = parse ( CStr :: from_ptr ( * environ) . to_bytes ( ) ) {
485
- result. push ( key_value) ;
483
+ if !environ. is_null ( ) {
484
+ while !( * environ) . is_null ( ) {
485
+ if let Some ( key_value) = parse ( CStr :: from_ptr ( * environ) . to_bytes ( ) ) {
486
+ result. push ( key_value) ;
487
+ }
488
+ environ = environ. add ( 1 ) ;
486
489
}
487
- environ = environ. offset ( 1 ) ;
488
490
}
489
491
return Env { iter : result. into_iter ( ) , _dont_send_or_sync_me : PhantomData } ;
490
492
}
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ use crate::marker::PhantomData;
7
7
use crate :: mem;
8
8
use crate :: memchr;
9
9
use crate :: path:: { self , Path , PathBuf } ;
10
- use crate :: ptr;
11
10
use crate :: slice;
12
11
use crate :: str;
13
12
use crate :: sys:: cvt;
@@ -226,15 +225,15 @@ pub fn env() -> Env {
226
225
unsafe {
227
226
let _guard = env_lock ( ) ;
228
227
let mut environ = * environ ( ) ;
229
- if environ == ptr :: null ( ) {
228
+ if environ. is_null ( ) {
230
229
panic ! ( "os::env() failure getting env string from OS: {}" , io:: Error :: last_os_error( ) ) ;
231
230
}
232
231
let mut result = Vec :: new ( ) ;
233
- while * environ != ptr :: null ( ) {
232
+ while ! ( * environ) . is_null ( ) {
234
233
if let Some ( key_value) = parse ( CStr :: from_ptr ( * environ) . to_bytes ( ) ) {
235
234
result. push ( key_value) ;
236
235
}
237
- environ = environ. offset ( 1 ) ;
236
+ environ = environ. add ( 1 ) ;
238
237
}
239
238
return Env { iter : result. into_iter ( ) , _dont_send_or_sync_me : PhantomData } ;
240
239
}
Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ use crate::io;
6
6
use crate :: marker:: PhantomData ;
7
7
use crate :: os:: wasi:: prelude:: * ;
8
8
use crate :: path:: { self , PathBuf } ;
9
- use crate :: ptr;
10
9
use crate :: str;
11
10
use crate :: sys:: memchr;
12
11
use crate :: sys:: { unsupported, Void } ;
@@ -107,11 +106,13 @@ pub fn env() -> Env {
107
106
let _guard = env_lock ( ) ;
108
107
let mut environ = libc:: environ;
109
108
let mut result = Vec :: new ( ) ;
110
- while environ != ptr:: null_mut ( ) && * environ != ptr:: null_mut ( ) {
111
- if let Some ( key_value) = parse ( CStr :: from_ptr ( * environ) . to_bytes ( ) ) {
112
- result. push ( key_value) ;
109
+ if !environ. is_null ( ) {
110
+ while !( * environ) . is_null ( ) {
111
+ if let Some ( key_value) = parse ( CStr :: from_ptr ( * environ) . to_bytes ( ) ) {
112
+ result. push ( key_value) ;
113
+ }
114
+ environ = environ. add ( 1 ) ;
113
115
}
114
- environ = environ. offset ( 1 ) ;
115
116
}
116
117
return Env { iter : result. into_iter ( ) , _dont_send_or_sync_me : PhantomData } ;
117
118
}
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ pub fn error_string(mut errnum: i32) -> String {
43
43
] ;
44
44
module = c:: GetModuleHandleW ( NTDLL_DLL . as_ptr ( ) ) ;
45
45
46
- if module != ptr :: null_mut ( ) {
46
+ if !module . is_null ( ) {
47
47
errnum ^= c:: FACILITY_NT_BIT as i32 ;
48
48
flags = c:: FORMAT_MESSAGE_FROM_HMODULE ;
49
49
}
You can’t perform that action at this time.
0 commit comments