Skip to content

IComparable and IEquatable implementations #2322

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
Feb 28, 2024

Conversation

lostmsu
Copy link
Member

@lostmsu lostmsu commented Feb 15, 2024

IComparable and IEquatable implementations for PyInt, PyFloat, and PyString for primitive .NET types

What does this implement/fix? Explain your changes.

Let's one do PyInt.CompareTo(42) and similar things

Does this close any currently open issues?

N/A

Any other comments?

Should we take GIL in these methods? Might be useful for Array.Sort when called from Python.

On a more general topic: should we have a way for Python to call a .NET method and have it not release the GIL for compatibility with 3rd party (to Python.NET) libraries that assume they can call back any methods they wish at any time. Because having explicit GIL acquisition in CompareTo to use with Array.Sort would kill performance. E.g. something like:

with clr.HoldGIL():
  Array.Sort(dotnet_array_of_python_objects)

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

@lostmsu lostmsu requested a review from filmor February 27, 2024 03:14
@filmor
Copy link
Member

filmor commented Feb 28, 2024

Regarding the GIL, maybe we could a custom thread local ref count could speed things up?

@lostmsu lostmsu force-pushed the ComparableEquatable branch from 3e27819 to f3d8c60 Compare February 28, 2024 19:57
@lostmsu lostmsu force-pushed the ComparableEquatable branch 2 times, most recently from ebab183 to f738505 Compare February 28, 2024 20:08
@lostmsu lostmsu merged commit 563e369 into pythonnet:master Feb 28, 2024
@lostmsu lostmsu deleted the ComparableEquatable branch February 28, 2024 21:46
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