-
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
Allow non-mutable reference in PyIterProtocol::__iter__ #854
Comments
Completely agree with you. I think that I think at the moment it might be complicated to add this flexibility, and this code is due to be rewritten to remove specialization anyway, so I'm not sure how quickly we can make a change to support this... |
No emergency on my end, I can just disable GC integration for the time being. On a side note, I saw some more of these panics caused by double borrowing within the GC, i'll try to investigate in case this is a more serious issue with the garbage collector. |
Cool, thanks. To guide your investigation there's probably a point in the GC code where we're currently call (Unless the GC code itself has some kind of bug where it's dependent on double mutable borrow) |
@davidhewitt : that's exactly it! I'll open two separate PRs, one for the GC and a draft one for the current issue, since I have a working WIP implementation that could be refined further IMO. |
This is both a bug report and an improvement request concerning the
PyIterProtocol
trait.🐛 Bug Reports
🌍 Environment
pacman
rustc --version
):1.43.0-nightly
version = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
usingmaster
💥 Reproducing
(complete code in althonos/nanoset.py repo on the
experimental
branch)I have a Rust struct wrapping a single
PyObject
, which I expose both in thePyIterProtocol
to call the wrapped object__iter__
, and in thePyGCProtocol
so that it's traversed and garbage collected as expected:However, when running this within Python, I get some panics whenever the GC tries to traverse my object and i'm requesting iteration of the object at about the same time. That can happen when iterating on the object from within a function it was passed as an argument of. I get the following backtrace:
which suggests that
pyo3
tried to borrow mutablyMyWrapper
twice.However, I don't actually need a mutable reference in
__iter__
, so i tried tinkering with thepyo3
code, and I got my code to work without panics after chaning thePyIteratorProtocol::__iter__
signature only to take aPyRef
.This leads to my following question: would it be possible to make
__iter__
accept eitherPyRef
orPyMutRef
, like other methods support several arbitrary types?The text was updated successfully, but these errors were encountered: