Skip to content

Commit d691ac6

Browse files
authored
Allow reentrant ctypes OUT construction (#9620)
Retain the pointed-to type and release the pointer metadata lock before invoking its Python constructor, which may re-enter pointer setup. Assisted-by: OpenAI Codex:model version not exposed
1 parent 1db3c47 commit d691ac6

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎crates/vm/src/stdlib/_ctypes/function.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,11 +1312,12 @@ fn get_buffer_addr(obj: &PyObject) -> Option<usize> {
13121312
/// Create OUT buffer for a parameter type
13131313
fn create_out_buffer(arg_type: &Py<PyType>, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
13141314
// For POINTER(T) types, create T instance (the pointed-to type)
1315-
if arg_type.fast_issubclass(PyCPointer::static_type())
1316-
&& let Some(stg_info) = arg_type.stg_info_opt()
1317-
&& let Some(ref proto) = stg_info.proto
1318-
{
1319-
return proto.as_object().call((), vm);
1315+
if arg_type.fast_issubclass(PyCPointer::static_type()) {
1316+
// Constructing the pointed-to type can re-enter pointer type setup.
1317+
let proto = arg_type.stg_info_opt().and_then(|info| info.proto.clone());
1318+
if let Some(proto) = proto {
1319+
return proto.as_object().call((), vm);
1320+
}
13201321
}
13211322
// Not a pointer type or no proto, create instance directly
13221323
arg_type.as_object().call((), vm)

0 commit comments

Comments
 (0)