| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,6 +136,7 @@ | |||
| 136 | 136 | <Compile Include="runtime.cs" /> | |
| 137 | 137 | <Compile Include="typemanager.cs" /> | |
| 138 | 138 | <Compile Include="typemethod.cs" /> | |
| 139 | + <Compile Include="Util.cs" /> | ||
| 139 | 140 | </ItemGroup> | |
| 140 | 141 | <ItemGroup Condition=" '$(PythonInteropFile)' != '' "> | |
| 141 | 142 | <Compile Include="$(PythonInteropFile)" /> | |
@@ -164,4 +165,4 @@ | |||
| 164 | 165 | <Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" /> | |
| 165 | 166 | <!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /--> | |
| 166 | 167 | </Target> | |
| 167 | - </Project> | ||
| 168 | + </Project> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Runtime.InteropServices; | ||
| 3 | + | ||
| 4 | + namespace Python.Runtime | ||
| 5 | + { | ||
| 6 | + internal class Util | ||
| 7 | + { | ||
| 8 | + internal static Int64 ReadCLong(IntPtr tp, int offset) | ||
| 9 | + { | ||
| 10 | + // On Windows, a C long is always 32 bits. | ||
| 11 | + if (Runtime.IsWindows || Runtime.Is32Bit) | ||
| 12 | + { | ||
| 13 | + return Marshal.ReadInt32(tp, offset); | ||
| 14 | + } | ||
| 15 | + else | ||
| 16 | + { | ||
| 17 | + return Marshal.ReadInt64(tp, offset); | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + internal static void WriteCLong(IntPtr type, int offset, Int64 flags) | ||
| 22 | + { | ||
| 23 | + if (Runtime.IsWindows || Runtime.Is32Bit) | ||
| 24 | + { | ||
| 25 | + Marshal.WriteInt32(type, offset, (Int32)(flags & 0xffffffffL)); | ||
| 26 | + } | ||
| 27 | + else | ||
| 28 | + { | ||
| 29 | + Marshal.WriteInt64(type, offset, flags); | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | + } | ||
| 33 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - using System; | ||
| 1 | + using System; | ||
| 2 | 2 | using System.Runtime.InteropServices; | |
| 3 | 3 | ||
| 4 | 4 | namespace Python.Runtime | |
@@ -11,7 +11,7 @@ internal CLRObject(object ob, IntPtr tp) | |||
| 11 | 11 | { | |
| 12 | 12 | IntPtr py = Runtime.PyType_GenericAlloc(tp, 0); | |
| 13 | 13 | ||
| 14 | - var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags); | ||
| 14 | + long flags = Util.ReadCLong(tp, TypeOffset.tp_flags); | ||
| 15 | 15 | if ((flags & TypeFlags.Subclass) != 0) | |
| 16 | 16 | { | |
| 17 | 17 | IntPtr dict = Marshal.ReadIntPtr(py, ObjectOffset.DictOffset(tp)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - using System; | ||
| 1 | + using System; | ||
| 2 | 2 | using System.Runtime.InteropServices; | |
| 3 | 3 | ||
| 4 | 4 | namespace Python.Runtime | |
@@ -28,7 +28,7 @@ internal static ManagedType GetManagedObject(IntPtr ob) | |||
| 28 | 28 | tp = ob; | |
| 29 | 29 | } | |
| 30 | 30 | ||
| 31 | - var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags); | ||
| 31 | + var flags = Util.ReadCLong(tp, TypeOffset.tp_flags); | ||
| 32 | 32 | if ((flags & TypeFlags.Managed) != 0) | |
| 33 | 33 | { | |
| 34 | 34 | IntPtr op = tp == ob | |
@@ -63,7 +63,7 @@ internal static bool IsManagedType(IntPtr ob) | |||
| 63 | 63 | tp = ob; | |
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | - var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags); | ||
| 66 | + var flags = Util.ReadCLong(tp, TypeOffset.tp_flags); | ||
| 67 | 67 | if ((flags & TypeFlags.Managed) != 0) | |
| 68 | 68 | { | |
| 69 | 69 | return true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,7 +105,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) | |||
| 105 | 105 | flags |= TypeFlags.BaseType; | |
| 106 | 106 | flags |= TypeFlags.Subclass; | |
| 107 | 107 | flags |= TypeFlags.HaveGC; | |
| 108 | - Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags); | ||
| 108 | + Util.WriteCLong(type, TypeOffset.tp_flags, flags); | ||
| 109 | 109 | ||
| 110 | 110 | TypeManager.CopySlot(base_type, type, TypeOffset.tp_dealloc); | |
| 111 | 111 | ||
@@ -237,7 +237,7 @@ public static void tp_dealloc(IntPtr tp) | |||
| 237 | 237 | { | |
| 238 | 238 | // Fix this when we dont cheat on the handle for subclasses! | |
| 239 | 239 | ||
| 240 | - var flags = (int)Marshal.ReadIntPtr(tp, TypeOffset.tp_flags); | ||
| 240 | + var flags = Util.ReadCLong(tp, TypeOffset.tp_flags); | ||
| 241 | 241 | if ((flags & TypeFlags.Subclass) == 0) | |
| 242 | 242 | { | |
| 243 | 243 | IntPtr gc = Marshal.ReadIntPtr(tp, TypeOffset.magic()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -152,6 +152,10 @@ public class Runtime | |||
| 152 | 152 | internal static bool IsFinalizing; | |
| 153 | 153 | ||
| 154 | 154 | internal static bool Is32Bit = IntPtr.Size == 4; | |
| 155 | + | ||
| 156 | + // .NET core: System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows) | ||
| 157 | + internal static bool IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT; | ||
| 158 | + | ||
| 155 | 159 | internal static bool IsPython2 = pyversionnumber < 30; | |
| 156 | 160 | internal static bool IsPython3 = pyversionnumber >= 30; | |
| 157 | 161 | ||
@@ -762,7 +766,7 @@ internal static bool PyObject_IsIterable(IntPtr pointer) | |||
| 762 | 766 | { | |
| 763 | 767 | var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type); | |
| 764 | 768 | #if PYTHON2 | |
| 765 | - long tp_flags = Marshal.ReadInt64(ob_type, TypeOffset.tp_flags); | ||
| 769 | + long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags); | ||
| 766 | 770 | if ((tp_flags & TypeFlags.HaveIter) == 0) | |
| 767 | 771 | return false; | |
| 768 | 772 | #endif | |
@@ -1419,7 +1423,7 @@ internal static bool PyIter_Check(IntPtr pointer) | |||
| 1419 | 1423 | { | |
| 1420 | 1424 | var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type); | |
| 1421 | 1425 | #if PYTHON2 | |
| 1422 | - long tp_flags = Marshal.ReadInt64(ob_type, TypeOffset.tp_flags); | ||
| 1426 | + long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags); | ||
| 1423 | 1427 | if ((tp_flags & TypeFlags.HaveIter) == 0) | |
| 1424 | 1428 | return false; | |
| 1425 | 1429 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - using System; | ||
| 1 | + using System; | ||
| 2 | 2 | using System.Collections; | |
| 3 | 3 | using System.Collections.Generic; | |
| 4 | 4 | using System.Reflection; | |
@@ -86,7 +86,7 @@ internal static IntPtr CreateType(Type impl) | |||
| 86 | 86 | ||
| 87 | 87 | int flags = TypeFlags.Default | TypeFlags.Managed | | |
| 88 | 88 | TypeFlags.HeapType | TypeFlags.HaveGC; | |
| 89 | - Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags); | ||
| 89 | + Util.WriteCLong(type, TypeOffset.tp_flags, flags); | ||
| 90 | 90 | ||
| 91 | 91 | Runtime.PyType_Ready(type); | |
| 92 | 92 | ||
@@ -160,7 +160,7 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType) | |||
| 160 | 160 | flags |= TypeFlags.HeapType; | |
| 161 | 161 | flags |= TypeFlags.BaseType; | |
| 162 | 162 | flags |= TypeFlags.HaveGC; | |
| 163 | - Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags); | ||
| 163 | + Util.WriteCLong(type, TypeOffset.tp_flags, flags); | ||
| 164 | 164 | ||
| 165 | 165 | // Leverage followup initialization from the Python runtime. Note | |
| 166 | 166 | // that the type of the new type must PyType_Type at the time we | |
@@ -323,7 +323,7 @@ internal static IntPtr CreateMetaType(Type impl) | |||
| 323 | 323 | flags |= TypeFlags.Managed; | |
| 324 | 324 | flags |= TypeFlags.HeapType; | |
| 325 | 325 | flags |= TypeFlags.HaveGC; | |
| 326 | - Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags); | ||
| 326 | + Util.WriteCLong(type, TypeOffset.tp_flags, flags); | ||
| 327 | 327 | ||
| 328 | 328 | // We need space for 3 PyMethodDef structs, each of them | |
| 329 | 329 | // 4 int-ptrs in size. | |
@@ -380,7 +380,7 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl) | |||
| 380 | 380 | flags |= TypeFlags.Managed; | |
| 381 | 381 | flags |= TypeFlags.HeapType; | |
| 382 | 382 | flags |= TypeFlags.HaveGC; | |
| 383 | - Marshal.WriteIntPtr(type, TypeOffset.tp_flags, (IntPtr)flags); | ||
| 383 | + Util.WriteCLong(type, TypeOffset.tp_flags, flags); | ||
| 384 | 384 | ||
| 385 | 385 | CopySlot(base_, type, TypeOffset.tp_traverse); | |
| 386 | 386 | CopySlot(base_, type, TypeOffset.tp_clear); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments