-
Notifications
You must be signed in to change notification settings - Fork 760
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
Protocols: implement __getattribute__ #2187
Conversation
src/impl_/pyclass.rs
Outdated
attr: *mut ffi::PyObject, | ||
) -> PyResult<*mut ffi::PyObject> { | ||
let res = ffi::PyObject_GenericGetAttr(slf, attr); | ||
if res.is_null() { Err(PyErr::fetch(py)) } |
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.
I'm not sure about this implementation, does it look correct?
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.
Looks good to me!
src/impl_/pyclass.rs
Outdated
_slf: *mut ffi::PyObject, | ||
attr: *mut ffi::PyObject, | ||
) -> PyResult<*mut ffi::PyObject> { | ||
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),))) |
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.
Same here
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.
I think this pointer is not owned by the function call, so need to use from_borrowed:
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),))) | |
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_borrowed_ptr(py, attr),))) |
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.
Awesome, nice one! Just a couple tidy ups needed I think...
src/impl_/pyclass.rs
Outdated
_slf: *mut ffi::PyObject, | ||
attr: *mut ffi::PyObject, | ||
) -> PyResult<*mut ffi::PyObject> { | ||
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),))) |
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.
I think this pointer is not owned by the function call, so need to use from_borrowed:
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),))) | |
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_borrowed_ptr(py, attr),))) |
src/impl_/pyclass.rs
Outdated
attr: *mut ffi::PyObject, | ||
) -> PyResult<*mut ffi::PyObject> { | ||
let res = ffi::PyObject_GenericGetAttr(slf, attr); | ||
if res.is_null() { Err(PyErr::fetch(py)) } |
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.
Looks good to me!
converting tp_getattro to a shared slot Fixes #2186
d8153cf
to
dc4f114
Compare
Thanks for the review, should be good 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.
LGTM! Thanks, will include it in the release I guess :)
converting tp_getattro to a shared slot
Fixes #2186