From d53baf65c14e23c46d251adbd10ce480f29d6d1e Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 21 Oct 2025 18:41:05 +0200 Subject: [PATCH] Add PyConfig-related functions --- src/runtime/Native/PyStatus.cs | 12 ++++++++++++ src/runtime/Runtime.Delegates.cs | 17 ++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/runtime/Native/PyStatus.cs diff --git a/src/runtime/Native/PyStatus.cs b/src/runtime/Native/PyStatus.cs new file mode 100644 index 000000000..35cb11f30 --- /dev/null +++ b/src/runtime/Native/PyStatus.cs @@ -0,0 +1,12 @@ +using System; +using System.Runtime.InteropServices; + +namespace Python.Runtime.Native; + +[StructLayout(LayoutKind.Sequential)] +struct PyStatus +{ + int exitcode; + IntPtr err_msg; + IntPtr func; +} diff --git a/src/runtime/Runtime.Delegates.cs b/src/runtime/Runtime.Delegates.cs index 262dc1e19..92c08dbbb 100644 --- a/src/runtime/Runtime.Delegates.cs +++ b/src/runtime/Runtime.Delegates.cs @@ -31,7 +31,6 @@ static Delegates() } catch (MissingMethodException) { - PyThreadState_GetUnchecked = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyThreadState_GetUnchecked), GetUnmanagedDll(_PythonDll)); } try @@ -277,6 +276,15 @@ static Delegates() PyType_GetSlot = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_GetSlot), GetUnmanagedDll(_PythonDll)); PyType_FromSpecWithBases = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_FromSpecWithBases), GetUnmanagedDll(PythonDLL)); + PyConfig_InitPythonConfig = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyConfig_InitPythonConfig), GetUnmanagedDll(_PythonDll)); + PyConfig_InitIsolatedConfig = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyConfig_InitIsolatedConfig), GetUnmanagedDll(_PythonDll)); + PyConfig_SetString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyConfig_SetString), GetUnmanagedDll(_PythonDll)); + + Py_InitializeFromConfig = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_InitializeFromConfig), GetUnmanagedDll(_PythonDll)); + PyConfig_Clear = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyConfig_Clear), GetUnmanagedDll(_PythonDll)); + PyStatus_Exception = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyStatus_Exception), GetUnmanagedDll(_PythonDll)); + Py_ExitStatusException = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_ExitStatusException), GetUnmanagedDll(_PythonDll)); + try { _Py_NewReference = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_Py_NewReference), GetUnmanagedDll(_PythonDll)); @@ -548,5 +556,12 @@ static Delegates() internal static delegate* unmanaged[Cdecl] _Py_IsFinalizing { get; } internal static IntPtr PyType_Type { get; } internal static int* Py_NoSiteFlag { get; } + internal static delegate* unmanaged[Cdecl] PyConfig_InitPythonConfig { get; } + internal static delegate* unmanaged[Cdecl] PyConfig_InitIsolatedConfig { get; } + internal static delegate* unmanaged[Cdecl] PyConfig_SetString { get; } + internal static delegate* unmanaged[Cdecl] Py_InitializeFromConfig { get; } + internal static delegate* unmanaged[Cdecl] PyConfig_Clear { get; } + internal static delegate* unmanaged[Cdecl] PyStatus_Exception { get; } + internal static delegate* unmanaged[Cdecl] Py_ExitStatusException { get; } } }