Skip to content

Commit 9ab5e4a

Browse files
committed
Fix PyCSimple
1 parent ff68bd1 commit 9ab5e4a

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

crates/vm/src/stdlib/ctypes/base.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,12 @@ impl Constructor for PyCSimple {
218218
_ => vm.ctx.none(), // "z" | "Z" | "P"
219219
}
220220
};
221-
Ok(PyCSimple {
221+
PyCSimple {
222222
_type_,
223223
value: AtomicCell::new(value),
224224
}
225-
.to_pyobject(vm))
225+
.into_ref_with_type(vm, cls)
226+
.map(Into::into)
226227
}
227228
}
228229

crates/vm/src/stdlib/ctypes/field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct PyCField {
3636
impl Representable for PyCField {
3737
fn repr_str(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
3838
let tp_name = zelf.proto.name().to_string();
39-
if zelf.bitfield_size != false {
39+
if zelf.bitfield_size {
4040
Ok(format!(
4141
"<{} type={}, ofs={byte_offset}, bit_size={bitfield_size}, bit_offset={bit_offset}",
4242
zelf.name,

crates/vm/src/stdlib/ctypes/function.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use libffi::middle::{Arg, Cif, CodePtr, Type};
1313
use libloading::Symbol;
1414
use num_traits::ToPrimitive;
1515
use rustpython_common::lock::PyRwLock;
16-
use std::ffi::{self, CString, c_void};
16+
use std::ffi::{self, c_void};
1717
use std::fmt::Debug;
1818

1919
// See also: https://github.com/python/cpython/blob/4f8bb3947cfbc20f970ff9d9531e1132a9e95396/Modules/_ctypes/callproc.c#L15
@@ -61,6 +61,7 @@ impl ArgumentType for PyTypeRef {
6161

6262
pub trait ReturnType {
6363
fn to_ffi_type(&self) -> Option<Type>;
64+
#[allow(clippy::wrong_self_convention)]
6465
fn from_ffi_type(
6566
&self,
6667
value: *mut ffi::c_void,
@@ -197,9 +198,8 @@ impl Callable for PyCFuncPtr {
197198
let return_type = zelf.res_type.read();
198199
let ffi_return_type = return_type
199200
.as_ref()
200-
.map(|t| ReturnType::to_ffi_type(&t.clone().downcast::<PyType>().unwrap()))
201-
.flatten()
202-
.unwrap_or_else(|| Type::i32());
201+
.and_then(|t| ReturnType::to_ffi_type(&t.clone().downcast::<PyType>().unwrap()))
202+
.unwrap_or_else(Type::i32);
203203
let cif = Cif::new(ffi_arg_types, ffi_return_type);
204204

205205
// Call the function

0 commit comments

Comments
 (0)