Skip to content

Commit

Permalink
allow converting python floats to dotnet ints
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Jan 26, 2024
1 parent 0a5a63c commit f03446b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/runtime/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,18 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec

case TypeCode.Int32:
{
// lets allow sending python floats into dotnet integers
nint num;
if (Runtime.PyFloat_Check(value))
{
num = (int)Runtime.PyFloat_AsDouble(value);
}
// Python3 always use PyLong API
nint num = Runtime.PyLong_AsSignedSize_t(value);
else
{
num = Runtime.PyLong_AsSignedSize_t(value);
}

if (num == -1 && Exceptions.ErrorOccurred())
{
goto convert_error;
Expand Down

0 comments on commit f03446b

Please sign in to comment.