You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creating UInt32 in python with a value greater than 0x7FFFFFFF in dotnetcore will cause an overflow error. This is due (seemingly) to the fact that .NET core clr will cast the uint to a signed long (64 bits in size on my system) before calling the PyLong_FromUsignedLong function. Using GDB and breaking before the errornous overflow we can examine the created PyLongObject:
The PyLongObject given to C# by the python interpretter that can be converted to a uint using PyLong_AsUnsignedLong
Using PyLong_FromUnsignedLong on the resulting uint gives this:
I have raised an issue on the coreclr project: Issue 26444
Well, this is problematic. We want to be platform-independent, but C's unsigned long that is used in Python is 64bit on most 64bit Unices and 32bit on Windows, so the uint parameter is indeed wrong.
On 11 Sep 2019, at 07:39, Benedikt Reinartz ***@***.***> wrote:
Well, this is problematic. We want to be platform-independent, but C's unsigned long that is used in Python is 64bit on most 64bit Unices and 32bit on Windows, so the uint parameter is indeed wrong.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
As far as I can tell, Python is completely oblivious to this difference as it "lives" on the C platform, so all compiled modules will have the same idea of what long means. We can pretty reliably decide this by looking at the platform we are running on in .NET, though. We are already providing internally booleans for IsWindows and Is32Bit here https://github.com/pythonnet/pythonnet/blob/master/src/runtime/runtime.cs#L106-L109.
As far as I can tell, Python is completely oblivious to this difference as it "lives" on the C platform, so all compiled modules will have the same idea of what long means. We can pretty reliably decide this by looking at the platform we are running on in .NET, though. We are already providing internally booleans for IsWindows and Is32Bit here https://github.com/pythonnet/pythonnet/blob/master/src/runtime/runtime.cs#L106-L109.
Would this method get caught out if, for whatever reason, someone is using CPython compiled with 64bit longs on Win64 or CPython compiled with 32bit longs on 64bit Linux?
As per a discussion with Joe, It seems the correct way to do this would be with a call to struct.calcsize('P') which can be done in runtime.cs, in InitializePlatformData(). This gives us the bitness of the interpreter architecture, rather than the platform architecture.
As far as I can tell, Python is completely oblivious to this difference as it "lives" on the C platform, so all compiled modules will have the same idea of what long means. We can pretty reliably decide this by looking at the platform we are running on in .NET, though. We are already providing internally booleans for IsWindows and Is32Bit here https://github.com/pythonnet/pythonnet/blob/master/src/runtime/runtime.cs#L106-L109.
Would this method get caught out if, for whatever reason, someone is using CPython compiled with 64bit longs on Win64 or CPython compiled with 32bit longs on 64bit Linux?
If you managed to compile a program that messed up, it will not be able to reliably interact with anything else on the same system. This is an ABI thing, it's not something a user can just decide.
/edit: Note, that this is a completely different question than asking for a 32bit vs 64bit program on a given system. All operating systems that I know of have separate variants of all relevant libraries compiled in the respective fashion, but sizeof(long) is consistent in each of those environments individually.
On 26 Sep 2019, at 07:53, Benedikt Reinartz ***@***.***> wrote:
As far as I can tell, Python is completely oblivious to this difference as it "lives" on the C platform, so all compiled modules will have the same idea of what long means. We can pretty reliably decide this by looking at the platform we are running on in .NET, though. We are already providing internally booleans for IsWindows and Is32Bit here https://github.com/pythonnet/pythonnet/blob/master/src/runtime/runtime.cs#L106-L109.
Would this method get caught out if, for whatever reason, someone is using CPython compiled with 64bit longs on Win64 or CPython compiled with 32bit longs on 64bit Linux?
If you managed to compile a program that messed up, it will not be able to reliably interact with anything else on the same system. This is an ABI thing, it's not something a user can just decide.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
Yes, and the correct P/Invoke signature can be decided by looking at the IsWindows and Is32Bit values. You wouldn't be able to boot up a .NET VM (or load a libpython in case you're embedding) with non-matching bitness, so drawing those values from .NET will lead to the same result with much less work.
Activity
filmor commentedon Sep 11, 2019
Well, this is problematic. We want to be platform-independent, but C's
unsigned longthat is used in Python is 64bit on most 64bit Unices and 32bit on Windows, so theuintparameter is indeed wrong.Cronan commentedon Sep 11, 2019
filmor commentedon Sep 18, 2019
As far as I can tell, Python is completely oblivious to this difference as it "lives" on the C platform, so all compiled modules will have the same idea of what
longmeans. We can pretty reliably decide this by looking at the platform we are running on in .NET, though. We are already providing internally booleans forIsWindowsandIs32Bithere https://github.com/pythonnet/pythonnet/blob/master/src/runtime/runtime.cs#L106-L109.jmlidbetter commentedon Sep 24, 2019
Would this method get caught out if, for whatever reason, someone is using CPython compiled with 64bit longs on Win64 or CPython compiled with 32bit longs on 64bit Linux?
jmlidbetter commentedon Sep 24, 2019
What we really need is some hook or proxy into
sizeof(long).Cronan commentedon Sep 24, 2019
As per a discussion with Joe, It seems the correct way to do this would be with a call to
struct.calcsize('P')which can be done inruntime.cs, inInitializePlatformData(). This gives us the bitness of the interpreter architecture, rather than the platform architecture.filmor commentedon Sep 26, 2019
If you managed to compile a program that messed up, it will not be able to reliably interact with anything else on the same system. This is an ABI thing, it's not something a user can just decide.
/edit: Note, that this is a completely different question than asking for a 32bit vs 64bit program on a given system. All operating systems that I know of have separate variants of all relevant libraries compiled in the respective fashion, but
sizeof(long)is consistent in each of those environments individually.Cronan commentedon Sep 26, 2019
filmor commentedon Sep 26, 2019
Yes, and the correct P/Invoke signature can be decided by looking at the
IsWindowsandIs32Bitvalues. You wouldn't be able to boot up a .NET VM (or load alibpythonin case you're embedding) with non-matching bitness, so drawing those values from .NET will lead to the same result with much less work.jmlidbetter commentedon Oct 2, 2019
Fixed in PR #961