Skip to content

Memory issue in Converter.ToArray() #1899

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

Open
Tiehong opened this issue Aug 8, 2022 · 2 comments
Open

Memory issue in Converter.ToArray() #1899

Tiehong opened this issue Aug 8, 2022 · 2 comments

Comments

@Tiehong
Copy link

Tiehong commented Aug 8, 2022

Environment

  • Pythonnet version:3.0.0-rc4
  • Python version:3.8
  • Operating System:Win11
  • .NET Runtime: 4.8

Details

  • Program hangs and crashes.

  • Under debug, there is a dead loop in Converter.ToArray() method:
    image

null should be checked before adding to the list:

        while (true)
        {
            using var item = Runtime.PyIter_Next(IterObject.Borrow());
            if (item.IsNull()) break;

            if (!Converter.ToManaged(item.Borrow(), elementType, out var obj, setError))
            {
                return false;
            }

            **if (obj == null)  break;**

            list.Add(obj);
        }
@lostmsu
Copy link
Member

lostmsu commented Aug 8, 2022

The code looks correct to me. See PyIter_Next. What is the source sequence? The example is incomplete.

@Tiehong
Copy link
Author

Tiehong commented Aug 9, 2022

I found this issue along with the other issue (#1900). If a Python class has getitem() defined, this will happen when converting it to managed type.

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

No branches or pull requests

2 participants