| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,6 +64,8 @@ public static void DomainReloadAndGC() | |||
| 64 | 64 | // objects is gone. | |
| 65 | 65 | Assembly pythonRunner2 = BuildAssembly("test2"); | |
| 66 | 66 | RunAssemblyAndUnload(pythonRunner2, "test2"); | |
| 67 | + | ||
| 68 | + PythonEngine.Shutdown(); | ||
| 67 | 69 | } | |
| 68 | 70 | ||
| 69 | 71 | // | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,15 +27,14 @@ public static void PlatformCache() | |||
| 27 | 27 | { | |
| 28 | 28 | Runtime.Runtime.Initialize(); | |
| 29 | 29 | ||
| 30 | - Assert.That(Runtime.Runtime.Machine, Is.Not.EqualTo(MachineType.Other)); | ||
| 31 | - Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.MachineName)); | ||
| 30 | + Assert.That(NativeCodePageHelper.Machine, Is.Not.EqualTo(MachineType.Other)); | ||
| 31 | + Assert.That(!string.IsNullOrEmpty(NativeCodePageHelper.MachineName)); | ||
| 32 | 32 | ||
| 33 | - Assert.That(Runtime.Runtime.OperatingSystem, Is.Not.EqualTo(OperatingSystemType.Other)); | ||
| 34 | - Assert.That(!string.IsNullOrEmpty(Runtime.Runtime.OperatingSystemName)); | ||
| 33 | + Assert.That(NativeCodePageHelper.OperatingSystem, Is.Not.EqualTo(OperatingSystemType.Other)); | ||
| 34 | + Assert.That(!string.IsNullOrEmpty(NativeCodePageHelper.OperatingSystemName)); | ||
| 35 | 35 | ||
| 36 | - // Don't shut down the runtime: if the python engine was initialized | ||
| 37 | - // but not shut down by another test, we'd end up in a bad state. | ||
| 38 | - } | ||
| 36 | + Runtime.Runtime.Shutdown(); | ||
| 37 | + } | ||
| 39 | 38 | ||
| 40 | 39 | [Test] | |
| 41 | 40 | public static void Py_IsInitializedValue() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | using NUnit.Framework; | |
| 2 | 2 | using Python.Runtime; | |
| 3 | + using Python.Runtime.Platform; | ||
| 3 | 4 | using System.Runtime.InteropServices; | |
| 4 | 5 | ||
| 5 | 6 | namespace Python.EmbeddingTest | |
@@ -15,22 +16,21 @@ public static void Init() | |||
| 15 | 16 | [TearDown] | |
| 16 | 17 | public static void Fini() | |
| 17 | 18 | { | |
| 18 | - // Don't shut down the runtime: if the python engine was initialized | ||
| 19 | - // but not shut down by another test, we'd end up in a bad state. | ||
| 19 | + Runtime.Runtime.Shutdown(); | ||
| 20 | 20 | } | |
| 21 | 21 | ||
| 22 | 22 | [Test] | |
| 23 | 23 | public static void TestNativeCode() | |
| 24 | 24 | { | |
| 25 | - Assert.That(() => { var _ = TypeManager.NativeCode.Active; }, Throws.Nothing); | ||
| 26 | - Assert.That(TypeManager.NativeCode.Active.Code.Length, Is.GreaterThan(0)); | ||
| 25 | + Assert.That(() => { var _ = NativeCodePageHelper.NativeCode.Active; }, Throws.Nothing); | ||
| 26 | + Assert.That(NativeCodePageHelper.NativeCode.Active.Code.Length, Is.GreaterThan(0)); | ||
| 27 | 27 | } | |
| 28 | 28 | ||
| 29 | 29 | [Test] | |
| 30 | 30 | public static void TestMemoryMapping() | |
| 31 | 31 | { | |
| 32 | - Assert.That(() => { var _ = TypeManager.CreateMemoryMapper(); }, Throws.Nothing); | ||
| 33 | - var mapper = TypeManager.CreateMemoryMapper(); | ||
| 32 | + Assert.That(() => { var _ = NativeCodePageHelper.CreateMemoryMapper(); }, Throws.Nothing); | ||
| 33 | + var mapper = NativeCodePageHelper.CreateMemoryMapper(); | ||
| 34 | 34 | ||
| 35 | 35 | // Allocate a read-write page. | |
| 36 | 36 | int len = 12; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,7 @@ public void SetUp() | |||
| 40 | 40 | IntPtr str = Runtime.Runtime.PyString_FromString(testPath); | |
| 41 | 41 | IntPtr path = Runtime.Runtime.PySys_GetObject("path"); | |
| 42 | 42 | Runtime.Runtime.PyList_Append(path, str); | |
| 43 | + Runtime.Runtime.XDecref(str); | ||
| 43 | 44 | } | |
| 44 | 45 | ||
| 45 | 46 | [TearDown] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,7 @@ public static void LoadDefaultArgs() | |||
| 26 | 26 | using (new PythonEngine()) | |
| 27 | 27 | using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv"))) | |
| 28 | 28 | { | |
| 29 | + Runtime.Runtime.XIncref(argv.Handle); | ||
| 29 | 30 | Assert.AreNotEqual(0, argv.Length()); | |
| 30 | 31 | } | |
| 31 | 32 | } | |
@@ -37,6 +38,7 @@ public static void LoadSpecificArgs() | |||
| 37 | 38 | using (new PythonEngine(args)) | |
| 38 | 39 | using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv"))) | |
| 39 | 40 | { | |
| 41 | + Runtime.Runtime.XIncref(argv.Handle); | ||
| 40 | 42 | Assert.AreEqual(args[0], argv[0].ToString()); | |
| 41 | 43 | Assert.AreEqual(args[1], argv[1].ToString()); | |
| 42 | 44 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -143,6 +143,7 @@ | |||
| 143 | 143 | <Compile Include="Util.cs" /> | |
| 144 | 144 | <Compile Include="platform\Types.cs" /> | |
| 145 | 145 | <Compile Include="platform\LibraryLoader.cs" /> | |
| 146 | + <Compile Include="platform\NativeCodePage.cs" /> | ||
| 146 | 147 | <Compile Include="slots\mp_length.cs" /> | |
| 147 | 148 | </ItemGroup> | |
| 148 | 149 | <ItemGroup Condition=" '$(PythonInteropFile)' != '' "> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,6 +99,10 @@ internal static IntPtr ToPython(IPythonDerivedType obj) | |||
| 99 | 99 | // collected while Python still has a reference to it. | |
| 100 | 100 | if (Runtime.Refcount(self.pyHandle) == 1) | |
| 101 | 101 | { | |
| 102 | + | ||
| 103 | + #if PYTHON_WITH_PYDEBUG | ||
| 104 | + Runtime._Py_NewReference(self.pyHandle); | ||
| 105 | + #endif | ||
| 102 | 106 | GCHandle gc = GCHandle.Alloc(self, GCHandleType.Normal); | |
| 103 | 107 | Marshal.WriteIntPtr(self.pyHandle, ObjectOffset.magic(self.tpHandle), (IntPtr)gc); | |
| 104 | 108 | self.gcHandle.Free(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,37 @@ public ModulePropertyAttribute() | |||
| 69 | 69 | } | |
| 70 | 70 | } | |
| 71 | 71 | ||
| 72 | + internal static partial class TypeOffset | ||
| 73 | + { | ||
| 74 | + static class Helper | ||
| 75 | + { | ||
| 76 | + public static int magic; | ||
| 77 | + public static readonly Dictionary<string, int> NameMapping = new Dictionary<string, int>(); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + static TypeOffset() | ||
| 81 | + { | ||
| 82 | + Type type = typeof(TypeOffset); | ||
| 83 | + FieldInfo[] fields = type.GetFields(); | ||
| 84 | + int size = IntPtr.Size; | ||
| 85 | + for (int i = 0; i < fields.Length; i++) | ||
| 86 | + { | ||
| 87 | + int offset = i * size; | ||
| 88 | + FieldInfo fi = fields[i]; | ||
| 89 | + fi.SetValue(null, offset); | ||
| 90 | + Helper.NameMapping[fi.Name] = offset; | ||
| 91 | + } | ||
| 92 | + // XXX: Use the members after PyHeapTypeObject as magic slot | ||
| 93 | + Helper.magic = members; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public static int magic() => Helper.magic; | ||
| 97 | + | ||
| 98 | + public static int GetSlotOffset(string name) | ||
| 99 | + { | ||
| 100 | + return Helper.NameMapping[name]; | ||
| 101 | + } | ||
| 102 | + } | ||
| 72 | 103 | ||
| 73 | 104 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
| 74 | 105 | internal class ObjectOffset | |
@@ -556,4 +587,5 @@ struct PyMethodDef | |||
| 556 | 587 | public int ml_flags; | |
| 557 | 588 | public IntPtr ml_doc; | |
| 558 | 589 | } | |
| 590 | + | ||
| 559 | 591 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | + | ||
| 1 | 2 | // Auto-generated by geninterop.py. | |
| 2 | - // DO NOT MODIFIY BY HAND. | ||
| 3 | + // DO NOT MODIFY BY HAND. | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | 6 | #if PYTHON27 | |
@@ -12,25 +13,10 @@ | |||
| 12 | 13 | ||
| 13 | 14 | namespace Python.Runtime | |
| 14 | 15 | { | |
| 15 | - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | ||
| 16 | - internal class TypeOffset | ||
| 17 | - { | ||
| 18 | - static TypeOffset() | ||
| 19 | - { | ||
| 20 | - Type type = typeof(TypeOffset); | ||
| 21 | - FieldInfo[] fi = type.GetFields(); | ||
| 22 | - int size = IntPtr.Size; | ||
| 23 | - for (int i = 0; i < fi.Length; i++) | ||
| 24 | - { | ||
| 25 | - fi[i].SetValue(null, i * size); | ||
| 26 | - } | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - public static int magic() | ||
| 30 | - { | ||
| 31 | - return ob_size; | ||
| 32 | - } | ||
| 33 | 16 | ||
| 17 | + [StructLayout(LayoutKind.Sequential)] | ||
| 18 | + internal static partial class TypeOffset | ||
| 19 | + { | ||
| 34 | 20 | // Auto-generated from PyHeapTypeObject in Python.h | |
| 35 | 21 | public static int ob_refcnt = 0; | |
| 36 | 22 | public static int ob_type = 0; | |
@@ -145,6 +131,94 @@ public static int magic() | |||
| 145 | 131 | /* here are optional user slots, followed by the members. */ | |
| 146 | 132 | public static int members = 0; | |
| 147 | 133 | } | |
| 148 | - } | ||
| 149 | 134 | ||
| 135 | + [StructLayout(LayoutKind.Sequential)] | ||
| 136 | + internal struct PyNumberMethods | ||
| 137 | + { | ||
| 138 | + public IntPtr nb_add; | ||
| 139 | + public IntPtr nb_subtract; | ||
| 140 | + public IntPtr nb_multiply; | ||
| 141 | + public IntPtr nb_divide; | ||
| 142 | + public IntPtr nb_remainder; | ||
| 143 | + public IntPtr nb_divmod; | ||
| 144 | + public IntPtr nb_power; | ||
| 145 | + public IntPtr nb_negative; | ||
| 146 | + public IntPtr nb_positive; | ||
| 147 | + public IntPtr nb_absolute; | ||
| 148 | + public IntPtr nb_nonzero; | ||
| 149 | + public IntPtr nb_invert; | ||
| 150 | + public IntPtr nb_lshift; | ||
| 151 | + public IntPtr nb_rshift; | ||
| 152 | + public IntPtr nb_and; | ||
| 153 | + public IntPtr nb_xor; | ||
| 154 | + public IntPtr nb_or; | ||
| 155 | + public IntPtr nb_coerce; | ||
| 156 | + public IntPtr nb_int; | ||
| 157 | + public IntPtr nb_long; | ||
| 158 | + public IntPtr nb_float; | ||
| 159 | + public IntPtr nb_oct; | ||
| 160 | + public IntPtr nb_hex; | ||
| 161 | + public IntPtr nb_inplace_add; | ||
| 162 | + public IntPtr nb_inplace_subtract; | ||
| 163 | + public IntPtr nb_inplace_multiply; | ||
| 164 | + public IntPtr nb_inplace_divide; | ||
| 165 | + public IntPtr nb_inplace_remainder; | ||
| 166 | + public IntPtr nb_inplace_power; | ||
| 167 | + public IntPtr nb_inplace_lshift; | ||
| 168 | + public IntPtr nb_inplace_rshift; | ||
| 169 | + public IntPtr nb_inplace_and; | ||
| 170 | + public IntPtr nb_inplace_xor; | ||
| 171 | + public IntPtr nb_inplace_or; | ||
| 172 | + public IntPtr nb_floor_divide; | ||
| 173 | + public IntPtr nb_true_divide; | ||
| 174 | + public IntPtr nb_inplace_floor_divide; | ||
| 175 | + public IntPtr nb_inplace_true_divide; | ||
| 176 | + public IntPtr nb_index; | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + [StructLayout(LayoutKind.Sequential)] | ||
| 180 | + internal struct PySequenceMethods | ||
| 181 | + { | ||
| 182 | + public IntPtr sq_length; | ||
| 183 | + public IntPtr sq_concat; | ||
| 184 | + public IntPtr sq_repeat; | ||
| 185 | + public IntPtr sq_item; | ||
| 186 | + public IntPtr sq_slice; | ||
| 187 | + public IntPtr sq_ass_item; | ||
| 188 | + public IntPtr sq_ass_slice; | ||
| 189 | + public IntPtr sq_contains; | ||
| 190 | + public IntPtr sq_inplace_concat; | ||
| 191 | + public IntPtr sq_inplace_repeat; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + [StructLayout(LayoutKind.Sequential)] | ||
| 195 | + internal struct PyMappingMethods | ||
| 196 | + { | ||
| 197 | + public IntPtr mp_length; | ||
| 198 | + public IntPtr mp_subscript; | ||
| 199 | + public IntPtr mp_ass_subscript; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + [StructLayout(LayoutKind.Sequential)] | ||
| 203 | + internal struct PyBufferProcs | ||
| 204 | + { | ||
| 205 | + public IntPtr bf_getreadbuffer; | ||
| 206 | + public IntPtr bf_getwritebuffer; | ||
| 207 | + public IntPtr bf_getsegcount; | ||
| 208 | + public IntPtr bf_getcharbuffer; | ||
| 209 | + public IntPtr bf_getbuffer; | ||
| 210 | + public IntPtr bf_releasebuffer; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + internal static partial class SlotTypes | ||
| 214 | + { | ||
| 215 | + public static readonly Type[] Types = { | ||
| 216 | + typeof(PyNumberMethods), | ||
| 217 | + typeof(PySequenceMethods), | ||
| 218 | + typeof(PyMappingMethods), | ||
| 219 | + typeof(PyBufferProcs), | ||
| 220 | + }; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + } | ||
| 150 | 224 | #endif | |
| Back | FazBrowse Home | New Git URL |
0 commit comments