@@ -495,8 +495,6 @@ private static void NullGCHandles(IEnumerable<IntPtr> objects)
495495 internal static PyType PyNoneType ;
496496 internal static BorrowedReference PyTypeType => new ( Delegates . PyType_Type ) ;
497497
498- internal static int * Py_NoSiteFlag ;
499-
500498 internal static PyObject PyBytesType ;
501499 internal static NativeFunc * _PyObject_NextNotImplemented ;
502500
@@ -1881,24 +1879,11 @@ internal static IntPtr PyCapsule_GetPointer(BorrowedReference capsule, IntPtr na
18811879
18821880 internal static void SetNoSiteFlag ( )
18831881 {
1884- var loader = LibraryLoader . Instance ;
1885- IntPtr dllLocal = IntPtr . Zero ;
1886- if ( _PythonDll != "__Internal" )
1887- {
1888- dllLocal = loader . Load ( _PythonDll ) ;
1889- }
1890- try
1891- {
1892- Py_NoSiteFlag = ( int * ) loader . GetFunction ( dllLocal , "Py_NoSiteFlag" ) ;
1893- * Py_NoSiteFlag = 1 ;
1894- }
1895- finally
1882+ TryUsingDll ( ( ) =>
18961883 {
1897- if ( dllLocal != IntPtr . Zero )
1898- {
1899- loader . Free ( dllLocal ) ;
1900- }
1901- }
1884+ * Delegates . Py_NoSiteFlag = 1 ;
1885+ return * Delegates . Py_NoSiteFlag ;
1886+ } ) ;
19021887 }
19031888
19041889 internal static class Delegates
@@ -2170,6 +2155,7 @@ static Delegates()
21702155 catch ( MissingMethodException ) { }
21712156
21722157 PyType_Type = GetFunctionByName ( nameof ( PyType_Type ) , GetUnmanagedDll ( _PythonDll ) ) ;
2158+ Py_NoSiteFlag = ( int * ) GetFunctionByName ( nameof ( Py_NoSiteFlag ) , GetUnmanagedDll ( _PythonDll ) ) ;
21732159 }
21742160
21752161 static global ::System . IntPtr GetUnmanagedDll ( string ? libraryName )
@@ -2426,6 +2412,7 @@ static Delegates()
24262412 internal static delegate * unmanaged[ Cdecl] < BorrowedReference , void > _Py_NewReference { get ; }
24272413 internal static delegate * unmanaged[ Cdecl] < int > _Py_IsFinalizing { get ; }
24282414 internal static IntPtr PyType_Type { get ; }
2415+ internal static int * Py_NoSiteFlag { get ; }
24292416 }
24302417 }
24312418
0 commit comments