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

Minimal overhead C# string to/from PyString conversions with CopyOnCopyPyString CPython implementation #271

Open
minesworld opened this issue Oct 13, 2024 · 0 comments

Comments

@minesworld
Copy link

Whats needed for that is:

  • a UTF-16 first compiled CPython DLL. In such PyString will always store a dotnet compatible representation.
  • a CopyOnCopyPyString subclass of PyString implemented in C. Such an instance will be used during CPython API calls. So it is assured that the C# remained valid and its char buffer doesn't move,

CopyOnCopyPyString will use a pointer to the C# string character buffer. The difference to constructing a normal PyString is:

  • if after the CPython ABI call the CopyOnCopyPyString refcount shows thats someone else holds a reference the C# string characters will be copied so it is CPython managed.
  • same if a view or PyBuffer etc. is created on the CopyOnCopyPyString .

For most CPython ABI calls like passing the name of an attribute or key to get an item out of a dictionary - the will be no copy made. But there can be some "funny" Python code which does - and it will still work 100% correctly.

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

1 participant