-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some safe functions are marked unsafe
?
#1389
Comments
I agree with
|
Oops, yes, of course.
I've briefly looked at all the |
Agreed that
If you're willing, that'd be very much appreciated! It'd technically be breaking so I probably wouldn't be able to merge the PR for a little bit until we're ready to merge all the breaking changes that will go into 0.14. |
Sorry to post on an old issue: I think clear_weakrefs is another of these actually safe functions. https://github.com/PyO3/pyo3/blob/master/src/pyclass_slots.rs#L69 PyObject_ClearWeakRefs clears the remaining weak references to the object. A weak reference (another PyObject)
I believe it's safe to clear weak references, as their being cleared "unexpectedly" is explicitly why weak references exist. If not, I suppose I'm about to learn what remark should be put into the "Safety" docstring... (#698) |
I don't think this can be safe as long as it takes a raw pointer, since there is no guarantee that it points to a valid PyObject. |
Ah, of course -- my bad |
When I was looking at the remaining unsafe functions without safety notes for #698, I noticed that a couple of functions didn't seem to be
unsafe
at all.This issue is about whether these functions should be safe to call (i.e. no need to be marked
unsafe
) because they wrap up the unsafety, or aren't actually unsafe.PyLayout::py_init
. This function takes ownership of avalue: T
, which could be leaked in the worst case, but leaking memory is considered safe Rust. For reference, both implementations don't use anyunsafe
code.pyo3/src/type_object.rs
Line 23 in b6f595b
PyClassDict::clear_dict
. In this case the implementation calls the FFI functionPyDict_Clear
, which seems to be safe as it operates solely on the refcounted contents of the class dict.pyo3/src/pyclass_slots.rs
Line 9 in 3de51d5
PyClassAlloc::new
. This feels like implementations should encapsulate any unsafety, but I'm not sure.pyo3/src/pyclass.rs
Line 75 in 3de51d5
Opening this issue as suggested in #1388 (comment), even if it's not obvious that we want to change the
unsafe
marking on any of the functions. I realise that most of these APIs are probably only used internally.The text was updated successfully, but these errors were encountered: