Skip to content

Commit 3a46cca

Browse files
Revert "#![deny(unsafe_op_in_unsafe_fn)] in sys/hermit"
This reverts commit 7cae9e8.
1 parent 7cae9e8 commit 3a46cca

File tree

10 files changed

+75
-147
lines changed

10 files changed

+75
-147
lines changed

library/std/src/sys/hermit/alloc.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
2-
31
use crate::alloc::{GlobalAlloc, Layout, System};
42
use crate::ptr;
53
use crate::sys::hermit::abi;
@@ -8,33 +6,26 @@ use crate::sys::hermit::abi;
86
unsafe impl GlobalAlloc for System {
97
#[inline]
108
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
11-
// SAFETY: The safety contract for `malloc` must be upheld by the caller.
12-
unsafe { abi::malloc(layout.size(), layout.align()) }
9+
abi::malloc(layout.size(), layout.align())
1310
}
1411

1512
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
16-
// SAFETY: The safety contract for `malloc` must be upheld by the caller.
17-
// Also, `addr` must be valid for writes of `layout.size() * size_of::<u8>()` bytes.
18-
unsafe {
19-
let addr = abi::malloc(layout.size(), layout.align());
20-
21-
if !addr.is_null() {
22-
ptr::write_bytes(addr, 0x00, layout.size());
23-
}
13+
let addr = abi::malloc(layout.size(), layout.align());
2414

25-
addr
15+
if !addr.is_null() {
16+
ptr::write_bytes(addr, 0x00, layout.size());
2617
}
18+
19+
addr
2720
}
2821

2922
#[inline]
3023
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
31-
// SAFETY: The safety contract for `free` must be upheld by the caller.
32-
unsafe { abi::free(ptr, layout.size(), layout.align()) }
24+
abi::free(ptr, layout.size(), layout.align())
3325
}
3426

3527
#[inline]
3628
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
37-
// SAFETY: The safety contract for `realloc` must be upheld by the caller.
38-
unsafe { abi::realloc(ptr, layout.size(), layout.align(), new_size) }
29+
abi::realloc(ptr, layout.size(), layout.align(), new_size)
3930
}
4031
}

library/std/src/sys/hermit/args.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
2-
31
use crate::ffi::OsString;
42
use crate::marker::PhantomData;
53
use crate::vec;
64

75
/// One-time global initialization.
86
pub unsafe fn init(argc: isize, argv: *const *const u8) {
9-
unsafe { imp::init(argc, argv) }
7+
imp::init(argc, argv)
108
}
119

1210
/// One-time global cleanup.
1311
pub unsafe fn cleanup() {
14-
unsafe { imp::cleanup() }
12+
imp::cleanup()
1513
}
1614

1715
/// Returns the command line arguments
@@ -67,18 +65,14 @@ mod imp {
6765

6866
pub unsafe fn init(argc: isize, argv: *const *const u8) {
6967
let _guard = LOCK.lock();
70-
unsafe {
71-
ARGC = argc;
72-
ARGV = argv;
73-
}
68+
ARGC = argc;
69+
ARGV = argv;
7470
}
7571

7672
pub unsafe fn cleanup() {
7773
let _guard = LOCK.lock();
7874
ARGC = 0;
79-
unsafe {
80-
ARGV = ptr::null();
81-
}
75+
ARGV = ptr::null();
8276
}
8377

8478
pub fn args() -> Args {

library/std/src/sys/hermit/condvar.rs

+10-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
2-
31
use crate::ffi::c_void;
42
use crate::ptr;
53
use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
@@ -25,43 +23,33 @@ impl Condvar {
2523
}
2624

2725
pub unsafe fn init(&mut self) {
28-
unsafe {
29-
let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0);
30-
let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0);
31-
}
26+
let _ = abi::sem_init(&mut self.sem1 as *mut *const c_void, 0);
27+
let _ = abi::sem_init(&mut self.sem2 as *mut *const c_void, 0);
3228
}
3329

3430
pub unsafe fn notify_one(&self) {
3531
if self.counter.load(SeqCst) > 0 {
3632
self.counter.fetch_sub(1, SeqCst);
37-
unsafe {
38-
abi::sem_post(self.sem1);
39-
abi::sem_timedwait(self.sem2, 0);
40-
}
33+
abi::sem_post(self.sem1);
34+
abi::sem_timedwait(self.sem2, 0);
4135
}
4236
}
4337

