Skip to content
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
Fix PyCSimple
  • Loading branch information
youknowone committed Nov 28, 2025
commit 14cf4e32d04b234549fae3ae0dddb0b34a09f76a
5 changes: 3 additions & 2 deletions crates/vm/src/stdlib/ctypes/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,12 @@ impl Constructor for PyCSimple {
_ => vm.ctx.none(), // "z" | "Z" | "P"
}
};
Ok(PyCSimple {
PyCSimple {
_type_,
value: AtomicCell::new(value),
}
.to_pyobject(vm))
.into_ref_with_type(vm, cls)
.map(Into::into)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/stdlib/ctypes/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct PyCField {
impl Representable for PyCField {
fn repr_str(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String> {
let tp_name = zelf.proto.name().to_string();
if zelf.bitfield_size != false {
if zelf.bitfield_size {
Ok(format!(
"<{} type={}, ofs={byte_offset}, bit_size={bitfield_size}, bit_offset={bit_offset}",
zelf.name,
Expand Down
16 changes: 8 additions & 8 deletions crates/vm/src/stdlib/ctypes/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use libffi::middle::{Arg, Cif, CodePtr, Type};
use libloading::Symbol;
use num_traits::ToPrimitive;
use rustpython_common::lock::PyRwLock;
use std::ffi::{self, CString, c_void};
use std::ffi::{self, c_void};
use std::fmt::Debug;

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

pub trait ReturnType {
fn to_ffi_type(&self) -> Option<Type>;
#[allow(clippy::wrong_self_convention)]
fn from_ffi_type(
&self,
value: *mut ffi::c_void,
Expand Down Expand Up @@ -197,9 +198,8 @@ impl Callable for PyCFuncPtr {
let return_type = zelf.res_type.read();
let ffi_return_type = return_type
.as_ref()
.map(|t| ReturnType::to_ffi_type(&t.clone().downcast::<PyType>().unwrap()))
.flatten()
.unwrap_or_else(|| Type::i32());
.and_then(|t| ReturnType::to_ffi_type(&t.clone().downcast::<PyType>().unwrap()))
.unwrap_or_else(Type::i32);
let cif = Cif::new(ffi_arg_types, ffi_return_type);

// Call the function
Expand Down Expand Up @@ -243,12 +243,12 @@ impl Representable for PyCFuncPtr {
let index = zelf.ptr.read();
let index = index.map(|ptr| ptr.0 as usize).unwrap_or(0);
let type_name = zelf.class().name();
#[cfg(windows)]
{
if cfg!(windows) {
let index = index - 0x1000;
return Ok(format!("<COM method offset {index:#x} {type_name}>"));
Ok(format!("<COM method offset {index:#x} {type_name}>"))
} else {
Ok(format!("<{type_name} object at {index:#x}>"))
}
Ok(format!("<{type_name} object at {index:#x}>"))
}
}

Expand Down