Repository navigation
Conversation
4efbaef to
7660b57
Compare
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks, I like the idea, some thoughts in comments.
| // SAFETY: we are holding a Python marker and caller guarantees that `ty` | ||
| // is valid | ||
| let is_heap_type = unsafe {ffi::PyType_HasFeature(ty, ffi::Py_TPFLAGS_HEAPTYPE)} == 0; | ||
| if !is_runtime_3_10(_py) && is_heap_type |
There was a problem hiding this comment.
I think we should probably change to a form of Python::version_info which doesn't have a receiver. We'll need to create it.
| let mut traverse: Option<ffi::traverseproc>; | ||
|
|
||
| // SAFETY: this `py` is only used to call `get_slot` which has no side effects | ||
| let py = unsafe { Python::assume_attached() }; |
There was a problem hiding this comment.
I would strongly prefer we avoided creating Python inside traverse as it's wildly unsafe. I think my other idea might give us a route to doing so...
| unsafe fn get_slot( | ||
| self, | ||
| _py: Python<'_>, | ||
| ty: *mut ffi::PyTypeObject, |
There was a problem hiding this comment.
If we made this &Py<PyType> we might be able to contain the unsafety to a much lower level.
There was a problem hiding this comment.
How should the callers convert *mut ffi::PyTypeObject to &Py<PyType>?
I think it's sounds to transmute &*mut ffi::PyTypeObject to Option<&Py<PyType>>, but I don't think it's a great idea to have transmutes all over the place. Should it be a method on Py<PyType>?
Part of #5487
Minor refactoring of
get_slot.rsto remove some safety requirements.get_slotfunction takes aPythonis_runtime_3_10is removed, the one place it was checked is replaced by a call to theis_runtime_3_10function