Skip to content
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

Merged
merged 2 commits into from Feb 26, 2022
Merged

Protocols: implement __getattribute__ #2187

merged 2 commits into from Feb 26, 2022

Conversation

birkenfeld
Copy link
Member

converting tp_getattro to a shared slot

Fixes #2186

attr: *mut ffi::PyObject,
) -> PyResult<*mut ffi::PyObject> {
let res = ffi::PyObject_GenericGetAttr(slf, attr);
if res.is_null() { Err(PyErr::fetch(py)) }
Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

_slf: *mut ffi::PyObject,
attr: *mut ffi::PyObject,
) -> PyResult<*mut ffi::PyObject> {
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Member

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:

Suggested change
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),)))
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_borrowed_ptr(py, attr),)))

Copy link
Member

@davidhewitt davidhewitt left a 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...

CHANGELOG.md Outdated Show resolved Hide resolved
_slf: *mut ffi::PyObject,
attr: *mut ffi::PyObject,
) -> PyResult<*mut ffi::PyObject> {
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),)))
Copy link
Member

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:

Suggested change
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_owned_ptr(py, attr),)))
Err(PyErr::new::<PyAttributeError, _>((Py::<PyAny>::from_borrowed_ptr(py, attr),)))

attr: *mut ffi::PyObject,
) -> PyResult<*mut ffi::PyObject> {
let res = ffi::PyObject_GenericGetAttr(slf, attr);
if res.is_null() { Err(PyErr::fetch(py)) }
Copy link
Member

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 Show resolved Hide resolved
@davidhewitt davidhewitt mentioned this pull request Feb 26, 2022
@birkenfeld
Copy link
Member Author

Thanks for the review, should be good now.

Copy link
Member

@davidhewitt davidhewitt left a 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 :)

@davidhewitt davidhewitt merged commit 1ed9a73 into main Feb 26, 2022
@davidhewitt davidhewitt deleted the getattribute branch February 26, 2022 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support __getattribute__ in #[pymethods]
2 participants