diff --git a/crates/vm/src/stdlib/_ctypes/base.rs b/crates/vm/src/stdlib/_ctypes/base.rs index 7d611c27b0..afc03213b2 100644 --- a/crates/vm/src/stdlib/_ctypes/base.rs +++ b/crates/vm/src/stdlib/_ctypes/base.rs @@ -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::() { let wc = if mem::size_of::() == 2 { diff --git a/crates/vm/src/stdlib/_ctypes/simple.rs b/crates/vm/src/stdlib/_ctypes/simple.rs index 1dd2001335..f5e07ebc2e 100644 --- a/crates/vm/src/stdlib/_ctypes/simple.rs +++ b/crates/vm/src/stdlib/_ctypes/simple.rs @@ -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)?;