Skip to content

Commit ef44edd

Browse files
committed
apply amos changes from soft shutdown
1 parent 61d1b7c commit ef44edd

File tree

8 files changed

+80
-132
lines changed

8 files changed

+80
-132
lines changed

pythonnet.15.sln

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.15", "src\console\C
1212
EndProject
1313
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test.15", "src\testing\Python.Test.15.csproj", "{F94B547A-E97E-4500-8D53-B4D64D076E5F}"
1414
EndProject
15-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.PerformanceTests", "src\perf_tests\Python.PerformanceTests.csproj", "{6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}"
16-
EndProject
1715
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Repo", "Repo", "{441A0123-F4C6-4EE4-9AEE-315FD79BE2D5}"
1816
ProjectSection(SolutionItems) = preProject
1917
.editorconfig = .editorconfig

setup.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# Allow config/verbosity to be set from cli
2727
# http://stackoverflow.com/a/4792601/5208670
28-
CONFIG = "Release" # Release or Debug
28+
CONFIG = "Debug" # Release or Debug
2929
VERBOSITY = "normal" # quiet, minimal, normal, detailed, diagnostic
3030

3131
is_64bits = sys.maxsize > 2 ** 32
@@ -356,16 +356,6 @@ def build_extension(self, ext):
356356
),
357357
shell=use_shell,
358358
)
359-
subprocess.check_call(
360-
" ".join(
361-
cmd
362-
+ [
363-
'"/t:Python_PerformanceTests:publish"',
364-
"/p:TargetFramework=net461",
365-
]
366-
),
367-
shell=use_shell,
368-
)
369359
if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet":
370360
self._build_monoclr()
371361

src/runtime/interop.cs

+73-33
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Runtime.InteropServices;
66
using System.Reflection;
77
using System.Text;
8-
using System.Collections.Generic;
98

109
namespace Python.Runtime
1110
{
@@ -69,27 +68,66 @@ public ModulePropertyAttribute()
6968
}
7069
}
7170

71+
internal static partial class TypeOffset
72+
{
73+
static TypeOffset()
74+
{
75+
Type type = typeof(TypeOffset);
76+
FieldInfo[] fields = type.GetFields();
77+
int size = IntPtr.Size;
78+
for (int i = 0; i < fields.Length; i++)
79+
{
80+
int offset = i * size;
81+
FieldInfo fi = fields[i];
82+
fi.SetValue(null, offset);
83+
}
84+
}
85+
86+
public static int magic() => ManagedDataOffsets.Magic;
87+
}
88+
7289
internal static class ManagedDataOffsets
7390
{
74-
static ManagedDataOffsets()
91+
public static int Magic { get; private set; }
92+
public static readonly Dictionary<string, int> NameMapping = new Dictionary<string, int>();
93+
94+
static class DataOffsets
7595
{
76-
FieldInfo[] fi = typeof(ManagedDataOffsets).GetFields(BindingFlags.Static | BindingFlags.Public);
77-
for (int i = 0; i < fi.Length; i++)
96+
public static readonly int ob_data;
97+
public static readonly int ob_dict;
98+
99+
static DataOffsets()
78100
{
79-
fi[i].SetValue(null, -(i * IntPtr.Size) - IntPtr.Size);
101+
FieldInfo[] fields = typeof(DataOffsets).GetFields(BindingFlags.Static | BindingFlags.Public);
102+
for (int i = 0; i < fields.Length; i++)
103+
{
104+
fields[i].SetValue(null, -(i * IntPtr.Size) - IntPtr.Size);
105+
}
80106
}
107+
}
81108

82-
size = fi.Length * IntPtr.Size;
109+
static ManagedDataOffsets()
110+
{
111+
Type type = typeof(TypeOffset);
112+
foreach (FieldInfo fi in type.GetFields())
113+
{
114+
NameMapping[fi.Name] = (int)fi.GetValue(null);
115+
}
116+
Magic = TypeOffset.members;
117+
FieldInfo[] fields = typeof(DataOffsets).GetFields(BindingFlags.Static | BindingFlags.Public);
118+
size = fields.Length * IntPtr.Size;
83119
}
84120

85-
public static readonly int ob_data;
86-
public static readonly int ob_dict;
121+
public static int GetSlotOffset(string name)
122+
{
123+
return NameMapping[name];
124+
}
87125

88126
private static int BaseOffset(IntPtr type)
89127
{
90128
Debug.Assert(type != IntPtr.Zero);
91129
int typeSize = Marshal.ReadInt32(type, TypeOffset.tp_basicsize);
92-
Debug.Assert(typeSize > 0 && typeSize <= ExceptionOffset.Size());
130+
Debug.Assert(typeSize > 0);
93131
return typeSize;
94132
}
95133
public static int DataOffset(IntPtr type)
@@ -102,6 +140,8 @@ public static int DictOffset(IntPtr type)
102140
return BaseOffset(type) + ob_dict;
103141
}
104142

143+
public static int ob_data => DataOffsets.ob_data;
144+
public static int ob_dict => DataOffsets.ob_dict;
105145
public static int Size { get { return size; } }
106146

