8000 Enable `unsafe_op_in_unsafe_fn` and `missing_unsafe_on_extern` lints by coolreader18 · Pull Request #5557 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Enable unsafe_op_in_unsafe_fn and missing_unsafe_on_extern lints #5557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable missing_unsafe_on_extern lint
  • Loading branch information
coolreader18 committed Feb 25, 2025
commit 0a8b0406f57542e0afb31096ddb0301e8ac9131e
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ wasm-bindgen = "0.2.100"
[workspace.lints.rust]
unsafe_code = "allow"
unsafe_op_in_unsafe_fn = "deny"
missing_unsafe_on_extern = "deny"
unsafe_attr_outside_unsafe = "deny"

[workspace.lints.clippy]
perf = "warn"
Expand Down
4 changes: 2 additions & 2 deletions common/src/crt_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{cmp, ffi, io};
#[cfg(windows)]
use libc::commit as fsync;
#[cfg(windows)]
extern "C" {
unsafe extern "C" {
#[link_name = "_chsize_s"]
fn ftruncate(fd: i32, len: i64) -> i32;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Fd {

#[cfg(windows)]
pub fn to_raw_handle(&self) -> io::Result<std::os::windows::io::RawHandle> {
extern "C" {
unsafe extern "C" {
fn _get_osfhandle(fd: i32) -> libc::intptr_t;
}
let handle = unsafe { suppress_iph!(_get_osfhandle(self.0)) };
Expand Down
2 changes: 1 addition & 1 deletion common/src/fileutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub mod windows {
}
}

extern "C" {
unsafe extern "C" {
fn _get_osfhandle(fd: i32) -> libc::intptr_t;
}

Expand Down
2 changes: 1 addition & 1 deletion common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub mod __macro_private {
libc::uintptr_t,
);
#[cfg(target_env = "msvc")]
extern "C" {
unsafe extern "C" {
pub fn _set_thread_local_invalid_parameter_handler(
pNew: InvalidParamHandler,
) -> InvalidParamHandler;
Expand Down
4 changes: 2 additions & 2 deletions common/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn last_os_error() -> io::Error {
let err = io::Error::last_os_error();
// FIXME: probably not ideal, we need a bigger dichotomy between GetLastError and errno
if err.raw_os_error() == Some(0) {
extern "C" {
unsafe extern "C" {
fn _get_errno(pValue: *mut i32) -> i32;
}
let mut errno = 0;
Expand All @@ -44,7 +44,7 @@ pub fn last_os_error() -> io::Error {
pub fn last_posix_errno() -> i32 {
let err = io::Error::last_os_error();
if err.raw_os_error() == Some(0) {
extern "C" {
unsafe extern "C" {
fn _get_errno(pValue: *mut i32) -> i32;
}
let mut errno = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn run(init: impl FnOnce(&mut VirtualMachine) + 'static) -> ExitCode {
// don't translate newlines (\r\n <=> \n)
#[cfg(windows)]
{
extern "C" {
unsafe extern "C" {
fn _setmode(fd: i32, flags: i32) -> i32;
}
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct lconv {
}

#[cfg(windows)]
extern "C" {
unsafe extern "C" {
fn localeconv() -> *mut lconv;
}

Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod platform {
set.__nfds = 0;
}

extern "C" {
unsafe extern "C" {
pub fn select(
nfds: libc::c_int,
readfds: *mut fd_set,
Expand Down
6 changes: 3 additions & 3 deletions vm/src/stdlib/msvcrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod msvcrt {
unsafe { suppress_iph!(_setmode(fd, libc::O_BINARY)) };
}

extern "C" {
unsafe extern "C" {
fn _getch() -> i32;
fn _getwch() -> u32;
fn _getche() -> i32;
Expand Down Expand Up @@ -70,7 +70,7 @@ mod msvcrt {
Ok(())
}

extern "C" {
unsafe extern "C" {
fn _setmode(fd: i32, flags: i32) F438 -> i32;
}

Expand All @@ -84,7 +84,7 @@ mod msvcrt {
}
}

extern "C" {
unsafe extern "C" {
fn _open_osfhandle(osfhandle: isize, flags: i32) -> i32;
fn _get_osfhandle(fd: i32) -> libc::intptr_t;
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/nt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub(crate) mod module {

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

Expand Down Expand Up @@ -194,7 +194,7 @@ pub(crate) mod module {
}

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

Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ pub(super) mod _os {

#[pyfunction]
fn abort() {
extern "C" {
unsafe extern "C" {
fn abort();
}
unsafe { abort() }
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ pub mod module {
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd",))]
#[pyfunction]
fn lchmod(path: OsPath, mode: u32, vm: &VirtualMachine) -> PyResult<()> {
extern "C" {
unsafe extern "C" {
fn lchmod(path: *const libc::c_char, mode: libc::mode_t) -> libc::c_int;
}
let c_path = path.clone().into_cstring(vm)?;
Expand Down Expand Up @@ -1605,7 +1605,7 @@ pub mod module {
// from libstd:
// https://github.com/rust-lang/rust/blob/daecab3a784f28082df90cebb204998051f3557d/src/libstd/sys/unix/fs.rs#L1251
#[cfg(target_os = "macos")]
extern "C" {
unsafe extern "C" {
fn fcopyfile(
in_fd: libc::c_int,
out_fd: libc::c_int,
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub(crate) mod _signal {
pub const SIG_ERR: sighandler_t = -1 as _;

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

Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {

#[cfg(not(target_env = "msvc"))]
#[cfg(not(target_arch = "wasm32"))]
extern "C" {
unsafe extern "C" {
#[cfg(not(target_os = "freebsd"))]
#[link_name = "daylight"]
static c_daylight: std::ffi::c_int;
Expand Down
0