-
Notifications
You must be signed in to change notification settings - Fork 763
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
NonNull pointer for Py, PyObject #260
Conversation
} | ||
|
||
/// Creates a `PyObject` instance for the given FFI pointer. | ||
/// Panics if the pointer is `null`. | ||
/// Undefined behavior if the pointer is invalid. | ||
#[inline] | ||
pub unsafe fn from_owned_ptr_or_panic(py: Python, ptr: *mut ffi::PyObject) -> PyObject { | ||
pub unsafe fn from_owned_ptr_or_panic(_py: Python, ptr: *mut ffi::PyObject) -> PyObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the unused _py
arg leads to pyfunction
macro breaking in a way I'm not familiar enough to address now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because you need to have the GIL acquired or the python c api calls done by panic_after_error and the debug version of from_owned_ptr are undefined behavior.
src/instance.rs
Outdated
@@ -212,12 +213,14 @@ where | |||
|
|||
/// Specialization workaround | |||
trait AsPyRefDispatch<T: PyTypeInfo>: ToPyPointer { | |||
#[inline] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary?
Great, thanks! |
In general I like the idea of using Do have benchmarks for the inline annotations? I'm reluctant to sprinkling |
I've replaced the I've removed the inlines rather than worry about it, except on |
Thank you, look good now! |
This feels marginally safer and the combination of NonNull and inlines yield a small performance improvement in a library I have.