| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 46c7597 commit 60e6045
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 25 | 25 | - Fixed runtime that fails loading when using pythonnet in an environment | |
| 26 | 26 | together with Nuitka | |
| 27 | 27 | - Fixes bug where delegates get casts (dotnetcore) | |
| 28 | + - Determine size of interpreter longs at runtime | ||
| 28 | 29 | ||
| 29 | 30 | ## [2.4.0][] | |
| 30 | 31 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -728,7 +728,20 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo | |||
| 728 | 728 | } | |
| 729 | 729 | goto type_error; | |
| 730 | 730 | } | |
| 731 | - uint ui = (uint)Runtime.PyLong_AsUnsignedLong(op); | ||
| 731 | + | ||
| 732 | + uint ui; | ||
| 733 | + try | ||
| 734 | + { | ||
| 735 | + ui = Convert.ToUInt32(Runtime.PyLong_AsUnsignedLong(op)); | ||
| 736 | + } catch (OverflowException) | ||
| 737 | + { | ||
| 738 | + // Probably wasn't an overflow in python but was in C# (e.g. if cpython | ||
| 739 | + // longs are 64 bit then 0xFFFFFFFF + 1 will not overflow in | ||
| 740 | + // PyLong_AsUnsignedLong) | ||
| 741 | + Runtime.XDecref(op); | ||
| 742 | + goto overflow; | ||
| 743 | + } | ||
| 744 | + | ||
| 732 | 745 | ||
| 733 | 746 | if (Exceptions.ErrorOccurred()) | |
| 734 | 747 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1036,8 +1036,21 @@ internal static bool PyLong_Check(IntPtr ob) | |||
| 1036 | 1036 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 1037 | 1037 | internal static extern IntPtr PyLong_FromLong(long value); | |
| 1038 | 1038 | ||
| 1039 | - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | ||
| 1040 | - internal static extern IntPtr PyLong_FromUnsignedLong(uint value); | ||
| 1039 | + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, | ||
| 1040 | + EntryPoint = "PyLong_FromUnsignedLong")] | ||
| 1041 | + internal static extern IntPtr PyLong_FromUnsignedLong32(uint value); | ||
| 1042 | + | ||
| 1043 | + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, | ||
| 1044 | + EntryPoint = "PyLong_FromUnsignedLong")] | ||
| 1045 | + internal static extern IntPtr PyLong_FromUnsignedLong64(ulong value); | ||
| 1046 | + | ||
| 1047 | + internal static IntPtr PyLong_FromUnsignedLong(object value) | ||
| 1048 | + { | ||
| 1049 | + if(Is32Bit || IsWindows) | ||
| 1050 | + return PyLong_FromUnsignedLong32(Convert.ToUInt32(value)); | ||
| 1051 | + else | ||
| 1052 | + return PyLong_FromUnsignedLong64(Convert.ToUInt64(value)); | ||
| 1053 | + } | ||
| 1041 | 1054 | ||
| 1042 | 1055 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 1043 | 1056 | internal static extern IntPtr PyLong_FromDouble(double value); | |
@@ -1054,8 +1067,21 @@ internal static bool PyLong_Check(IntPtr ob) | |||
| 1054 | 1067 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 1055 | 1068 | internal static extern int PyLong_AsLong(IntPtr value); | |
| 1056 | 1069 | ||
| 1057 | - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | ||
| 1058 | - internal static extern uint PyLong_AsUnsignedLong(IntPtr value); | ||
| 1070 | + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, | ||
| 1071 | + EntryPoint = "PyLong_AsUnsignedLong")] | ||
| 1072 | + internal static extern uint PyLong_AsUnsignedLong32(IntPtr value); | ||
| 1073 | + | ||
| 1074 | + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, | ||
| 1075 | + EntryPoint = "PyLong_AsUnsignedLong")] | ||
| 1076 | + internal static extern ulong PyLong_AsUnsignedLong64(IntPtr value); | ||
| 1077 | + | ||
| 1078 | + internal static object PyLong_AsUnsignedLong(IntPtr value) | ||
| 1079 | + { | ||
| 1080 | + if (Is32Bit || IsWindows) | ||
| 1081 | + return PyLong_AsUnsignedLong32(value); | ||
| 1082 | + else | ||
| 1083 | + return PyLong_AsUnsignedLong64(value); | ||
| 1084 | + } | ||
| 1059 | 1085 | ||
| 1060 | 1086 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 1061 | 1087 | internal static extern long PyLong_AsLongLong(IntPtr value); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments