Skip to content

Commit ceb3fab

Browse files
authored
Merge branch 'master' into domain-reload-test-cases-fixes
2 parents f97262b + ab97b02 commit ceb3fab

20 files changed

+841
-1020
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ csharp_new_line_before_finally = true
3434
[*.sln]
3535
indent_style = tab
3636

37+
[*.csproj]
38+
charset = utf-8
39+
insert_final_newline = true
40+
3741
# bumpversion reformats itself after every bump
3842
[.bumpversion.cfg]
3943
trim_trailing_whitespace = false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/src/runtime/interopNative.cs
2+
13
# General binaries and Build results
24
*.dll
35
*.exe

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1313

1414
### Changed
1515
- Drop support for Python 2, 3.4, and 3.5
16+
- `wchar_t` size aka `Runtime.UCS` is now determined at runtime
1617
- `clr.AddReference` may now throw errors besides `FileNotFoundException`, that provide more
1718
details about the cause of the failure
1819
- `clr.AddReference` no longer adds ".dll" implicitly

pythonnet.15.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "conda.recipe", "conda.recip
4444
conda.recipe\README.md = conda.recipe\README.md
4545
EndProjectSection
4646
EndProject
47+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{BC426F42-8494-4AA5-82C9-5109ACD97BD1}"
48+
ProjectSection(SolutionItems) = preProject
49+
tools\geninterop\geninterop.py = tools\geninterop\geninterop.py
50+
EndProjectSection
51+
EndProject
4752
Global
4853
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4954
Debug|Any CPU = Debug|Any CPU

setup.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,8 @@ def build_extension(self, ext):
251251
if not os.path.exists(dest_dir):
252252
os.makedirs(dest_dir)
253253

254-
# Up to Python 3.2 sys.maxunicode is used to determine the size of
255-
# Py_UNICODE, but from 3.3 onwards Py_UNICODE is a typedef of wchar_t.
256-
import ctypes
257-
unicode_width = ctypes.sizeof(ctypes.c_wchar)
258-
259254
defines = [
260255
"PYTHON{0}{1}".format(PY_MAJOR, PY_MINOR),
261-
"UCS{0}".format(unicode_width),
262256
]
263257

264258
if CONFIG == "Debug":

src/runtime/Python.Runtime.15.csproj

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@
4949
<Python3Version>$(PYTHONNET_PY3_VERSION)</Python3Version>
5050
<Python3Version Condition="'$(Python3Version)'==''">PYTHON38</Python3Version>
5151
<PythonWinDefineConstants>$(PYTHONNET_WIN_DEFINE_CONSTANTS)</PythonWinDefineConstants>
52-
<PythonWinDefineConstants Condition="'$(PythonWinDefineConstants)'==''">UCS2</PythonWinDefineConstants>
5352
<PythonMonoDefineConstants>$(PYTHONNET_MONO_DEFINE_CONSTANTS)</PythonMonoDefineConstants>
54-
<PythonMonoDefineConstants Condition="'$(PythonMonoDefineConstants)'==''">UCS4;MONO_LINUX;PYTHON_WITH_PYMALLOC</PythonMonoDefineConstants>
53+
<PythonMonoDefineConstants Condition="'$(PythonMonoDefineConstants)'==''">MONO_LINUX;PYTHON_WITH_PYMALLOC</PythonMonoDefineConstants>
5554
<PythonInteropFile Condition="'$(PythonInteropFile)'==''">$(PYTHONNET_INTEROP_FILE)</PythonInteropFile>
5655
</PropertyGroup>
5756
<PropertyGroup Condition="$(Configuration.Contains('Debug')) AND '$(TargetFramework)'=='net40'">
@@ -143,20 +142,20 @@
143142
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
144143
</ItemGroup>
145144

146-
<ItemGroup>
147-
<None Update="intern_.tt">
148-
<Generator>TextTemplatingFileGenerator</Generator>
149-
<LastGenOutput>intern_.cs</LastGenOutput>
150-
</None>
145+
<ItemGroup>
146+
<None Update="intern_.tt">
147+
<Generator>TextTemplatingFileGenerator</Generator>
148+
<LastGenOutput>intern_.cs</LastGenOutput>
149+
</None>
151150
</ItemGroup>
152151

153152

154-
<ItemGroup>
155-
<Compile Update="intern_.cs">
156-
<DesignTime>True</DesignTime>
157-
<AutoGen>True</AutoGen>
158-
<DependentUpon>intern_.tt</DependentUpon>
159-
</Compile>
153+
<ItemGroup>
154+
<Compile Update="intern_.cs">
155+
<DesignTime>True</DesignTime>
156+
<AutoGen>True</AutoGen>
157+
<DependentUpon>intern_.tt</DependentUpon>
158+
</Compile>
160159
</ItemGroup>
161160

162161
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

