Skip to content

Commit ab6ddbc

Browse files
committed
Assembly path hardcore removed, files reformated, namespace changed for Python.Runtime.Interop project.
1 parent 1ea3773 commit ab6ddbc

17 files changed

+475
-362
lines changed
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
1-
using System;
2-
3-
namespace Python.Runtime
1+
namespace Python.Runtime.Interop
42
{
3+
using System;
54
using System.Reflection;
65
using System.Runtime.InteropServices;
76

7+
using JetBrains.Annotations;
8+
89
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
910
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
11+
[NoReorder]
1012
internal class BytesOffset
1113
{
1214
static BytesOffset()
1315
{
14-
Type type = typeof(BytesOffset);
15-
FieldInfo[] fi = type.GetFields();
16-
int size = IntPtr.Size;
17-
for (int i = 0; i < fi.Length; i++)
16+
var type = typeof(BytesOffset);
17+
var fi = type.GetFields();
18+
var size = IntPtr.Size;
19+
for (var i = 0; i < fi.Length; i++)
1820
{
1921
fi[i].SetValue(null, i * size);
2022
}
2123
}
2224

2325
/* The *real* layout of a type object when allocated on the heap */
2426
//typedef struct _heaptypeobject {
25-
#if (Py_DEBUG) // #ifdef Py_TRACE_REFS
27+
#if (Py_DEBUG) // #ifdef Py_TRACE_REFS
2628
/* _PyObject_HEAD_EXTRA defines pointers to support a doubly-linked list of all live heap objects. */
2729
public static int _ob_next = 0;
2830
public static int _ob_prev = 0;
2931
#endif
3032
// PyObject_VAR_HEAD {
3133
// PyObject_HEAD {
3234
public static int ob_refcnt = 0;
35+
3336
public static int ob_type = 0;
37+
3438
// }
35-
public static int ob_size = 0; /* Number of items in _VAR_iable part */
39+
public static int ob_size = 0; /* Number of items in _VAR_iable part */
40+
3641
// }
3742
public static int ob_shash = 0;
43+
3844
public static int ob_sval = 0; /* start of data */
3945

4046
/* Invariants:
@@ -45,4 +51,4 @@ static BytesOffset()
4551
//} PyBytesObject;
4652
}
4753
#endif
48-
}
54+
}
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
using System;
2-
3-
namespace Python.Runtime.Interop
1+
namespace Python.Runtime.Interop
42
{
3+
using System;
54
using System.Reflection;
65
using System.Runtime.InteropServices;
76

7+
using JetBrains.Annotations;
8+
89
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
10+
[NoReorder]
911
internal class ExceptionOffset
1012
{
1113
static ExceptionOffset()
1214
{
13-
Type type = typeof(ExceptionOffset);
14-
FieldInfo[] fi = type.GetFields();
15-
int size = IntPtr.Size;
16-
for (int i = 0; i < fi.Length; i++)
15+
var type = typeof(ExceptionOffset);
16+
var fi = type.GetFields();
17+
var size = IntPtr.Size;
18+
for (var i = 0; i < fi.Length; i++)
1719
{
1820
fi[i].SetValue(null, (i * size) + ObjectOffset.ob_type + size);
1921
}
@@ -22,20 +24,26 @@ static ExceptionOffset()
2224
// PyException_HEAD
2325
// (start after PyObject_HEAD)
2426
public static int dict = 0;
27+
2528
public static int args = 0;
29+
2630
#if (PYTHON25 || PYTHON26 || PYTHON27)
2731
public static int message = 0;
2832
#elif (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
2933
public static int traceback = 0;
34+
3035
public static int context = 0;
36+
3137
public static int cause = 0;
38+
3239
#if !PYTHON32
3340
public static int suppress_context = 0;
3441
#endif
3542
#endif
3643

3744
// extra c# data
3845
public static int ob_dict;
46+
3947
public static int ob_data;
4048
}
41-
}
49+
}

src/Python.Runtime.Interop/Python.Runtime.Interop.xproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
88
<PropertyGroup Label="Globals">
99
<ProjectGuid>7395d369-8aea-40f2-ad38-138b422fad3b</ProjectGuid>
10-
<RootNamespace>Python.Runtime</RootNamespace>
10+
<RootNamespace>Python.Runtime.Interop</RootNamespace>
1111
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
1212
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
1313
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

src/Python.Runtime.Interop/PythonInterop.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
namespace Python.Runtime
1+
namespace Python.Runtime.Interop
22
{
3-
using System;
43
using System.Linq;
54
using System.Reflection;
65
using System.Runtime.InteropServices;
76

8-
using Python.Runtime.InteropContracts;
7+
using InteropContracts;
98

109
public class PythonInterop : IPythonInterop
1110
{
@@ -39,19 +38,24 @@ public bool IsPyDebug
3938
}
4039
}
4140

41+
public void InitExceptionOffset()
42+
{
43+
CopyStaticFields<ExceptionOffset, Python.Runtime.ExceptionOffset>();
44+
}
45+
4246
public void InitTypeOffset()
4347
{
44-
CopyStaticFields<Interop.TypeOffset, TypeOffset>();
48+
CopyStaticFields<TypeOffset, Python.Runtime.TypeOffset>();
4549
}
4650

4751
private void CopyStaticFields<TFrom, TTo>()
4852
{
49-
Type type = typeof(TFrom);
53+
var type = typeof(TFrom);
5054
var actualValues = type.GetFields().ToDictionary(x => x.Name);
5155

52-
Type targetType = typeof(TTo);
56+
var targetType = typeof(TTo);
5357
var targetFields = targetType.GetFields();
54-
for (int i = 0; i < targetFields.Length; i++)
58+
for (var i = 0; i < targetFields.Length; i++)
5559
{
5660
FieldInfo actualField;
5761
if (actualValues.TryGetValue(targetFields[i].Name, out actualField))
@@ -60,10 +64,5 @@ private void CopyStaticFields<TFrom, TTo>()
6064
}
6165
}
6266
}
63-
64-
public void InitExceptionOffset()
65-
{
66-
CopyStaticFields<Interop.ExceptionOffset, ExceptionOffset>();
67-
}
6867
}
6968
}

src/Python.Runtime.Interop/PythonNativeMethodsInterop.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using System;
2-
3-
namespace Python.Runtime
1+
namespace Python.Runtime.Interop
42
{
3+
using System;
54
using System.Runtime.InteropServices;
65

76
using InteropContracts;
8-
public class PythonNativeMethodsInterop: IPythonNativeMethodsInterop
7+
8+
public class PythonNativeMethodsInterop : IPythonNativeMethodsInterop
99
{
1010
#if (MONO_LINUX || MONO_OSX)
1111
static public IntPtr LoadLibrary(string fileName) {
@@ -106,7 +106,5 @@ bool IPythonNativeMethodsInterop.FreeLibrary(IntPtr hModule)
106106
return FreeLibrary(hModule);
107107
}
108108
#endif
109-
110-
111109
}
112-
}
110+
}

0 commit comments

Comments
 (0)