GeezerVison is showing github.com — Allow reentrant ctypes OUT construction (#9620) · RustPython/RustPython@d691ac6
File tree
Expand file treeCollapse file tree
Open diff view settings
crates/vm/src/stdlib/_ctypes
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/_ctypes/function.rs +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1312,11 +1312,12 @@ fn get_buffer_addr(obj: &PyObject) -> Option<usize> { |
1312 | 1312 | /// Create OUT buffer for a parameter type |
1313 | 1313 | fn create_out_buffer(arg_type: &Py<PyType>, vm: &VirtualMachine) -> PyResult<PyObjectRef> { |
1314 | 1314 | // 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 | + } |
1320 | 1321 | } |
1321 | 1322 | // Not a pointer type or no proto, create instance directly |
1322 | 1323 | arg_type.as_object().call((), vm) |
|