Rollup merge of #67666 - lzutao:ptr-null-cmp, r=dtolnay
make use of pointer::is_null r? @Mark-Simulacrum
This commit is contained in:
commit
76edc5c4eb
8 changed files with 26 additions and 21 deletions
|
|
@ -63,7 +63,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
|
|||
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
|
||||
let sz = mem::size_of_val(&data);
|
||||
let exception = __cxa_allocate_exception(sz);
|
||||
if exception == ptr::null_mut() {
|
||||
if exception.is_null() {
|
||||
return uw::_URC_FATAL_PHASE1_ERROR as u32;
|
||||
}
|
||||
ptr::write(exception as *mut _, data);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use crate::io;
|
|||
use crate::marker::PhantomData;
|
||||
use crate::memchr;
|
||||
use crate::path::{self, PathBuf};
|
||||
use crate::ptr;
|
||||
use crate::str;
|
||||
use crate::sync::Mutex;
|
||||
use crate::sys::hermit::abi;
|
||||
|
|
@ -77,13 +76,17 @@ pub fn init_environment(env: *const *const i8) {
|
|||
unsafe {
|
||||
ENV = Some(Mutex::new(HashMap::new()));
|
||||
|
||||
if env.is_null() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut guard = ENV.as_ref().unwrap().lock().unwrap();
|
||||
let mut environ = env;
|
||||
while environ != ptr::null() && *environ != ptr::null() {
|
||||
while !(*environ).is_null() {
|
||||
if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) {
|
||||
guard.insert(key, value);
|
||||
}
|
||||
environ = environ.offset(1);
|
||||
environ = environ.add(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@ static KEYS_LOCK: Mutex = Mutex::new();
|
|||
static mut LOCALS: *mut BTreeMap<Key, *mut u8> = ptr::null_mut();
|
||||
|
||||
unsafe fn keys() -> &'static mut BTreeMap<Key, Option<Dtor>> {
|
||||
if KEYS == ptr::null_mut() {
|
||||
if KEYS.is_null() {
|
||||
KEYS = Box::into_raw(Box::new(BTreeMap::new()));
|
||||
}
|
||||
&mut *KEYS
|
||||
}
|
||||
|
||||
unsafe fn locals() -> &'static mut BTreeMap<Key, *mut u8> {
|
||||
if LOCALS == ptr::null_mut() {
|
||||
if LOCALS.is_null() {
|
||||
LOCALS = Box::into_raw(Box::new(BTreeMap::new()));
|
||||
}
|
||||
&mut *LOCALS
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ impl<'a> Drop for ActiveTls<'a> {
|
|||
any_non_null_dtor = false;
|
||||
for (value, dtor) in TLS_KEY_IN_USE.iter().filter_map(&value_with_destructor) {
|
||||
let value = value.replace(ptr::null_mut());
|
||||
if value != ptr::null_mut() {
|
||||
if !value.is_null() {
|
||||
any_non_null_dtor = true;
|
||||
unsafe { dtor(value) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -480,11 +480,13 @@ pub fn env() -> Env {
|
|||
let _guard = env_lock();
|
||||
let mut environ = *environ();
|
||||
let mut result = Vec::new();
|
||||
while environ != ptr::null() && *environ != ptr::null() {
|
||||
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
|
||||
result.push(key_value);
|
||||
if !environ.is_null() {
|
||||
while !(*environ).is_null() {
|
||||
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
|
||||
result.push(key_value);
|
||||
}
|
||||
environ = environ.add(1);
|
||||
}
|
||||
environ = environ.offset(1);
|
||||
}
|
||||
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use crate::marker::PhantomData;
|
|||
use crate::mem;
|
||||
use crate::memchr;
|
||||
use crate::path::{self, Path, PathBuf};
|
||||
use crate::ptr;
|
||||
use crate::slice;
|
||||
use crate::str;
|
||||
use crate::sys::cvt;
|
||||
|
|
@ -226,15 +225,15 @@ pub fn env() -> Env {
|
|||
unsafe {
|
||||
let _guard = env_lock();
|
||||
let mut environ = *environ();
|
||||
if environ == ptr::null() {
|
||||
if environ.is_null() {
|
||||
panic!("os::env() failure getting env string from OS: {}", io::Error::last_os_error());
|
||||
}
|
||||
let mut result = Vec::new();
|
||||
while *environ != ptr::null() {
|
||||
while !(*environ).is_null() {
|
||||
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
|
||||
result.push(key_value);
|
||||
}
|
||||
environ = environ.offset(1);
|
||||
environ = environ.add(1);
|
||||
}
|
||||
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use crate::io;
|
|||
use crate::marker::PhantomData;
|
||||
use crate::os::wasi::prelude::*;
|
||||
use crate::path::{self, PathBuf};
|
||||
use crate::ptr;
|
||||
use crate::str;
|
||||
use crate::sys::memchr;
|
||||
use crate::sys::{unsupported, Void};
|
||||
|
|
@ -107,11 +106,13 @@ pub fn env() -> Env {
|
|||
let _guard = env_lock();
|
||||
let mut environ = libc::environ;
|
||||
let mut result = Vec::new();
|
||||
while environ != ptr::null_mut() && *environ != ptr::null_mut() {
|
||||
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
|
||||
result.push(key_value);
|
||||
if !environ.is_null() {
|
||||
while !(*environ).is_null() {
|
||||
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
|
||||
result.push(key_value);
|
||||
}
|
||||
environ = environ.add(1);
|
||||
}
|
||||
environ = environ.offset(1);
|
||||
}
|
||||
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ pub fn error_string(mut errnum: i32) -> String {
|
|||
];
|
||||
module = c::GetModuleHandleW(NTDLL_DLL.as_ptr());
|
||||
|
||||
if module != ptr::null_mut() {
|
||||
if !module.is_null() {
|
||||
errnum ^= c::FACILITY_NT_BIT as i32;
|
||||
flags = c::FORMAT_MESSAGE_FROM_HMODULE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue