Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit67c6d11

Browse files
committed
detect the size of wchar_t (aka Runtime.UCS) at runtime using PyUnicode_GetMax
1 parent182faed commit67c6d11

File tree

6 files changed

+29
-62
lines changed

6 files changed

+29
-62
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

‎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

‎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
ifnotos.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-
importctypes
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
ifCONFIG=="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
<Python3VersionCondition="'$(Python3Version)'==''">PYTHON38</Python3Version>
5151
<PythonWinDefineConstants>$(PYTHONNET_WIN_DEFINE_CONSTANTS)</PythonWinDefineConstants>
52-
<PythonWinDefineConstantsCondition="'$(PythonWinDefineConstants)'==''">UCS2</PythonWinDefineConstants>
5352
<PythonMonoDefineConstants>$(PYTHONNET_MONO_DEFINE_CONSTANTS)</PythonMonoDefineConstants>
54-
<PythonMonoDefineConstantsCondition="'$(PythonMonoDefineConstants)'==''">UCS4;MONO_LINUX;PYTHON_WITH_PYMALLOC</PythonMonoDefineConstants>
53+
<PythonMonoDefineConstantsCondition="'$(PythonMonoDefineConstants)'==''">MONO_LINUX;PYTHON_WITH_PYMALLOC</PythonMonoDefineConstants>
5554
<PythonInteropFileCondition="'$(PythonInteropFile)'==''">$(PYTHONNET_INTEROP_FILE)</PythonInteropFile>
5655
</PropertyGroup>
5756
<PropertyGroupCondition="$(Configuration.Contains('Debug')) AND '$(TargetFramework)'=='net40'">
@@ -143,20 +142,20 @@
143142
<PackageReferenceInclude="Microsoft.SourceLink.GitHub"Version="1.0.0"PrivateAssets="All" />
144143
</ItemGroup>
145144

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

153152

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

162161
<ImportProject="Sdk.targets"Sdk="Microsoft.NET.Sdk" />

‎src/runtime/Python.Runtime.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,46 @@
2929
<PlatformTarget>x64</PlatformTarget>
3030
</PropertyGroup>-->
3131
<PropertyGroupCondition=" '$(Configuration)' == 'ReleaseMono'">
32-
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4</DefineConstants>
32+
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27</DefineConstants>
3333
<Optimize>true</Optimize>
3434
<DebugType>pdbonly</DebugType>
3535
</PropertyGroup>
3636
<PropertyGroupCondition=" '$(Configuration)' == 'ReleaseMonoPY3'">
37-
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS4</DefineConstants>
37+
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38</DefineConstants>
3838
<Optimize>true</Optimize>
3939
<DebugType>pdbonly</DebugType>
4040
</PropertyGroup>
4141
<PropertyGroupCondition=" '$(Configuration)' == 'DebugMono'">
4242
<DebugSymbols>true</DebugSymbols>
43-
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4;TRACE;DEBUG</DefineConstants>
43+
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;TRACE;DEBUG</DefineConstants>
4444
<Optimize>false</Optimize>
4545
<DebugType>full</DebugType>
4646
</PropertyGroup>
4747
<PropertyGroupCondition=" '$(Configuration)' == 'DebugMonoPY3'">
4848
<DebugSymbols>true</DebugSymbols>
49-
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS4;TRACE;DEBUG</DefineConstants>
49+
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;TRACE;DEBUG</DefineConstants>
5050
<Optimize>false</Optimize>
5151
<DebugType>full</DebugType>
5252
</PropertyGroup>
5353
<PropertyGroupCondition=" '$(Configuration)' == 'ReleaseWin'">
54-
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2</DefineConstants>
54+
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27</DefineConstants>
5555
<Optimize>true</Optimize>
5656
<DebugType>pdbonly</DebugType>
5757
</PropertyGroup>
5858
<PropertyGroupCondition=" '$(Configuration)' == 'ReleaseWinPY3'">
59-
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS2</DefineConstants>
59+
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38</DefineConstants>
6060
<Optimize>true</Optimize>
6161
<DebugType>pdbonly</DebugType>
6262
</PropertyGroup>
6363
<PropertyGroupCondition=" '$(Configuration)' == 'DebugWin'">
6464
<DebugSymbols>true</DebugSymbols>
65-
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2;TRACE;DEBUG</DefineConstants>
65+
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;TRACE;DEBUG</DefineConstants>
6666
<Optimize>false</Optimize>
6767
<DebugType>full</DebugType>
6868
</PropertyGroup>
6969
<PropertyGroupCondition=" '$(Configuration)' == 'DebugWinPY3'">
7070
<DebugSymbols>true</DebugSymbols>
71-
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS2;TRACE;DEBUG</DefineConstants>
71+
<DefineConstantsCondition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;TRACE;DEBUG</DefineConstants>
7272
<Optimize>false</Optimize>
7373
<DebugType>full</DebugType>
7474
</PropertyGroup>

‎src/runtime/runtime.cs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,8 @@ namespace Python.Runtime
1818
/// </summary>
1919
publicclassRuntime
2020
{
21-
// C# compiler copies constants to the assemblies that references this library.
22-
// We needs to replace all public constants to static readonly fields to allow
23-
// binary substitution of different Python.Runtime.dll builds in a target application.
24-
2521
publicstaticintUCS=>_UCS;
26-
27-
#ifUCS4
28-
internalconstint_UCS=4;
29-
30-
/// <summary>
31-
/// EntryPoint to be used in DllImport to map to correct Unicode
32-
/// methods prior to PEP393. Only used for PY27.
33-
/// </summary>
34-
privateconststringPyUnicodeEntryPoint="PyUnicodeUCS4_";
35-
#elifUCS2
36-
internalconstint_UCS=2;
37-
38-
/// <summary>
39-
/// EntryPoint to be used in DllImport to map to correct Unicode
40-
/// methods prior to PEP393. Only used for PY27.
41-
/// </summary>
42-
privateconststringPyUnicodeEntryPoint="PyUnicodeUCS2_";
43-
#else
44-
#error You must define either UCS2 or UCS4!
45-
#endif
22+
internalstaticreadonlyint_UCS=PyUnicode_GetMax()<=0xFFFF?2:4;
4623

4724
#ifPYTHON36
4825
conststring_minor="6";
@@ -1537,17 +1514,6 @@ internal static IntPtr PyBytes_AS_STRING(IntPtr ob)
15371514
return ob+ BytesOffset.ob_sval;
15381515
}
15391516

1540-
internalstatic IntPtr PyString_FromStringAndSize(string value,long size)
1541-
{
1542-
return _PyString_FromStringAndSize(value,new IntPtr(size));
1543-
}
1544-
1545-
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl,
1546-
EntryPoint= "PyUnicode_FromStringAndSize")]
1547-
internalstaticextern IntPtr _PyString_FromStringAndSize(
1548-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Utf8Marshaler))]string value,
1549-
IntPtr size
1550-
);
15511517

15521518
internalstatic IntPtr PyUnicode_FromStringAndSize(IntPtr value,long size)
15531519
{
@@ -1588,6 +1554,9 @@ internal static IntPtr PyUnicode_FromUnicode(string s, long size)
15881554
return PyUnicode_FromKindAndData(_UCS, s, size);
15891555
}
15901556

1557+
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
1558+
internalstaticexternint PyUnicode_GetMax();
1559+
15911560
internalstaticlong PyUnicode_GetSize(IntPtr ob)
15921561
{
15931562
return(long)_PyUnicode_GetSize(ob);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp