8000 PyIter: do not force dispose previous object upon moving to the next one by lostmsu · Pull Request #1331 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

PyIter: do not force dispose previous object upon moving to the next one #1331

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

Merged
merged 1 commit into from
Dec 18, 2020

Conversation

lostmsu
Copy link
Member
@lostmsu lostmsu commented Dec 17, 2020

What does this implement/fix? Explain your changes.

Prior to this change trying to use object returned by iterating over PyObject would fail after iterator is closed, because iterator would dispose previously returned objects on close/moving to the next one.

This also adds error handling for PyIter_Next calls, which can have other reasons to fail beyond reaching the end of collection.

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

@@ -1855,6 +1855,8 @@ internal static bool PyIter_Check(IntPtr pointer)

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyIter_Next(IntPtr pointer);
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there are still a few uses.

also added exception handling for PyIter_Next

PyObject now implements `IEnumerable<PyObject>`
@filmor filmor merged commit 7149d5e into pythonnet:master Dec 18, 2020
@lostmsu lostmsu deleted the PyIterFixes branch December 18, 2020 20:48
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.

2 participants
0