Fix ctypes.py_object handling (#7836)

* Fix `ctypes.py_object` handling

* Assume owned pointer
This commit is contained in:
Bas Schoenmaeckers authored and GitHub committed 2026-05-12 03:20:01 +09:00
1 parent 4290fd8966
commit 713c2646ca
2 files changed
+23

No files matched your search

+12
View File
@@ -2342,6 +2342,18 @@ pub(super) fn bytes_to_pyobject(
}
Ok(vm.ctx.new_int(val).into())
}
"O" => {
// py_object: return Python object from pointer
let ptr = read_ptr_from_buffer(bytes);
if ptr == 0 {
return Err(vm.new_value_error("PyObject is NULL"));
}
unsafe {
let obj =
PyObjectRef::from_raw(core::ptr::NonNull::new_unchecked(ptr as *mut _));
Ok(obj)
}
}
"u" => {
let val = if bytes.len() >= mem::size_of::<WideChar>() {
let wc = if mem::size_of::<WideChar>() == 2 {
+11
View File
@@ -466,6 +466,17 @@ impl PyCSimpleType {
}
}
}
// py_object: pass any Python object as PyObject*
Some("O") => {
return Ok(CArgObject {
tag: b'O',
value: FfiArgValue::Pointer(value.get_id()),
obj: value,
size: 0,
offset: 0,
}
.to_pyobject(vm));
}
// c_bool
Some("?") => {
let bool_val = value.is_true(vm)?;