8000 Use Delegates to access Py_NoSiteFlag by lostmsu · Pull Request #1659 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Use Delegates to access Py_NoSiteFlag #1659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
8000 Loading
Diff view
Diff view
use the same facility to access Py_NoSiteFlag as the one used to load…
… Python C API functions

fixes #1517
  • Loading branch information
lostmsu committed Jan 5, 2022
commit 1129a73838903f27bc2d4b0dc5e2c1bef033637f
25 changes: 6 additions & 19 deletions src/runtime/runtime.cs
< 720D td id="diff-f1749bdd9f64fdac5c64d5cb0982ce1dac5e2d9a2cdd55b93d3f83b5047a855dR2155" data-line-number="2155" class="blob-num blob-num-context js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,6 @@ private static void NullGCHandles(IEnumerable<IntPtr> objects)
internal static PyType PyNoneType;
internal static BorrowedReference PyTypeType => new(Delegates.PyType_Type);

internal static int* Py_NoSiteFlag;

internal static PyObject PyBytesType;
internal static NativeFunc* _PyObject_NextNotImplemented;

Expand Down Expand Up @@ -1881,24 +1879,11 @@ internal static IntPtr PyCapsule_GetPointer(BorrowedReference capsule, IntPtr na

internal static void SetNoSiteFlag()
{
var loader = LibraryLoader.Instance;
IntPtr dllLocal = IntPtr.Zero;
if (_PythonDll != "__Internal")
{
dllLocal = loader.Load(_PythonDll);
}
try
{
Py_NoSiteFlag = (int*)loader.GetFunction(dllLocal, "Py_NoSiteFlag");
*Py_NoSiteFlag = 1;
}
finally
TryUsingDll(() =>
{
if (dllLocal != IntPtr.Zero)
{
loader.Free(dllLocal);
}
}
*Delegates.Py_NoSiteFlag = 1;
return *Delegates.Py_NoSiteFlag;
});
}

internal static class Delegates
Expand Down Expand Up @@ -2170,6 +2155,7 @@ static Delegates()
catch (MissingMethodException) { }

PyType_Type = GetFunctionByName(nameof(PyType_Type), GetUnmanagedDll(_PythonDll));
Py_NoSiteFlag = (int*)GetFunctionByName(nameof(Py_NoSiteFlag), GetUnmanagedDll(_PythonDll));
}

static global::System.IntPtr GetUnmanagedDll(string? libraryName)
Expand Down Expand Up @@ -2426,6 +2412,7 @@ static Delegates()
internal static delegate* unmanaged[Cdecl]<BorrowedReference, void> _Py_NewReference { get; }
internal static delegate* unmanaged[Cdecl]<int> _Py_IsFinalizing { get; }
internal static IntPtr PyType_Type { get; }
internal static int* Py_NoSiteFlag { get; }
}
}

Expand Down
0