107147
private static readonly int size;
@@ -320,34 +360,34 @@ public static void FreeModuleDef(IntPtr ptr)
320360
/// </summary>
321361
internal class TypeFlags
322362
{
323-
public static int HeapType = (1 << 9);
324-
public static int BaseType = (1 << 10);
325-
public static int Ready = (1 << 12);
326-
public static int Readying = (1 << 13);
327-
public static int HaveGC = (1 << 14);
363+
public const int HeapType = (1 << 9);
364+
public const int BaseType = (1 << 10);
365+
public const int Ready = (1 << 12);
366+
public const int Readying = (1 << 13);
367+
public const int HaveGC = (1 << 14);
328368
// 15 and 16 are reserved for stackless
329-
public static int HaveStacklessExtension = 0;
369+
public const int HaveStacklessExtension = 0;
330370
/* XXX Reusing reserved constants */
331-
public static int Managed = (1 << 15); // PythonNet specific
332-
public static int Subclass = (1 << 16); // PythonNet specific
333-
public static int HaveIndex = (1 << 17);
371+
public const int Managed = (1 << 15); // PythonNet specific
372+
public const int Subclass = (1 << 16); // PythonNet specific
373+
public const int HaveIndex = (1 << 17);
334374
/* Objects support nb_index in PyNumberMethods */
335-
public static int HaveVersionTag = (1 << 18);
336-
public static int ValidVersionTag = (1 << 19);
337-
public static int IsAbstract = (1 << 20);
338-
public static int HaveNewBuffer = (1 << 21);
375+
public const int HaveVersionTag = (1 << 18);
376+
public const int ValidVersionTag = (1 << 19);
377+
public const int IsAbstract = (1 << 20);
378+
public const int HaveNewBuffer = (1 << 21);
339379
// TODO: Implement FastSubclass functions
340-
public static int IntSubclass = (1 << 23);
341-
public static int LongSubclass = (1 << 24);
342-
public static int ListSubclass = (1 << 25);
343-
public static int TupleSubclass = (1 << 26);
344-
public static int StringSubclass = (1 << 27);
345-
public static int UnicodeSubclass = (1 << 28);
346-
public static int DictSubclass = (1 << 29);
347-
public static int BaseExceptionSubclass = (1 << 30);
348-
public static int TypeSubclass = (1 << 31);
349-
350-
public static int Default = (
380+
public const int IntSubclass = (1 << 23);
381+
public const int LongSubclass = (1 << 24);
382+
public const int ListSubclass = (1 << 25);
383+
public const int TupleSubclass = (1 << 26);
384+
public const int StringSubclass = (1 << 27);
385+
public const int UnicodeSubclass = (1 << 28);
386+
public const int DictSubclass = (1 << 29);
387+
public const int BaseExceptionSubclass = (1 << 30);
388+
public const int TypeSubclass = (1 << 31);
389+
390+
public const int Default = (
351391
HaveStacklessExtension |
352392
HaveVersionTag);
353393
}

src/runtime/interop34.cs

+1-17
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,9 @@
1212

1313
namespace Python.Runtime
1414
{
15-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
15+
[StructLayout(LayoutKind.Sequential)]
1616
internal class TypeOffset
1717
{
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-
3418
// Auto-generated from PyHeapTypeObject in Python.h
3519
public static int ob_refcnt = 0;
3620
public static int ob_type = 0;

src/runtime/interop35.cs

+1-17
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,9 @@
1212

1313
namespace Python.Runtime
1414
{
15-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
15+
[StructLayout(LayoutKind.Sequential)]
1616
internal class TypeOffset
1717
{
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-
3418
// Auto-generated from PyHeapTypeObject in Python.h
3519
public static int ob_refcnt = 0;
3620
public static int ob_type = 0;

src/runtime/interop36.cs

+1-17
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,9 @@
1212

1313
namespace Python.Runtime
1414
{
15-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
15+
[StructLayout(LayoutKind.Sequential)]
1616
internal class TypeOffset
1717
{
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-
3418
// Auto-generated from PyHeapTypeObject in Python.h
3519
public static int ob_refcnt = 0;
3620
public static int ob_type = 0;

src/runtime/interop37.cs

+1-17
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,9 @@
1212

1313
namespace Python.Runtime
1414
{
15-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
15+
[StructLayout(LayoutKind.Sequential)]
1616
internal class TypeOffset
1717
{
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-
3418
// Auto-generated from PyHeapTypeObject in Python.h
3519
public static int ob_refcnt = 0;
3620
public static int ob_type = 0;

src/runtime/interop38.cs

+2-18
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,9 @@
1313

1414
namespace Python.Runtime
1515
{
16-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
17-
internal class TypeOffset
16+
[StructLayout(LayoutKind.Sequential)]
17+
internal static partial class TypeOffset
1818
{
19-
static TypeOffset()
20-
{
21-
Type type = typeof(TypeOffset);
22-
FieldInfo[] fi = type.GetFields();
23-
int size = IntPtr.Size;
24-
for (int i = 0; i < fi.Length; i++)
25-
{
26-
fi[i].SetValue(null, i * size);
27-
}
28-
}
29-
30-
public static int magic()
31-
{
32-
return ob_size;
33-
}
34-
3519
// Auto-generated from PyHeapTypeObject in Python.h
3620
public static int ob_refcnt = 0;
3721
public static int ob_type = 0;

0 commit comments

Comments
 (0)