Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustpython-stdlib = {workspace = true, features = ["threading"] }
rustpython-pylib = { workspace = true }

[dev-dependencies]
static_assertions = { workspace = true }
pyo3 = { workspace = true, features = ["auto-initialize", "abi3t"] }

[lints]
Expand Down
1 change: 0 additions & 1 deletion crates/capi/src/pyerrors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use core::convert::Infallible;
use core::ffi::{c_char, c_int};
use core::slice;
use rustpython_vm::builtins::{PyBaseException, PyTraceback, PyTuple, PyType};
use rustpython_vm::convert::IntoObject;
use rustpython_vm::exceptions::ExceptionZoo;
use rustpython_vm::{AsObject, PyResult};

Expand Down
22 changes: 11 additions & 11 deletions crates/capi/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,12 @@ where

impl<T> FfiResult<*mut Py<T>> for PyRef<T>
where
Self: Into<PyObjectRef>,
T: rustpython_vm::object::PyRefTarget<Target = Py<T>>,
{
const ERR_VALUE: *mut Py<T> = core::ptr::null_mut();

fn into_output(self, _vm: &VirtualMachine) -> *mut Py<T> {
self.into().into_raw().as_ptr().cast()
}
}

impl FfiResult<*mut PyObject> for PyObjectRef {
const ERR_VALUE: *mut PyObject = core::ptr::null_mut();

fn into_output(self, _vm: &VirtualMachine) -> *mut PyObject {
self.into_raw().as_ptr()
PyObjectRef::from(self).into_raw().as_ptr().cast()
}
}

Expand Down Expand Up @@ -324,7 +316,7 @@ impl<T: PyPayload> FfiPtrExt for *mut Py<T> {
"Attempted to dereference NULL {}",
type_name::<Self>()
);
unsafe { PyRef::from_raw(self.cast_const()) }
unsafe { PyRef::<T>::from_raw(self.cast_const()) }
}

#[inline]
Expand Down Expand Up @@ -384,6 +376,14 @@ mod tests {
use core::ffi::{c_longlong, c_ulonglong};
use core::fmt::Debug;

#[test]
fn pyref_object_ffi_targets() {
use rustpython_vm::builtins::PyInt;
static_assertions::assert_impl_all!(PyObjectRef: FfiResult<*mut PyObject>);
static_assertions::assert_impl_all!(PyRef<PyInt>: FfiResult<*mut PyObject>, FfiResult<*mut Py<PyInt>>);
static_assertions::assert_not_impl_any!(PyObjectRef: FfiResult<*mut Py<PyObject>>);
}

#[test]
fn ffi_result_err_value() {
fn assert_error_value<T, Output>(value: Output)
Expand Down
1 change: 0 additions & 1 deletion crates/stdlib/src/_sqlite3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ mod _sqlite3 {
PyInt, PyIntRef, PyModule, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef, PyType,
PyTypeRef, PyUtf8Str, PyUtf8StrRef,
},
convert::IntoObject,
function::{
ArgCallable, ArgIterable, FsPath, FuncArgs, KwArgs, OptionalArg, PyComparisonValue,
PySetterValue, TimeoutSeconds,
Expand Down
6 changes: 0 additions & 6 deletions crates/vm/src/builtins/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,6 @@ impl MemberCell for core::sync::atomic::AtomicU32 {}
// One object pointer. Readonly members may be a plain pointer. Writable
// members are an atomic cell: `PyAtomicRef<PyObject>` when the pointer is
// never null, or `PyAtomicRef<Option<PyObject>>` when it may be.
impl MemberLayout for PyObjectRef {
const KIND: MemberKind = MemberKind::Object;
}
impl MemberLayout for Option<PyObjectRef> {
const KIND: MemberKind = MemberKind::Object;
}
impl MemberLayout for crate::object::PyObjectCell {
const KIND: MemberKind = MemberKind::Object;
const ATOMIC: bool = true;
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/src/builtins/frame_locals_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ impl FrameLocalsProxy {
return Ok(vm.ctx.not_implemented());
}
let result = self.snapshot(vm)?;
if other.downcast_ref::<PyDict>().is_some() {
if let Some(dict) = other.downcast_ref::<PyDict>() {
// PyDict_Update reads a dict subclass's stored entries directly;
// it does not dispatch to overridden mapping methods.
result.merge_dict(&other.downcast().unwrap(), true, vm)?;
result.merge_dict(dict, true, vm)?;
} else {
result.merge_object(other, vm)?;
}
Expand Down
Loading
Loading