mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Updates for Rust 1.82
This commit is contained in:
@@ -105,7 +105,7 @@ members = [
|
||||
version = "0.4.0"
|
||||
authors = ["RustPython Team"]
|
||||
edition = "2021"
|
||||
rust-version = "1.80.0"
|
||||
rust-version = "1.82.0"
|
||||
repository = "https://github.com/RustPython/RustPython"
|
||||
license = "MIT"
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! An unresizable vector backed by a `Box<[T]>`
|
||||
|
||||
use std::{
|
||||
alloc,
|
||||
borrow::{Borrow, BorrowMut},
|
||||
cmp, fmt,
|
||||
mem::{self, MaybeUninit},
|
||||
@@ -35,29 +34,11 @@ macro_rules! panic_oob {
|
||||
};
|
||||
}
|
||||
|
||||
fn capacity_overflow() -> ! {
|
||||
panic!("capacity overflow")
|
||||
}
|
||||
|
||||
impl<T> BoxVec<T> {
|
||||
pub fn new(n: usize) -> BoxVec<T> {
|
||||
unsafe {
|
||||
let layout = match alloc::Layout::array::<T>(n) {
|
||||
Ok(l) => l,
|
||||
Err(_) => capacity_overflow(),
|
||||
};
|
||||
let ptr = if mem::size_of::<T>() == 0 {
|
||||
ptr::NonNull::<MaybeUninit<T>>::dangling().as_ptr()
|
||||
} else {
|
||||
let ptr = alloc::alloc(layout);
|
||||
if ptr.is_null() {
|
||||
alloc::handle_alloc_error(layout)
|
||||
}
|
||||
ptr as *mut MaybeUninit<T>
|
||||
};
|
||||
let ptr = ptr::slice_from_raw_parts_mut(ptr, n);
|
||||
let xs = Box::from_raw(ptr);
|
||||
BoxVec { xs, len: 0 }
|
||||
BoxVec {
|
||||
xs: Box::new_uninit_slice(n),
|
||||
len: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use lock_api::{
|
||||
GetThreadId, RawMutex, RawRwLock, RawRwLockDowngrade, RawRwLockRecursive, RawRwLockUpgrade,
|
||||
RawRwLockUpgradeDowngrade,
|
||||
};
|
||||
use std::{cell::Cell, num::NonZeroUsize};
|
||||
use std::{cell::Cell, num::NonZero};
|
||||
|
||||
pub struct RawCellMutex {
|
||||
locked: Cell<bool>,
|
||||
@@ -203,7 +203,7 @@ fn deadlock(lock_kind: &str, ty: &str) -> ! {
|
||||
pub struct SingleThreadId(());
|
||||
unsafe impl GetThreadId for SingleThreadId {
|
||||
const INIT: Self = SingleThreadId(());
|
||||
fn nonzero_thread_id(&self) -> NonZeroUsize {
|
||||
NonZeroUsize::new(1).unwrap()
|
||||
fn nonzero_thread_id(&self) -> NonZero<usize> {
|
||||
NonZero::new(1).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ mod grp {
|
||||
#[pyfunction]
|
||||
fn getgrall(vm: &VirtualMachine) -> PyResult<Vec<PyObjectRef>> {
|
||||
// setgrent, getgrent, etc are not thread safe. Could use fgetgrent_r, but this is easier
|
||||
static GETGRALL: parking_lot::Mutex<()> = parking_lot::const_mutex(());
|
||||
static GETGRALL: parking_lot::Mutex<()> = parking_lot::Mutex::new(());
|
||||
let _guard = GETGRALL.lock();
|
||||
let mut list = Vec::new();
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ mod platform {
|
||||
// based off winsock2.h: https://gist.github.com/piscisaureus/906386#file-winsock2-h-L128-L141
|
||||
|
||||
pub unsafe fn FD_SET(fd: RawFd, set: *mut fd_set) {
|
||||
let mut slot = std::ptr::addr_of_mut!((*set).fd_array).cast::<RawFd>();
|
||||
let mut slot = (&raw mut (*set).fd_array).cast::<RawFd>();
|
||||
let fd_count = (*set).fd_count;
|
||||
for _ in 0..fd_count {
|
||||
if *slot == fd {
|
||||
|
||||
@@ -2217,7 +2217,7 @@ mod _socket {
|
||||
fn as_slice(&self) -> &[netioapi::MIB_IF_ROW2] {
|
||||
unsafe {
|
||||
let p = self.ptr.as_ptr();
|
||||
let ptr = ptr::addr_of!((*p).Table) as *const netioapi::MIB_IF_ROW2;
|
||||
let ptr = &raw const (*p).Table as *const netioapi::MIB_IF_ROW2;
|
||||
std::slice::from_raw_parts(ptr, (*p).NumEntries as usize)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ mod _sqlite {
|
||||
ffi::{c_int, c_longlong, c_uint, c_void, CStr},
|
||||
fmt::Debug,
|
||||
ops::Deref,
|
||||
ptr::{addr_of_mut, null, null_mut},
|
||||
ptr::{null, null_mut},
|
||||
thread::ThreadId,
|
||||
};
|
||||
|
||||
@@ -1178,14 +1178,10 @@ mod _sqlite {
|
||||
)
|
||||
};
|
||||
|
||||
// TODO: replace with Result.inspect_err when stable
|
||||
if let Err(exc) = db.check(ret, vm) {
|
||||
db.check(ret, vm).inspect_err(|_| {
|
||||
// create_collation do not call destructor if error occur
|
||||
let _ = unsafe { Box::from_raw(data) };
|
||||
Err(exc)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -2396,7 +2392,7 @@ mod _sqlite {
|
||||
let ret = unsafe {
|
||||
sqlite3_open_v2(
|
||||
path,
|
||||
addr_of_mut!(db),
|
||||
&raw mut db,
|
||||
SQLITE_OPEN_READWRITE
|
||||
| SQLITE_OPEN_CREATE
|
||||
| if uri { SQLITE_OPEN_URI } else { 0 },
|
||||
|
||||
@@ -322,7 +322,7 @@ unsafe impl Link for WeakLink {
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn pointers(target: NonNull<Self::Target>) -> NonNull<Pointers<Self::Target>> {
|
||||
NonNull::new_unchecked(ptr::addr_of_mut!((*target.as_ptr()).0.payload.pointers))
|
||||
NonNull::new_unchecked(&raw mut (*target.as_ptr()).0.payload.pointers)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1047,7 +1047,7 @@ impl<T: PyObjectPayload> PyRef<T> {
|
||||
pub fn leak(pyref: Self) -> &'static Py<T> {
|
||||
let ptr = pyref.ptr;
|
||||
std::mem::forget(pyref);
|
||||
unsafe { &*ptr.as_ptr() }
|
||||
unsafe { ptr.as_ref() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ mod pwd {
|
||||
#[pyfunction]
|
||||
fn getpwall(vm: &VirtualMachine) -> PyResult<Vec<PyObjectRef>> {
|
||||
// setpwent, getpwent, etc are not thread safe. Could use fgetpwent_r, but this is easier
|
||||
static GETPWALL: parking_lot::Mutex<()> = parking_lot::const_mutex(());
|
||||
static GETPWALL: parking_lot::Mutex<()> = parking_lot::Mutex::new(());
|
||||
let _guard = GETPWALL.lock();
|
||||
let mut list = Vec::new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user