Disable implicit conversion from PyFloat to .NET integer types by lostmsu · Pull Request #1343 · pythonnet/pythonnet
int num = Runtime.PyLong_AsLong(value); nint num = Runtime.PyLong_AsSignedSize_t(value); if (num == -1 && Exceptions.ErrorOccurred()) { goto convert_error;
int num = Runtime.PyLong_AsLong(value); nint num = Runtime.PyLong_AsSignedSize_t(value); if (num == -1 && Exceptions.ErrorOccurred()) { goto convert_error;
case TypeCode.Int16: { int num = Runtime.PyLong_AsLong(value); nint num = Runtime.PyLong_AsSignedSize_t(value); if (num == -1 && Exceptions.ErrorOccurred()) { goto convert_error;
case TypeCode.Int64: { long num = (long)Runtime.PyLong_AsLongLong(value); if (num == -1 && Exceptions.ErrorOccurred()) if (Runtime.Is32Bit) { goto convert_error; if (!Runtime.PyLong_Check(value)) { goto type_error; } long num = Runtime.PyExplicitlyConvertToInt64(value); if (num == -1 && Exceptions.ErrorOccurred()) { goto convert_error; } result = num; return true; } else { nint num = Runtime.PyLong_AsSignedSize_t(value); if (num == -1 && Exceptions.ErrorOccurred()) { goto convert_error; } result = (long)num; return true; } result = num; return true; }
case TypeCode.UInt16: { long num = Runtime.PyLong_AsLong(value); nint num = Runtime.PyLong_AsSignedSize_t(value); if (num == -1 && Exceptions.ErrorOccurred()) { goto convert_error;
case TypeCode.UInt32: { op = value; if (Runtime.PyObject_TYPE(value) != Runtime.PyLongType) { op = Runtime.PyNumber_Long(value); if (op == IntPtr.Zero) { goto convert_error; } } if (Runtime.Is32Bit || Runtime.IsWindows) nuint num = Runtime.PyLong_AsUnsignedSize_t(value); if (num == unchecked((nuint)(-1)) && Exceptions.ErrorOccurred()) { uint num = Runtime.PyLong_AsUnsignedLong32(op); if (num == uint.MaxValue && Exceptions.ErrorOccurred()) { goto convert_error; } result = num; goto convert_error; } else if (num > UInt32.MaxValue) { ulong num = Runtime.PyLong_AsUnsignedLong64(op); if (num == ulong.MaxValue && Exceptions.ErrorOccurred()) { goto convert_error; } try { result = Convert.ToUInt32(num); } catch (OverflowException) { // Probably wasn't an overflow in python but was in C# (e.g. if cpython // longs are 64 bit then 0xFFFFFFFF + 1 will not overflow in // PyLong_AsUnsignedLong) goto overflow; } goto overflow; } result = (uint)num; return true; }