8000 Dotnetcore System.UInt32 conversion issues · Issue #950 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content
Dotnetcore System.UInt32 conversion issues #950
Closed
@jmlidbetter

Description

@jmlidbetter

Environment

  • Pythonnet version: 2.4.0
  • Python version: 3.6.5
  • Operating System: Centos 7 64bit

Details

  • 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

image

Using PyLong_FromUnsignedLong on the resulting uint gives this:

image

I have raised an issue on the coreclr project: Issue 26444

FYI changing the function definition from

internal static extern IntPtr PyLong_FromUnsignedLong(uint value);

to

internal static extern IntPtr PyLong_FromUnsignedLong(ulong value);

fixes the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0