tonybaloney / CSnakes

https://tonybaloney.github.io/CSnakes/
MIT License
335 stars 25 forks source link

Fix missing __file__ attribute on builtin modules by applying PythonPath as appending to sys.path #308

Open minesworld opened 2 weeks ago

minesworld commented 2 weeks ago

This time it should work...

The patch:

AppendMissingPathsToSysPathis written using "raw" nintC-API calls. Added the missing DLL calls as xxxRaw() .

minesworld commented 2 weeks ago

@Tony : my first pull request failed to work as it was based on the wrong fork. The first thing I did was refactoring the CAPI...

PyList_GetItem
PyList_GetItem_

and an (now) an additional

PyList_GetItemRaw

Sorry - but WTF ?!?

My "minesworld" fork which refactors the raw calls into an "Unmanaged" nint based CAPI which is the base for the normal IntPtr CAPI is much "cleaner"... https://github.com/minesworld/CSnakes/tree/minesworld

But the real beauty is the kind of genious NewReference/ BorrowedReference C# language usage of pythonnet. Was really astonished seeing that...

The code is the documentation implemented in a perfect way for CPythons C-API. (Somehow ironic looking at the CPython C-API naming)

The only downside to that might be that there is no raw nint and such it might have effects on the heap/stack and is a bit slower...

PS: is there a way in C# to alias a type definition in a way that it is its own type and must be "forced" back if used as its original definition? Like

using pyoPtr = nint;

and passig a pyoPtr x to a function which accepts a nint arg would fail without (nint)x ??