4438
pub unsafe fn notify_all(&self) {
4539
let counter = self.counter.swap(0, SeqCst);
4640
for _ in 0..counter {
47-
unsafe {
48-
abi::sem_post(self.sem1);
49-
}
41+
abi::sem_post(self.sem1);
5042
}
5143
for _ in 0..counter {
52-
unsafe {
53-
abi::sem_timedwait(self.sem2, 0);
54-
}
44+
abi::sem_timedwait(self.sem2, 0);
5545
}
5646
}
5747

5848
pub unsafe fn wait(&self, mutex: &Mutex) {
5949
self.counter.fetch_add(1, SeqCst);
6050
mutex.unlock();
61-
unsafe {
62-
abi::sem_timedwait(self.sem1, 0);
63-
abi::sem_post(self.sem2);
64-
}
51+
abi::sem_timedwait(self.sem1, 0);
52+
abi::sem_post(self.sem2);
6553
mutex.lock();
6654
}
6755

@@ -70,9 +58,7 @@ impl Condvar {
7058
}
7159

7260
pub unsafe fn destroy(&self) {
73-
unsafe {
74-
let _ = abi::sem_destroy(self.sem1);
75-
let _ = abi::sem_destroy(self.sem2);
76-
}
61+
let _ = abi::sem_destroy(self.sem1);
62+
let _ = abi::sem_destroy(self.sem2);
7763
}
7864
}

library/std/src/sys/hermit/fd.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
21
#![unstable(reason = "not public", issue = "none", feature = "fd")]
32

43
use crate::io::{self, ErrorKind, Read};

library/std/src/sys/hermit/mod.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
//! compiling for wasm. That way it's a compile time error for something that's
1414
//! guaranteed to be a runtime error!
1515
16-
#![deny(unsafe_op_in_unsafe_fn)]
17-
1816
use crate::intrinsics;
1917
use crate::os::raw::c_char;
2018

