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.
Whats needed for that is:
CopyOnCopyPyString will use a pointer to the C# string character buffer. The difference to constructing a normal PyString is:
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.