src/runtime/Python.Runtime.csproj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,46 @@
2929
<PlatformTarget>x64</PlatformTarget>
3030
</PropertyGroup>-->
3131
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseMono'">
32-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4</DefineConstants>
32+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27</DefineConstants>
3333
<Optimize>true</Optimize>
3434
<DebugType>pdbonly</DebugType>
3535
</PropertyGroup>
3636
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseMonoPY3'">
37-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS4</DefineConstants>
37+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38</DefineConstants>
3838
<Optimize>true</Optimize>
3939
<DebugType>pdbonly</DebugType>
4040
</PropertyGroup>
4141
<PropertyGroup Condition=" '$(Configuration)' == 'DebugMono'">
4242
<DebugSymbols>true</DebugSymbols>
43-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4;TRACE;DEBUG</DefineConstants>
43+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;TRACE;DEBUG</DefineConstants>
4444
<Optimize>false</Optimize>
4545
<DebugType>full</DebugType>
4646
</PropertyGroup>
4747
<PropertyGroup Condition=" '$(Configuration)' == 'DebugMonoPY3'">
4848
<DebugSymbols>true</DebugSymbols>
49-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS4;TRACE;DEBUG</DefineConstants>
49+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;TRACE;DEBUG</DefineConstants>
5050
<Optimize>false</Optimize>
5151
<DebugType>full</DebugType>
5252
</PropertyGroup>
5353
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseWin'">
54-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2</DefineConstants>
54+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27</DefineConstants>
5555
<Optimize>true</Optimize>
5656
<DebugType>pdbonly</DebugType>
5757
</PropertyGroup>
5858
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseWinPY3'">
59-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS2</DefineConstants>
59+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38</DefineConstants>
6060
<Optimize>true</Optimize>
6161
<DebugType>pdbonly</DebugType>
6262
</PropertyGroup>
6363
<PropertyGroup Condition=" '$(Configuration)' == 'DebugWin'">
6464
<DebugSymbols>true</DebugSymbols>
65-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2;TRACE;DEBUG</DefineConstants>
65+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;TRACE;DEBUG</DefineConstants>
6666
<Optimize>false</Optimize>
6767
<DebugType>full</DebugType>
6868
</PropertyGroup>
6969
<PropertyGroup Condition=" '$(Configuration)' == 'DebugWinPY3'">
7070
<DebugSymbols>true</DebugSymbols>
71-
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS2;TRACE;DEBUG</DefineConstants>
71+
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;TRACE;DEBUG</DefineConstants>
7272
<Optimize>false</Optimize>
7373
<DebugType>full</DebugType>
7474
</PropertyGroup>
@@ -80,6 +80,10 @@
8080
<Compile Include="Codecs\DecoderGroup.cs" />
8181
<Compile Include="Codecs\RawProxyEncoder.cs" />
8282
<Compile Include="Codecs\TupleCodecs.cs" />
83+
<Compile Include="native\ABI.cs" />
84+
<Compile Include="native\GeneratedTypeOffsets.cs" />
85+
<Compile Include="native\ITypeOffsets.cs" />
86+
<Compile Include="native\TypeOffset.cs" />
8387
<Compile Include="converterextensions.cs" />
8488
<Compile Include="finalizer.cs" />
8589
<Compile Include="intern.cs" />

src/runtime/debughelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ internal static void DumpType(IntPtr type)
6060
//DebugUtil.Print(" mro: ", op);
6161

6262

63-
FieldInfo[] slots = typeof(TypeOffset).GetFields();
63+
var slots = TypeOffset.GetOffsets();
6464
int size = IntPtr.Size;
6565

66-
for (var i = 0; i < slots.Length; i++)
66+
foreach (var entry in slots)
6767
{
68-
int offset = i * size;
69-
name = slots[i].Name;
68+
int offset = entry.Value;
69+
name = entry.Key;
7070
op = Marshal.ReadIntPtr(type, offset);
7171
Console.WriteLine(" {0}: {1}", name, op);
7272
}

src/runtime/interop.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,12 @@ public ModulePropertyAttribute()
7070

7171
internal static partial class TypeOffset
7272
{
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-
8673
public static int magic() => ManagedDataOffsets.Magic;
8774
}
8875

8976
internal static class ManagedDataOffsets
9077
{
91-
public static int Magic { get; private set; }
78+
public static int Magic { get; internal set; }
9279
public static readonly Dictionary<string, int> NameMapping = new Dictionary<string, int>();
9380

9481
static class DataOffsets
@@ -108,13 +95,7 @@ static DataOffsets()
10895

10996
static ManagedDataOffsets()
11097
{
111-
Type type = typeof(TypeOffset);
112-
foreach (FieldInfo fi in type.GetFields())
113-
{
114-
NameMapping[fi.Name] = (int)fi.GetValue(null);
115-
}
116-
// XXX: Use the members after PyHeapTypeObject as magic slot
117-
Magic = TypeOffset.members;
98+
NameMapping = TypeOffset.GetOffsets();
11899

119100
FieldInfo[] fields = typeof(DataOffsets).GetFields(BindingFlags.Static | BindingFlags.Public);
120101
size = fields.Length * IntPtr.Size;

0 commit comments

Comments
 (0)