Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion pythonnet/src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,26 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.Int32:
#if (PYTHON32 || PYTHON33 || PYTHON34)
// Python3 uses only 64 bits integers as ints
op = Runtime.PyNumber_Long(value);
if (op == IntPtr.Zero) {
if (Exceptions.ExceptionMatches(overflow)) {
goto overflow;
}
goto type_error;
}
long ll = (long)Runtime.PyLong_AsLongLong(op);
Runtime.Decref(op);
if ((ll == -1) && Exceptions.ErrorOccurred()) {
goto overflow;
}
if (ll > Int32.MaxValue || ll < Int32.MinValue) {
goto overflow;
}
result = (int)ll;
return true;
#else
// Trickery to support 64-bit platforms.
if (IntPtr.Size == 4) {
op = Runtime.PyNumber_Int(value);
Expand Down Expand Up @@ -444,7 +464,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
result = (int)ll;
return true;
}

#endif
case TypeCode.Boolean:
result = (Runtime.PyObject_IsTrue(value) != 0);
return true;
Expand Down