Skip to content

Commit b608df8

Browse files
committed
revert changes that cast functions to raw pointers, portability hazard
1 parent 09395f6 commit b608df8

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

library/core/src/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ impl<'a> ArgumentV1<'a> {
355355
// We are type punning a bit here: USIZE_MARKER only takes an &usize but
356356
// formatter takes an &Opaque. Rust understandably doesn't think we should compare
357357
// the function pointers if they don't have the same signature, so we cast to
358-
// pointers to convince it that we know what we're doing.
359-
if self.formatter as *mut u8 == USIZE_MARKER as *mut u8 {
358+
// usizes to tell it that we just want to compare addresses.
359+
if self.formatter as usize == USIZE_MARKER as usize {
360360
// SAFETY: The `formatter` field is only set to USIZE_MARKER if
361361
// the value is a usize, so this is safe
362362
Some(unsafe { *(self.value as *const _ as *const usize) })

library/std/src/backtrace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl Backtrace {
293293
if !Backtrace::enabled() {
294294
return Backtrace { inner: Inner::Disabled };
295295
}
296-
Backtrace::create((Backtrace::capture as *mut ()).addr())
296+
Backtrace::create(Backtrace::capture as usize)
297297
}
298298

299299
/// Forcibly captures a full backtrace, regardless of environment variable
@@ -308,7 +308,7 @@ impl Backtrace {
308308
/// parts of code.
309309
#[inline(never)] // want to make sure there's a frame here to remove
310310
pub fn force_capture() -> Backtrace {
311-
Backtrace::create((Backtrace::force_capture as *mut ()).addr())
311+
Backtrace::create(Backtrace::force_capture as usize)
312312
}
313313

314314
/// Forcibly captures a disabled backtrace, regardless of environment

library/std/src/sys/unix/weak.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
// that, we'll just allow that some unix targets don't use this module at all.
2323
#![allow(dead_code, unused_macros)]
2424

25-
use crate::ffi::{c_void, CStr};
25+
use crate::ffi::CStr;
2626
use crate::marker::PhantomData;
2727
use crate::mem;
28-
use crate::ptr;
2928
use crate::sync::atomic::{self, AtomicUsize, Ordering};
3029

3130
// We can use true weak linkage on ELF targets.
@@ -130,25 +129,25 @@ impl<F> DlsymWeak<F> {
130129
// Cold because it should only happen during first-time initialization.
131130
#[cold]
132131
unsafe fn initialize(&self) -> Option<F> {
133-
assert_eq!(mem::size_of::<F>(), mem::size_of::<*mut ()>());
132+
assert_eq!(mem::size_of::<F>(), mem::size_of::<usize>());
134133

135134
let val = fetch(self.name);
136135
// This synchronizes with the acquire fence in `get`.
137-
self.addr.store(val.addr(), Ordering::Release);
136+
self.addr.store(val, Ordering::Release);
138137

139-
match val.addr() {
138+
match val {
140139
0 => None,
141-
_ => Some(mem::transmute_copy::<*mut c_void, F>(&val)),
140+
addr => Some(mem::transmute_copy::<usize, F>(&addr)),
142141
}
143142
}
144143
}
145144

146-
unsafe fn fetch(name: &str) -> *mut c_void {
145+
unsafe fn fetch(name: &str) -> usize {
147146
let name = match CStr::from_bytes_with_nul(name.as_bytes()) {
148147
Ok(cstr) => cstr,
149-
Err(..) => return ptr::null_mut(),
148+
Err(..) => return 0,
150149
};
151-
libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr())
150+
libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize
152151
}
153152

154153
#[cfg(not(any(target_os = "linux", target_os = "android")))]

0 commit comments

Comments
 (0)