diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..43e8ab1e3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.dockerignore +.env +.git +.gitignore +.vs +.vscode +docker-compose.yml +docker-compose.*.yml +*/bin +*/obj diff --git a/DockerTest/DockerTest.csproj b/DockerTest/DockerTest.csproj new file mode 100644 index 000000000..0751c5ba5 --- /dev/null +++ b/DockerTest/DockerTest.csproj @@ -0,0 +1,19 @@ + + + + Exe + netcoreapp2.1 + Debug;Release + + + + + + + + + PreserveNewest + + + + diff --git a/DockerTest/Dockerfile b/DockerTest/Dockerfile new file mode 100644 index 000000000..d89dc670a --- /dev/null +++ b/DockerTest/Dockerfile @@ -0,0 +1,26 @@ +FROM microsoft/dotnet:2.1-runtime AS base +RUN apt-get update -y && apt-get install python3 -y && apt-get install python3-pip -y +RUN ldconfig + +WORKDIR /app + +FROM microsoft/dotnet:2.1-sdk AS build +WORKDIR /src +COPY DockerTest/DockerTest.csproj DockerTest/ +RUN dotnet restore DockerTest/DockerTest.csproj +COPY . . +WORKDIR /src/DockerTest +RUN dotnet build DockerTest.csproj -c ReleasePy3 -o /app + +FROM build AS publish +RUN dotnet publish DockerTest.csproj -c ReleasePy3 -o /app + +FROM base AS final +WORKDIR /app +COPY --from=publish /app . + +RUN pip3 install --no-cache-dir -r requirements.txt + +ENV LD_LIBRARY_PATH /usr/lib/python3.5/config-3.5m-x86_64-linux-gnu + +ENTRYPOINT ["dotnet", "DockerTest.dll"] diff --git a/DockerTest/Program.cs b/DockerTest/Program.cs new file mode 100644 index 000000000..b086b3f3f --- /dev/null +++ b/DockerTest/Program.cs @@ -0,0 +1,17 @@ +using Python.Runtime; +using System; + +namespace DockerTest +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + + var state = Py.GIL(); + var sys = Py.Import("sys"); + var np = Py.Import("numpy"); + } + } +} diff --git a/DockerTest/requirements.txt b/DockerTest/requirements.txt new file mode 100644 index 000000000..24ce15ab7 --- /dev/null +++ b/DockerTest/requirements.txt @@ -0,0 +1 @@ +numpy diff --git a/docker-compose.dcproj b/docker-compose.dcproj new file mode 100644 index 000000000..cd6e2027f --- /dev/null +++ b/docker-compose.dcproj @@ -0,0 +1,25 @@ + + + + + Debug + AnyCPU + + + Release + AnyCPU + + + + 2.1 + Linux + 7b1fe155-4e45-42a7-9a4b-0a19f12d89ac + + + + docker-compose.yml + + + + + \ No newline at end of file diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 000000000..8e89b0713 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1 @@ +version: '3.4' diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..240dba072 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.4' + +services: + dockertest: + image: ${DOCKER_REGISTRY}dockertest + build: + context: . + dockerfile: DockerTest/Dockerfile diff --git a/pythonnet.15.sln b/pythonnet.15.sln index f2015e480..591312184 100644 --- a/pythonnet.15.sln +++ b/pythonnet.15.sln @@ -2,188 +2,188 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26730.3 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime.15", "src/runtime/Python.Runtime.15.csproj", "{2759F4FF-716B-4828-916F-50FA86613DFC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime.15", "src\runtime\Python.Runtime.15.csproj", "{2759F4FF-716B-4828-916F-50FA86613DFC}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest.15", "src/embed_tests/Python.EmbeddingTest.15.csproj", "{66B8D01A-9906-452A-B09E-BF75EA76468F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest.15", "src\embed_tests\Python.EmbeddingTest.15.csproj", "{66B8D01A-9906-452A-B09E-BF75EA76468F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule.15", "src/clrmodule/clrmodule.15.csproj", "{E08678D4-9A52-4AD5-B63D-8EBC7399981B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule.15", "src\clrmodule\clrmodule.15.csproj", "{E08678D4-9A52-4AD5-B63D-8EBC7399981B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.15", "src/console/Console.15.csproj", "{CDAD305F-8E72-492C-A314-64CF58D472A0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.15", "src\console\Console.15.csproj", "{CDAD305F-8E72-492C-A314-64CF58D472A0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test.15", "src/testing/Python.Test.15.csproj", "{F94B547A-E97E-4500-8D53-B4D64D076E5F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test.15", "src\testing\Python.Test.15.csproj", "{F94B547A-E97E-4500-8D53-B4D64D076E5F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DockerTest", "DockerTest\DockerTest.csproj", "{C30466F1-FA00-407C-B8C3-748887AB1082}" +EndProject +Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}" 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 + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + DebugPY3|Any CPU = DebugPY3|Any CPU + DebugPY3|x64 = DebugPY3|x64 + DebugPY3|x86 = DebugPY3|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + ReleasePY3|Any CPU = ReleasePY3|Any CPU + ReleasePY3|x64 = ReleasePY3|x64 + ReleasePY3|x86 = ReleasePY3|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {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|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|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|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}.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|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|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|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}.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|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|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|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}.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|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|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|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}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMono|x86.ActiveCfg = DebugMono|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|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|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}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMono|x86.ActiveCfg = ReleaseMono|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|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|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}.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|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|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|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}.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|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|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|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}.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|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|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|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}.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|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|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|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 + {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}.Debug|x64.ActiveCfg = Debug|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x64.Build.0 = Debug|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x86.ActiveCfg = Debug|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x86.Build.0 = Debug|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugPY3|Any CPU.ActiveCfg = DebugPY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugPY3|Any CPU.Build.0 = DebugPY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugPY3|x64.ActiveCfg = DebugPY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugPY3|x64.Build.0 = DebugPY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugPY3|x86.ActiveCfg = DebugPY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugPY3|x86.Build.0 = DebugPY3|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 + {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x64.ActiveCfg = Release|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x64.Build.0 = Release|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x86.ActiveCfg = Release|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x86.Build.0 = Release|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleasePY3|Any CPU.ActiveCfg = ReleasePY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleasePY3|Any CPU.Build.0 = ReleasePY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleasePY3|x64.ActiveCfg = ReleasePY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleasePY3|x64.Build.0 = ReleasePY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleasePY3|x86.ActiveCfg = ReleasePY3|Any CPU + {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleasePY3|x86.Build.0 = ReleasePY3|Any CPU + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|Any CPU.ActiveCfg = Debug|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x64.ActiveCfg = Debug|x64 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x64.Build.0 = Debug|x64 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x86.ActiveCfg = Debug|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x86.Build.0 = Debug|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugPY3|Any CPU.ActiveCfg = DebugPY3|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugPY3|x64.ActiveCfg = DebugPY3|x64 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugPY3|x64.Build.0 = DebugPY3|x64 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugPY3|x86.ActiveCfg = DebugPY3|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugPY3|x86.Build.0 = DebugPY3|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|Any CPU.ActiveCfg = Release|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x64.ActiveCfg = Release|x64 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x64.Build.0 = Release|x64 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x86.ActiveCfg = Release|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x86.Build.0 = Release|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleasePY3|Any CPU.ActiveCfg = ReleasePY3|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleasePY3|x64.ActiveCfg = ReleasePY3|x64 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleasePY3|x64.Build.0 = ReleasePY3|x64 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleasePY3|x86.ActiveCfg = ReleasePY3|x86 + {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleasePY3|x86.Build.0 = ReleasePY3|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|Any CPU.ActiveCfg = Debug|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x64.ActiveCfg = Debug|x64 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x64.Build.0 = Debug|x64 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x86.ActiveCfg = Debug|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x86.Build.0 = Debug|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugPY3|Any CPU.ActiveCfg = DebugPY3|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugPY3|x64.ActiveCfg = DebugPY3|x64 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugPY3|x64.Build.0 = DebugPY3|x64 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugPY3|x86.ActiveCfg = DebugPY3|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugPY3|x86.Build.0 = DebugPY3|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|Any CPU.ActiveCfg = Release|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x64.ActiveCfg = Release|x64 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x64.Build.0 = Release|x64 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x86.ActiveCfg = Release|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x86.Build.0 = Release|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleasePY3|Any CPU.ActiveCfg = ReleasePY3|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleasePY3|x64.ActiveCfg = ReleasePY3|x64 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleasePY3|x64.Build.0 = ReleasePY3|x64 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleasePY3|x86.ActiveCfg = ReleasePY3|x86 + {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleasePY3|x86.Build.0 = ReleasePY3|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|Any CPU.ActiveCfg = Debug|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x64.ActiveCfg = Debug|x64 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x64.Build.0 = Debug|x64 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x86.ActiveCfg = Debug|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x86.Build.0 = Debug|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugPY3|Any CPU.ActiveCfg = DebugPY3|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugPY3|x64.ActiveCfg = DebugPY3|x64 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugPY3|x64.Build.0 = DebugPY3|x64 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugPY3|x86.ActiveCfg = DebugPY3|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugPY3|x86.Build.0 = DebugPY3|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|Any CPU.ActiveCfg = Release|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x64.ActiveCfg = Release|x64 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x64.Build.0 = Release|x64 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x86.ActiveCfg = Release|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x86.Build.0 = Release|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleasePY3|Any CPU.ActiveCfg = ReleasePY3|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleasePY3|x64.ActiveCfg = ReleasePY3|x64 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleasePY3|x64.Build.0 = ReleasePY3|x64 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleasePY3|x86.ActiveCfg = ReleasePY3|x86 + {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleasePY3|x86.Build.0 = ReleasePY3|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|Any CPU.ActiveCfg = Debug|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x64.ActiveCfg = Debug|x64 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x64.Build.0 = Debug|x64 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x86.ActiveCfg = Debug|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x86.Build.0 = Debug|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugPY3|Any CPU.ActiveCfg = DebugPY3|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugPY3|x64.ActiveCfg = DebugPY3|x64 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugPY3|x64.Build.0 = DebugPY3|x64 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugPY3|x86.ActiveCfg = DebugPY3|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugPY3|x86.Build.0 = DebugPY3|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|Any CPU.ActiveCfg = Release|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x64.ActiveCfg = Release|x64 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x64.Build.0 = Release|x64 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x86.ActiveCfg = Release|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x86.Build.0 = Release|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleasePY3|Any CPU.ActiveCfg = ReleasePY3|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleasePY3|x64.ActiveCfg = ReleasePY3|x64 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleasePY3|x64.Build.0 = ReleasePY3|x64 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleasePY3|x86.ActiveCfg = ReleasePY3|x86 + {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleasePY3|x86.Build.0 = ReleasePY3|x86 + {C30466F1-FA00-407C-B8C3-748887AB1082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Debug|x64.ActiveCfg = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Debug|x64.Build.0 = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Debug|x86.ActiveCfg = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Debug|x86.Build.0 = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.DebugPY3|Any CPU.ActiveCfg = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.DebugPY3|Any CPU.Build.0 = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.DebugPY3|x64.ActiveCfg = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.DebugPY3|x64.Build.0 = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.DebugPY3|x86.ActiveCfg = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.DebugPY3|x86.Build.0 = Debug|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Release|Any CPU.Build.0 = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Release|x64.ActiveCfg = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Release|x64.Build.0 = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Release|x86.ActiveCfg = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.Release|x86.Build.0 = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.ReleasePY3|Any CPU.ActiveCfg = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.ReleasePY3|Any CPU.Build.0 = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.ReleasePY3|x64.ActiveCfg = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.ReleasePY3|x64.Build.0 = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.ReleasePY3|x86.ActiveCfg = Release|Any CPU + {C30466F1-FA00-407C-B8C3-748887AB1082}.ReleasePY3|x86.Build.0 = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Debug|x64.ActiveCfg = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Debug|x64.Build.0 = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Debug|x86.ActiveCfg = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Debug|x86.Build.0 = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.DebugPY3|Any CPU.ActiveCfg = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.DebugPY3|Any CPU.Build.0 = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.DebugPY3|x64.ActiveCfg = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.DebugPY3|x64.Build.0 = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.DebugPY3|x86.ActiveCfg = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.DebugPY3|x86.Build.0 = Debug|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Release|Any CPU.Build.0 = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Release|x64.ActiveCfg = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Release|x64.Build.0 = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Release|x86.ActiveCfg = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.Release|x86.Build.0 = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.ReleasePY3|Any CPU.ActiveCfg = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.ReleasePY3|Any CPU.Build.0 = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.ReleasePY3|x64.ActiveCfg = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.ReleasePY3|x64.Build.0 = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.ReleasePY3|x86.ActiveCfg = Release|Any CPU + {7B1FE155-4E45-42A7-9A4B-0A19F12D89AC}.ReleasePY3|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/clrmodule/clrmodule.15.csproj b/src/clrmodule/clrmodule.15.csproj index 2585ffdd2..384085986 100644 --- a/src/clrmodule/clrmodule.15.csproj +++ b/src/clrmodule/clrmodule.15.csproj @@ -5,7 +5,7 @@ net40 x64;x86 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 + Debug;DebugPY3;Release;ReleasePY3 clrmodule clrmodule clrmodule @@ -46,29 +46,16 @@ true pdbonly - - - $(DefineConstants);PYTHON2;TRACE;DEBUG - - - $(DefineConstants);PYTHON2 - - + $(DefineConstants);PYTHON2;TRACE;DEBUG - + $(DefineConstants);PYTHON2 - - $(DefineConstants);PYTHON3;TRACE;DEBUG - - - $(DefineConstants);PYTHON3 - - + $(DefineConstants);PYTHON3;TRACE;DEBUG - + $(DefineConstants);PYTHON3 diff --git a/src/console/Console.15.csproj b/src/console/Console.15.csproj index ec5008036..db04bc4e8 100644 --- a/src/console/Console.15.csproj +++ b/src/console/Console.15.csproj @@ -1,9 +1,9 @@ - + net40;netcoreapp2.0 x64;x86 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 + Debug;DebugPY3;Release;ReleasePY3 Exe nPython Python.Runtime diff --git a/src/console/pythonconsole.cs b/src/console/pythonconsole.cs index 912e9bb0d..c6da4278c 100644 --- a/src/console/pythonconsole.cs +++ b/src/console/pythonconsole.cs @@ -34,7 +34,7 @@ public static int Main(string[] args) string[] cmd = Environment.GetCommandLineArgs(); PythonEngine.Initialize(); - int i = Runtime.Py_Main(cmd.Length, cmd); + int i = Runtime.Interop.Py_Main(cmd.Length, cmd); PythonEngine.Shutdown(); return i; diff --git a/src/embed_tests/Python.EmbeddingTest.15.csproj b/src/embed_tests/Python.EmbeddingTest.15.csproj index 92d55a7e0..2faa3bd98 100644 --- a/src/embed_tests/Python.EmbeddingTest.15.csproj +++ b/src/embed_tests/Python.EmbeddingTest.15.csproj @@ -4,7 +4,7 @@ net40;netcoreapp2.0 x64;x86 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 + Debug;DebugPY3;Release;ReleasePY3 Exe false Python.EmbeddingTest diff --git a/src/embed_tests/TestRuntime.cs b/src/embed_tests/TestRuntime.cs index 2e0598da7..e8372c409 100644 --- a/src/embed_tests/TestRuntime.cs +++ b/src/embed_tests/TestRuntime.cs @@ -1,4 +1,4 @@ -using System; +using System; using NUnit.Framework; using Python.Runtime; @@ -9,18 +9,18 @@ public class TestRuntime [Test] public static void Py_IsInitializedValue() { - Runtime.Runtime.Py_Finalize(); // In case another test left it on. - Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized()); - Runtime.Runtime.Py_Initialize(); - Assert.AreEqual(1, Runtime.Runtime.Py_IsInitialized()); - Runtime.Runtime.Py_Finalize(); - Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized()); + Runtime.Runtime.Interop.Py_Finalize(); // In case another test left it on. + Assert.AreEqual(0, Runtime.Runtime.Interop.Py_IsInitialized()); + Runtime.Runtime.Interop.Py_Initialize(); + Assert.AreEqual(1, Runtime.Runtime.Interop.Py_IsInitialized()); + Runtime.Runtime.Interop.Py_Finalize(); + Assert.AreEqual(0, Runtime.Runtime.Interop.Py_IsInitialized()); } [Test] public static void RefCountTest() { - Runtime.Runtime.Py_Initialize(); + Runtime.Runtime.Interop.Py_Initialize(); IntPtr op = Runtime.Runtime.PyUnicode_FromString("FooBar"); // New object RefCount should be one @@ -34,9 +34,9 @@ public static void RefCountTest() Assert.AreEqual(1, Runtime.Runtime.Refcount(p)); // Py_IncRef/Py_DecRef increase and decrease RefCount - Runtime.Runtime.Py_IncRef(op); + Runtime.Runtime.Interop.Py_IncRef(op); Assert.AreEqual(2, Runtime.Runtime.Refcount(op)); - Runtime.Runtime.Py_DecRef(op); + Runtime.Runtime.Interop.Py_DecRef(op); Assert.AreEqual(1, Runtime.Runtime.Refcount(op)); // XIncref/XDecref increase and decrease RefCount @@ -45,48 +45,48 @@ public static void RefCountTest() Runtime.Runtime.XDecref(op); Assert.AreEqual(1, Runtime.Runtime.Refcount(op)); - Runtime.Runtime.Py_Finalize(); + Runtime.Runtime.Interop.Py_Finalize(); } [Test] public static void PyCheck_Iter_PyObject_IsIterable_Test() { - Runtime.Runtime.Py_Initialize(); + Runtime.Runtime.Interop.Py_Initialize(); // Tests that a python list is an iterable, but not an iterator - var pyList = Runtime.Runtime.PyList_New(0); + var pyList = Runtime.Runtime.Interop.PyList_New(0); Assert.IsFalse(Runtime.Runtime.PyIter_Check(pyList)); Assert.IsTrue(Runtime.Runtime.PyObject_IsIterable(pyList)); // Tests that a python list iterator is both an iterable and an iterator - var pyListIter = Runtime.Runtime.PyObject_GetIter(pyList); + var pyListIter = Runtime.Runtime.Interop.PyObject_GetIter(pyList); Assert.IsTrue(Runtime.Runtime.PyObject_IsIterable(pyListIter)); Assert.IsTrue(Runtime.Runtime.PyIter_Check(pyListIter)); // Tests that a python float is neither an iterable nor an iterator - var pyFloat = Runtime.Runtime.PyFloat_FromDouble(2.73); + var pyFloat = Runtime.Runtime.Interop.PyFloat_FromDouble(2.73); Assert.IsFalse(Runtime.Runtime.PyObject_IsIterable(pyFloat)); Assert.IsFalse(Runtime.Runtime.PyIter_Check(pyFloat)); - Runtime.Runtime.Py_Finalize(); + Runtime.Runtime.Interop.Py_Finalize(); } [Test] public static void PyCheck_Iter_PyObject_IsIterable_ThreadingLock_Test() { - Runtime.Runtime.Py_Initialize(); + Runtime.Runtime.Interop.Py_Initialize(); // Create an instance of threading.Lock, which is one of the very few types that does not have the // TypeFlags.HaveIter set in Python 2. This tests a different code path in PyObject_IsIterable and PyIter_Check. - var threading = Runtime.Runtime.PyImport_ImportModule("threading"); - var threadingDict = Runtime.Runtime.PyModule_GetDict(threading); - var lockType = Runtime.Runtime.PyDict_GetItemString(threadingDict, "Lock"); - var lockInstance = Runtime.Runtime.PyObject_CallObject(lockType, Runtime.Runtime.PyTuple_New(0)); + var threading = Runtime.Runtime.Interop.PyImport_ImportModule("threading"); + var threadingDict = Runtime.Runtime.Interop.PyModule_GetDict(threading); + var lockType = Runtime.Runtime.Interop.PyDict_GetItemString(threadingDict, "Lock"); + var lockInstance = Runtime.Runtime.Interop.PyObject_CallObject(lockType, Runtime.Runtime.Interop.PyTuple_New(0)); Assert.IsFalse(Runtime.Runtime.PyObject_IsIterable(lockInstance)); Assert.IsFalse(Runtime.Runtime.PyIter_Check(lockInstance)); - Runtime.Runtime.Py_Finalize(); + Runtime.Runtime.Interop.Py_Finalize(); } } } diff --git a/src/embed_tests/pyimport.cs b/src/embed_tests/pyimport.cs index acb3433de..1a091ed03 100644 --- a/src/embed_tests/pyimport.cs +++ b/src/embed_tests/pyimport.cs @@ -38,8 +38,8 @@ public void SetUp() string testPath = Path.Combine(TestContext.CurrentContext.TestDirectory, s); IntPtr str = Runtime.Runtime.PyString_FromString(testPath); - IntPtr path = Runtime.Runtime.PySys_GetObject("path"); - Runtime.Runtime.PyList_Append(path, str); + IntPtr path = Runtime.Runtime.Interop.PySys_GetObject("path"); + Runtime.Runtime.Interop.PyList_Append(path, str); } [TearDown] diff --git a/src/embed_tests/pyinitialize.cs b/src/embed_tests/pyinitialize.cs index 2f9aae2c7..e42fc6f63 100644 --- a/src/embed_tests/pyinitialize.cs +++ b/src/embed_tests/pyinitialize.cs @@ -24,7 +24,7 @@ public static void StartAndStopTwice() public static void LoadDefaultArgs() { using (new PythonEngine()) - using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv"))) + using (var argv = new PyList(Runtime.Runtime.Interop.PySys_GetObject("argv"))) { Assert.AreNotEqual(0, argv.Length()); } @@ -35,7 +35,7 @@ public static void LoadSpecificArgs() { var args = new[] { "test1", "test2" }; using (new PythonEngine(args)) - using (var argv = new PyList(Runtime.Runtime.PySys_GetObject("argv"))) + using (var argv = new PyList(Runtime.Runtime.Interop.PySys_GetObject("argv"))) { Assert.AreEqual(args[0], argv[0].ToString()); Assert.AreEqual(args[1], argv[1].ToString()); diff --git a/src/runtime/IInterop.cs b/src/runtime/IInterop.cs new file mode 100644 index 000000000..995ac09e8 --- /dev/null +++ b/src/runtime/IInterop.cs @@ -0,0 +1,235 @@ +using System; + +namespace Python.Runtime +{ + public interface IInterop + { + string GetDllName(); + IntPtr PyBytes_FromString(string op); + int PyBytes_Size(IntPtr op); + int PyCallable_Check(IntPtr pointer); + IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw); + IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod); + IntPtr PyClass_New(IntPtr bases, IntPtr dict, IntPtr name); + IntPtr PyDictProxy_New(IntPtr dict); + void PyDict_Clear(IntPtr pointer); + IntPtr PyDict_Copy(IntPtr pointer); + int PyDict_DelItem(IntPtr pointer, IntPtr key); + int PyDict_DelItemString(IntPtr pointer, string key); + IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key); + IntPtr PyDict_GetItemString(IntPtr pointer, string key); + IntPtr PyDict_Items(IntPtr pointer); + IntPtr PyDict_Keys(IntPtr pointer); + IntPtr PyDict_New(); + int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value); + int PyDict_SetItemString(IntPtr pointer, string key, IntPtr value); + int PyDict_Size(IntPtr pointer); + int PyDict_Update(IntPtr pointer, IntPtr other); + IntPtr PyDict_Values(IntPtr pointer); + void PyErr_Clear(); + int PyErr_ExceptionMatches(IntPtr exception); + void PyErr_Fetch(ref IntPtr ob, ref IntPtr val, ref IntPtr tb); + int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val); + void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb); + int PyErr_Occurred(); + void PyErr_Print(); + void PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb); + IntPtr PyErr_SetFromErrno(IntPtr ob); + void PyErr_SetNone(IntPtr ob); + void PyErr_SetObject(IntPtr ob, IntPtr message); + void PyErr_SetString(IntPtr ob, string message); + void PyEval_AcquireThread(IntPtr tstate); + IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals); + IntPtr PyEval_GetBuiltins(); + IntPtr PyEval_GetGlobals(); + IntPtr PyEval_GetLocals(); + void PyEval_InitThreads(); + void PyEval_ReleaseLock(); + void PyEval_ReleaseThread(IntPtr tstate); + void PyEval_RestoreThread(IntPtr tstate); + IntPtr PyEval_SaveThread(); + int PyEval_ThreadsInitialized(); + double PyFloat_AsDouble(IntPtr ob); + IntPtr PyFloat_FromDouble(double value); + IntPtr PyFloat_FromString(IntPtr value, IntPtr junk); + IntPtr PyGILState_Ensure(); + IntPtr PyGILState_GetThisThreadState(); + void PyGILState_Release(IntPtr gs); + IntPtr PyImport_AddModule(string name); + IntPtr PyImport_ExecCodeModule(string name, IntPtr code); + IntPtr PyImport_GetModuleDict(); + IntPtr PyImport_Import(IntPtr name); + IntPtr PyImport_ImportModule(string name); + IntPtr PyImport_ReloadModule(IntPtr module); + IntPtr PyInstance_New(IntPtr cls, IntPtr args, IntPtr kw); + IntPtr PyInstance_NewRaw(IntPtr cls, IntPtr dict); + int PyInt_AsLong(IntPtr value); + IntPtr PyInt_FromString(string value, IntPtr end, int radix); + int PyInt_GetMax(); + IntPtr PyIter_Next(IntPtr pointer); + int PyList_Append(IntPtr pointer, IntPtr value); + IntPtr PyList_AsTuple(IntPtr pointer); + IntPtr PyList_GetItem(IntPtr pointer, int index); + IntPtr PyList_GetSlice(IntPtr pointer, int start, int end); + int PyList_Insert(IntPtr pointer, int index, IntPtr value); + IntPtr PyList_New(int size); + int PyList_Reverse(IntPtr pointer); + int PyList_SetItem(IntPtr pointer, int index, IntPtr value); + int PyList_SetSlice(IntPtr pointer, int start, int end, IntPtr value); + int PyList_Size(IntPtr pointer); + int PyList_Sort(IntPtr pointer); + int PyLong_AsLong(IntPtr value); + long PyLong_AsLongLong(IntPtr value); +#pragma warning disable CS3002 // Return type is not CLS-compliant + uint PyLong_AsUnsignedLong(IntPtr value); + ulong PyLong_AsUnsignedLongLong(IntPtr value); +#pragma warning restore CS3002 // Return type is not CLS-compliant + IntPtr PyLong_FromDouble(double value); + IntPtr PyLong_FromLong(long value); + IntPtr PyLong_FromLongLong(long value); + IntPtr PyLong_FromString(string value, IntPtr end, int radix); +#pragma warning disable CS3001 // Argument type is not CLS-compliant + IntPtr PyLong_FromUnsignedLong(uint value); + IntPtr PyLong_FromUnsignedLongLong(ulong value); +#pragma warning restore CS3001 // Argument type is not CLS-compliant + int PyMapping_HasKey(IntPtr pointer, IntPtr key); + void PyMem_Free(IntPtr ptr); + IntPtr PyMem_Malloc(int size); + IntPtr PyMem_Realloc(IntPtr ptr, int size); + IntPtr PyMethod_Function(IntPtr ob); + IntPtr PyMethod_New(IntPtr func, IntPtr self, IntPtr cls); + IntPtr PyMethod_Self(IntPtr ob); + IntPtr PyModule_Create2(IntPtr module, int apiver); + IntPtr PyModule_GetDict(IntPtr module); + string PyModule_GetFilename(IntPtr module); + string PyModule_GetName(IntPtr module); + IntPtr PyModule_New(string name); + IntPtr PyNumber_Add(IntPtr o1, IntPtr o2); + IntPtr PyNumber_And(IntPtr o1, IntPtr o2); + bool PyNumber_Check(IntPtr ob); + IntPtr PyNumber_Divide(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Float(IntPtr ob); + IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceDivide(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Int(IntPtr ob); + IntPtr PyNumber_Invert(IntPtr o1); + IntPtr PyNumber_Long(IntPtr ob); + IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Negative(IntPtr o1); + IntPtr PyNumber_Or(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Positive(IntPtr o1); + IntPtr PyNumber_Power(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2); + IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw); + IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args); + int PyObject_DelItem(IntPtr pointer, IntPtr key); + IntPtr PyObject_Dir(IntPtr pointer); + void PyObject_GC_Del(IntPtr tp); + IntPtr PyObject_GC_New(IntPtr tp); + void PyObject_GC_Track(IntPtr tp); + void PyObject_GC_UnTrack(IntPtr tp); + IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name); + int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value); + IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name); + IntPtr PyObject_GetAttrString(IntPtr pointer, string name); + IntPtr PyObject_GetItem(IntPtr pointer, IntPtr key); + IntPtr PyObject_GetIter(IntPtr op); + int PyObject_HasAttr(IntPtr pointer, IntPtr name); + int PyObject_HasAttrString(IntPtr pointer, string name); + IntPtr PyObject_Hash(IntPtr op); + int PyObject_IsInstance(IntPtr ob, IntPtr type); + int PyObject_IsSubclass(IntPtr ob, IntPtr type); + int PyObject_IsTrue(IntPtr pointer); + int PyObject_Not(IntPtr pointer); + IntPtr PyObject_Repr(IntPtr pointer); + int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid); + int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value); + int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value); + int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value); + int PyObject_Size(IntPtr pointer); + IntPtr PyObject_Str(IntPtr pointer); + IntPtr PyObject_Unicode(IntPtr pointer); + int PyRun_SimpleString(string code); + IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals); + bool PySequence_Check(IntPtr pointer); + IntPtr PySequence_Concat(IntPtr pointer, IntPtr other); + int PySequence_Contains(IntPtr pointer, IntPtr item); + int PySequence_Count(IntPtr pointer, IntPtr value); + int PySequence_DelItem(IntPtr pointer, int index); + int PySequence_DelSlice(IntPtr pointer, int i1, int i2); + IntPtr PySequence_GetItem(IntPtr pointer, int index); + IntPtr PySequence_GetSlice(IntPtr pointer, int i1, int i2); + int PySequence_Index(IntPtr pointer, IntPtr item); + IntPtr PySequence_List(IntPtr pointer); + IntPtr PySequence_Repeat(IntPtr pointer, int count); + int PySequence_SetItem(IntPtr pointer, int index, IntPtr value); + int PySequence_SetSlice(IntPtr pointer, int i1, int i2, IntPtr v); + int PySequence_Size(IntPtr pointer); + IntPtr PySequence_Tuple(IntPtr pointer); + IntPtr PyString_FromStringAndSize(string value, int size); + IntPtr PySys_GetObject(string name); + void PySys_SetArgvEx(int argc, string[] argv, int updatepath); + int PySys_SetObject(string name, IntPtr ob); + IntPtr PyThreadState_Get(); + IntPtr PyThreadState_New(IntPtr istate); + IntPtr PyThreadState_Swap(IntPtr key); + IntPtr PyThread_get_key_value(IntPtr key); + int PyThread_get_thread_ident(); + int PyThread_set_key_value(IntPtr key, IntPtr value); + IntPtr PyTuple_GetItem(IntPtr pointer, int index); + IntPtr PyTuple_GetSlice(IntPtr pointer, int start, int end); + IntPtr PyTuple_New(int size); + int PyTuple_SetItem(IntPtr pointer, int index, IntPtr value); + int PyTuple_Size(IntPtr pointer); + IntPtr PyType_GenericAlloc(IntPtr type, int n); + IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw); + bool PyType_IsSubtype(IntPtr t1, IntPtr t2); + void PyType_Modified(IntPtr type); + int PyType_Ready(IntPtr type); + IntPtr PyUnicode_AsUnicode(IntPtr ob); + IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err); + IntPtr PyUnicode_FromKindAndData(int kind, string s, int size); + IntPtr PyUnicode_FromObject(IntPtr ob); + IntPtr PyUnicode_FromOrdinal(int c); + IntPtr PyUnicode_FromStringAndSize(IntPtr value, int size); + int PyUnicode_GetSize(IntPtr ob); + IntPtr Py_CompileString(string code, string file, IntPtr tok); + void Py_DecRef(IntPtr ob); + void Py_EndInterpreter(IntPtr threadState); + void Py_Finalize(); + IntPtr Py_GetBuildInfo(); + IntPtr Py_GetCompiler(); + IntPtr Py_GetCopyright(); + IntPtr Py_GetPath(); + IntPtr Py_GetPlatform(); + IntPtr Py_GetProgramName(); + IntPtr Py_GetPythonHome(); + IntPtr Py_GetVersion(); + void Py_IncRef(IntPtr ob); + void Py_Initialize(); + int Py_IsInitialized(); + int Py_Main(int argc, string[] argv); + IntPtr Py_NewInterpreter(); + void Py_SetPath(IntPtr home); + void Py_SetProgramName(IntPtr name); + void Py_SetPythonHome(IntPtr home); +#pragma warning disable CS3008 // Identifier is not CLS-compliant + IntPtr _PyObject_GetDictPtr(IntPtr obj); + IntPtr _PyType_Lookup(IntPtr type, IntPtr name); +#pragma warning restore CS3008 // Identifier is not CLS-compliant + IntPtr PyInt_FromLong(IntPtr value); + } +} diff --git a/src/runtime/InteropPosix.cs b/src/runtime/InteropPosix.cs new file mode 100644 index 000000000..56206456e --- /dev/null +++ b/src/runtime/InteropPosix.cs @@ -0,0 +1,798 @@ +using Python.Runtime; +using System; + +namespace Python.Runtime +{ + internal class InteropPosix : IInterop + { + public string GetDllName() + { + return Runtime_Posix._PythonDll; + } + + public void Py_IncRef(IntPtr ob) { Runtime_Posix.Py_IncRef(ob); } + + + public void Py_DecRef(IntPtr ob){ Runtime_Posix.Py_DecRef(ob); } + + + public void Py_Initialize(){ Runtime_Posix.Py_Initialize(); } + + + public int Py_IsInitialized(){ return Runtime_Posix.Py_IsInitialized(); } + + + public void Py_Finalize(){ Runtime_Posix.Py_Finalize(); } + + + public IntPtr Py_NewInterpreter(){ return Runtime_Posix.Py_NewInterpreter(); } + + + public void Py_EndInterpreter(IntPtr threadState){ Runtime_Posix.Py_EndInterpreter(threadState); } + + + public IntPtr PyThreadState_New(IntPtr istate){ return Runtime_Posix.PyThreadState_New(istate); } + + + public IntPtr PyThreadState_Get(){ return Runtime_Posix.PyThreadState_Get(); } + + + public IntPtr PyThread_get_key_value(IntPtr key){ return Runtime_Posix.PyThread_get_key_value(key); } + + + public int PyThread_get_thread_ident(){ return Runtime_Posix.PyThread_get_thread_ident(); } + + + public int PyThread_set_key_value(IntPtr key, IntPtr value){ return Runtime_Posix.PyThread_set_key_value(key, value); } + + + public IntPtr PyThreadState_Swap(IntPtr key){ return Runtime_Posix.PyThreadState_Swap(key); } + + + public IntPtr PyGILState_Ensure(){ return Runtime_Posix.PyGILState_Ensure(); } + + + public void PyGILState_Release(IntPtr gs){ Runtime_Posix.PyGILState_Release(gs); } + + public IntPtr PyGILState_GetThisThreadState(){ return Runtime_Posix.PyGILState_GetThisThreadState(); } + +#if PYTHON3 + public int Py_Main( + int argc, + string[] argv + ){ return Runtime_Posix.Py_Main(argc, argv); } +#elif PYTHON2 + public int Py_Main(int argc, string[] argv){ return Runtime_Posix.Py_Main(argc, argv); } +#endif + + + public void PyEval_InitThreads(){ Runtime_Posix.PyEval_InitThreads(); } + + + public int PyEval_ThreadsInitialized(){ return Runtime_Posix.PyEval_ThreadsInitialized(); } + + + + + public void PyEval_ReleaseLock(){ Runtime_Posix.PyEval_ReleaseLock(); } + + + public void PyEval_AcquireThread(IntPtr tstate){ Runtime_Posix.PyEval_AcquireThread(tstate); } + + + public void PyEval_ReleaseThread(IntPtr tstate){ Runtime_Posix.PyEval_ReleaseThread(tstate); } + + + public IntPtr PyEval_SaveThread(){ return Runtime_Posix.PyEval_SaveThread(); } + + + public void PyEval_RestoreThread(IntPtr tstate){ Runtime_Posix.PyEval_RestoreThread(tstate); } + + + public IntPtr PyEval_GetBuiltins(){ return Runtime_Posix.PyEval_GetBuiltins(); } + + + public IntPtr PyEval_GetGlobals(){ return Runtime_Posix.PyEval_GetGlobals(); } + + + public IntPtr PyEval_GetLocals(){ return Runtime_Posix.PyEval_GetLocals(); } + + + public IntPtr Py_GetProgramName(){ return Runtime_Posix.Py_GetProgramName(); } + + + public void Py_SetProgramName(IntPtr name){ Runtime_Posix.Py_SetProgramName(name); } + + + public IntPtr Py_GetPythonHome(){ return Runtime_Posix.Py_GetPythonHome(); } + + + public void Py_SetPythonHome(IntPtr home){ Runtime_Posix.Py_SetPythonHome(home); } + + + public IntPtr Py_GetPath(){ return Runtime_Posix.Py_GetPath(); } + + + public void Py_SetPath(IntPtr home){ Runtime_Posix.Py_SetPath(home); } + + + public IntPtr Py_GetVersion(){ return Runtime_Posix.Py_GetVersion(); } + + + public IntPtr Py_GetPlatform(){ return Runtime_Posix.Py_GetPlatform(); } + + + public IntPtr Py_GetCopyright(){ return Runtime_Posix.Py_GetCopyright(); } + + + public IntPtr Py_GetCompiler(){ return Runtime_Posix.Py_GetCompiler(); } + + + public IntPtr Py_GetBuildInfo(){ return Runtime_Posix.Py_GetBuildInfo(); } + + + public int PyRun_SimpleString(string code){ return Runtime_Posix.PyRun_SimpleString(code); } + + + public IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals){ return Runtime_Posix.PyRun_String(code, st, globals, locals); } + + + public IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals){ return Runtime_Posix.PyEval_EvalCode(co, globals, locals); } + + + public IntPtr Py_CompileString(string code, string file, IntPtr tok){ return Runtime_Posix.Py_CompileString(code, file, tok); } + + + public IntPtr PyImport_ExecCodeModule(string name, IntPtr code){ return Runtime_Posix.PyImport_ExecCodeModule(name, code); } + + + public IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod){ return Runtime_Posix.PyCFunction_NewEx(ml, self, mod); } + + + public IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw){ return Runtime_Posix.PyCFunction_Call(func, args, kw); } + + + public IntPtr PyClass_New(IntPtr bases, IntPtr dict, IntPtr name){ return Runtime_Posix.PyClass_New(bases, dict, name); } + + + public IntPtr PyInstance_New(IntPtr cls, IntPtr args, IntPtr kw){ return Runtime_Posix.PyInstance_New(cls, args, kw); } + + + public IntPtr PyInstance_NewRaw(IntPtr cls, IntPtr dict){ return Runtime_Posix.PyInstance_NewRaw(cls, dict); } + + + public IntPtr PyMethod_New(IntPtr func, IntPtr self, IntPtr cls){ return Runtime_Posix.PyMethod_New(func, self, cls); } + + + public int PyObject_HasAttrString(IntPtr pointer, string name){ return Runtime_Posix.PyObject_HasAttrString(pointer, name); } + + + public IntPtr PyObject_GetAttrString(IntPtr pointer, string name){ return Runtime_Posix.PyObject_GetAttrString(pointer, name); } + + + public int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value){ return Runtime_Posix.PyObject_SetAttrString(pointer, name, value); } + + + public int PyObject_HasAttr(IntPtr pointer, IntPtr name){ return Runtime_Posix.PyObject_HasAttr(pointer, name); } + + + public IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name){ return Runtime_Posix.PyObject_GetAttr(pointer, name); } + + + public int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value){ return Runtime_Posix.PyObject_SetAttr(pointer, name, value); } + + + public IntPtr PyObject_GetItem(IntPtr pointer, IntPtr key){ return Runtime_Posix.PyObject_GetItem(pointer, key); } + + + public int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value){ return Runtime_Posix.PyObject_SetItem(pointer, key, value); } + + + public int PyObject_DelItem(IntPtr pointer, IntPtr key){ return Runtime_Posix.PyObject_DelItem(pointer, key); } + + + public IntPtr PyObject_GetIter(IntPtr op){ return Runtime_Posix.PyObject_GetIter(op); } + + + public IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw){ return Runtime_Posix.PyObject_Call(pointer, args, kw); } + + + public IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args){ return Runtime_Posix.PyObject_CallObject(pointer, args); } + +#if PYTHON3 + + public int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid){ return Runtime_Posix.PyObject_RichCompareBool(value1, value2, opid); } + +#elif PYTHON2 + + public int PyObject_Compare(IntPtr value1, IntPtr value2){ return Runtime_Posix.PyObject_Compare(value1, value2); } +#endif + + + public int PyObject_IsInstance(IntPtr ob, IntPtr type){ return Runtime_Posix.PyObject_IsInstance(ob, type); } + + + public int PyObject_IsSubclass(IntPtr ob, IntPtr type){ return Runtime_Posix.PyObject_IsSubclass(ob, type); } + + + public int PyCallable_Check(IntPtr pointer){ return Runtime_Posix.PyCallable_Check(pointer); } + + + public int PyObject_IsTrue(IntPtr pointer){ return Runtime_Posix.PyObject_IsTrue(pointer); } + + + public int PyObject_Not(IntPtr pointer){ return Runtime_Posix.PyObject_Not(pointer); } + + + public int PyObject_Size(IntPtr pointer){ return Runtime_Posix.PyObject_Size(pointer); } + + + public IntPtr PyObject_Hash(IntPtr op){ return Runtime_Posix.PyObject_Hash(op); } + + + public IntPtr PyObject_Repr(IntPtr pointer){ return Runtime_Posix.PyObject_Repr(pointer); } + + + public IntPtr PyObject_Str(IntPtr pointer){ return Runtime_Posix.PyObject_Str(pointer); } + +#if PYTHON3 + public IntPtr PyObject_Unicode(IntPtr pointer){ return Runtime_Posix.PyObject_Unicode(pointer); } +#elif PYTHON2 + + public IntPtr PyObject_Unicode(IntPtr pointer){ return Runtime_Posix.PyObject_Unicode(opointerb); } +#endif + + + public IntPtr PyObject_Dir(IntPtr pointer){ return Runtime_Posix.PyObject_Dir(pointer); } + + + //==================================================================== + // Python number API + //==================================================================== + +#if PYTHON3 + public IntPtr PyNumber_Int(IntPtr ob){ return Runtime_Posix.PyNumber_Int(ob); } +#elif PYTHON2 + + public IntPtr PyNumber_Int(IntPtr ob){ return Runtime_Posix.PyNumber_Int(ob); } +#endif + + + public IntPtr PyNumber_Long(IntPtr ob){ return Runtime_Posix.PyNumber_Long(ob); } + + + public IntPtr PyNumber_Float(IntPtr ob){ return Runtime_Posix.PyNumber_Float(ob); } + + + public bool PyNumber_Check(IntPtr ob){ return Runtime_Posix.PyNumber_Check(ob); } + + +#if PYTHON3 + public IntPtr PyInt_FromLong(IntPtr value){ return Runtime_Posix.PyInt_FromLong(value); } + + public int PyInt_AsLong(IntPtr value){ return Runtime_Posix.PyInt_AsLong(value); } + + public IntPtr PyInt_FromString(string value, IntPtr end, int radix){ return Runtime_Posix.PyInt_FromString(value, end, radix); } + + public int PyInt_GetMax(){ return Runtime_Posix.PyInt_GetMax(); } +#elif PYTHON2 + + public IntPtr PyInt_FromLong(IntPtr value){ return Runtime_Posix.PyInt_FromLong(value); } + + + public int PyInt_AsLong(IntPtr value){ return Runtime_Posix.PyInt_AsLong(value); } + + + public IntPtr PyInt_FromString(string value, IntPtr end, int radix){ return Runtime_Posix.PyInt_FromString(value, end, radix); } + + + public int PyInt_GetMax(){ return Runtime_Posix.PyInt_GetMax(); } +#endif + + + public IntPtr PyLong_FromLong(long value){ return Runtime_Posix.PyLong_FromLong(value); } + + + public IntPtr PyLong_FromUnsignedLong(uint value){ return Runtime_Posix.PyLong_FromUnsignedLong(value); } + + + public IntPtr PyLong_FromDouble(double value){ return Runtime_Posix.PyLong_FromDouble(value); } + + + public IntPtr PyLong_FromLongLong(long value){ return Runtime_Posix.PyLong_FromLongLong(value); } + + + public IntPtr PyLong_FromUnsignedLongLong(ulong value){ return Runtime_Posix.PyLong_FromUnsignedLongLong(value); } + + + public IntPtr PyLong_FromString(string value, IntPtr end, int radix){ return Runtime_Posix.PyLong_FromString(value, end, radix); } + + + public int PyLong_AsLong(IntPtr value){ return Runtime_Posix.PyLong_AsLong(value); } + + + public uint PyLong_AsUnsignedLong(IntPtr value){ return Runtime_Posix.PyLong_AsUnsignedLong(value); } + + + public long PyLong_AsLongLong(IntPtr value){ return Runtime_Posix.PyLong_AsLongLong(value); } + + + public ulong PyLong_AsUnsignedLongLong(IntPtr value){ return Runtime_Posix.PyLong_AsUnsignedLongLong(value); } + + + public IntPtr PyFloat_FromDouble(double value){ return Runtime_Posix.PyFloat_FromDouble(value); } + + + public IntPtr PyFloat_FromString(IntPtr value, IntPtr junk){ return Runtime_Posix.PyFloat_FromString(value, junk); } + + + public double PyFloat_AsDouble(IntPtr ob){ return Runtime_Posix.PyFloat_AsDouble(ob); } + + + public IntPtr PyNumber_Add(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Add(o1, o2); } + + + public IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Subtract(o1, o2); } + + + public IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Multiply(o1, o2); } + + + public IntPtr PyNumber_Divide(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Divide(o1, o2); } + + + public IntPtr PyNumber_And(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_And(o1, o2); } + + + public IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Xor(o1, o2); } + + + public IntPtr PyNumber_Or(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Or(o1, o2); } + + + public IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Lshift(o1, o2); } + + + public IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Rshift(o1, o2); } + + + public IntPtr PyNumber_Power(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Power(o1, o2); } + + + public IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_Remainder(o1, o2); } + + + public IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceAdd(o1, o2); } + + + public IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceSubtract(o1, o2); } + + + public IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceMultiply(o1, o2); } + + + public IntPtr PyNumber_InPlaceDivide(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceDivide(o1, o2); } + + + public IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceAnd(o1, o2); } + + + public IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceXor(o1, o2); } + + + public IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceOr(o1, o2); } + + + public IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceLshift(o1, o2); } + + + public IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceRshift(o1, o2); } + + + public IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlacePower(o1, o2); } + + + public IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2){ return Runtime_Posix.PyNumber_InPlaceRemainder(o1, o2); } + + + public IntPtr PyNumber_Negative(IntPtr o1){ return Runtime_Posix.PyNumber_Negative(o1); } + + + public IntPtr PyNumber_Positive(IntPtr o1){ return Runtime_Posix.PyNumber_Positive(o1); } + + + public IntPtr PyNumber_Invert(IntPtr o1){ return Runtime_Posix.PyNumber_Invert(o1); } + + + public bool PySequence_Check(IntPtr pointer){ return Runtime_Posix.PySequence_Check(pointer); } + + + public IntPtr PySequence_GetItem(IntPtr pointer, int index){ return Runtime_Posix.PySequence_GetItem(pointer, index); } + + + public int PySequence_SetItem(IntPtr pointer, int index, IntPtr value){ return Runtime_Posix.PySequence_SetItem(pointer, index, value); } + + + public int PySequence_DelItem(IntPtr pointer, int index){ return Runtime_Posix.PySequence_DelItem(pointer, index); } + + + public IntPtr PySequence_GetSlice(IntPtr pointer, int i1, int i2){ return Runtime_Posix.PySequence_GetSlice(pointer, i1, i2); } + + + public int PySequence_SetSlice(IntPtr pointer, int i1, int i2, IntPtr v){ return Runtime_Posix.PySequence_SetSlice(pointer, i1, i2, v); } + + + public int PySequence_DelSlice(IntPtr pointer, int i1, int i2){ return Runtime_Posix.PySequence_DelSlice(pointer, i1, i2); } + + + public int PySequence_Size(IntPtr pointer){ return Runtime_Posix.PySequence_Size(pointer); } + + + public int PySequence_Contains(IntPtr pointer, IntPtr item){ return Runtime_Posix.PySequence_Contains(pointer, item); } + + + public IntPtr PySequence_Concat(IntPtr pointer, IntPtr other){ return Runtime_Posix.PySequence_Concat(pointer, other); } + + + public IntPtr PySequence_Repeat(IntPtr pointer, int count){ return Runtime_Posix.PySequence_Repeat(pointer, count); } + + + public int PySequence_Index(IntPtr pointer, IntPtr item){ return Runtime_Posix.PySequence_Index(pointer, item); } + + + public int PySequence_Count(IntPtr pointer, IntPtr value){ return Runtime_Posix.PySequence_Count(pointer, value); } + + + public IntPtr PySequence_Tuple(IntPtr pointer){ return Runtime_Posix.PySequence_Tuple(pointer); } + + + public IntPtr PySequence_List(IntPtr pointer){ return Runtime_Posix.PySequence_List(pointer); } + +#if PYTHON3 + + public IntPtr PyBytes_FromString(string op){ return Runtime_Posix.PyBytes_FromString(op); } + + + public int PyBytes_Size(IntPtr op){ return Runtime_Posix.PyBytes_Size(op); } + + + public IntPtr PyString_FromStringAndSize( + string value, + int size + ){ return Runtime_Posix.PyString_FromStringAndSize(value, size); } + + + public IntPtr PyUnicode_FromStringAndSize(IntPtr value, int size){ return Runtime_Posix.PyUnicode_FromStringAndSize(value, size); } +#elif PYTHON2 + + public IntPtr PyString_FromStringAndSize(string value, int size){ return Runtime_Posix.PyUnicode_FromStringAndSize(value, size); } + + + public IntPtr PyString_AsString(IntPtr op){ return Runtime_Posix.PyString_AsString(op); } + + + public int PyString_Size(IntPtr pointer){ return Runtime_Posix.PyString_Size(pointer); } +#endif + + +#if PYTHON3 + + public IntPtr PyUnicode_FromObject(IntPtr ob){ return Runtime_Posix.PyUnicode_FromObject(ob); } + + + public IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err){ return Runtime_Posix.PyUnicode_FromEncodedObject(ob, enc, err); } + + + public IntPtr PyUnicode_FromKindAndData( + int kind, + string s, + int size + ){ return Runtime_Posix.PyUnicode_FromKindAndData(kind, s, size); } + + + public int PyUnicode_GetSize(IntPtr ob){ return Runtime_Posix.PyUnicode_GetSize(ob); } + + + public IntPtr PyUnicode_AsUnicode(IntPtr ob){ return Runtime_Posix.PyUnicode_AsUnicode(ob); } + + + public IntPtr PyUnicode_FromOrdinal(int c){ return Runtime_Posix.PyUnicode_FromOrdinal(c); } +#elif PYTHON2 + public IntPtr PyUnicode_FromObject(IntPtr ob){ return Runtime_Posix.PyUnicode_FromObject(ob); } + + public IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err){ return Runtime_Posix.PyUnicode_FromEncodedObject(ob, enc, err); } + + public IntPtr PyUnicode_FromUnicode( + string s, + int size + ){ return Runtime_Posix.PyUnicode_FromUnicode(s, size); } + + public int PyUnicode_GetSize(IntPtr ob){ return Runtime_Posix.PyUnicode_GetSize(ob); } + + public IntPtr PyUnicode_AsUnicode(IntPtr ob){ return Runtime_Posix.PyUnicode_AsUnicode(ob); } + + public IntPtr PyUnicode_FromOrdinal(int c){ return Runtime_Posix.PyUnicode_FromOrdinal(c); } +#endif + + + + + public IntPtr PyDict_New(){ return Runtime_Posix.PyDict_New(); } + + + public IntPtr PyDictProxy_New(IntPtr dict){ return Runtime_Posix.PyDictProxy_New(dict); } + + + public IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key){ return Runtime_Posix.PyDict_GetItem(pointer, key); } + + + public IntPtr PyDict_GetItemString(IntPtr pointer, string key){ return Runtime_Posix.PyDict_GetItemString(pointer, key); } + + + public int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value){ return Runtime_Posix.PyDict_SetItem(pointer, key, value); } + + + public int PyDict_SetItemString(IntPtr pointer, string key, IntPtr value){ return Runtime_Posix.PyDict_SetItemString(pointer, key, value); } + + + public int PyDict_DelItem(IntPtr pointer, IntPtr key){ return Runtime_Posix.PyDict_DelItem(pointer, key); } + + + public int PyDict_DelItemString(IntPtr pointer, string key){ return Runtime_Posix.PyDict_DelItemString(pointer, key); } + + + public int PyMapping_HasKey(IntPtr pointer, IntPtr key){ return Runtime_Posix.PyMapping_HasKey(pointer, key); } + + + public IntPtr PyDict_Keys(IntPtr pointer){ return Runtime_Posix.PyDict_Keys(pointer); } + + + public IntPtr PyDict_Values(IntPtr pointer){ return Runtime_Posix.PyDict_Values(pointer); } + + + public IntPtr PyDict_Items(IntPtr pointer){ return Runtime_Posix.PyDict_Items(pointer); } + + + public IntPtr PyDict_Copy(IntPtr pointer){ return Runtime_Posix.PyDict_Copy(pointer); } + + + public int PyDict_Update(IntPtr pointer, IntPtr other){ return Runtime_Posix.PyDict_Update(pointer, other); } + + + public void PyDict_Clear(IntPtr pointer){ Runtime_Posix.PyDict_Clear(pointer); } + + + public int PyDict_Size(IntPtr pointer){ return Runtime_Posix.PyDict_Size(pointer); } + + + + + + public IntPtr PyList_New(int size){ return Runtime_Posix.PyList_New(size); } + + + public IntPtr PyList_AsTuple(IntPtr pointer){ return Runtime_Posix.PyList_AsTuple(pointer); } + + + public IntPtr PyList_GetItem(IntPtr pointer, int index){ return Runtime_Posix.PyList_GetItem(pointer, index); } + + + public int PyList_SetItem(IntPtr pointer, int index, IntPtr value){ return Runtime_Posix.PyList_SetItem(pointer, index, value); } + + + public int PyList_Insert(IntPtr pointer, int index, IntPtr value){ return Runtime_Posix.PyList_Insert(pointer, index, value); } + + + public int PyList_Append(IntPtr pointer, IntPtr value){ return Runtime_Posix.PyList_Append(pointer, value); } + + + public int PyList_Reverse(IntPtr pointer){ return Runtime_Posix.PyList_Reverse(pointer); } + + + public int PyList_Sort(IntPtr pointer){ return Runtime_Posix.PyList_Sort(pointer); } + + + public IntPtr PyList_GetSlice(IntPtr pointer, int start, int end){ return Runtime_Posix.PyList_GetSlice(pointer, start, end); } + + + public int PyList_SetSlice(IntPtr pointer, int start, int end, IntPtr value){ return Runtime_Posix.PyList_SetSlice(pointer, start, end, value); } + + + public int PyList_Size(IntPtr pointer){ return Runtime_Posix.PyList_Size(pointer); } + + + + public IntPtr PyTuple_New(int size){ return Runtime_Posix.PyTuple_New(size); } + + + public IntPtr PyTuple_GetItem(IntPtr pointer, int index){ return Runtime_Posix.PyTuple_GetItem(pointer, index); } + + + public int PyTuple_SetItem(IntPtr pointer, int index, IntPtr value){ return Runtime_Posix.PyTuple_SetItem(pointer, index, value); } + + + public IntPtr PyTuple_GetSlice(IntPtr pointer, int start, int end){ return Runtime_Posix.PyTuple_GetSlice(pointer, start, end); } + + + public int PyTuple_Size(IntPtr pointer){ return Runtime_Posix.PyTuple_Size(pointer); } + + + + + + public IntPtr PyIter_Next(IntPtr pointer){ return Runtime_Posix.PyIter_Next(pointer); } + + + //==================================================================== + // Python module API + //==================================================================== + + + public IntPtr PyModule_New(string name){ return Runtime_Posix.PyModule_New(name); } + + + public string PyModule_GetName(IntPtr module){ return Runtime_Posix.PyModule_GetName(module); } + + + public IntPtr PyModule_GetDict(IntPtr module){ return Runtime_Posix.PyModule_GetDict(module); } + + + public string PyModule_GetFilename(IntPtr module){ return Runtime_Posix.PyModule_GetFilename(module); } + +#if PYTHON3 + + public IntPtr PyModule_Create2(IntPtr module, int apiver){ return Runtime_Posix.PyModule_Create2(module, apiver); } +#endif + + + public IntPtr PyImport_Import(IntPtr name){ return Runtime_Posix.PyImport_Import(name); } + + + public IntPtr PyImport_ImportModule(string name){ return Runtime_Posix.PyImport_ImportModule(name); } + + + public IntPtr PyImport_ReloadModule(IntPtr module){ return Runtime_Posix.PyImport_ReloadModule(module); } + + + public IntPtr PyImport_AddModule(string name){ return Runtime_Posix.PyImport_AddModule(name); } + + + public IntPtr PyImport_GetModuleDict(){ return Runtime_Posix.PyImport_GetModuleDict(); } + +#if PYTHON3 + + public void PySys_SetArgvEx( + int argc, + string[] argv, + int updatepath + ){ Runtime_Posix.PySys_SetArgvEx(argc, + argv, + updatepath); } +#elif PYTHON2 + + public void PySys_SetArgvEx( + int argc, + string[] argv, + int updatepath + ){ return Runtime_Posix.PySys_SetArgvEx(argc, + argv, + updatepath); } +#endif + + + public IntPtr PySys_GetObject(string name){ return Runtime_Posix.PySys_GetObject(name); } + + + public int PySys_SetObject(string name, IntPtr ob){ return Runtime_Posix.PySys_SetObject(name, ob); } + + + + public void PyType_Modified(IntPtr type){ Runtime_Posix.PyType_Modified(type); } + + + public bool PyType_IsSubtype(IntPtr t1, IntPtr t2){ return Runtime_Posix.PyType_IsSubtype(t1, t2); } + + + + + public IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw){ return Runtime_Posix.PyType_GenericNew(type, args, kw); } + + + public IntPtr PyType_GenericAlloc(IntPtr type, int n){ return Runtime_Posix.PyType_GenericAlloc(type, n); } + + + public int PyType_Ready(IntPtr type){ return Runtime_Posix.PyType_Ready(type); } + + + public IntPtr _PyType_Lookup(IntPtr type, IntPtr name){ return Runtime_Posix._PyType_Lookup(type, name); } + + + public IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name){ return Runtime_Posix.PyObject_GenericGetAttr(obj, name); } + + + public int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value){ return Runtime_Posix.PyObject_GenericSetAttr(obj, name, value); } + + + public IntPtr _PyObject_GetDictPtr(IntPtr obj){ return Runtime_Posix._PyObject_GetDictPtr(obj); } + + + public IntPtr PyObject_GC_New(IntPtr tp){ return Runtime_Posix.PyObject_GC_New(tp); } + + + public void PyObject_GC_Del(IntPtr tp){ Runtime_Posix.PyObject_GC_Del(tp); } + + + public void PyObject_GC_Track(IntPtr tp){ Runtime_Posix.PyObject_GC_Track(tp); } + + + public void PyObject_GC_UnTrack(IntPtr tp){ Runtime_Posix.PyObject_GC_UnTrack(tp); } + + + //==================================================================== + // Python memory API + //==================================================================== + + + public IntPtr PyMem_Malloc(int size){ return Runtime_Posix.PyMem_Malloc(size); } + + + public IntPtr PyMem_Realloc(IntPtr ptr, int size){ return Runtime_Posix.PyMem_Realloc(ptr, size); } + + + public void PyMem_Free(IntPtr ptr){ Runtime_Posix.PyMem_Free(ptr); } + + + //==================================================================== + // Python exception API + //==================================================================== + + + public void PyErr_SetString(IntPtr ob, string message){ Runtime_Posix.PyErr_SetString(ob, message); } + + + public void PyErr_SetObject(IntPtr ob, IntPtr message){ Runtime_Posix.PyErr_SetObject(ob, message); } + + + public IntPtr PyErr_SetFromErrno(IntPtr ob){ return Runtime_Posix.PyErr_SetFromErrno(ob); } + + + public void PyErr_SetNone(IntPtr ob){ Runtime_Posix.PyErr_SetNone(ob); } + + + public int PyErr_ExceptionMatches(IntPtr exception){ return Runtime_Posix.PyErr_ExceptionMatches(exception); } + + + public int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val){ return Runtime_Posix.PyErr_GivenExceptionMatches(ob, val); } + + + public void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb){ Runtime_Posix.PyErr_NormalizeException(ob, val, tb); } + + + public int PyErr_Occurred(){ return Runtime_Posix.PyErr_Occurred(); } + + + public void PyErr_Fetch(ref IntPtr ob, ref IntPtr val, ref IntPtr tb){ Runtime_Posix.PyErr_Fetch(ref ob, ref val, ref tb); } + + + public void PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb){ Runtime_Posix.PyErr_Restore(ob, val, tb); } + + + public void PyErr_Clear(){ Runtime_Posix.PyErr_Clear(); } + + + public void PyErr_Print(){ Runtime_Posix.PyErr_Print(); } + + + //==================================================================== + // Miscellaneous + //==================================================================== + + + public IntPtr PyMethod_Self(IntPtr ob){ return Runtime_Posix.PyMethod_Self(ob); } + + + public IntPtr PyMethod_Function(IntPtr ob){ return Runtime_Posix.PyMethod_Function(ob); } + + + } +} diff --git a/src/runtime/InteropWindows.cs b/src/runtime/InteropWindows.cs new file mode 100644 index 000000000..4c7e49dde --- /dev/null +++ b/src/runtime/InteropWindows.cs @@ -0,0 +1,796 @@ +using Python.Runtime; +using System; + +namespace Python.Runtime +{ + internal class InteropWindows : IInterop + { + public string GetDllName() { + return Runtime_Windows._PythonDll; + } + public void Py_IncRef(IntPtr ob) { Runtime_Windows.Py_IncRef(ob); } + + + public void Py_DecRef(IntPtr ob){ Runtime_Windows.Py_DecRef(ob); } + + + public void Py_Initialize(){ Runtime_Windows.Py_Initialize(); } + + + public int Py_IsInitialized(){ return Runtime_Windows.Py_IsInitialized(); } + + + public void Py_Finalize(){ Runtime_Windows.Py_Finalize(); } + + + public IntPtr Py_NewInterpreter(){ return Runtime_Windows.Py_NewInterpreter(); } + + + public void Py_EndInterpreter(IntPtr threadState){ Runtime_Windows.Py_EndInterpreter(threadState); } + + + public IntPtr PyThreadState_New(IntPtr istate){ return Runtime_Windows.PyThreadState_New(istate); } + + + public IntPtr PyThreadState_Get(){ return Runtime_Windows.PyThreadState_Get(); } + + + public IntPtr PyThread_get_key_value(IntPtr key){ return Runtime_Windows.PyThread_get_key_value(key); } + + + public int PyThread_get_thread_ident(){ return Runtime_Windows.PyThread_get_thread_ident(); } + + + public int PyThread_set_key_value(IntPtr key, IntPtr value){ return Runtime_Windows.PyThread_set_key_value(key, value); } + + + public IntPtr PyThreadState_Swap(IntPtr key){ return Runtime_Windows.PyThreadState_Swap(key); } + + + public IntPtr PyGILState_Ensure(){ return Runtime_Windows.PyGILState_Ensure(); } + + + public void PyGILState_Release(IntPtr gs){ Runtime_Windows.PyGILState_Release(gs); } + + public IntPtr PyGILState_GetThisThreadState(){ return Runtime_Windows.PyGILState_GetThisThreadState(); } + +#if PYTHON3 + public int Py_Main( + int argc, + string[] argv + ){ return Runtime_Windows.Py_Main(argc, argv); } +#elif PYTHON2 + public int Py_Main(int argc, string[] argv){ return Runtime_Windows.Py_Main(argc, argv); } +#endif + + + public void PyEval_InitThreads(){ Runtime_Windows.PyEval_InitThreads(); } + + + public int PyEval_ThreadsInitialized(){ return Runtime_Windows.PyEval_ThreadsInitialized(); } + + + + + public void PyEval_ReleaseLock(){ Runtime_Windows.PyEval_ReleaseLock(); } + + + public void PyEval_AcquireThread(IntPtr tstate){ Runtime_Windows.PyEval_AcquireThread(tstate); } + + + public void PyEval_ReleaseThread(IntPtr tstate){ Runtime_Windows.PyEval_ReleaseThread(tstate); } + + + public IntPtr PyEval_SaveThread(){ return Runtime_Windows.PyEval_SaveThread(); } + + + public void PyEval_RestoreThread(IntPtr tstate){ Runtime_Windows.PyEval_RestoreThread(tstate); } + + + public IntPtr PyEval_GetBuiltins(){ return Runtime_Windows.PyEval_GetBuiltins(); } + + + public IntPtr PyEval_GetGlobals(){ return Runtime_Windows.PyEval_GetGlobals(); } + + + public IntPtr PyEval_GetLocals(){ return Runtime_Windows.PyEval_GetLocals(); } + + + public IntPtr Py_GetProgramName(){ return Runtime_Windows.Py_GetProgramName(); } + + + public void Py_SetProgramName(IntPtr name){ Runtime_Windows.Py_SetProgramName(name); } + + + public IntPtr Py_GetPythonHome(){ return Runtime_Windows.Py_GetPythonHome(); } + + + public void Py_SetPythonHome(IntPtr home){ Runtime_Windows.Py_SetPythonHome(home); } + + + public IntPtr Py_GetPath(){ return Runtime_Windows.Py_GetPath(); } + + + public void Py_SetPath(IntPtr home){ Runtime_Windows.Py_SetPath(home); } + + + public IntPtr Py_GetVersion(){ return Runtime_Windows.Py_GetVersion(); } + + + public IntPtr Py_GetPlatform(){ return Runtime_Windows.Py_GetPlatform(); } + + + public IntPtr Py_GetCopyright(){ return Runtime_Windows.Py_GetCopyright(); } + + + public IntPtr Py_GetCompiler(){ return Runtime_Windows.Py_GetCompiler(); } + + + public IntPtr Py_GetBuildInfo(){ return Runtime_Windows.Py_GetBuildInfo(); } + + + public int PyRun_SimpleString(string code){ return Runtime_Windows.PyRun_SimpleString(code); } + + + public IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals){ return Runtime_Windows.PyRun_String(code, st, globals, locals); } + + + public IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals){ return Runtime_Windows.PyEval_EvalCode(co, globals, locals); } + + + public IntPtr Py_CompileString(string code, string file, IntPtr tok){ return Runtime_Windows.Py_CompileString(code, file, tok); } + + + public IntPtr PyImport_ExecCodeModule(string name, IntPtr code){ return Runtime_Windows.PyImport_ExecCodeModule(name, code); } + + + public IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod){ return Runtime_Windows.PyCFunction_NewEx(ml, self, mod); } + + + public IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw){ return Runtime_Windows.PyCFunction_Call(func, args, kw); } + + + public IntPtr PyClass_New(IntPtr bases, IntPtr dict, IntPtr name){ return Runtime_Windows.PyClass_New(bases, dict, name); } + + + public IntPtr PyInstance_New(IntPtr cls, IntPtr args, IntPtr kw){ return Runtime_Windows.PyInstance_New(cls, args, kw); } + + + public IntPtr PyInstance_NewRaw(IntPtr cls, IntPtr dict){ return Runtime_Windows.PyInstance_NewRaw(cls, dict); } + + + public IntPtr PyMethod_New(IntPtr func, IntPtr self, IntPtr cls){ return Runtime_Windows.PyMethod_New(func, self, cls); } + + + public int PyObject_HasAttrString(IntPtr pointer, string name){ return Runtime_Windows.PyObject_HasAttrString(pointer, name); } + + + public IntPtr PyObject_GetAttrString(IntPtr pointer, string name){ return Runtime_Windows.PyObject_GetAttrString(pointer, name); } + + + public int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value){ return Runtime_Windows.PyObject_SetAttrString(pointer, name, value); } + + + public int PyObject_HasAttr(IntPtr pointer, IntPtr name){ return Runtime_Windows.PyObject_HasAttr(pointer, name); } + + + public IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name){ return Runtime_Windows.PyObject_GetAttr(pointer, name); } + + + public int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value){ return Runtime_Windows.PyObject_SetAttr(pointer, name, value); } + + + public IntPtr PyObject_GetItem(IntPtr pointer, IntPtr key){ return Runtime_Windows.PyObject_GetItem(pointer, key); } + + + public int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value){ return Runtime_Windows.PyObject_SetItem(pointer, key, value); } + + + public int PyObject_DelItem(IntPtr pointer, IntPtr key){ return Runtime_Windows.PyObject_DelItem(pointer, key); } + + + public IntPtr PyObject_GetIter(IntPtr op){ return Runtime_Windows.PyObject_GetIter(op); } + + + public IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw){ return Runtime_Windows.PyObject_Call(pointer, args, kw); } + + + public IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args){ return Runtime_Windows.PyObject_CallObject(pointer, args); } + +#if PYTHON3 + + public int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid){ return Runtime_Windows.PyObject_RichCompareBool(value1, value2, opid); } + +#elif PYTHON2 + + public int PyObject_Compare(IntPtr value1, IntPtr value2){ return Runtime_Windows.PyObject_Compare(value1, value2); } +#endif + + + public int PyObject_IsInstance(IntPtr ob, IntPtr type){ return Runtime_Windows.PyObject_IsInstance(ob, type); } + + + public int PyObject_IsSubclass(IntPtr ob, IntPtr type){ return Runtime_Windows.PyObject_IsSubclass(ob, type); } + + + public int PyCallable_Check(IntPtr pointer){ return Runtime_Windows.PyCallable_Check(pointer); } + + + public int PyObject_IsTrue(IntPtr pointer){ return Runtime_Windows.PyObject_IsTrue(pointer); } + + + public int PyObject_Not(IntPtr pointer){ return Runtime_Windows.PyObject_Not(pointer); } + + + public int PyObject_Size(IntPtr pointer){ return Runtime_Windows.PyObject_Size(pointer); } + + + public IntPtr PyObject_Hash(IntPtr op){ return Runtime_Windows.PyObject_Hash(op); } + + + public IntPtr PyObject_Repr(IntPtr pointer){ return Runtime_Windows.PyObject_Repr(pointer); } + + + public IntPtr PyObject_Str(IntPtr pointer){ return Runtime_Windows.PyObject_Str(pointer); } + +#if PYTHON3 + public IntPtr PyObject_Unicode(IntPtr pointer){ return Runtime_Windows.PyObject_Unicode(pointer); } +#elif PYTHON2 + + public IntPtr PyObject_Unicode(IntPtr pointer){ return Runtime_Windows.PyObject_Unicode(opointerb); } +#endif + + + public IntPtr PyObject_Dir(IntPtr pointer){ return Runtime_Windows.PyObject_Dir(pointer); } + + + //==================================================================== + // Python number API + //==================================================================== + +#if PYTHON3 + public IntPtr PyNumber_Int(IntPtr ob){ return Runtime_Windows.PyNumber_Int(ob); } +#elif PYTHON2 + + public IntPtr PyNumber_Int(IntPtr ob){ return Runtime_Windows.PyNumber_Int(ob); } +#endif + + + public IntPtr PyNumber_Long(IntPtr ob){ return Runtime_Windows.PyNumber_Long(ob); } + + + public IntPtr PyNumber_Float(IntPtr ob){ return Runtime_Windows.PyNumber_Float(ob); } + + + public bool PyNumber_Check(IntPtr ob){ return Runtime_Windows.PyNumber_Check(ob); } + + +#if PYTHON3 + public IntPtr PyInt_FromLong(IntPtr value){ return Runtime_Windows.PyInt_FromLong(value); } + + public int PyInt_AsLong(IntPtr value){ return Runtime_Windows.PyInt_AsLong(value); } + + public IntPtr PyInt_FromString(string value, IntPtr end, int radix){ return Runtime_Windows.PyInt_FromString(value, end, radix); } + + public int PyInt_GetMax(){ return Runtime_Windows.PyInt_GetMax(); } +#elif PYTHON2 + + public IntPtr PyInt_FromLong(IntPtr value){ return Runtime_Windows.PyInt_FromLong(value); } + + + public int PyInt_AsLong(IntPtr value){ return Runtime_Windows.PyInt_AsLong(value); } + + + public IntPtr PyInt_FromString(string value, IntPtr end, int radix){ return Runtime_Windows.PyInt_FromString(value, end, radix); } + + + public int PyInt_GetMax(){ return Runtime_Windows.PyInt_GetMax(); } +#endif + + + public IntPtr PyLong_FromLong(long value){ return Runtime_Windows.PyLong_FromLong(value); } + + + public IntPtr PyLong_FromUnsignedLong(uint value){ return Runtime_Windows.PyLong_FromUnsignedLong(value); } + + + public IntPtr PyLong_FromDouble(double value){ return Runtime_Windows.PyLong_FromDouble(value); } + + + public IntPtr PyLong_FromLongLong(long value){ return Runtime_Windows.PyLong_FromLongLong(value); } + + + public IntPtr PyLong_FromUnsignedLongLong(ulong value){ return Runtime_Windows.PyLong_FromUnsignedLongLong(value); } + + + public IntPtr PyLong_FromString(string value, IntPtr end, int radix){ return Runtime_Windows.PyLong_FromString(value, end, radix); } + + + public int PyLong_AsLong(IntPtr value){ return Runtime_Windows.PyLong_AsLong(value); } + + + public uint PyLong_AsUnsignedLong(IntPtr value){ return Runtime_Windows.PyLong_AsUnsignedLong(value); } + + + public long PyLong_AsLongLong(IntPtr value){ return Runtime_Windows.PyLong_AsLongLong(value); } + + + public ulong PyLong_AsUnsignedLongLong(IntPtr value){ return Runtime_Windows.PyLong_AsUnsignedLongLong(value); } + + + public IntPtr PyFloat_FromDouble(double value){ return Runtime_Windows.PyFloat_FromDouble(value); } + + + public IntPtr PyFloat_FromString(IntPtr value, IntPtr junk){ return Runtime_Windows.PyFloat_FromString(value, junk); } + + + public double PyFloat_AsDouble(IntPtr ob){ return Runtime_Windows.PyFloat_AsDouble(ob); } + + + public IntPtr PyNumber_Add(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Add(o1, o2); } + + + public IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Subtract(o1, o2); } + + + public IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Multiply(o1, o2); } + + + public IntPtr PyNumber_Divide(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Divide(o1, o2); } + + + public IntPtr PyNumber_And(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_And(o1, o2); } + + + public IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Xor(o1, o2); } + + + public IntPtr PyNumber_Or(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Or(o1, o2); } + + + public IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Lshift(o1, o2); } + + + public IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Rshift(o1, o2); } + + + public IntPtr PyNumber_Power(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Power(o1, o2); } + + + public IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_Remainder(o1, o2); } + + + public IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceAdd(o1, o2); } + + + public IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceSubtract(o1, o2); } + + + public IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceMultiply(o1, o2); } + + + public IntPtr PyNumber_InPlaceDivide(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceDivide(o1, o2); } + + + public IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceAnd(o1, o2); } + + + public IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceXor(o1, o2); } + + + public IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceOr(o1, o2); } + + + public IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceLshift(o1, o2); } + + + public IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceRshift(o1, o2); } + + + public IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlacePower(o1, o2); } + + + public IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2){ return Runtime_Windows.PyNumber_InPlaceRemainder(o1, o2); } + + + public IntPtr PyNumber_Negative(IntPtr o1){ return Runtime_Windows.PyNumber_Negative(o1); } + + + public IntPtr PyNumber_Positive(IntPtr o1){ return Runtime_Windows.PyNumber_Positive(o1); } + + + public IntPtr PyNumber_Invert(IntPtr o1){ return Runtime_Windows.PyNumber_Invert(o1); } + + + public bool PySequence_Check(IntPtr pointer){ return Runtime_Windows.PySequence_Check(pointer); } + + + public IntPtr PySequence_GetItem(IntPtr pointer, int index){ return Runtime_Windows.PySequence_GetItem(pointer, index); } + + + public int PySequence_SetItem(IntPtr pointer, int index, IntPtr value){ return Runtime_Windows.PySequence_SetItem(pointer, index, value); } + + + public int PySequence_DelItem(IntPtr pointer, int index){ return Runtime_Windows.PySequence_DelItem(pointer, index); } + + + public IntPtr PySequence_GetSlice(IntPtr pointer, int i1, int i2){ return Runtime_Windows.PySequence_GetSlice(pointer, i1, i2); } + + + public int PySequence_SetSlice(IntPtr pointer, int i1, int i2, IntPtr v){ return Runtime_Windows.PySequence_SetSlice(pointer, i1, i2, v); } + + + public int PySequence_DelSlice(IntPtr pointer, int i1, int i2){ return Runtime_Windows.PySequence_DelSlice(pointer, i1, i2); } + + + public int PySequence_Size(IntPtr pointer){ return Runtime_Windows.PySequence_Size(pointer); } + + + public int PySequence_Contains(IntPtr pointer, IntPtr item){ return Runtime_Windows.PySequence_Contains(pointer, item); } + + + public IntPtr PySequence_Concat(IntPtr pointer, IntPtr other){ return Runtime_Windows.PySequence_Concat(pointer, other); } + + + public IntPtr PySequence_Repeat(IntPtr pointer, int count){ return Runtime_Windows.PySequence_Repeat(pointer, count); } + + + public int PySequence_Index(IntPtr pointer, IntPtr item){ return Runtime_Windows.PySequence_Index(pointer, item); } + + + public int PySequence_Count(IntPtr pointer, IntPtr value){ return Runtime_Windows.PySequence_Count(pointer, value); } + + + public IntPtr PySequence_Tuple(IntPtr pointer){ return Runtime_Windows.PySequence_Tuple(pointer); } + + + public IntPtr PySequence_List(IntPtr pointer){ return Runtime_Windows.PySequence_List(pointer); } + +#if PYTHON3 + + public IntPtr PyBytes_FromString(string op){ return Runtime_Windows.PyBytes_FromString(op); } + + + public int PyBytes_Size(IntPtr op){ return Runtime_Windows.PyBytes_Size(op); } + + + public IntPtr PyString_FromStringAndSize( + string value, + int size + ){ return Runtime_Windows.PyString_FromStringAndSize(value, size); } + + + public IntPtr PyUnicode_FromStringAndSize(IntPtr value, int size){ return Runtime_Windows.PyUnicode_FromStringAndSize(value, size); } +#elif PYTHON2 + + public IntPtr PyString_FromStringAndSize(string value, int size){ return Runtime_Windows.PyUnicode_FromStringAndSize(value, size); } + + + public IntPtr PyString_AsString(IntPtr op){ return Runtime_Windows.PyString_AsString(op); } + + + public int PyString_Size(IntPtr pointer){ return Runtime_Windows.PyString_Size(pointer); } +#endif + + +#if PYTHON3 + + public IntPtr PyUnicode_FromObject(IntPtr ob){ return Runtime_Windows.PyUnicode_FromObject(ob); } + + + public IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err){ return Runtime_Windows.PyUnicode_FromEncodedObject(ob, enc, err); } + + + public IntPtr PyUnicode_FromKindAndData( + int kind, + string s, + int size + ){ return Runtime_Windows.PyUnicode_FromKindAndData(kind, s, size); } + + + public int PyUnicode_GetSize(IntPtr ob){ return Runtime_Windows.PyUnicode_GetSize(ob); } + + + public IntPtr PyUnicode_AsUnicode(IntPtr ob){ return Runtime_Windows.PyUnicode_AsUnicode(ob); } + + + public IntPtr PyUnicode_FromOrdinal(int c){ return Runtime_Windows.PyUnicode_FromOrdinal(c); } +#elif PYTHON2 + public IntPtr PyUnicode_FromObject(IntPtr ob){ return Runtime_Windows.PyUnicode_FromObject(ob); } + + public IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err){ return Runtime_Windows.PyUnicode_FromEncodedObject(ob, enc, err); } + + public IntPtr PyUnicode_FromUnicode( + string s, + int size + ){ return Runtime_Windows.PyUnicode_FromUnicode(s, size); } + + public int PyUnicode_GetSize(IntPtr ob){ return Runtime_Windows.PyUnicode_GetSize(ob); } + + public IntPtr PyUnicode_AsUnicode(IntPtr ob){ return Runtime_Windows.PyUnicode_AsUnicode(ob); } + + public IntPtr PyUnicode_FromOrdinal(int c){ return Runtime_Windows.PyUnicode_FromOrdinal(c); } +#endif + + + + + public IntPtr PyDict_New(){ return Runtime_Windows.PyDict_New(); } + + + public IntPtr PyDictProxy_New(IntPtr dict){ return Runtime_Windows.PyDictProxy_New(dict); } + + + public IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key){ return Runtime_Windows.PyDict_GetItem(pointer, key); } + + + public IntPtr PyDict_GetItemString(IntPtr pointer, string key){ return Runtime_Windows.PyDict_GetItemString(pointer, key); } + + + public int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value){ return Runtime_Windows.PyDict_SetItem(pointer, key, value); } + + + public int PyDict_SetItemString(IntPtr pointer, string key, IntPtr value){ return Runtime_Windows.PyDict_SetItemString(pointer, key, value); } + + + public int PyDict_DelItem(IntPtr pointer, IntPtr key){ return Runtime_Windows.PyDict_DelItem(pointer, key); } + + + public int PyDict_DelItemString(IntPtr pointer, string key){ return Runtime_Windows.PyDict_DelItemString(pointer, key); } + + + public int PyMapping_HasKey(IntPtr pointer, IntPtr key){ return Runtime_Windows.PyMapping_HasKey(pointer, key); } + + + public IntPtr PyDict_Keys(IntPtr pointer){ return Runtime_Windows.PyDict_Keys(pointer); } + + + public IntPtr PyDict_Values(IntPtr pointer){ return Runtime_Windows.PyDict_Values(pointer); } + + + public IntPtr PyDict_Items(IntPtr pointer){ return Runtime_Windows.PyDict_Items(pointer); } + + + public IntPtr PyDict_Copy(IntPtr pointer){ return Runtime_Windows.PyDict_Copy(pointer); } + + + public int PyDict_Update(IntPtr pointer, IntPtr other){ return Runtime_Windows.PyDict_Update(pointer, other); } + + + public void PyDict_Clear(IntPtr pointer){ Runtime_Windows.PyDict_Clear(pointer); } + + + public int PyDict_Size(IntPtr pointer){ return Runtime_Windows.PyDict_Size(pointer); } + + + + + + public IntPtr PyList_New(int size){ return Runtime_Windows.PyList_New(size); } + + + public IntPtr PyList_AsTuple(IntPtr pointer){ return Runtime_Windows.PyList_AsTuple(pointer); } + + + public IntPtr PyList_GetItem(IntPtr pointer, int index){ return Runtime_Windows.PyList_GetItem(pointer, index); } + + + public int PyList_SetItem(IntPtr pointer, int index, IntPtr value){ return Runtime_Windows.PyList_SetItem(pointer, index, value); } + + + public int PyList_Insert(IntPtr pointer, int index, IntPtr value){ return Runtime_Windows.PyList_Insert(pointer, index, value); } + + + public int PyList_Append(IntPtr pointer, IntPtr value){ return Runtime_Windows.PyList_Append(pointer, value); } + + + public int PyList_Reverse(IntPtr pointer){ return Runtime_Windows.PyList_Reverse(pointer); } + + + public int PyList_Sort(IntPtr pointer){ return Runtime_Windows.PyList_Sort(pointer); } + + + public IntPtr PyList_GetSlice(IntPtr pointer, int start, int end){ return Runtime_Windows.PyList_GetSlice(pointer, start, end); } + + + public int PyList_SetSlice(IntPtr pointer, int start, int end, IntPtr value){ return Runtime_Windows.PyList_SetSlice(pointer, start, end, value); } + + + public int PyList_Size(IntPtr pointer){ return Runtime_Windows.PyList_Size(pointer); } + + + + public IntPtr PyTuple_New(int size){ return Runtime_Windows.PyTuple_New(size); } + + + public IntPtr PyTuple_GetItem(IntPtr pointer, int index){ return Runtime_Windows.PyTuple_GetItem(pointer, index); } + + + public int PyTuple_SetItem(IntPtr pointer, int index, IntPtr value){ return Runtime_Windows.PyTuple_SetItem(pointer, index, value); } + + + public IntPtr PyTuple_GetSlice(IntPtr pointer, int start, int end){ return Runtime_Windows.PyTuple_GetSlice(pointer, start, end); } + + + public int PyTuple_Size(IntPtr pointer){ return Runtime_Windows.PyTuple_Size(pointer); } + + + + + + public IntPtr PyIter_Next(IntPtr pointer){ return Runtime_Windows.PyIter_Next(pointer); } + + + //==================================================================== + // Python module API + //==================================================================== + + + public IntPtr PyModule_New(string name){ return Runtime_Windows.PyModule_New(name); } + + + public string PyModule_GetName(IntPtr module){ return Runtime_Windows.PyModule_GetName(module); } + + + public IntPtr PyModule_GetDict(IntPtr module){ return Runtime_Windows.PyModule_GetDict(module); } + + + public string PyModule_GetFilename(IntPtr module){ return Runtime_Windows.PyModule_GetFilename(module); } + +#if PYTHON3 + + public IntPtr PyModule_Create2(IntPtr module, int apiver){ return Runtime_Windows.PyModule_Create2(module, apiver); } +#endif + + + public IntPtr PyImport_Import(IntPtr name){ return Runtime_Windows.PyImport_Import(name); } + + + public IntPtr PyImport_ImportModule(string name){ return Runtime_Windows.PyImport_ImportModule(name); } + + + public IntPtr PyImport_ReloadModule(IntPtr module){ return Runtime_Windows.PyImport_ReloadModule(module); } + + + public IntPtr PyImport_AddModule(string name){ return Runtime_Windows.PyImport_AddModule(name); } + + + public IntPtr PyImport_GetModuleDict(){ return Runtime_Windows.PyImport_GetModuleDict(); } + +#if PYTHON3 + + public void PySys_SetArgvEx( + int argc, + string[] argv, + int updatepath + ){ Runtime_Windows.PySys_SetArgvEx(argc, + argv, + updatepath); } +#elif PYTHON2 + + public void PySys_SetArgvEx( + int argc, + string[] argv, + int updatepath + ){ return Runtime_Windows.PySys_SetArgvEx(argc, + argv, + updatepath); } +#endif + + + public IntPtr PySys_GetObject(string name){ return Runtime_Windows.PySys_GetObject(name); } + + + public int PySys_SetObject(string name, IntPtr ob){ return Runtime_Windows.PySys_SetObject(name, ob); } + + + + public void PyType_Modified(IntPtr type){ Runtime_Windows.PyType_Modified(type); } + + + public bool PyType_IsSubtype(IntPtr t1, IntPtr t2){ return Runtime_Windows.PyType_IsSubtype(t1, t2); } + + + + + public IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw){ return Runtime_Windows.PyType_GenericNew(type, args, kw); } + + + public IntPtr PyType_GenericAlloc(IntPtr type, int n){ return Runtime_Windows.PyType_GenericAlloc(type, n); } + + + public int PyType_Ready(IntPtr type){ return Runtime_Windows.PyType_Ready(type); } + + + public IntPtr _PyType_Lookup(IntPtr type, IntPtr name){ return Runtime_Windows._PyType_Lookup(type, name); } + + + public IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name){ return Runtime_Windows.PyObject_GenericGetAttr(obj, name); } + + + public int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value){ return Runtime_Windows.PyObject_GenericSetAttr(obj, name, value); } + + + public IntPtr _PyObject_GetDictPtr(IntPtr obj){ return Runtime_Windows._PyObject_GetDictPtr(obj); } + + + public IntPtr PyObject_GC_New(IntPtr tp){ return Runtime_Windows.PyObject_GC_New(tp); } + + + public void PyObject_GC_Del(IntPtr tp){ Runtime_Windows.PyObject_GC_Del(tp); } + + + public void PyObject_GC_Track(IntPtr tp){ Runtime_Windows.PyObject_GC_Track(tp); } + + + public void PyObject_GC_UnTrack(IntPtr tp){ Runtime_Windows.PyObject_GC_UnTrack(tp); } + + + //==================================================================== + // Python memory API + //==================================================================== + + + public IntPtr PyMem_Malloc(int size){ return Runtime_Windows.PyMem_Malloc(size); } + + + public IntPtr PyMem_Realloc(IntPtr ptr, int size){ return Runtime_Windows.PyMem_Realloc(ptr, size); } + + + public void PyMem_Free(IntPtr ptr){ Runtime_Windows.PyMem_Free(ptr); } + + + //==================================================================== + // Python exception API + //==================================================================== + + + public void PyErr_SetString(IntPtr ob, string message){ Runtime_Windows.PyErr_SetString(ob, message); } + + + public void PyErr_SetObject(IntPtr ob, IntPtr message){ Runtime_Windows.PyErr_SetObject(ob, message); } + + + public IntPtr PyErr_SetFromErrno(IntPtr ob){ return Runtime_Windows.PyErr_SetFromErrno(ob); } + + + public void PyErr_SetNone(IntPtr ob){ Runtime_Windows.PyErr_SetNone(ob); } + + + public int PyErr_ExceptionMatches(IntPtr exception){ return Runtime_Windows.PyErr_ExceptionMatches(exception); } + + + public int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val){ return Runtime_Windows.PyErr_GivenExceptionMatches(ob, val); } + + + public void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb){ Runtime_Windows.PyErr_NormalizeException(ob, val, tb); } + + + public int PyErr_Occurred(){ return Runtime_Windows.PyErr_Occurred(); } + + + public void PyErr_Fetch(ref IntPtr ob, ref IntPtr val, ref IntPtr tb){ Runtime_Windows.PyErr_Fetch(ref ob, ref val, ref tb); } + + + public void PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb){ Runtime_Windows.PyErr_Restore(ob, val, tb); } + + + public void PyErr_Clear(){ Runtime_Windows.PyErr_Clear(); } + + + public void PyErr_Print(){ Runtime_Windows.PyErr_Print(); } + + + //==================================================================== + // Miscellaneous + //==================================================================== + + + public IntPtr PyMethod_Self(IntPtr ob){ return Runtime_Windows.PyMethod_Self(ob); } + + + public IntPtr PyMethod_Function(IntPtr ob){ return Runtime_Windows.PyMethod_Function(ob); } + + + } +} diff --git a/src/runtime/NativeMethods_Linux.cs b/src/runtime/NativeMethods_Linux.cs new file mode 100644 index 000000000..491f8c169 --- /dev/null +++ b/src/runtime/NativeMethods_Linux.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +namespace Python.Runtime +{ + [SuppressUnmanagedCodeSecurity] + public class NativeMethods_Linux + { + +#if NETSTANDARD || NETCOREAPP + private static int RTLD_NOW = 0x2; + private static int RTLD_GLOBAL = 0x100; + private static IntPtr RTLD_DEFAULT = IntPtr.Zero; + private const string NativeDll = "libdl.so"; + public static IntPtr LoadLibrary(string fileName) + { + return dlopen($"lib{fileName}.so", RTLD_NOW | RTLD_GLOBAL); + } +#else + private static int RTLD_NOW = 0x2; + private static int RTLD_SHARED = 0x20; + private static IntPtr RTLD_DEFAULT = IntPtr.Zero; + private const string NativeDll = "libdl.so"; + + public static IntPtr LoadLibrary(string fileName) + { + return dlopen(fileName, RTLD_NOW | RTLD_SHARED); + } +#endif + + public static void FreeLibrary(IntPtr handle) + { + dlclose(handle); + } + + public static IntPtr GetProcAddress(IntPtr dllHandle, string name) + { + // look in the exe if dllHandle is NULL + if (dllHandle == IntPtr.Zero) + { + dllHandle = RTLD_DEFAULT; + } + + // clear previous errors if any + dlerror(); + IntPtr res = dlsym(dllHandle, name); + IntPtr errPtr = dlerror(); + if (errPtr != IntPtr.Zero) + { + throw new Exception("dlsym: " + Marshal.PtrToStringAnsi(errPtr)); + } + return res; + } + + [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr dlopen(String fileName, int flags); + + [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + private static extern IntPtr dlsym(IntPtr handle, String symbol); + + [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)] + private static extern int dlclose(IntPtr handle); + + [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr dlerror(); + } +} diff --git a/src/runtime/NativeMethods_OSX.cs b/src/runtime/NativeMethods_OSX.cs new file mode 100644 index 000000000..9ee1e4124 --- /dev/null +++ b/src/runtime/NativeMethods_OSX.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +namespace Python.Runtime +{ + [SuppressUnmanagedCodeSecurity] + + public class NativeMethods_OSX + { +#if NETSTANDARD || NETCOREAPP + private static int RTLD_NOW = 0x2; + + private static int RTLD_GLOBAL = 0x8; + private const string NativeDll = "/usr/lib/libSystem.dylib"; + private static IntPtr RTLD_DEFAULT = new IntPtr(-2); + + public static IntPtr LoadLibrary(string fileName) + { + return dlopen($"lib{fileName}.dylib", RTLD_NOW | RTLD_GLOBAL); + } +#else + private static int RTLD_NOW = 0x2; + private static int RTLD_SHARED = 0x20; + private static IntPtr RTLD_DEFAULT = new IntPtr(-2); + private const string NativeDll = "__Internal"; + + + public static IntPtr LoadLibrary(string fileName) + { + return dlopen(fileName, RTLD_NOW | RTLD_SHARED); + } +#endif + + + public static void FreeLibrary(IntPtr handle) + { + dlclose(handle); + } + + public static IntPtr GetProcAddress(IntPtr dllHandle, string name) + { + // look in the exe if dllHandle is NULL + if (dllHandle == IntPtr.Zero) + { + dllHandle = RTLD_DEFAULT; + } + + // clear previous errors if any + dlerror(); + IntPtr res = dlsym(dllHandle, name); + IntPtr errPtr = dlerror(); + if (errPtr != IntPtr.Zero) + { + throw new Exception("dlsym: " + Marshal.PtrToStringAnsi(errPtr)); + } + return res; + } + + [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr dlopen(String fileName, int flags); + + [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + private static extern IntPtr dlsym(IntPtr handle, String symbol); + + [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)] + private static extern int dlclose(IntPtr handle); + + [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr dlerror(); + } +} diff --git a/src/runtime/NativeMethods_WIndows.cs b/src/runtime/NativeMethods_WIndows.cs new file mode 100644 index 000000000..934169dcc --- /dev/null +++ b/src/runtime/NativeMethods_WIndows.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +namespace Python.Runtime +{ + [SuppressUnmanagedCodeSecurity] + + public class NativeMethods_Windows + { + private const string NativeDll = "kernel32.dll"; + + [DllImport(NativeDll)] + public static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport(NativeDll)] + public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); + + [DllImport(NativeDll)] + public static extern bool FreeLibrary(IntPtr hModule); + } +} diff --git a/src/runtime/Python.Runtime.15.csproj b/src/runtime/Python.Runtime.15.csproj index dc0e1e442..19831fad2 100644 --- a/src/runtime/Python.Runtime.15.csproj +++ b/src/runtime/Python.Runtime.15.csproj @@ -1,14 +1,16 @@ - + - net40;netstandard2.0 + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + net40;netstandard2.0;netcoreapp2.1 AnyCPU - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 + Debug;DebugPY3;Release;ReleasePY3 net45 Python.Runtime Python.Runtime Python.Runtime - 2.4.0 + 2.4.64 false false false @@ -30,12 +32,13 @@ XPLAT $(DefineConstants);$(CustomDefineConstants);$(BaseDefineConstants); $(DefineConstants);NETSTANDARD + $(DefineConstants);NETCOREAPP;NETCOREAPP2_1 $(DefineConstants);TRACE;DEBUG $(NuGetPackageRoot)\microsoft.targetingpack.netframework.v4.5\1.0.1\lib\net45\ $(PYTHONNET_PY2_VERSION) PYTHON27 $(PYTHONNET_PY3_VERSION) - PYTHON36 + PYTHON35 $(PYTHONNET_WIN_DEFINE_CONSTANTS) UCS2 $(PYTHONNET_MONO_DEFINE_CONSTANTS) @@ -60,29 +63,16 @@ true portable - - - $(DefineConstants);PYTHON2;$(Python2Version);$(PythonMonoDefineConstants) - - - $(DefineConstants);PYTHON3;$(Python3Version);$(PythonMonoDefineConstants) - - - $(DefineConstants);PYTHON2;$(Python2Version);$(PythonMonoDefineConstants);TRACE;DEBUG - - - $(DefineConstants);PYTHON3;$(Python3Version);$(PythonMonoDefineConstants);TRACE;DEBUG - - + $(DefineConstants);PYTHON2;$(Python2Version);$(PythonWinDefineConstants) - + $(DefineConstants);PYTHON3;$(Python3Version);$(PythonWinDefineConstants) - + $(DefineConstants);PYTHON2;$(Python2Version);$(PythonWinDefineConstants);TRACE;DEBUG - + $(DefineConstants);PYTHON3;$(Python3Version);$(PythonWinDefineConstants);TRACE;DEBUG @@ -114,6 +104,12 @@ + + + + + + diff --git a/src/runtime/arrayobject.cs b/src/runtime/arrayobject.cs index a10688749..96ce17232 100644 --- a/src/runtime/arrayobject.cs +++ b/src/runtime/arrayobject.cs @@ -22,11 +22,11 @@ internal override bool CanSubclass() public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { var self = GetManagedObject(tp) as ArrayObject; - if (Runtime.PyTuple_Size(args) != 1) + if (Runtime.Interop.PyTuple_Size(args) != 1) { return Exceptions.RaiseTypeError("array expects 1 argument"); } - IntPtr op = Runtime.PyTuple_GetItem(args, 0); + IntPtr op = Runtime.Interop.PyTuple_GetItem(args, 0); object result; if (!Converter.ToManaged(op, self.type, out result, true)) @@ -60,7 +60,7 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) if (rank == 1) { - index = Runtime.PyInt_AsLong(idx); + index = Runtime.Interop.PyInt_AsLong(idx); if (Exceptions.ErrorOccurred()) { @@ -93,14 +93,14 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) return IntPtr.Zero; } - int count = Runtime.PyTuple_Size(idx); + int count = Runtime.Interop.PyTuple_Size(idx); var args = new int[count]; for (var i = 0; i < count; i++) { - IntPtr op = Runtime.PyTuple_GetItem(idx, i); - index = Runtime.PyInt_AsLong(op); + IntPtr op = Runtime.Interop.PyTuple_GetItem(idx, i); + index = Runtime.Interop.PyInt_AsLong(op); if (Exceptions.ErrorOccurred()) { @@ -154,7 +154,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) if (rank == 1) { - index = Runtime.PyInt_AsLong(idx); + index = Runtime.Interop.PyInt_AsLong(idx); if (Exceptions.ErrorOccurred()) { @@ -186,13 +186,13 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) return -1; } - int count = Runtime.PyTuple_Size(idx); + int count = Runtime.Interop.PyTuple_Size(idx); var args = new int[count]; for (var i = 0; i < count; i++) { - IntPtr op = Runtime.PyTuple_GetItem(idx, i); - index = Runtime.PyInt_AsLong(op); + IntPtr op = Runtime.Interop.PyTuple_GetItem(idx, i); + index = Runtime.Interop.PyInt_AsLong(op); if (Exceptions.ErrorOccurred()) { diff --git a/src/runtime/assemblymanager.cs b/src/runtime/assemblymanager.cs index d63930a58..4eddc5fb0 100644 --- a/src/runtime/assemblymanager.cs +++ b/src/runtime/assemblymanager.cs @@ -131,15 +131,15 @@ private static Assembly ResolveHandler(object ob, ResolveEventArgs args) /// internal static void UpdatePath() { - IntPtr list = Runtime.PySys_GetObject("path"); - int count = Runtime.PyList_Size(list); + IntPtr list = Runtime.Interop.PySys_GetObject("path"); + int count = Runtime.Interop.PyList_Size(list); if (count != pypath.Count) { pypath.Clear(); probed.Clear(); for (var i = 0; i < count; i++) { - IntPtr item = Runtime.PyList_GetItem(list, i); + IntPtr item = Runtime.Interop.PyList_GetItem(list, i); string path = Runtime.GetManagedString(item); if (path != null) { @@ -387,7 +387,7 @@ public static AssemblyName[] ListAssemblies() /// public static bool IsValidNamespace(string name) { - return !string.IsNullOrEmpty(name) && namespaces.ContainsKey(name); + return !string.IsNullOrEmpty(name) && !name.Contains(Environment.NewLine) && namespaces.ContainsKey(name); } /// @@ -422,8 +422,9 @@ public static List GetNames(string nsname) Type[] types = a.GetTypes(); foreach (Type t in types) { - if ((t.Namespace ?? "") == nsname) - { + //if ((t.Namespace ?? "") == nsname) + if (t.Namespace == nsname) + { names.Add(t.Name); } } diff --git a/src/runtime/classbase.cs b/src/runtime/classbase.cs index 4dd3b5364..fc05e76bd 100644 --- a/src/runtime/classbase.cs +++ b/src/runtime/classbase.cs @@ -276,8 +276,8 @@ public static void tp_dealloc(IntPtr ob) { Runtime.XDecref(dict); } - Runtime.PyObject_GC_UnTrack(self.pyHandle); - Runtime.PyObject_GC_Del(self.pyHandle); + Runtime.Interop.PyObject_GC_UnTrack(self.pyHandle); + Runtime.Interop.PyObject_GC_Del(self.pyHandle); Runtime.XDecref(self.tpHandle); self.gcHandle.Free(); } diff --git a/src/runtime/classderived.cs b/src/runtime/classderived.cs index 16d3b99db..5fb842fa9 100644 --- a/src/runtime/classderived.cs +++ b/src/runtime/classderived.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -60,7 +60,7 @@ internal ClassDerivedObject(Type tp) : base(tp) var self = (CLRObject)GetManagedObject(ob); // don't let the python GC destroy this object - Runtime.PyObject_GC_UnTrack(self.pyHandle); + Runtime.Interop.PyObject_GC_UnTrack(self.pyHandle); // The python should now have a ref count of 0, but we don't actually want to // deallocate the object until the C# object that references it is destroyed. @@ -98,7 +98,7 @@ internal static IntPtr ToPython(IPythonDerivedType obj) self.gcHandle = gc; // now the object has a python reference it's safe for the python GC to track it - Runtime.PyObject_GC_Track(self.pyHandle); + Runtime.Interop.PyObject_GC_Track(self.pyHandle); } return self.pyHandle; @@ -631,7 +631,7 @@ public static T InvokeMethod(IPythonDerivedType obj, string methodName, strin if (null != self) { var disposeList = new List(); - IntPtr gs = Runtime.PyGILState_Ensure(); + IntPtr gs = Runtime.Interop.PyGILState_Ensure(); try { Runtime.XIncref(self.pyHandle); @@ -669,7 +669,7 @@ public static T InvokeMethod(IPythonDerivedType obj, string methodName, strin { x?.Dispose(); } - Runtime.PyGILState_Release(gs); + Runtime.Interop.PyGILState_Release(gs); } } @@ -693,7 +693,7 @@ public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, s if (null != self) { var disposeList = new List(); - IntPtr gs = Runtime.PyGILState_Ensure(); + IntPtr gs = Runtime.Interop.PyGILState_Ensure(); try { Runtime.XIncref(self.pyHandle); @@ -731,7 +731,7 @@ public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, s { x?.Dispose(); } - Runtime.PyGILState_Release(gs); + Runtime.Interop.PyGILState_Release(gs); } } @@ -757,7 +757,7 @@ public static T InvokeGetProperty(IPythonDerivedType obj, string propertyName throw new NullReferenceException("Instance must be specified when getting a property"); } - IntPtr gs = Runtime.PyGILState_Ensure(); + IntPtr gs = Runtime.Interop.PyGILState_Ensure(); try { Runtime.XIncref(self.pyHandle); @@ -769,7 +769,7 @@ public static T InvokeGetProperty(IPythonDerivedType obj, string propertyName } finally { - Runtime.PyGILState_Release(gs); + Runtime.Interop.PyGILState_Release(gs); } } @@ -783,7 +783,7 @@ public static void InvokeSetProperty(IPythonDerivedType obj, string propertyN throw new NullReferenceException("Instance must be specified when setting a property"); } - IntPtr gs = Runtime.PyGILState_Ensure(); + IntPtr gs = Runtime.Interop.PyGILState_Ensure(); try { Runtime.XIncref(self.pyHandle); @@ -795,7 +795,7 @@ public static void InvokeSetProperty(IPythonDerivedType obj, string propertyN } finally { - Runtime.PyGILState_Release(gs); + Runtime.Interop.PyGILState_Release(gs); } } @@ -809,7 +809,7 @@ public static void InvokeCtor(IPythonDerivedType obj, string origCtorName, objec args); CLRObject self = null; - IntPtr gs = Runtime.PyGILState_Ensure(); + IntPtr gs = Runtime.Interop.PyGILState_Ensure(); try { // create the python object @@ -831,7 +831,7 @@ public static void InvokeCtor(IPythonDerivedType obj, string origCtorName, objec Runtime.XDecref(self.pyHandle); } - Runtime.PyGILState_Release(gs); + Runtime.Interop.PyGILState_Release(gs); } } @@ -843,7 +843,7 @@ public static void Finalize(IPythonDerivedType obj) // If python's been terminated then just free the gchandle. lock (Runtime.IsFinalizingLock) { - if (0 == Runtime.Py_IsInitialized() || Runtime.IsFinalizing) + if (0 == Runtime.Interop.Py_IsInitialized() || Runtime.IsFinalizing) { self.gcHandle.Free(); return; @@ -858,13 +858,13 @@ public static void Finalize(IPythonDerivedType obj) lock (Runtime.IsFinalizingLock) { // If python's been terminated then just free the gchandle. - if (0 == Runtime.Py_IsInitialized() || Runtime.IsFinalizing) + if (0 == Runtime.Interop.Py_IsInitialized() || Runtime.IsFinalizing) { self.gcHandle.Free(); return; } - IntPtr gs = Runtime.PyGILState_Ensure(); + IntPtr gs = Runtime.Interop.PyGILState_Ensure(); try { // the C# object is being destroyed which must mean there are no more @@ -875,12 +875,12 @@ public static void Finalize(IPythonDerivedType obj) { Runtime.XDecref(dict); } - Runtime.PyObject_GC_Del(self.pyHandle); + Runtime.Interop.PyObject_GC_Del(self.pyHandle); self.gcHandle.Free(); } finally { - Runtime.PyGILState_Release(gs); + Runtime.Interop.PyGILState_Release(gs); } } }); diff --git a/src/runtime/classmanager.cs b/src/runtime/classmanager.cs index 6a9d40ebd..5f9b535d1 100644 --- a/src/runtime/classmanager.cs +++ b/src/runtime/classmanager.cs @@ -140,7 +140,7 @@ private static void InitClassBase(Type type, ClassBase impl) { var item = (ManagedType)iter.Value; var name = (string)iter.Key; - Runtime.PyDict_SetItemString(dict, name, item.pyHandle); + Runtime.Interop.PyDict_SetItemString(dict, name, item.pyHandle); } // If class has constructors, generate an __doc__ attribute. @@ -156,7 +156,7 @@ private static void InitClassBase(Type type, ClassBase impl) var attr = (DocStringAttribute)attrs[0]; string docStr = attr.DocString; doc = Runtime.PyString_FromString(docStr); - Runtime.PyDict_SetItemString(dict, "__doc__", doc); + Runtime.Interop.PyDict_SetItemString(dict, "__doc__", doc); Runtime.XDecref(doc); } @@ -173,15 +173,15 @@ private static void InitClassBase(Type type, ClassBase impl) var ctors = new ConstructorBinding(type, tp, co.binder); // ExtensionType types are untracked, so don't Incref() them. // TODO: deprecate __overloads__ soon... - Runtime.PyDict_SetItemString(dict, "__overloads__", ctors.pyHandle); - Runtime.PyDict_SetItemString(dict, "Overloads", ctors.pyHandle); + Runtime.Interop.PyDict_SetItemString(dict, "__overloads__", ctors.pyHandle); + Runtime.Interop.PyDict_SetItemString(dict, "Overloads", ctors.pyHandle); } // don't generate the docstring if one was already set from a DocStringAttribute. if (!CLRModule._SuppressDocs && doc == IntPtr.Zero) { doc = co.GetDocString(); - Runtime.PyDict_SetItemString(dict, "__doc__", doc); + Runtime.Interop.PyDict_SetItemString(dict, "__doc__", doc); Runtime.XDecref(doc); } } diff --git a/src/runtime/classobject.cs b/src/runtime/classobject.cs index 46257c73f..354a03f8b 100644 --- a/src/runtime/classobject.cs +++ b/src/runtime/classobject.cs @@ -67,13 +67,13 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) // convertible primitive types, just convert the arg directly. if (type.IsPrimitive || type == typeof(string)) { - if (Runtime.PyTuple_Size(args) != 1) + if (Runtime.Interop.PyTuple_Size(args) != 1) { Exceptions.SetError(Exceptions.TypeError, "no constructors match given arguments"); return IntPtr.Zero; } - IntPtr op = Runtime.PyTuple_GetItem(args, 0); + IntPtr op = Runtime.Interop.PyTuple_GetItem(args, 0); object result; if (!Converter.ToManaged(op, type, out result, true)) @@ -177,9 +177,9 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) if (!Runtime.PyTuple_Check(idx)) { - args = Runtime.PyTuple_New(1); + args = Runtime.Interop.PyTuple_New(1); Runtime.XIncref(idx); - Runtime.PyTuple_SetItem(args, 0, idx); + Runtime.Interop.PyTuple_SetItem(args, 0, idx); free = true; } @@ -223,31 +223,31 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) if (!Runtime.PyTuple_Check(idx)) { - args = Runtime.PyTuple_New(1); + args = Runtime.Interop.PyTuple_New(1); Runtime.XIncref(idx); - Runtime.PyTuple_SetItem(args, 0, idx); + Runtime.Interop.PyTuple_SetItem(args, 0, idx); free = true; } // Get the args passed in. - int i = Runtime.PyTuple_Size(args); + int i = Runtime.Interop.PyTuple_Size(args); IntPtr defaultArgs = cls.indexer.GetDefaultArgs(args); - int numOfDefaultArgs = Runtime.PyTuple_Size(defaultArgs); + int numOfDefaultArgs = Runtime.Interop.PyTuple_Size(defaultArgs); int temp = i + numOfDefaultArgs; - IntPtr real = Runtime.PyTuple_New(temp + 1); + IntPtr real = Runtime.Interop.PyTuple_New(temp + 1); for (var n = 0; n < i; n++) { - IntPtr item = Runtime.PyTuple_GetItem(args, n); + IntPtr item = Runtime.Interop.PyTuple_GetItem(args, n); Runtime.XIncref(item); - Runtime.PyTuple_SetItem(real, n, item); + Runtime.Interop.PyTuple_SetItem(real, n, item); } // Add Default Args if needed for (var n = 0; n < numOfDefaultArgs; n++) { - IntPtr item = Runtime.PyTuple_GetItem(defaultArgs, n); + IntPtr item = Runtime.Interop.PyTuple_GetItem(defaultArgs, n); Runtime.XIncref(item); - Runtime.PyTuple_SetItem(real, n + i, item); + Runtime.Interop.PyTuple_SetItem(real, n + i, item); } // no longer need defaultArgs Runtime.XDecref(defaultArgs); @@ -255,7 +255,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) // Add value to argument list Runtime.XIncref(v); - Runtime.PyTuple_SetItem(real, i, v); + Runtime.Interop.PyTuple_SetItem(real, i, v); try { diff --git a/src/runtime/clrobject.cs b/src/runtime/clrobject.cs index fb3d0e0d7..55ce2154b 100644 --- a/src/runtime/clrobject.cs +++ b/src/runtime/clrobject.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.InteropServices; namespace Python.Runtime @@ -9,7 +9,7 @@ internal class CLRObject : ManagedType internal CLRObject(object ob, IntPtr tp) { - IntPtr py = Runtime.PyType_GenericAlloc(tp, 0); + IntPtr py = Runtime.Interop.PyType_GenericAlloc(tp, 0); long flags = Util.ReadCLong(tp, TypeOffset.tp_flags); if ((flags & TypeFlags.Subclass) != 0) @@ -17,7 +17,7 @@ internal CLRObject(object ob, IntPtr tp) IntPtr dict = Marshal.ReadIntPtr(py, ObjectOffset.DictOffset(tp)); if (dict == IntPtr.Zero) { - dict = Runtime.PyDict_New(); + dict = Runtime.Interop.PyDict_New(); Marshal.WriteIntPtr(py, ObjectOffset.DictOffset(tp), dict); } } diff --git a/src/runtime/constructorbinder.cs b/src/runtime/constructorbinder.cs index 1fc541920..c9a83d49c 100644 --- a/src/runtime/constructorbinder.cs +++ b/src/runtime/constructorbinder.cs @@ -53,7 +53,7 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info) if (_containingType.IsValueType && !_containingType.IsPrimitive && !_containingType.IsEnum && _containingType != typeof(decimal) && - Runtime.PyTuple_Size(args) == 0) + Runtime.Interop.PyTuple_Size(args) == 0) { // If you are trying to construct an instance of a struct by // calling its default constructor, that ConstructorInfo @@ -87,7 +87,7 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info) // if there is a default constructor and, if so, assume that // any extra args are intended for the subclass' __init__. - IntPtr eargs = Runtime.PyTuple_New(0); + IntPtr eargs = Runtime.Interop.PyTuple_New(0); binding = Bind(inst, eargs, kw); Runtime.XDecref(eargs); diff --git a/src/runtime/converter.cs b/src/runtime/converter.cs index 13498e3dc..fa84a20a9 100644 --- a/src/runtime/converter.cs +++ b/src/runtime/converter.cs @@ -155,15 +155,15 @@ internal static IntPtr ToPython(object value, Type type) var pyderived = value as IPythonDerivedType; if (null != pyderived) { - #if NETSTANDARD +#if NETSTANDARD || NETCOREAPP return ClassDerivedObject.ToPython(pyderived); - #else +#else // if object is remote don't do this if (!System.Runtime.Remoting.RemotingServices.IsTransparentProxy(pyderived)) { return ClassDerivedObject.ToPython(pyderived); } - #endif +#endif } // hmm - from Python, we almost never care what the declared @@ -198,24 +198,24 @@ internal static IntPtr ToPython(object value, Type type) return Runtime.PyInt_FromInt32((int)((byte)value)); case TypeCode.Char: - return Runtime.PyUnicode_FromOrdinal((int)((char)value)); + return Runtime.Interop.PyUnicode_FromOrdinal((int)((char)value)); case TypeCode.Int16: return Runtime.PyInt_FromInt32((int)((short)value)); case TypeCode.Int64: - return Runtime.PyLong_FromLongLong((long)value); + return Runtime.Interop.PyLong_FromLongLong((long)value); case TypeCode.Single: // return Runtime.PyFloat_FromDouble((double)((float)value)); string ss = ((float)value).ToString(nfi); IntPtr ps = Runtime.PyString_FromString(ss); - IntPtr op = Runtime.PyFloat_FromString(ps, IntPtr.Zero); + IntPtr op = Runtime.Interop.PyFloat_FromString(ps, IntPtr.Zero); Runtime.XDecref(ps); return op; case TypeCode.Double: - return Runtime.PyFloat_FromDouble((double)value); + return Runtime.Interop.PyFloat_FromDouble((double)value); case TypeCode.SByte: return Runtime.PyInt_FromInt32((int)((sbyte)value)); @@ -224,10 +224,10 @@ internal static IntPtr ToPython(object value, Type type) return Runtime.PyInt_FromInt32((int)((ushort)value)); case TypeCode.UInt32: - return Runtime.PyLong_FromUnsignedLong((uint)value); + return Runtime.Interop.PyLong_FromUnsignedLong((uint)value); case TypeCode.UInt64: - return Runtime.PyLong_FromUnsignedLongLong((ulong)value); + return Runtime.Interop.PyLong_FromUnsignedLongLong((ulong)value); default: if (value is IEnumerable) @@ -328,7 +328,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType, if (obType.IsGenericType && obType.GetGenericTypeDefinition() == typeof(Nullable<>)) { - if( value == Runtime.PyNone ) + if (value == Runtime.PyNone) { result = null; return true; @@ -376,7 +376,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType, return ToPrimitive(value, doubleType, out result, setError); } - if (Runtime.PySequence_Check(value)) + if (Runtime.Interop.PySequence_Check(value)) { return ToArray(value, typeof(object[]), out result, setError); } @@ -465,7 +465,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo // Trickery to support 64-bit platforms. if (Runtime.IsPython2 && Runtime.Is32Bit) { - op = Runtime.PyNumber_Int(value); + op = Runtime.Interop.PyNumber_Int(value); // As of Python 2.3, large ints magically convert :( if (Runtime.PyLong_Check(op)) @@ -482,14 +482,14 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - ival = (int)Runtime.PyInt_AsLong(op); + ival = (int)Runtime.Interop.PyInt_AsLong(op); Runtime.XDecref(op); result = ival; return true; } else // Python3 always use PyLong API { - op = Runtime.PyNumber_Long(value); + op = Runtime.Interop.PyNumber_Long(value); if (op == IntPtr.Zero) { Exceptions.Clear(); @@ -499,7 +499,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - long ll = (long)Runtime.PyLong_AsLongLong(op); + long ll = (long)Runtime.Interop.PyLong_AsLongLong(op); Runtime.XDecref(op); if (ll == -1 && Exceptions.ErrorOccurred()) { @@ -514,14 +514,14 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } case TypeCode.Boolean: - result = Runtime.PyObject_IsTrue(value) != 0; + result = Runtime.Interop.PyObject_IsTrue(value) != 0; return true; case TypeCode.Byte: #if PYTHON3 if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) { - if (Runtime.PyBytes_Size(value) == 1) + if (Runtime.Interop.PyBytes_Size(value) == 1) { op = Runtime.PyBytes_AS_STRING(value); result = (byte)Marshal.ReadByte(op); @@ -542,7 +542,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } #endif - op = Runtime.PyNumber_Int(value); + op = Runtime.Interop.PyNumber_Int(value); if (op == IntPtr.Zero) { if (Exceptions.ExceptionMatches(overflow)) @@ -551,7 +551,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - ival = (int)Runtime.PyInt_AsLong(op); + ival = (int)Runtime.Interop.PyInt_AsLong(op); Runtime.XDecref(op); if (ival > Byte.MaxValue || ival < Byte.MinValue) @@ -566,7 +566,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo #if PYTHON3 if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) { - if (Runtime.PyBytes_Size(value) == 1) + if (Runtime.Interop.PyBytes_Size(value) == 1) { op = Runtime.PyBytes_AS_STRING(value); result = (byte)Marshal.ReadByte(op); @@ -587,7 +587,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } #endif - op = Runtime.PyNumber_Int(value); + op = Runtime.Interop.PyNumber_Int(value); if (op == IntPtr.Zero) { if (Exceptions.ExceptionMatches(overflow)) @@ -596,7 +596,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - ival = (int)Runtime.PyInt_AsLong(op); + ival = (int)Runtime.Interop.PyInt_AsLong(op); Runtime.XDecref(op); if (ival > SByte.MaxValue || ival < SByte.MinValue) @@ -611,7 +611,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo #if PYTHON3 if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) { - if (Runtime.PyBytes_Size(value) == 1) + if (Runtime.Interop.PyBytes_Size(value) == 1) { op = Runtime.PyBytes_AS_STRING(value); result = (byte)Marshal.ReadByte(op); @@ -633,9 +633,9 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo #endif else if (Runtime.PyObject_TypeCheck(value, Runtime.PyUnicodeType)) { - if (Runtime.PyUnicode_GetSize(value) == 1) + if (Runtime.Interop.PyUnicode_GetSize(value) == 1) { - op = Runtime.PyUnicode_AsUnicode(value); + op = Runtime.Interop.PyUnicode_AsUnicode(value); Char[] buff = new Char[1]; Marshal.Copy(op, buff, 0, 1); result = buff[0]; @@ -644,12 +644,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo goto type_error; } - op = Runtime.PyNumber_Int(value); + op = Runtime.Interop.PyNumber_Int(value); if (op == IntPtr.Zero) { goto type_error; } - ival = Runtime.PyInt_AsLong(op); + ival = Runtime.Interop.PyInt_AsLong(op); Runtime.XDecref(op); if (ival > Char.MaxValue || ival < Char.MinValue) { @@ -659,7 +659,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.Int16: - op = Runtime.PyNumber_Int(value); + op = Runtime.Interop.PyNumber_Int(value); if (op == IntPtr.Zero) { if (Exceptions.ExceptionMatches(overflow)) @@ -668,7 +668,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - ival = (int)Runtime.PyInt_AsLong(op); + ival = (int)Runtime.Interop.PyInt_AsLong(op); Runtime.XDecref(op); if (ival > Int16.MaxValue || ival < Int16.MinValue) { @@ -679,7 +679,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.Int64: - op = Runtime.PyNumber_Long(value); + op = Runtime.Interop.PyNumber_Long(value); if (op == IntPtr.Zero) { if (Exceptions.ExceptionMatches(overflow)) @@ -688,7 +688,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - long l = (long)Runtime.PyLong_AsLongLong(op); + long l = (long)Runtime.Interop.PyLong_AsLongLong(op); Runtime.XDecref(op); if ((l == -1) && Exceptions.ErrorOccurred()) { @@ -698,7 +698,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.UInt16: - op = Runtime.PyNumber_Int(value); + op = Runtime.Interop.PyNumber_Int(value); if (op == IntPtr.Zero) { if (Exceptions.ExceptionMatches(overflow)) @@ -707,7 +707,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - ival = (int)Runtime.PyInt_AsLong(op); + ival = (int)Runtime.Interop.PyInt_AsLong(op); Runtime.XDecref(op); if (ival > UInt16.MaxValue || ival < UInt16.MinValue) { @@ -718,7 +718,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.UInt32: - op = Runtime.PyNumber_Long(value); + op = Runtime.Interop.PyNumber_Long(value); if (op == IntPtr.Zero) { if (Exceptions.ExceptionMatches(overflow)) @@ -727,7 +727,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - uint ui = (uint)Runtime.PyLong_AsUnsignedLong(op); + uint ui = (uint)Runtime.Interop.PyLong_AsUnsignedLong(op); if (Exceptions.ErrorOccurred()) { @@ -735,7 +735,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo goto overflow; } - IntPtr check = Runtime.PyLong_FromUnsignedLong(ui); + IntPtr check = Runtime.Interop.PyLong_FromUnsignedLong(ui); int err = Runtime.PyObject_Compare(check, op); Runtime.XDecref(check); Runtime.XDecref(op); @@ -748,7 +748,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.UInt64: - op = Runtime.PyNumber_Long(value); + op = Runtime.Interop.PyNumber_Long(value); if (op == IntPtr.Zero) { if (Exceptions.ExceptionMatches(overflow)) @@ -757,7 +757,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - ulong ul = (ulong)Runtime.PyLong_AsUnsignedLongLong(op); + ulong ul = (ulong)Runtime.Interop.PyLong_AsUnsignedLongLong(op); Runtime.XDecref(op); if (Exceptions.ErrorOccurred()) { @@ -768,7 +768,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo case TypeCode.Single: - op = Runtime.PyNumber_Float(value); + op = Runtime.Interop.PyNumber_Float(value); if (op == IntPtr.Zero) { if (Exceptions.ExceptionMatches(overflow)) @@ -777,7 +777,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - double dd = Runtime.PyFloat_AsDouble(op); + double dd = Runtime.Interop.PyFloat_AsDouble(op); Runtime.CheckExceptionOccurred(); Runtime.XDecref(op); if (dd > Single.MaxValue || dd < Single.MinValue) @@ -791,12 +791,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.Double: - op = Runtime.PyNumber_Float(value); + op = Runtime.Interop.PyNumber_Float(value); if (op == IntPtr.Zero) { goto type_error; } - double d = Runtime.PyFloat_AsDouble(op); + double d = Runtime.Interop.PyFloat_AsDouble(op); Runtime.CheckExceptionOccurred(); Runtime.XDecref(op); result = d; @@ -827,7 +827,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo private static void SetConversionError(IntPtr value, Type target) { - IntPtr ob = Runtime.PyObject_Repr(value); + IntPtr ob = Runtime.Interop.PyObject_Repr(value); string src = Runtime.GetManagedString(ob); Runtime.XDecref(ob); Exceptions.SetError(Exceptions.TypeError, $"Cannot convert {src} to {target}"); @@ -842,7 +842,7 @@ private static void SetConversionError(IntPtr value, Type target) private static bool ToArray(IntPtr value, Type obType, out object result, bool setError) { Type elementType = obType.GetElementType(); - int size = Runtime.PySequence_Size(value); + int size = Runtime.Interop.PySequence_Size(value); result = null; if (size < 0) @@ -860,7 +860,7 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s for (var i = 0; i < size; i++) { object obj = null; - IntPtr item = Runtime.PySequence_GetItem(value, i); + IntPtr item = Runtime.Interop.PySequence_GetItem(value, i); if (item == IntPtr.Zero) { if (setError) diff --git a/src/runtime/debughelper.cs b/src/runtime/debughelper.cs index 2a91a74b4..34804e9e8 100644 --- a/src/runtime/debughelper.cs +++ b/src/runtime/debughelper.cs @@ -25,7 +25,7 @@ public static void Print(string msg, params IntPtr[] args) { Console.WriteLine("null arg to print"); } - IntPtr ob = Runtime.PyObject_Repr(t); + IntPtr ob = Runtime.Interop.PyObject_Repr(t); result += Runtime.GetManagedString(ob); Runtime.XDecref(ob); result += " "; diff --git a/src/runtime/delegatemanager.cs b/src/runtime/delegatemanager.cs index 7632816d1..992c17963 100644 --- a/src/runtime/delegatemanager.cs +++ b/src/runtime/delegatemanager.cs @@ -201,7 +201,7 @@ public Dispatcher(IntPtr target, Type dtype) // Note: the managed GC thread can run and try to free one of // these *after* the Python runtime has been finalized! - if (Runtime.Py_IsInitialized() > 0) + if (Runtime.Interop.Py_IsInitialized() > 0) { IntPtr gs = PythonEngine.AcquireLock(); Runtime.XDecref(target); @@ -232,7 +232,7 @@ public object TrueDispatch(ArrayList args) { MethodInfo method = dtype.GetMethod("Invoke"); ParameterInfo[] pi = method.GetParameters(); - IntPtr pyargs = Runtime.PyTuple_New(pi.Length); + IntPtr pyargs = Runtime.Interop.PyTuple_New(pi.Length); Type rtype = method.ReturnType; for (var i = 0; i < pi.Length; i++) @@ -240,10 +240,10 @@ public object TrueDispatch(ArrayList args) // Here we own the reference to the Python value, and we // give the ownership to the arg tuple. IntPtr arg = Converter.ToPython(args[i], pi[i].ParameterType); - Runtime.PyTuple_SetItem(pyargs, i, arg); + Runtime.Interop.PyTuple_SetItem(pyargs, i, arg); } - IntPtr op = Runtime.PyObject_Call(target, pyargs, IntPtr.Zero); + IntPtr op = Runtime.Interop.PyObject_Call(target, pyargs, IntPtr.Zero); Runtime.XDecref(pyargs); if (op == IntPtr.Zero) diff --git a/src/runtime/delegateobject.cs b/src/runtime/delegateobject.cs index e1103cbc7..8f49eb35c 100644 --- a/src/runtime/delegateobject.cs +++ b/src/runtime/delegateobject.cs @@ -51,14 +51,14 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { var self = (DelegateObject)GetManagedObject(tp); - if (Runtime.PyTuple_Size(args) != 1) + if (Runtime.Interop.PyTuple_Size(args) != 1) { return Exceptions.RaiseTypeError("class takes exactly one argument"); } - IntPtr method = Runtime.PyTuple_GetItem(args, 0); + IntPtr method = Runtime.Interop.PyTuple_GetItem(args, 0); - if (Runtime.PyCallable_Check(method) != 1) + if (Runtime.Interop.PyCallable_Check(method) != 1) { return Exceptions.RaiseTypeError("argument must be callable"); } diff --git a/src/runtime/eventbinding.cs b/src/runtime/eventbinding.cs index b8b4c82ad..2b45379a9 100644 --- a/src/runtime/eventbinding.cs +++ b/src/runtime/eventbinding.cs @@ -25,7 +25,7 @@ public static IntPtr nb_inplace_add(IntPtr ob, IntPtr arg) { var self = (EventBinding)GetManagedObject(ob); - if (Runtime.PyCallable_Check(arg) < 1) + if (Runtime.Interop.PyCallable_Check(arg) < 1) { Exceptions.SetError(Exceptions.TypeError, "event handlers must be callable"); return IntPtr.Zero; @@ -48,7 +48,7 @@ public static IntPtr nb_inplace_subtract(IntPtr ob, IntPtr arg) { var self = (EventBinding)GetManagedObject(ob); - if (Runtime.PyCallable_Check(arg) < 1) + if (Runtime.Interop.PyCallable_Check(arg) < 1) { Exceptions.SetError(Exceptions.TypeError, "invalid event handler"); return IntPtr.Zero; @@ -75,14 +75,14 @@ public static IntPtr tp_hash(IntPtr ob) if (self.target != IntPtr.Zero) { - x = Runtime.PyObject_Hash(self.target).ToInt64(); + x = Runtime.Interop.PyObject_Hash(self.target).ToInt64(); if (x == -1) { return new IntPtr(-1); } } - y = Runtime.PyObject_Hash(self.e.pyHandle).ToInt64(); + y = Runtime.Interop.PyObject_Hash(self.e.pyHandle).ToInt64(); if (y == -1) { return new IntPtr(-1); diff --git a/src/runtime/eventobject.cs b/src/runtime/eventobject.cs index 5f18c4609..9e495d306 100644 --- a/src/runtime/eventobject.cs +++ b/src/runtime/eventobject.cs @@ -54,7 +54,7 @@ internal bool AddEventHandler(IntPtr target, IntPtr handler) list = new ArrayList(); reg[key] = list; } - list.Add(new Handler(Runtime.PyObject_Hash(handler), d)); + list.Add(new Handler(Runtime.Interop.PyObject_Hash(handler), d)); // Note that AddEventHandler helper only works for public events, // so we have to get the underlying add method explicitly. @@ -78,7 +78,7 @@ internal bool RemoveEventHandler(IntPtr target, IntPtr handler) obj = co.inst; } - IntPtr hash = Runtime.PyObject_Hash(handler); + IntPtr hash = Runtime.Interop.PyObject_Hash(handler); if (Exceptions.ErrorOccurred() || reg == null) { Exceptions.SetError(Exceptions.ValueError, "unknown event handler"); @@ -151,7 +151,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) return binding.pyHandle; } - if (Runtime.PyObject_IsInstance(ob, tp) < 1) + if (Runtime.Interop.PyObject_IsInstance(ob, tp) < 1) { return Exceptions.RaiseTypeError("invalid argument"); } diff --git a/src/runtime/exceptions.cs b/src/runtime/exceptions.cs index 9023cfcfa..5fcf67855 100644 --- a/src/runtime/exceptions.cs +++ b/src/runtime/exceptions.cs @@ -81,15 +81,15 @@ private Exceptions() internal static void Initialize() { string exceptionsModuleName = Runtime.IsPython3 ? "builtins" : "exceptions"; - exceptions_module = Runtime.PyImport_ImportModule(exceptionsModuleName); + exceptions_module = Runtime.Interop.PyImport_ImportModule(exceptionsModuleName); Exceptions.ErrorCheck(exceptions_module); - warnings_module = Runtime.PyImport_ImportModule("warnings"); + warnings_module = Runtime.Interop.PyImport_ImportModule("warnings"); Exceptions.ErrorCheck(warnings_module); Type type = typeof(Exceptions); foreach (FieldInfo fi in type.GetFields(BindingFlags.Public | BindingFlags.Static)) { - IntPtr op = Runtime.PyObject_GetAttrString(exceptions_module, fi.Name); + IntPtr op = Runtime.Interop.PyObject_GetAttrString(exceptions_module, fi.Name); if (op != IntPtr.Zero) { fi.SetValue(type, op); @@ -100,7 +100,7 @@ internal static void Initialize() DebugUtil.Print($"Unknown exception: {fi.Name}"); } } - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); } @@ -109,7 +109,7 @@ internal static void Initialize() /// internal static void Shutdown() { - if (Runtime.Py_IsInitialized() != 0) + if (Runtime.Interop.Py_IsInitialized() != 0) { Type type = typeof(Exceptions); foreach (FieldInfo fi in type.GetFields(BindingFlags.Public | BindingFlags.Static)) @@ -121,7 +121,7 @@ internal static void Shutdown() } } Runtime.XDecref(exceptions_module); - Runtime.PyObject_HasAttrString(warnings_module, "xx"); + Runtime.Interop.PyObject_HasAttrString(warnings_module, "xx"); Runtime.XDecref(warnings_module); } } @@ -146,13 +146,13 @@ internal static void SetArgsAndCause(IntPtr ob) IntPtr args; if (!string.IsNullOrEmpty(e.Message)) { - args = Runtime.PyTuple_New(1); + args = Runtime.Interop.PyTuple_New(1); IntPtr msg = Runtime.PyUnicode_FromString(e.Message); - Runtime.PyTuple_SetItem(args, 0, msg); + Runtime.Interop.PyTuple_SetItem(args, 0, msg); } else { - args = Runtime.PyTuple_New(0); + args = Runtime.Interop.PyTuple_New(0); } Marshal.WriteIntPtr(ob, ExceptionOffset.args, args); @@ -198,7 +198,7 @@ internal static void ErrorOccurredCheck(IntPtr pointer) /// public static bool ExceptionMatches(IntPtr ob) { - return Runtime.PyErr_ExceptionMatches(ob) != 0; + return Runtime.Interop.PyErr_ExceptionMatches(ob) != 0; } /// @@ -210,7 +210,7 @@ public static bool ExceptionMatches(IntPtr ob) /// public static bool ExceptionMatches(IntPtr exc, IntPtr ob) { - int i = Runtime.PyErr_GivenExceptionMatches(exc, ob); + int i = Runtime.Interop.PyErr_GivenExceptionMatches(exc, ob); return i != 0; } @@ -223,7 +223,7 @@ public static bool ExceptionMatches(IntPtr exc, IntPtr ob) /// public static void SetError(IntPtr ob, string value) { - Runtime.PyErr_SetString(ob, value); + Runtime.Interop.PyErr_SetString(ob, value); } /// @@ -235,7 +235,7 @@ public static void SetError(IntPtr ob, string value) /// public static void SetError(IntPtr ob, IntPtr value) { - Runtime.PyErr_SetObject(ob, value); + Runtime.Interop.PyErr_SetObject(ob, value); } /// @@ -256,13 +256,13 @@ public static void SetError(Exception e) var pe = e as PythonException; if (pe != null) { - Runtime.PyErr_SetObject(pe.PyType, pe.PyValue); + Runtime.Interop.PyErr_SetObject(pe.PyType, pe.PyValue); return; } IntPtr op = CLRObject.GetInstHandle(e); - IntPtr etype = Runtime.PyObject_GetAttrString(op, "__class__"); - Runtime.PyErr_SetObject(etype, op); + IntPtr etype = Runtime.Interop.PyObject_GetAttrString(op, "__class__"); + Runtime.Interop.PyErr_SetObject(etype, op); Runtime.XDecref(etype); Runtime.XDecref(op); } @@ -276,7 +276,7 @@ public static void SetError(Exception e) /// public static bool ErrorOccurred() { - return Runtime.PyErr_Occurred() != 0; + return Runtime.Interop.PyErr_Occurred() != 0; } /// @@ -287,7 +287,7 @@ public static bool ErrorOccurred() /// public static void Clear() { - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); } //==================================================================== @@ -300,25 +300,25 @@ public static void Clear() public static void warn(string message, IntPtr exception, int stacklevel) { if (exception == IntPtr.Zero || - (Runtime.PyObject_IsSubclass(exception, Exceptions.Warning) != 1)) + (Runtime.Interop.PyObject_IsSubclass(exception, Exceptions.Warning) != 1)) { Exceptions.RaiseTypeError("Invalid exception"); } Runtime.XIncref(warnings_module); - IntPtr warn = Runtime.PyObject_GetAttrString(warnings_module, "warn"); + IntPtr warn = Runtime.Interop.PyObject_GetAttrString(warnings_module, "warn"); Runtime.XDecref(warnings_module); Exceptions.ErrorCheck(warn); - IntPtr args = Runtime.PyTuple_New(3); + IntPtr args = Runtime.Interop.PyTuple_New(3); IntPtr msg = Runtime.PyString_FromString(message); Runtime.XIncref(exception); // PyTuple_SetItem steals a reference IntPtr level = Runtime.PyInt_FromInt32(stacklevel); - Runtime.PyTuple_SetItem(args, 0, msg); - Runtime.PyTuple_SetItem(args, 1, exception); - Runtime.PyTuple_SetItem(args, 2, level); + Runtime.Interop.PyTuple_SetItem(args, 0, msg); + Runtime.Interop.PyTuple_SetItem(args, 1, exception); + Runtime.Interop.PyTuple_SetItem(args, 2, level); - IntPtr result = Runtime.PyObject_CallObject(warn, args); + IntPtr result = Runtime.Interop.PyObject_CallObject(warn, args); Exceptions.ErrorCheck(result); Runtime.XDecref(warn); diff --git a/src/runtime/extensiontype.cs b/src/runtime/extensiontype.cs index 9569b0485..cc49027fb 100644 --- a/src/runtime/extensiontype.cs +++ b/src/runtime/extensiontype.cs @@ -26,7 +26,7 @@ public ExtensionType() // DebugUtil.DumpType(tp); //} - IntPtr py = Runtime.PyType_GenericAlloc(tp, 0); + IntPtr py = Runtime.Interop.PyType_GenericAlloc(tp, 0); GCHandle gc = GCHandle.Alloc(this); Marshal.WriteIntPtr(py, ObjectOffset.magic(tp), (IntPtr)gc); @@ -36,7 +36,7 @@ public ExtensionType() // concrete extension types, so untrack the object to save calls // from Python into the managed runtime that are pure overhead. - Runtime.PyObject_GC_UnTrack(py); + Runtime.Interop.PyObject_GC_UnTrack(py); tpHandle = tp; pyHandle = py; @@ -49,7 +49,7 @@ public ExtensionType() /// public static void FinalizeObject(ManagedType self) { - Runtime.PyObject_GC_Del(self.pyHandle); + Runtime.Interop.PyObject_GC_Del(self.pyHandle); Runtime.XDecref(self.tpHandle); self.gcHandle.Free(); } diff --git a/src/runtime/importhook.cs b/src/runtime/importhook.cs index bc9ac5eee..ce7e10861 100644 --- a/src/runtime/importhook.cs +++ b/src/runtime/importhook.cs @@ -34,15 +34,15 @@ internal static void Initialize() // built-in Python __import__ with our own. This isn't ideal, // but it provides the most "Pythonic" way of dealing with CLR // modules (Python doesn't provide a way to emulate packages). - IntPtr dict = Runtime.PyImport_GetModuleDict(); + IntPtr dict = Runtime.Interop.PyImport_GetModuleDict(); IntPtr mod = Runtime.IsPython3 - ? Runtime.PyImport_ImportModule("builtins") - : Runtime.PyDict_GetItemString(dict, "__builtin__"); + ? Runtime.Interop.PyImport_ImportModule("builtins") + : Runtime.Interop.PyDict_GetItemString(dict, "__builtin__"); - py_import = Runtime.PyObject_GetAttrString(mod, "__import__"); + py_import = Runtime.Interop.PyObject_GetAttrString(mod, "__import__"); hook = new MethodWrapper(typeof(ImportHook), "__import__", "TernaryFunc"); - Runtime.PyObject_SetAttrString(mod, "__import__", hook.ptr); + Runtime.Interop.PyObject_SetAttrString(mod, "__import__", hook.ptr); Runtime.XDecref(hook.ptr); root = new CLRModule(); @@ -50,20 +50,20 @@ internal static void Initialize() #if PYTHON3 // create a python module with the same methods as the clr module-like object InitializeModuleDef(); - py_clr_module = Runtime.PyModule_Create2(module_def, 3); + py_clr_module = Runtime.Interop.PyModule_Create2(module_def, 3); // both dicts are borrowed references - IntPtr mod_dict = Runtime.PyModule_GetDict(py_clr_module); - IntPtr clr_dict = Runtime._PyObject_GetDictPtr(root.pyHandle); // PyObject** + IntPtr mod_dict = Runtime.Interop.PyModule_GetDict(py_clr_module); + IntPtr clr_dict = Runtime.Interop._PyObject_GetDictPtr(root.pyHandle); // PyObject** clr_dict = (IntPtr)Marshal.PtrToStructure(clr_dict, typeof(IntPtr)); - Runtime.PyDict_Update(mod_dict, clr_dict); + Runtime.Interop.PyDict_Update(mod_dict, clr_dict); #elif PYTHON2 Runtime.XIncref(root.pyHandle); // we are using the module two times py_clr_module = root.pyHandle; // Alias handle for PY2/PY3 #endif - Runtime.PyDict_SetItemString(dict, "CLR", py_clr_module); - Runtime.PyDict_SetItemString(dict, "clr", py_clr_module); + Runtime.Interop.PyDict_SetItemString(dict, "CLR", py_clr_module); + Runtime.Interop.PyDict_SetItemString(dict, "clr", py_clr_module); } @@ -72,7 +72,7 @@ internal static void Initialize() /// internal static void Shutdown() { - if (Runtime.Py_IsInitialized() != 0) + if (Runtime.Interop.Py_IsInitialized() != 0) { Runtime.XDecref(py_clr_module); Runtime.XDecref(root.pyHandle); @@ -96,10 +96,10 @@ public static IntPtr GetCLRModule(IntPtr? fromList = null) // Python 3 // update the module dictionary with the contents of the root dictionary root.LoadNames(); - IntPtr py_mod_dict = Runtime.PyModule_GetDict(py_clr_module); - IntPtr clr_dict = Runtime._PyObject_GetDictPtr(root.pyHandle); // PyObject** + IntPtr py_mod_dict = Runtime.Interop.PyModule_GetDict(py_clr_module); + IntPtr clr_dict = Runtime.Interop._PyObject_GetDictPtr(root.pyHandle); // PyObject** clr_dict = (IntPtr)Marshal.PtrToStructure(clr_dict, typeof(IntPtr)); - Runtime.PyDict_Update(py_mod_dict, clr_dict); + Runtime.Interop.PyDict_Update(py_mod_dict, clr_dict); // find any items from the from list and get them from the root if they're not // already in the module dictionary @@ -155,14 +155,14 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) // hook is saved as this.py_import. This version handles CLR // import and defers to the normal builtin for everything else. - int num_args = Runtime.PyTuple_Size(args); + int num_args = Runtime.Interop.PyTuple_Size(args); if (num_args < 1) { return Exceptions.RaiseTypeError("__import__() takes at least 1 argument (0 given)"); } // borrowed reference - IntPtr py_mod_name = Runtime.PyTuple_GetItem(args, 0); + IntPtr py_mod_name = Runtime.Interop.PyTuple_GetItem(args, 0); if (py_mod_name == IntPtr.Zero || !Runtime.IsStringType(py_mod_name)) { @@ -176,9 +176,9 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) var fromlist = false; if (num_args >= 4) { - fromList = Runtime.PyTuple_GetItem(args, 3); + fromList = Runtime.Interop.PyTuple_GetItem(args, 3); if (fromList != IntPtr.Zero && - Runtime.PyObject_IsTrue(fromList) == 1) + Runtime.Interop.PyObject_IsTrue(fromList) == 1) { fromlist = true; } @@ -193,10 +193,10 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) IntPtr clr_module = GetCLRModule(fromList); if (clr_module != IntPtr.Zero) { - IntPtr sys_modules = Runtime.PyImport_GetModuleDict(); + IntPtr sys_modules = Runtime.Interop.PyImport_GetModuleDict(); if (sys_modules != IntPtr.Zero) { - Runtime.PyDict_SetItemString(sys_modules, "clr", clr_module); + Runtime.Interop.PyDict_SetItemString(sys_modules, "clr", clr_module); } } return clr_module; @@ -207,10 +207,10 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) IntPtr clr_module = GetCLRModule(fromList); if (clr_module != IntPtr.Zero) { - IntPtr sys_modules = Runtime.PyImport_GetModuleDict(); + IntPtr sys_modules = Runtime.Interop.PyImport_GetModuleDict(); if (sys_modules != IntPtr.Zero) { - Runtime.PyDict_SetItemString(sys_modules, "clr", clr_module); + Runtime.Interop.PyDict_SetItemString(sys_modules, "clr", clr_module); } } return clr_module; @@ -233,7 +233,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) // Turns out that the AssemblyManager.ResolveHandler() checks to see if any // Assembly's FullName.ToLower().StartsWith(name.ToLower()), which makes very // little sense to me. - IntPtr res = Runtime.PyObject_Call(py_import, args, kw); + IntPtr res = Runtime.Interop.PyObject_Call(py_import, args, kw); if (res != IntPtr.Zero) { // There was no error. @@ -277,14 +277,14 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { // May be called when a module being imported imports a module. // In particular, I've seen decimal import copy import org.python.core - return Runtime.PyObject_Call(py_import, args, kw); + return Runtime.Interop.PyObject_Call(py_import, args, kw); } } // See if sys.modules for this interpreter already has the // requested module. If so, just return the existing module. - IntPtr modules = Runtime.PyImport_GetModuleDict(); - IntPtr module = Runtime.PyDict_GetItem(modules, py_mod_name); + IntPtr modules = Runtime.Interop.PyImport_GetModuleDict(); + IntPtr module = Runtime.Interop.PyDict_GetItem(modules, py_mod_name); if (module != IntPtr.Zero) { @@ -297,7 +297,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { return GetCLRModule(fromList); } - module = Runtime.PyDict_GetItemString(modules, names[0]); + module = Runtime.Interop.PyDict_GetItemString(modules, names[0]); Runtime.XIncref(module); return module; } @@ -336,20 +336,20 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) } // Add the module to sys.modules - Runtime.PyDict_SetItemString(modules, tail.moduleName, tail.pyHandle); + Runtime.Interop.PyDict_SetItemString(modules, tail.moduleName, tail.pyHandle); // If imported from CLR add CLR. to sys.modules as well if (clr_prefix != null) { - Runtime.PyDict_SetItemString(modules, clr_prefix + tail.moduleName, tail.pyHandle); + Runtime.Interop.PyDict_SetItemString(modules, clr_prefix + tail.moduleName, tail.pyHandle); } } ModuleObject mod = fromlist ? tail : head; - if (fromlist && Runtime.PySequence_Size(fromList) == 1) + if (fromlist && Runtime.Interop.PySequence_Size(fromList) == 1) { - IntPtr fp = Runtime.PySequence_GetItem(fromList, 0); + IntPtr fp = Runtime.Interop.PySequence_GetItem(fromList, 0); if (!CLRModule.preload && Runtime.GetManagedString(fp) == "*") { mod.LoadNames(); diff --git a/src/runtime/indexer.cs b/src/runtime/indexer.cs index 7b6d90ca8..3b869b6ab 100644 --- a/src/runtime/indexer.cs +++ b/src/runtime/indexer.cs @@ -56,7 +56,7 @@ internal void SetItem(IntPtr inst, IntPtr args) internal bool NeedsDefaultArgs(IntPtr args) { - int pynargs = Runtime.PyTuple_Size(args); + int pynargs = Runtime.Interop.PyTuple_Size(args); MethodBase[] methods = SetterBinder.GetMethods(); if (methods.Length == 0) { @@ -93,16 +93,16 @@ internal IntPtr GetDefaultArgs(IntPtr args) // if we don't need default args return empty tuple if (!NeedsDefaultArgs(args)) { - return Runtime.PyTuple_New(0); + return Runtime.Interop.PyTuple_New(0); } - int pynargs = Runtime.PyTuple_Size(args); + int pynargs = Runtime.Interop.PyTuple_Size(args); // Get the default arg tuple MethodBase[] methods = SetterBinder.GetMethods(); MethodBase mi = methods[0]; ParameterInfo[] pi = mi.GetParameters(); int clrnargs = pi.Length - 1; - IntPtr defaultArgs = Runtime.PyTuple_New(clrnargs - pynargs); + IntPtr defaultArgs = Runtime.Interop.PyTuple_New(clrnargs - pynargs); for (var i = 0; i < clrnargs - pynargs; i++) { if (pi[i + pynargs].DefaultValue == DBNull.Value) @@ -110,7 +110,7 @@ internal IntPtr GetDefaultArgs(IntPtr args) continue; } IntPtr arg = Converter.ToPython(pi[i + pynargs].DefaultValue, pi[i + pynargs].ParameterType); - Runtime.PyTuple_SetItem(defaultArgs, i, arg); + Runtime.Interop.PyTuple_SetItem(defaultArgs, i, arg); } return defaultArgs; } diff --git a/src/runtime/interfaceobject.cs b/src/runtime/interfaceobject.cs index ce1bc9eb0..84806dab4 100644 --- a/src/runtime/interfaceobject.cs +++ b/src/runtime/interfaceobject.cs @@ -36,13 +36,13 @@ static InterfaceObject() public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { var self = (InterfaceObject)GetManagedObject(tp); - int nargs = Runtime.PyTuple_Size(args); + int nargs = Runtime.Interop.PyTuple_Size(args); Type type = self.type; object obj; if (nargs == 1) { - IntPtr inst = Runtime.PyTuple_GetItem(args, 0); + IntPtr inst = Runtime.Interop.PyTuple_GetItem(args, 0); var co = GetManagedObject(inst) as CLRObject; if (co == null || !type.IsInstanceOfType(co.inst)) diff --git a/src/runtime/interop.cs b/src/runtime/interop.cs index 4ae4b61e0..089007f7e 100644 --- a/src/runtime/interop.cs +++ b/src/runtime/interop.cs @@ -89,7 +89,7 @@ static ObjectOffset() public static int magic(IntPtr ob) { if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) || - (Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException)))) + (Runtime.PyType_Check(ob) && Runtime.Interop.PyType_IsSubtype(ob, Exceptions.BaseException)))) { return ExceptionOffset.ob_data; } @@ -99,7 +99,7 @@ public static int magic(IntPtr ob) public static int DictOffset(IntPtr ob) { if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) || - (Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException)))) + (Runtime.PyType_Check(ob) && Runtime.Interop.PyType_IsSubtype(ob, Exceptions.BaseException)))) { return ExceptionOffset.ob_dict; } @@ -109,7 +109,7 @@ public static int DictOffset(IntPtr ob) public static int Size(IntPtr ob) { if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) || - (Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException)))) + (Runtime.PyType_Check(ob) && Runtime.Interop.PyType_IsSubtype(ob, Exceptions.BaseException)))) { return ExceptionOffset.Size(); } diff --git a/src/runtime/metatype.cs b/src/runtime/metatype.cs index 3295ab110..0e9063f80 100644 --- a/src/runtime/metatype.cs +++ b/src/runtime/metatype.cs @@ -29,27 +29,27 @@ public static IntPtr Initialize() /// public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) { - int len = Runtime.PyTuple_Size(args); + int len = Runtime.Interop.PyTuple_Size(args); if (len < 3) { return Exceptions.RaiseTypeError("invalid argument list"); } - IntPtr name = Runtime.PyTuple_GetItem(args, 0); - IntPtr bases = Runtime.PyTuple_GetItem(args, 1); - IntPtr dict = Runtime.PyTuple_GetItem(args, 2); + IntPtr name = Runtime.Interop.PyTuple_GetItem(args, 0); + IntPtr bases = Runtime.Interop.PyTuple_GetItem(args, 1); + IntPtr dict = Runtime.Interop.PyTuple_GetItem(args, 2); // We do not support multiple inheritance, so the bases argument // should be a 1-item tuple containing the type we are subtyping. // That type must itself have a managed implementation. We check // that by making sure its metatype is the CLR metatype. - if (Runtime.PyTuple_Size(bases) != 1) + if (Runtime.Interop.PyTuple_Size(bases) != 1) { return Exceptions.RaiseTypeError("cannot use multiple inheritance with managed classes"); } - IntPtr base_type = Runtime.PyTuple_GetItem(bases, 0); + IntPtr base_type = Runtime.Interop.PyTuple_GetItem(bases, 0); IntPtr mt = Runtime.PyObject_TYPE(base_type); if (!(mt == PyCLRMetaType || mt == Runtime.PyTypeType)) @@ -69,7 +69,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) } } - IntPtr slots = Runtime.PyDict_GetItemString(dict, "__slots__"); + IntPtr slots = Runtime.Interop.PyDict_GetItemString(dict, "__slots__"); if (slots != IntPtr.Zero) { return Exceptions.RaiseTypeError("subclasses of managed classes do not support __slots__"); @@ -127,14 +127,14 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) public static IntPtr tp_alloc(IntPtr mt, int n) { - IntPtr type = Runtime.PyType_GenericAlloc(mt, n); + IntPtr type = Runtime.Interop.PyType_GenericAlloc(mt, n); return type; } public static void tp_free(IntPtr tp) { - Runtime.PyObject_GC_Del(tp); + Runtime.Interop.PyObject_GC_Del(tp); } @@ -157,12 +157,12 @@ public static IntPtr tp_call(IntPtr tp, IntPtr args, IntPtr kw) return IntPtr.Zero; } - var init = Runtime.PyObject_GetAttrString(obj, "__init__"); - Runtime.PyErr_Clear(); + var init = Runtime.Interop.PyObject_GetAttrString(obj, "__init__"); + Runtime.Interop.PyErr_Clear(); if (init != IntPtr.Zero) { - IntPtr result = Runtime.PyObject_Call(init, args, kw); + IntPtr result = Runtime.Interop.PyObject_Call(init, args, kw); Runtime.XDecref(init); if (result == IntPtr.Zero) @@ -187,7 +187,7 @@ public static IntPtr tp_call(IntPtr tp, IntPtr args, IntPtr kw) /// public static int tp_setattro(IntPtr tp, IntPtr name, IntPtr value) { - IntPtr descr = Runtime._PyType_Lookup(tp, name); + IntPtr descr = Runtime.Interop._PyType_Lookup(tp, name); if (descr != IntPtr.Zero) { @@ -208,8 +208,8 @@ public static int tp_setattro(IntPtr tp, IntPtr name, IntPtr value) } } - int res = Runtime.PyObject_GenericSetAttr(tp, name, value); - Runtime.PyType_Modified(tp); + int res = Runtime.Interop.PyObject_GenericSetAttr(tp, name, value); + Runtime.Interop.PyType_Modified(tp); return res; } diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index f0c58f34f..e72693f74 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -279,7 +279,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth { // loop to find match, return invoker w/ or /wo error MethodBase[] _methods = null; - int pynargs = Runtime.PyTuple_Size(args); + int pynargs = Runtime.Interop.PyTuple_Size(args); object arg; var isGeneric = false; ArrayList defaultArgList = null; @@ -347,11 +347,11 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth { // map remaining Python arguments to a tuple since // the managed function accepts it - hopefully :] - op = Runtime.PyTuple_GetSlice(args, arrayStart, pynargs); + op = Runtime.Interop.PyTuple_GetSlice(args, arrayStart, pynargs); } else { - op = Runtime.PyTuple_GetItem(args, n); + op = Runtime.Interop.PyTuple_GetItem(args, n); } // this logic below handles cases when multiple overloading methods @@ -557,9 +557,9 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i int c = pi.Length; var n = 0; - IntPtr t = Runtime.PyTuple_New(binding.outs + 1); + IntPtr t = Runtime.Interop.PyTuple_New(binding.outs + 1); IntPtr v = Converter.ToPython(result, mi.ReturnType); - Runtime.PyTuple_SetItem(t, n, v); + Runtime.Interop.PyTuple_SetItem(t, n, v); n++; for (var i = 0; i < c; i++) @@ -568,14 +568,14 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i if (pi[i].IsOut || pt.IsByRef) { v = Converter.ToPython(binding.args[i], pt); - Runtime.PyTuple_SetItem(t, n, v); + Runtime.Interop.PyTuple_SetItem(t, n, v); n++; } } if (binding.outs == 1 && mi.ReturnType == typeof(void)) { - v = Runtime.PyTuple_GetItem(t, 1); + v = Runtime.Interop.PyTuple_GetItem(t, 1); Runtime.XIncref(v); Runtime.XDecref(t); return v; diff --git a/src/runtime/methodbinding.cs b/src/runtime/methodbinding.cs index 07090a92c..b722ed887 100644 --- a/src/runtime/methodbinding.cs +++ b/src/runtime/methodbinding.cs @@ -88,7 +88,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) Runtime.XIncref(om.pyHandle); return om.pyHandle; default: - return Runtime.PyObject_GenericGetAttr(ob, key); + return Runtime.Interop.PyObject_GenericGetAttr(ob, key); } } @@ -106,7 +106,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) { if (self.info.IsGenericMethod) { - int len = Runtime.PyTuple_Size(args); //FIXME: Never used + int len = Runtime.Interop.PyTuple_Size(args); //FIXME: Never used Type[] sigTp = Runtime.PythonArgsToTypeArray(args, true); if (sigTp != null) { @@ -131,17 +131,17 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) if (target == IntPtr.Zero && !self.m.IsStatic()) { - int len = Runtime.PyTuple_Size(args); + int len = Runtime.Interop.PyTuple_Size(args); if (len < 1) { Exceptions.SetError(Exceptions.TypeError, "not enough arguments"); return IntPtr.Zero; } - target = Runtime.PyTuple_GetItem(args, 0); + target = Runtime.Interop.PyTuple_GetItem(args, 0); Runtime.XIncref(target); disposeList.Add(target); - args = Runtime.PyTuple_GetSlice(args, 1, len); + args = Runtime.Interop.PyTuple_GetSlice(args, 1, len); disposeList.Add(args); } @@ -158,7 +158,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) if (baseType != null) { string baseMethodName = "_" + baseType.type.Name + "__" + self.m.name; - IntPtr baseMethod = Runtime.PyObject_GetAttrString(target, baseMethodName); + IntPtr baseMethod = Runtime.Interop.PyObject_GetAttrString(target, baseMethodName); if (baseMethod != IntPtr.Zero) { var baseSelf = GetManagedObject(baseMethod) as MethodBinding; @@ -170,7 +170,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) } else { - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); } } } @@ -199,14 +199,14 @@ public static IntPtr tp_hash(IntPtr ob) if (self.target != IntPtr.Zero) { - x = Runtime.PyObject_Hash(self.target).ToInt64(); + x = Runtime.Interop.PyObject_Hash(self.target).ToInt64(); if (x == -1) { return new IntPtr(-1); } } - y = Runtime.PyObject_Hash(self.m.pyHandle).ToInt64(); + y = Runtime.Interop.PyObject_Hash(self.m.pyHandle).ToInt64(); if (y == -1) { return new IntPtr(-1); diff --git a/src/runtime/methodobject.cs b/src/runtime/methodobject.cs index 8df9c8029..f854ce27d 100644 --- a/src/runtime/methodobject.cs +++ b/src/runtime/methodobject.cs @@ -129,7 +129,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) return doc; } - return Runtime.PyObject_GenericGetAttr(ob, key); + return Runtime.Interop.PyObject_GenericGetAttr(ob, key); } /// @@ -157,7 +157,7 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) return binding.pyHandle; } - if (Runtime.PyObject_IsInstance(ob, tp) < 1) + if (Runtime.Interop.PyObject_IsInstance(ob, tp) < 1) { return Exceptions.RaiseTypeError("invalid argument"); } diff --git a/src/runtime/methodwrapper.cs b/src/runtime/methodwrapper.cs index 2f3ce3ef2..476d8e8b6 100644 --- a/src/runtime/methodwrapper.cs +++ b/src/runtime/methodwrapper.cs @@ -22,14 +22,14 @@ public MethodWrapper(Type type, string name, string funcType = null) // Allocate and initialize a PyMethodDef structure to represent // the managed method, then create a PyCFunction. - mdef = Runtime.PyMem_Malloc(4 * IntPtr.Size); + mdef = Runtime.Interop.PyMem_Malloc(4 * IntPtr.Size); TypeManager.WriteMethodDef(mdef, name, fp, 0x0003); - ptr = Runtime.PyCFunction_NewEx(mdef, IntPtr.Zero, IntPtr.Zero); + ptr = Runtime.Interop.PyCFunction_NewEx(mdef, IntPtr.Zero, IntPtr.Zero); } public IntPtr Call(IntPtr args, IntPtr kw) { - return Runtime.PyCFunction_Call(ptr, args, kw); + return Runtime.Interop.PyCFunction_Call(ptr, args, kw); } } } diff --git a/src/runtime/moduleobject.cs b/src/runtime/moduleobject.cs index e683026f9..6e25e02cb 100644 --- a/src/runtime/moduleobject.cs +++ b/src/runtime/moduleobject.cs @@ -40,15 +40,15 @@ public ModuleObject(string name) docstring += "- " + a.FullName + "\n"; } - dict = Runtime.PyDict_New(); + dict = Runtime.Interop.PyDict_New(); IntPtr pyname = Runtime.PyString_FromString(moduleName); IntPtr pyfilename = Runtime.PyString_FromString(filename); IntPtr pydocstring = Runtime.PyString_FromString(docstring); IntPtr 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.Interop.PyDict_SetItemString(dict, "__name__", pyname); + Runtime.Interop.PyDict_SetItemString(dict, "__file__", pyfilename); + Runtime.Interop.PyDict_SetItemString(dict, "__doc__", pydocstring); + Runtime.Interop.PyDict_SetItemString(dict, "__class__", pycls); Runtime.XDecref(pyname); Runtime.XDecref(pyfilename); Runtime.XDecref(pydocstring); @@ -174,7 +174,7 @@ public ManagedType GetAttribute(string name, bool guess) /// private void StoreAttribute(string name, ManagedType ob) { - Runtime.PyDict_SetItemString(dict, name, ob.pyHandle); + Runtime.Interop.PyDict_SetItemString(dict, name, ob.pyHandle); cache[name] = ob; } @@ -259,7 +259,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key) return IntPtr.Zero; } - IntPtr op = Runtime.PyDict_GetItem(self.dict, key); + IntPtr op = Runtime.Interop.PyDict_GetItem(self.dict, key); if (op != IntPtr.Zero) { Runtime.XIncref(op); @@ -338,7 +338,7 @@ internal void InitializePreload() if (interactive_preload) { interactive_preload = false; - if (Runtime.PySys_GetObject("ps1") != IntPtr.Zero) + if (Runtime.Interop.PySys_GetObject("ps1") != IntPtr.Zero) { preload = true; } diff --git a/src/runtime/nativecall.cs b/src/runtime/nativecall.cs index b5bf25dd7..2330f0641 100644 --- a/src/runtime/nativecall.cs +++ b/src/runtime/nativecall.cs @@ -23,7 +23,7 @@ namespace Python.Runtime /// internal class NativeCall { -#if NETSTANDARD +#if NETSTANDARD || NETCOREAPP [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void Void_1_Delegate(IntPtr a1); @@ -159,7 +159,7 @@ public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) #endif } -#if !NETSTANDARD +#if !(NETSTANDARD || NETCOREAPP) /// /// Defines native call signatures to be generated by NativeCall. /// diff --git a/src/runtime/polyfill/ReflectionPolifills.cs b/src/runtime/polyfill/ReflectionPolifills.cs index a7e9c879a..d347856d2 100644 --- a/src/runtime/polyfill/ReflectionPolifills.cs +++ b/src/runtime/polyfill/ReflectionPolifills.cs @@ -4,7 +4,7 @@ namespace Python.Runtime { -#if NETSTANDARD +#if NETSTANDARD || NETCOREAPP public static class ReflectionPolifills { public static AssemblyBuilder DefineDynamicAssembly(this AppDomain appDomain, AssemblyName assemblyName, AssemblyBuilderAccess assemblyBuilderAccess) diff --git a/src/runtime/pydict.cs b/src/runtime/pydict.cs index 7237d1990..e262346a9 100644 --- a/src/runtime/pydict.cs +++ b/src/runtime/pydict.cs @@ -31,7 +31,7 @@ public PyDict(IntPtr ptr) : base(ptr) /// public PyDict() { - obj = Runtime.PyDict_New(); + obj = Runtime.Interop.PyDict_New(); if (obj == IntPtr.Zero) { throw new PythonException(); @@ -78,7 +78,7 @@ public static bool IsDictType(PyObject value) /// public bool HasKey(PyObject key) { - return Runtime.PyMapping_HasKey(obj, key.obj) != 0; + return Runtime.Interop.PyMapping_HasKey(obj, key.obj) != 0; } @@ -105,7 +105,7 @@ public bool HasKey(string key) /// public PyObject Keys() { - IntPtr items = Runtime.PyDict_Keys(obj); + IntPtr items = Runtime.Interop.PyDict_Keys(obj); if (items == IntPtr.Zero) { throw new PythonException(); @@ -122,7 +122,7 @@ public PyObject Keys() /// public PyObject Values() { - IntPtr items = Runtime.PyDict_Values(obj); + IntPtr items = Runtime.Interop.PyDict_Values(obj); if (items == IntPtr.Zero) { throw new PythonException(); @@ -139,7 +139,7 @@ public PyObject Values() /// public PyObject Items() { - IntPtr items = Runtime.PyDict_Items(obj); + IntPtr items = Runtime.Interop.PyDict_Items(obj); if (items == IntPtr.Zero) { throw new PythonException(); @@ -156,7 +156,7 @@ public PyObject Items() /// public PyDict Copy() { - IntPtr op = Runtime.PyDict_Copy(obj); + IntPtr op = Runtime.Interop.PyDict_Copy(obj); if (op == IntPtr.Zero) { throw new PythonException(); @@ -173,7 +173,7 @@ public PyDict Copy() /// public void Update(PyObject other) { - int result = Runtime.PyDict_Update(obj, other.obj); + int result = Runtime.Interop.PyDict_Update(obj, other.obj); if (result < 0) { throw new PythonException(); @@ -189,7 +189,7 @@ public void Update(PyObject other) /// public void Clear() { - Runtime.PyDict_Clear(obj); + Runtime.Interop.PyDict_Clear(obj); } } } diff --git a/src/runtime/pyfloat.cs b/src/runtime/pyfloat.cs index edfaca542..f58ac1a33 100644 --- a/src/runtime/pyfloat.cs +++ b/src/runtime/pyfloat.cs @@ -50,7 +50,7 @@ public PyFloat(PyObject o) /// public PyFloat(double value) { - obj = Runtime.PyFloat_FromDouble(value); + obj = Runtime.Interop.PyFloat_FromDouble(value); Runtime.CheckExceptionOccurred(); } @@ -65,7 +65,7 @@ public PyFloat(string value) { using (var s = new PyString(value)) { - obj = Runtime.PyFloat_FromString(s.obj, IntPtr.Zero); + obj = Runtime.Interop.PyFloat_FromString(s.obj, IntPtr.Zero); Runtime.CheckExceptionOccurred(); } } @@ -93,7 +93,7 @@ public static bool IsFloatType(PyObject value) /// public static PyFloat AsFloat(PyObject value) { - IntPtr op = Runtime.PyNumber_Float(value.obj); + IntPtr op = Runtime.Interop.PyNumber_Float(value.obj); Runtime.CheckExceptionOccurred(); return new PyFloat(op); } diff --git a/src/runtime/pyint.cs b/src/runtime/pyint.cs index f6911d9d7..894de24a7 100644 --- a/src/runtime/pyint.cs +++ b/src/runtime/pyint.cs @@ -150,7 +150,7 @@ public PyInt(sbyte value) : this((int)value) /// public PyInt(string value) { - obj = Runtime.PyInt_FromString(value, IntPtr.Zero, 0); + obj = Runtime.Interop.PyInt_FromString(value, IntPtr.Zero, 0); Runtime.CheckExceptionOccurred(); } @@ -177,7 +177,7 @@ public static bool IsIntType(PyObject value) /// public static PyInt AsInt(PyObject value) { - IntPtr op = Runtime.PyNumber_Int(value.obj); + IntPtr op = Runtime.Interop.PyNumber_Int(value.obj); Runtime.CheckExceptionOccurred(); return new PyInt(op); } @@ -203,7 +203,7 @@ public short ToInt16() /// public int ToInt32() { - return Runtime.PyInt_AsLong(obj); + return Runtime.Interop.PyInt_AsLong(obj); } diff --git a/src/runtime/pyiter.cs b/src/runtime/pyiter.cs index ee07bcecf..38df5aeab 100644 --- a/src/runtime/pyiter.cs +++ b/src/runtime/pyiter.cs @@ -33,7 +33,7 @@ public PyIter(IntPtr ptr) : base(ptr) /// public PyIter(PyObject iterable) { - obj = Runtime.PyObject_GetIter(iterable.obj); + obj = Runtime.Interop.PyObject_GetIter(iterable.obj); if (obj == IntPtr.Zero) { throw new PythonException(); @@ -59,7 +59,7 @@ public bool MoveNext() _current = null; } - IntPtr next = Runtime.PyIter_Next(obj); + IntPtr next = Runtime.Interop.PyIter_Next(obj); if (next == IntPtr.Zero) { return false; diff --git a/src/runtime/pylist.cs b/src/runtime/pylist.cs index b22d9d51f..b1262a989 100644 --- a/src/runtime/pylist.cs +++ b/src/runtime/pylist.cs @@ -50,7 +50,7 @@ public PyList(PyObject o) /// public PyList() { - obj = Runtime.PyList_New(0); + obj = Runtime.Interop.PyList_New(0); if (obj == IntPtr.Zero) { throw new PythonException(); @@ -67,12 +67,12 @@ public PyList() public PyList(PyObject[] items) { int count = items.Length; - obj = Runtime.PyList_New(count); + obj = Runtime.Interop.PyList_New(count); for (var i = 0; i < count; i++) { IntPtr ptr = items[i].obj; Runtime.XIncref(ptr); - int r = Runtime.PyList_SetItem(obj, i, ptr); + int r = Runtime.Interop.PyList_SetItem(obj, i, ptr); if (r < 0) { throw new PythonException(); @@ -103,7 +103,7 @@ public static bool IsListType(PyObject value) /// public static PyList AsList(PyObject value) { - IntPtr op = Runtime.PySequence_List(value.obj); + IntPtr op = Runtime.Interop.PySequence_List(value.obj); if (op == IntPtr.Zero) { throw new PythonException(); @@ -120,7 +120,7 @@ public static PyList AsList(PyObject value) /// public void Append(PyObject item) { - int r = Runtime.PyList_Append(obj, item.obj); + int r = Runtime.Interop.PyList_Append(obj, item.obj); if (r < 0) { throw new PythonException(); @@ -135,7 +135,7 @@ public void Append(PyObject item) /// public void Insert(int index, PyObject item) { - int r = Runtime.PyList_Insert(obj, index, item.obj); + int r = Runtime.Interop.PyList_Insert(obj, index, item.obj); if (r < 0) { throw new PythonException(); @@ -151,7 +151,7 @@ public void Insert(int index, PyObject item) /// public void Reverse() { - int r = Runtime.PyList_Reverse(obj); + int r = Runtime.Interop.PyList_Reverse(obj); if (r < 0) { throw new PythonException(); @@ -167,7 +167,7 @@ public void Reverse() /// public void Sort() { - int r = Runtime.PyList_Sort(obj); + int r = Runtime.Interop.PyList_Sort(obj); if (r < 0) { throw new PythonException(); diff --git a/src/runtime/pylong.cs b/src/runtime/pylong.cs index 286af40df..822477541 100644 --- a/src/runtime/pylong.cs +++ b/src/runtime/pylong.cs @@ -50,7 +50,7 @@ public PyLong(PyObject o) /// public PyLong(int value) { - obj = Runtime.PyLong_FromLong(value); + obj = Runtime.Interop.PyLong_FromLong(value); Runtime.CheckExceptionOccurred(); } @@ -64,7 +64,7 @@ public PyLong(int value) [CLSCompliant(false)] public PyLong(uint value) { - obj = Runtime.PyLong_FromLong(value); + obj = Runtime.Interop.PyLong_FromLong(value); Runtime.CheckExceptionOccurred(); } @@ -77,7 +77,7 @@ public PyLong(uint value) /// public PyLong(long value) { - obj = Runtime.PyLong_FromLongLong(value); + obj = Runtime.Interop.PyLong_FromLongLong(value); Runtime.CheckExceptionOccurred(); } @@ -91,7 +91,7 @@ public PyLong(long value) [CLSCompliant(false)] public PyLong(ulong value) { - obj = Runtime.PyLong_FromUnsignedLongLong(value); + obj = Runtime.Interop.PyLong_FromUnsignedLongLong(value); Runtime.CheckExceptionOccurred(); } @@ -104,7 +104,7 @@ public PyLong(ulong value) /// public PyLong(short value) { - obj = Runtime.PyLong_FromLong(value); + obj = Runtime.Interop.PyLong_FromLong(value); Runtime.CheckExceptionOccurred(); } @@ -118,7 +118,7 @@ public PyLong(short value) [CLSCompliant(false)] public PyLong(ushort value) { - obj = Runtime.PyLong_FromLong(value); + obj = Runtime.Interop.PyLong_FromLong(value); Runtime.CheckExceptionOccurred(); } @@ -131,7 +131,7 @@ public PyLong(ushort value) /// public PyLong(byte value) { - obj = Runtime.PyLong_FromLong(value); + obj = Runtime.Interop.PyLong_FromLong(value); Runtime.CheckExceptionOccurred(); } @@ -145,7 +145,7 @@ public PyLong(byte value) [CLSCompliant(false)] public PyLong(sbyte value) { - obj = Runtime.PyLong_FromLong(value); + obj = Runtime.Interop.PyLong_FromLong(value); Runtime.CheckExceptionOccurred(); } @@ -158,7 +158,7 @@ public PyLong(sbyte value) /// public PyLong(double value) { - obj = Runtime.PyLong_FromDouble(value); + obj = Runtime.Interop.PyLong_FromDouble(value); Runtime.CheckExceptionOccurred(); } @@ -171,7 +171,7 @@ public PyLong(double value) /// public PyLong(string value) { - obj = Runtime.PyLong_FromString(value, IntPtr.Zero, 0); + obj = Runtime.Interop.PyLong_FromString(value, IntPtr.Zero, 0); Runtime.CheckExceptionOccurred(); } @@ -198,7 +198,7 @@ public static bool IsLongType(PyObject value) /// public static PyLong AsLong(PyObject value) { - IntPtr op = Runtime.PyNumber_Long(value.obj); + IntPtr op = Runtime.Interop.PyNumber_Long(value.obj); Runtime.CheckExceptionOccurred(); return new PyLong(op); } @@ -235,7 +235,7 @@ public int ToInt32() /// public long ToInt64() { - return Runtime.PyLong_AsLongLong(obj); + return Runtime.Interop.PyLong_AsLongLong(obj); } } } diff --git a/src/runtime/pynumber.cs b/src/runtime/pynumber.cs index 4f7373a8c..5e8ab4c88 100644 --- a/src/runtime/pynumber.cs +++ b/src/runtime/pynumber.cs @@ -31,7 +31,7 @@ protected PyNumber() /// public static bool IsNumberType(PyObject value) { - return Runtime.PyNumber_Check(value.obj); + return Runtime.Interop.PyNumber_Check(value.obj); } } } diff --git a/src/runtime/pyobject.cs b/src/runtime/pyobject.cs index 4da74f96a..50bb9dfc2 100644 --- a/src/runtime/pyobject.cs +++ b/src/runtime/pyobject.cs @@ -138,7 +138,7 @@ protected virtual void Dispose(bool disposing) { if (!disposed) { - if (Runtime.Py_IsInitialized() > 0 && !Runtime.IsFinalizing) + if (Runtime.Interop.Py_IsInitialized() > 0 && !Runtime.IsFinalizing) { IntPtr gs = PythonEngine.AcquireLock(); Runtime.XDecref(obj); @@ -191,7 +191,7 @@ public bool TypeCheck(PyObject typeOrClass) /// public bool HasAttr(string name) { - return Runtime.PyObject_HasAttrString(obj, name) != 0; + return Runtime.Interop.PyObject_HasAttrString(obj, name) != 0; } @@ -204,7 +204,7 @@ public bool HasAttr(string name) /// public bool HasAttr(PyObject name) { - return Runtime.PyObject_HasAttr(obj, name.obj) != 0; + return Runtime.Interop.PyObject_HasAttr(obj, name.obj) != 0; } @@ -217,7 +217,7 @@ public bool HasAttr(PyObject name) /// public PyObject GetAttr(string name) { - IntPtr op = Runtime.PyObject_GetAttrString(obj, name); + IntPtr op = Runtime.Interop.PyObject_GetAttrString(obj, name); if (op == IntPtr.Zero) { throw new PythonException(); @@ -235,10 +235,10 @@ public PyObject GetAttr(string name) /// public PyObject GetAttr(string name, PyObject _default) { - IntPtr op = Runtime.PyObject_GetAttrString(obj, name); + IntPtr op = Runtime.Interop.PyObject_GetAttrString(obj, name); if (op == IntPtr.Zero) { - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); return _default; } return new PyObject(op); @@ -255,7 +255,7 @@ public PyObject GetAttr(string name, PyObject _default) /// public PyObject GetAttr(PyObject name) { - IntPtr op = Runtime.PyObject_GetAttr(obj, name.obj); + IntPtr op = Runtime.Interop.PyObject_GetAttr(obj, name.obj); if (op == IntPtr.Zero) { throw new PythonException(); @@ -274,10 +274,10 @@ public PyObject GetAttr(PyObject name) /// public PyObject GetAttr(PyObject name, PyObject _default) { - IntPtr op = Runtime.PyObject_GetAttr(obj, name.obj); + IntPtr op = Runtime.Interop.PyObject_GetAttr(obj, name.obj); if (op == IntPtr.Zero) { - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); return _default; } return new PyObject(op); @@ -293,7 +293,7 @@ public PyObject GetAttr(PyObject name, PyObject _default) /// public void SetAttr(string name, PyObject value) { - int r = Runtime.PyObject_SetAttrString(obj, name, value.obj); + int r = Runtime.Interop.PyObject_SetAttrString(obj, name, value.obj); if (r < 0) { throw new PythonException(); @@ -311,7 +311,7 @@ public void SetAttr(string name, PyObject value) /// public void SetAttr(PyObject name, PyObject value) { - int r = Runtime.PyObject_SetAttr(obj, name.obj, value.obj); + int r = Runtime.Interop.PyObject_SetAttr(obj, name.obj, value.obj); if (r < 0) { throw new PythonException(); @@ -328,7 +328,7 @@ public void SetAttr(PyObject name, PyObject value) /// public void DelAttr(string name) { - int r = Runtime.PyObject_SetAttrString(obj, name, IntPtr.Zero); + int r = Runtime.Interop.PyObject_SetAttrString(obj, name, IntPtr.Zero); if (r < 0) { throw new PythonException(); @@ -346,7 +346,7 @@ public void DelAttr(string name) /// public void DelAttr(PyObject name) { - int r = Runtime.PyObject_SetAttr(obj, name.obj, IntPtr.Zero); + int r = Runtime.Interop.PyObject_SetAttr(obj, name.obj, IntPtr.Zero); if (r < 0) { throw new PythonException(); @@ -364,7 +364,7 @@ public void DelAttr(PyObject name) /// public virtual PyObject GetItem(PyObject key) { - IntPtr op = Runtime.PyObject_GetItem(obj, key.obj); + IntPtr op = Runtime.Interop.PyObject_GetItem(obj, key.obj); if (op == IntPtr.Zero) { throw new PythonException(); @@ -417,7 +417,7 @@ public virtual PyObject GetItem(int index) /// public virtual void SetItem(PyObject key, PyObject value) { - int r = Runtime.PyObject_SetItem(obj, key.obj, value.obj); + int r = Runtime.Interop.PyObject_SetItem(obj, key.obj, value.obj); if (r < 0) { throw new PythonException(); @@ -469,7 +469,7 @@ public virtual void SetItem(int index, PyObject value) /// public virtual void DelItem(PyObject key) { - int r = Runtime.PyObject_DelItem(obj, key.obj); + int r = Runtime.Interop.PyObject_DelItem(obj, key.obj); if (r < 0) { throw new PythonException(); @@ -520,10 +520,10 @@ public virtual void DelItem(int index) /// public virtual int Length() { - int s = Runtime.PyObject_Size(obj); + int s = Runtime.Interop.PyObject_Size(obj); if (s < 0) { - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); return 0; } return s; @@ -582,7 +582,7 @@ public virtual PyObject this[int index] /// public PyObject GetIterator() { - IntPtr r = Runtime.PyObject_GetIter(obj); + IntPtr r = Runtime.Interop.PyObject_GetIter(obj); if (r == IntPtr.Zero) { throw new PythonException(); @@ -614,7 +614,7 @@ public IEnumerator GetEnumerator() public PyObject Invoke(params PyObject[] args) { var t = new PyTuple(args); - IntPtr r = Runtime.PyObject_Call(obj, t.obj, IntPtr.Zero); + IntPtr r = Runtime.Interop.PyObject_Call(obj, t.obj, IntPtr.Zero); t.Dispose(); if (r == IntPtr.Zero) { @@ -633,7 +633,7 @@ public PyObject Invoke(params PyObject[] args) /// public PyObject Invoke(PyTuple args) { - IntPtr r = Runtime.PyObject_Call(obj, args.obj, IntPtr.Zero); + IntPtr r = Runtime.Interop.PyObject_Call(obj, args.obj, IntPtr.Zero); if (r == IntPtr.Zero) { throw new PythonException(); @@ -652,7 +652,7 @@ public PyObject Invoke(PyTuple args) public PyObject Invoke(PyObject[] args, PyDict kw) { var t = new PyTuple(args); - IntPtr r = Runtime.PyObject_Call(obj, t.obj, kw != null ? kw.obj : IntPtr.Zero); + IntPtr r = Runtime.Interop.PyObject_Call(obj, t.obj, kw != null ? kw.obj : IntPtr.Zero); t.Dispose(); if (r == IntPtr.Zero) { @@ -671,7 +671,7 @@ public PyObject Invoke(PyObject[] args, PyDict kw) /// public PyObject Invoke(PyTuple args, PyDict kw) { - IntPtr r = Runtime.PyObject_Call(obj, args.obj, kw != null ? kw.obj : IntPtr.Zero); + IntPtr r = Runtime.Interop.PyObject_Call(obj, args.obj, kw != null ? kw.obj : IntPtr.Zero); if (r == IntPtr.Zero) { throw new PythonException(); @@ -755,10 +755,10 @@ public PyObject InvokeMethod(string name, PyTuple args, PyDict kw) /// public bool IsInstance(PyObject typeOrClass) { - int r = Runtime.PyObject_IsInstance(obj, typeOrClass.obj); + int r = Runtime.Interop.PyObject_IsInstance(obj, typeOrClass.obj); if (r < 0) { - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); return false; } return r != 0; @@ -774,10 +774,10 @@ public bool IsInstance(PyObject typeOrClass) /// public bool IsSubclass(PyObject typeOrClass) { - int r = Runtime.PyObject_IsSubclass(obj, typeOrClass.obj); + int r = Runtime.Interop.PyObject_IsSubclass(obj, typeOrClass.obj); if (r < 0) { - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); return false; } return r != 0; @@ -793,7 +793,7 @@ public bool IsSubclass(PyObject typeOrClass) /// public bool IsCallable() { - return Runtime.PyCallable_Check(obj) != 0; + return Runtime.Interop.PyCallable_Check(obj) != 0; } @@ -819,7 +819,7 @@ public bool IsIterable() /// public bool IsTrue() { - return Runtime.PyObject_IsTrue(obj) != 0; + return Runtime.Interop.PyObject_IsTrue(obj) != 0; } @@ -832,7 +832,7 @@ public bool IsTrue() /// public PyList Dir() { - IntPtr r = Runtime.PyObject_Dir(obj); + IntPtr r = Runtime.Interop.PyObject_Dir(obj); if (r == IntPtr.Zero) { throw new PythonException(); @@ -850,7 +850,7 @@ public PyList Dir() /// public string Repr() { - IntPtr strval = Runtime.PyObject_Repr(obj); + IntPtr strval = Runtime.Interop.PyObject_Repr(obj); string result = Runtime.GetManagedString(strval); Runtime.XDecref(strval); return result; @@ -866,7 +866,7 @@ public string Repr() /// public override string ToString() { - IntPtr strval = Runtime.PyObject_Unicode(obj); + IntPtr strval = Runtime.Interop.PyObject_Unicode(obj); string result = Runtime.GetManagedString(strval); Runtime.XDecref(strval); return result; @@ -909,7 +909,7 @@ public override bool Equals(object o) /// public override int GetHashCode() { - return ((ulong)Runtime.PyObject_Hash(obj)).GetHashCode(); + return ((ulong)Runtime.Interop.PyObject_Hash(obj)).GetHashCode(); } @@ -931,7 +931,7 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) public override bool TrySetMember(SetMemberBinder binder, object value) { IntPtr ptr = Converter.ToPython(value, value?.GetType()); - int r = Runtime.PyObject_SetAttrString(obj, binder.Name, ptr); + int r = Runtime.Interop.PyObject_SetAttrString(obj, binder.Name, ptr); if (r < 0) { throw new PythonException(); @@ -952,7 +952,7 @@ private void GetArgs(object[] inargs, CallInfo callInfo, out PyTuple args, out P var namedArgumentCount = callInfo.ArgumentNames.Count; var regularArgumentCount = callInfo.ArgumentCount - namedArgumentCount; - var argTuple = Runtime.PyTuple_New(regularArgumentCount); + var argTuple = Runtime.Interop.PyTuple_New(regularArgumentCount); for (int i = 0; i < regularArgumentCount; ++i) { AddArgument(argTuple, i, inargs[i]); @@ -975,7 +975,7 @@ private void GetArgs(object[] inargs, out PyTuple args, out PyDict kwargs) { ; } - IntPtr argtuple = Runtime.PyTuple_New(arg_count); + IntPtr argtuple = Runtime.Interop.PyTuple_New(arg_count); for (var i = 0; i < arg_count; i++) { AddArgument(argtuple, i, inargs[i]); @@ -1004,7 +1004,7 @@ private static void AddArgument(IntPtr argtuple, int i, object target) { IntPtr ptr = GetPythonObject(target); - if (Runtime.PyTuple_SetItem(argtuple, i, ptr) < 0) + if (Runtime.Interop.PyTuple_SetItem(argtuple, i, ptr) < 0) { throw new PythonException(); } @@ -1102,40 +1102,40 @@ public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg switch (binder.Operation) { case ExpressionType.Add: - res = Runtime.PyNumber_Add(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Add(this.obj, ((PyObject)arg).obj); break; case ExpressionType.AddAssign: - res = Runtime.PyNumber_InPlaceAdd(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceAdd(this.obj, ((PyObject)arg).obj); break; case ExpressionType.Subtract: - res = Runtime.PyNumber_Subtract(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Subtract(this.obj, ((PyObject)arg).obj); break; case ExpressionType.SubtractAssign: - res = Runtime.PyNumber_InPlaceSubtract(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceSubtract(this.obj, ((PyObject)arg).obj); break; case ExpressionType.Multiply: - res = Runtime.PyNumber_Multiply(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Multiply(this.obj, ((PyObject)arg).obj); break; case ExpressionType.MultiplyAssign: - res = Runtime.PyNumber_InPlaceMultiply(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceMultiply(this.obj, ((PyObject)arg).obj); break; case ExpressionType.Divide: - res = Runtime.PyNumber_Divide(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Divide(this.obj, ((PyObject)arg).obj); break; case ExpressionType.DivideAssign: - res = Runtime.PyNumber_InPlaceDivide(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceDivide(this.obj, ((PyObject)arg).obj); break; case ExpressionType.And: - res = Runtime.PyNumber_And(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_And(this.obj, ((PyObject)arg).obj); break; case ExpressionType.AndAssign: - res = Runtime.PyNumber_InPlaceAnd(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceAnd(this.obj, ((PyObject)arg).obj); break; case ExpressionType.ExclusiveOr: - res = Runtime.PyNumber_Xor(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Xor(this.obj, ((PyObject)arg).obj); break; case ExpressionType.ExclusiveOrAssign: - res = Runtime.PyNumber_InPlaceXor(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceXor(this.obj, ((PyObject)arg).obj); break; case ExpressionType.GreaterThan: result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) > 0; @@ -1144,10 +1144,10 @@ public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) >= 0; return true; case ExpressionType.LeftShift: - res = Runtime.PyNumber_Lshift(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Lshift(this.obj, ((PyObject)arg).obj); break; case ExpressionType.LeftShiftAssign: - res = Runtime.PyNumber_InPlaceLshift(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceLshift(this.obj, ((PyObject)arg).obj); break; case ExpressionType.LessThan: result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) < 0; @@ -1156,28 +1156,28 @@ public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) <= 0; return true; case ExpressionType.Modulo: - res = Runtime.PyNumber_Remainder(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Remainder(this.obj, ((PyObject)arg).obj); break; case ExpressionType.ModuloAssign: - res = Runtime.PyNumber_InPlaceRemainder(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceRemainder(this.obj, ((PyObject)arg).obj); break; case ExpressionType.NotEqual: result = Runtime.PyObject_Compare(this.obj, ((PyObject)arg).obj) != 0; return true; case ExpressionType.Or: - res = Runtime.PyNumber_Or(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Or(this.obj, ((PyObject)arg).obj); break; case ExpressionType.OrAssign: - res = Runtime.PyNumber_InPlaceOr(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceOr(this.obj, ((PyObject)arg).obj); break; case ExpressionType.Power: - res = Runtime.PyNumber_Power(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Power(this.obj, ((PyObject)arg).obj); break; case ExpressionType.RightShift: - res = Runtime.PyNumber_Rshift(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_Rshift(this.obj, ((PyObject)arg).obj); break; case ExpressionType.RightShiftAssign: - res = Runtime.PyNumber_InPlaceRshift(this.obj, ((PyObject)arg).obj); + res = Runtime.Interop.PyNumber_InPlaceRshift(this.obj, ((PyObject)arg).obj); break; default: result = null; @@ -1209,24 +1209,24 @@ public override bool TryUnaryOperation(UnaryOperationBinder binder, out object r switch (binder.Operation) { case ExpressionType.Negate: - res = Runtime.PyNumber_Negative(this.obj); + res = Runtime.Interop.PyNumber_Negative(this.obj); break; case ExpressionType.UnaryPlus: - res = Runtime.PyNumber_Positive(this.obj); + res = Runtime.Interop.PyNumber_Positive(this.obj); break; case ExpressionType.OnesComplement: - res = Runtime.PyNumber_Invert(this.obj); + res = Runtime.Interop.PyNumber_Invert(this.obj); break; case ExpressionType.Not: - r = Runtime.PyObject_Not(this.obj); + r = Runtime.Interop.PyObject_Not(this.obj); result = r == 1; return r != -1; case ExpressionType.IsFalse: - r = Runtime.PyObject_IsTrue(this.obj); + r = Runtime.Interop.PyObject_IsTrue(this.obj); result = r == 0; return r != -1; case ExpressionType.IsTrue: - r = Runtime.PyObject_IsTrue(this.obj); + r = Runtime.Interop.PyObject_IsTrue(this.obj); result = r == 1; return r != -1; case ExpressionType.Decrement: diff --git a/src/runtime/pyscope.cs b/src/runtime/pyscope.cs index 67f93c6e2..cb3617e7c 100644 --- a/src/runtime/pyscope.cs +++ b/src/runtime/pyscope.cs @@ -57,19 +57,19 @@ public class PyScope : DynamicObject, IDisposable /// internal PyScope(IntPtr ptr, PyScopeManager manager) { - if (!Runtime.PyType_IsSubtype(Runtime.PyObject_TYPE(ptr), Runtime.PyModuleType)) + if (!Runtime.Interop.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); + variables = Runtime.Interop.PyModule_GetDict(obj); Runtime.CheckExceptionOccurred(); - Runtime.PyDict_SetItemString( + Runtime.Interop.PyDict_SetItemString( variables, "__builtins__", - Runtime.PyEval_GetBuiltins() + Runtime.Interop.PyEval_GetBuiltins() ); this.Name = this.Get("__name__"); } @@ -182,7 +182,7 @@ public void ImportAll(string name) /// public void ImportAll(PyScope scope) { - int result = Runtime.PyDict_Update(variables, scope.variables); + int result = Runtime.Interop.PyDict_Update(variables, scope.variables); if (result < 0) { throw new PythonException(); @@ -201,8 +201,8 @@ public void ImportAll(PyObject module) { throw new PyScopeException("object is not a module"); } - var module_dict = Runtime.PyModule_GetDict(module.obj); - int result = Runtime.PyDict_Update(variables, module_dict); + var module_dict = Runtime.Interop.PyModule_GetDict(module.obj); + int result = Runtime.Interop.PyDict_Update(variables, module_dict); if (result < 0) { throw new PythonException(); @@ -217,7 +217,7 @@ public void ImportAll(PyObject module) /// public void ImportAll(PyDict dict) { - int result = Runtime.PyDict_Update(variables, dict.obj); + int result = Runtime.Interop.PyDict_Update(variables, dict.obj); if (result < 0) { throw new PythonException(); @@ -235,7 +235,7 @@ public PyObject Execute(PyObject script, PyDict locals = null) { Check(); IntPtr _locals = locals == null ? variables : locals.obj; - IntPtr ptr = Runtime.PyEval_EvalCode(script.Handle, variables, _locals); + IntPtr ptr = Runtime.Interop.PyEval_EvalCode(script.Handle, variables, _locals); Runtime.CheckExceptionOccurred(); if (ptr == Runtime.PyNone) { @@ -277,7 +277,7 @@ public PyObject Eval(string code, PyDict locals = null) Check(); IntPtr _locals = locals == null ? variables : locals.obj; var flag = (IntPtr)Runtime.Py_eval_input; - IntPtr ptr = Runtime.PyRun_String( + IntPtr ptr = Runtime.Interop.PyRun_String( code, flag, variables, _locals ); Runtime.CheckExceptionOccurred(); @@ -315,7 +315,7 @@ public void Exec(string code, PyDict locals = null) private void Exec(string code, IntPtr _globals, IntPtr _locals) { var flag = (IntPtr)Runtime.Py_file_input; - IntPtr ptr = Runtime.PyRun_String( + IntPtr ptr = Runtime.Interop.PyRun_String( code, flag, _globals, _locals ); Runtime.CheckExceptionOccurred(); @@ -345,7 +345,7 @@ private void Set(string name, IntPtr value) Check(); using (var pyKey = new PyString(name)) { - int r = Runtime.PyObject_SetItem(variables, pyKey.obj, value); + int r = Runtime.Interop.PyObject_SetItem(variables, pyKey.obj, value); if (r < 0) { throw new PythonException(); @@ -364,7 +364,7 @@ public void Remove(string name) Check(); using (var pyKey = new PyString(name)) { - int r = Runtime.PyObject_DelItem(variables, pyKey.obj); + int r = Runtime.Interop.PyObject_DelItem(variables, pyKey.obj); if (r < 0) { throw new PythonException(); @@ -383,7 +383,7 @@ public bool Contains(string name) Check(); using (var pyKey = new PyString(name)) { - return Runtime.PyMapping_HasKey(variables, pyKey.obj) != 0; + return Runtime.Interop.PyMapping_HasKey(variables, pyKey.obj) != 0; } } @@ -417,9 +417,9 @@ public bool TryGet(string name, out PyObject value) Check(); using (var pyKey = new PyString(name)) { - if (Runtime.PyMapping_HasKey(variables, pyKey.obj) != 0) + if (Runtime.Interop.PyMapping_HasKey(variables, pyKey.obj) != 0) { - IntPtr op = Runtime.PyObject_GetItem(variables, pyKey.obj); + IntPtr op = Runtime.Interop.PyObject_GetItem(variables, pyKey.obj); if (op == IntPtr.Zero) { throw new PythonException(); @@ -547,7 +547,7 @@ internal PyScope NewScope(string name) { name = ""; } - var module = Runtime.PyModule_New(name); + var module = Runtime.Interop.PyModule_New(name); if (module == IntPtr.Zero) { throw new PythonException(); diff --git a/src/runtime/pysequence.cs b/src/runtime/pysequence.cs index bfaee79a6..6e43e316d 100644 --- a/src/runtime/pysequence.cs +++ b/src/runtime/pysequence.cs @@ -29,7 +29,7 @@ protected PySequence() /// public static bool IsSequenceType(PyObject value) { - return Runtime.PySequence_Check(value.obj); + return Runtime.Interop.PySequence_Check(value.obj); } @@ -41,7 +41,7 @@ public static bool IsSequenceType(PyObject value) /// public PyObject GetSlice(int i1, int i2) { - IntPtr op = Runtime.PySequence_GetSlice(obj, i1, i2); + IntPtr op = Runtime.Interop.PySequence_GetSlice(obj, i1, i2); if (op == IntPtr.Zero) { throw new PythonException(); @@ -58,7 +58,7 @@ public PyObject GetSlice(int i1, int i2) /// public void SetSlice(int i1, int i2, PyObject v) { - int r = Runtime.PySequence_SetSlice(obj, i1, i2, v.obj); + int r = Runtime.Interop.PySequence_SetSlice(obj, i1, i2, v.obj); if (r < 0) { throw new PythonException(); @@ -74,7 +74,7 @@ public void SetSlice(int i1, int i2, PyObject v) /// public void DelSlice(int i1, int i2) { - int r = Runtime.PySequence_DelSlice(obj, i1, i2); + int r = Runtime.Interop.PySequence_DelSlice(obj, i1, i2); if (r < 0) { throw new PythonException(); @@ -91,10 +91,10 @@ public void DelSlice(int i1, int i2) /// public int Index(PyObject item) { - int r = Runtime.PySequence_Index(obj, item.obj); + int r = Runtime.Interop.PySequence_Index(obj, item.obj); if (r < 0) { - Runtime.PyErr_Clear(); + Runtime.Interop.PyErr_Clear(); return -1; } return r; @@ -110,7 +110,7 @@ public int Index(PyObject item) /// public bool Contains(PyObject item) { - int r = Runtime.PySequence_Contains(obj, item.obj); + int r = Runtime.Interop.PySequence_Contains(obj, item.obj); if (r < 0) { throw new PythonException(); @@ -128,7 +128,7 @@ public bool Contains(PyObject item) /// public PyObject Concat(PyObject other) { - IntPtr op = Runtime.PySequence_Concat(obj, other.obj); + IntPtr op = Runtime.Interop.PySequence_Concat(obj, other.obj); if (op == IntPtr.Zero) { throw new PythonException(); @@ -146,7 +146,7 @@ public PyObject Concat(PyObject other) /// public PyObject Repeat(int count) { - IntPtr op = Runtime.PySequence_Repeat(obj, count); + IntPtr op = Runtime.Interop.PySequence_Repeat(obj, count); if (op == IntPtr.Zero) { throw new PythonException(); diff --git a/src/runtime/pythonengine.cs b/src/runtime/pythonengine.cs index a23c7ac79..d7c5d8923 100644 --- a/src/runtime/pythonengine.cs +++ b/src/runtime/pythonengine.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -60,14 +60,14 @@ public static string ProgramName { get { - IntPtr p = Runtime.Py_GetProgramName(); + IntPtr p = Runtime.Interop.Py_GetProgramName(); return UcsMarshaler.PtrToPy3UnicodePy2String(p) ?? ""; } set { Marshal.FreeHGlobal(_programName); _programName = UcsMarshaler.Py3UnicodePy2StringtoPtr(value); - Runtime.Py_SetProgramName(_programName); + Runtime.Interop.Py_SetProgramName(_programName); } } @@ -75,14 +75,14 @@ public static string PythonHome { get { - IntPtr p = Runtime.Py_GetPythonHome(); + IntPtr p = Runtime.Interop.Py_GetPythonHome(); return UcsMarshaler.PtrToPy3UnicodePy2String(p) ?? ""; } set { Marshal.FreeHGlobal(_pythonHome); _pythonHome = UcsMarshaler.Py3UnicodePy2StringtoPtr(value); - Runtime.Py_SetPythonHome(_pythonHome); + Runtime.Interop.Py_SetPythonHome(_pythonHome); } } @@ -90,7 +90,7 @@ public static string PythonPath { get { - IntPtr p = Runtime.Py_GetPath(); + IntPtr p = Runtime.Interop.Py_GetPath(); return UcsMarshaler.PtrToPy3UnicodePy2String(p) ?? ""; } set @@ -101,38 +101,38 @@ public static string PythonPath } Marshal.FreeHGlobal(_pythonPath); _pythonPath = UcsMarshaler.Py3UnicodePy2StringtoPtr(value); - Runtime.Py_SetPath(_pythonPath); + Runtime.Interop.Py_SetPath(_pythonPath); } } public static string Version { - get { return Marshal.PtrToStringAnsi(Runtime.Py_GetVersion()); } + get { return Marshal.PtrToStringAnsi(Runtime.Interop.Py_GetVersion()); } } public static string BuildInfo { - get { return Marshal.PtrToStringAnsi(Runtime.Py_GetBuildInfo()); } + get { return Marshal.PtrToStringAnsi(Runtime.Interop.Py_GetBuildInfo()); } } public static string Platform { - get { return Marshal.PtrToStringAnsi(Runtime.Py_GetPlatform()); } + get { return Marshal.PtrToStringAnsi(Runtime.Interop.Py_GetPlatform()); } } public static string Copyright { - get { return Marshal.PtrToStringAnsi(Runtime.Py_GetCopyright()); } + get { return Marshal.PtrToStringAnsi(Runtime.Interop.Py_GetCopyright()); } } public static string Compiler { - get { return Marshal.PtrToStringAnsi(Runtime.Py_GetCompiler()); } + get { return Marshal.PtrToStringAnsi(Runtime.Interop.Py_GetCompiler()); } } public static int RunSimpleString(string code) { - return Runtime.PyRun_SimpleString(code); + return Runtime.Interop.PyRun_SimpleString(code); } public static void Initialize() @@ -183,15 +183,15 @@ 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); + IntPtr clr_dict = Runtime.Interop.PyModule_GetDict(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); + IntPtr module = Runtime.Interop.PyImport_AddModule("clr._extras"); + IntPtr module_globals = Runtime.Interop.PyModule_GetDict(module); + IntPtr builtins = Runtime.Interop.PyEval_GetBuiltins(); + Runtime.Interop.PyDict_SetItemString(module_globals, "__builtins__", builtins); Assembly assembly = Assembly.GetExecutingAssembly(); using (Stream stream = assembly.GetManifestResourceStream("clr.py")) @@ -204,13 +204,13 @@ public static void Initialize(IEnumerable args, bool setSysArgv = true) // 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); + Runtime.Interop.PyDict_SetItemString(clr_dict, "_extras", module); foreach (PyObject key in locals.Keys()) { if (!key.ToString().StartsWith("_") || key.ToString().Equals("__version__")) { PyObject value = locals[key]; - Runtime.PyDict_SetItem(clr_dict, key.Handle, value.Handle); + Runtime.Interop.PyDict_SetItem(clr_dict, key.Handle, value.Handle); value.Dispose(); } key.Dispose(); @@ -324,7 +324,7 @@ public static void Shutdown() /// public static IntPtr AcquireLock() { - return Runtime.PyGILState_Ensure(); + return Runtime.Interop.PyGILState_Ensure(); } @@ -339,7 +339,7 @@ public static IntPtr AcquireLock() /// public static void ReleaseLock(IntPtr gs) { - Runtime.PyGILState_Release(gs); + Runtime.Interop.PyGILState_Release(gs); } @@ -355,7 +355,7 @@ public static void ReleaseLock(IntPtr gs) /// public static IntPtr BeginAllowThreads() { - return Runtime.PyEval_SaveThread(); + return Runtime.Interop.PyEval_SaveThread(); } @@ -371,7 +371,7 @@ public static IntPtr BeginAllowThreads() /// public static void EndAllowThreads(IntPtr ts) { - Runtime.PyEval_RestoreThread(ts); + Runtime.Interop.PyEval_RestoreThread(ts); } @@ -385,7 +385,7 @@ public static void EndAllowThreads(IntPtr ts) /// public static PyObject ImportModule(string name) { - IntPtr op = Runtime.PyImport_ImportModule(name); + IntPtr op = Runtime.Interop.PyImport_ImportModule(name); Runtime.CheckExceptionOccurred(); return new PyObject(op); } @@ -400,7 +400,7 @@ public static PyObject ImportModule(string name) /// public static PyObject ReloadModule(PyObject module) { - IntPtr op = Runtime.PyImport_ReloadModule(module.Handle); + IntPtr op = Runtime.Interop.PyImport_ReloadModule(module.Handle); Runtime.CheckExceptionOccurred(); return new PyObject(op); } @@ -415,9 +415,9 @@ public static PyObject ReloadModule(PyObject module) /// public static PyObject ModuleFromString(string name, string code) { - IntPtr c = Runtime.Py_CompileString(code, "none", (IntPtr)257); + IntPtr c = Runtime.Interop.Py_CompileString(code, "none", (IntPtr)257); Runtime.CheckExceptionOccurred(); - IntPtr m = Runtime.PyImport_ExecCodeModule(name, c); + IntPtr m = Runtime.Interop.PyImport_ExecCodeModule(name, c); Runtime.CheckExceptionOccurred(); return new PyObject(m); } @@ -425,7 +425,7 @@ public static PyObject ModuleFromString(string name, string code) public static PyObject Compile(string code, string filename = "", RunFlagType mode = RunFlagType.File) { var flag = (IntPtr)mode; - IntPtr ptr = Runtime.Py_CompileString(code, filename, flag); + IntPtr ptr = Runtime.Interop.Py_CompileString(code, filename, flag); Runtime.CheckExceptionOccurred(); return new PyObject(ptr); } @@ -485,13 +485,13 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals, var borrowedGlobals = true; if (globals == null) { - globals = Runtime.PyEval_GetGlobals(); + globals = Runtime.Interop.PyEval_GetGlobals(); if (globals == IntPtr.Zero) { - globals = Runtime.PyDict_New(); - Runtime.PyDict_SetItemString( + globals = Runtime.Interop.PyDict_New(); + Runtime.Interop.PyDict_SetItemString( globals.Value, "__builtins__", - Runtime.PyEval_GetBuiltins() + Runtime.Interop.PyEval_GetBuiltins() ); borrowedGlobals = false; } @@ -504,7 +504,7 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals, try { - IntPtr result = Runtime.PyRun_String( + IntPtr result = Runtime.Interop.PyRun_String( code, (IntPtr)flag, globals.Value, locals.Value ); @@ -596,7 +596,7 @@ public static KeywordArguments kw(params object[] kv) { value = Converter.ToPython(kv[i + 1], kv[i + 1]?.GetType()); } - if (Runtime.PyDict_SetItemString(dict.Handle, (string)kv[i], value) != 0) + if (Runtime.Interop.PyDict_SetItemString(dict.Handle, (string)kv[i], value) != 0) { throw new ArgumentException(string.Format("Cannot add key '{0}' to dictionary.", (string)kv[i])); } @@ -642,7 +642,7 @@ public static void SetArgv(IEnumerable argv) using (GIL()) { string[] arr = argv.ToArray(); - Runtime.PySys_SetArgvEx(arr.Length, arr, 0); + Runtime.Interop.PySys_SetArgvEx(arr.Length, arr, 0); Runtime.CheckExceptionOccurred(); } } diff --git a/src/runtime/pythonexception.cs b/src/runtime/pythonexception.cs index ded7fbeb5..8bc3b7c13 100644 --- a/src/runtime/pythonexception.cs +++ b/src/runtime/pythonexception.cs @@ -19,7 +19,7 @@ public class PythonException : System.Exception public PythonException() { IntPtr gs = PythonEngine.AcquireLock(); - Runtime.PyErr_Fetch(ref _pyType, ref _pyValue, ref _pyTB); + Runtime.Interop.PyErr_Fetch(ref _pyType, ref _pyValue, ref _pyTB); Runtime.XIncref(_pyType); Runtime.XIncref(_pyValue); Runtime.XIncref(_pyTB); @@ -73,7 +73,7 @@ public PythonException() public void Restore() { IntPtr gs = PythonEngine.AcquireLock(); - Runtime.PyErr_Restore(_pyType, _pyValue, _pyTB); + Runtime.Interop.PyErr_Restore(_pyType, _pyValue, _pyTB); _pyType = IntPtr.Zero; _pyValue = IntPtr.Zero; _pyTB = IntPtr.Zero; @@ -156,7 +156,7 @@ public void Dispose() { if (!disposed) { - if (Runtime.Py_IsInitialized() > 0 && !Runtime.IsFinalizing) + if (Runtime.Interop.Py_IsInitialized() > 0 && !Runtime.IsFinalizing) { IntPtr gs = PythonEngine.AcquireLock(); Runtime.XDecref(_pyType); @@ -182,7 +182,7 @@ public void Dispose() /// public static bool Matches(IntPtr ob) { - return Runtime.PyErr_ExceptionMatches(ob) != 0; + return Runtime.Interop.PyErr_ExceptionMatches(ob) != 0; } } } diff --git a/src/runtime/pytuple.cs b/src/runtime/pytuple.cs index 45f3d8350..091d3cab8 100644 --- a/src/runtime/pytuple.cs +++ b/src/runtime/pytuple.cs @@ -50,7 +50,7 @@ public PyTuple(PyObject o) /// public PyTuple() { - obj = Runtime.PyTuple_New(0); + obj = Runtime.Interop.PyTuple_New(0); Runtime.CheckExceptionOccurred(); } @@ -67,12 +67,12 @@ public PyTuple() public PyTuple(PyObject[] items) { int count = items.Length; - obj = Runtime.PyTuple_New(count); + obj = Runtime.Interop.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.Interop.PyTuple_SetItem(obj, i, ptr); Runtime.CheckExceptionOccurred(); } } @@ -100,7 +100,7 @@ public static bool IsTupleType(PyObject value) /// public static PyTuple AsTuple(PyObject value) { - IntPtr op = Runtime.PySequence_Tuple(value.obj); + IntPtr op = Runtime.Interop.PySequence_Tuple(value.obj); Runtime.CheckExceptionOccurred(); return new PyTuple(op); } diff --git a/src/runtime/runtime.cs b/src/runtime/runtime.cs index abd0661a4..64a8a1eca 100644 --- a/src/runtime/runtime.cs +++ b/src/runtime/runtime.cs @@ -5,104 +5,65 @@ namespace Python.Runtime { - [SuppressUnmanagedCodeSecurity] - internal static class NativeMethods + + + /// + /// 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 { -#if MONO_LINUX || MONO_OSX -#if NETSTANDARD - private static int RTLD_NOW = 0x2; -#if MONO_LINUX - private static int RTLD_GLOBAL = 0x100; - private static IntPtr RTLD_DEFAULT = IntPtr.Zero; - private const string NativeDll = "libdl.so"; - public static IntPtr LoadLibrary(string fileName) - { - return dlopen($"lib{fileName}.so", RTLD_NOW | RTLD_GLOBAL); - } -#elif MONO_OSX - private static int RTLD_GLOBAL = 0x8; - private const string NativeDll = "/usr/lib/libSystem.dylib" - private static IntPtr RTLD_DEFAULT = new IntPtr(-2); - public static IntPtr LoadLibrary(string fileName) + public static class OS { - return dlopen($"lib{fileName}.dylib", RTLD_NOW | RTLD_GLOBAL); - } -#endif + public static bool IsPosix { get { return !IsWindows; } } + public static bool IsLinux + { + get + { +#if NETSTANDARD || NETCOREAPP + return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux); #else - private static int RTLD_NOW = 0x2; - private static int RTLD_SHARED = 0x20; -#if MONO_OSX - private static IntPtr RTLD_DEFAULT = new IntPtr(-2); - private const string NativeDll = "__Internal"; -#elif MONO_LINUX - private static IntPtr RTLD_DEFAULT = IntPtr.Zero; - private const string NativeDll = "libdl.so"; -#endif - - public static IntPtr LoadLibrary(string fileName) - { - return dlopen(fileName, RTLD_NOW | RTLD_SHARED); - } + return System.Environment.OSVersion.Platform == PlatformID.Unix; #endif + } + } - - public static void FreeLibrary(IntPtr handle) - { - dlclose(handle); - } - - public static IntPtr GetProcAddress(IntPtr dllHandle, string name) - { - // look in the exe if dllHandle is NULL - if (dllHandle == IntPtr.Zero) + public static bool IsOSX { - dllHandle = RTLD_DEFAULT; + get + { +#if NETSTANDARD || NETCOREAPP + return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX); +#else + return System.Environment.OSVersion.Platform == PlatformID.MacOSX; +#endif + } } - - // clear previous errors if any - dlerror(); - IntPtr res = dlsym(dllHandle, name); - IntPtr errPtr = dlerror(); - if (errPtr != IntPtr.Zero) + public static bool IsWindows { - throw new Exception("dlsym: " + Marshal.PtrToStringAnsi(errPtr)); + get + { +#if NETSTANDARD || NETCOREAPP + return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows); +#else + return System.Environment.OSVersion.Platform == PlatformID.Win32NT; +#endif + } + } - return res; } - [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern IntPtr dlopen(String fileName, int flags); + public static IInterop Interop; - [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - private static extern IntPtr dlsym(IntPtr handle, String symbol); - - [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)] - private static extern int dlclose(IntPtr handle); - - [DllImport(NativeDll, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr dlerror(); -#else // Windows - private const string NativeDll = "kernel32.dll"; - - [DllImport(NativeDll)] - public static extern IntPtr LoadLibrary(string dllToLoad); - - [DllImport(NativeDll)] - public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); - - [DllImport(NativeDll)] - public static extern bool FreeLibrary(IntPtr hModule); -#endif - } - - /// - /// 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 - { + static Runtime() + { + if (OS.IsPosix) + Interop = new InteropPosix(); + else + Interop = new InteropWindows(); + } // 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. @@ -158,34 +119,11 @@ public class Runtime #error You must define one of PYTHON33 to PYTHON37 or PYTHON27 #endif -#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 - -#if PYTHON_WITH_PYDEBUG - internal const string dllWithPyDebug = "d"; -#else - internal const string dllWithPyDebug = ""; -#endif -#if PYTHON_WITH_PYMALLOC - internal const string dllWithPyMalloc = "m"; -#else - internal const string 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. - public static readonly string PythonDLL = _PythonDll; - -#if PYTHON_WITHOUT_ENABLE_SHARED && !NETSTANDARD - internal const string _PythonDll = "__Internal"; -#else - internal const string _PythonDll = dllBase + dllWithPyDebug + dllWithPyMalloc; -#endif public static readonly int pyversionnumber = Convert.ToInt32(_pyver); @@ -211,41 +149,41 @@ public class Runtime /// internal static void Initialize() { - if (Py_IsInitialized() == 0) + if (Interop.Py_IsInitialized() == 0) { - Py_Initialize(); + Interop.Py_Initialize(); } - if (PyEval_ThreadsInitialized() == 0) + if (Interop.PyEval_ThreadsInitialized() == 0) { - PyEval_InitThreads(); + Interop.PyEval_InitThreads(); } IntPtr op; IntPtr dict; if (IsPython3) { - op = PyImport_ImportModule("builtins"); - dict = PyObject_GetAttrString(op, "__dict__"); + op = Interop.PyImport_ImportModule("builtins"); + dict = Interop.PyObject_GetAttrString(op, "__dict__"); } else // Python2 { - dict = PyImport_GetModuleDict(); - op = PyDict_GetItemString(dict, "__builtin__"); + dict = Interop.PyImport_GetModuleDict(); + op = Interop.PyDict_GetItemString(dict, "__builtin__"); } - PyNotImplemented = PyObject_GetAttrString(op, "NotImplemented"); - PyBaseObjectType = PyObject_GetAttrString(op, "object"); + PyNotImplemented = Interop.PyObject_GetAttrString(op, "NotImplemented"); + PyBaseObjectType = Interop.PyObject_GetAttrString(op, "object"); PyModuleType = PyObject_Type(op); - PyNone = PyObject_GetAttrString(op, "None"); - PyTrue = PyObject_GetAttrString(op, "True"); - PyFalse = PyObject_GetAttrString(op, "False"); + PyNone = Interop.PyObject_GetAttrString(op, "None"); + PyTrue = Interop.PyObject_GetAttrString(op, "True"); + PyFalse = Interop.PyObject_GetAttrString(op, "False"); PyBoolType = PyObject_Type(PyTrue); PyNoneType = PyObject_Type(PyNone); PyTypeType = PyObject_Type(PyNoneType); - op = PyObject_GetAttrString(dict, "keys"); + op = Interop.PyObject_GetAttrString(dict, "keys"); PyMethodType = PyObject_Type(op); XDecref(op); @@ -253,7 +191,7 @@ internal static void Initialize() // a wrapper_descriptor, even though dict.__setitem__ is. // // object.__init__ seems safe, though. - op = PyObject_GetAttrString(PyBaseObjectType, "__init__"); + op = Interop.PyObject_GetAttrString(PyBaseObjectType, "__init__"); PyWrapperDescriptorType = PyObject_Type(op); XDecref(op); @@ -270,20 +208,20 @@ internal static void Initialize() XDecref(op); #if PYTHON3 - op = PyBytes_FromString("bytes"); + op = Interop.PyBytes_FromString("bytes"); PyBytesType = PyObject_Type(op); XDecref(op); #endif - op = PyTuple_New(0); + op = Interop.PyTuple_New(0); PyTupleType = PyObject_Type(op); XDecref(op); - op = PyList_New(0); + op = Interop.PyList_New(0); PyListType = PyObject_Type(op); XDecref(op); - op = PyDict_New(); + op = Interop.PyDict_New(); PyDictType = PyObject_Type(op); XDecref(op); @@ -291,11 +229,11 @@ internal static void Initialize() PyIntType = PyObject_Type(op); XDecref(op); - op = PyLong_FromLong(0); + op = Interop.PyLong_FromLong(0); PyLongType = PyObject_Type(op); XDecref(op); - op = PyFloat_FromDouble(0); + op = Interop.PyFloat_FromDouble(0); PyFloatType = PyObject_Type(op); XDecref(op); @@ -303,14 +241,14 @@ internal static void Initialize() PyClassType = IntPtr.Zero; PyInstanceType = IntPtr.Zero; #elif PYTHON2 - IntPtr s = PyString_FromString("_temp"); - IntPtr d = PyDict_New(); + IntPtr s = Interop.PyString_FromString("_temp"); + IntPtr d = Interop.PyDict_New(); - IntPtr c = PyClass_New(IntPtr.Zero, d, s); - PyClassType = PyObject_Type(c); + IntPtr c = Interop.PyClass_New(IntPtr.Zero, d, s); + PyClassType = Interop.PyObject_Type(c); - IntPtr i = PyInstance_New(c, IntPtr.Zero, IntPtr.Zero); - PyInstanceType = PyObject_Type(i); + IntPtr i = Interop.PyInstance_New(c, IntPtr.Zero, IntPtr.Zero); + PyInstanceType = Interop.PyObject_Type(i); XDecref(s); XDecref(i); @@ -322,18 +260,29 @@ internal static void Initialize() IntPtr dllLocal = IntPtr.Zero; - if (_PythonDll != "__Internal") + if (Interop.GetDllName() != "__Internal") { - dllLocal = NativeMethods.LoadLibrary(_PythonDll); + if (OS.IsLinux) + dllLocal = NativeMethods_Linux.LoadLibrary(Interop.GetDllName()); + else if (OS.IsOSX) + dllLocal = NativeMethods_OSX.LoadLibrary(Interop.GetDllName()); + else if (OS.IsWindows) + dllLocal = NativeMethods_Windows.LoadLibrary(Interop.GetDllName()); } - _PyObject_NextNotImplemented = NativeMethods.GetProcAddress(dllLocal, "_PyObject_NextNotImplemented"); -#if !(MONO_LINUX || MONO_OSX) - if (dllLocal != IntPtr.Zero) + if (OS.IsLinux) + _PyObject_NextNotImplemented = NativeMethods_Linux.GetProcAddress(dllLocal, "_PyObject_NextNotImplemented"); + else if (OS.IsOSX) + _PyObject_NextNotImplemented = NativeMethods_OSX.GetProcAddress(dllLocal, "_PyObject_NextNotImplemented"); + else if (OS.IsWindows) + _PyObject_NextNotImplemented = NativeMethods_Windows.GetProcAddress(dllLocal, "_PyObject_NextNotImplemented"); + + + + if (OS.IsWindows && dllLocal != IntPtr.Zero) { - NativeMethods.FreeLibrary(dllLocal); + NativeMethods_Windows.FreeLibrary(dllLocal); } -#endif // Initialize modules that depend on the runtime class. AssemblyManager.Initialize(); @@ -344,19 +293,23 @@ internal static void Initialize() // Need to add the runtime directory to sys.path so that we // can find built-in assemblies like System.Data, et. al. string rtdir = RuntimeEnvironment.GetRuntimeDirectory(); - IntPtr path = PySys_GetObject("path"); + IntPtr path = Interop.PySys_GetObject("path"); IntPtr item = PyString_FromString(rtdir); - PyList_Append(path, item); + Interop.PyList_Append(path, item); XDecref(item); AssemblyManager.UpdatePath(); } + internal static IntPtr PyBytes_AS_STRING(IntPtr ob) + { + return ob + BytesOffset.ob_sval; + } internal static void Shutdown() { AssemblyManager.Shutdown(); Exceptions.Shutdown(); ImportHook.Shutdown(); - Py_Finalize(); + Interop.Py_Finalize(); } // called *without* the GIL acquired by clr._AtExit @@ -420,7 +373,7 @@ internal static int AtExit() /// internal static void CheckExceptionOccurred() { - if (PyErr_Occurred() != 0) + if (Interop.PyErr_Occurred() != 0) { throw new PythonException(); } @@ -428,23 +381,23 @@ internal static void CheckExceptionOccurred() internal static IntPtr ExtendTuple(IntPtr t, params IntPtr[] args) { - int size = PyTuple_Size(t); + int size = Interop.PyTuple_Size(t); int add = args.Length; IntPtr item; - IntPtr items = PyTuple_New(size + add); + IntPtr items = Interop.PyTuple_New(size + add); for (var i = 0; i < size; i++) { - item = PyTuple_GetItem(t, i); + item = Interop.PyTuple_GetItem(t, i); XIncref(item); - PyTuple_SetItem(items, i, item); + Interop.PyTuple_SetItem(items, i, item); } for (var n = 0; n < add; n++) { item = args[n]; XIncref(item); - PyTuple_SetItem(items, size + n, item); + Interop.PyTuple_SetItem(items, size + n, item); } return items; @@ -465,19 +418,19 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects) if (!PyTuple_Check(arg)) { - args = PyTuple_New(1); + args = Interop.PyTuple_New(1); XIncref(arg); - PyTuple_SetItem(args, 0, arg); + Interop.PyTuple_SetItem(args, 0, arg); free = true; } - int n = PyTuple_Size(args); + int n = Interop.PyTuple_Size(args); var types = new Type[n]; Type t = null; for (var i = 0; i < n; i++) { - IntPtr op = PyTuple_GetItem(args, i); + IntPtr op = Interop.PyTuple_GetItem(args, i); if (mangleObjects && (!PyType_Check(op))) { op = PyObject_TYPE(op); @@ -522,8 +475,8 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects) /// internal static unsafe void XIncref(IntPtr op) { -#if PYTHON_WITH_PYDEBUG || NETSTANDARD - Py_IncRef(op); +#if PYTHON_WITH_PYDEBUG || NETSTANDARD || NETCOREAPP + Interop.Py_IncRef(op); return; #else var p = (void*)op; @@ -543,8 +496,8 @@ internal static unsafe void XIncref(IntPtr op) internal static unsafe void XDecref(IntPtr op) { -#if PYTHON_WITH_PYDEBUG || NETSTANDARD - Py_DecRef(op); +#if PYTHON_WITH_PYDEBUG || NETSTANDARD || NETCOREAPP + Interop.Py_DecRef(op); return; #else var p = (void*)op; @@ -588,174 +541,7 @@ internal static unsafe long Refcount(IntPtr op) return Is32Bit ? (*(int*)p) : (*(long*)p); } - /// - /// Export of Macro Py_XIncRef. Use XIncref instead. - /// 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); - - /// - /// 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); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void Py_Initialize(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int Py_IsInitialized(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void Py_Finalize(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_NewInterpreter(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void Py_EndInterpreter(IntPtr threadState); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyThreadState_New(IntPtr istate); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyThreadState_Get(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyThread_get_key_value(IntPtr key); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyThread_get_thread_ident(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyThread_set_key_value(IntPtr key, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyThreadState_Swap(IntPtr key); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyGILState_Ensure(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyGILState_Release(IntPtr gs); - - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyGILState_GetThisThreadState(); - -#if PYTHON3 - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - public static extern 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 - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyEval_InitThreads(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyEval_ThreadsInitialized(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyEval_AcquireLock(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyEval_ReleaseLock(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyEval_AcquireThread(IntPtr tstate); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyEval_ReleaseThread(IntPtr tstate); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyEval_SaveThread(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyEval_RestoreThread(IntPtr tstate); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyEval_GetBuiltins(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyEval_GetGlobals(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyEval_GetLocals(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_GetProgramName(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void Py_SetProgramName(IntPtr name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_GetPythonHome(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void Py_SetPythonHome(IntPtr home); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_GetPath(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void Py_SetPath(IntPtr home); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_GetVersion(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_GetPlatform(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_GetCopyright(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_GetCompiler(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_GetBuildInfo(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyRun_SimpleString(string code); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr Py_CompileString(string code, string file, IntPtr tok); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyImport_ExecCodeModule(string name, IntPtr code); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyClass_New(IntPtr bases, IntPtr dict, IntPtr name); - - [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); + //==================================================================== @@ -818,62 +604,23 @@ internal static bool PyObject_IsIterable(IntPtr pointer) return tp_iter != IntPtr.Zero; } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_HasAttrString(IntPtr pointer, string name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_GetAttrString(IntPtr pointer, string name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_HasAttr(IntPtr pointer, IntPtr name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_GetItem(IntPtr pointer, IntPtr key); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_DelItem(IntPtr pointer, IntPtr key); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_GetIter(IntPtr op); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args); - -#if PYTHON3 - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid); - + internal static int PyObject_Compare(IntPtr value1, IntPtr value2) { int res; - res = PyObject_RichCompareBool(value1, value2, Py_LT); + res = Interop.PyObject_RichCompareBool(value1, value2, Py_LT); if (-1 == res) return -1; else if (1 == res) return -1; - res = PyObject_RichCompareBool(value1, value2, Py_EQ); + res = Interop.PyObject_RichCompareBool(value1, value2, Py_EQ); if (-1 == res) return -1; else if (1 == res) return 0; - res = PyObject_RichCompareBool(value1, value2, Py_GT); + res = Interop.PyObject_RichCompareBool(value1, value2, Py_GT); if (-1 == res) return -1; else if (1 == res) @@ -882,72 +629,7 @@ 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); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_IsSubclass(IntPtr ob, IntPtr type); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyCallable_Check(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_IsTrue(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_Not(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_Size(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_Hash(IntPtr op); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_Repr(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_Str(IntPtr 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 - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_Dir(IntPtr pointer); - - - //==================================================================== - // 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 - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Long(IntPtr ob); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Float(IntPtr ob); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern bool PyNumber_Check(IntPtr ob); internal static bool PyInt_Check(IntPtr ob) { @@ -962,219 +644,25 @@ internal static bool PyBool_Check(IntPtr ob) internal static IntPtr PyInt_FromInt32(int value) { var v = new IntPtr(value); - return PyInt_FromLong(v); + return Interop.PyInt_FromLong(v); } internal static IntPtr PyInt_FromInt64(long value) { var v = new IntPtr(value); - return PyInt_FromLong(v); + return Interop.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); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, - EntryPoint = "PyLong_GetMax")] - internal static extern int PyInt_GetMax(); -#elif PYTHON2 - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr PyInt_FromLong(IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyInt_AsLong(IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyInt_FromString(string value, IntPtr end, int 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)] - internal static extern IntPtr PyLong_FromUnsignedLong(uint value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyLong_FromDouble(double value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyLong_FromLongLong(long value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyLong_FromUnsignedLongLong(ulong value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyLong_FromString(string value, IntPtr end, int radix); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyLong_AsLong(IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern uint PyLong_AsUnsignedLong(IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern long PyLong_AsLongLong(IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern ulong PyLong_AsUnsignedLongLong(IntPtr 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); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyFloat_FromString(IntPtr value, IntPtr junk); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern double PyFloat_AsDouble(IntPtr ob); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Add(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Divide(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_And(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Or(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Power(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceDivide(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Negative(IntPtr o1); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Positive(IntPtr o1); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyNumber_Invert(IntPtr o1); - - - //==================================================================== - // Python sequence API - //==================================================================== - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern bool PySequence_Check(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PySequence_GetItem(IntPtr pointer, int index); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PySequence_SetItem(IntPtr pointer, int index, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PySequence_DelItem(IntPtr pointer, int index); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PySequence_GetSlice(IntPtr pointer, int i1, int i2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PySequence_SetSlice(IntPtr pointer, int i1, int i2, IntPtr v); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PySequence_DelSlice(IntPtr pointer, int i1, int i2); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PySequence_Size(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PySequence_Contains(IntPtr pointer, IntPtr item); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PySequence_Concat(IntPtr pointer, IntPtr other); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PySequence_Repeat(IntPtr pointer, int count); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PySequence_Index(IntPtr pointer, IntPtr item); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PySequence_Count(IntPtr pointer, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PySequence_Tuple(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PySequence_List(IntPtr pointer); - //==================================================================== // Python string API @@ -1193,102 +681,19 @@ internal static bool PyString_Check(IntPtr ob) internal static IntPtr PyString_FromString(string value) { - return PyString_FromStringAndSize(value, value.Length); - } - -#if PYTHON3 - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyBytes_FromString(string op); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyBytes_Size(IntPtr op); - - internal static IntPtr PyBytes_AS_STRING(IntPtr ob) - { - return ob + BytesOffset.ob_sval; + return Interop.PyString_FromStringAndSize(value, value.Length); } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, - EntryPoint = "PyUnicode_FromStringAndSize")] - internal static extern IntPtr PyString_FromStringAndSize( - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value, - int size - ); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyUnicode_FromStringAndSize(IntPtr value, int size); -#elif PYTHON2 - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyString_FromStringAndSize(string value, int size); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyString_AsString(IntPtr op); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyString_Size(IntPtr pointer); -#endif - 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); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyUnicode_FromKindAndData( - int kind, - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s, - int size - ); - internal static IntPtr PyUnicode_FromUnicode(string s, int size) { - return PyUnicode_FromKindAndData(_UCS, s, size); + return Interop.PyUnicode_FromKindAndData(_UCS, s, size); } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int 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); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, - EntryPoint = PyUnicodeEntryPoint + "FromUnicode")] - internal static extern IntPtr PyUnicode_FromUnicode( - [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s, - int size - ); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, - EntryPoint = PyUnicodeEntryPoint + "GetSize")] - internal static extern int PyUnicode_GetSize(IntPtr ob); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, - EntryPoint = PyUnicodeEntryPoint + "AsUnicode")] - internal static extern IntPtr PyUnicode_AsUnicode(IntPtr ob); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, - EntryPoint = PyUnicodeEntryPoint + "FromOrdinal")] - internal static extern IntPtr PyUnicode_FromOrdinal(int c); -#endif - internal static IntPtr PyUnicode_FromString(string s) { return PyUnicode_FromUnicode(s, s.Length); @@ -1320,8 +725,8 @@ internal static string GetManagedString(IntPtr op) if (type == PyUnicodeType) { - IntPtr p = PyUnicode_AsUnicode(op); - int length = PyUnicode_GetSize(op); + IntPtr p = Interop.PyUnicode_AsUnicode(op); + int length = Interop.PyUnicode_GetSize(op); int size = length * _UCS; var buffer = new byte[size]; @@ -1342,53 +747,6 @@ internal static bool PyDict_Check(IntPtr ob) return PyObject_TYPE(ob) == PyDictType; } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyDict_New(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyDictProxy_New(IntPtr dict); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyDict_GetItemString(IntPtr pointer, string key); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value); - - [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); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyDict_DelItemString(IntPtr pointer, string key); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyMapping_HasKey(IntPtr pointer, IntPtr key); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyDict_Keys(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyDict_Values(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyDict_Items(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyDict_Copy(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyDict_Update(IntPtr pointer, IntPtr other); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyDict_Clear(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyDict_Size(IntPtr pointer); //==================================================================== @@ -1399,41 +757,6 @@ internal static bool PyList_Check(IntPtr ob) { return PyObject_TYPE(ob) == PyListType; } - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyList_New(int size); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyList_AsTuple(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyList_GetItem(IntPtr pointer, int index); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyList_SetItem(IntPtr pointer, int index, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyList_Insert(IntPtr pointer, int index, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyList_Append(IntPtr pointer, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyList_Reverse(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyList_Sort(IntPtr pointer); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyList_GetSlice(IntPtr pointer, int start, int end); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyList_SetSlice(IntPtr pointer, int start, int end, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyList_Size(IntPtr pointer); - - //==================================================================== // Python tuple API //==================================================================== @@ -1443,22 +766,6 @@ internal static bool PyTuple_Check(IntPtr ob) return PyObject_TYPE(ob) == PyTupleType; } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyTuple_New(int size); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyTuple_GetItem(IntPtr pointer, int index); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyTuple_SetItem(IntPtr pointer, int index, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyTuple_GetSlice(IntPtr pointer, int start, int end); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyTuple_Size(IntPtr pointer); - - //==================================================================== // Python iterator API //==================================================================== @@ -1475,187 +782,16 @@ internal static bool PyIter_Check(IntPtr pointer) return tp_iternext != IntPtr.Zero && tp_iternext != _PyObject_NextNotImplemented; } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyIter_Next(IntPtr pointer); - - - //==================================================================== - // Python module API - //==================================================================== - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyModule_New(string name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern string PyModule_GetName(IntPtr 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); - -#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); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyImport_ImportModule(string name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyImport_ReloadModule(IntPtr module); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyImport_AddModule(string name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyImport_GetModuleDict(); - -#if PYTHON3 - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern 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 - - [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); - - - //==================================================================== - // Python type object API - //==================================================================== internal static bool PyType_Check(IntPtr ob) { return PyObject_TypeCheck(ob, PyTypeType); } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyType_Modified(IntPtr type); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern bool PyType_IsSubtype(IntPtr t1, IntPtr t2); - internal static bool PyObject_TypeCheck(IntPtr ob, IntPtr tp) { IntPtr t = PyObject_TYPE(ob); - return (t == tp) || PyType_IsSubtype(t, tp); + return (t == tp) || Interop.PyType_IsSubtype(t, tp); } - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyType_GenericAlloc(IntPtr type, int n); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyType_Ready(IntPtr type); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr _PyType_Lookup(IntPtr type, IntPtr name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr _PyObject_GetDictPtr(IntPtr obj); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyObject_GC_New(IntPtr 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); - - - //==================================================================== - // Python memory API - //==================================================================== - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyMem_Malloc(int size); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyMem_Realloc(IntPtr ptr, int size); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyMem_Free(IntPtr ptr); - - - //==================================================================== - // Python exception API - //==================================================================== - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyErr_SetString(IntPtr ob, string message); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyErr_SetObject(IntPtr ob, IntPtr message); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyErr_SetFromErrno(IntPtr ob); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyErr_SetNone(IntPtr ob); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyErr_ExceptionMatches(IntPtr exception); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyErr_Occurred(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyErr_Fetch(ref IntPtr ob, ref IntPtr val, ref IntPtr tb); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyErr_Clear(); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern void PyErr_Print(); - - - //==================================================================== - // Miscellaneous - //==================================================================== - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyMethod_Self(IntPtr ob); - - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr PyMethod_Function(IntPtr ob); } } diff --git a/src/runtime/runtime_posix.cs b/src/runtime/runtime_posix.cs new file mode 100644 index 000000000..2fd15f7ef --- /dev/null +++ b/src/runtime/runtime_posix.cs @@ -0,0 +1,861 @@ +using System; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +namespace Python.Runtime +{ + public class Runtime_Posix + { +#if PYTHON27 + internal const string _pyversion = "2.7"; + internal const string _pyver = "27"; +#elif PYTHON33 + internal const string _pyversion = "3.3"; + internal const string _pyver = "33"; +#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 // TODO: Add `interop37.cs` after PY37 is released + internal const string _pyversion = "3.7"; + internal const string _pyver = "37"; +#else +#error You must define one of PYTHON33 to PYTHON37 or PYTHON27 +#endif + + internal const string dllBase = "python" + _pyversion; + +#if PYTHON_WITH_PYDEBUG + internal const string dllWithPyDebug = "d"; +#else + internal const string dllWithPyDebug = ""; +#endif +#if PYTHON_WITH_PYMALLOC + internal const string dllWithPyMalloc = "m"; +#else + internal const string dllWithPyMalloc = ""; +#endif + +#if PYTHON_WITHOUT_ENABLE_SHARED && !(NETSTANDARD || NETCOREAPP) + internal const string _PythonDll = "__Internal"; +#else + internal const string _PythonDll = dllBase + dllWithPyDebug + dllWithPyMalloc; +#endif + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_IncRef(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_DecRef(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_Initialize(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int Py_IsInitialized(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_Finalize(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_NewInterpreter(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_EndInterpreter(IntPtr threadState); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyThreadState_New(IntPtr istate); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyThreadState_Get(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyThread_get_key_value(IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyThread_get_thread_ident(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyThread_set_key_value(IntPtr key, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyThreadState_Swap(IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyGILState_Ensure(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyGILState_Release(IntPtr gs); + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyGILState_GetThisThreadState(); + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + public static extern 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 + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_InitThreads(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyEval_ThreadsInitialized(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_AcquireLock(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_ReleaseLock(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_AcquireThread(IntPtr tstate); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_ReleaseThread(IntPtr tstate); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_SaveThread(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_RestoreThread(IntPtr tstate); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_GetBuiltins(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_GetGlobals(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_GetLocals(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetProgramName(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_SetProgramName(IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetPythonHome(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_SetPythonHome(IntPtr home); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetPath(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_SetPath(IntPtr home); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetVersion(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetPlatform(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetCopyright(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetCompiler(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetBuildInfo(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyRun_SimpleString(string code); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_CompileString(string code, string file, IntPtr tok); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_ExecCodeModule(string name, IntPtr code); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyClass_New(IntPtr bases, IntPtr dict, IntPtr name); + + [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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_HasAttrString(IntPtr pointer, string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GetAttrString(IntPtr pointer, string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_HasAttr(IntPtr pointer, IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GetItem(IntPtr pointer, IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_DelItem(IntPtr pointer, IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GetIter(IntPtr op); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args); + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid); + +#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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_IsSubclass(IntPtr ob, IntPtr type); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyCallable_Check(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_IsTrue(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_Not(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_Size(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Hash(IntPtr op); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Repr(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Str(IntPtr 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 + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Dir(IntPtr pointer); + + + //==================================================================== + // 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 + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Long(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Float(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern bool PyNumber_Check(IntPtr ob); + + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = "PyLong_FromLong")] + internal 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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = "PyLong_GetMax")] + internal static extern int PyInt_GetMax(); +#elif PYTHON2 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyInt_FromLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyInt_AsLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyInt_FromString(string value, IntPtr end, int radix); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyInt_GetMax(); +#endif + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromLong(long value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromUnsignedLong(uint value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromDouble(double value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromLongLong(long value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromUnsignedLongLong(ulong value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromString(string value, IntPtr end, int radix); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyLong_AsLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern uint PyLong_AsUnsignedLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern long PyLong_AsLongLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern ulong PyLong_AsUnsignedLongLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyFloat_FromDouble(double value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyFloat_FromString(IntPtr value, IntPtr junk); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern double PyFloat_AsDouble(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Add(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Divide(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_And(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Or(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Power(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceDivide(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Negative(IntPtr o1); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Positive(IntPtr o1); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Invert(IntPtr o1); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern bool PySequence_Check(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_GetItem(IntPtr pointer, int index); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_SetItem(IntPtr pointer, int index, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_DelItem(IntPtr pointer, int index); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_GetSlice(IntPtr pointer, int i1, int i2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_SetSlice(IntPtr pointer, int i1, int i2, IntPtr v); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_DelSlice(IntPtr pointer, int i1, int i2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_Size(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_Contains(IntPtr pointer, IntPtr item); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_Concat(IntPtr pointer, IntPtr other); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_Repeat(IntPtr pointer, int count); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_Index(IntPtr pointer, IntPtr item); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_Count(IntPtr pointer, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_Tuple(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_List(IntPtr pointer); + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyBytes_FromString(string op); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyBytes_Size(IntPtr op); + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = "PyUnicode_FromStringAndSize")] + internal static extern IntPtr PyString_FromStringAndSize( + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value, + int size + ); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyUnicode_FromStringAndSize(IntPtr value, int size); +#elif PYTHON2 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyString_FromStringAndSize(string value, int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyString_AsString(IntPtr op); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyString_Size(IntPtr pointer); +#endif + + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyUnicode_FromObject(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyUnicode_FromKindAndData( + int kind, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s, + int size + ); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int 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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = PyUnicodeEntryPoint + "FromUnicode")] + internal static extern IntPtr PyUnicode_FromUnicode( + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s, + int size + ); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = PyUnicodeEntryPoint + "GetSize")] + internal static extern int PyUnicode_GetSize(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = PyUnicodeEntryPoint + "AsUnicode")] + internal static extern IntPtr PyUnicode_AsUnicode(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = PyUnicodeEntryPoint + "FromOrdinal")] + internal static extern IntPtr PyUnicode_FromOrdinal(int c); +#endif + + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_New(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDictProxy_New(IntPtr dict); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_GetItemString(IntPtr pointer, string key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value); + + [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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyDict_DelItemString(IntPtr pointer, string key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyMapping_HasKey(IntPtr pointer, IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_Keys(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_Values(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_Items(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_Copy(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyDict_Update(IntPtr pointer, IntPtr other); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyDict_Clear(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyDict_Size(IntPtr pointer); + + + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyList_New(int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyList_AsTuple(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyList_GetItem(IntPtr pointer, int index); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_SetItem(IntPtr pointer, int index, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Insert(IntPtr pointer, int index, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Append(IntPtr pointer, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Reverse(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Sort(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyList_GetSlice(IntPtr pointer, int start, int end); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_SetSlice(IntPtr pointer, int start, int end, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Size(IntPtr pointer); + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyTuple_New(int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyTuple_GetItem(IntPtr pointer, int index); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyTuple_SetItem(IntPtr pointer, int index, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyTuple_GetSlice(IntPtr pointer, int start, int end); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyTuple_Size(IntPtr pointer); + + + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyIter_Next(IntPtr pointer); + + + //==================================================================== + // Python module API + //==================================================================== + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyModule_New(string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern string PyModule_GetName(IntPtr 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); + +#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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_ImportModule(string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_ReloadModule(IntPtr module); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_AddModule(string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_GetModuleDict(); + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern 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 + + [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); + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyType_Modified(IntPtr type); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern bool PyType_IsSubtype(IntPtr t1, IntPtr t2); + + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyType_GenericAlloc(IntPtr type, int n); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyType_Ready(IntPtr type); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr _PyType_Lookup(IntPtr type, IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr _PyObject_GetDictPtr(IntPtr obj); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GC_New(IntPtr 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); + + + //==================================================================== + // Python memory API + //==================================================================== + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyMem_Malloc(int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyMem_Realloc(IntPtr ptr, int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyMem_Free(IntPtr ptr); + + + //==================================================================== + // Python exception API + //==================================================================== + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_SetString(IntPtr ob, string message); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_SetObject(IntPtr ob, IntPtr message); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyErr_SetFromErrno(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_SetNone(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyErr_ExceptionMatches(IntPtr exception); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyErr_Occurred(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_Fetch(ref IntPtr ob, ref IntPtr val, ref IntPtr tb); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_Clear(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_Print(); + + + //==================================================================== + // Miscellaneous + //==================================================================== + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyMethod_Self(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyMethod_Function(IntPtr ob); + } +} diff --git a/src/runtime/runtime_windows.cs b/src/runtime/runtime_windows.cs new file mode 100644 index 000000000..80b0be77e --- /dev/null +++ b/src/runtime/runtime_windows.cs @@ -0,0 +1,861 @@ +using System; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +namespace Python.Runtime +{ + public class Runtime_Windows + { +#if PYTHON27 + internal const string _pyversion = "2.7"; + internal const string _pyver = "27"; +#elif PYTHON33 + internal const string _pyversion = "3.3"; + internal const string _pyver = "33"; +#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 // TODO: Add `interop37.cs` after PY37 is released + internal const string _pyversion = "3.7"; + internal const string _pyver = "37"; +#else +#error You must define one of PYTHON33 to PYTHON37 or PYTHON27 +#endif + + internal const string dllBase = "python" + _pyver; + +#if PYTHON_WITH_PYDEBUG + internal const string dllWithPyDebug = "d"; +#else + internal const string dllWithPyDebug = ""; +#endif +#if PYTHON_WITH_PYMALLOC + internal const string dllWithPyMalloc = "m"; +#else + internal const string dllWithPyMalloc = ""; +#endif + +#if PYTHON_WITHOUT_ENABLE_SHARED && !(NETSTANDARD || NETCOREAPP) + internal const string _PythonDll = "__Internal"; +#else + internal const string _PythonDll = dllBase + dllWithPyDebug + dllWithPyMalloc; +#endif + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_IncRef(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_DecRef(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_Initialize(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int Py_IsInitialized(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_Finalize(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_NewInterpreter(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_EndInterpreter(IntPtr threadState); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyThreadState_New(IntPtr istate); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyThreadState_Get(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyThread_get_key_value(IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyThread_get_thread_ident(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyThread_set_key_value(IntPtr key, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyThreadState_Swap(IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyGILState_Ensure(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyGILState_Release(IntPtr gs); + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyGILState_GetThisThreadState(); + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + public static extern 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 + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_InitThreads(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyEval_ThreadsInitialized(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_AcquireLock(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_ReleaseLock(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_AcquireThread(IntPtr tstate); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_ReleaseThread(IntPtr tstate); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_SaveThread(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyEval_RestoreThread(IntPtr tstate); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_GetBuiltins(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_GetGlobals(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_GetLocals(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetProgramName(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_SetProgramName(IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetPythonHome(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_SetPythonHome(IntPtr home); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetPath(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void Py_SetPath(IntPtr home); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetVersion(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetPlatform(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetCopyright(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetCompiler(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_GetBuildInfo(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyRun_SimpleString(string code); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr Py_CompileString(string code, string file, IntPtr tok); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_ExecCodeModule(string name, IntPtr code); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyClass_New(IntPtr bases, IntPtr dict, IntPtr name); + + [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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_HasAttrString(IntPtr pointer, string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GetAttrString(IntPtr pointer, string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_HasAttr(IntPtr pointer, IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GetItem(IntPtr pointer, IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_DelItem(IntPtr pointer, IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GetIter(IntPtr op); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args); + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid); + +#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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_IsSubclass(IntPtr ob, IntPtr type); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyCallable_Check(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_IsTrue(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_Not(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_Size(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Hash(IntPtr op); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Repr(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Str(IntPtr 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 + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_Dir(IntPtr pointer); + + + //==================================================================== + // 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 + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Long(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Float(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern bool PyNumber_Check(IntPtr ob); + + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = "PyLong_FromLong")] + internal 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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = "PyLong_GetMax")] + internal static extern int PyInt_GetMax(); +#elif PYTHON2 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyInt_FromLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyInt_AsLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyInt_FromString(string value, IntPtr end, int radix); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyInt_GetMax(); +#endif + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromLong(long value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromUnsignedLong(uint value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromDouble(double value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromLongLong(long value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromUnsignedLongLong(ulong value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyLong_FromString(string value, IntPtr end, int radix); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyLong_AsLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern uint PyLong_AsUnsignedLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern long PyLong_AsLongLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern ulong PyLong_AsUnsignedLongLong(IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyFloat_FromDouble(double value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyFloat_FromString(IntPtr value, IntPtr junk); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern double PyFloat_AsDouble(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Add(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Divide(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_And(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Or(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Power(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceDivide(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Negative(IntPtr o1); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Positive(IntPtr o1); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyNumber_Invert(IntPtr o1); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern bool PySequence_Check(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_GetItem(IntPtr pointer, int index); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_SetItem(IntPtr pointer, int index, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_DelItem(IntPtr pointer, int index); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_GetSlice(IntPtr pointer, int i1, int i2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_SetSlice(IntPtr pointer, int i1, int i2, IntPtr v); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_DelSlice(IntPtr pointer, int i1, int i2); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_Size(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_Contains(IntPtr pointer, IntPtr item); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_Concat(IntPtr pointer, IntPtr other); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_Repeat(IntPtr pointer, int count); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_Index(IntPtr pointer, IntPtr item); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PySequence_Count(IntPtr pointer, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_Tuple(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PySequence_List(IntPtr pointer); + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyBytes_FromString(string op); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyBytes_Size(IntPtr op); + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = "PyUnicode_FromStringAndSize")] + internal static extern IntPtr PyString_FromStringAndSize( + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value, + int size + ); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyUnicode_FromStringAndSize(IntPtr value, int size); +#elif PYTHON2 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyString_FromStringAndSize(string value, int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyString_AsString(IntPtr op); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyString_Size(IntPtr pointer); +#endif + + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyUnicode_FromObject(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyUnicode_FromKindAndData( + int kind, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s, + int size + ); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int 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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = PyUnicodeEntryPoint + "FromUnicode")] + internal static extern IntPtr PyUnicode_FromUnicode( + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s, + int size + ); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = PyUnicodeEntryPoint + "GetSize")] + internal static extern int PyUnicode_GetSize(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = PyUnicodeEntryPoint + "AsUnicode")] + internal static extern IntPtr PyUnicode_AsUnicode(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, + EntryPoint = PyUnicodeEntryPoint + "FromOrdinal")] + internal static extern IntPtr PyUnicode_FromOrdinal(int c); +#endif + + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_New(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDictProxy_New(IntPtr dict); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_GetItemString(IntPtr pointer, string key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value); + + [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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyDict_DelItemString(IntPtr pointer, string key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyMapping_HasKey(IntPtr pointer, IntPtr key); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_Keys(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_Values(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_Items(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyDict_Copy(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyDict_Update(IntPtr pointer, IntPtr other); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyDict_Clear(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyDict_Size(IntPtr pointer); + + + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyList_New(int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyList_AsTuple(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyList_GetItem(IntPtr pointer, int index); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_SetItem(IntPtr pointer, int index, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Insert(IntPtr pointer, int index, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Append(IntPtr pointer, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Reverse(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Sort(IntPtr pointer); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyList_GetSlice(IntPtr pointer, int start, int end); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_SetSlice(IntPtr pointer, int start, int end, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyList_Size(IntPtr pointer); + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyTuple_New(int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyTuple_GetItem(IntPtr pointer, int index); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyTuple_SetItem(IntPtr pointer, int index, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyTuple_GetSlice(IntPtr pointer, int start, int end); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyTuple_Size(IntPtr pointer); + + + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyIter_Next(IntPtr pointer); + + + //==================================================================== + // Python module API + //==================================================================== + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyModule_New(string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern string PyModule_GetName(IntPtr 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); + +#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); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_ImportModule(string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_ReloadModule(IntPtr module); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_AddModule(string name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyImport_GetModuleDict(); + +#if PYTHON3 + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern 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 + + [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); + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyType_Modified(IntPtr type); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern bool PyType_IsSubtype(IntPtr t1, IntPtr t2); + + + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyType_GenericAlloc(IntPtr type, int n); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyType_Ready(IntPtr type); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr _PyType_Lookup(IntPtr type, IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr _PyObject_GetDictPtr(IntPtr obj); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyObject_GC_New(IntPtr 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); + + + //==================================================================== + // Python memory API + //==================================================================== + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyMem_Malloc(int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyMem_Realloc(IntPtr ptr, int size); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyMem_Free(IntPtr ptr); + + + //==================================================================== + // Python exception API + //==================================================================== + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_SetString(IntPtr ob, string message); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_SetObject(IntPtr ob, IntPtr message); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyErr_SetFromErrno(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_SetNone(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyErr_ExceptionMatches(IntPtr exception); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern int PyErr_Occurred(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_Fetch(ref IntPtr ob, ref IntPtr val, ref IntPtr tb); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_Clear(); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern void PyErr_Print(); + + + //==================================================================== + // Miscellaneous + //==================================================================== + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyMethod_Self(IntPtr ob); + + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr PyMethod_Function(IntPtr ob); + } +} diff --git a/src/runtime/typemanager.cs b/src/runtime/typemanager.cs index 6570ee083..08e10f53f 100644 --- a/src/runtime/typemanager.cs +++ b/src/runtime/typemanager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Reflection; @@ -88,11 +88,11 @@ internal static IntPtr CreateType(Type impl) TypeFlags.HeapType | TypeFlags.HaveGC; Util.WriteCLong(type, TypeOffset.tp_flags, flags); - Runtime.PyType_Ready(type); + Runtime.Interop.PyType_Ready(type); IntPtr dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict); IntPtr mod = Runtime.PyString_FromString("CLR"); - Runtime.PyDict_SetItemString(dict, "__module__", mod); + Runtime.Interop.PyDict_SetItemString(dict, "__module__", mod); InitMethods(type, impl); @@ -166,12 +166,12 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType) // that the type of the new type must PyType_Type at the time we // call this, else PyType_Ready will skip some slot initialization. - Runtime.PyType_Ready(type); + Runtime.Interop.PyType_Ready(type); IntPtr dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict); string mn = clrType.Namespace ?? ""; IntPtr mod = Runtime.PyString_FromString(mn); - Runtime.PyDict_SetItemString(dict, "__module__", mod); + Runtime.Interop.PyDict_SetItemString(dict, "__module__", mod); // Hide the gchandle of the implementation in a magic type slot. GCHandle gc = GCHandle.Alloc(impl); @@ -203,9 +203,9 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr { var assemblyKey = new PyObject(Converter.ToPython("__assembly__", typeof(string))); disposeList.Add(assemblyKey); - if (0 != Runtime.PyMapping_HasKey(py_dict, assemblyKey.Handle)) + if (0 != Runtime.Interop.PyMapping_HasKey(py_dict, assemblyKey.Handle)) { - var pyAssembly = new PyObject(Runtime.PyDict_GetItem(py_dict, assemblyKey.Handle)); + var pyAssembly = new PyObject(Runtime.Interop.PyDict_GetItem(py_dict, assemblyKey.Handle)); Runtime.XIncref(pyAssembly.Handle); disposeList.Add(pyAssembly); if (!Converter.ToManagedValue(pyAssembly.Handle, typeof(string), out assembly, false)) @@ -216,9 +216,9 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr var namespaceKey = new PyObject(Converter.ToPythonImplicit("__namespace__")); disposeList.Add(namespaceKey); - if (0 != Runtime.PyMapping_HasKey(py_dict, namespaceKey.Handle)) + if (0 != Runtime.Interop.PyMapping_HasKey(py_dict, namespaceKey.Handle)) { - var pyNamespace = new PyObject(Runtime.PyDict_GetItem(py_dict, namespaceKey.Handle)); + var pyNamespace = new PyObject(Runtime.Interop.PyDict_GetItem(py_dict, namespaceKey.Handle)); Runtime.XIncref(pyNamespace.Handle); disposeList.Add(pyNamespace); if (!Converter.ToManagedValue(pyNamespace.Handle, typeof(string), out namespaceStr, false)) @@ -257,7 +257,7 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr // by default the class dict will have all the C# methods in it, but as this is a // derived class we want the python overrides in there instead if they exist. IntPtr cls_dict = Marshal.ReadIntPtr(py_type, TypeOffset.tp_dict); - Runtime.PyDict_Update(cls_dict, py_dict); + Runtime.Interop.PyDict_Update(cls_dict, py_dict); return py_type; } @@ -327,7 +327,7 @@ internal static IntPtr CreateMetaType(Type impl) // We need space for 3 PyMethodDef structs, each of them // 4 int-ptrs in size. - IntPtr mdef = Runtime.PyMem_Malloc(3 * 4 * IntPtr.Size); + IntPtr mdef = Runtime.Interop.PyMem_Malloc(3 * 4 * IntPtr.Size); IntPtr mdefStart = mdef; mdef = WriteMethodDef( mdef, @@ -346,11 +346,11 @@ internal static IntPtr CreateMetaType(Type impl) Marshal.WriteIntPtr(type, TypeOffset.tp_methods, mdefStart); - Runtime.PyType_Ready(type); + Runtime.Interop.PyType_Ready(type); IntPtr dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict); IntPtr mod = Runtime.PyString_FromString("CLR"); - Runtime.PyDict_SetItemString(dict, "__module__", mod); + Runtime.Interop.PyDict_SetItemString(dict, "__module__", mod); //DebugUtil.DumpType(type); @@ -388,11 +388,11 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl) InitializeSlots(type, impl); - Runtime.PyType_Ready(type); + Runtime.Interop.PyType_Ready(type); IntPtr tp_dict = Marshal.ReadIntPtr(type, TypeOffset.tp_dict); IntPtr mod = Runtime.PyString_FromString("CLR"); - Runtime.PyDict_SetItemString(tp_dict, "__module__", mod); + Runtime.Interop.PyDict_SetItemString(tp_dict, "__module__", mod); return type; } @@ -403,7 +403,7 @@ internal static IntPtr BasicSubType(string name, IntPtr base_, Type impl) /// internal static IntPtr AllocateTypeObject(string name) { - IntPtr type = Runtime.PyType_GenericAlloc(Runtime.PyTypeType, 0); + IntPtr type = Runtime.Interop.PyType_GenericAlloc(Runtime.PyTypeType, 0); // Cheat a little: we'll set tp_name to the internal char * of // the Python version of the type name - otherwise we'd have to @@ -412,7 +412,7 @@ internal static IntPtr AllocateTypeObject(string name) // For python3 we leak two objects. One for the ASCII representation // required for tp_name, and another for the Unicode representation // for ht_name. - IntPtr temp = Runtime.PyBytes_FromString(name); + IntPtr temp = Runtime.Interop.PyBytes_FromString(name); IntPtr raw = Runtime.PyBytes_AS_STRING(temp); temp = Runtime.PyUnicode_FromString(name); #elif PYTHON2 @@ -519,7 +519,7 @@ private static void InitMethods(IntPtr pytype, Type type) var mi = new MethodInfo[1]; mi[0] = method; MethodObject m = new TypeMethod(type, method_name, mi); - Runtime.PyDict_SetItemString(dict, method_name, m.pyHandle); + Runtime.Interop.PyDict_SetItemString(dict, method_name, m.pyHandle); addedMethods.Add(method_name); } } diff --git a/src/testing/Python.Test.15.csproj b/src/testing/Python.Test.15.csproj index da20ed2ef..a6d303dbe 100644 --- a/src/testing/Python.Test.15.csproj +++ b/src/testing/Python.Test.15.csproj @@ -3,7 +3,7 @@ net40;netstandard2.0 x64;x86 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 + Debug;DebugPY3;Release;ReleasePY3 Python.Test Python.Test Python.Test