@@ -23,7 +23,17 @@ static Delegates()
2323 Py_EndInterpreter = ( delegate * unmanaged[ Cdecl] < PyThreadState * , void > ) GetFunctionByName ( nameof ( Py_EndInterpreter ) , GetUnmanagedDll ( _PythonDll ) ) ;
2424 PyThreadState_New = ( delegate * unmanaged[ Cdecl] < PyInterpreterState * , PyThreadState * > ) GetFunctionByName ( nameof ( PyThreadState_New ) , GetUnmanagedDll ( _PythonDll ) ) ;
2525 PyThreadState_Get = ( delegate * unmanaged[ Cdecl] < PyThreadState * > ) GetFunctionByName ( nameof ( PyThreadState_Get ) , GetUnmanagedDll ( _PythonDll ) ) ;
26- _PyThreadState_UncheckedGet = ( delegate * unmanaged[ Cdecl] < PyThreadState * > ) GetFunctionByName ( nameof ( _PyThreadState_UncheckedGet ) , GetUnmanagedDll ( _PythonDll ) ) ;
26+ try
27+ {
28+ // Up until Python 3.13, this function was private and named
29+ // slightly differently.
30+ PyThreadState_GetUnchecked = ( delegate * unmanaged[ Cdecl] < PyThreadState * > ) GetFunctionByName ( "_PyThreadState_UncheckedGet" , GetUnmanagedDll ( _PythonDll ) ) ;
31+ }
32+ catch ( MissingMethodException )
33+ {
34+
35+ PyThreadState_GetUnchecked = ( delegate * unmanaged[ Cdecl] < PyThreadState * > ) GetFunctionByName ( nameof ( PyThreadState_GetUnchecked ) , GetUnmanagedDll ( _PythonDll ) ) ;
36+ }
2737 try
2838 {
2939 PyGILState_Check = ( delegate * unmanaged[ Cdecl] < int > ) GetFunctionByName ( nameof ( PyGILState_Check ) , GetUnmanagedDll ( _PythonDll ) ) ;
@@ -316,7 +326,7 @@ static Delegates()
316326 internal static delegate * unmanaged[ Cdecl] < PyThreadState * , void > Py_EndInterpreter { get ; }
317327 internal static delegate * unmanaged[ Cdecl] < PyInterpreterState * , PyThreadState * > PyThreadState_New { get ; }
318328 internal static delegate * unmanaged[ Cdecl] < PyThreadState * > PyThreadState_Get { get ; }
319- internal static delegate * unmanaged[ Cdecl] < PyThreadState * > _PyThreadState_UncheckedGet { get ; }
329+ internal static delegate * unmanaged[ Cdecl] < PyThreadState * > PyThreadState_GetUnchecked { get ; }
320330 internal static delegate * unmanaged[ Cdecl] < int > PyGILState_Check { get ; }
321331 internal static delegate * unmanaged[ Cdecl] < PyGILState > PyGILState_Ensure { get ; }
322332 internal static delegate * unmanaged[ Cdecl] < PyGILState , void > PyGILState_Release { get ; }
0 commit comments