@@ -64,12 +62,8 @@ pub enum Void {}
6462
pub unsafe fn strlen(start: *const c_char) -> usize {
6563
let mut str = start;
6664

67-
// SAFETY: The safety contract for `*str != 0` must be upheld by the caller.
68-
// `start` must not be null.
69-
unsafe {
70-
while *str != 0 {
71-
str = str.offset(1);
72-
}
65+
while *str != 0 {
66+
str = str.offset(1);
7367
}
7468

7569
(str as usize) - (start as usize)
@@ -117,15 +111,13 @@ pub unsafe extern "C" fn runtime_entry(
117111
fn main(argc: isize, argv: *const *const c_char) -> i32;
118112
}
119113

120-
unsafe {
121-
// initialize environment
122-
os::init_environment(env as *const *const i8);
114+
// initialize environment
115+
os::init_environment(env as *const *const i8);
123116

124-
let result = main(argc as isize, argv);
117+
let result = main(argc as isize, argv);
125118

126-
run_dtors();
127-
abi::exit(result);
128-
}
119+
run_dtors();
120+
abi::exit(result);
129121
}
130122

131123
pub fn decode_error_kind(errno: i32) -> ErrorKind {

library/std/src/sys/hermit/mutex.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
2-
31
use crate::ffi::c_void;
42
use crate::ptr;
53
use crate::sys::hermit::abi;
@@ -18,34 +16,28 @@ impl Mutex {
1816

1917
#[inline]
2018
pub unsafe fn init(&mut self) {
21-
unsafe {
22-
let _ = abi::sem_init(&mut self.inner as *mut *const c_void, 1);
23-
}
19+
let _ = abi::sem_init(&mut self.inner as *mut *const c_void, 1);
2420
}
2521

2622
#[inline]
2723
pub unsafe fn lock(&self) {
28-
unsafe {
29-
let _ = abi::sem_timedwait(self.inner, 0);
30-
}
24+
let _ = abi::sem_timedwait(self.inner, 0);
3125
}
3226

3327
#[inline]
3428
pub unsafe fn unlock(&self) {
35-
unsafe {
36-
let _ = abi::sem_post(self.inner);
37-
}
29+
let _ = abi::sem_post(self.inner);
3830
}
3931

4032
#[inline]
4133
pub unsafe fn try_lock(&self) -> bool {
42-
let result = unsafe { abi::sem_trywait(self.inner) };
34+
let result = abi::sem_trywait(self.inner);
4335
result == 0
4436
}
4537

4638
#[inline]
4739
pub unsafe fn destroy(&self) {
48-
let _ = unsafe { abi::sem_destroy(self.inner) };
40+
let _ = abi::sem_destroy(self.inner);
4941
}
5042
}
5143

@@ -60,12 +52,12 @@ impl ReentrantMutex {
6052

6153
#[inline]
6254
pub unsafe fn init(&self) {
63-
let _ = unsafe { abi::recmutex_init(&self.inner as *const *const c_void as *mut _) };
55+
let _ = abi::recmutex_init(&self.inner as *const *const c_void as *mut _);
6456
}
6557

6658
#[inline]
6759
pub unsafe fn lock(&self) {
68-
let _ = unsafe { abi::recmutex_lock(self.inner) };
60+
let _ = abi::recmutex_lock(self.inner);
6961
}
7062

7163
#[inline]
@@ -75,11 +67,11 @@ impl ReentrantMutex {
7567

7668
#[inline]
7769
pub unsafe fn unlock(&self) {
78-
let _ = unsafe { abi::recmutex_unlock(self.inner) };
70+
let _ = abi::recmutex_unlock(self.inner);
7971
}
8072

8173
#[inline]
8274
pub unsafe fn destroy(&self) {
83-
let _ = unsafe { abi::recmutex_destroy(self.inner) };
75+
let _ = abi::recmutex_destroy(self.inner);
8476
}
8577
}

library/std/src/sys/hermit/os.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
2-
31
use crate::collections::HashMap;
42
use crate::error::Error as StdError;
53
use crate::ffi::{CStr, OsStr, OsString};

library/std/src/sys/hermit/rwlock.rs

+26-42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(unsafe_op_in_unsafe_fn)]
2-
31
use crate::cell::UnsafeCell;
42
use crate::sys::condvar::Condvar;
53
use crate::sys::mutex::Mutex;
@@ -34,76 +32,62 @@ impl RWLock {
3432

3533
#[inline]
3634
pub unsafe fn read(&self) {
37-
unsafe {
38-
self.lock.lock();
39-
while !(*self.state.get()).inc_readers() {
40-
self.cond.wait(&self.lock);
41-
}
42-
self.lock.unlock();
35+
self.lock.lock();
36+
while !(*self.state.get()).inc_readers() {
37+
self.cond.wait(&self.lock);
4338
}
39+
self.lock.unlock();
4440
}
4541

4642
#[inline]
4743
pub unsafe fn try_read(&self) -> bool {
48-
unsafe {
49-
self.lock.lock();
50-
let ok = (*self.state.get()).inc_readers();
51-
self.lock.unlock();
52-
}
44+
self.lock.lock();
45+
let ok = (*self.state.get()).inc_readers();
46+
self.lock.unlock();
5347
return ok;
5448
}
5549

5650
#[inline]
5751
pub unsafe fn write(&self) {
58-
unsafe {
59-
self.lock.lock();
60-
while !(*self.state.get()).inc_writers() {
61-
self.cond.wait(&self.lock);
62-
}
52+
self.lock.lock();
53+
while !(*self.state.get()).inc_writers() {
54+
self.cond.wait(&self.lock);
6355
}
6456
self.lock.unlock();
6557
}
6658

6759
#[inline]
6860
pub unsafe fn try_write(&self) -> bool {
69-
unsafe {
70-
self.lock.lock();
71-
let ok = (*self.state.get()).inc_writers();
72-
self.lock.unlock();
73-
}
61+
self.lock.lock();
62+
let ok = (*self.state.get()).inc_writers();
63+
self.lock.unlock();
7464
return ok;
7565
}
7666

7767
#[inline]
7868
pub unsafe fn read_unlock(&self) {
79-
unsafe {
80-
self.lock.lock();
81-
let notify = (*self.state.get()).dec_readers();
82-
self.lock.unlock();
83-
if notify {
84-
// FIXME: should only wake up one of these some of the time
85-
self.cond.notify_all();
86-
}
69+
self.lock.lock();
70+
let notify = (*self.state.get()).dec_readers();
71+
self.lock.unlock();
72+
if notify {
73+
// FIXME: should only wake up one of these some of the time
74+
self.cond.notify_all();
8775
}
8876
}
8977

9078
#[inline]
9179
pub unsafe fn write_unlock(&self) {
92-
unsafe {
93-
self.lock.lock();
94-
(*self.state.get()).dec_writers();
95-
self.lock.unlock();
96-
// FIXME: should only wake up one of these some of the time
97-
self.cond.notify_all();
98-
}
80+
self.lock.lock();
81+
(*self.state.get()).dec_writers();
82+
self.lock.unlock();
83+
// FIXME: should only wake up one of these some of the time
84+
self.cond.notify_all();
9985
}
10086

10187
#[inline]
10288
pub unsafe fn destroy(&self) {
103-
unsafe {
104-
self.lock.destroy();
105-
self.cond.destroy();
106-
}
89+
self.lock.destroy();
90+
self.cond.destroy();
10791
}
10892
}
10993

0 commit comments

Comments
 (0)