diff --git a/.editorconfig b/.editorconfig
index d64f74bc1..2261004d2 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -25,10 +25,11 @@ dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = true
[*.cs]
-csharp_new_line_before_open_brace = all
-csharp_new_line_before_else = true
-csharp_new_line_before_catch = true
-csharp_new_line_before_finally = true
+csharp_new_line_before_open_brace = all:suggestion
+csharp_new_line_before_else = true:suggestion
+csharp_new_line_before_catch = true:suggestion
+csharp_new_line_before_finally = true:suggesion
+csharp_prefer_braces = true:suggestion
# Solution
[*.sln]
diff --git a/.github/workflows/build+test.yml b/.github/workflows/build+test.yml
new file mode 100644
index 000000000..c1c5dbef3
--- /dev/null
+++ b/.github/workflows/build+test.yml
@@ -0,0 +1,32 @@
+name: Build + Test
+
+on:
+ push:
+ branches:
+ - losttech/master
+ pull_request:
+ branches:
+ - losttech/master
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ python-version: [3.5, 3.7]
+ steps:
+ - uses: actions/checkout@v2
+ - name: Setup .NET Core
+ uses: actions/setup-dotnet@v1
+ with:
+ dotnet-version: 3.1.101
+ - name: Set up Python ${{ matrix.python-version }}
+ uses: actions/setup-python@v1
+ with:
+ python-version: ${{ matrix.python-version }}
+ - name: Build
+ run: dotnet build src/runtime/Python.Runtime.15.csproj --configuration Release
+ - name: Test
+ run: dotnet test src/embed_tests/Python.EmbeddingTest.15.csproj --configuration Release
+ env:
+ PYTHON_VERSION: ${{ matrix.python-version }}
diff --git a/AUTHORS.md b/AUTHORS.md
index 5dbf1e1ce..3b9d5534b 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -71,6 +71,8 @@
- ([@OneBlue](https://github.com/OneBlue))
- ([@rico-chet](https://github.com/rico-chet))
- ([@rmadsen-ks](https://github.com/rmadsen-ks))
+- ([@SnGmng](https://github.com/SnGmng))
- ([@stonebig](https://github.com/stonebig))
- ([@testrunner123](https://github.com/testrunner123))
+- ([@DanBarzilian](https://github.com/DanBarzilian))
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad4016450..afb2badbd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
### Fixed
+- Fix incorrect dereference of wrapper object in tp_repr, which may result in a program crash
+
## [2.5.0][] - 2020-06-14
This version improves performance on benchmarks significantly compared to 2.3.
diff --git a/LICENSE b/LICENSE
index 19c31a12f..788160102 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,21 +1,9 @@
-MIT License
+You must have a license for LostTech.TensorFlow
+(see https://losttech.software/gradient.html) to use this software.
-Copyright (c) 2006-2020 the contributors of the Python.NET project
+If you wish to obtain a version of this sofware with a more liberal
+license, refer to https://github.com/pythonnet/pythonnet.
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-DEALINGS IN THE SOFTWARE.
+This fork contains substantial parts of the original project, which are
+distributed under MIT License:
+https://github.com/pythonnet/pythonnet/blob/master/LICENSE
diff --git a/NuGet.config b/NuGet.config
index 5210cd6c9..ed9d41057 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -1,7 +1,6 @@
-
\ No newline at end of file
diff --git a/README.rst b/README.rst
index 55f0e50a1..e8a55f95e 100644
--- a/README.rst
+++ b/README.rst
@@ -3,12 +3,15 @@ pythonnet - Python.NET
|Join the chat at https://gitter.im/pythonnet/pythonnet|
-|appveyor shield| |travis shield| |codecov shield|
+|github test shield|
-|license shield| |pypi package version| |conda-forge version| |python supported shield|
+|nuget version|
|stackexchange shield|
-Python.NET is a package that gives Python programmers nearly
+This fork is part of `Gradient `_ and has a `different
+license `_.
+
+Python for .NET is a package that gives Python programmers nearly
seamless integration with the .NET Common Language Runtime (CLR) and
provides a powerful application scripting tool for .NET developers. It
allows Python code to interact with the CLR, and may also be used to
@@ -126,3 +129,6 @@ This project is supported by the `.NET Foundation
:target: http://stackoverflow.com/questions/tagged/python.net
.. |conda-forge version| image:: https://img.shields.io/conda/vn/conda-forge/pythonnet.svg
:target: https://anaconda.org/conda-forge/pythonnet
+.. |github test shield| image:: https://github.com/losttech/pythonnet/workflows/Build%20%2B%20Test/badge.svg
+.. |nuget version| image:: https://img.shields.io/nuget/vpre/LostTech.Python.Runtime
+ :target: https://www.nuget.org/packages/LostTech.Python.Runtime/
diff --git a/global.json b/global.json
new file mode 100644
index 000000000..73fa45c8d
--- /dev/null
+++ b/global.json
@@ -0,0 +1,5 @@
+{
+ "msbuild-sdks": {
+ "MSBuild.Sdk.Extras": "1.6.65"
+ }
+}
diff --git a/pythonnet.15.sln b/pythonnet.15.sln
index ce863817f..82b70fb09 100644
--- a/pythonnet.15.sln
+++ b/pythonnet.15.sln
@@ -19,7 +19,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Repo", "Repo", "{441A0123-F
.editorconfig = .editorconfig
.gitignore = .gitignore
CHANGELOG.md = CHANGELOG.md
+ LICENSE = LICENSE
README.rst = README.rst
+ src\SharedAssemblyInfo.cs = src\SharedAssemblyInfo.cs
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{D301657F-5EAF-4534-B280-B858D651B2E5}"
@@ -28,6 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{D301657F-5EAF-
appveyor.yml = appveyor.yml
ci\appveyor_build_recipe.ps1 = ci\appveyor_build_recipe.ps1
ci\appveyor_run_tests.ps1 = ci\appveyor_run_tests.ps1
+ .github\workflows\build+test.yml = .github\workflows\build+test.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{57F5D701-F265-4736-A5A2-07249E7A4DA3}"
@@ -45,349 +48,33 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
- Debug|x64 = Debug|x64
- Debug|x86 = Debug|x86
- DebugMono|Any CPU = DebugMono|Any CPU
- DebugMono|x64 = DebugMono|x64
- DebugMono|x86 = DebugMono|x86
- DebugMonoPY3|Any CPU = DebugMonoPY3|Any CPU
- DebugMonoPY3|x64 = DebugMonoPY3|x64
- DebugMonoPY3|x86 = DebugMonoPY3|x86
- DebugWin|Any CPU = DebugWin|Any CPU
- DebugWin|x64 = DebugWin|x64
- DebugWin|x86 = DebugWin|x86
- DebugWinPY3|Any CPU = DebugWinPY3|Any CPU
- DebugWinPY3|x64 = DebugWinPY3|x64
- DebugWinPY3|x86 = DebugWinPY3|x86
Release|Any CPU = Release|Any CPU
- Release|x64 = Release|x64
- Release|x86 = Release|x86
- ReleaseMono|Any CPU = ReleaseMono|Any CPU
- ReleaseMono|x64 = ReleaseMono|x64
- ReleaseMono|x86 = ReleaseMono|x86
- ReleaseMonoPY3|Any CPU = ReleaseMonoPY3|Any CPU
- ReleaseMonoPY3|x64 = ReleaseMonoPY3|x64
- ReleaseMonoPY3|x86 = ReleaseMonoPY3|x86
- ReleaseWin|Any CPU = ReleaseWin|Any CPU
- ReleaseWin|x64 = ReleaseWin|x64
- ReleaseWin|x86 = ReleaseWin|x86
- ReleaseWinPY3|Any CPU = ReleaseWinPY3|Any CPU
- ReleaseWinPY3|x64 = ReleaseWinPY3|x64
- ReleaseWinPY3|x86 = ReleaseWinPY3|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|Any CPU.ActiveCfg = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|Any CPU.Build.0 = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x64.ActiveCfg = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x64.Build.0 = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x86.ActiveCfg = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x86.Build.0 = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|Any CPU.ActiveCfg = DebugMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|Any CPU.Build.0 = DebugMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|x64.ActiveCfg = DebugMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|x64.Build.0 = DebugMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|x86.ActiveCfg = DebugMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|x86.Build.0 = DebugMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|Any CPU.Build.0 = DebugMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|Any CPU.ActiveCfg = DebugWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|Any CPU.Build.0 = DebugWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|x64.ActiveCfg = DebugWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|x64.Build.0 = DebugWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|x86.ActiveCfg = DebugWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|x86.Build.0 = DebugWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|Any CPU.Build.0 = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|x64.Build.0 = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|x86.Build.0 = DebugWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|Any CPU.Build.0 = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x64.ActiveCfg = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x64.Build.0 = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x86.ActiveCfg = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x86.Build.0 = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|Any CPU.Build.0 = ReleaseMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|x64.ActiveCfg = ReleaseMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|x64.Build.0 = ReleaseMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|x86.ActiveCfg = ReleaseMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|x86.Build.0 = ReleaseMono|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|Any CPU.Build.0 = ReleaseMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|Any CPU.Build.0 = ReleaseWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|x64.ActiveCfg = ReleaseWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|x64.Build.0 = ReleaseWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|x86.ActiveCfg = ReleaseWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|x86.Build.0 = ReleaseWin|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|Any CPU.Build.0 = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|Any CPU
- {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|Any CPU
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|Any CPU.Build.0 = ReleaseWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x64.ActiveCfg = DebugWinPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x64.Build.0 = DebugWinPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x86.ActiveCfg = DebugWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x86.Build.0 = DebugWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|x64.Build.0 = DebugMono|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|x86.Build.0 = DebugMono|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|x64.Build.0 = DebugWin|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|x86.Build.0 = DebugWin|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|Any CPU.Build.0 = ReleaseWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x64.ActiveCfg = ReleaseWinPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x64.Build.0 = ReleaseWinPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x86.ActiveCfg = ReleaseWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x86.Build.0 = ReleaseWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|Any CPU.Build.0 = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x64.ActiveCfg = DebugWinPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x64.Build.0 = DebugWinPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x86.ActiveCfg = DebugWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x86.Build.0 = DebugWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|x64.Build.0 = DebugWin|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|x86.Build.0 = DebugWin|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|Any CPU.Build.0 = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x64.ActiveCfg = ReleaseWinPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x64.Build.0 = ReleaseWinPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x86.ActiveCfg = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x86.Build.0 = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|Any CPU.Build.0 = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x64.ActiveCfg = DebugWinPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x64.Build.0 = DebugWinPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x86.ActiveCfg = DebugWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x86.Build.0 = DebugWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|x64.Build.0 = DebugMono|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|x86.Build.0 = DebugMono|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|x64.Build.0 = DebugWin|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|x86.Build.0 = DebugWin|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|Any CPU.Build.0 = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x64.ActiveCfg = ReleaseWinPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x64.Build.0 = ReleaseWinPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x86.ActiveCfg = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x86.Build.0 = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|Any CPU.Build.0 = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x64.ActiveCfg = DebugWinPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x64.Build.0 = DebugWinPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x86.ActiveCfg = DebugWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x86.Build.0 = DebugWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|x64.Build.0 = DebugMono|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|x86.Build.0 = DebugMono|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|x64.Build.0 = DebugWin|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|x86.Build.0 = DebugWin|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|Any CPU.Build.0 = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x64.ActiveCfg = ReleaseWinPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x64.Build.0 = ReleaseWinPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x86.ActiveCfg = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x86.Build.0 = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|Any CPU.ActiveCfg = ReleaseWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|Any CPU.Build.0 = ReleaseWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|x64.ActiveCfg = DebugWinPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|x64.Build.0 = DebugWinPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|x86.ActiveCfg = DebugWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|x86.Build.0 = DebugWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMono|x64.Build.0 = DebugMono|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMono|x86.Build.0 = DebugMono|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|x64.Build.0 = DebugWin|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|x86.Build.0 = DebugWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|Any CPU.ActiveCfg = ReleaseWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|Any CPU.Build.0 = ReleaseWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|x64.ActiveCfg = ReleaseWinPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|x64.Build.0 = ReleaseWinPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|x86.ActiveCfg = ReleaseWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|x86.Build.0 = ReleaseWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
+ {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|Any CPU.ActiveCfg = Debug|x64
+ {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|Any CPU.Build.0 = Debug|x64
+ {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|Any CPU.ActiveCfg = Release|x64
+ {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|Any CPU.Build.0 = Release|x64
+ {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|Any CPU.Build.0 = Debug|x86
+ {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|Any CPU.ActiveCfg = Release|x86
+ {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|Any CPU.Build.0 = Release|x86
+ {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|Any CPU.Build.0 = Debug|x86
+ {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|Any CPU.ActiveCfg = Release|x86
+ {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|Any CPU.Build.0 = Release|x86
+ {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|Any CPU.Build.0 = Debug|x86
+ {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|Any CPU.ActiveCfg = Release|x86
+ {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|Any CPU.Build.0 = Release|x86
+ {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|Any CPU.ActiveCfg = DebugWin|x86
+ {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|Any CPU.Build.0 = DebugWin|x86
+ {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|Any CPU.ActiveCfg = DebugWin|x86
+ {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|Any CPU.Build.0 = DebugWin|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/pythonnet.sln b/pythonnet.sln
deleted file mode 100644
index c5afd66c3..000000000
--- a/pythonnet.sln
+++ /dev/null
@@ -1,202 +0,0 @@
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Runtime", "src\runtime\Python.Runtime.csproj", "{097B4AC0-74E9-4C58-BCF8-C69746EC8271}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Test", "src\testing\Python.Test.csproj", "{6F401A34-273B-450F-9A4C-13550BE0767B}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.EmbeddingTest", "src\embed_tests\Python.EmbeddingTest.csproj", "{4165C59D-2822-499F-A6DB-EACA4C331EB5}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "src\console\Console.csproj", "{E29DCF0A-5114-4A98-B1DD-71264B6EA349}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "clrmodule", "src\clrmodule\clrmodule.csproj", "{86E834DE-1139-4511-96CC-69636A56E7AC}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- DebugMono|x64 = DebugMono|x64
- DebugMono|x86 = DebugMono|x86
- DebugMonoPY3|x64 = DebugMonoPY3|x64
- DebugMonoPY3|x86 = DebugMonoPY3|x86
- DebugWin|x64 = DebugWin|x64
- DebugWin|x86 = DebugWin|x86
- DebugWinPY3|x64 = DebugWinPY3|x64
- DebugWinPY3|x86 = DebugWinPY3|x86
- ReleaseMono|x64 = ReleaseMono|x64
- ReleaseMono|x86 = ReleaseMono|x86
- ReleaseMonoPY3|x64 = ReleaseMonoPY3|x64
- ReleaseMonoPY3|x86 = ReleaseMonoPY3|x86
- ReleaseWin|x64 = ReleaseWin|x64
- ReleaseWin|x86 = ReleaseWin|x86
- ReleaseWinPY3|x64 = ReleaseWinPY3|x64
- ReleaseWinPY3|x86 = ReleaseWinPY3|x86
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMono|x64.Build.0 = DebugMono|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMono|x86.Build.0 = DebugMono|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWin|x64.Build.0 = DebugWin|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWin|x86.Build.0 = DebugWin|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMono|x64.Build.0 = DebugMono|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMono|x86.Build.0 = DebugMono|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWin|x64.Build.0 = DebugWin|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWin|x86.Build.0 = DebugWin|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMono|x64.Build.0 = DebugMono|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMono|x86.Build.0 = DebugMono|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWin|x64.Build.0 = DebugWin|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWin|x86.Build.0 = DebugWin|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMono|x64.Build.0 = DebugMono|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMono|x86.Build.0 = DebugMono|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWin|x64.Build.0 = DebugWin|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWin|x86.Build.0 = DebugWin|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMono|x64.Build.0 = ReleaseMono|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMono|x86.Build.0 = ReleaseMono|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMono|x64.ActiveCfg = DebugMono|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMono|x86.ActiveCfg = DebugMono|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x64.ActiveCfg = DebugWin|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x64.Build.0 = DebugWin|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x86.ActiveCfg = DebugWin|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x86.Build.0 = DebugWin|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x64.Build.0 = ReleaseWin|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x86.Build.0 = ReleaseWin|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86
- {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(MonoDevelopProperties) = preSolution
- StartupItem = src\console\Console.csproj
- Policies = $0
- $0.VersionControlPolicy = $1
- $1.inheritsSet = Mono
- $0.ChangeLogPolicy = $2
- $2.UpdateMode = None
- $2.MessageStyle = $3
- $3.LineAlign = 0
- $2.inheritsSet = Mono
- EndGlobalSection
-EndGlobal
diff --git a/src/SharedAssemblyInfo.cs b/src/SharedAssemblyInfo.cs
index dd057b144..071360e55 100644
--- a/src/SharedAssemblyInfo.cs
+++ b/src/SharedAssemblyInfo.cs
@@ -7,9 +7,9 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("pythonnet")]
-[assembly: AssemblyProduct("Python.NET")]
-[assembly: AssemblyCopyright("Copyright (c) 2006-2020 the contributors of the Python.NET project")]
+[assembly: AssemblyCompany("Lost Tech LLC")]
+[assembly: AssemblyProduct("LostTech.Python.Runtime")]
+[assembly: AssemblyCopyright("Copyright (c) 2006-2020 Lost Tech and the contributors of the Python.NET project")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -25,4 +25,4 @@
// Version Information. Keeping it simple. May need to revisit for Nuget
// See: https://codingforsmarties.wordpress.com/2016/01/21/how-to-version-assemblies-destined-for-nuget/
// AssemblyVersion can only be numeric
-[assembly: AssemblyVersion("2.5.0")]
+[assembly: AssemblyVersion("3.0.0")]
diff --git a/src/clrmodule/ClrModule.cs b/src/clrmodule/ClrModule.cs
index 377be66d1..e0a0f67c8 100644
--- a/src/clrmodule/ClrModule.cs
+++ b/src/clrmodule/ClrModule.cs
@@ -28,15 +28,10 @@
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
-public class clrModule
+public static class clrModule
{
-#if PYTHON3
[DllExport("PyInit_clr", CallingConvention.StdCall)]
public static IntPtr PyInit_clr()
-#elif PYTHON2
- [DllExport("initclr", CallingConvention.StdCall)]
- public static void initclr()
-#endif
{
DebugPrint("Attempting to load 'Python.Runtime' using standard binding rules.");
#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN
@@ -95,11 +90,7 @@ public static void initclr()
catch (InvalidOperationException)
{
DebugPrint("Could not load 'Python.Runtime'.");
-#if PYTHON3
return IntPtr.Zero;
-#elif PYTHON2
- return;
-#endif
}
}
@@ -107,11 +98,7 @@ public static void initclr()
// So now we get the PythonEngine and execute the InitExt method on it.
Type pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine");
-#if PYTHON3
return (IntPtr)pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null);
-#elif PYTHON2
- pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null);
-#endif
}
///
diff --git a/src/clrmodule/clrmodule.15.csproj b/src/clrmodule/clrmodule.15.csproj
index 7fc9c2dda..5f80a1698 100644
--- a/src/clrmodule/clrmodule.15.csproj
+++ b/src/clrmodule/clrmodule.15.csproj
@@ -5,7 +5,6 @@
net40
x64;x86
- DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3
clrmodule
clrmodule
clrmodule
diff --git a/src/clrmodule/clrmodule.csproj b/src/clrmodule/clrmodule.csproj
deleted file mode 100644
index 6e5ff4966..000000000
--- a/src/clrmodule/clrmodule.csproj
+++ /dev/null
@@ -1,95 +0,0 @@
-
-
-
- Debug
- AnyCPU
- {86E834DE-1139-4511-96CC-69636A56E7AC}
- Library
- clrmodule
- clrmodule
- bin\clrmodule.xml
- bin\
- v4.0
-
- 1591
- ..\..\
- $(SolutionDir)\bin\
- Properties
- 6
- true
- prompt
-
-
- x86
-
-
- x64
-
-
- true
- PYTHON2;TRACE;DEBUG
- full
-
-
- PYTHON2
- true
- pdbonly
-
-
- true
- PYTHON2;TRACE;DEBUG
- full
-
-
- PYTHON2
- true
- pdbonly
-
-
- true
- PYTHON3;TRACE;DEBUG
- full
-
-
- PYTHON3
- true
- pdbonly
-
-
- true
- PYTHON3;TRACE;DEBUG
- full
-
-
- PYTHON3
- true
- pdbonly
-
-
-
- ..\..\packages\UnmanagedExports.1.2.7\lib\net\RGiesecke.DllExport.Metadata.dll
- False
-
-
-
-
-
-
- Properties\SharedAssemblyInfo.cs
-
-
-
-
-
-
-
-
- $(TargetPath)
- $(TargetDir)$(TargetName).pdb
-
-
-
-
-
-
-
diff --git a/src/console/Console.15.csproj b/src/console/Console.15.csproj
index 3c51caa31..4dcd1c32f 100644
--- a/src/console/Console.15.csproj
+++ b/src/console/Console.15.csproj
@@ -1,9 +1,8 @@
- net40;netcoreapp2.0
+ netcoreapp2.0
x64;x86
- DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3
Exe
nPython
Python.Runtime
diff --git a/src/console/Console.csproj b/src/console/Console.csproj
deleted file mode 100644
index ea88b6356..000000000
--- a/src/console/Console.csproj
+++ /dev/null
@@ -1,101 +0,0 @@
-
-
-
- Debug
- AnyCPU
- {E29DCF0A-5114-4A98-B1DD-71264B6EA349}
- Exe
- nPython
- Python.Runtime
- bin\nPython.xml
- bin\
- v4.0
-
- 1591
- ..\..\
- $(SolutionDir)\bin\
- Properties
- 6
- python-clear.ico
- prompt
-
-
- x86
-
-
- x64
-
-
- true
- DEBUG;TRACE
- full
-
-
-
-
- true
- pdbonly
-
-
- true
- DEBUG;TRACE
- full
-
-
-
-
- true
- pdbonly
-
-
- true
- DEBUG;TRACE
- full
-
-
-
-
- true
- pdbonly
-
-
- true
- DEBUG;TRACE
- full
-
-
-
-
- true
- pdbonly
-
-
- $(PythonManifest)
-
-
-
-
-
-
-
- Properties\SharedAssemblyInfo.cs
-
-
-
-
-
-
- Python.Runtime.dll
-
-
-
-
- {097b4ac0-74e9-4c58-bcf8-c69746ec8271}
- Python.Runtime
-
-
-
-
-
-
-
diff --git a/src/embed_tests/Arrays.cs b/src/embed_tests/Arrays.cs
new file mode 100644
index 000000000..f71a87f9c
--- /dev/null
+++ b/src/embed_tests/Arrays.cs
@@ -0,0 +1,32 @@
+namespace Python.EmbeddingTest {
+ using System;
+ using System.Linq;
+
+ using NUnit.Framework;
+
+ using Python.Runtime;
+
+ public class Arrays {
+ [Test]
+ public void Enumerate() {
+ var objArray = new[] { new Uri("http://a"), new Uri("http://b") };
+ using var scope = Py.CreateScope();
+ scope.Set("arr", objArray);
+ scope.Set("s", "");
+ scope.Exec("for item in arr: s += str(item)");
+ var result = scope.Eval("s");
+ Assert.AreEqual(string.Concat(args: objArray), result);
+ }
+
+
+ [OneTimeSetUp]
+ public void SetUp() {
+ PythonEngine.Initialize();
+ }
+
+ [OneTimeTearDown]
+ public void Dispose() {
+ PythonEngine.Shutdown();
+ }
+ }
+}
diff --git a/src/embed_tests/CallableObject.cs b/src/embed_tests/CallableObject.cs
new file mode 100644
index 000000000..553a666e6
--- /dev/null
+++ b/src/embed_tests/CallableObject.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+
+using NUnit.Framework;
+using Python.Runtime;
+
+namespace Python.EmbeddingTest {
+ class CallableObject {
+ [OneTimeSetUp]
+ public void SetUp() {
+ PythonEngine.Initialize();
+ using (Py.GIL()) {
+ using var locals = new PyDict();
+ PythonEngine.Exec(CallViaInheritance.BaseClassSource, locals: locals.Handle);
+ CustomBaseTypeProvider.BaseClass = locals[CallViaInheritance.BaseClassName];
+ PythonEngine.InteropConfiguration.PythonBaseTypeProviders.Add(new CustomBaseTypeProvider());
+ }
+ }
+
+ [OneTimeTearDown]
+ public void Dispose() {
+ PythonEngine.Shutdown();
+ }
+ [Test]
+ public void CallMethodMakesObjectCallable() {
+ var doubler = new DerivedDoubler();
+ using (Py.GIL()) {
+ dynamic applyObjectTo21 = PythonEngine.Eval("lambda o: o(21)");
+ Assert.AreEqual(doubler.__call__(21), (int)applyObjectTo21(doubler.ToPython()));
+ }
+ }
+ [Test]
+ public void CallMethodCanBeInheritedFromPython() {
+ var callViaInheritance = new CallViaInheritance();
+ using (Py.GIL()) {
+ dynamic applyObjectTo14 = PythonEngine.Eval("lambda o: o(14)");
+ Assert.AreEqual(callViaInheritance.Call(14), (int)applyObjectTo14(callViaInheritance.ToPython()));
+ }
+ }
+
+ [Test]
+ public void CanOverwriteCall() {
+ var callViaInheritance = new CallViaInheritance();
+ using var _ = Py.GIL();
+ using var scope = Py.CreateScope();
+ scope.Set("o", callViaInheritance);
+ scope.Exec("orig_call = o.Call");
+ scope.Exec("o.Call = lambda a: orig_call(a*7)");
+ int result = scope.Eval("o.Call(5)");
+ Assert.AreEqual(105, result);
+ }
+
+ class Doubler {
+ public int __call__(int arg) => 2 * arg;
+ }
+
+ class DerivedDoubler : Doubler { }
+
+ class CallViaInheritance {
+ public const string BaseClassName = "Forwarder";
+ public static readonly string BaseClassSource = $@"
+class MyCallableBase:
+ def __call__(self, val):
+ return self.Call(val)
+
+class {BaseClassName}(MyCallableBase): pass
+";
+ public int Call(int arg) => 3 * arg;
+ }
+
+ class CustomBaseTypeProvider : IPythonBaseTypeProvider {
+ internal static PyObject BaseClass;
+
+ public IEnumerable GetBaseTypes(Type type, IList existingBases) {
+ Assert.Greater(BaseClass.Refcount, 0);
+ return type != typeof(CallViaInheritance)
+ ? existingBases
+ : new []{BaseClass};
+ }
+ }
+ }
+}
diff --git a/src/embed_tests/Codecs.cs b/src/embed_tests/Codecs.cs
index 18fcd32d1..aa7627847 100644
--- a/src/embed_tests/Codecs.cs
+++ b/src/embed_tests/Codecs.cs
@@ -5,6 +5,7 @@ namespace Python.EmbeddingTest {
using NUnit.Framework;
using Python.Runtime;
using Python.Runtime.Codecs;
+ using static Python.Runtime.PyObjectConversions;
public class Codecs {
[SetUp]
@@ -82,6 +83,163 @@ static void TupleRoundtripGeneric() {
Assert.AreEqual(expected: tuple, actual: restored);
}
}
+
+ [Test]
+ public void EnumEncoded() {
+ var enumEncoder = new FakeEncoder();
+ RegisterEncoder(enumEncoder);
+ ConsoleModifiers.Alt.ToPython();
+ Assert.AreEqual(ConsoleModifiers.Alt, enumEncoder.LastObject);
+ }
+
+ [Test]
+ public void EnumDecoded() {
+ var enumDecoder = new DecoderReturningPredefinedValue(
+ objectType: PythonEngine.Eval("list"),
+ decodeResult: ConsoleModifiers.Alt);
+ RegisterDecoder(enumDecoder);
+ var decoded = PythonEngine.Eval("[]").As();
+ Assert.AreEqual(ConsoleModifiers.Alt, decoded);
+ }
+
+ const string TestExceptionMessage = "Hello World!";
+ [Test]
+ public void ExceptionEncoded() {
+ RegisterEncoder(new ValueErrorCodec());
+ void CallMe() => throw new ValueErrorWrapper(TestExceptionMessage);
+ var callMeAction = new Action(CallMe);
+ using var _ = Py.GIL();
+ using var scope = Py.CreateScope();
+ scope.Exec(@"
+def call(func):
+ try:
+ func()
+ except ValueError as e:
+ return str(e)
+");
+ var callFunc = scope.Get("call");
+ string message = callFunc.Invoke(callMeAction.ToPython()).As();
+ Assert.AreEqual(TestExceptionMessage, message);
+ }
+
+ [Test]
+ public void ExceptionDecoded() {
+ RegisterDecoder(new ValueErrorCodec());
+ using var _ = Py.GIL();
+ using var scope = Py.CreateScope();
+ var error = Assert.Throws(() => PythonEngine.Exec(
+ $"raise ValueError('{TestExceptionMessage}')"));
+ Assert.AreEqual(TestExceptionMessage, error.Message);
+ }
+
+ [Test]
+ public void ExceptionDecodedNoInstance() {
+ using var _ = Py.GIL();
+ RegisterDecoder(new InstancelessExceptionDecoder());
+ using var scope = Py.CreateScope();
+ var error = Assert.Throws(() => PythonEngine.Exec(
+ $"[].__iter__().__next__()"));
+ Assert.AreEqual(TestExceptionMessage, error.Message);
+ }
+
+ [Test]
+ public void ExceptionStringValue() {
+ RegisterDecoder(new AttributeErrorDecoder());
+ using var _ = Py.GIL();
+ using var scope = Py.CreateScope();
+ var error = Assert.Throws(() => "hi".ToPython().GetAttr("blah"));
+ StringAssert.Contains("blah", error.Message);
+ }
+
+ [Test]
+ public void OutParameterEncoded()
+ {
+ var enumEncoder = new FakeEncoder();
+ RegisterEncoder(enumEncoder);
+
+ using var scope = Py.CreateScope();
+ scope.Set("func", new Codecs().ToPython().GetAttr(nameof(GetModifiers)));
+ scope.Set("dummy", PyObject.FromManagedObject(ConsoleModifiers.Shift));
+ var evalResult = scope.Eval("func(dummy)").As
public static IntPtr tp_repr(IntPtr ob)
{
- var self = (MethodBinding)GetManagedObject(ob);
+ var self = GetInstance(ob);
string type = self.target == IntPtr.Zero ? "unbound" : "bound";
string name = self.m.name;
return Runtime.PyString_FromString($"<{type} method '{name}'>");
@@ -236,7 +309,7 @@ public static IntPtr tp_repr(IntPtr ob)
///
public new static void tp_dealloc(IntPtr ob)
{
- var self = (MethodBinding)GetManagedObject(ob);
+ var self = GetInstance(ob);
Runtime.XDecref(self.target);
Runtime.XDecref(self.targetType);
FinalizeObject(self);
diff --git a/src/runtime/methodobject.cs b/src/runtime/methodobject.cs
index 8df9c8029..47332b831 100644
--- a/src/runtime/methodobject.cs
+++ b/src/runtime/methodobject.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
namespace Python.Runtime
@@ -90,6 +92,16 @@ internal IntPtr GetDocString()
return doc;
}
+ internal IntPtr GetName()
+ {
+ var names = new HashSet(binder.GetMethods().Select(m => m.Name));
+ if (names.Count != 1) {
+ Exceptions.SetError(Exceptions.AttributeError, "a method has no name");
+ return IntPtr.Zero;
+ }
+ return Runtime.PyString_FromString(names.First());
+ }
+
///
/// This is a little tricky: a class can actually have a static method
@@ -138,7 +150,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
///
public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
{
- var self = (MethodObject)GetManagedObject(ds);
+ var self = GetManagedObject(new BorrowedReference(ds));
MethodBinding binding;
// If the method is accessed through its type (rather than via
@@ -166,7 +178,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
// this descriptor was defined on then it will be because the base class method
// is being called via super(Derived, self).method(...).
// In which case create a MethodBinding bound to the base class.
- var obj = GetManagedObject(ob) as CLRObject;
+ var obj = ManagedType.GetManagedObject(ob) as CLRObject;
if (obj != null
&& obj.inst.GetType() != self.type
&& obj.inst is IPythonDerivedType
diff --git a/src/runtime/modulefunctionobject.cs b/src/runtime/modulefunctionobject.cs
index 8f8692af9..f6321eca9 100644
--- a/src/runtime/modulefunctionobject.cs
+++ b/src/runtime/modulefunctionobject.cs
@@ -23,7 +23,7 @@ public ModuleFunctionObject(Type type, string name, MethodInfo[] info, bool allo
///
public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
{
- var self = (ModuleFunctionObject)GetManagedObject(ob);
+ var self = GetManagedObject(new BorrowedReference(ob));
return self.Invoke(ob, args, kw);
}
@@ -32,7 +32,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw)
///
public new static IntPtr tp_repr(IntPtr ob)
{
- var self = (ModuleFunctionObject)GetManagedObject(ob);
+ var self = GetManagedObject(new BorrowedReference(ob));
return Runtime.PyString_FromString($"");
}
}
diff --git a/src/runtime/moduleobject.cs b/src/runtime/moduleobject.cs
index 15e4feee8..abab4f8b2 100644
--- a/src/runtime/moduleobject.cs
+++ b/src/runtime/moduleobject.cs
@@ -45,16 +45,16 @@ public ModuleObject(string name)
IntPtr pyname = Runtime.PyString_FromString(moduleName);
IntPtr pyfilename = Runtime.PyString_FromString(filename);
IntPtr pydocstring = Runtime.PyString_FromString(docstring);
- IntPtr pycls = TypeManager.GetTypeHandle(GetType());
+ BorrowedReference pycls = TypeManager.GetTypeHandle(GetType());
Runtime.PyDict_SetItemString(dict, "__name__", pyname);
Runtime.PyDict_SetItemString(dict, "__file__", pyfilename);
Runtime.PyDict_SetItemString(dict, "__doc__", pydocstring);
- Runtime.PyDict_SetItemString(dict, "__class__", pycls);
+ Runtime.PyDict_SetItemString(dict, "__class__", pycls.DangerousGetAddress());
Runtime.XDecref(pyname);
Runtime.XDecref(pyfilename);
Runtime.XDecref(pydocstring);
- Marshal.WriteIntPtr(pyHandle, ObjectOffset.TypeDictOffset(tpHandle), dict);
+ Marshal.WriteIntPtr(pyHandle, ObjectOffset.TypeDictOffset(Type), dict);
InitializeModuleMembers();
}
@@ -251,7 +251,7 @@ internal void InitializeModuleMembers()
///
public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
{
- var self = (ModuleObject)GetManagedObject(ob);
+ var self = GetManagedObject(new BorrowedReference(ob));
if (!Runtime.PyString_Check(key))
{
@@ -301,7 +301,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
///
public static IntPtr tp_repr(IntPtr ob)
{
- var self = (ModuleObject)GetManagedObject(ob);
+ var self = GetManagedObject(new BorrowedReference(ob));
return Runtime.PyString_FromString($"");
}
}
diff --git a/src/runtime/nativecall.cs b/src/runtime/nativecall.cs
index 4a7bf05c8..fc72209ee 100644
--- a/src/runtime/nativecall.cs
+++ b/src/runtime/nativecall.cs
@@ -21,7 +21,7 @@ namespace Python.Runtime
/// build process to generate the thunks as a separate assembly
/// that could then be referenced by the main Python runtime.
///
- internal class NativeCall
+ internal static class NativeCall
{
#if NETSTANDARD
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@@ -48,6 +48,12 @@ public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
var d = Marshal.GetDelegateForFunctionPointer(fp);
return d(a1, a2, a3);
}
+
+ public static IntPtr Call_2(IntPtr fp, IntPtr a1, IntPtr a2)
+ {
+ var d = (Interop.BinaryFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(Interop.BinaryFunc));
+ return d(a1, a2);
+ }
#else
private static AssemblyBuilder aBuilder;
private static ModuleBuilder mBuilder;
@@ -149,6 +155,11 @@ public static void Void_Call_1(IntPtr fp, IntPtr a1)
Impl.Void_Call_1(fp, a1);
}
+ public static IntPtr Call_2(IntPtr fp, IntPtr a1, IntPtr a2)
+ {
+ return Impl.Call_2(fp, a1, a2);
+ }
+
public static IntPtr Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
{
return Impl.Call_3(fp, a1, a2, a3);
@@ -171,6 +182,8 @@ public interface INativeCall
void Void_Call_1(IntPtr funcPtr, IntPtr arg1);
+ IntPtr Call_2(IntPtr funcPtr, IntPtr a1, IntPtr a2);
+
int Int_Call_3(IntPtr funcPtr, IntPtr t, IntPtr n, IntPtr v);
IntPtr Call_3(IntPtr funcPtr, IntPtr a1, IntPtr a2, IntPtr a3);
diff --git a/src/runtime/platform/LibraryLoader.cs b/src/runtime/platform/LibraryLoader.cs
index a6d88cd19..4aa6d53a2 100644
--- a/src/runtime/platform/LibraryLoader.cs
+++ b/src/runtime/platform/LibraryLoader.cs
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
+using System.IO;
using System.Runtime.InteropServices;
namespace Python.Runtime.Platform
@@ -40,7 +41,7 @@ class LinuxLoader : ILibraryLoader
public IntPtr Load(string dllToLoad)
{
- var filename = $"lib{dllToLoad}.so";
+ var filename = File.Exists(dllToLoad) ? dllToLoad : $"lib{dllToLoad}.so";
ClearError();
var res = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
if (res == IntPtr.Zero)
@@ -111,7 +112,7 @@ class DarwinLoader : ILibraryLoader
public IntPtr Load(string dllToLoad)
{
- var filename = $"lib{dllToLoad}.dylib";
+ var filename = File.Exists(dllToLoad) ? dllToLoad : $"lib{dllToLoad}.dylib";
ClearError();
var res = dlopen(filename, RTLD_NOW | RTLD_GLOBAL);
if (res == IntPtr.Zero)
diff --git a/src/runtime/polyfill/ExceptionPolifills.cs b/src/runtime/polyfill/ExceptionPolifills.cs
new file mode 100644
index 000000000..923ff41a3
--- /dev/null
+++ b/src/runtime/polyfill/ExceptionPolifills.cs
@@ -0,0 +1,19 @@
+namespace Python.Runtime
+{
+ using System;
+ using System.Runtime.ExceptionServices;
+
+ static class ExceptionPolifills
+ {
+ public static Exception Rethrow(this Exception exception)
+ {
+ if (exception is null)
+ throw new ArgumentNullException(nameof(exception));
+
+#if NETSTANDARD
+ ExceptionDispatchInfo.Capture(exception).Throw();
+#endif
+ throw exception;
+ }
+ }
+}
diff --git a/src/runtime/polyfill/ReflectionPolifills.cs b/src/runtime/polyfill/ReflectionPolifills.cs
index b9ce78d63..b2c60a83e 100644
--- a/src/runtime/polyfill/ReflectionPolifills.cs
+++ b/src/runtime/polyfill/ReflectionPolifills.cs
@@ -16,9 +16,10 @@ public static AssemblyBuilder DefineDynamicAssembly(this AppDomain appDomain, As
public static Type CreateType(this TypeBuilder typeBuilder)
{
- return typeBuilder.GetTypeInfo().GetType();
+ return typeBuilder.CreateTypeInfo();
}
#endif
+#if NETFX
public static T GetCustomAttribute(this Type type) where T: Attribute
{
return type.GetCustomAttributes(typeof(T), inherit: false)
@@ -32,5 +33,31 @@ public static T GetCustomAttribute(this Assembly assembly) where T: Attribute
.Cast()
.SingleOrDefault();
}
+#endif
+
+ public static object GetDefaultValue(this ParameterInfo parameterInfo)
+ {
+ // parameterInfo.HasDefaultValue is preferable but doesn't exist in .NET 4.0
+ bool hasDefaultValue = (parameterInfo.Attributes & ParameterAttributes.HasDefault) ==
+ ParameterAttributes.HasDefault;
+
+ if (hasDefaultValue)
+ {
+ return parameterInfo.DefaultValue;
+ }
+ else
+ {
+ // [OptionalAttribute] was specified for the parameter.
+ // See https://stackoverflow.com/questions/3416216/optionalattribute-parameters-default-value
+ // for rules on determining the value to pass to the parameter
+ var type = parameterInfo.ParameterType;
+ if (type == typeof(object))
+ return Type.Missing;
+ else if (type.IsValueType)
+ return Activator.CreateInstance(type);
+ else
+ return null;
+ }
+ }
}
}
diff --git a/src/runtime/propertyobject.cs b/src/runtime/propertyobject.cs
index f2c97f163..728988bba 100644
--- a/src/runtime/propertyobject.cs
+++ b/src/runtime/propertyobject.cs
@@ -9,7 +9,7 @@ namespace Python.Runtime
///
internal class PropertyObject : ExtensionType
{
- private PropertyInfo info;
+ internal PropertyInfo info;
private MethodInfo getter;
private MethodInfo setter;
@@ -21,15 +21,17 @@ public PropertyObject(PropertyInfo md)
info = md;
}
-
+ static PropertyObject GetInstance(IntPtr ob)
+ => GetManagedObject(new BorrowedReference(ob));
///
/// Descriptor __get__ implementation. This method returns the
/// value of the property on the given object. The returned value
/// is converted to an appropriately typed Python object.
///
- public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
+ public static IntPtr tp_descr_get(IntPtr ds, IntPtr obRaw, IntPtr tp)
{
- var self = (PropertyObject)GetManagedObject(ds);
+ var ob = new BorrowedReference(obRaw);
+ var self = GetInstance(ds);
MethodInfo getter = self.getter;
object result;
@@ -43,23 +45,24 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
{
if (!getter.IsStatic)
{
- Exceptions.SetError(Exceptions.TypeError,
- "instance property must be accessed through a class instance");
- return IntPtr.Zero;
+ Runtime.XIncref(ds);
+ // unbound property
+ return ds;
}
try
{
result = self.info.GetValue(null, null);
- return Converter.ToPython(result, self.info.PropertyType);
+ return Converter.ToPython(result);
}
catch (Exception e)
{
- return Exceptions.RaiseTypeError(e.Message);
+ Exceptions.SetError(e);
+ return IntPtr.Zero;
}
}
- var co = GetManagedObject(ob) as CLRObject;
+ var co = ManagedType.GetManagedObject(ob) as CLRObject;
if (co == null)
{
return Exceptions.RaiseTypeError("invalid target");
@@ -68,7 +71,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
try
{
result = self.info.GetValue(co.inst, null);
- return Converter.ToPython(result, self.info.PropertyType);
+ return Converter.ToPython(result);
}
catch (Exception e)
{
@@ -87,9 +90,10 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
/// a property based on the given Python value. The Python value must
/// be convertible to the type of the property.
///
- public new static int tp_descr_set(IntPtr ds, IntPtr ob, IntPtr val)
+ public new static int tp_descr_set(IntPtr ds, IntPtr obRaw, IntPtr val)
{
- var self = (PropertyObject)GetManagedObject(ds);
+ var ob = new BorrowedReference(obRaw);
+ var self = GetInstance(ds);
MethodInfo setter = self.setter;
object newval;
@@ -126,7 +130,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
{
if (!is_static)
{
- var co = GetManagedObject(ob) as CLRObject;
+ var co = ManagedType.GetManagedObject(ob) as CLRObject;
if (co == null)
{
Exceptions.RaiseTypeError("invalid target");
@@ -157,7 +161,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
///
public static IntPtr tp_repr(IntPtr ob)
{
- var self = (PropertyObject)GetManagedObject(ob);
+ var self = GetInstance(ob);
return Runtime.PyString_FromString($"");
}
}
diff --git a/src/runtime/pyansistring.cs b/src/runtime/pyansistring.cs
index 3d1d6ab68..acedc59c6 100644
--- a/src/runtime/pyansistring.cs
+++ b/src/runtime/pyansistring.cs
@@ -25,14 +25,20 @@ public PyAnsiString(IntPtr ptr) : base(ptr)
/// An ArgumentException will be thrown if the given object is not
/// a Python string object.
///
- public PyAnsiString(PyObject o)
+ public PyAnsiString(PyObject o): base(FromPyObject(o))
{
+ }
+
+ static IntPtr FromPyObject(PyObject o)
+ {
+ if (o == null) throw new ArgumentNullException(nameof(o));
+
if (!IsStringType(o))
{
throw new ArgumentException("object is not a string");
}
Runtime.XIncref(o.obj);
- obj = o.obj;
+ return o.obj;
}
@@ -42,10 +48,8 @@ public PyAnsiString(PyObject o)
///
/// Creates a Python string from a managed string.
///
- public PyAnsiString(string s)
+ public PyAnsiString(string s):base(PythonException.ThrowIfIsNull(Runtime.PyString_FromString(s)))
{
- obj = Runtime.PyString_FromString(s);
- Runtime.CheckExceptionOccurred();
}
@@ -57,6 +61,8 @@ public PyAnsiString(string s)
///
public static bool IsStringType(PyObject value)
{
+ if (value == null) throw new ArgumentNullException(nameof(value));
+
return Runtime.PyString_Check(value.obj);
}
}
diff --git a/src/runtime/pybuffer.cs b/src/runtime/pybuffer.cs
new file mode 100644
index 000000000..84ef2bde8
--- /dev/null
+++ b/src/runtime/pybuffer.cs
@@ -0,0 +1,241 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace Python.Runtime
+{
+ public sealed class PyBuffer : IPyDisposable
+ {
+ private PyObject _exporter;
+ private Py_buffer _view;
+
+ unsafe internal PyBuffer(PyObject exporter, PyBUF flags)
+ {
+ if (Runtime.PyObject_GetBuffer(exporter.Reference, out _view, flags) < 0)
+ {
+ throw PythonException.ThrowLastAsClrException();
+ }
+
+ _exporter = exporter;
+
+ var intPtrBuf = new IntPtr[_view.ndim];
+ if (_view.shape != IntPtr.Zero)
+ {
+ Marshal.Copy(_view.shape, intPtrBuf, 0, (int)_view.len * sizeof(IntPtr));
+ Shape = intPtrBuf.Select(x => (long)x).ToArray();
+ }
+
+ if (_view.strides != IntPtr.Zero) {
+ Marshal.Copy(_view.strides, intPtrBuf, 0, (int)_view.len * sizeof(IntPtr));
+ Strides = intPtrBuf.Select(x => (long)x).ToArray();
+ }
+
+ if (_view.suboffsets != IntPtr.Zero) {
+ Marshal.Copy(_view.suboffsets, intPtrBuf, 0, (int)_view.len * sizeof(IntPtr));
+ SubOffsets = intPtrBuf.Select(x => (long)x).ToArray();
+ }
+ }
+
+ public PyObject Object => _exporter;
+ public long Length => (long)_view.len;
+ public long ItemSize => (long)_view.itemsize;
+ public int Dimensions => _view.ndim;
+ public bool ReadOnly => _view._readonly;
+ public IntPtr Buffer => _view.buf;
+ public string Format => _view.format;
+
+ ///
+ /// An array of length indicating the shape of the memory as an n-dimensional array.
+ ///
+ public long[] Shape { get; private set; }
+
+ ///
+ /// An array of length giving the number of bytes to skip to get to a new element in each dimension.
+ /// Will be null except when PyBUF_STRIDES or PyBUF_INDIRECT flags in GetBuffer/>.
+ ///
+ public long[] Strides { get; private set; }
+
+ ///
+ /// An array of Py_ssize_t of length ndim. If suboffsets[n] >= 0,
+ /// the values stored along the nth dimension are pointers and the suboffset value dictates how many bytes to add to each pointer after de-referencing.
+ /// A suboffset value that is negative indicates that no de-referencing should occur (striding in a contiguous memory block).
+ ///
+ public long[] SubOffsets { get; private set; }
+
+ ///
+ /// Return the implied itemsize from format. On error, raise an exception and return -1.
+ /// New in version 3.9.
+ ///
+ public static long SizeFromFormat(string format)
+ {
+ if (Runtime.PythonVersion < new Version(3, 9))
+ throw new NotSupportedException("SizeFromFormat requires at least Python 3.9");
+ return (long)Runtime.PyBuffer_SizeFromFormat(format);
+ }
+
+ ///
+ /// Returns true if the memory defined by the view is C-style (order is 'C') or Fortran-style (order is 'F') contiguous or either one (order is 'A'). Returns false otherwise.
+ ///
+ /// C-style (order is 'C') or Fortran-style (order is 'F') contiguous or either one (order is 'A')
+ public bool IsContiguous(BufferOrderStyle order)
+ {
+ if (disposedValue)
+ throw new ObjectDisposedException(nameof(PyBuffer));
+ return Convert.ToBoolean(Runtime.PyBuffer_IsContiguous(ref _view, order));
+ }
+
+ ///
+ /// Get the memory area pointed to by the indices inside the given view. indices must point to an array of view->ndim indices.
+ ///
+ public IntPtr GetPointer(long[] indices)
+ {
+ if (disposedValue)
+ throw new ObjectDisposedException(nameof(PyBuffer));
+ if (Runtime.PythonVersion < new Version(3, 7))
+ throw new NotSupportedException("GetPointer requires at least Python 3.7");
+ return Runtime.PyBuffer_GetPointer(ref _view, indices.Select(x => (IntPtr)x).ToArray());
+ }
+
+ ///
+ /// Copy contiguous len bytes from buf to view. fort can be 'C' or 'F' (for C-style or Fortran-style ordering).
+ ///
+ public void FromContiguous(IntPtr buf, long len, BufferOrderStyle fort)
+ {
+ if (disposedValue)
+ throw new ObjectDisposedException(nameof(PyBuffer));
+ if (Runtime.PythonVersion < new Version(3, 7))
+ throw new NotSupportedException("FromContiguous requires at least Python 3.7");
+
+ if (Runtime.PyBuffer_FromContiguous(ref _view, buf, (IntPtr)len, fort) < 0)
+ throw PythonException.ThrowLastAsClrException();
+ }
+
+ ///
+ /// Copy len bytes from view to its contiguous representation in buf. order can be 'C' or 'F' or 'A' (for C-style or Fortran-style ordering or either one). 0 is returned on success, -1 on error.
+ ///
+ /// order can be 'C' or 'F' or 'A' (for C-style or Fortran-style ordering or either one).
+ /// Buffer to copy to
+ public void ToContiguous(IntPtr buf, BufferOrderStyle order)
+ {
+ if (disposedValue)
+ throw new ObjectDisposedException(nameof(PyBuffer));
+ if (Runtime.PythonVersion < new Version(3, 6))
+ throw new NotSupportedException("ToContiguous requires at least Python 3.6");
+
+ if (Runtime.PyBuffer_ToContiguous(buf, ref _view, _view.len, order) < 0)
+ throw new PythonException();
+ }
+
+ ///
+ /// Fill the strides array with byte-strides of a contiguous (C-style if order is 'C' or Fortran-style if order is 'F') array of the given shape with the given number of bytes per element.
+ ///
+ public static void FillContiguousStrides(int ndims, IntPtr[] shape, IntPtr[] strides, int itemsize, BufferOrderStyle order)
+ {
+ Runtime.PyBuffer_FillContiguousStrides(ndims, shape, strides, itemsize, order);
+ }
+
+ ///
+ /// FillInfo Method
+ ///
+ ///
+ /// Handle buffer requests for an exporter that wants to expose buf of size len with writability set according to readonly. buf is interpreted as a sequence of unsigned bytes.
+ /// The flags argument indicates the request type. This function always fills in view as specified by flags, unless buf has been designated as read-only and PyBUF_WRITABLE is set in flags.
+ /// On success, set view->obj to a new reference to exporter and return 0. Otherwise, raise PyExc_BufferError, set view->obj to NULL and return -1;
+ /// If this function is used as part of a getbufferproc, exporter MUST be set to the exporting object and flags must be passed unmodified.Otherwise, exporter MUST be NULL.
+ ///
+ /// On success, set view->obj to a new reference to exporter and return 0. Otherwise, raise PyExc_BufferError, set view->obj to NULL and return -1;
+ public void FillInfo(IntPtr exporter, IntPtr buf, long len, bool @readonly, PyBUF flags)
+ {
+ if (disposedValue)
+ throw new ObjectDisposedException(nameof(PyBuffer));
+ if (Runtime.PyBuffer_FillInfo(ref _view, new BorrowedReference(exporter), buf, (IntPtr)len, @readonly, flags) < 0)
+ throw new PythonException();
+ }
+
+ ///
+ /// Writes a managed byte array into the buffer of a python object. This can be used to pass data like images from managed to python.
+ ///
+ public void Write(byte[] buffer, int offset, int count)
+ {
+ if (disposedValue)
+ throw new ObjectDisposedException(nameof(PyBuffer));
+ if (ReadOnly)
+ throw new InvalidOperationException("Buffer is read-only");
+ if ((long)_view.len > int.MaxValue)
+ throw new NotSupportedException("Python buffers bigger than int.MaxValue are not supported.");
+ if (count > buffer.Length)
+ throw new ArgumentOutOfRangeException("count", "Count is bigger than the buffer.");
+ if (count > (int)_view.len)
+ throw new ArgumentOutOfRangeException("count", "Count is bigger than the python buffer.");
+ if (_view.ndim != 1)
+ throw new NotSupportedException("Multidimensional arrays, scalars and objects without a buffer are not supported.");
+
+ Marshal.Copy(buffer, offset, _view.buf, count);
+ }
+
+ ///
+ /// Reads the buffer of a python object into a managed byte array. This can be used to pass data like images from python to managed.
+ ///
+ public int Read(byte[] buffer, int offset, int count) {
+ if (disposedValue)
+ throw new ObjectDisposedException(nameof(PyBuffer));
+ if (count > buffer.Length)
+ throw new ArgumentOutOfRangeException("count", "Count is bigger than the buffer.");
+ if (_view.ndim != 1)
+ throw new NotSupportedException("Multidimensional arrays, scalars and objects without a buffer are not supported.");
+ if (_view.len.ToInt64() > int.MaxValue)
+ throw new NotSupportedException("Python buffers bigger than int.MaxValue are not supported.");
+
+ int copylen = count < (int)_view.len ? count : (int)_view.len;
+ Marshal.Copy(_view.buf, buffer, offset, copylen);
+ return copylen;
+ }
+
+ private bool disposedValue = false; // To detect redundant calls
+
+ private void Dispose(bool disposing)
+ {
+ if (!disposedValue)
+ {
+ if (Runtime.Py_IsInitialized() == 0)
+ throw new InvalidOperationException("Python runtime must be initialized");
+
+ // this also decrements ref count for _view->obj
+ Runtime.PyBuffer_Release(ref _view);
+
+ _exporter = null;
+ Shape = null;
+ Strides = null;
+ SubOffsets = null;
+
+ disposedValue = true;
+ }
+ }
+
+ ~PyBuffer()
+ {
+ if (disposedValue)
+ {
+ return;
+ }
+ Finalizer.Instance.AddFinalizedObject(this);
+ }
+
+ ///
+ /// Release the buffer view and decrement the reference count for view->obj. This function MUST be called when the buffer is no longer being used, otherwise reference leaks may occur.
+ /// It is an error to call this function on a buffer that was not obtained via .
+ ///
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ public IntPtr[] GetTrackedHandles()
+ {
+ return new IntPtr[] { _view.obj };
+ }
+ }
+}
diff --git a/src/runtime/pydict.cs b/src/runtime/pydict.cs
index 7ff7a83c8..ea9633d61 100644
--- a/src/runtime/pydict.cs
+++ b/src/runtime/pydict.cs
@@ -29,13 +29,8 @@ public PyDict(IntPtr ptr) : base(ptr)
///
/// Creates a new Python dictionary object.
///
- public PyDict()
+ public PyDict():base(Exceptions.ErrorCheck(Runtime.PyDict_New()))
{
- obj = Runtime.PyDict_New();
- if (obj == IntPtr.Zero)
- {
- throw new PythonException();
- }
}
@@ -47,14 +42,20 @@ public PyDict()
/// ArgumentException will be thrown if the given object is not a
/// Python dictionary object.
///
- public PyDict(PyObject o)
+ public PyDict(PyObject o):base(FromPyObject(o))
+ {
+ }
+
+ static IntPtr FromPyObject(PyObject o)
{
+ if (o == null) throw new ArgumentNullException(nameof(o));
+
if (!IsDictType(o))
{
throw new ArgumentException("object is not a dict");
}
Runtime.XIncref(o.obj);
- obj = o.obj;
+ return o.obj;
}
@@ -106,10 +107,7 @@ public bool HasKey(string key)
public PyObject Keys()
{
IntPtr items = Runtime.PyDict_Keys(obj);
- if (items == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(items);
return new PyObject(items);
}
@@ -123,10 +121,7 @@ public PyObject Keys()
public PyObject Values()
{
IntPtr items = Runtime.PyDict_Values(obj);
- if (items == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(items);
return new PyObject(items);
}
@@ -144,7 +139,7 @@ public PyObject Items()
{
if (items.IsNull())
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
return items.MoveToPyObject();
@@ -165,10 +160,7 @@ public PyObject Items()
public PyDict Copy()
{
IntPtr op = Runtime.PyDict_Copy(obj);
- if (op == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(op);
return new PyDict(op);
}
@@ -184,7 +176,7 @@ public void Update(PyObject other)
int result = Runtime.PyDict_Update(obj, other.obj);
if (result < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
diff --git a/src/runtime/pyfloat.cs b/src/runtime/pyfloat.cs
index edfaca542..3a5f92e3c 100644
--- a/src/runtime/pyfloat.cs
+++ b/src/runtime/pyfloat.cs
@@ -31,14 +31,19 @@ public PyFloat(IntPtr ptr) : base(ptr)
/// ArgumentException will be thrown if the given object is not a
/// Python float object.
///
- public PyFloat(PyObject o)
+ public PyFloat(PyObject o):base(FromPyObject(o))
{
+ }
+
+ static IntPtr FromPyObject(PyObject o)
+ {
+ if (o == null) throw new ArgumentNullException(nameof(o));
if (!IsFloatType(o))
{
throw new ArgumentException("object is not a float");
}
Runtime.XIncref(o.obj);
- obj = o.obj;
+ return o.obj;
}
@@ -48,10 +53,8 @@ public PyFloat(PyObject o)
///
/// Creates a new Python float from a double value.
///
- public PyFloat(double value)
+ public PyFloat(double value):base(PythonException.ThrowIfIsNull(Runtime.PyFloat_FromDouble(value)))
{
- obj = Runtime.PyFloat_FromDouble(value);
- Runtime.CheckExceptionOccurred();
}
@@ -61,12 +64,19 @@ public PyFloat(double value)
///
/// Creates a new Python float from a string value.
///
- public PyFloat(string value)
+ public PyFloat(string value):base(FromString(value))
{
+ }
+
+ static IntPtr FromString(string value)
+ {
+ if (value == null) throw new ArgumentNullException(nameof(value));
+
using (var s = new PyString(value))
{
- obj = Runtime.PyFloat_FromString(s.obj, IntPtr.Zero);
+ var obj = Runtime.PyFloat_FromString(s.obj, IntPtr.Zero);
Runtime.CheckExceptionOccurred();
+ return obj;
}
}
@@ -79,6 +89,8 @@ public PyFloat(string value)
///
public static bool IsFloatType(PyObject value)
{
+ if (value == null) throw new ArgumentNullException(nameof(value));
+
return Runtime.PyFloat_Check(value.obj);
}
diff --git a/src/runtime/pyint.cs b/src/runtime/pyint.cs
index 217cf7e20..9ed41cdd7 100644
--- a/src/runtime/pyint.cs
+++ b/src/runtime/pyint.cs
@@ -31,14 +31,20 @@ public PyInt(IntPtr ptr) : base(ptr)
/// ArgumentException will be thrown if the given object is not a
/// Python int object.
///
- public PyInt(PyObject o)
+ public PyInt(PyObject o):base(FromPyObject(o))
{
+ }
+
+ static IntPtr FromPyObject(PyObject o)
+ {
+ if (o == null) throw new ArgumentNullException(nameof(o));
+
if (!IsIntType(o))
{
throw new ArgumentException("object is not an int");
}
Runtime.XIncref(o.obj);
- obj = o.obj;
+ return o.obj;
}
@@ -48,10 +54,8 @@ public PyInt(PyObject o)
///
/// Creates a new Python int from an int32 value.
///
- public PyInt(int value)
+ public PyInt(int value):base(PythonException.ThrowIfIsNull(Runtime.PyInt_FromInt32(value)))
{
- obj = Runtime.PyInt_FromInt32(value);
- Runtime.CheckExceptionOccurred();
}
@@ -62,10 +66,8 @@ public PyInt(int value)
/// Creates a new Python int from a uint32 value.
///
[CLSCompliant(false)]
- public PyInt(uint value)
+ public PyInt(uint value) : base(PythonException.ThrowIfIsNull(Runtime.PyInt_FromInt64(value)))
{
- obj = Runtime.PyInt_FromInt64(value);
- Runtime.CheckExceptionOccurred();
}
@@ -75,10 +77,8 @@ public PyInt(uint value)
///
/// Creates a new Python int from an int64 value.
///
- public PyInt(long value)
+ public PyInt(long value) : base(PythonException.ThrowIfIsNull(Runtime.PyInt_FromInt64(value)))
{
- obj = Runtime.PyInt_FromInt64(value);
- Runtime.CheckExceptionOccurred();
}
@@ -89,10 +89,8 @@ public PyInt(long value)
/// Creates a new Python int from a uint64 value.
///
[CLSCompliant(false)]
- public PyInt(ulong value)
+ public PyInt(ulong value) : base(PythonException.ThrowIfIsNull(Runtime.PyInt_FromInt64((long)value)))
{
- obj = Runtime.PyInt_FromInt64((long)value);
- Runtime.CheckExceptionOccurred();
}
@@ -148,10 +146,10 @@ public PyInt(sbyte value) : this((int)value)
///
/// Creates a new Python int from a string value.
///
- public PyInt(string value)
+ public PyInt(string value):base(
+ PythonException.ThrowIfIsNull(
+ Runtime.PyInt_FromString(value ?? throw new ArgumentNullException(nameof(value)), IntPtr.Zero, 0)))
{
- obj = Runtime.PyInt_FromString(value, IntPtr.Zero, 0);
- Runtime.CheckExceptionOccurred();
}
@@ -163,6 +161,8 @@ public PyInt(string value)
///
public static bool IsIntType(PyObject value)
{
+ if (value == null) throw new ArgumentNullException(nameof(value));
+
return Runtime.PyInt_Check(value.obj);
}
@@ -177,6 +177,8 @@ public static bool IsIntType(PyObject value)
///
public static PyInt AsInt(PyObject value)
{
+ if (value == null) throw new ArgumentNullException(nameof(value));
+
IntPtr op = Runtime.PyNumber_Int(value.obj);
Runtime.CheckExceptionOccurred();
return new PyInt(op);
diff --git a/src/runtime/pyiter.cs b/src/runtime/pyiter.cs
index ee07bcecf..7be981678 100644
--- a/src/runtime/pyiter.cs
+++ b/src/runtime/pyiter.cs
@@ -9,7 +9,7 @@ namespace Python.Runtime
/// PY3: https://docs.python.org/3/c-api/iterator.html
/// for details.
///
- public class PyIter : PyObject, IEnumerator
+ public class PyIter : PyObject, IEnumerator
{
private PyObject _current;
@@ -24,59 +24,50 @@ public class PyIter : PyObject, IEnumerator
public PyIter(IntPtr ptr) : base(ptr)
{
}
-
///
- /// PyIter Constructor
+ /// Creates new from an untyped reference to Python iterator object.
///
- ///
- /// Creates a Python iterator from an iterable. Like doing "iter(iterable)" in python.
- ///
- public PyIter(PyObject iterable)
- {
- obj = Runtime.PyObject_GetIter(iterable.obj);
- if (obj == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ public PyIter(PyObject pyObject) : base(FromPyObject(pyObject)) { }
+ static BorrowedReference FromPyObject(PyObject pyObject) {
+ if (pyObject is null) throw new ArgumentNullException(nameof(pyObject));
+
+ if (!Runtime.PyIter_Check(pyObject.Reference))
+ throw new ArgumentException("Object does not support iterator protocol");
+
+ return pyObject.Reference;
}
+ internal PyIter(BorrowedReference reference) : base(reference) { }
+
protected override void Dispose(bool disposing)
{
- if (null != _current)
- {
- _current.Dispose();
- _current = null;
- }
+ _current = null;
base.Dispose(disposing);
}
public bool MoveNext()
{
- // dispose of the previous object, if there was one
- if (null != _current)
+ using var next = Runtime.PyIter_Next(Reference);
+ if (next.IsNull())
{
- _current.Dispose();
- _current = null;
- }
+ if (Exceptions.ErrorOccurred())
+ throw PythonException.ThrowLastAsClrException();
- IntPtr next = Runtime.PyIter_Next(obj);
- if (next == IntPtr.Zero)
- {
+ // dispose of the previous object, if there was one
+ _current = null;
return false;
}
- _current = new PyObject(next);
+ _current = next.MoveToPyObject();
return true;
}
public void Reset()
{
- //Not supported in python.
+ throw new NotSupportedException();
}
- public object Current
- {
- get { return _current; }
- }
+ public PyObject Current => _current;
+ object System.Collections.IEnumerator.Current => this.Current;
}
}
diff --git a/src/runtime/pylist.cs b/src/runtime/pylist.cs
index 347cc3000..2da90d027 100644
--- a/src/runtime/pylist.cs
+++ b/src/runtime/pylist.cs
@@ -10,6 +10,22 @@ namespace Python.Runtime
///
public class PyList : PySequence
{
+ ///
+ /// Gets an instance of representing the same object as the given object.
+ ///
+ public static PyList Wrap(PyObject o)
+ {
+ if (o is null)
+ {
+ throw new ArgumentNullException(nameof(o));
+ }
+ if (!IsListType(o))
+ {
+ throw new ArgumentException("object is not a list");
+ }
+ return new PyList(o.Reference);
+ }
+
///
/// PyList Constructor
///
@@ -22,39 +38,25 @@ public PyList(IntPtr ptr) : base(ptr)
{
}
-
///
/// PyList Constructor
///
///
- /// Copy constructor - obtain a PyList from a generic PyObject. An
- /// ArgumentException will be thrown if the given object is not a
- /// Python list object.
+ /// Creates a new PyList from an existing object reference.
+ /// The object reference is not checked for type-correctness.
///
- public PyList(PyObject o)
+ internal PyList(BorrowedReference reference) : base(reference)
{
- if (!IsListType(o))
- {
- throw new ArgumentException("object is not a list");
- }
- Runtime.XIncref(o.obj);
- obj = o.obj;
}
-
///
/// PyList Constructor
///
///
/// Creates a new empty Python list object.
///
- public PyList()
+ public PyList(): base(Exceptions.ErrorCheck(Runtime.PyList_New(0)))
{
- obj = Runtime.PyList_New(0);
- if (obj == IntPtr.Zero)
- {
- throw new PythonException();
- }
}
@@ -75,7 +77,7 @@ public PyList(PyObject[] items)
int r = Runtime.PyList_SetItem(obj, i, ptr);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
}
@@ -104,10 +106,7 @@ public static bool IsListType(PyObject value)
public static PyList AsList(PyObject value)
{
IntPtr op = Runtime.PySequence_List(value.obj);
- if (op == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(op);
return new PyList(op);
}
@@ -123,7 +122,7 @@ public void Append(PyObject item)
int r = Runtime.PyList_Append(this.Reference, item.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -138,7 +137,7 @@ public void Insert(int index, PyObject item)
int r = Runtime.PyList_Insert(this.Reference, index, item.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -154,7 +153,7 @@ public void Reverse()
int r = Runtime.PyList_Reverse(this.Reference);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -170,7 +169,7 @@ public void Sort()
int r = Runtime.PyList_Sort(this.Reference);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
}
diff --git a/src/runtime/pyobject.cs b/src/runtime/pyobject.cs
index 699ebf873..500a9156a 100644
--- a/src/runtime/pyobject.cs
+++ b/src/runtime/pyobject.cs
@@ -20,6 +20,7 @@ public interface IPyDisposable : IDisposable
/// PY3: https://docs.python.org/3/c-api/object.html
/// for details.
///
+ [DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public class PyObject : DynamicObject, IEnumerable, IPyDisposable
{
#if TRACE_ALLOC
@@ -27,8 +28,9 @@ public class PyObject : DynamicObject, IEnumerable, IPyDisposable
/// Trace stack for PyObject's construction
///
public StackTrace Traceback { get; private set; }
-#endif
+#endif
+ readonly long run = Runtime.GetRun();
protected internal IntPtr obj = IntPtr.Zero;
internal BorrowedReference Reference => new BorrowedReference(obj);
@@ -99,10 +101,7 @@ protected PyObject()
/// Gets the native handle of the underlying Python object. This
/// value is generally for internal use by the PythonNet runtime.
///
- public IntPtr Handle
- {
- get { return obj; }
- }
+ public IntPtr Handle => obj == IntPtr.Zero ? throw new ObjectDisposedException(this.GetType().Name) : obj;
///
@@ -136,9 +135,10 @@ public static PyObject FromManagedObject(object ob)
public object AsManagedObject(Type t)
{
object result;
- if (!Converter.ToManaged(obj, t, out result, false))
+ if (!Converter.ToManaged(obj, t, out result, setError: true))
{
- throw new InvalidCastException("cannot convert object to target type");
+ throw new InvalidCastException("cannot convert object to target type",
+ innerException: PythonException.FromPyErrOrNull());
}
return result;
}
@@ -150,19 +150,7 @@ public object AsManagedObject(Type t)
/// Return a managed object of the given type, based on the
/// value of the Python object.
///
- public T As()
- {
- if (typeof(T) == typeof(PyObject) || typeof(T) == typeof(object))
- {
- return (T)(this as object);
- }
- object result;
- if (!Converter.ToManaged(obj, typeof(T), out result, false))
- {
- throw new InvalidCastException("cannot convert object to target type");
- }
- return (T)result;
- }
+ public T As() => (T)this.AsManagedObject(typeof(T));
///
@@ -178,6 +166,8 @@ public T As()
///
protected virtual void Dispose(bool disposing)
{
+ DebugUtil.EnsureGIL();
+
if (this.obj == IntPtr.Zero)
{
return;
@@ -204,7 +194,7 @@ protected virtual void Dispose(bool disposing)
{
// Python requires finalizers to preserve exception:
// https://docs.python.org/3/extending/newtypes.html#finalization-and-de-allocation
- Runtime.PyErr_Restore(errType, errVal, traceback);
+ Runtime.PyErr_Restore(errType.Steal(), errVal.Steal(), traceback.Steal());
}
}
else
@@ -226,6 +216,8 @@ public IntPtr[] GetTrackedHandles()
return new IntPtr[] { obj };
}
+ internal BorrowedReference GetPythonTypeHandle() => new BorrowedReference(Runtime.PyObject_TYPE(obj));
+
///
/// GetPythonType Method
///
@@ -295,11 +287,10 @@ public PyObject GetAttr(string name)
{
if (name == null) throw new ArgumentNullException(nameof(name));
+ DebugUtil.EnsureGIL();
+
IntPtr op = Runtime.PyObject_GetAttrString(obj, name);
- if (op == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(op);
return new PyObject(op);
}
@@ -311,10 +302,13 @@ public PyObject GetAttr(string name)
/// Returns the named attribute of the Python object, or the given
/// default object if the attribute access fails.
///
+ [Obsolete("This method ignores any Python exceptions, and should not be used. Use GetAttrOrElse.")]
public PyObject GetAttr(string name, PyObject _default)
{
if (name == null) throw new ArgumentNullException(nameof(name));
+ DebugUtil.EnsureGIL();
+
IntPtr op = Runtime.PyObject_GetAttrString(obj, name);
if (op == IntPtr.Zero)
{
@@ -324,6 +318,29 @@ public PyObject GetAttr(string name, PyObject _default)
return new PyObject(op);
}
+ ///
+ /// Gets the specified attribute. If attribute is not found, returns the fallback value.
+ ///
+ public PyObject GetAttrOrElse(string name, PyObject _default)
+ {
+ if (name == null) throw new ArgumentNullException(nameof(name));
+
+ DebugUtil.EnsureGIL();
+
+ IntPtr op = Runtime.PyObject_GetAttrString(obj, name);
+ if (op == IntPtr.Zero)
+ {
+ if (!Exceptions.ExceptionMatches(Exceptions.AttributeError))
+ {
+ throw PythonException.ThrowLastAsClrException();
+ }
+
+ Runtime.PyErr_Clear();
+ return _default;
+ }
+ return new PyObject(op);
+ }
+
///
/// GetAttr Method
@@ -337,11 +354,10 @@ public PyObject GetAttr(PyObject name)
{
if (name == null) throw new ArgumentNullException(nameof(name));
+ DebugUtil.EnsureGIL();
+
IntPtr op = Runtime.PyObject_GetAttr(obj, name.obj);
- if (op == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(op);
return new PyObject(op);
}
@@ -358,6 +374,8 @@ public PyObject GetAttr(PyObject name, PyObject _default)
{
if (name == null) throw new ArgumentNullException(nameof(name));
+ DebugUtil.EnsureGIL();
+
IntPtr op = Runtime.PyObject_GetAttr(obj, name.obj);
if (op == IntPtr.Zero)
{
@@ -380,10 +398,12 @@ public void SetAttr(string name, PyObject value)
if (name == null) throw new ArgumentNullException(nameof(name));
if (value == null) throw new ArgumentNullException(nameof(value));
+ DebugUtil.EnsureGIL();
+
int r = Runtime.PyObject_SetAttrString(obj, name, value.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -401,10 +421,12 @@ public void SetAttr(PyObject name, PyObject value)
if (name == null) throw new ArgumentNullException(nameof(name));
if (value == null) throw new ArgumentNullException(nameof(value));
+ DebugUtil.EnsureGIL();
+
int r = Runtime.PyObject_SetAttr(obj, name.obj, value.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -420,10 +442,12 @@ public void DelAttr(string name)
{
if (name == null) throw new ArgumentNullException(nameof(name));
+ DebugUtil.EnsureGIL();
+
int r = Runtime.PyObject_SetAttrString(obj, name, IntPtr.Zero);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -440,10 +464,12 @@ public void DelAttr(PyObject name)
{
if (name == null) throw new ArgumentNullException(nameof(name));
+ DebugUtil.EnsureGIL();
+
int r = Runtime.PyObject_SetAttr(obj, name.obj, IntPtr.Zero);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -460,12 +486,15 @@ public virtual PyObject GetItem(PyObject key)
{
if (key == null) throw new ArgumentNullException(nameof(key));
- IntPtr op = Runtime.PyObject_GetItem(obj, key.obj);
- if (op == IntPtr.Zero)
+ DebugUtil.EnsureGIL();
+
+ using var op = Runtime.PyObject_GetItem(Reference, key.Reference);
+ if (op.IsNull())
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
- return new PyObject(op);
+
+ return op.MoveToPyObject();
}
@@ -518,10 +547,12 @@ public virtual void SetItem(PyObject key, PyObject value)
if (key == null) throw new ArgumentNullException(nameof(key));
if (value == null) throw new ArgumentNullException(nameof(value));
+ DebugUtil.EnsureGIL();
+
int r = Runtime.PyObject_SetItem(obj, key.obj, value.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -577,10 +608,12 @@ public virtual void DelItem(PyObject key)
{
if (key == null) throw new ArgumentNullException(nameof(key));
+ DebugUtil.EnsureGIL();
+
int r = Runtime.PyObject_DelItem(obj, key.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -624,17 +657,14 @@ public virtual void DelItem(int index)
///
/// Length Method
///
- ///
- /// Returns the length for objects that support the Python sequence
- /// protocol, or 0 if the object does not support the protocol.
- ///
public virtual long Length()
{
+ DebugUtil.EnsureGIL();
+
var s = Runtime.PyObject_Size(obj);
if (s < 0)
{
- Runtime.PyErr_Clear();
- return 0;
+ throw PythonException.ThrowLastAsClrException();
}
return s;
}
@@ -690,14 +720,12 @@ public virtual PyObject this[int index]
/// to the Python expression "iter(object)". A PythonException will be
/// raised if the object cannot be iterated.
///
- public PyObject GetIterator()
+ public PyIter GetIterator()
{
- IntPtr r = Runtime.PyObject_GetIter(obj);
- if (r == IntPtr.Zero)
- {
- throw new PythonException();
- }
- return new PyObject(r);
+ DebugUtil.EnsureGIL();
+ using var r = Runtime.PyObject_GetIter(Reference);
+ Exceptions.ErrorCheck(r);
+ return new PyIter(r);
}
///
@@ -708,10 +736,7 @@ public PyObject GetIterator()
/// python object to be iterated over in C#. A PythonException will be
/// raised if the object is not iterable.
///
- public IEnumerator GetEnumerator()
- {
- return new PyIter(this);
- }
+ public IEnumerator GetEnumerator() => this.GetIterator();
///
@@ -726,13 +751,12 @@ public PyObject Invoke(params PyObject[] args)
if (args == null) throw new ArgumentNullException(nameof(args));
if (args.Contains(null)) throw new ArgumentNullException();
+ DebugUtil.EnsureGIL();
+
var t = new PyTuple(args);
IntPtr r = Runtime.PyObject_Call(obj, t.obj, IntPtr.Zero);
t.Dispose();
- if (r == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(r);
return new PyObject(r);
}
@@ -748,11 +772,10 @@ public PyObject Invoke(PyTuple args)
{
if (args == null) throw new ArgumentNullException(nameof(args));
+ DebugUtil.EnsureGIL();
+
IntPtr r = Runtime.PyObject_Call(obj, args.obj, IntPtr.Zero);
- if (r == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(r);
return new PyObject(r);
}
@@ -769,13 +792,12 @@ public PyObject Invoke(PyObject[] args, PyDict kw)
if (args == null) throw new ArgumentNullException(nameof(args));
if (args.Contains(null)) throw new ArgumentNullException();
+ DebugUtil.EnsureGIL();
+
var t = new PyTuple(args);
IntPtr r = Runtime.PyObject_Call(obj, t.obj, kw?.obj ?? IntPtr.Zero);
t.Dispose();
- if (r == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(r);
return new PyObject(r);
}
@@ -791,11 +813,10 @@ public PyObject Invoke(PyTuple args, PyDict kw)
{
if (args == null) throw new ArgumentNullException(nameof(args));
+ DebugUtil.EnsureGIL();
+
IntPtr r = Runtime.PyObject_Call(obj, args.obj, kw?.obj ?? IntPtr.Zero);
- if (r == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(r);
return new PyObject(r);
}
@@ -843,7 +864,7 @@ public PyObject InvokeMethod(string name, PyTuple args)
///
///
/// Invoke the named method of the object with the given arguments.
- /// A PythonException is raised if the invocation is unsuccessful.
+ /// A PythonException is raised if the invokation is unsuccessful.
///
public PyObject InvokeMethod(PyObject name, params PyObject[] args)
{
@@ -863,7 +884,7 @@ public PyObject InvokeMethod(PyObject name, params PyObject[] args)
///
///
/// Invoke the named method of the object with the given arguments.
- /// A PythonException is raised if the invocation is unsuccessful.
+ /// A PythonException is raised if the invokation is unsuccessful.
///
public PyObject InvokeMethod(PyObject name, PyTuple args)
{
@@ -929,6 +950,8 @@ public bool IsInstance(PyObject typeOrClass)
{
if (typeOrClass == null) throw new ArgumentNullException(nameof(typeOrClass));
+ DebugUtil.EnsureGIL();
+
int r = Runtime.PyObject_IsInstance(obj, typeOrClass.obj);
if (r < 0)
{
@@ -950,6 +973,8 @@ public bool IsSubclass(PyObject typeOrClass)
{
if (typeOrClass == null) throw new ArgumentNullException(nameof(typeOrClass));
+ DebugUtil.EnsureGIL();
+
int r = Runtime.PyObject_IsSubclass(obj, typeOrClass.obj);
if (r < 0)
{
@@ -969,6 +994,7 @@ public bool IsSubclass(PyObject typeOrClass)
///
public bool IsCallable()
{
+ DebugUtil.EnsureGIL();
return Runtime.PyCallable_Check(obj) != 0;
}
@@ -982,7 +1008,8 @@ public bool IsCallable()
///
public bool IsIterable()
{
- return Runtime.PyObject_IsIterable(obj);
+ DebugUtil.EnsureGIL();
+ return Runtime.PyObject_IsIterable(Reference);
}
@@ -995,6 +1022,7 @@ public bool IsIterable()
///
public bool IsTrue()
{
+ DebugUtil.EnsureGIL();
return Runtime.PyObject_IsTrue(obj) != 0;
}
@@ -1012,11 +1040,9 @@ public bool IsTrue()
///
public PyList Dir()
{
+ DebugUtil.EnsureGIL();
IntPtr r = Runtime.PyObject_Dir(obj);
- if (r == IntPtr.Zero)
- {
- throw new PythonException();
- }
+ Exceptions.ErrorCheck(r);
return new PyList(r);
}
@@ -1030,6 +1056,7 @@ public PyList Dir()
///
public string Repr()
{
+ DebugUtil.EnsureGIL();
IntPtr strval = Runtime.PyObject_Repr(obj);
string result = Runtime.GetManagedString(strval);
Runtime.XDecref(strval);
@@ -1046,12 +1073,18 @@ public string Repr()
///
public override string ToString()
{
+ DebugUtil.EnsureGIL();
IntPtr strval = Runtime.PyObject_Unicode(obj);
+ PythonException.ThrowIfIsNull(strval);
string result = Runtime.GetManagedString(strval);
Runtime.XDecref(strval);
return result;
}
+ string DebuggerDisplay => DebugUtil.HaveInterpreterLock() != false
+ ? this.ToString()
+ : $"pyobj at 0x{this.obj:X} (get Py.GIL to see more info)";
+
///
/// Equals Method
@@ -1070,10 +1103,11 @@ public override bool Equals(object o)
{
return true;
}
+ DebugUtil.EnsureGIL();
int r = Runtime.PyObject_Compare(obj, ((PyObject)o).obj);
if (Exceptions.ErrorOccurred())
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
return r == 0;
}
@@ -1089,9 +1123,25 @@ public override bool Equals(object o)
///
public override int GetHashCode()
{
+ DebugUtil.EnsureGIL();
return ((ulong)Runtime.PyObject_Hash(obj)).GetHashCode();
}
+ ///
+ /// GetBuffer Method. This Method only works for objects that have a buffer (like "bytes", "bytearray" or "array.array")
+ ///
+ ///
+ /// Send a request to the PyObject to fill in view as specified by flags. If the PyObject cannot provide a buffer of the exact type, it MUST raise PyExc_BufferError, set view->obj to NULL and return -1.
+ /// On success, fill in view, set view->obj to a new reference to exporter and return 0. In the case of chained buffer providers that redirect requests to a single object, view->obj MAY refer to this object instead of exporter(See Buffer Object Structures).
+ /// Successful calls to must be paired with calls to , similar to malloc() and free(). Thus, after the consumer is done with the buffer, must be called exactly once.
+ ///
+ public PyBuffer GetBuffer(PyBUF flags = PyBUF.SIMPLE)
+ {
+ if (Runtime.PythonVersion < new Version(3, 5))
+ throw new NotSupportedException("GetBuffer requires at least Python 3.5");
+ return new PyBuffer(this, flags);
+ }
+
public long Refcount
{
@@ -1110,11 +1160,12 @@ public override bool TryGetMember(GetMemberBinder binder, out object result)
public override bool TrySetMember(SetMemberBinder binder, object value)
{
- IntPtr ptr = Converter.ToPython(value, value?.GetType());
+ DebugUtil.EnsureGIL();
+ IntPtr ptr = Converter.ToPython(value);
int r = Runtime.PyObject_SetAttrString(obj, binder.Name, ptr);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
Runtime.XDecref(ptr);
return true;
@@ -1132,6 +1183,7 @@ private void GetArgs(object[] inargs, CallInfo callInfo, out PyTuple args, out P
var namedArgumentCount = callInfo.ArgumentNames.Count;
var regularArgumentCount = callInfo.ArgumentCount - namedArgumentCount;
+ DebugUtil.EnsureGIL();
var argTuple = Runtime.PyTuple_New(regularArgumentCount);
for (int i = 0; i < regularArgumentCount; ++i)
{
@@ -1155,6 +1207,7 @@ private void GetArgs(object[] inargs, out PyTuple args, out PyDict kwargs)
{
;
}
+ DebugUtil.EnsureGIL();
IntPtr argtuple = Runtime.PyTuple_New(arg_count);
for (var i = 0; i < arg_count; i++)
{
@@ -1182,11 +1235,12 @@ private void GetArgs(object[] inargs, out PyTuple args, out PyDict kwargs)
private static void AddArgument(IntPtr argtuple, int i, object target)
{
+ DebugUtil.EnsureGIL();
IntPtr ptr = GetPythonObject(target);
if (Runtime.PyTuple_SetItem(argtuple, i, ptr) < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -1200,7 +1254,7 @@ private static IntPtr GetPythonObject(object target)
}
else
{
- ptr = Converter.ToPython(target, target?.GetType());
+ ptr = Converter.ToPython(target);
}
return ptr;
@@ -1273,6 +1327,7 @@ public override bool TryConvert(ConvertBinder binder, out object result)
public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
{
+ DebugUtil.EnsureGIL();
IntPtr res;
if (!(arg is PyObject))
{
@@ -1363,6 +1418,7 @@ public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg
result = null;
return false;
}
+ Exceptions.ErrorCheck(res);
result = CheckNone(new PyObject(res));
return true;
}
@@ -1384,6 +1440,7 @@ private static object CheckNone(PyObject pyObj)
public override bool TryUnaryOperation(UnaryOperationBinder binder, out object result)
{
+ DebugUtil.EnsureGIL();
int r;
IntPtr res;
switch (binder.Operation)
@@ -1415,6 +1472,7 @@ public override bool TryUnaryOperation(UnaryOperationBinder binder, out object r
result = null;
return false;
}
+ Exceptions.ErrorCheck(res);
result = CheckNone(new PyObject(res));
return true;
}
@@ -1433,5 +1491,7 @@ public override IEnumerable GetDynamicMemberNames()
yield return pyObj.ToString();
}
}
+
+ public PyObject Clone() => new PyObject(Runtime.SelfIncRef(this.Handle));
}
}
diff --git a/src/runtime/pyscope.cs b/src/runtime/pyscope.cs
index 8738824f5..f9c4b19f7 100644
--- a/src/runtime/pyscope.cs
+++ b/src/runtime/pyscope.cs
@@ -22,22 +22,15 @@ public class PyGILAttribute : Attribute
}
[PyGIL]
- public class PyScope : DynamicObject, IPyDisposable
+ public class PyScope : PyObject, IPyDisposable
{
- public readonly string Name;
-
- ///
- /// the python Module object the scope associated with.
- ///
- internal readonly IntPtr obj;
+ public string Name { get; }
///
/// the variable dict of the scope.
///
- internal readonly IntPtr variables;
-
- private bool _isDisposed;
- private bool _finalized = false;
+ internal IntPtr variables;
+ internal BorrowedReference VarsReference => new BorrowedReference(variables);
///
/// The Manager this scope associated with.
@@ -56,20 +49,23 @@ public class PyScope : DynamicObject, IPyDisposable
///
/// Create a scope based on a Python Module.
///
- internal PyScope(IntPtr ptr, PyScopeManager manager)
+ internal PyScope(IntPtr ptr, PyScopeManager manager): base(ptr)
{
if (!Runtime.PyType_IsSubtype(Runtime.PyObject_TYPE(ptr), Runtime.PyModuleType))
{
throw new PyScopeException("object is not a module");
}
Manager = manager ?? PyScopeManager.Global;
- obj = ptr;
//Refcount of the variables not increase
variables = Runtime.PyModule_GetDict(obj);
+ if (variables == IntPtr.Zero)
+ {
+ throw new ArgumentException(message: "Scope does not have '__dict__'");
+ }
Runtime.CheckExceptionOccurred();
Runtime.PyDict_SetItemString(
- variables, "__builtins__",
+ VarsReference, "__builtins__",
Runtime.PyEval_GetBuiltins()
);
this.Name = this.Get("__name__");
@@ -81,6 +77,8 @@ internal PyScope(IntPtr ptr, PyScopeManager manager)
///
public PyDict Variables()
{
+ this.EnsureNotDisposed();
+
Runtime.XIncref(variables);
return new PyDict(variables);
}
@@ -91,6 +89,8 @@ public PyDict Variables()
///
public PyScope NewScope()
{
+ this.EnsureNotDisposed();
+
var scope = Manager.Create();
scope.ImportAll(this);
return scope;
@@ -105,7 +105,9 @@ public PyScope NewScope()
///
public dynamic Import(string name, string asname = null)
{
- Check();
+ if (name is null) throw new ArgumentNullException(nameof(name));
+ this.EnsureNotDisposed();
+
if (String.IsNullOrEmpty(asname))
{
asname = name;
@@ -133,7 +135,9 @@ public dynamic Import(string name, string asname = null)
///
public void Import(PyScope scope, string asname)
{
- this.Set(asname, scope.obj);
+ if (scope is null) throw new ArgumentNullException(nameof(scope));
+
+ this.SetInternal(asname, scope.Reference);
}
///
@@ -145,6 +149,8 @@ public void Import(PyScope scope, string asname)
///
public void Import(PyObject module, string asname = null)
{
+ if (module is null) throw new ArgumentNullException(nameof(module));
+
if (String.IsNullOrEmpty(asname))
{
asname = module.GetAttr("__name__").As();
@@ -161,6 +167,8 @@ public void Import(PyObject module, string asname = null)
///
public void ImportAll(string name)
{
+ if (name is null) throw new ArgumentNullException(nameof(name));
+
PyScope scope;
Manager.TryGet(name, out scope);
if (scope != null)
@@ -183,10 +191,13 @@ public void ImportAll(string name)
///
public void ImportAll(PyScope scope)
{
+ if (scope is null) throw new ArgumentNullException(nameof(scope));
+ this.EnsureNotDisposed();
+
int result = Runtime.PyDict_Update(variables, scope.variables);
if (result < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -198,15 +209,18 @@ public void ImportAll(PyScope scope)
///
public void ImportAll(PyObject module)
{
+ if (module is null) throw new ArgumentNullException(nameof(module));
+ this.EnsureNotDisposed();
if (Runtime.PyObject_Type(module.obj) != Runtime.PyModuleType)
{
throw new PyScopeException("object is not a module");
}
+
var module_dict = Runtime.PyModule_GetDict(module.obj);
int result = Runtime.PyDict_Update(variables, module_dict);
if (result < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -218,10 +232,13 @@ public void ImportAll(PyObject module)
///
public void ImportAll(PyDict dict)
{
+ if (dict is null) throw new ArgumentNullException(nameof(dict));
+ this.EnsureNotDisposed();
+
int result = Runtime.PyDict_Update(variables, dict.obj);
if (result < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -234,7 +251,9 @@ public void ImportAll(PyDict dict)
///
public PyObject Execute(PyObject script, PyDict locals = null)
{
- Check();
+ if (script is null) throw new ArgumentNullException(nameof(script));
+ this.EnsureNotDisposed();
+
IntPtr _locals = locals == null ? variables : locals.obj;
IntPtr ptr = Runtime.PyEval_EvalCode(script.Handle, variables, _locals);
Runtime.CheckExceptionOccurred();
@@ -256,14 +275,12 @@ public PyObject Execute(PyObject script, PyDict locals = null)
///
public T Execute(PyObject script, PyDict locals = null)
{
- Check();
PyObject pyObj = Execute(script, locals);
if (pyObj == null)
{
return default(T);
}
- var obj = pyObj.As();
- return obj;
+ return pyObj.As();
}
///
@@ -275,7 +292,8 @@ public T Execute(PyObject script, PyDict locals = null)
///
public PyObject Eval(string code, PyDict locals = null)
{
- Check();
+ this.EnsureNotDisposed();
+
IntPtr _locals = locals == null ? variables : locals.obj;
var flag = (IntPtr)Runtime.Py_eval_input;
@@ -302,10 +320,8 @@ public PyObject Eval(string code, PyDict locals = null)
///
public T Eval(string code, PyDict locals = null)
{
- Check();
PyObject pyObj = Eval(code, locals);
- var obj = pyObj.As();
- return obj;
+ return pyObj.As();
}
///
@@ -316,13 +332,14 @@ public T Eval(string code, PyDict locals = null)
///
public void Exec(string code, PyDict locals = null)
{
- Check();
IntPtr _locals = locals == null ? variables : locals.obj;
Exec(code, variables, _locals);
}
private void Exec(string code, IntPtr _globals, IntPtr _locals)
{
+ this.EnsureNotDisposed();
+
var flag = (IntPtr)Runtime.Py_file_input;
NewReference reference = Runtime.PyRun_String(
code, flag, _globals, _locals
@@ -333,7 +350,7 @@ private void Exec(string code, IntPtr _globals, IntPtr _locals)
Runtime.CheckExceptionOccurred();
if (!reference.IsNone())
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
finally
@@ -351,20 +368,28 @@ private void Exec(string code, IntPtr _globals, IntPtr _locals)
///
public void Set(string name, object value)
{
- IntPtr _value = Converter.ToPython(value, value?.GetType());
- Set(name, _value);
- Runtime.XDecref(_value);
+ this.EnsureNotDisposed();
+
+ IntPtr _value = Converter.ToPython(value);
+ try
+ {
+ this.SetInternal(name, new BorrowedReference(_value));
+ }
+ finally
+ {
+ Runtime.XDecref(_value);
+ }
}
- private void Set(string name, IntPtr value)
+ private void SetInternal(string name, BorrowedReference value)
{
- Check();
+ this.EnsureNotDisposed();
using (var pyKey = new PyString(name))
{
- int r = Runtime.PyObject_SetItem(variables, pyKey.obj, value);
+ int r = Runtime.PyObject_SetItem(variables, pyKey.obj, value.DangerousGetAddress());
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
}
@@ -377,13 +402,14 @@ private void Set(string name, IntPtr value)
///
public void Remove(string name)
{
- Check();
+ this.EnsureNotDisposed();
+
using (var pyKey = new PyString(name))
{
int r = Runtime.PyObject_DelItem(variables, pyKey.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
}
@@ -396,7 +422,8 @@ public void Remove(string name)
///
public bool Contains(string name)
{
- Check();
+ this.EnsureNotDisposed();
+
using (var pyKey = new PyString(name))
{
return Runtime.PyMapping_HasKey(variables, pyKey.obj) != 0;
@@ -430,23 +457,23 @@ public PyObject Get(string name)
///
public bool TryGet(string name, out PyObject value)
{
- Check();
+ this.EnsureNotDisposed();
+
using (var pyKey = new PyString(name))
{
if (Runtime.PyMapping_HasKey(variables, pyKey.obj) != 0)
{
- IntPtr op = Runtime.PyObject_GetItem(variables, pyKey.obj);
- if (op == IntPtr.Zero)
+ using var op = Runtime.PyObject_GetItem(VarsReference, pyKey.Reference);
+ if (op.IsNull())
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
- if (op == Runtime.PyNone)
+ if (op.IsNone())
{
- Runtime.XDecref(op);
value = null;
return true;
}
- value = new PyObject(op);
+ value = op.MoveToPyObject();
return true;
}
else
@@ -467,7 +494,8 @@ public bool TryGet(string name, out PyObject value)
///
public T Get(string name)
{
- Check();
+ this.EnsureNotDisposed();
+
PyObject pyObj = Get(name);
if (pyObj == null)
{
@@ -486,7 +514,8 @@ public T Get(string name)
///
public bool TryGet(string name, out T value)
{
- Check();
+ this.EnsureNotDisposed();
+
PyObject pyObj;
var result = TryGet(name, out pyObj);
if (!result)
@@ -522,38 +551,24 @@ public override bool TrySetMember(SetMemberBinder binder, object value)
return true;
}
- private void Check()
+ private void EnsureNotDisposed()
{
- if (_isDisposed)
+ if (this.obj == IntPtr.Zero)
{
- throw new PyScopeException($"The scope of name '{Name}' object has been disposed");
+ throw new ObjectDisposedException(
+ objectName: this.Name,
+ message: $"The scope object has been disposed");
}
}
- public void Dispose()
+ protected override void Dispose(bool disposing)
{
- if (_isDisposed)
+ this.variables = IntPtr.Zero;
+ if (disposing)
{
- return;
- }
- _isDisposed = true;
- Runtime.XDecref(obj);
- this.OnDispose?.Invoke(this);
- }
-
- public IntPtr[] GetTrackedHandles()
- {
- return new IntPtr[] { obj };
- }
-
- ~PyScope()
- {
- if (_finalized || _isDisposed)
- {
- return;
+ this.OnDispose?.Invoke(this);
}
- _finalized = true;
- Finalizer.Instance.AddFinalizedObject(this);
+ base.Dispose(disposing);
}
}
@@ -577,7 +592,7 @@ internal PyScope NewScope(string name)
var module = Runtime.PyModule_New(name);
if (module == IntPtr.Zero)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
return new PyScope(module, this);
}
diff --git a/src/runtime/pysequence.cs b/src/runtime/pysequence.cs
index bfaee79a6..5010531c4 100644
--- a/src/runtime/pysequence.cs
+++ b/src/runtime/pysequence.cs
@@ -12,10 +12,12 @@ namespace Python.Runtime
///
public class PySequence : PyObject, IEnumerable
{
- protected PySequence(IntPtr ptr) : base(ptr)
+ public PySequence(IntPtr ptr) : base(ptr)
{
}
+ internal PySequence(BorrowedReference reference) : base(reference) { }
+ [Obsolete]
protected PySequence()
{
}
@@ -44,7 +46,7 @@ public PyObject GetSlice(int i1, int i2)
IntPtr op = Runtime.PySequence_GetSlice(obj, i1, i2);
if (op == IntPtr.Zero)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
return new PyObject(op);
}
@@ -61,7 +63,7 @@ public void SetSlice(int i1, int i2, PyObject v)
int r = Runtime.PySequence_SetSlice(obj, i1, i2, v.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -77,7 +79,7 @@ public void DelSlice(int i1, int i2)
int r = Runtime.PySequence_DelSlice(obj, i1, i2);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -113,7 +115,7 @@ public bool Contains(PyObject item)
int r = Runtime.PySequence_Contains(obj, item.obj);
if (r < 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
return r != 0;
}
@@ -131,7 +133,7 @@ public PyObject Concat(PyObject other)
IntPtr op = Runtime.PySequence_Concat(obj, other.obj);
if (op == IntPtr.Zero)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
return new PyObject(op);
}
@@ -149,7 +151,7 @@ public PyObject Repeat(int count)
IntPtr op = Runtime.PySequence_Repeat(obj, count);
if (op == IntPtr.Zero)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
return new PyObject(op);
}
diff --git a/src/runtime/pystring.cs b/src/runtime/pystring.cs
index c9c4f9f5b..85b5af618 100644
--- a/src/runtime/pystring.cs
+++ b/src/runtime/pystring.cs
@@ -34,14 +34,19 @@ public PyString(IntPtr ptr) : base(ptr)
/// An ArgumentException will be thrown if the given object is not
/// a Python string object.
///
- public PyString(PyObject o)
+ public PyString(PyObject o):base(FromString(o))
{
+ }
+
+ static IntPtr FromString(PyObject o)
+ {
+ if (o == null) throw new ArgumentNullException(nameof(o));
if (!IsStringType(o))
{
throw new ArgumentException("object is not a string");
}
Runtime.XIncref(o.obj);
- obj = o.obj;
+ return o.obj;
}
@@ -51,10 +56,10 @@ public PyString(PyObject o)
///
/// Creates a Python string from a managed string.
///
- public PyString(string s)
+ public PyString(string s):base(
+ Exceptions.ErrorOccurredCheck(
+ Runtime.PyUnicode_FromUnicode(s ?? throw new ArgumentNullException(nameof(s)), s.Length)))
{
- obj = Runtime.PyUnicode_FromUnicode(s, s.Length);
- Runtime.CheckExceptionOccurred();
}
@@ -64,8 +69,9 @@ public PyString(string s)
///
/// Returns true if the given object is a Python string.
///
- public static bool IsStringType(PyObject value)
- {
+ public static bool IsStringType(PyObject value) {
+ if (value == null) throw new ArgumentNullException(nameof(value));
+
return Runtime.PyString_Check(value.obj);
}
}
diff --git a/src/runtime/pythonengine.cs b/src/runtime/pythonengine.cs
index 11fc88cd4..ddbb5e38c 100644
--- a/src/runtime/pythonengine.cs
+++ b/src/runtime/pythonengine.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -17,6 +18,7 @@ public class PythonEngine : IDisposable
private static IntPtr _pythonHome = IntPtr.Zero;
private static IntPtr _programName = IntPtr.Zero;
private static IntPtr _pythonPath = IntPtr.Zero;
+ private static InteropConfiguration interopConfiguration = InteropConfiguration.MakeDefault();
public PythonEngine()
{
@@ -56,6 +58,18 @@ internal static DelegateManager DelegateManager
}
}
+ public static InteropConfiguration InteropConfiguration
+ {
+ get => interopConfiguration;
+ set
+ {
+ if (IsInitialized)
+ throw new NotSupportedException("Changing interop configuration when engine is running is not supported");
+
+ interopConfiguration = value ?? throw new ArgumentNullException(nameof(InteropConfiguration));
+ }
+ }
+
public static string ProgramName
{
get
@@ -96,10 +110,6 @@ public static string PythonPath
}
set
{
- if (Runtime.IsPython2)
- {
- throw new NotSupportedException("Set PythonPath not supported on Python 2");
- }
Marshal.FreeHGlobal(_pythonPath);
_pythonPath = UcsMarshaler.Py3UnicodePy2StringtoPtr(value);
Runtime.Py_SetPath(_pythonPath);
@@ -205,15 +215,13 @@ public static void Initialize(IEnumerable args, bool setSysArgv = true,
// Load the clr.py resource into the clr module
IntPtr clr = Python.Runtime.ImportHook.GetCLRModule();
- IntPtr clr_dict = Runtime.PyModule_GetDict(clr);
+ var clr_dict = Runtime.PyModule_GetDict(new BorrowedReference(clr));
var locals = new PyDict();
try
{
- IntPtr module = Runtime.PyImport_AddModule("clr._extras");
- IntPtr module_globals = Runtime.PyModule_GetDict(module);
- IntPtr builtins = Runtime.PyEval_GetBuiltins();
- Runtime.PyDict_SetItemString(module_globals, "__builtins__", builtins);
+ var module = DefineModule("clr._extras");
+ var module_globals = Runtime.PyModule_GetDict(module);
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("clr.py"))
@@ -221,9 +229,13 @@ public static void Initialize(IEnumerable args, bool setSysArgv = true,
{
// add the contents of clr.py to the module
string clr_py = reader.ReadToEnd();
- Exec(clr_py, module_globals, locals.Handle);
+ Exec(clr_py, module_globals.DangerousGetAddress(), locals.Handle);
}
+ LoadMixins(module_globals);
+
+ LoadSubmodule(module_globals, "clr.interop", "interop.py");
+
// add the imported module to the clr module, and copy the API functions
// and decorators into the main clr module.
Runtime.PyDict_SetItemString(clr_dict, "_extras", module);
@@ -232,7 +244,7 @@ public static void Initialize(IEnumerable args, bool setSysArgv = true,
if (!key.ToString().StartsWith("_") || key.ToString().Equals("__version__"))
{
PyObject value = locals[key];
- Runtime.PyDict_SetItem(clr_dict, key.Handle, value.Handle);
+ Runtime.PyDict_SetItem(clr_dict, key.Reference, value.Reference);
value.Dispose();
}
key.Dispose();
@@ -245,6 +257,43 @@ public static void Initialize(IEnumerable args, bool setSysArgv = true,
}
}
+ static BorrowedReference DefineModule(string name)
+ {
+ var module = Runtime.PyImport_AddModule(name);
+ var module_globals = Runtime.PyModule_GetDict(module);
+ var builtins = Runtime.PyEval_GetBuiltins();
+ int r = Runtime.PyDict_SetItemString(module_globals, "__builtins__", builtins);
+ PythonException.ThrowIfIsNotZero(r);
+ return module;
+ }
+
+ static void LoadMixins(BorrowedReference targetModuleDict)
+ {
+ foreach (string nested in new[] {"collections"})
+ {
+ LoadSubmodule(targetModuleDict,
+ fullName: "clr._extras." + nested,
+ resourceName: typeof(PythonEngine).Namespace + ".Mixins." + nested + ".py");
+ }
+ }
+
+ static void LoadSubmodule(BorrowedReference targetModuleDict, string fullName, string resourceName)
+ {
+ string memberName = fullName.AfterLast('.');
+ Debug.Assert(memberName != null);
+ Assembly assembly = Assembly.GetExecutingAssembly();
+ var module = DefineModule(fullName);
+ var module_globals = Runtime.PyModule_GetDict(module);
+ using (var stream = assembly.GetManifestResourceStream(resourceName))
+ using (var reader = new StreamReader(stream))
+ {
+ string pyCode = reader.ReadToEnd();
+ Exec(pyCode, module_globals.DangerousGetAddress(), module_globals.DangerousGetAddress());
+ }
+
+ Runtime.PyDict_SetItemString(targetModuleDict, memberName, module);
+ }
+
static void OnDomainUnload(object _, EventArgs __)
{
Shutdown();
@@ -255,11 +304,7 @@ static void OnDomainUnload(object _, EventArgs __)
/// CPython interpreter process - this bootstraps the managed runtime
/// when it is imported by the CLR extension module.
///
-#if PYTHON3
public static IntPtr InitExt()
-#elif PYTHON2
- public static void InitExt()
-#endif
{
try
{
@@ -299,14 +344,10 @@ public static void InitExt()
catch (PythonException e)
{
e.Restore();
-#if PYTHON3
return IntPtr.Zero;
-#endif
}
-#if PYTHON3
return Python.Runtime.ImportHook.GetCLRModule();
-#endif
}
///
@@ -322,7 +363,7 @@ public static void Shutdown()
if (initialized)
{
PyScopeManager.Global.Clear();
-
+
// If the shutdown handlers trigger a domain unload,
// don't call shutdown again.
AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload;
@@ -332,6 +373,8 @@ public static void Shutdown()
PyObjectConversions.Reset();
initialized = false;
+
+ InteropConfiguration = InteropConfiguration.MakeDefault();
}
}
@@ -477,7 +520,7 @@ public static void EndAllowThreads(IntPtr ts)
public static PyObject ImportModule(string name)
{
IntPtr op = Runtime.PyImport_ImportModule(name);
- Runtime.CheckExceptionOccurred();
+ Exceptions.ErrorCheck(op);
return new PyObject(op);
}
@@ -492,7 +535,7 @@ public static PyObject ImportModule(string name)
public static PyObject ReloadModule(PyObject module)
{
IntPtr op = Runtime.PyImport_ReloadModule(module.Handle);
- Runtime.CheckExceptionOccurred();
+ Exceptions.ErrorCheck(op);
return new PyObject(op);
}
@@ -507,9 +550,9 @@ public static PyObject ReloadModule(PyObject module)
public static PyObject ModuleFromString(string name, string code)
{
IntPtr c = Runtime.Py_CompileString(code, "none", (int)RunFlagType.File);
- Runtime.CheckExceptionOccurred();
+ Exceptions.ErrorCheck(c);
IntPtr m = Runtime.PyImport_ExecCodeModule(name, c);
- Runtime.CheckExceptionOccurred();
+ Exceptions.ErrorCheck(c);
return new PyObject(m);
}
@@ -517,7 +560,7 @@ public static PyObject Compile(string code, string filename = "", RunFlagType mo
{
var flag = (int)mode;
IntPtr ptr = Runtime.Py_CompileString(code, filename, flag);
- Runtime.CheckExceptionOccurred();
+ Exceptions.ErrorCheck(ptr);
return new PyObject(ptr);
}
@@ -548,7 +591,7 @@ public static void Exec(string code, IntPtr? globals = null, IntPtr? locals = nu
{
if (result.obj != Runtime.PyNone)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
}
@@ -582,13 +625,13 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals,
{
globals = Runtime.PyDict_New();
Runtime.PyDict_SetItemString(
- globals.Value, "__builtins__",
+ new BorrowedReference(globals.Value), "__builtins__",
Runtime.PyEval_GetBuiltins()
);
borrowedGlobals = false;
}
}
-
+
if (locals == null)
{
locals = globals;
@@ -651,7 +694,7 @@ public static PyScope CreateScope(string name)
var scope = PyScopeManager.Global.Create(name);
return scope;
}
-
+
public class GILState : IDisposable
{
private readonly IntPtr state;
@@ -697,7 +740,7 @@ public static KeywordArguments kw(params object[] kv)
}
else
{
- value = Converter.ToPython(kv[i + 1], kv[i + 1]?.GetType());
+ value = Converter.ToPython(kv[i + 1]);
}
if (Runtime.PyDict_SetItemString(dict.Handle, (string)kv[i], value) != 0)
{
@@ -752,7 +795,7 @@ public static void SetArgv(IEnumerable argv)
public static void With(PyObject obj, Action Body)
{
- // Behavior described here:
+ // Behavior described here:
// https://docs.python.org/2/reference/datamodel.html#with-statement-context-managers
IntPtr type = Runtime.PyNone;
diff --git a/src/runtime/pythonexception.cs b/src/runtime/pythonexception.cs
index 8efdccc91..45cf43572 100644
--- a/src/runtime/pythonexception.cs
+++ b/src/runtime/pythonexception.cs
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
+using System.Runtime.ExceptionServices;
using System.Text;
namespace Python.Runtime
@@ -13,48 +14,208 @@ public class PythonException : System.Exception, IPyDisposable
private IntPtr _pyType = IntPtr.Zero;
private IntPtr _pyValue = IntPtr.Zero;
private IntPtr _pyTB = IntPtr.Zero;
- private string _tb = "";
+ private string _traceback = "";
private string _message = "";
private string _pythonTypeName = "";
- private bool disposed = false;
- private bool _finalized = false;
+ [Obsolete("Please, use FromPyErr instead")]
public PythonException()
{
IntPtr gs = PythonEngine.AcquireLock();
- Runtime.PyErr_Fetch(out _pyType, out _pyValue, out _pyTB);
+ Runtime.PyErr_Fetch(out var type, out var value, out var traceback);
+ _pyType = type.IsNull() ? IntPtr.Zero : type.DangerousMoveToPointer();
+ _pyValue = value.IsNull() ? IntPtr.Zero : value.DangerousMoveToPointer();
+ _pyTB = traceback.IsNull() ? IntPtr.Zero : traceback.DangerousMoveToPointer();
if (_pyType != IntPtr.Zero && _pyValue != IntPtr.Zero)
{
- string type;
string message;
Runtime.XIncref(_pyType);
using (var pyType = new PyObject(_pyType))
using (PyObject pyTypeName = pyType.GetAttr("__name__"))
{
- type = pyTypeName.ToString();
+ _pythonTypeName = pyTypeName.ToString();
}
- _pythonTypeName = type;
-
Runtime.XIncref(_pyValue);
using (var pyValue = new PyObject(_pyValue))
{
message = pyValue.ToString();
}
- _message = type + " : " + message;
+ _message = _pythonTypeName + " : " + message;
}
if (_pyTB != IntPtr.Zero)
{
- using (PyObject tb_module = PythonEngine.ImportModule("traceback"))
+ this._traceback = TracebackHandleToString(new BorrowedReference(_pyTB));
+ }
+ PythonEngine.ReleaseLock(gs);
+ }
+
+ private PythonException(BorrowedReference pyTypeHandle,
+ BorrowedReference pyValueHandle,
+ BorrowedReference pyTracebackHandle,
+ string message, string pythonTypeName, string traceback,
+ Exception innerException)
+ : base(message, innerException)
+ {
+ _pyType = pyTypeHandle.DangerousIncRefOrNull();
+ _pyValue = pyValueHandle.DangerousIncRefOrNull();
+ _pyTB = pyTracebackHandle.DangerousIncRefOrNull();
+ _message = message;
+ _pythonTypeName = pythonTypeName ?? _pythonTypeName;
+ _traceback = traceback ?? _traceback;
+ }
+
+ internal static Exception FromPyErr()
+ {
+ Runtime.PyErr_Fetch(out var pyTypeHandle, out var pyValueHandle, out var pyTracebackHandle);
+ using (pyTypeHandle)
+ using (pyValueHandle)
+ using (pyTracebackHandle) {
+ return FromPyErr(
+ pyTypeHandle: pyTypeHandle,
+ pyValueHandle: pyValueHandle,
+ pyTracebackHandle: pyTracebackHandle);
+ }
+ }
+
+ internal static Exception FromPyErrOrNull()
+ {
+ Runtime.PyErr_Fetch(out var pyTypeHandle, out var pyValueHandle, out var pyTracebackHandle);
+ using (pyTypeHandle)
+ using (pyValueHandle)
+ using (pyTracebackHandle) {
+ if (pyValueHandle.IsNull() && pyTypeHandle.IsNull() && pyTracebackHandle.IsNull()) {
+ return null;
+ }
+
+ var result = FromPyErr(pyTypeHandle, pyValueHandle, pyTracebackHandle);
+ return result;
+ }
+ }
+
+ ///
+ /// Rethrows the last Python exception as corresponding CLR exception.
+ /// It is recommended to call this as throw ThrowLastAsClrException()
+ /// to assist control flow checks.
+ ///
+ internal static Exception ThrowLastAsClrException() {
+ // prevent potential interop errors in this method
+ // from crashing process with undebuggable StackOverflowException
+ RuntimeHelpers.EnsureSufficientExecutionStack();
+
+ IntPtr gs = PythonEngine.AcquireLock();
+ try {
+ Runtime.PyErr_Fetch(out var pyTypeHandle, out var pyValueHandle, out var pyTracebackHandle);
+ using (pyTypeHandle)
+ using (pyValueHandle)
+ using (pyTracebackHandle) {
+ var clrObject = ManagedType.GetManagedObject(pyValueHandle) as CLRObject;
+ if (clrObject?.inst is Exception e) {
+#if NETSTANDARD
+ ExceptionDispatchInfo.Capture(e).Throw();
+#endif
+ throw e;
+ }
+
+ var result = FromPyErr(pyTypeHandle, pyValueHandle, pyTracebackHandle);
+ throw result;
+ }
+ } finally {
+ PythonEngine.ReleaseLock(gs);
+ }
+ }
+
+ ///
+ /// Requires lock to be acquired elsewhere
+ ///
+ static Exception FromPyErr(BorrowedReference pyTypeHandle, BorrowedReference pyValueHandle, BorrowedReference pyTracebackHandle) {
+ Exception inner = null;
+ string pythonTypeName = null, msg = "", traceback = null;
+
+ var clrObject = ManagedType.GetManagedObject(pyValueHandle) as CLRObject;
+ if (clrObject?.inst is Exception e) {
+ return e;
+ }
+
+ var errorDict = new PyDict();
+ if (!pyTypeHandle.IsNull) errorDict["type"] = new PyObject(pyTypeHandle);
+ if (!pyValueHandle.IsNull) errorDict["value"] = new PyObject(pyValueHandle);
+ if (!pyTracebackHandle.IsNull) errorDict["traceback"] = new PyObject(pyTracebackHandle);
+
+ object decoded;
+
+ var pyErrType = Runtime.InteropModule.GetAttr("PyErr");
+ using (PyObject pyErrInfo = pyErrType.Invoke(new PyTuple(), errorDict))
+ {
+ if (PyObjectConversions.TryDecode(pyErrInfo.Reference, pyErrType.Reference,
+ typeof(Exception), out decoded) && decoded is Exception decodedPyErrInfo)
{
- Runtime.XIncref(_pyTB);
- using (var pyTB = new PyObject(_pyTB))
+ return decodedPyErrInfo;
+ }
+ }
+
+ if (!pyTypeHandle.IsNull)
+ {
+ if (!pyValueHandle.IsNull)
+ {
+ if (Runtime.PyString_Check(pyValueHandle) && pyTypeHandle != Runtime.PyStringType) {
+ using var type = new PyObject(pyTypeHandle);
+ using var message = new PyObject(pyValueHandle);
+ var instance = type.Invoke(message);
+ if (PyObjectConversions.TryDecode(instance.Reference, pyTypeHandle, typeof(Exception),
+ out decoded) && decoded is Exception decodedExceptionInstance) {
+ return decodedExceptionInstance;
+ }
+ } else if (PyObjectConversions.TryDecode(pyValueHandle, pyTypeHandle, typeof(Exception),
+ out decoded) && decoded is Exception decodedException) {
+ return decodedException;
+ }
+
+ using (var pyValue = new PyObject(pyValueHandle))
{
- _tb = tb_module.InvokeMethod("format_tb", pyTB).ToString();
+ msg = pyValue.ToString();
+ var cause = pyValue.GetAttr("__cause__", null);
+ if (cause != null && cause.Handle != Runtime.PyNone) {
+ using var innerTraceback = cause.GetAttr("__traceback__", null);
+ inner = FromPyErr(
+ pyTypeHandle: cause.GetPythonTypeHandle(),
+ pyValueHandle: cause.Reference,
+ pyTracebackHandle: innerTraceback is null ? new BorrowedReference() : innerTraceback.Reference);
+ }
}
}
+
+ using (var pyType = new PyObject(pyTypeHandle))
+ using (PyObject pyTypeName = pyType.GetAttr("__name__"))
+ {
+ pythonTypeName = pyTypeName.ToString();
+ }
+
+ msg = string.IsNullOrEmpty(msg) ? pythonTypeName : pythonTypeName + " : " + msg;
}
- PythonEngine.ReleaseLock(gs);
+ if (!pyTracebackHandle.IsNull)
+ {
+ traceback = TracebackHandleToString(pyTracebackHandle);
+ }
+
+ return new PythonException(pyTypeHandle, pyValueHandle, pyTracebackHandle,
+ msg, pythonTypeName, traceback, inner);
+ }
+
+ static string TracebackHandleToString(BorrowedReference tracebackHandle) {
+ if (tracebackHandle.IsNull) {
+ throw new ArgumentNullException(nameof(tracebackHandle));
+ }
+
+ PyObject tracebackModule = PythonEngine.ImportModule("traceback");
+ using var traceback = new PyObject(tracebackHandle);
+ PyList stackLines = PyList.Wrap(tracebackModule.InvokeMethod("format_tb", traceback));
+ stackLines.Reverse();
+ var result = new StringBuilder();
+ foreach (object stackLine in stackLines) {
+ result.Append(stackLine);
+ }
+ return result.ToString();
}
// Ensure that encapsulated Python objects are decref'ed appropriately
@@ -62,11 +223,10 @@ public PythonException()
~PythonException()
{
- if (_finalized || disposed)
+ if (this.IsDisposed)
{
return;
}
- _finalized = true;
Finalizer.Instance.AddFinalizedObject(this);
}
@@ -76,10 +236,10 @@ public PythonException()
public void Restore()
{
IntPtr gs = PythonEngine.AcquireLock();
- Runtime.PyErr_Restore(_pyType, _pyValue, _pyTB);
- _pyType = IntPtr.Zero;
- _pyValue = IntPtr.Zero;
- _pyTB = IntPtr.Zero;
+ Runtime.PyErr_Restore(
+ NewReference.DangerousMoveFromPointer(ref _pyType).Steal(),
+ NewReference.DangerousMoveFromPointer(ref _pyValue).Steal(),
+ NewReference.DangerousMoveFromPointer(ref _pyTB).Steal());
PythonEngine.ReleaseLock(gs);
}
@@ -94,6 +254,11 @@ public IntPtr PyType
get { return _pyType; }
}
+ ///
+ /// Type of the exception (nullable).
+ ///
+ internal BorrowedReference PythonType => new BorrowedReference(_pyType);
+
///
/// PyValue Property
///
@@ -105,6 +270,11 @@ public IntPtr PyValue
get { return _pyValue; }
}
+ ///
+ /// Exception object value (nullable).
+ ///
+ internal BorrowedReference Value => new BorrowedReference(_pyValue);
+
///
/// PyTB Property
///
@@ -116,6 +286,11 @@ public IntPtr PyTB
get { return _pyTB; }
}
+ ///
+ /// Traceback (nullable).
+ ///
+ internal BorrowedReference Traceback => new BorrowedReference(_pyTB);
+
///
/// Message Property
///
@@ -135,7 +310,7 @@ public override string Message
///
public override string StackTrace
{
- get { return _tb + base.StackTrace; }
+ get { return this._traceback + base.StackTrace; }
}
///
@@ -198,34 +373,35 @@ public string Format()
///
public void Dispose()
{
- if (!disposed)
+ if (this.IsDisposed)
+ return;
+
+ if (Runtime.Py_IsInitialized() == 0)
+ throw new InvalidOperationException("Python runtime must be initialized");
+
+ if (!Runtime.IsFinalizing)
{
- if (Runtime.Py_IsInitialized() > 0 && !Runtime.IsFinalizing)
+ if (_pyType != IntPtr.Zero)
{
- IntPtr gs = PythonEngine.AcquireLock();
- if (_pyType != IntPtr.Zero)
- {
- Runtime.XDecref(_pyType);
- _pyType= IntPtr.Zero;
- }
+ Runtime.XDecref(_pyType);
+ _pyType= IntPtr.Zero;
+ }
- if (_pyValue != IntPtr.Zero)
- {
- Runtime.XDecref(_pyValue);
- _pyValue = IntPtr.Zero;
- }
+ if (_pyValue != IntPtr.Zero)
+ {
+ Runtime.XDecref(_pyValue);
+ _pyValue = IntPtr.Zero;
+ }
- // XXX Do we ever get TraceBack? //
- if (_pyTB != IntPtr.Zero)
- {
- Runtime.XDecref(_pyTB);
- _pyTB = IntPtr.Zero;
- }
- PythonEngine.ReleaseLock(gs);
+ // XXX Do we ever get TraceBack? //
+ if (_pyTB != IntPtr.Zero)
+ {
+ Runtime.XDecref(_pyTB);
+ _pyTB = IntPtr.Zero;
}
- GC.SuppressFinalize(this);
- disposed = true;
}
+
+ GC.SuppressFinalize(this);
}
public IntPtr[] GetTrackedHandles()
@@ -233,6 +409,8 @@ public IntPtr[] GetTrackedHandles()
return new IntPtr[] { _pyType, _pyValue, _pyTB };
}
+ bool IsDisposed => _pyType == IntPtr.Zero && _pyValue == IntPtr.Zero && _pyTB == IntPtr.Zero;
+
///
/// Matches Method
///
@@ -245,19 +423,21 @@ public static bool Matches(IntPtr ob)
return Runtime.PyErr_ExceptionMatches(ob) != 0;
}
- public static void ThrowIfIsNull(IntPtr ob)
+ public static IntPtr ThrowIfIsNull(IntPtr ob)
{
if (ob == IntPtr.Zero)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
+
+ return ob;
}
public static void ThrowIfIsNotZero(int value)
{
if (value != 0)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
}
diff --git a/src/runtime/pytuple.cs b/src/runtime/pytuple.cs
index 45f3d8350..e7c1d234a 100644
--- a/src/runtime/pytuple.cs
+++ b/src/runtime/pytuple.cs
@@ -31,14 +31,18 @@ public PyTuple(IntPtr ptr) : base(ptr)
/// ArgumentException will be thrown if the given object is not a
/// Python tuple object.
///
- public PyTuple(PyObject o)
+ public PyTuple(PyObject o):base(FromPyObject(o))
{
- if (!IsTupleType(o))
- {
+ }
+
+ static BorrowedReference FromPyObject(PyObject o)
+ {
+ if (o == null) throw new ArgumentNullException(nameof(o));
+
+ if (!IsTupleType(o)) {
throw new ArgumentException("object is not a tuple");
}
- Runtime.XIncref(o.obj);
- obj = o.obj;
+ return o.Reference;
}
@@ -48,10 +52,8 @@ public PyTuple(PyObject o)
///
/// Creates a new empty PyTuple.
///
- public PyTuple()
+ public PyTuple():base(PythonException.ThrowIfIsNull(Runtime.PyTuple_New(0)))
{
- obj = Runtime.PyTuple_New(0);
- Runtime.CheckExceptionOccurred();
}
@@ -64,17 +66,31 @@ public PyTuple()
/// See caveats about PyTuple_SetItem:
/// https://www.coursehero.com/file/p4j2ogg/important-exceptions-to-this-rule-PyTupleSetItem-and-PyListSetItem-These/
///
- public PyTuple(PyObject[] items)
+ public PyTuple(PyObject[] items):base(FromItems(items))
+ {
+ }
+
+ static IntPtr FromItems(PyObject[] items)
{
+ if (items == null) throw new ArgumentNullException(nameof(items));
+
int count = items.Length;
- obj = Runtime.PyTuple_New(count);
- for (var i = 0; i < count; i++)
- {
- IntPtr ptr = items[i].obj;
- Runtime.XIncref(ptr);
- Runtime.PyTuple_SetItem(obj, i, ptr);
- Runtime.CheckExceptionOccurred();
+ IntPtr obj = Runtime.PyTuple_New(count);
+ Exceptions.ErrorCheck(obj);
+ try {
+ for (var i = 0; i < count; i++) {
+ if (items[i] == null) throw new ArgumentNullException();
+
+ IntPtr ptr = items[i].obj;
+ Runtime.XIncref(ptr);
+ PythonException.ThrowIfIsNotZero(Runtime.PyTuple_SetItem(obj, i, ptr));
+ }
+ } catch {
+ Runtime.XDecref(obj);
+ throw;
}
+
+ return obj;
}
@@ -104,5 +120,11 @@ public static PyTuple AsTuple(PyObject value)
Runtime.CheckExceptionOccurred();
return new PyTuple(op);
}
+
+ ///
+ /// Create a with single element
+ ///
+ public static PyTuple FromSingleElement(PyObject value)
+ => new PyTuple(items: new []{value});
}
}
diff --git a/src/runtime/pytype.cs b/src/runtime/pytype.cs
new file mode 100644
index 000000000..14d394360
--- /dev/null
+++ b/src/runtime/pytype.cs
@@ -0,0 +1,64 @@
+namespace Python.Runtime {
+ using System;
+
+ public class PyType : PyObject
+ {
+ ///
+ /// Creates a new instance from an existing object reference. Note
+ /// that the instance assumes ownership of the object reference.
+ /// The object reference is not checked for type-correctness.
+ ///
+ public PyType(IntPtr ptr) : base(ptr) { }
+
+ ///
+ /// Creates a new instance from an existing object reference.
+ /// Ensures the type of the object is Python type.
+ ///
+ public PyType(PyObject o) : base(FromPyObject(o)) { }
+
+ static IntPtr FromPyObject(PyObject o) {
+ if (o == null) throw new ArgumentNullException(nameof(o));
+
+ if (!IsTypeType(o)) {
+ throw new ArgumentException("object is not a type");
+ }
+ Runtime.XIncref(o.obj);
+ return o.obj;
+ }
+
+ ///
+ /// Returns true if the given object is Python type.
+ ///
+ public static bool IsTypeType(PyObject obj) {
+ if (obj == null) {
+ throw new ArgumentNullException(nameof(obj));
+ }
+
+ return Runtime.PyType_Check(obj.Reference);
+ }
+
+ ///
+ /// Returns true if the given object is Python type.
+ ///
+ public static bool IsTypeType(IntPtr typeHandle) {
+ if (typeHandle == IntPtr.Zero) {
+ throw new ArgumentNullException(nameof(typeHandle));
+ }
+
+ return Runtime.PyType_Check(new BorrowedReference(typeHandle));
+ }
+
+ ///
+ /// Gets , which represents the specified CLR type.
+ /// Must be called after the CLR type was mapped to its Python type.
+ ///
+ public static PyType Get(Type clrType) {
+ if (clrType == null) {
+ throw new ArgumentNullException(nameof(clrType));
+ }
+
+ ClassBase pyClass = ClassManager.GetClass(clrType);
+ return new PyType(Runtime.SelfIncRef(pyClass.pyHandle));
+ }
+ }
+}
diff --git a/src/runtime/resources/interop.py b/src/runtime/resources/interop.py
new file mode 100644
index 000000000..a47d16c68
--- /dev/null
+++ b/src/runtime/resources/interop.py
@@ -0,0 +1,10 @@
+_UNSET = object()
+
+class PyErr:
+ def __init__(self, type=_UNSET, value=_UNSET, traceback=_UNSET):
+ if not(type is _UNSET):
+ self.type = type
+ if not(value is _UNSET):
+ self.value = value
+ if not(traceback is _UNSET):
+ self.traceback = traceback
diff --git a/src/runtime/runtime.cs b/src/runtime/runtime.cs
index 8cf24ba70..954c6286b 100644
--- a/src/runtime/runtime.cs
+++ b/src/runtime/runtime.cs
@@ -1,6 +1,7 @@
-using System.Reflection.Emit;
using System;
+using System.Globalization;
using System.Diagnostics.Contracts;
+using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
@@ -8,100 +9,122 @@
using System.Collections.Generic;
using Python.Runtime.Platform;
+using Python.Runtime.Platforms;
+
namespace Python.Runtime
{
+ [SuppressUnmanagedCodeSecurity]
+ internal static class NativeMethods
+ {
+ public static IntPtr LoadLibrary(string dllToLoad) => impl.LoadLibrary(dllToLoad);
+ public static IntPtr GetProcAddress(IntPtr hModule, string procedureName)
+ => impl.GetProcAddress(hModule, procedureName);
+ public static void FreeLibrary(IntPtr hModule) => impl.FreeLibrary(hModule);
+
+ static readonly INativeLibraryLoader impl =
+ RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? WindowsLibraryLoader.Instance
+ : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? LinuxLibraryLoader.Instance
+ : RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? MacLibraryLoader.Instance
+ : Throw(new PlatformNotSupportedException());
+
+ internal static T Throw(Exception exception)
+ {
+ throw exception;
+ }
+ }
+
///
/// Encapsulates the low-level Python C API. Note that it is
/// the responsibility of the caller to have acquired the GIL
/// before calling any of these methods.
///
- public class Runtime
+ public static class Runtime
{
+ static Runtime() {
+ lock (VerLock) {
+ UpdateVersionFields();
+ }
+ }
+
// C# compiler copies constants to the assemblies that references this library.
// We needs to replace all public constants to static readonly fields to allow
// binary substitution of different Python.Runtime.dll builds in a target application.
- public static int UCS => _UCS;
-
-#if UCS4
- internal const int _UCS = 4;
-
- ///
- /// EntryPoint to be used in DllImport to map to correct Unicode
- /// methods prior to PEP393. Only used for PY27.
- ///
- private const string PyUnicodeEntryPoint = "PyUnicodeUCS4_";
-#elif UCS2
- internal const int _UCS = 2;
-
- ///
- /// EntryPoint to be used in DllImport to map to correct Unicode
- /// methods prior to PEP393. Only used for PY27.
- ///
- private const string PyUnicodeEntryPoint = "PyUnicodeUCS2_";
-#else
-#error You must define either UCS2 or UCS4!
-#endif
+ public static int UCS { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 2 : 4;
// C# compiler copies constants to the assemblies that references this library.
// We needs to replace all public constants to static readonly fields to allow
// binary substitution of different Python.Runtime.dll builds in a target application.
public static string pyversion => _pyversion;
+ ///
+ /// Two-character string, describing Python version (e.g. "36" for Python 3.6)
+ ///
public static string pyver => _pyver;
-#if PYTHON27
- internal const string _pyversion = "2.7";
- internal const string _pyver = "27";
-#elif PYTHON34
- internal const string _pyversion = "3.4";
- internal const string _pyver = "34";
-#elif PYTHON35
- internal const string _pyversion = "3.5";
- internal const string _pyver = "35";
-#elif PYTHON36
- internal const string _pyversion = "3.6";
- internal const string _pyver = "36";
-#elif PYTHON37
- internal const string _pyversion = "3.7";
- internal const string _pyver = "37";
-#elif PYTHON38
- internal const string _pyversion = "3.8";
- internal const string _pyver = "38";
-#else
-#error You must define one of PYTHON34 to PYTHON38 or PYTHON27
-#endif
+ static readonly object VerLock = new object();
+ static Version pythonVersion = new Version(3, 7);
+ public static Version PythonVersion {
+ get {
+ lock (VerLock) {
+ return pythonVersion;
+ }
+ }
+ set {
+ if (value == null)
+ throw new ArgumentNullException(nameof(Version));
-#if MONO_LINUX || MONO_OSX // Linux/macOS use dotted version string
- internal const string dllBase = "python" + _pyversion;
-#else // Windows
- internal const string dllBase = "python" + _pyver;
-#endif
+ lock (VerLock) {
+ pythonVersion = value;
+ UpdateVersionFields();
+ }
+ }
+ }
+
+ static void UpdateVersionFields() {
+ _pyversion = pythonVersion.ToString(2);
+ _pyver = string.Format(CultureInfo.InvariantCulture,
+ "{0}{1}", pythonVersion.Major, pythonVersion.Minor);
+ pyversionnumber = GetPyVersionNumber();
+ }
+
+ internal static string _pyversion { get; private set; }
+ internal static string _pyver { get; private set; }
#if PYTHON_WITH_PYDEBUG
- internal const string dllWithPyDebug = "d";
+ const string dllWithPyDebug = "d";
#else
- internal const string dllWithPyDebug = "";
+ const string dllWithPyDebug = "";
#endif
-#if PYTHON_WITH_PYMALLOC
- internal const string dllWithPyMalloc = "m";
+
+ static readonly bool IsWindowsPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+ static string GetDefaultDllName() {
+#if PYTHON_WITHOUT_ENABLE_SHARED && !NETSTANDARD
+ return "__Internal";
#else
- internal const string dllWithPyMalloc = "";
+ string dllBase = "python" + (IsWindowsPlatform ? _pyver : _pyversion);
+ string dllWithPyMalloc = IsWindowsPlatform ? "" : "m";
+ return dllBase + dllWithPyDebug + dllWithPyMalloc;
#endif
+ }
- // C# compiler copies constants to the assemblies that references this library.
- // We needs to replace all public constants to static readonly fields to allow
- // binary substitution of different Python.Runtime.dll builds in a target application.
+ static string pythonDllOverride;
- public static readonly string PythonDLL = _PythonDll;
+ public static string PythonDLL {
+ get { return pythonDllOverride ?? GetDefaultDllName(); }
+ set {
+ if (value == null)
+ throw new ArgumentNullException(nameof(PythonDLL));
-#if PYTHON_WITHOUT_ENABLE_SHARED && !NETSTANDARD
- internal const string _PythonDll = "__Internal";
-#else
- internal const string _PythonDll = dllBase + dllWithPyDebug + dllWithPyMalloc;
-#endif
+ pythonDllOverride = value;
+ }
+ }
- public static readonly int pyversionnumber = Convert.ToInt32(_pyver);
+ static int GetPyVersionNumber() {
+ return PythonVersion.Major * 10 + PythonVersion.Minor;;
+ }
+ [Obsolete("Use PythonVersion instead")]
+ public static int pyversionnumber = GetPyVersionNumber();
// set to true when python is finalizing
internal static object IsFinalizingLock = new object();
@@ -109,8 +132,8 @@ public class Runtime
internal static bool Is32Bit => IntPtr.Size == 4;
- // .NET core: System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
- internal static bool IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
+ [Obsolete("Use IsWindowsPlatform")]
+ internal static readonly bool IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
static readonly Dictionary OperatingSystemTypeMapping = new Dictionary()
{
@@ -155,18 +178,23 @@ public class Runtime
///
public static MachineType Machine { get; private set; }/* set in Initialize using python's platform.machine */
- internal static bool IsPython2 = pyversionnumber < 30;
- internal static bool IsPython3 = pyversionnumber >= 30;
-
public static int MainManagedThreadId { get; private set; }
///
/// Encoding to use to convert Unicode to/from Managed to Native
///
- internal static readonly Encoding PyEncoding = _UCS == 2 ? Encoding.Unicode : Encoding.UTF32;
+ internal static readonly Encoding PyEncoding = UCS == 2 ? Encoding.Unicode : Encoding.UTF32;
private static PyReferenceCollection _pyRefs = new PyReferenceCollection();
+ static long run = 0;
+
+ internal static long GetRun() {
+ long runNumber = Interlocked.Read(ref run);
+ System.Diagnostics.Debug.Assert(runNumber > 0);
+ return runNumber;
+ }
+
///
/// Initialize the runtime...
///
@@ -244,12 +272,10 @@ internal static void Initialize(bool initSigs = false)
() => PyUnicodeType = IntPtr.Zero);
XDecref(op);
-#if PYTHON3
op = PyBytes_FromString("bytes");
SetPyMember(ref PyBytesType, PyObject_Type(op),
() => PyBytesType = IntPtr.Zero);
XDecref(op);
-#endif
op = PyTuple_New(0);
SetPyMember(ref PyTupleType, PyObject_Type(op),
@@ -281,31 +307,13 @@ internal static void Initialize(bool initSigs = false)
() => PyFloatType = IntPtr.Zero);
XDecref(op);
-#if !PYTHON2
PyClassType = IntPtr.Zero;
PyInstanceType = IntPtr.Zero;
-#else
- {
- IntPtr s = PyString_FromString("_temp");
- IntPtr d = PyDict_New();
-
- IntPtr c = PyClass_New(IntPtr.Zero, d, s);
- SetPyMember(ref PyClassType, PyObject_Type(c),
- () => PyClassType = IntPtr.Zero);
-
- IntPtr i = PyInstance_New(c, IntPtr.Zero, IntPtr.Zero);
- SetPyMember(ref PyInstanceType, PyObject_Type(i),
- () => PyInstanceType = IntPtr.Zero);
-
- XDecref(s);
- XDecref(i);
- XDecref(c);
- XDecref(d);
- }
-#endif
Error = new IntPtr(-1);
+ Interlocked.Increment(ref run);
+
// Initialize data about the platform we're running on. We need
// this for the type manager and potentially other details. Must
// happen after caching the python types, above.
@@ -314,9 +322,9 @@ internal static void Initialize(bool initSigs = false)
IntPtr dllLocal = IntPtr.Zero;
var loader = LibraryLoader.Get(OperatingSystem);
- if (_PythonDll != "__Internal")
+ if (PythonDLL != "__Internal")
{
- dllLocal = loader.Load(_PythonDll);
+ dllLocal = loader.Load(PythonDLL);
}
_PyObject_NextNotImplemented = loader.GetFunction(dllLocal, "_PyObject_NextNotImplemented");
PyModuleType = loader.GetFunction(dllLocal, "PyModule_Type");
@@ -340,6 +348,9 @@ internal static void Initialize(bool initSigs = false)
PyList_Append(new BorrowedReference(path), item);
XDecref(item);
AssemblyManager.UpdatePath();
+
+ inspect = GetModuleLazy("inspect");
+ clrInterop = GetModuleLazy("clr.interop");
}
///
@@ -431,6 +442,11 @@ internal static void Shutdown()
Py_Finalize();
}
+ private static Lazy GetModuleLazy(string moduleName)
+ => moduleName is null
+ ? throw new ArgumentNullException(nameof(moduleName))
+ : new Lazy(() => PythonEngine.ImportModule(moduleName), isThreadSafe: false);
+
// called *without* the GIL acquired by clr._AtExit
internal static int AtExit()
{
@@ -481,9 +497,7 @@ private static void ResetPyMembers()
internal static IntPtr Py_NoSiteFlag;
-#if PYTHON3
internal static IntPtr PyBytesType;
-#endif
internal static IntPtr _PyObject_NextNotImplemented;
internal static IntPtr PyNotImplemented;
@@ -509,6 +523,11 @@ public static PyObject None
}
}
+ private static Lazy inspect;
+ internal static PyObject InspectModule => inspect.Value;
+ private static Lazy clrInterop;
+ internal static PyObject InteropModule => clrInterop.Value;
+
///
/// Check if any Python Exceptions occurred.
/// If any exist throw new PythonException.
@@ -520,7 +539,7 @@ internal static void CheckExceptionOccurred()
{
if (PyErr_Occurred() != IntPtr.Zero)
{
- throw new PythonException();
+ throw PythonException.ThrowLastAsClrException();
}
}
@@ -575,7 +594,7 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects)
for (var i = 0; i < n; i++)
{
- IntPtr op = PyTuple_GetItem(args, i);
+ var op = new BorrowedReference(PyTuple_GetItem(args, i));
if (mangleObjects && (!PyType_Check(op)))
{
op = PyObject_TYPE(op);
@@ -613,6 +632,12 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects)
return types;
}
+ ///
+ /// Raise an exception when a refcount of Python object exceeds this limit.
+ /// Only affects debug builds.
+ ///
+ public static long RefCountSanityLimit { get; set; } = Int32.MaxValue;
+
///
/// Managed exports of the Python C API. Where appropriate, we do
/// some optimization to avoid managed <--> unmanaged transitions
@@ -620,6 +645,18 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects)
///
internal static unsafe void XIncref(IntPtr op)
{
+ DebugUtil.EnsureGIL();
+ if (op == IntPtr.Zero)
+ throw new ArgumentNullException(nameof(op));
+#if DEBUG
+ long refcount = Refcount(op);
+ if (refcount < 0 || refcount > RefCountSanityLimit)
+ throw new ArgumentOutOfRangeException(
+ message: "Reference count is insane",
+ paramName: nameof(op),
+ actualValue: refcount);
+#endif
+
#if PYTHON_WITH_PYDEBUG || NETSTANDARD
Py_IncRef(op);
return;
@@ -650,6 +687,18 @@ internal static IntPtr SelfIncRef(IntPtr op)
internal static unsafe void XDecref(IntPtr op)
{
+ DebugUtil.EnsureGIL();
+#if DEBUG
+ if (op == IntPtr.Zero)
+ throw new ArgumentNullException(nameof(op));
+ long refcount = Refcount(op);
+ if (refcount <= 0 || refcount > RefCountSanityLimit)
+ throw new ArgumentOutOfRangeException(
+ paramName: nameof(refcount),
+ actualValue: refcount,
+ message: "Reference count is insane");
+#endif
+
#if PYTHON_WITH_PYDEBUG || NETSTANDARD
Py_DecRef(op);
return;
@@ -685,6 +734,11 @@ internal static unsafe void XDecref(IntPtr op)
#endif
}
+ internal static void XDecrefIgnoreNull(IntPtr op)
+ {
+ if (op != IntPtr.Zero) { XDecref(op); }
+ }
+
[Pure]
internal static unsafe long Refcount(IntPtr op)
{
@@ -701,157 +755,147 @@ internal static unsafe long Refcount(IntPtr op)
/// Limit this function usage for Testing and Py_Debug builds
///
/// PyObject Ptr
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_IncRef(IntPtr ob);
+
+ internal static void Py_IncRef(IntPtr ob) => Delegates.Py_IncRef(ob);
///
/// Export of Macro Py_XDecRef. Use XDecref instead.
/// Limit this function usage for Testing and Py_Debug builds
///
/// PyObject Ptr
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_DecRef(IntPtr ob);
+
+ internal static void Py_DecRef(IntPtr ob) => Delegates.Py_DecRef(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_Initialize();
+
+ internal static void Py_Initialize() => Delegates.Py_Initialize();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_InitializeEx(int initsigs);
+
+ internal static void Py_InitializeEx(int initsigs) => Delegates.Py_InitializeEx(initsigs);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int Py_IsInitialized();
+
+ internal static int Py_IsInitialized() => Delegates.Py_IsInitialized();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_Finalize();
+
+ internal static void Py_Finalize() => Delegates.Py_Finalize();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_NewInterpreter();
+
+ internal static IntPtr Py_NewInterpreter() => Delegates.Py_NewInterpreter();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_EndInterpreter(IntPtr threadState);
+
+ internal static void Py_EndInterpreter(IntPtr threadState) => Delegates.Py_EndInterpreter(threadState);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyThreadState_New(IntPtr istate);
+
+ internal static IntPtr PyThreadState_New(IntPtr istate) => Delegates.PyThreadState_New(istate);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyThreadState_Get();
+
+ internal static IntPtr PyThreadState_Get() => Delegates.PyThreadState_Get();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyThread_get_key_value(IntPtr key);
+
+ internal static IntPtr PyThread_get_key_value(IntPtr key) => Delegates.PyThread_get_key_value(key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyThread_get_thread_ident();
+
+ internal static int PyThread_get_thread_ident() => Delegates.PyThread_get_thread_ident();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyThread_set_key_value(IntPtr key, IntPtr value);
+
+ internal static int PyThread_set_key_value(IntPtr key, IntPtr value) => Delegates.PyThread_set_key_value(key, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyThreadState_Swap(IntPtr key);
+
+ internal static IntPtr PyThreadState_Swap(IntPtr key) => Delegates.PyThreadState_Swap(key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyGILState_Ensure();
+
+ internal static IntPtr PyGILState_Ensure() => Delegates.PyGILState_Ensure();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyGILState_Release(IntPtr gs);
+
+ internal static void PyGILState_Release(IntPtr gs) => Delegates.PyGILState_Release(gs);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyGILState_GetThisThreadState();
+
+ internal static IntPtr PyGILState_GetThisThreadState() => Delegates.PyGILState_GetThisThreadState();
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- public static extern int Py_Main(
+ internal static int PyGILState_Check() => Delegates.PyGILState_Check();
+
+ public static int Py_Main(
int argc,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrArrayMarshaler))] string[] argv
- );
-#elif PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- public static extern int Py_Main(int argc, string[] argv);
-#endif
+ ) => Delegates.Py_Main(argc, argv
+);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyEval_InitThreads();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyEval_ThreadsInitialized();
+
+ internal static void PyEval_InitThreads() => Delegates.PyEval_InitThreads();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyEval_AcquireLock();
+
+ internal static int PyEval_ThreadsInitialized() => Delegates.PyEval_ThreadsInitialized();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyEval_ReleaseLock();
+
+ internal static void PyEval_AcquireLock() => Delegates.PyEval_AcquireLock();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyEval_AcquireThread(IntPtr tstate);
+
+ internal static void PyEval_ReleaseLock() => Delegates.PyEval_ReleaseLock();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyEval_ReleaseThread(IntPtr tstate);
+
+ internal static void PyEval_AcquireThread(IntPtr tstate) => Delegates.PyEval_AcquireThread(tstate);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyEval_SaveThread();
+
+ internal static void PyEval_ReleaseThread(IntPtr tstate) => Delegates.PyEval_ReleaseThread(tstate);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyEval_RestoreThread(IntPtr tstate);
+
+ internal static IntPtr PyEval_SaveThread() => Delegates.PyEval_SaveThread();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyEval_GetBuiltins();
+
+ internal static void PyEval_RestoreThread(IntPtr tstate) => Delegates.PyEval_RestoreThread(tstate);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyEval_GetGlobals();
+
+ internal static BorrowedReference PyEval_GetBuiltins() => Delegates.PyEval_GetBuiltins();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyEval_GetLocals();
+
+ internal static IntPtr PyEval_GetGlobals() => Delegates.PyEval_GetGlobals();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_GetProgramName();
+
+ internal static IntPtr PyEval_GetLocals() => Delegates.PyEval_GetLocals();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_SetProgramName(IntPtr name);
+
+ internal static IntPtr Py_GetProgramName() => Delegates.Py_GetProgramName();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_GetPythonHome();
+
+ internal static void Py_SetProgramName(IntPtr name) => Delegates.Py_SetProgramName(name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_SetPythonHome(IntPtr home);
+
+ internal static IntPtr Py_GetPythonHome() => Delegates.Py_GetPythonHome();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_GetPath();
+
+ internal static void Py_SetPythonHome(IntPtr home) => Delegates.Py_SetPythonHome(home);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void Py_SetPath(IntPtr home);
+
+ internal static IntPtr Py_GetPath() => Delegates.Py_GetPath();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_GetVersion();
+
+ internal static void Py_SetPath(IntPtr home) => Delegates.Py_SetPath(home);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_GetPlatform();
+
+ internal static IntPtr Py_GetVersion() => Delegates.Py_GetVersion();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_GetCopyright();
+
+ internal static IntPtr Py_GetPlatform() => Delegates.Py_GetPlatform();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_GetCompiler();
+
+ internal static IntPtr Py_GetCopyright() => Delegates.Py_GetCopyright();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_GetBuildInfo();
+
+ internal static IntPtr Py_GetCompiler() => Delegates.Py_GetCompiler();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyRun_SimpleString(string code);
+
+ internal static IntPtr Py_GetBuildInfo() => Delegates.Py_GetBuildInfo();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
-#if PYTHON2
- internal static extern NewReference PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals);
-#else
- internal static extern NewReference PyRun_String([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string code, IntPtr st, IntPtr globals, IntPtr locals);
-#endif
+
+ internal static int PyRun_SimpleString(string code) => Delegates.PyRun_SimpleString(code);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals);
+
+ internal static NewReference PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals) => Delegates.PyRun_String(code, st, globals, locals);
+
+
+ internal static IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals) => Delegates.PyEval_EvalCode(co, globals, locals);
-#if PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_CompileString(string code, string file, int start);
-#else
///
/// Return value: New reference.
/// This is a simplified interface to Py_CompileStringFlags() below, leaving flags set to NULL.
@@ -874,33 +918,16 @@ internal static IntPtr Py_CompileStringFlags(string str, string file, int start,
/// Return value: New reference.
/// Like Py_CompileStringObject(), but filename is a byte string decoded from the filesystem encoding(os.fsdecode()).
///
- ///
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr Py_CompileStringExFlags(string str, string file, int start, IntPtr flags, int optimize);
-#endif
+ internal static IntPtr Py_CompileStringExFlags(string str, string file, int start, IntPtr flags, int optimize) => Delegates.Py_CompileStringExFlags(str, file, start, flags, optimize);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyImport_ExecCodeModule(string name, IntPtr code);
+
+ internal static IntPtr PyImport_ExecCodeModule(string name, IntPtr code) => Delegates.PyImport_ExecCodeModule(name, code);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod);
+
+ internal static IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod) => Delegates.PyCFunction_NewEx(ml, self, mod);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw);
-
-#if PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyClass_New(IntPtr bases, IntPtr dict, IntPtr name);
-#endif
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyInstance_New(IntPtr cls, IntPtr args, IntPtr kw);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyInstance_NewRaw(IntPtr cls, IntPtr dict);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyMethod_New(IntPtr func, IntPtr self, IntPtr cls);
+
+ internal static IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw) => Delegates.PyCFunction_Call(func, args, kw);
//====================================================================
@@ -929,6 +956,12 @@ internal static unsafe IntPtr PyObject_TYPE(IntPtr op)
: new IntPtr((void*)(*((ulong*)p + n)));
}
+ internal static BorrowedReference PyObject_TYPE(BorrowedReference reference) {
+ return reference.IsNull
+ ? throw new ArgumentNullException(nameof(reference))
+ : new BorrowedReference(PyObject_TYPE(reference.DangerousGetAddress()));
+ }
+
///
/// Managed version of the standard Python C API PyObject_Type call.
/// This version avoids a managed <-> unmanaged transition.
@@ -951,57 +984,51 @@ internal static string PyObject_GetTypeName(IntPtr op)
///
/// Test whether the Python object is an iterable.
///
- internal static bool PyObject_IsIterable(IntPtr pointer)
+ internal static bool PyObject_IsIterable(BorrowedReference pointer)
{
- var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type);
-#if PYTHON2
- long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags);
- if ((tp_flags & TypeFlags.HaveIter) == 0)
- return false;
-#endif
+ var ob_type = Marshal.ReadIntPtr(pointer.DangerousGetAddress(), ObjectOffset.ob_type);
IntPtr tp_iter = Marshal.ReadIntPtr(ob_type, TypeOffset.tp_iter);
return tp_iter != IntPtr.Zero;
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_HasAttrString(IntPtr pointer, string name);
+
+ internal static int PyObject_HasAttrString(IntPtr pointer, string name) => Delegates.PyObject_HasAttrString(pointer, name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_GetAttrString(IntPtr pointer, string name);
+ internal static NewReference PyObject_GetAttrString(BorrowedReference pointer, string name)
+ => NewReference.DangerousFromPointer(PyObject_GetAttrString(pointer.DangerousGetAddress(), name));
+ internal static IntPtr PyObject_GetAttrString(IntPtr pointer, string name) => Delegates.PyObject_GetAttrString(pointer, name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value);
+
+ internal static int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value) => Delegates.PyObject_SetAttrString(pointer, name, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_HasAttr(IntPtr pointer, IntPtr name);
+
+ internal static int PyObject_HasAttr(IntPtr pointer, IntPtr name) => Delegates.PyObject_HasAttr(pointer, name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name);
+
+ internal static IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name) => Delegates.PyObject_GetAttr(pointer, name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value);
+
+ internal static int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value) => Delegates.PyObject_SetAttr(pointer, name, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_GetItem(IntPtr pointer, IntPtr key);
+
+ internal static NewReference PyObject_GetItem(BorrowedReference pointer, BorrowedReference key) => Delegates.PyObject_GetItem(pointer, key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value);
+
+ internal static int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value) => Delegates.PyObject_SetItem(pointer, key, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_DelItem(IntPtr pointer, IntPtr key);
+
+ internal static int PyObject_DelItem(IntPtr pointer, IntPtr key) => Delegates.PyObject_DelItem(pointer, key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_GetIter(IntPtr op);
+
+ internal static NewReference PyObject_GetIter(BorrowedReference op) => Delegates.PyObject_GetIter(op);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw);
+
+ internal static IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw) => Delegates.PyObject_Call(pointer, args, kw);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args);
+
+ internal static IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args) => Delegates.PyObject_CallObject(pointer, args);
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid);
+ internal static int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid) => Delegates.PyObject_RichCompareBool(value1, value2, opid);
internal static int PyObject_Compare(IntPtr value1, IntPtr value2)
{
@@ -1027,77 +1054,101 @@ internal static int PyObject_Compare(IntPtr value1, IntPtr value2)
Exceptions.SetError(Exceptions.SystemError, "Error comparing objects");
return -1;
}
-#elif PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_Compare(IntPtr value1, IntPtr value2);
-#endif
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_IsInstance(IntPtr ob, IntPtr type);
+
+ internal static int PyObject_IsInstance(IntPtr ob, IntPtr type) => Delegates.PyObject_IsInstance(ob, type);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_IsSubclass(IntPtr ob, IntPtr type);
+
+ internal static int PyObject_IsSubclass(IntPtr ob, IntPtr type) => Delegates.PyObject_IsSubclass(ob, type);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyCallable_Check(IntPtr pointer);
+
+ internal static int PyCallable_Check(IntPtr pointer) => Delegates.PyCallable_Check(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_IsTrue(IntPtr pointer);
+
+ internal static int PyObject_IsTrue(IntPtr pointer) => Delegates.PyObject_IsTrue(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_Not(IntPtr pointer);
+
+ internal static int PyObject_Not(IntPtr pointer) => Delegates.PyObject_Not(pointer);
internal static long PyObject_Size(IntPtr pointer)
{
return (long)_PyObject_Size(pointer);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyObject_Size")]
- private static extern IntPtr _PyObject_Size(IntPtr pointer);
+
+ private static IntPtr _PyObject_Size(IntPtr pointer) => Delegates._PyObject_Size(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_Hash(IntPtr op);
+
+ internal static IntPtr PyObject_Hash(IntPtr op) => Delegates.PyObject_Hash(op);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_Repr(IntPtr pointer);
+
+ internal static IntPtr PyObject_Repr(IntPtr pointer) => Delegates.PyObject_Repr(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_Str(IntPtr pointer);
+
+ internal static IntPtr PyObject_Str(IntPtr pointer) => Delegates.PyObject_Str(pointer);
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyObject_Str")]
- internal static extern IntPtr PyObject_Unicode(IntPtr pointer);
-#elif PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_Unicode(IntPtr pointer);
-#endif
+
+ internal static IntPtr PyObject_Unicode(IntPtr pointer) => Delegates.PyObject_Unicode(pointer);
+
+
+ internal static IntPtr PyObject_Dir(IntPtr pointer) => Delegates.PyObject_Dir(pointer);
+
+ //====================================================================
+ // Python buffer API
+ //====================================================================
+
+
+ internal static bool PyObject_CheckBuffer(BorrowedReference obj)
+ {
+ var type = PyObject_TYPE(obj);
+ var bufferProcs = Marshal.ReadIntPtr(type.DangerousGetAddress(), TypeOffset.tp_as_buffer);
+ if (bufferProcs == IntPtr.Zero) return false;
+ var getBuffer = Marshal.ReadIntPtr(bufferProcs, 0);
+ return getBuffer != IntPtr.Zero;
+ }
+
+
+ internal static int PyObject_GetBuffer(BorrowedReference exporter, out Py_buffer view, PyBUF flags) => Delegates.PyObject_GetBuffer(exporter, out view, flags);
+
+
+ internal static void PyBuffer_Release(ref Py_buffer view) => Delegates.PyBuffer_Release(ref view);
+
+
+ internal static IntPtr PyBuffer_SizeFromFormat([MarshalAs(UnmanagedType.LPStr)] string format) => Delegates.PyBuffer_SizeFromFormat(format);
+
+
+ internal static int PyBuffer_IsContiguous(ref Py_buffer view, BufferOrderStyle order) => Delegates.PyBuffer_IsContiguous(ref view, order);
+
+
+ internal static IntPtr PyBuffer_GetPointer(ref Py_buffer view, IntPtr[] indices) => Delegates.PyBuffer_GetPointer(ref view, indices);
+
+
+ internal static int PyBuffer_FromContiguous(ref Py_buffer view, IntPtr buf, IntPtr len, BufferOrderStyle fort) => Delegates.PyBuffer_FromContiguous(ref view, buf, len, fort);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_Dir(IntPtr pointer);
+
+ internal static int PyBuffer_ToContiguous(IntPtr buf, ref Py_buffer src, IntPtr len, BufferOrderStyle order) => Delegates.PyBuffer_ToContiguous(buf, ref src, len, order);
+
+ internal static void PyBuffer_FillContiguousStrides(int ndims, IntPtr[] shape, IntPtr[] strides, int itemsize, BufferOrderStyle order) => Delegates.PyBuffer_FillContiguousStrides(ndims, shape, strides, itemsize, order);
+
+
+ internal static int PyBuffer_FillInfo(ref Py_buffer view, BorrowedReference exporter, IntPtr buf, IntPtr len, bool @readonly, PyBUF flags) => Delegates.PyBuffer_FillInfo(ref view, exporter, buf, len, @readonly, flags);
//====================================================================
// Python number API
//====================================================================
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyNumber_Long")]
- internal static extern IntPtr PyNumber_Int(IntPtr ob);
-#elif PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Int(IntPtr ob);
-#endif
+
+ internal static IntPtr PyNumber_Int(IntPtr ob) => Delegates.PyNumber_Int(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Long(IntPtr ob);
+
+ internal static IntPtr PyNumber_Long(IntPtr ob) => Delegates.PyNumber_Long(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Float(IntPtr ob);
+
+ internal static IntPtr PyNumber_Float(IntPtr ob) => Delegates.PyNumber_Float(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern bool PyNumber_Check(IntPtr ob);
+
+ internal static bool PyNumber_Check(IntPtr ob) => Delegates.PyNumber_Check(ob);
internal static bool PyInt_Check(IntPtr ob)
{
@@ -1121,47 +1172,24 @@ internal static IntPtr PyInt_FromInt64(long value)
return PyInt_FromLong(v);
}
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyLong_FromLong")]
- private static extern IntPtr PyInt_FromLong(IntPtr value);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyLong_AsLong")]
- internal static extern int PyInt_AsLong(IntPtr value);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyLong_FromString")]
- internal static extern IntPtr PyInt_FromString(string value, IntPtr end, int radix);
-#elif PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyInt_FromLong(IntPtr value);
+ [Obsolete("Should not be used due to the size of long not being guaranteed")]
+ private static IntPtr PyInt_FromLong(IntPtr value) => Delegates.PyInt_FromLong(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyInt_AsLong(IntPtr value);
+ internal static int PyInt_AsLong(IntPtr value) => Delegates.PyInt_AsLong(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyInt_FromString(string value, IntPtr end, int radix);
+ internal static IntPtr PyInt_FromString(string value, IntPtr end, int radix) => Delegates.PyInt_FromString(value, end, radix);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyInt_GetMax();
-#endif
internal static bool PyLong_Check(IntPtr ob)
{
return PyObject_TYPE(ob) == PyLongType;
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyLong_FromLong(long value);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyLong_FromUnsignedLong")]
- internal static extern IntPtr PyLong_FromUnsignedLong32(uint value);
+ [Obsolete("Should not be used due to the size of long not being guaranteed")]
+ internal static IntPtr PyLong_FromLong(long value) => Delegates.PyLong_FromLong(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyLong_FromUnsignedLong")]
- internal static extern IntPtr PyLong_FromUnsignedLong64(ulong value);
+ internal static IntPtr PyLong_FromUnsignedLong32(uint value) => Delegates.PyLong_FromUnsignedLong32(value);
+ internal static IntPtr PyLong_FromUnsignedLong64(ulong value) => Delegates.PyLong_FromUnsignedLong64(value);
internal static IntPtr PyLong_FromUnsignedLong(object value)
{
@@ -1171,28 +1199,22 @@ internal static IntPtr PyLong_FromUnsignedLong(object value)
return PyLong_FromUnsignedLong64(Convert.ToUInt64(value));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyLong_FromDouble(double value);
+
+ internal static IntPtr PyLong_FromDouble(double value) => Delegates.PyLong_FromDouble(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyLong_FromLongLong(long value);
+ [Obsolete("Should not be used due to the size of long not being guaranteed")]
+ internal static IntPtr PyLong_FromLongLong(long value) => Delegates.PyLong_FromLongLong(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyLong_FromUnsignedLongLong(ulong value);
+ [Obsolete("Should not be used due to the size of long not being guaranteed")]
+ internal static IntPtr PyLong_FromUnsignedLongLong(ulong value) => Delegates.PyLong_FromUnsignedLongLong(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyLong_FromString(string value, IntPtr end, int radix);
+
+ internal static IntPtr PyLong_FromString(string value, IntPtr end, int radix) => Delegates.PyLong_FromString(value, end, radix);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyLong_AsLong(IntPtr value);
+ internal static int PyLong_AsLong(IntPtr value) => Delegates.PyLong_AsLong(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyLong_AsUnsignedLong")]
- internal static extern uint PyLong_AsUnsignedLong32(IntPtr value);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyLong_AsUnsignedLong")]
- internal static extern ulong PyLong_AsUnsignedLong64(IntPtr value);
+ internal static uint PyLong_AsUnsignedLong32(IntPtr value) => Delegates.PyLong_AsUnsignedLong32(value);
+ internal static ulong PyLong_AsUnsignedLong64(IntPtr value) => Delegates.PyLong_AsUnsignedLong64(value);
internal static object PyLong_AsUnsignedLong(IntPtr value)
{
@@ -1202,195 +1224,195 @@ internal static object PyLong_AsUnsignedLong(IntPtr value)
return PyLong_AsUnsignedLong64(value);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern long PyLong_AsLongLong(IntPtr value);
+ [Obsolete("Should not be used due to the size of long not being guaranteed")]
+ internal static long PyLong_AsLongLong(IntPtr value) => Delegates.PyLong_AsLongLong(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern ulong PyLong_AsUnsignedLongLong(IntPtr value);
+ [Obsolete("Should not be used due to the size of long not being guaranteed")]
+ internal static ulong PyLong_AsUnsignedLongLong(IntPtr value) => Delegates.PyLong_AsUnsignedLongLong(value);
internal static bool PyFloat_Check(IntPtr ob)
{
return PyObject_TYPE(ob) == PyFloatType;
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyFloat_FromDouble(double value);
+
+ internal static IntPtr PyFloat_FromDouble(double value) => Delegates.PyFloat_FromDouble(value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyFloat_FromString(IntPtr value, IntPtr junk);
+
+ internal static IntPtr PyFloat_FromString(IntPtr value, IntPtr junk) => Delegates.PyFloat_FromString(value, junk);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern double PyFloat_AsDouble(IntPtr ob);
+
+ internal static double PyFloat_AsDouble(IntPtr ob) => Delegates.PyFloat_AsDouble(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Add(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Add(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Add(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Subtract(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Multiply(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_TrueDivide(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_TrueDivide(IntPtr o1, IntPtr o2) => Delegates.PyNumber_TrueDivide(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_And(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_And(IntPtr o1, IntPtr o2) => Delegates.PyNumber_And(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Xor(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Or(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Or(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Or(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Lshift(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Rshift(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Power(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Power(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Power(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2) => Delegates.PyNumber_Remainder(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceAdd(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceSubtract(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceMultiply(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceTrueDivide(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceTrueDivide(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceTrueDivide(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceAnd(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceXor(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceOr(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceLshift(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceRshift(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlacePower(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2);
+
+ internal static IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2) => Delegates.PyNumber_InPlaceRemainder(o1, o2);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Negative(IntPtr o1);
+
+ internal static IntPtr PyNumber_Negative(IntPtr o1) => Delegates.PyNumber_Negative(o1);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Positive(IntPtr o1);
+
+ internal static IntPtr PyNumber_Positive(IntPtr o1) => Delegates.PyNumber_Positive(o1);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyNumber_Invert(IntPtr o1);
+
+ internal static IntPtr PyNumber_Invert(IntPtr o1) => Delegates.PyNumber_Invert(o1);
//====================================================================
// Python sequence API
//====================================================================
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern bool PySequence_Check(IntPtr pointer);
+
+ internal static bool PySequence_Check(IntPtr pointer) => Delegates.PySequence_Check(pointer);
internal static IntPtr PySequence_GetItem(IntPtr pointer, long index)
{
return PySequence_GetItem(pointer, new IntPtr(index));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PySequence_GetItem(IntPtr pointer, IntPtr index);
+
+ private static IntPtr PySequence_GetItem(IntPtr pointer, IntPtr index) => Delegates.PySequence_GetItem(pointer, index);
internal static int PySequence_SetItem(IntPtr pointer, long index, IntPtr value)
{
return PySequence_SetItem(pointer, new IntPtr(index), value);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern int PySequence_SetItem(IntPtr pointer, IntPtr index, IntPtr value);
+
+ private static int PySequence_SetItem(IntPtr pointer, IntPtr index, IntPtr value) => Delegates.PySequence_SetItem(pointer, index, value);
internal static int PySequence_DelItem(IntPtr pointer, long index)
{
return PySequence_DelItem(pointer, new IntPtr(index));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern int PySequence_DelItem(IntPtr pointer, IntPtr index);
+
+ private static int PySequence_DelItem(IntPtr pointer, IntPtr index) => Delegates.PySequence_DelItem(pointer, index);
internal static IntPtr PySequence_GetSlice(IntPtr pointer, long i1, long i2)
{
return PySequence_GetSlice(pointer, new IntPtr(i1), new IntPtr(i2));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PySequence_GetSlice(IntPtr pointer, IntPtr i1, IntPtr i2);
+
+ private static IntPtr PySequence_GetSlice(IntPtr pointer, IntPtr i1, IntPtr i2) => Delegates.PySequence_GetSlice(pointer, i1, i2);
internal static int PySequence_SetSlice(IntPtr pointer, long i1, long i2, IntPtr v)
{
return PySequence_SetSlice(pointer, new IntPtr(i1), new IntPtr(i2), v);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern int PySequence_SetSlice(IntPtr pointer, IntPtr i1, IntPtr i2, IntPtr v);
+
+ private static int PySequence_SetSlice(IntPtr pointer, IntPtr i1, IntPtr i2, IntPtr v) => Delegates.PySequence_SetSlice(pointer, i1, i2, v);
internal static int PySequence_DelSlice(IntPtr pointer, long i1, long i2)
{
return PySequence_DelSlice(pointer, new IntPtr(i1), new IntPtr(i2));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern int PySequence_DelSlice(IntPtr pointer, IntPtr i1, IntPtr i2);
+
+ private static int PySequence_DelSlice(IntPtr pointer, IntPtr i1, IntPtr i2) => Delegates.PySequence_DelSlice(pointer, i1, i2);
internal static long PySequence_Size(IntPtr pointer)
{
return (long)_PySequence_Size(pointer);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PySequence_Size")]
- private static extern IntPtr _PySequence_Size(IntPtr pointer);
+
+ private static IntPtr _PySequence_Size(IntPtr pointer) => Delegates._PySequence_Size(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PySequence_Contains(IntPtr pointer, IntPtr item);
+
+ internal static int PySequence_Contains(IntPtr pointer, IntPtr item) => Delegates.PySequence_Contains(pointer, item);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PySequence_Concat(IntPtr pointer, IntPtr other);
+
+ internal static IntPtr PySequence_Concat(IntPtr pointer, IntPtr other) => Delegates.PySequence_Concat(pointer, other);
internal static IntPtr PySequence_Repeat(IntPtr pointer, long count)
{
return PySequence_Repeat(pointer, new IntPtr(count));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PySequence_Repeat(IntPtr pointer, IntPtr count);
+
+ private static IntPtr PySequence_Repeat(IntPtr pointer, IntPtr count) => Delegates.PySequence_Repeat(pointer, count);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PySequence_Index(IntPtr pointer, IntPtr item);
+
+ internal static int PySequence_Index(IntPtr pointer, IntPtr item) => Delegates.PySequence_Index(pointer, item);
internal static long PySequence_Count(IntPtr pointer, IntPtr value)
{
return (long)_PySequence_Count(pointer, value);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PySequence_Count")]
- private static extern IntPtr _PySequence_Count(IntPtr pointer, IntPtr value);
+
+ private static IntPtr _PySequence_Count(IntPtr pointer, IntPtr value) => Delegates._PySequence_Count(pointer, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PySequence_Tuple(IntPtr pointer);
+
+ internal static IntPtr PySequence_Tuple(IntPtr pointer) => Delegates.PySequence_Tuple(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PySequence_List(IntPtr pointer);
+
+ internal static IntPtr PySequence_List(IntPtr pointer) => Delegates.PySequence_List(pointer);
//====================================================================
@@ -1403,31 +1425,27 @@ internal static bool IsStringType(IntPtr op)
return (t == PyStringType) || (t == PyUnicodeType);
}
+ [Obsolete(Util.UseOverloadWithReferenceTypes)]
internal static bool PyString_Check(IntPtr ob)
{
return PyObject_TYPE(ob) == PyStringType;
}
+ internal static bool PyString_Check(BorrowedReference ob)
+ => PyObject_TYPE(ob) == PyStringType;
internal static IntPtr PyString_FromString(string value)
{
-#if PYTHON3
- return PyUnicode_FromKindAndData(_UCS, value, value.Length);
-#elif PYTHON2
- return PyString_FromStringAndSize(value, value.Length);
-#endif
+ return PyUnicode_FromKindAndData(UCS, value, value.Length);
}
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyBytes_FromString(string op);
+ internal static IntPtr PyBytes_FromString(string op) => Delegates.PyBytes_FromString(op);
internal static long PyBytes_Size(IntPtr op)
{
return (long)_PyBytes_Size(op);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyBytes_Size")]
- private static extern IntPtr _PyBytes_Size(IntPtr op);
+ private static IntPtr _PyBytes_Size(IntPtr op) => Delegates._PyBytes_Size(op);
internal static IntPtr PyBytes_AS_STRING(IntPtr ob)
{
@@ -1439,67 +1457,44 @@ internal static IntPtr PyString_FromStringAndSize(string value, long size)
return _PyString_FromStringAndSize(value, new IntPtr(size));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = "PyUnicode_FromStringAndSize")]
- internal static extern IntPtr _PyString_FromStringAndSize(
+ internal static IntPtr _PyString_FromStringAndSize(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value,
IntPtr size
- );
+ ) => Delegates._PyString_FromStringAndSize(value, size);
internal static IntPtr PyUnicode_FromStringAndSize(IntPtr value, long size)
{
return PyUnicode_FromStringAndSize(value, new IntPtr(size));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyUnicode_FromStringAndSize(IntPtr value, IntPtr size);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyUnicode_AsUTF8(IntPtr unicode);
-
-#elif PYTHON2
- internal static IntPtr PyString_FromStringAndSize(string value, long size)
- {
- return PyString_FromStringAndSize(value, new IntPtr(size));
- }
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyString_FromStringAndSize(string value, IntPtr size);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyString_AsString(IntPtr op);
+ private static IntPtr PyUnicode_FromStringAndSize(IntPtr value, IntPtr size) => Delegates.PyUnicode_FromStringAndSize(value, size);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyString_Size(IntPtr pointer);
-#endif
+ internal static IntPtr PyUnicode_AsUTF8(IntPtr unicode) => Delegates.PyUnicode_AsUTF8(unicode);
internal static bool PyUnicode_Check(IntPtr ob)
{
return PyObject_TYPE(ob) == PyUnicodeType;
}
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyUnicode_FromObject(IntPtr ob);
+ internal static IntPtr PyUnicode_FromObject(IntPtr ob) => Delegates.PyUnicode_FromObject(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);
+ internal static IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err) => Delegates.PyUnicode_FromEncodedObject(ob, enc, err);
internal static IntPtr PyUnicode_FromKindAndData(int kind, string s, long size)
{
return PyUnicode_FromKindAndData(kind, s, new IntPtr(size));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyUnicode_FromKindAndData(
+ private static IntPtr PyUnicode_FromKindAndData(
int kind,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s,
IntPtr size
- );
+ ) => Delegates.PyUnicode_FromKindAndData(kind, s, size
+);
internal static IntPtr PyUnicode_FromUnicode(string s, long size)
{
- return PyUnicode_FromKindAndData(_UCS, s, size);
+ return PyUnicode_FromKindAndData(UCS, s, size);
}
internal static long PyUnicode_GetSize(IntPtr ob)
@@ -1507,52 +1502,11 @@ internal static long PyUnicode_GetSize(IntPtr ob)
return (long)_PyUnicode_GetSize(ob);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyUnicode_GetSize")]
- private static extern IntPtr _PyUnicode_GetSize(IntPtr ob);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyUnicode_AsUnicode(IntPtr ob);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyUnicode_FromOrdinal(int c);
-#elif PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = PyUnicodeEntryPoint + "FromObject")]
- internal static extern IntPtr PyUnicode_FromObject(IntPtr ob);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = PyUnicodeEntryPoint + "FromEncodedObject")]
- internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);
-
- internal static IntPtr PyUnicode_FromUnicode(string s, long size)
- {
- return PyUnicode_FromUnicode(s, new IntPtr(size));
- }
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = PyUnicodeEntryPoint + "FromUnicode")]
- private static extern IntPtr PyUnicode_FromUnicode(
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s,
- IntPtr size
- );
-
- internal static long PyUnicode_GetSize(IntPtr ob)
- {
- return (long) _PyUnicode_GetSize(ob);
- }
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = PyUnicodeEntryPoint + "GetSize")]
- internal static extern IntPtr _PyUnicode_GetSize(IntPtr ob);
+ private static IntPtr _PyUnicode_GetSize(IntPtr ob) => Delegates._PyUnicode_GetSize(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = PyUnicodeEntryPoint + "AsUnicode")]
- internal static extern IntPtr PyUnicode_AsUnicode(IntPtr ob);
+ internal static IntPtr PyUnicode_AsUnicode(IntPtr ob) => Delegates.PyUnicode_AsUnicode(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
- EntryPoint = PyUnicodeEntryPoint + "FromOrdinal")]
- internal static extern IntPtr PyUnicode_FromOrdinal(int c);
-#endif
+ internal static IntPtr PyUnicode_FromOrdinal(int c) => Delegates.PyUnicode_FromOrdinal(c);
internal static IntPtr PyUnicode_FromString(string s)
{
@@ -1578,19 +1532,13 @@ internal static string GetManagedString(IntPtr op)
{
IntPtr type = PyObject_TYPE(op);
-#if PYTHON2 // Python 3 strings are all Unicode
- if (type == PyStringType)
- {
- return Marshal.PtrToStringAnsi(PyString_AsString(op), PyString_Size(op));
- }
-#endif
-
if (type == PyUnicodeType)
{
IntPtr p = PyUnicode_AsUnicode(op);
- int length = (int)PyUnicode_GetSize(op);
+ Exceptions.ErrorCheck(p);
+ int length = checked((int)PyUnicode_GetSize(op));
- int size = length * _UCS;
+ int size = checked(length * UCS);
var buffer = new byte[size];
Marshal.Copy(p, buffer, 0, size);
return PyEncoding.GetString(buffer, 0, size);
@@ -1609,58 +1557,60 @@ internal static bool PyDict_Check(IntPtr ob)
return PyObject_TYPE(ob) == PyDictType;
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyDict_New();
+
+ internal static IntPtr PyDict_New() => Delegates.PyDict_New();
+
+
+ internal static IntPtr PyDictProxy_New(IntPtr dict) => Delegates.PyDictProxy_New(dict);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyDictProxy_New(IntPtr dict);
+
+ internal static IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key) => Delegates.PyDict_GetItem(pointer, key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key);
+
+ internal static IntPtr PyDict_GetItemString(IntPtr pointer, string key) => Delegates.PyDict_GetItemString(pointer, key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyDict_GetItemString(IntPtr pointer, string key);
+
+ internal static int PyDict_SetItem(BorrowedReference pointer, BorrowedReference key, BorrowedReference value) => Delegates.PyDict_SetItem(pointer, key, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value);
+
+ internal static int PyDict_SetItemString(IntPtr pointer, string key, IntPtr value) => Delegates.PyDict_SetItemString(pointer, key, value);
+ internal static int PyDict_SetItemString(BorrowedReference pointer, string key, BorrowedReference value)
+ => PyDict_SetItemString(pointer.DangerousGetAddress(), key, value.DangerousGetAddress());
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyDict_SetItemString(IntPtr pointer, string key, IntPtr value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyDict_DelItem(IntPtr pointer, IntPtr key);
+ internal static int PyDict_DelItem(IntPtr pointer, IntPtr key) => Delegates.PyDict_DelItem(pointer, key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyDict_DelItemString(IntPtr pointer, string key);
+
+ internal static int PyDict_DelItemString(IntPtr pointer, string key) => Delegates.PyDict_DelItemString(pointer, key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyMapping_HasKey(IntPtr pointer, IntPtr key);
+
+ internal static int PyMapping_HasKey(IntPtr pointer, IntPtr key) => Delegates.PyMapping_HasKey(pointer, key);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyDict_Keys(IntPtr pointer);
+
+ internal static IntPtr PyDict_Keys(IntPtr pointer) => Delegates.PyDict_Keys(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyDict_Values(IntPtr pointer);
+
+ internal static IntPtr PyDict_Values(IntPtr pointer) => Delegates.PyDict_Values(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern NewReference PyDict_Items(IntPtr pointer);
+
+ internal static NewReference PyDict_Items(IntPtr pointer) => Delegates.PyDict_Items(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyDict_Copy(IntPtr pointer);
+
+ internal static IntPtr PyDict_Copy(IntPtr pointer) => Delegates.PyDict_Copy(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyDict_Update(IntPtr pointer, IntPtr other);
+
+ internal static int PyDict_Update(IntPtr pointer, IntPtr other) => Delegates.PyDict_Update(pointer, other);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyDict_Clear(IntPtr pointer);
+
+ internal static void PyDict_Clear(IntPtr pointer) => Delegates.PyDict_Clear(pointer);
internal static long PyDict_Size(IntPtr pointer)
{
return (long)_PyDict_Size(pointer);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyDict_Size")]
- internal static extern IntPtr _PyDict_Size(IntPtr pointer);
+
+ internal static IntPtr _PyDict_Size(IntPtr pointer) => Delegates._PyDict_Size(pointer);
//====================================================================
@@ -1677,68 +1627,68 @@ internal static IntPtr PyList_New(long size)
return PyList_New(new IntPtr(size));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyList_New(IntPtr size);
+
+ private static IntPtr PyList_New(IntPtr size) => Delegates.PyList_New(size);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyList_AsTuple(IntPtr pointer);
+
+ internal static IntPtr PyList_AsTuple(IntPtr pointer) => Delegates.PyList_AsTuple(pointer);
internal static BorrowedReference PyList_GetItem(IntPtr pointer, long index)
{
return PyList_GetItem(pointer, new IntPtr(index));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern BorrowedReference PyList_GetItem(IntPtr pointer, IntPtr index);
+
+ private static BorrowedReference PyList_GetItem(IntPtr pointer, IntPtr index) => Delegates.PyList_GetItem(pointer, index);
internal static int PyList_SetItem(IntPtr pointer, long index, IntPtr value)
{
return PyList_SetItem(pointer, new IntPtr(index), value);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern int PyList_SetItem(IntPtr pointer, IntPtr index, IntPtr value);
+
+ private static int PyList_SetItem(IntPtr pointer, IntPtr index, IntPtr value) => Delegates.PyList_SetItem(pointer, index, value);
internal static int PyList_Insert(BorrowedReference pointer, long index, IntPtr value)
{
return PyList_Insert(pointer, new IntPtr(index), value);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern int PyList_Insert(BorrowedReference pointer, IntPtr index, IntPtr value);
+
+ private static int PyList_Insert(BorrowedReference pointer, IntPtr index, IntPtr value) => Delegates.PyList_Insert(pointer, index, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyList_Append(BorrowedReference pointer, IntPtr value);
+
+ internal static int PyList_Append(BorrowedReference pointer, IntPtr value) => Delegates.PyList_Append(pointer, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyList_Reverse(BorrowedReference pointer);
+
+ internal static int PyList_Reverse(BorrowedReference pointer) => Delegates.PyList_Reverse(pointer);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyList_Sort(BorrowedReference pointer);
+
+ internal static int PyList_Sort(BorrowedReference pointer) => Delegates.PyList_Sort(pointer);
internal static IntPtr PyList_GetSlice(IntPtr pointer, long start, long end)
{
return PyList_GetSlice(pointer, new IntPtr(start), new IntPtr(end));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyList_GetSlice(IntPtr pointer, IntPtr start, IntPtr end);
+
+ private static IntPtr PyList_GetSlice(IntPtr pointer, IntPtr start, IntPtr end) => Delegates.PyList_GetSlice(pointer, start, end);
internal static int PyList_SetSlice(IntPtr pointer, long start, long end, IntPtr value)
{
return PyList_SetSlice(pointer, new IntPtr(start), new IntPtr(end), value);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern int PyList_SetSlice(IntPtr pointer, IntPtr start, IntPtr end, IntPtr value);
+
+ private static int PyList_SetSlice(IntPtr pointer, IntPtr start, IntPtr end, IntPtr value) => Delegates.PyList_SetSlice(pointer, start, end, value);
internal static long PyList_Size(IntPtr pointer)
{
return (long)_PyList_Size(pointer);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyList_Size")]
- private static extern IntPtr _PyList_Size(IntPtr pointer);
+
+ private static IntPtr _PyList_Size(IntPtr pointer) => Delegates._PyList_Size(pointer);
//====================================================================
// Python tuple API
@@ -1754,138 +1704,120 @@ internal static IntPtr PyTuple_New(long size)
return PyTuple_New(new IntPtr(size));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyTuple_New(IntPtr size);
+
+ private static IntPtr PyTuple_New(IntPtr size) => Delegates.PyTuple_New(size);
internal static IntPtr PyTuple_GetItem(IntPtr pointer, long index)
{
return PyTuple_GetItem(pointer, new IntPtr(index));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyTuple_GetItem(IntPtr pointer, IntPtr index);
+
+ private static IntPtr PyTuple_GetItem(IntPtr pointer, IntPtr index) => Delegates.PyTuple_GetItem(pointer, index);
internal static int PyTuple_SetItem(IntPtr pointer, long index, IntPtr value)
{
return PyTuple_SetItem(pointer, new IntPtr(index), value);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern int PyTuple_SetItem(IntPtr pointer, IntPtr index, IntPtr value);
+
+ private static int PyTuple_SetItem(IntPtr pointer, IntPtr index, IntPtr value) => Delegates.PyTuple_SetItem(pointer, index, value);
internal static IntPtr PyTuple_GetSlice(IntPtr pointer, long start, long end)
{
return PyTuple_GetSlice(pointer, new IntPtr(start), new IntPtr(end));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyTuple_GetSlice(IntPtr pointer, IntPtr start, IntPtr end);
+
+ private static IntPtr PyTuple_GetSlice(IntPtr pointer, IntPtr start, IntPtr end) => Delegates.PyTuple_GetSlice(pointer, start, end);
internal static long PyTuple_Size(IntPtr pointer)
{
return (long)_PyTuple_Size(pointer);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyTuple_Size")]
- private static extern IntPtr _PyTuple_Size(IntPtr pointer);
+
+ private static IntPtr _PyTuple_Size(IntPtr pointer) => Delegates._PyTuple_Size(pointer);
//====================================================================
// Python iterator API
//====================================================================
- internal static bool PyIter_Check(IntPtr pointer)
+ internal static bool PyIter_Check(BorrowedReference pointer)
{
- var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type);
-#if PYTHON2
- long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags);
- if ((tp_flags & TypeFlags.HaveIter) == 0)
- return false;
-#endif
+ var ob_type = Marshal.ReadIntPtr(pointer.DangerousGetAddress(), ObjectOffset.ob_type);
IntPtr tp_iternext = Marshal.ReadIntPtr(ob_type, TypeOffset.tp_iternext);
return tp_iternext != IntPtr.Zero && tp_iternext != _PyObject_NextNotImplemented;
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyIter_Next(IntPtr pointer);
+
+ internal static NewReference PyIter_Next(BorrowedReference pointer) => Delegates.PyIter_Next(pointer);
//====================================================================
// Python module API
//====================================================================
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyModule_New(string name);
+
+ internal static IntPtr PyModule_New(string name) => Delegates.PyModule_New(name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern string PyModule_GetName(IntPtr module);
+
+ internal static string PyModule_GetName(IntPtr module) => Delegates.PyModule_GetName(module);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyModule_GetDict(IntPtr module);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern string PyModule_GetFilename(IntPtr module);
+ [Obsolete(Util.UseOverloadWithReferenceTypes)]
+ internal static IntPtr PyModule_GetDict(IntPtr module) => Delegates.PyModule_GetDict(module);
+ internal static BorrowedReference PyModule_GetDict(BorrowedReference module)
+ => new BorrowedReference(PyModule_GetDict(module.DangerousGetAddress()));
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyModule_Create2(IntPtr module, int apiver);
-#endif
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyImport_Import(IntPtr name);
+ internal static string PyModule_GetFilename(IntPtr module) => Delegates.PyModule_GetFilename(module);
- ///
- /// Return value: New reference.
- ///
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyImport_ImportModule(string name);
+ internal static IntPtr PyModule_Create2(IntPtr module, int apiver) => Delegates.PyModule_Create2(module, apiver);
+
+ internal static IntPtr PyImport_Import(IntPtr name) => Delegates.PyImport_Import(name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyImport_ReloadModule(IntPtr module);
+ internal static IntPtr PyImport_ImportModule(string name) => Delegates.PyImport_ImportModule(name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyImport_AddModule(string name);
+ internal static IntPtr PyImport_ReloadModule(IntPtr module) => Delegates.PyImport_ReloadModule(module);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyImport_GetModuleDict();
+ internal static BorrowedReference PyImport_AddModule(string name) => Delegates.PyImport_AddModule(name);
-#if PYTHON3
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PySys_SetArgvEx(
+ internal static IntPtr PyImport_GetModuleDict() => Delegates.PyImport_GetModuleDict();
+
+ internal static void PySys_SetArgvEx(
int argc,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrArrayMarshaler))] string[] argv,
int updatepath
- );
-#elif PYTHON2
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PySys_SetArgvEx(
- int argc,
- string[] argv,
- int updatepath
- );
-#endif
+ ) => Delegates.PySys_SetArgvEx(argc, argv, updatepath
+);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PySys_GetObject(string name);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PySys_SetObject(string name, IntPtr ob);
+ internal static IntPtr PySys_GetObject(string name) => Delegates.PySys_GetObject(name);
+ internal static int PySys_SetObject(string name, IntPtr ob) => Delegates.PySys_SetObject(name, ob);
//====================================================================
// Python type object API
//====================================================================
- internal static bool PyType_Check(IntPtr ob)
+ internal static bool PyType_Check(BorrowedReference ob)
+ {
+ // fast path using raw memory access
+ BorrowedReference type = PyObject_TYPE(ob);
+ if (type == PyTypeType) return true;
+ return PyType_FastSubclass(type, TypeFlags.TypeSubclass);
+ }
+
+ internal static bool PyType_FastSubclass(BorrowedReference type, TypeFlags baseType)
{
- return PyObject_TypeCheck(ob, PyTypeType);
+ var flags = (TypeFlags)Util.ReadCLong(type.DangerousGetAddress(), TypeOffset.tp_flags);
+ return (flags & baseType) != 0;
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyType_Modified(IntPtr type);
+ internal static void PyType_Modified(IntPtr type) => Delegates.PyType_Modified(type);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern bool PyType_IsSubtype(IntPtr t1, IntPtr t2);
+ internal static bool PyType_IsSubtype(IntPtr t1, IntPtr t2) => Delegates.PyType_IsSubtype(t1, t2);
internal static bool PyObject_TypeCheck(IntPtr ob, IntPtr tp)
{
@@ -1898,44 +1830,32 @@ internal static bool PyType_IsSameAsOrSubtype(IntPtr type, IntPtr ofType)
return (type == ofType) || PyType_IsSubtype(type, ofType);
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw);
+ internal static IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw) => Delegates.PyType_GenericNew(type, args, kw);
internal static IntPtr PyType_GenericAlloc(IntPtr type, long n)
{
return PyType_GenericAlloc(type, new IntPtr(n));
}
+ internal static NewReference PyType_GenericAlloc(BorrowedReference type, long n)
+ => NewReference.DangerousFromPointer(PyType_GenericAlloc(type.DangerousGetAddress(), n));
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyType_GenericAlloc(IntPtr type, IntPtr n);
+ private static IntPtr PyType_GenericAlloc(IntPtr type, IntPtr n) => Delegates.PyType_GenericAlloc(type, n);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyType_Ready(IntPtr type);
+ internal static int PyType_Ready(IntPtr type) => Delegates.PyType_Ready(type);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr _PyType_Lookup(IntPtr type, IntPtr name);
+ internal static IntPtr _PyType_Lookup(IntPtr type, IntPtr name) => Delegates._PyType_Lookup(type, name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name);
+ internal static IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name) => Delegates.PyObject_GenericGetAttr(obj, name);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value);
+ internal static int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value) => Delegates.PyObject_GenericSetAttr(obj, name, value);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr _PyObject_GetDictPtr(IntPtr obj);
+ internal static IntPtr _PyObject_GetDictPtr(IntPtr obj) => Delegates._PyObject_GetDictPtr(obj);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyObject_GC_New(IntPtr tp);
+ internal static void PyObject_GC_Del(IntPtr tp) => Delegates.PyObject_GC_Del(tp);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyObject_GC_Del(IntPtr tp);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyObject_GC_Track(IntPtr tp);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyObject_GC_UnTrack(IntPtr tp);
+ internal static void PyObject_GC_Track(IntPtr tp) => Delegates.PyObject_GC_Track(tp);
+ internal static void PyObject_GC_UnTrack(IntPtr tp) => Delegates.PyObject_GC_UnTrack(tp);
//====================================================================
// Python memory API
@@ -1946,104 +1866,83 @@ internal static IntPtr PyMem_Malloc(long size)
return PyMem_Malloc(new IntPtr(size));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyMem_Malloc(IntPtr size);
+ private static IntPtr PyMem_Malloc(IntPtr size) => Delegates.PyMem_Malloc(size);
internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
{
return PyMem_Realloc(ptr, new IntPtr(size));
}
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- private static extern IntPtr PyMem_Realloc(IntPtr ptr, IntPtr size);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyMem_Free(IntPtr ptr);
+ private static IntPtr PyMem_Realloc(IntPtr ptr, IntPtr size) => Delegates.PyMem_Realloc(ptr, size);
+ internal static void PyMem_Free(IntPtr ptr) => Delegates.PyMem_Free(ptr);
//====================================================================
// Python exception API
//====================================================================
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyErr_SetString(IntPtr ob, string message);
+ internal static void PyErr_SetString(IntPtr ob, string message) => Delegates.PyErr_SetString(ob, message);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyErr_SetObject(IntPtr ob, IntPtr message);
+ internal static void PyErr_SetObject(IntPtr ob, IntPtr message) => Delegates.PyErr_SetObject(ob, message);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyErr_SetFromErrno(IntPtr ob);
+ internal static IntPtr PyErr_SetFromErrno(IntPtr ob) => Delegates.PyErr_SetFromErrno(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyErr_SetNone(IntPtr ob);
+ internal static void PyErr_SetNone(IntPtr ob) => Delegates.PyErr_SetNone(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyErr_ExceptionMatches(IntPtr exception);
+ internal static int PyErr_ExceptionMatches(IntPtr exception) => Delegates.PyErr_ExceptionMatches(exception);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val);
+ internal static int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val) => Delegates.PyErr_GivenExceptionMatches(ob, val);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb);
+ internal static void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb) => Delegates.PyErr_NormalizeException(ob, val, tb);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyErr_Occurred();
+ internal static IntPtr PyErr_Occurred() => Delegates.PyErr_Occurred();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyErr_Fetch(out IntPtr ob, out IntPtr val, out IntPtr tb);
+ internal static void PyErr_Fetch(out NewReference type, out NewReference value, out NewReference traceback)
+ => Delegates.PyErr_Fetch(out type, out value, out traceback);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb);
+ internal static void PyErr_Restore(StealingReference ob, StealingReference val, StealingReference tb)
+ => Delegates.PyErr_Restore(
+ ob.DangerousGetAddressOrNull(),
+ val.DangerousGetAddressOrNull(),
+ tb.DangerousGetAddressOrNull());
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyErr_Clear();
+ internal static void PyErr_Clear() => Delegates.PyErr_Clear();
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void PyErr_Print();
+ internal static void PyErr_Print() => Delegates.PyErr_Print();
//====================================================================
// Cell API
//====================================================================
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern NewReference PyCell_Get(BorrowedReference cell);
-
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int PyCell_Set(BorrowedReference cell, IntPtr value);
+ internal static NewReference PyCell_Get(BorrowedReference cell) => Delegates.PyCell_Get(cell);
+ internal static int PyCell_Set(BorrowedReference cell, BorrowedReference value) => Delegates.PyCell_Set(cell, value);
//====================================================================
// Miscellaneous
//====================================================================
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyMethod_Self(IntPtr ob);
+ internal static IntPtr PyMethod_Self(IntPtr ob) => Delegates.PyMethod_Self(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr PyMethod_Function(IntPtr ob);
+ internal static IntPtr PyMethod_Function(IntPtr ob) => Delegates.PyMethod_Function(ob);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int Py_AddPendingCall(IntPtr func, IntPtr arg);
+ internal static IntPtr PyMethod_New(IntPtr func, IntPtr self) => Delegates.PyMethod_New(func, self);
- [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int Py_MakePendingCalls();
+ internal static int Py_AddPendingCall(IntPtr func, IntPtr arg) => Delegates.Py_AddPendingCall(func, arg);
- internal static void SetNoSiteFlag()
- {
+ internal static int Py_MakePendingCalls() => Delegates.Py_MakePendingCalls();
+
+ internal static void SetNoSiteFlag() {
var loader = LibraryLoader.Get(OperatingSystem);
- IntPtr dllLocal = _PythonDll != "__Internal"
- ? loader.Load(_PythonDll)
+ IntPtr dllLocal = PythonDLL != "__Internal"
+ ? loader.Load(PythonDLL)
: IntPtr.Zero;
- try
- {
+ try {
Py_NoSiteFlag = loader.GetFunction(dllLocal, "Py_NoSiteFlag");
Marshal.WriteInt32(Py_NoSiteFlag, 1);
- }
- finally
- {
- if (dllLocal != IntPtr.Zero)
- {
+ } finally {
+ if (dllLocal != IntPtr.Zero) {
loader.Free(dllLocal);
}
}
@@ -2052,35 +1951,1518 @@ internal static void SetNoSiteFlag()
///
/// Return value: New reference.
///
- internal static IntPtr GetBuiltins()
- {
- return IsPython3 ? PyImport_ImportModule("builtins")
- : PyImport_ImportModule("__builtin__");
- }
- }
+ internal static IntPtr GetBuiltins() => PyImport_ImportModule("builtins");
+ public static class Delegates
+ {
+ static Delegates()
+ {
+ Py_IncRef = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_IncRef), GetUnmanagedDll(PythonDLL)));
+ Py_DecRef = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_DecRef), GetUnmanagedDll(PythonDLL)));
+ Py_Initialize = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_Initialize), GetUnmanagedDll(PythonDLL)));
+ Py_InitializeEx = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_InitializeEx), GetUnmanagedDll(PythonDLL)));
+ Py_IsInitialized = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_IsInitialized), GetUnmanagedDll(PythonDLL)));
+ Py_Finalize = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_Finalize), GetUnmanagedDll(PythonDLL)));
+ Py_NewInterpreter = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_NewInterpreter), GetUnmanagedDll(PythonDLL)));
+ Py_EndInterpreter = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_EndInterpreter), GetUnmanagedDll(PythonDLL)));
+ PyThreadState_New = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyThreadState_New), GetUnmanagedDll(PythonDLL)));
+ PyThreadState_Get = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyThreadState_Get), GetUnmanagedDll(PythonDLL)));
+ PyThread_get_key_value = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyThread_get_key_value), GetUnmanagedDll(PythonDLL)));
+ PyThread_get_thread_ident = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyThread_get_thread_ident), GetUnmanagedDll(PythonDLL)));
+ PyThread_set_key_value = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyThread_set_key_value), GetUnmanagedDll(PythonDLL)));
+ PyThreadState_Swap = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyThreadState_Swap), GetUnmanagedDll(PythonDLL)));
+ PyGILState_Ensure = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyGILState_Ensure), GetUnmanagedDll(PythonDLL)));
+ PyGILState_Release = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyGILState_Release), GetUnmanagedDll(PythonDLL)));
+ PyGILState_GetThisThreadState = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyGILState_GetThisThreadState), GetUnmanagedDll(PythonDLL)));
+ if (PythonVersion >= new Version(3, 4)) {
+ PyGILState_Check = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyGILState_Check), GetUnmanagedDll(PythonDLL)));
+ }
+ Py_Main = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_Main), GetUnmanagedDll(PythonDLL)));
+ PyEval_InitThreads = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_InitThreads), GetUnmanagedDll(PythonDLL)));
+ PyEval_ThreadsInitialized = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_ThreadsInitialized), GetUnmanagedDll(PythonDLL)));
+ PyEval_AcquireLock = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_AcquireLock), GetUnmanagedDll(PythonDLL)));
+ PyEval_ReleaseLock = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_ReleaseLock), GetUnmanagedDll(PythonDLL)));
+ PyEval_AcquireThread = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_AcquireThread), GetUnmanagedDll(PythonDLL)));
+ PyEval_ReleaseThread = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_ReleaseThread), GetUnmanagedDll(PythonDLL)));
+ PyEval_SaveThread = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_SaveThread), GetUnmanagedDll(PythonDLL)));
+ PyEval_RestoreThread = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_RestoreThread), GetUnmanagedDll(PythonDLL)));
+ PyEval_GetBuiltins = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_GetBuiltins), GetUnmanagedDll(PythonDLL)));
+ PyEval_GetGlobals = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_GetGlobals), GetUnmanagedDll(PythonDLL)));
+ PyEval_GetLocals = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_GetLocals), GetUnmanagedDll(PythonDLL)));
+ Py_GetProgramName = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_GetProgramName), GetUnmanagedDll(PythonDLL)));
+ Py_SetProgramName = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_SetProgramName), GetUnmanagedDll(PythonDLL)));
+ Py_GetPythonHome = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_GetPythonHome), GetUnmanagedDll(PythonDLL)));
+ Py_SetPythonHome = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_SetPythonHome), GetUnmanagedDll(PythonDLL)));
+ Py_GetPath = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_GetPath), GetUnmanagedDll(PythonDLL)));
+ Py_SetPath = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_SetPath), GetUnmanagedDll(PythonDLL)));
+ Py_GetVersion = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_GetVersion), GetUnmanagedDll(PythonDLL)));
+ Py_GetPlatform = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_GetPlatform), GetUnmanagedDll(PythonDLL)));
+ Py_GetCopyright = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_GetCopyright), GetUnmanagedDll(PythonDLL)));
+ Py_GetCompiler = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_GetCompiler), GetUnmanagedDll(PythonDLL)));
+ Py_GetBuildInfo = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_GetBuildInfo), GetUnmanagedDll(PythonDLL)));
+ PyRun_SimpleString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyRun_SimpleString), GetUnmanagedDll(PythonDLL)));
+ PyRun_String = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyRun_String), GetUnmanagedDll(PythonDLL)));
+ PyEval_EvalCode = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyEval_EvalCode), GetUnmanagedDll(PythonDLL)));
+ Py_CompileString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_CompileString), GetUnmanagedDll(PythonDLL)));
+ Py_CompileStringExFlags = GetDelegateForFunctionPointer(GetFunctionByName(nameof(Py_CompileStringExFlags), GetUnmanagedDll(PythonDLL)));
+ PyImport_ExecCodeModule = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyImport_ExecCodeModule), GetUnmanagedDll(PythonDLL)));
+ PyCFunction_NewEx = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyCFunction_NewEx), GetUnmanagedDll(PythonDLL)));
+ PyCFunction_Call = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyCFunction_Call), GetUnmanagedDll(PythonDLL)));
+ PyObject_HasAttrString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_HasAttrString), GetUnmanagedDll(PythonDLL)));
+ PyObject_GetAttrString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GetAttrString), GetUnmanagedDll(PythonDLL)));
+ PyObject_SetAttrString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_SetAttrString), GetUnmanagedDll(PythonDLL)));
+ PyObject_HasAttr = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_HasAttr), GetUnmanagedDll(PythonDLL)));
+ PyObject_GetAttr = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GetAttr), GetUnmanagedDll(PythonDLL)));
+ PyObject_SetAttr = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_SetAttr), GetUnmanagedDll(PythonDLL)));
+ PyObject_GetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GetItem), GetUnmanagedDll(PythonDLL)));
+ PyObject_SetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_SetItem), GetUnmanagedDll(PythonDLL)));
+ PyObject_DelItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_DelItem), GetUnmanagedDll(PythonDLL)));
+ PyObject_GetIter = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GetIter), GetUnmanagedDll(PythonDLL)));
+ PyObject_Call = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_Call), GetUnmanagedDll(PythonDLL)));
+ PyObject_CallObject = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_CallObject), GetUnmanagedDll(PythonDLL)));
+ PyObject_RichCompareBool = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_RichCompareBool), GetUnmanagedDll(PythonDLL)));
+ PyObject_IsInstance = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_IsInstance), GetUnmanagedDll(PythonDLL)));
+ PyObject_IsSubclass = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_IsSubclass), GetUnmanagedDll(PythonDLL)));
+ PyCallable_Check = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyCallable_Check), GetUnmanagedDll(PythonDLL)));
+ PyObject_IsTrue = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_IsTrue), GetUnmanagedDll(PythonDLL)));
+ PyObject_Not = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_Not), GetUnmanagedDll(PythonDLL)));
+ _PyObject_Size = GetDelegateForFunctionPointer<_PyObject_SizeDelegate>(GetFunctionByName("PyObject_Size", GetUnmanagedDll(PythonDLL)));
+ PyObject_Hash = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_Hash), GetUnmanagedDll(PythonDLL)));
+ PyObject_Repr = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_Repr), GetUnmanagedDll(PythonDLL)));
+ PyObject_Str = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_Str), GetUnmanagedDll(PythonDLL)));
+ PyObject_Unicode = GetDelegateForFunctionPointer(GetFunctionByName("PyObject_Str", GetUnmanagedDll(PythonDLL)));
+ PyObject_Dir = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_Dir), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Int = GetDelegateForFunctionPointer(GetFunctionByName("PyNumber_Long", GetUnmanagedDll(PythonDLL)));
+ PyNumber_Long = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Long), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Float = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Float), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Check = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Check), GetUnmanagedDll(PythonDLL)));
+ PyInt_FromLong = GetDelegateForFunctionPointer(GetFunctionByName("PyLong_FromLong", GetUnmanagedDll(PythonDLL)));
+ PyInt_AsLong = GetDelegateForFunctionPointer(GetFunctionByName("PyLong_AsLong", GetUnmanagedDll(PythonDLL)));
+ PyInt_FromString = GetDelegateForFunctionPointer(GetFunctionByName("PyLong_FromString", GetUnmanagedDll(PythonDLL)));
+ PyLong_FromLong = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_FromLong), GetUnmanagedDll(PythonDLL)));
+ PyLong_FromUnsignedLong32 = GetDelegateForFunctionPointer(GetFunctionByName("PyLong_FromUnsignedLong", GetUnmanagedDll(PythonDLL)));
+ PyLong_FromUnsignedLong64 = GetDelegateForFunctionPointer(GetFunctionByName("PyLong_FromUnsignedLong", GetUnmanagedDll(PythonDLL)));
+ PyLong_FromUnsignedLong = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_FromUnsignedLong), GetUnmanagedDll(PythonDLL)));
+ PyLong_FromDouble = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_FromDouble), GetUnmanagedDll(PythonDLL)));
+ PyLong_FromLongLong = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_FromLongLong), GetUnmanagedDll(PythonDLL)));
+ PyLong_FromUnsignedLongLong = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_FromUnsignedLongLong), GetUnmanagedDll(PythonDLL)));
+ PyLong_FromString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_FromString), GetUnmanagedDll(PythonDLL)));
+ PyLong_AsLong = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_AsLong), GetUnmanagedDll(PythonDLL)));
+ PyLong_AsUnsignedLong32 = GetDelegateForFunctionPointer(GetFunctionByName("PyLong_AsUnsignedLong", GetUnmanagedDll(PythonDLL)));
+ PyLong_AsUnsignedLong64 = GetDelegateForFunctionPointer(GetFunctionByName("PyLong_AsUnsignedLong", GetUnmanagedDll(PythonDLL)));
+ PyLong_AsUnsignedLong = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_AsUnsignedLong), GetUnmanagedDll(PythonDLL)));
+ PyLong_AsLongLong = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_AsLongLong), GetUnmanagedDll(PythonDLL)));
+ PyLong_AsUnsignedLongLong = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyLong_AsUnsignedLongLong), GetUnmanagedDll(PythonDLL)));
+ PyFloat_FromDouble = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyFloat_FromDouble), GetUnmanagedDll(PythonDLL)));
+ PyFloat_FromString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyFloat_FromString), GetUnmanagedDll(PythonDLL)));
+ PyFloat_AsDouble = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyFloat_AsDouble), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Add = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Add), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Subtract = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Subtract), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Multiply = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Multiply), GetUnmanagedDll(PythonDLL)));
+ PyNumber_TrueDivide = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_TrueDivide), GetUnmanagedDll(PythonDLL)));
+ PyNumber_And = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_And), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Xor = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Xor), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Or = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Or), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Lshift = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Lshift), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Rshift = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Rshift), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Power = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Power), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Remainder = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Remainder), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceAdd = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceAdd), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceSubtract = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceSubtract), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceMultiply = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceMultiply), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceTrueDivide = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceTrueDivide), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceAnd = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceAnd), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceXor = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceXor), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceOr = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceOr), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceLshift = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceLshift), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceRshift = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceRshift), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlacePower = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlacePower), GetUnmanagedDll(PythonDLL)));
+ PyNumber_InPlaceRemainder = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_InPlaceRemainder), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Negative = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Negative), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Positive = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Positive), GetUnmanagedDll(PythonDLL)));
+ PyNumber_Invert = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyNumber_Invert), GetUnmanagedDll(PythonDLL)));
+ PySequence_Check = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_Check), GetUnmanagedDll(PythonDLL)));
+ PySequence_GetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_GetItem), GetUnmanagedDll(PythonDLL)));
+ PySequence_SetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_SetItem), GetUnmanagedDll(PythonDLL)));
+ PySequence_DelItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_DelItem), GetUnmanagedDll(PythonDLL)));
+ PySequence_GetSlice = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_GetSlice), GetUnmanagedDll(PythonDLL)));
+ PySequence_SetSlice = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_SetSlice), GetUnmanagedDll(PythonDLL)));
+ PySequence_DelSlice = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_DelSlice), GetUnmanagedDll(PythonDLL)));
+ _PySequence_Size = GetDelegateForFunctionPointer<_PySequence_SizeDelegate>(GetFunctionByName("PySequence_Size", GetUnmanagedDll(PythonDLL)));
+ PySequence_Contains = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_Contains), GetUnmanagedDll(PythonDLL)));
+ PySequence_Concat = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_Concat), GetUnmanagedDll(PythonDLL)));
+ PySequence_Repeat = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_Repeat), GetUnmanagedDll(PythonDLL)));
+ PySequence_Index = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_Index), GetUnmanagedDll(PythonDLL)));
+ _PySequence_Count = GetDelegateForFunctionPointer<_PySequence_CountDelegate>(GetFunctionByName("PySequence_Count", GetUnmanagedDll(PythonDLL)));
+ PySequence_Tuple = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_Tuple), GetUnmanagedDll(PythonDLL)));
+ PySequence_List = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySequence_List), GetUnmanagedDll(PythonDLL)));
+ PyBytes_FromString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyBytes_FromString), GetUnmanagedDll(PythonDLL)));
+ _PyBytes_Size = GetDelegateForFunctionPointer<_PyBytes_SizeDelegate>(GetFunctionByName("PyBytes_Size", GetUnmanagedDll(PythonDLL)));
+ _PyString_FromStringAndSize = GetDelegateForFunctionPointer<_PyString_FromStringAndSizeDelegate>(GetFunctionByName("PyUnicode_FromStringAndSize", GetUnmanagedDll(PythonDLL)));
+ PyUnicode_FromStringAndSize = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyUnicode_FromStringAndSize), GetUnmanagedDll(PythonDLL)));
+ PyUnicode_AsUTF8 = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyUnicode_AsUTF8), GetUnmanagedDll(PythonDLL)));
+ PyUnicode_FromObject = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyUnicode_FromObject), GetUnmanagedDll(PythonDLL)));
+ PyUnicode_FromEncodedObject = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyUnicode_FromEncodedObject), GetUnmanagedDll(PythonDLL)));
+ PyUnicode_FromKindAndData = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyUnicode_FromKindAndData), GetUnmanagedDll(PythonDLL)));
+ _PyUnicode_GetSize = GetDelegateForFunctionPointer<_PyUnicode_GetSizeDelegate>(GetFunctionByName("PyUnicode_GetSize", GetUnmanagedDll(PythonDLL)));
+ PyUnicode_AsUnicode = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyUnicode_AsUnicode), GetUnmanagedDll(PythonDLL)));
+ PyUnicode_FromOrdinal = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyUnicode_FromOrdinal), GetUnmanagedDll(PythonDLL)));
+ PyDict_New = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_New), GetUnmanagedDll(PythonDLL)));
+ PyDictProxy_New = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDictProxy_New), GetUnmanagedDll(PythonDLL)));
+ PyDict_GetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_GetItem), GetUnmanagedDll(PythonDLL)));
+ PyDict_GetItemString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_GetItemString), GetUnmanagedDll(PythonDLL)));
+ PyDict_SetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_SetItem), GetUnmanagedDll(PythonDLL)));
+ PyDict_SetItemString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_SetItemString), GetUnmanagedDll(PythonDLL)));
+ PyDict_DelItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_DelItem), GetUnmanagedDll(PythonDLL)));
+ PyDict_DelItemString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_DelItemString), GetUnmanagedDll(PythonDLL)));
+ PyMapping_HasKey = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyMapping_HasKey), GetUnmanagedDll(PythonDLL)));
+ PyDict_Keys = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_Keys), GetUnmanagedDll(PythonDLL)));
+ PyDict_Values = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_Values), GetUnmanagedDll(PythonDLL)));
+ PyDict_Items = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_Items), GetUnmanagedDll(PythonDLL)));
+ PyDict_Copy = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_Copy), GetUnmanagedDll(PythonDLL)));
+ PyDict_Update = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_Update), GetUnmanagedDll(PythonDLL)));
+ PyDict_Clear = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyDict_Clear), GetUnmanagedDll(PythonDLL)));
+ _PyDict_Size = GetDelegateForFunctionPointer<_PyDict_SizeDelegate>(GetFunctionByName("PyDict_Size", GetUnmanagedDll(PythonDLL)));
+ PyList_New = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_New), GetUnmanagedDll(PythonDLL)));
+ PyList_AsTuple = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_AsTuple), GetUnmanagedDll(PythonDLL)));
+ PyList_GetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_GetItem), GetUnmanagedDll(PythonDLL)));
+ PyList_SetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_SetItem), GetUnmanagedDll(PythonDLL)));
+ PyList_Insert = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_Insert), GetUnmanagedDll(PythonDLL)));
+ PyList_Append = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_Append), GetUnmanagedDll(PythonDLL)));
+ PyList_Reverse = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_Reverse), GetUnmanagedDll(PythonDLL)));
+ PyList_Sort = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_Sort), GetUnmanagedDll(PythonDLL)));
+ PyList_GetSlice = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_GetSlice), GetUnmanagedDll(PythonDLL)));
+ PyList_SetSlice = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyList_SetSlice), GetUnmanagedDll(PythonDLL)));
+ _PyList_Size = GetDelegateForFunctionPointer<_PyList_SizeDelegate>(GetFunctionByName("PyList_Size", GetUnmanagedDll(PythonDLL)));
+ PyTuple_New = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyTuple_New), GetUnmanagedDll(PythonDLL)));
+ PyTuple_GetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyTuple_GetItem), GetUnmanagedDll(PythonDLL)));
+ PyTuple_SetItem = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyTuple_SetItem), GetUnmanagedDll(PythonDLL)));
+ PyTuple_GetSlice = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyTuple_GetSlice), GetUnmanagedDll(PythonDLL)));
+ _PyTuple_Size = GetDelegateForFunctionPointer<_PyTuple_SizeDelegate>(GetFunctionByName("PyTuple_Size", GetUnmanagedDll(PythonDLL)));
+ PyIter_Next = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyIter_Next), GetUnmanagedDll(PythonDLL)));
+ PyModule_New = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyModule_New), GetUnmanagedDll(PythonDLL)));
+ PyModule_GetName = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyModule_GetName), GetUnmanagedDll(PythonDLL)));
+ PyModule_GetDict = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyModule_GetDict), GetUnmanagedDll(PythonDLL)));
+ PyModule_GetFilename = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyModule_GetFilename), GetUnmanagedDll(PythonDLL)));
+ PyModule_Create2 = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyModule_Create2), GetUnmanagedDll(PythonDLL)));
+ PyImport_Import = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyImport_Import), GetUnmanagedDll(PythonDLL)));
+ PyImport_ImportModule = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyImport_ImportModule), GetUnmanagedDll(PythonDLL)));
+ PyImport_ReloadModule = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyImport_ReloadModule), GetUnmanagedDll(PythonDLL)));
+ PyImport_AddModule = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyImport_AddModule), GetUnmanagedDll(PythonDLL)));
+ PyImport_GetModuleDict = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyImport_GetModuleDict), GetUnmanagedDll(PythonDLL)));
+ PySys_SetArgvEx = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySys_SetArgvEx), GetUnmanagedDll(PythonDLL)));
+ PySys_GetObject = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySys_GetObject), GetUnmanagedDll(PythonDLL)));
+ PySys_SetObject = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PySys_SetObject), GetUnmanagedDll(PythonDLL)));
+ PyType_Modified = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyType_Modified), GetUnmanagedDll(PythonDLL)));
+ PyType_IsSubtype = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyType_IsSubtype), GetUnmanagedDll(PythonDLL)));
+ PyType_GenericNew = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyType_GenericNew), GetUnmanagedDll(PythonDLL)));
+ PyType_GenericAlloc = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyType_GenericAlloc), GetUnmanagedDll(PythonDLL)));
+ PyType_Ready = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyType_Ready), GetUnmanagedDll(PythonDLL)));
+ _PyType_Lookup = GetDelegateForFunctionPointer<_PyType_LookupDelegate>(GetFunctionByName(nameof(_PyType_Lookup), GetUnmanagedDll(PythonDLL)));
+ PyObject_GenericGetAttr = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GenericGetAttr), GetUnmanagedDll(PythonDLL)));
+ PyObject_GenericSetAttr = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GenericSetAttr), GetUnmanagedDll(PythonDLL)));
+ _PyObject_GetDictPtr = GetDelegateForFunctionPointer<_PyObject_GetDictPtrDelegate>(GetFunctionByName(nameof(_PyObject_GetDictPtr), GetUnmanagedDll(PythonDLL)));
+ PyObject_GC_Del = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GC_Del), GetUnmanagedDll(PythonDLL)));
+ PyObject_GC_Track = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GC_Track), GetUnmanagedDll(PythonDLL)));
+ PyObject_GC_UnTrack = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyObject_GC_UnTrack), GetUnmanagedDll(PythonDLL)));
+ PyMem_Malloc = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyMem_Malloc), GetUnmanagedDll(PythonDLL)));
+ PyMem_Realloc = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyMem_Realloc), GetUnmanagedDll(PythonDLL)));
+ PyMem_Free = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyMem_Free), GetUnmanagedDll(PythonDLL)));
+ PyErr_SetString = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_SetString), GetUnmanagedDll(PythonDLL)));
+ PyErr_SetObject = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_SetObject), GetUnmanagedDll(PythonDLL)));
+ PyErr_SetFromErrno = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_SetFromErrno), GetUnmanagedDll(PythonDLL)));
+ PyErr_SetNone = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_SetNone), GetUnmanagedDll(PythonDLL)));
+ PyErr_ExceptionMatches = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_ExceptionMatches), GetUnmanagedDll(PythonDLL)));
+ PyErr_GivenExceptionMatches = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_GivenExceptionMatches), GetUnmanagedDll(PythonDLL)));
+ PyErr_NormalizeException = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_NormalizeException), GetUnmanagedDll(PythonDLL)));
+ PyErr_Occurred = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_Occurred), GetUnmanagedDll(PythonDLL)));
+ PyErr_Fetch = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_Fetch), GetUnmanagedDll(PythonDLL)));
+ PyErr_Restore = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_Restore), GetUnmanagedDll(PythonDLL)));
+ PyErr_Clear = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_Clear), GetUnmanagedDll(PythonDLL)));
+ PyErr_Print = GetDelegateForFunctionPointer(GetFunctionByName(nameof(PyErr_Print), GetUnmanagedDll(PythonDLL)));
+ PyCell_Get = GetDelegateForFunctionPointer