| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,10 @@ csharp_new_line_before_finally = true | |||
| 34 | 34 | [*.sln] | |
| 35 | 35 | indent_style = tab | |
| 36 | 36 | ||
| 37 | + [*.csproj] | ||
| 38 | + charset = utf-8 | ||
| 39 | + insert_final_newline = true | ||
| 40 | + | ||
| 37 | 41 | # bumpversion reformats itself after every bump | |
| 38 | 42 | [.bumpversion.cfg] | |
| 39 | 43 | trim_trailing_whitespace = false | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 13 | 13 | ||
| 14 | 14 | ### Changed | |
| 15 | 15 | - Drop support for Python 2, 3.4, and 3.5 | |
| 16 | + - `wchar_t` size aka `Runtime.UCS` is now determined at runtime | ||
| 16 | 17 | - `clr.AddReference` may now throw errors besides `FileNotFoundException`, that provide more | |
| 17 | 18 | details about the cause of the failure | |
| 18 | 19 | - `clr.AddReference` no longer adds ".dll" implicitly | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -251,14 +251,8 @@ def build_extension(self, ext): | |||
| 251 | 251 | if not os.path.exists(dest_dir): | |
| 252 | 252 | os.makedirs(dest_dir) | |
| 253 | 253 | ||
| 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 | - | ||
| 259 | 254 | defines = [ | |
| 260 | 255 | "PYTHON{0}{1}".format(PY_MAJOR, PY_MINOR), | |
| 261 | - "UCS{0}".format(unicode_width), | ||
| 262 | 256 | ] | |
| 263 | 257 | ||
| 264 | 258 | if CONFIG == "Debug": | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,9 +49,8 @@ | |||
| 49 | 49 | <Python3Version>$(PYTHONNET_PY3_VERSION)</Python3Version> | |
| 50 | 50 | <Python3Version Condition="'$(Python3Version)'==''">PYTHON38</Python3Version> | |
| 51 | 51 | <PythonWinDefineConstants>$(PYTHONNET_WIN_DEFINE_CONSTANTS)</PythonWinDefineConstants> | |
| 52 | - <PythonWinDefineConstants Condition="'$(PythonWinDefineConstants)'==''">UCS2</PythonWinDefineConstants> | ||
| 53 | 52 | <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> | ||
| 55 | 54 | <PythonInteropFile Condition="'$(PythonInteropFile)'==''">$(PYTHONNET_INTEROP_FILE)</PythonInteropFile> | |
| 56 | 55 | </PropertyGroup> | |
| 57 | 56 | <PropertyGroup Condition="$(Configuration.Contains('Debug')) AND '$(TargetFramework)'=='net40'"> | |
@@ -143,20 +142,20 @@ | |||
| 143 | 142 | <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" /> | |
| 144 | 143 | </ItemGroup> | |
| 145 | 144 | ||
| 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> | ||
| 151 | 150 | </ItemGroup> | |
| 152 | 151 | ||
| 153 | 152 | ||
| 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> | ||
| 160 | 159 | </ItemGroup> | |
| 161 | 160 | ||
| 162 | 161 | <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,46 +29,46 @@ | |||
| 29 | 29 | <PlatformTarget>x64</PlatformTarget> | |
| 30 | 30 | </PropertyGroup>--> | |
| 31 | 31 | <PropertyGroup Condition=" '$(Configuration)' == 'ReleaseMono'"> | |
| 32 | - <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4</DefineConstants> | ||
| 32 | + <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27</DefineConstants> | ||
| 33 | 33 | <Optimize>true</Optimize> | |
| 34 | 34 | <DebugType>pdbonly</DebugType> | |
| 35 | 35 | </PropertyGroup> | |
| 36 | 36 | <PropertyGroup Condition=" '$(Configuration)' == 'ReleaseMonoPY3'"> | |
| 37 | - <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS4</DefineConstants> | ||
| 37 | + <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38</DefineConstants> | ||
| 38 | 38 | <Optimize>true</Optimize> | |
| 39 | 39 | <DebugType>pdbonly</DebugType> | |
| 40 | 40 | </PropertyGroup> | |
| 41 | 41 | <PropertyGroup Condition=" '$(Configuration)' == 'DebugMono'"> | |
| 42 | 42 | <DebugSymbols>true</DebugSymbols> | |
| 43 | - <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4;TRACE;DEBUG</DefineConstants> | ||
| 43 | + <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;TRACE;DEBUG</DefineConstants> | ||
| 44 | 44 | <Optimize>false</Optimize> | |
| 45 | 45 | <DebugType>full</DebugType> | |
| 46 | 46 | </PropertyGroup> | |
| 47 | 47 | <PropertyGroup Condition=" '$(Configuration)' == 'DebugMonoPY3'"> | |
| 48 | 48 | <DebugSymbols>true</DebugSymbols> | |
| 49 | - <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS4;TRACE;DEBUG</DefineConstants> | ||
| 49 | + <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;TRACE;DEBUG</DefineConstants> | ||
| 50 | 50 | <Optimize>false</Optimize> | |
| 51 | 51 | <DebugType>full</DebugType> | |
| 52 | 52 | </PropertyGroup> | |
| 53 | 53 | <PropertyGroup Condition=" '$(Configuration)' == 'ReleaseWin'"> | |
| 54 | - <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2</DefineConstants> | ||
| 54 | + <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27</DefineConstants> | ||
| 55 | 55 | <Optimize>true</Optimize> | |
| 56 | 56 | <DebugType>pdbonly</DebugType> | |
| 57 | 57 | </PropertyGroup> | |
| 58 | 58 | <PropertyGroup Condition=" '$(Configuration)' == 'ReleaseWinPY3'"> | |
| 59 | - <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS2</DefineConstants> | ||
| 59 | + <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38</DefineConstants> | ||
| 60 | 60 | <Optimize>true</Optimize> | |
| 61 | 61 | <DebugType>pdbonly</DebugType> | |
| 62 | 62 | </PropertyGroup> | |
| 63 | 63 | <PropertyGroup Condition=" '$(Configuration)' == 'DebugWin'"> | |
| 64 | 64 | <DebugSymbols>true</DebugSymbols> | |
| 65 | - <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2;TRACE;DEBUG</DefineConstants> | ||
| 65 | + <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;TRACE;DEBUG</DefineConstants> | ||
| 66 | 66 | <Optimize>false</Optimize> | |
| 67 | 67 | <DebugType>full</DebugType> | |
| 68 | 68 | </PropertyGroup> | |
| 69 | 69 | <PropertyGroup Condition=" '$(Configuration)' == 'DebugWinPY3'"> | |
| 70 | 70 | <DebugSymbols>true</DebugSymbols> | |
| 71 | - <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS2;TRACE;DEBUG</DefineConstants> | ||
| 71 | + <DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;TRACE;DEBUG</DefineConstants> | ||
| 72 | 72 | <Optimize>false</Optimize> | |
| 73 | 73 | <DebugType>full</DebugType> | |
| 74 | 74 | </PropertyGroup> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,31 +18,8 @@ namespace Python.Runtime | |||
| 18 | 18 | /// </summary> | |
| 19 | 19 | public class Runtime | |
| 20 | 20 | { | |
| 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 | - | ||
| 25 | 21 | public static int UCS => _UCS; | |
| 26 | - | ||
| 27 | - #if UCS4 | ||
| 28 | - internal const int _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 | - private const string PyUnicodeEntryPoint = "PyUnicodeUCS4_"; | ||
| 35 | - #elif UCS2 | ||
| 36 | - internal const int _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 | - private const string PyUnicodeEntryPoint = "PyUnicodeUCS2_"; | ||
| 43 | - #else | ||
| 44 | - #error You must define either UCS2 or UCS4! | ||
| 45 | - #endif | ||
| 22 | + internal static readonly int _UCS = PyUnicode_GetMax() <= 0xFFFF ? 2 : 4; | ||
| 46 | 23 | ||
| 47 | 24 | #if PYTHON36 | |
| 48 | 25 | const string _minor = "6"; | |
@@ -1537,17 +1514,6 @@ internal static IntPtr PyBytes_AS_STRING(IntPtr ob) | |||
| 1537 | 1514 | return ob + BytesOffset.ob_sval; | |
| 1538 | 1515 | } | |
| 1539 | 1516 | ||
| 1540 | - internal static 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 | - internal static extern IntPtr _PyString_FromStringAndSize( | ||
| 1548 | - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value, | ||
| 1549 | - IntPtr size | ||
| 1550 | - ); | ||
| 1551 | 1517 | ||
| 1552 | 1518 | internal static IntPtr PyUnicode_FromStringAndSize(IntPtr value, long size) | |
| 1553 | 1519 | { | |
@@ -1588,6 +1554,9 @@ internal static IntPtr PyUnicode_FromUnicode(string s, long size) | |||
| 1588 | 1554 | return PyUnicode_FromKindAndData(_UCS, s, size); | |
| 1589 | 1555 | } | |
| 1590 | 1556 | ||
| 1557 | + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | ||
| 1558 | + internal static extern int PyUnicode_GetMax(); | ||
| 1559 | + | ||
| 1591 | 1560 | internal static long PyUnicode_GetSize(IntPtr ob) | |
| 1592 | 1561 | { | |
| 1593 | 1562 | return (long)_PyUnicode_GetSize(ob); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments