8000 Enable missing_unsafe_on_extern lint · RustPython/RustPython@0a8b040 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a8b040

Browse files
committed
Enable missing_unsafe_on_extern lint
1 parent 1c3b198 commit 0a8b040

File tree

14 files changed

+21
-19
lines changed

14 files changed

+21
-19
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ wasm-bindgen = "0.2.100"
190190
[workspace.lints.rust]
191191
unsafe_code = "allow"
192192
unsafe_op_in_unsafe_fn = "deny"
193+
missing_unsafe_on_extern = "deny"
194+
unsafe_attr_outside_unsafe = "deny"
193195

194196
[workspace.lints.clippy]
195197
perf = "warn"

common/src/crt_fd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{cmp, ffi, io};
66
#[cfg(windows)]
77
use libc::commit as fsync;
88
#[cfg(windows)]
9-
extern "C" {
9+
unsafe extern "C" {
1010
#[link_name = "_chsize_s"]
1111
fn ftruncate(fd: i32, len: i64) -> i32;
1212
}
@@ -74,7 +74,7 @@ impl Fd {
7474

7575
#[cfg(windows)]
7676
pub fn to_raw_handle(&self) -> io::Result<std::os::windows::io::RawHandle> {
77-
extern "C" {
77+
unsafe extern "C" {
7878
fn _get_osfhandle(fd: i32) -> libc::intptr_t;
7979
}
8080
let handle = unsafe { suppress_iph!(_get_osfhandle(self.0)) };

common/src/fileutils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub mod windows {
9494
}
9595
}
9696

97-
extern "C" {
97+
unsafe extern "C" {
9898
fn _get_osfhandle(fd: i32) -> libc::intptr_t;
9999
}
100100

common/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub mod __macro_private {
4141
libc::uintptr_t,
4242
);
4343
#[cfg(target_env = "msvc")]
44-
extern "C" {
44+
unsafe extern "C" {
4545
pub fn _set_thread_local_invalid_parameter_handler(
4646
pNew: InvalidParamHandler,
4747
) -> InvalidParamHandler;

common/src/os.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn last_os_error() -> io::Error {
2323
let err = io::Error::last_os_error();
2424
// FIXME: probably not ideal, we need a bigger dichotomy between GetLastError and errno
2525
if err.raw_os_error() == Some(0) {
26-
extern "C" {
26+
unsafe extern "C" {
2727
fn _get_errno(pValue: *mut i32) -> i32;
2828
}
2929
let mut errno = 0;
@@ -44,7 +44,7 @@ pub fn last_os_error() -> io::Error {
4444
pub fn last_posix_errno() -> i32 {
4545
let err = io::Error::last_os_error();
4646
if err.raw_os_error() == Some(0) {
47-
extern "C" {
47+
unsafe extern "C" {
4848
fn _get_errno(pValue: *mut i32) -> i32;
4949
}
5050
let mut errno = 0;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn run(init: impl FnOnce(&mut VirtualMachine) + 'static) -> ExitCode {
7878
// don't translate newlines (\r\n <=> \n)
7979
#[cfg(windows)]
8080
{
81-
extern "C" {
81+
unsafe extern "C" {
8282
fn _setmode(fd: i32, flags: i32) -> i32;
8383
}
8484
unsafe {

stdlib/src/locale.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct lconv {
3030
}
3131

3232
#[cfg(windows)]
33-
extern "C" {
33+
unsafe extern "C" {
3434
fn localeconv() -> *mut lconv;
3535
}
3636

stdlib/src/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ mod platform {
113113
set.__nfds = 0;
114114
}
115115

116-
extern "C" {
116+
unsafe extern "C" {
117117
pub fn select(
118118
nfds: libc::c_int,
119119
readfds: *mut fd_set,

vm/src/stdlib/msvcrt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod msvcrt {
2424
unsafe { suppress_iph!(_setmode(fd, libc::O_BINARY)) };
2525
}
2626

27-
extern "C" {
27+
unsafe extern "C" {
2828
fn _getch() -> i32;
2929
fn _getwch() -> u32;
3030
fn _getche() -> i32;
@@ -70,7 +70,7 @@ mod msvcrt {
7070
Ok(())
7171
}
7272

73-
extern "C" {
73+
unsafe extern "C" {
7474
fn _setmode(fd: i32, flags: i32) -> i32;
7575
}
7676

@@ -84,7 +84,7 @@ mod msvcrt {
8484
}
8585
}
8686

87-
extern "C" {
87+
unsafe extern "C" {
8888
fn _open_osfhandle(osfhandle: isize, flags: i32) -> i32;
8989
fn _get_osfhandle(fd: i32) -> libc::intptr_t;
9090
}

vm/src/stdlib/nt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub(crate) mod module {
116116

117117
// cwait is available on MSVC only (according to CPython)
118118
#[cfg(target_env = "msvc")]
119-
extern "C" {
119+
unsafe extern "C" {
120120
fn _cwait(termstat: *mut i32, procHandle: intptr_t, action: i32) -> intptr_t;
121121
}
122122

@@ -194,7 +194,7 @@ pub(crate) mod module {
194194
}
195195

196196
#[cfg(target_env = "msvc")]
197-
extern "C" {
197+
unsafe extern "C" {
198198
fn _wexecv(cmdname: *const u16, argv: *const *const u16) -> intptr_t;
199199
}
200200

vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ pub(super) mod _os {
966966

967967
#[pyfunction]
968968
fn abort() {
969-
extern "C" {
969+
unsafe extern "C" {
970970
fn abort();
971971
}
972972
unsafe { abort() }

vm/src/stdlib/posix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ pub mod module {
971971
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd",))]
972972
#[pyfunction]
973973
fn lchmod(path: OsPath, mode: u32, vm: &VirtualMachine) -> PyResult<()> {
974-
extern "C" {
974+
unsafe extern "C" {
975975
fn lchmod(path: *const libc::c_char, mode: libc::mode_t) -> libc::c_int;
976976
}
977977
let c_path = path.clone().into_cstring(vm)?;
@@ -1605,7 +1605,7 @@ pub mod module {
16051605
// from libstd:
16061606
// https://github.com/rust-lang/rust/blob/daecab3a784f28082df90cebb204998051f3557d/src/libstd/sys/unix/fs.rs#L1251
16071607
#[cfg(target_os = "macos")]
1608-
extern "C" {
1608+
unsafe extern "C" {
16091609
fn fcopyfile(
16101610
in_fd: libc::c_int,
16111611
out_fd: libc::c_int,

vm/src/stdlib/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(crate) mod _signal {
7878
pub const SIG_ERR: sighandler_t = -1 as _;
7979

8080
#[cfg(all(unix, not(target_os = "redox")))]
81-
extern "C" {
81+
unsafe extern "C" {
8282
fn siginterrupt(sig: i32, flag: i32) -> i32;
8383
}
8484

vm/src/stdlib/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
1717

1818
#[cfg(not(target_env = "msvc"))]
1919
#[cfg(not(target_arch = "wasm32"))]
20-
extern "C" {
20+
unsafe extern "C" {
2121
#[cfg(not(target_os = "freebsd"))]
2222
#[link_name = "daylight"]
2323
static c_daylight: std::ffi::c_int;

0 commit comments

Comments
 (0)
0