diff --git a/src/runtime/assemblymanager.cs b/src/runtime/AssemblyManager.cs similarity index 100% rename from src/runtime/assemblymanager.cs rename to src/runtime/AssemblyManager.cs diff --git a/src/runtime/classmanager.cs b/src/runtime/ClassManager.cs similarity index 100% rename from src/runtime/classmanager.cs rename to src/runtime/ClassManager.cs diff --git a/src/runtime/Codecs/IPyObjectDecoder.cs b/src/runtime/Codecs/IPyObjectDecoder.cs new file mode 100644 index 000000000..a8cd8ff03 --- /dev/null +++ b/src/runtime/Codecs/IPyObjectDecoder.cs @@ -0,0 +1,22 @@ +namespace Python.Runtime; + +using System; + +/// +/// Defines conversion to CLR types (unmarshalling) +/// +public interface IPyObjectDecoder +{ + /// + /// Checks if this decoder can decode from to + /// + bool CanDecode(PyType objectType, Type targetType); + /// + /// Attempts do decode into a variable of specified type + /// + /// CLR type to decode into + /// Object to decode + /// The variable, that will receive decoding result + /// + bool TryDecode(PyObject pyObj, out T? value); +} diff --git a/src/runtime/Codecs/IPyObjectEncoder.cs b/src/runtime/Codecs/IPyObjectEncoder.cs new file mode 100644 index 000000000..94d19da90 --- /dev/null +++ b/src/runtime/Codecs/IPyObjectEncoder.cs @@ -0,0 +1,18 @@ +namespace Python.Runtime; + +using System; + +/// +/// Defines conversion from CLR objects into Python objects (e.g. ) (marshalling) +/// +public interface IPyObjectEncoder +{ + /// + /// Checks if encoder can encode CLR objects of specified type + /// + bool CanEncode(Type type); + /// + /// Attempts to encode CLR object into Python object + /// + PyObject? TryEncode(object value); +} diff --git a/src/runtime/converterextensions.cs b/src/runtime/Codecs/PyObjectConversions.cs similarity index 80% rename from src/runtime/converterextensions.cs rename to src/runtime/Codecs/PyObjectConversions.cs index 9a7ae5403..94ed4cdc3 100644 --- a/src/runtime/converterextensions.cs +++ b/src/runtime/Codecs/PyObjectConversions.cs @@ -6,41 +6,8 @@ namespace Python.Runtime using System.Diagnostics; using System.Linq; using System.Reflection; - using Python.Runtime.Codecs; - - /// - /// Defines conversion to CLR types (unmarshalling) - /// - public interface IPyObjectDecoder - { - /// - /// Checks if this decoder can decode from to - /// - bool CanDecode(PyType objectType, Type targetType); - /// - /// Attempts do decode into a variable of specified type - /// - /// CLR type to decode into - /// Object to decode - /// The variable, that will receive decoding result - /// - bool TryDecode(PyObject pyObj, out T? value); - } - /// - /// Defines conversion from CLR objects into Python objects (e.g. ) (marshalling) - /// - public interface IPyObjectEncoder - { - /// - /// Checks if encoder can encode CLR objects of specified type - /// - bool CanEncode(Type type); - /// - /// Attempts to encode CLR object into Python object - /// - PyObject? TryEncode(object value); - } + using Python.Runtime.Codecs; /// /// This class allows to register additional marshalling codecs. diff --git a/src/runtime/converter.cs b/src/runtime/Converter.cs similarity index 100% rename from src/runtime/converter.cs rename to src/runtime/Converter.cs diff --git a/src/runtime/delegatemanager.cs b/src/runtime/DelegateManager.cs similarity index 100% rename from src/runtime/delegatemanager.cs rename to src/runtime/DelegateManager.cs diff --git a/src/runtime/exceptions.cs b/src/runtime/Exceptions.cs similarity index 84% rename from src/runtime/exceptions.cs rename to src/runtime/Exceptions.cs index 5cf845155..c3ac889ed 100644 --- a/src/runtime/exceptions.cs +++ b/src/runtime/Exceptions.cs @@ -5,87 +5,6 @@ namespace Python.Runtime { - /// - /// Base class for Python types that reflect managed exceptions based on - /// System.Exception - /// - /// - /// The Python wrapper for managed exceptions LIES about its inheritance - /// tree. Although the real System.Exception is a subclass of - /// System.Object the Python type for System.Exception does NOT claim that - /// it subclasses System.Object. Instead TypeManager.CreateType() uses - /// Python's exception.Exception class as base class for System.Exception. - /// - [Serializable] - internal class ExceptionClassObject : ClassObject - { - internal ExceptionClassObject(Type tp) : base(tp) - { - } - - internal static Exception? ToException(BorrowedReference ob) - { - var co = GetManagedObject(ob) as CLRObject; - return co?.inst as Exception; - } - - /// - /// Exception __repr__ implementation - /// - public new static NewReference tp_repr(BorrowedReference ob) - { - Exception? e = ToException(ob); - if (e == null) - { - return Exceptions.RaiseTypeError("invalid object"); - } - string name = e.GetType().Name; - string message; - if (e.Message != String.Empty) - { - message = String.Format("{0}('{1}')", name, e.Message); - } - else - { - message = String.Format("{0}()", name); - } - return Runtime.PyString_FromString(message); - } - - /// - /// Exception __str__ implementation - /// - public new static NewReference tp_str(BorrowedReference ob) - { - Exception? e = ToException(ob); - if (e == null) - { - return Exceptions.RaiseTypeError("invalid object"); - } - - string message = e.ToString(); - string fullTypeName = e.GetType().FullName; - string prefix = fullTypeName + ": "; - if (message.StartsWith(prefix)) - { - message = message.Substring(prefix.Length); - } - else if (message.StartsWith(fullTypeName)) - { - message = message.Substring(fullTypeName.Length); - } - return Runtime.PyString_FromString(message); - } - - public override bool Init(BorrowedReference obj, BorrowedReference args, BorrowedReference kw) - { - if (!base.Init(obj, args, kw)) return false; - - var e = (CLRObject)GetManagedObject(obj)!; - - return Exceptions.SetArgsAndCause(obj, (Exception)e.inst); - } - } /// /// Encapsulates the Python exception APIs. diff --git a/src/runtime/finalizer.cs b/src/runtime/Finalizer.cs similarity index 100% rename from src/runtime/finalizer.cs rename to src/runtime/Finalizer.cs diff --git a/src/runtime/importhook.cs b/src/runtime/ImportHook.cs similarity index 100% rename from src/runtime/importhook.cs rename to src/runtime/ImportHook.cs diff --git a/src/runtime/interfaces.cs b/src/runtime/Interfaces.cs similarity index 100% rename from src/runtime/interfaces.cs rename to src/runtime/Interfaces.cs diff --git a/src/runtime/intern.cs b/src/runtime/InternString.cs similarity index 100% rename from src/runtime/intern.cs rename to src/runtime/InternString.cs diff --git a/src/runtime/interop.cs b/src/runtime/Interop.cs similarity index 100% rename from src/runtime/interop.cs rename to src/runtime/Interop.cs diff --git a/src/runtime/loader.cs b/src/runtime/Loader.cs similarity index 100% rename from src/runtime/loader.cs rename to src/runtime/Loader.cs diff --git a/src/runtime/methodbinder.cs b/src/runtime/MethodBinder.cs similarity index 100% rename from src/runtime/methodbinder.cs rename to src/runtime/MethodBinder.cs diff --git a/src/runtime/native/ABI.cs b/src/runtime/Native/ABI.cs similarity index 100% rename from src/runtime/native/ABI.cs rename to src/runtime/Native/ABI.cs diff --git a/src/runtime/BorrowedReference.cs b/src/runtime/Native/BorrowedReference.cs similarity index 100% rename from src/runtime/BorrowedReference.cs rename to src/runtime/Native/BorrowedReference.cs diff --git a/src/runtime/CustomMarshaler.cs b/src/runtime/Native/CustomMarshaler.cs similarity index 100% rename from src/runtime/CustomMarshaler.cs rename to src/runtime/Native/CustomMarshaler.cs diff --git a/src/runtime/native/GeneratedTypeOffsets.cs b/src/runtime/Native/GeneratedTypeOffsets.cs similarity index 100% rename from src/runtime/native/GeneratedTypeOffsets.cs rename to src/runtime/Native/GeneratedTypeOffsets.cs diff --git a/src/runtime/native/ITypeOffsets.cs b/src/runtime/Native/ITypeOffsets.cs similarity index 100% rename from src/runtime/native/ITypeOffsets.cs rename to src/runtime/Native/ITypeOffsets.cs diff --git a/src/runtime/platform/LibDL.cs b/src/runtime/Native/LibDL.cs similarity index 100% rename from src/runtime/platform/LibDL.cs rename to src/runtime/Native/LibDL.cs diff --git a/src/runtime/platform/LibraryLoader.cs b/src/runtime/Native/LibraryLoader.cs similarity index 100% rename from src/runtime/platform/LibraryLoader.cs rename to src/runtime/Native/LibraryLoader.cs diff --git a/src/runtime/nativecall.cs b/src/runtime/Native/NativeCall.cs similarity index 100% rename from src/runtime/nativecall.cs rename to src/runtime/Native/NativeCall.cs diff --git a/src/runtime/native/NativeFunc.cs b/src/runtime/Native/NativeFunc.cs similarity index 100% rename from src/runtime/native/NativeFunc.cs rename to src/runtime/Native/NativeFunc.cs diff --git a/src/runtime/native/NativeTypeSpec.cs b/src/runtime/Native/NativeTypeSpec.cs similarity index 100% rename from src/runtime/native/NativeTypeSpec.cs rename to src/runtime/Native/NativeTypeSpec.cs diff --git a/src/runtime/NewReference.cs b/src/runtime/Native/NewReference.cs similarity index 100% rename from src/runtime/NewReference.cs rename to src/runtime/Native/NewReference.cs diff --git a/src/runtime/bufferinterface.cs b/src/runtime/Native/PyBufferInterface.cs similarity index 100% rename from src/runtime/bufferinterface.cs rename to src/runtime/Native/PyBufferInterface.cs diff --git a/src/runtime/native/PyCompilerFlags.cs b/src/runtime/Native/PyCompilerFlags.cs similarity index 100% rename from src/runtime/native/PyCompilerFlags.cs rename to src/runtime/Native/PyCompilerFlags.cs diff --git a/src/runtime/native/PyGILState.cs b/src/runtime/Native/PyGILState.cs similarity index 100% rename from src/runtime/native/PyGILState.cs rename to src/runtime/Native/PyGILState.cs diff --git a/src/runtime/intern_.cs b/src/runtime/Native/PyIdentifier_.cs similarity index 100% rename from src/runtime/intern_.cs rename to src/runtime/Native/PyIdentifier_.cs diff --git a/src/runtime/intern_.tt b/src/runtime/Native/PyIdentifier_.tt similarity index 100% rename from src/runtime/intern_.tt rename to src/runtime/Native/PyIdentifier_.tt diff --git a/src/runtime/native/PyInterpreterState.cs b/src/runtime/Native/PyInterpreterState.cs similarity index 100% rename from src/runtime/native/PyInterpreterState.cs rename to src/runtime/Native/PyInterpreterState.cs diff --git a/src/runtime/native/PyMemberFlags.cs b/src/runtime/Native/PyMemberFlags.cs similarity index 100% rename from src/runtime/native/PyMemberFlags.cs rename to src/runtime/Native/PyMemberFlags.cs diff --git a/src/runtime/native/PyMemberType.cs b/src/runtime/Native/PyMemberType.cs similarity index 100% rename from src/runtime/native/PyMemberType.cs rename to src/runtime/Native/PyMemberType.cs diff --git a/src/runtime/native/PyMethodFlags.cs b/src/runtime/Native/PyMethodFlags.cs similarity index 100% rename from src/runtime/native/PyMethodFlags.cs rename to src/runtime/Native/PyMethodFlags.cs diff --git a/src/runtime/native/PyThreadState.cs b/src/runtime/Native/PyThreadState.cs similarity index 100% rename from src/runtime/native/PyThreadState.cs rename to src/runtime/Native/PyThreadState.cs diff --git a/src/runtime/ReferenceExtensions.cs b/src/runtime/Native/ReferenceExtensions.cs similarity index 100% rename from src/runtime/ReferenceExtensions.cs rename to src/runtime/Native/ReferenceExtensions.cs diff --git a/src/runtime/StolenReference.cs b/src/runtime/Native/StolenReference.cs similarity index 100% rename from src/runtime/StolenReference.cs rename to src/runtime/Native/StolenReference.cs diff --git a/src/runtime/native/StrPtr.cs b/src/runtime/Native/StrPtr.cs similarity index 100% rename from src/runtime/native/StrPtr.cs rename to src/runtime/Native/StrPtr.cs diff --git a/src/runtime/native/TypeOffset.cs b/src/runtime/Native/TypeOffset.cs similarity index 100% rename from src/runtime/native/TypeOffset.cs rename to src/runtime/Native/TypeOffset.cs diff --git a/src/runtime/interop310.cs b/src/runtime/Native/TypeOffset310.cs similarity index 100% rename from src/runtime/interop310.cs rename to src/runtime/Native/TypeOffset310.cs diff --git a/src/runtime/interop36.cs b/src/runtime/Native/TypeOffset36.cs similarity index 100% rename from src/runtime/interop36.cs rename to src/runtime/Native/TypeOffset36.cs diff --git a/src/runtime/interop37.cs b/src/runtime/Native/TypeOffset37.cs similarity index 100% rename from src/runtime/interop37.cs rename to src/runtime/Native/TypeOffset37.cs diff --git a/src/runtime/interop38.cs b/src/runtime/Native/TypeOffset38.cs similarity index 100% rename from src/runtime/interop38.cs rename to src/runtime/Native/TypeOffset38.cs diff --git a/src/runtime/interop39.cs b/src/runtime/Native/TypeOffset39.cs similarity index 100% rename from src/runtime/interop39.cs rename to src/runtime/Native/TypeOffset39.cs diff --git a/src/runtime/Python.Runtime.csproj b/src/runtime/Python.Runtime.csproj index a90aa3aaa..fad5b9da8 100644 --- a/src/runtime/Python.Runtime.csproj +++ b/src/runtime/Python.Runtime.csproj @@ -50,10 +50,10 @@ - + clr.py - + interop.py diff --git a/src/runtime/pythonengine.cs b/src/runtime/PythonEngine.cs similarity index 100% rename from src/runtime/pythonengine.cs rename to src/runtime/PythonEngine.cs diff --git a/src/runtime/pythonexception.cs b/src/runtime/PythonException.cs similarity index 100% rename from src/runtime/pythonexception.cs rename to src/runtime/PythonException.cs diff --git a/src/runtime/pybuffer.cs b/src/runtime/PythonTypes/PyBuffer.cs similarity index 100% rename from src/runtime/pybuffer.cs rename to src/runtime/PythonTypes/PyBuffer.cs diff --git a/src/runtime/pydict.cs b/src/runtime/PythonTypes/PyDict.cs similarity index 100% rename from src/runtime/pydict.cs rename to src/runtime/PythonTypes/PyDict.cs diff --git a/src/runtime/pyfloat.cs b/src/runtime/PythonTypes/PyFloat.cs similarity index 100% rename from src/runtime/pyfloat.cs rename to src/runtime/PythonTypes/PyFloat.cs diff --git a/src/runtime/pyint.cs b/src/runtime/PythonTypes/PyInt.cs similarity index 100% rename from src/runtime/pyint.cs rename to src/runtime/PythonTypes/PyInt.cs diff --git a/src/runtime/pyiter.cs b/src/runtime/PythonTypes/PyIter.cs similarity index 100% rename from src/runtime/pyiter.cs rename to src/runtime/PythonTypes/PyIter.cs diff --git a/src/runtime/pyiterable.cs b/src/runtime/PythonTypes/PyIterable.cs similarity index 100% rename from src/runtime/pyiterable.cs rename to src/runtime/PythonTypes/PyIterable.cs diff --git a/src/runtime/pylist.cs b/src/runtime/PythonTypes/PyList.cs similarity index 100% rename from src/runtime/pylist.cs rename to src/runtime/PythonTypes/PyList.cs diff --git a/src/runtime/module.cs b/src/runtime/PythonTypes/PyModule.cs similarity index 100% rename from src/runtime/module.cs rename to src/runtime/PythonTypes/PyModule.cs diff --git a/src/runtime/pynumber.cs b/src/runtime/PythonTypes/PyNumber.cs similarity index 100% rename from src/runtime/pynumber.cs rename to src/runtime/PythonTypes/PyNumber.cs diff --git a/src/runtime/pyobject.cs b/src/runtime/PythonTypes/PyObject.cs similarity index 100% rename from src/runtime/pyobject.cs rename to src/runtime/PythonTypes/PyObject.cs diff --git a/src/runtime/pysequence.cs b/src/runtime/PythonTypes/PySequence.cs similarity index 100% rename from src/runtime/pysequence.cs rename to src/runtime/PythonTypes/PySequence.cs diff --git a/src/runtime/pystring.cs b/src/runtime/PythonTypes/PyString.cs similarity index 100% rename from src/runtime/pystring.cs rename to src/runtime/PythonTypes/PyString.cs diff --git a/src/runtime/pytuple.cs b/src/runtime/PythonTypes/PyTuple.cs similarity index 100% rename from src/runtime/pytuple.cs rename to src/runtime/PythonTypes/PyTuple.cs diff --git a/src/runtime/pytype.cs b/src/runtime/PythonTypes/PyType.cs similarity index 100% rename from src/runtime/pytype.cs rename to src/runtime/PythonTypes/PyType.cs diff --git a/src/runtime/TypeSpec.cs b/src/runtime/PythonTypes/TypeSpec.cs similarity index 100% rename from src/runtime/TypeSpec.cs rename to src/runtime/PythonTypes/TypeSpec.cs diff --git a/src/runtime/resources/clr.py b/src/runtime/Resources/clr.py similarity index 100% rename from src/runtime/resources/clr.py rename to src/runtime/Resources/clr.py diff --git a/src/runtime/resources/interop.py b/src/runtime/Resources/interop.py similarity index 100% rename from src/runtime/resources/interop.py rename to src/runtime/Resources/interop.py diff --git a/src/runtime/Runtime.Delegates.cs b/src/runtime/Runtime.Delegates.cs new file mode 100644 index 000000000..6388bde9f --- /dev/null +++ b/src/runtime/Runtime.Delegates.cs @@ -0,0 +1,542 @@ +using System; + +using Python.Runtime.Native; +using Python.Runtime.Platform; + +namespace Python.Runtime; + +public unsafe partial class Runtime +{ + internal static class Delegates + { + static readonly ILibraryLoader libraryLoader = LibraryLoader.Instance; + + static Delegates() + { + Py_IncRef = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_IncRef), GetUnmanagedDll(_PythonDll)); + Py_DecRef = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_DecRef), GetUnmanagedDll(_PythonDll)); + Py_Initialize = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_Initialize), GetUnmanagedDll(_PythonDll)); + Py_InitializeEx = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_InitializeEx), GetUnmanagedDll(_PythonDll)); + Py_IsInitialized = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_IsInitialized), GetUnmanagedDll(_PythonDll)); + Py_Finalize = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_Finalize), GetUnmanagedDll(_PythonDll)); + Py_NewInterpreter = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_NewInterpreter), GetUnmanagedDll(_PythonDll)); + Py_EndInterpreter = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_EndInterpreter), GetUnmanagedDll(_PythonDll)); + PyThreadState_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyThreadState_New), GetUnmanagedDll(_PythonDll)); + PyThreadState_Get = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyThreadState_Get), GetUnmanagedDll(_PythonDll)); + _PyThreadState_UncheckedGet = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_PyThreadState_UncheckedGet), GetUnmanagedDll(_PythonDll)); + try + { + PyGILState_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGILState_Check), GetUnmanagedDll(_PythonDll)); + } + catch (MissingMethodException e) + { + throw new NotSupportedException(Util.MinimalPythonVersionRequired, innerException: e); + } + PyGILState_Ensure = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGILState_Ensure), GetUnmanagedDll(_PythonDll)); + PyGILState_Release = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGILState_Release), GetUnmanagedDll(_PythonDll)); + PyGILState_GetThisThreadState = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGILState_GetThisThreadState), GetUnmanagedDll(_PythonDll)); + Py_Main = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_Main), GetUnmanagedDll(_PythonDll)); + PyEval_InitThreads = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_InitThreads), GetUnmanagedDll(_PythonDll)); + PyEval_ThreadsInitialized = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_ThreadsInitialized), GetUnmanagedDll(_PythonDll)); + PyEval_AcquireLock = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_AcquireLock), GetUnmanagedDll(_PythonDll)); + PyEval_ReleaseLock = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_ReleaseLock), GetUnmanagedDll(_PythonDll)); + PyEval_AcquireThread = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_AcquireThread), GetUnmanagedDll(_PythonDll)); + PyEval_ReleaseThread = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_ReleaseThread), GetUnmanagedDll(_PythonDll)); + PyEval_SaveThread = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_SaveThread), GetUnmanagedDll(_PythonDll)); + PyEval_RestoreThread = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_RestoreThread), GetUnmanagedDll(_PythonDll)); + PyEval_GetBuiltins = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_GetBuiltins), GetUnmanagedDll(_PythonDll)); + PyEval_GetGlobals = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_GetGlobals), GetUnmanagedDll(_PythonDll)); + PyEval_GetLocals = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_GetLocals), GetUnmanagedDll(_PythonDll)); + Py_GetProgramName = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetProgramName), GetUnmanagedDll(_PythonDll)); + Py_SetProgramName = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_SetProgramName), GetUnmanagedDll(_PythonDll)); + Py_GetPythonHome = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetPythonHome), GetUnmanagedDll(_PythonDll)); + Py_SetPythonHome = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_SetPythonHome), GetUnmanagedDll(_PythonDll)); + Py_GetPath = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetPath), GetUnmanagedDll(_PythonDll)); + Py_SetPath = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_SetPath), GetUnmanagedDll(_PythonDll)); + Py_GetVersion = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetVersion), GetUnmanagedDll(_PythonDll)); + Py_GetPlatform = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetPlatform), GetUnmanagedDll(_PythonDll)); + Py_GetCopyright = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetCopyright), GetUnmanagedDll(_PythonDll)); + Py_GetCompiler = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetCompiler), GetUnmanagedDll(_PythonDll)); + Py_GetBuildInfo = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetBuildInfo), GetUnmanagedDll(_PythonDll)); + PyRun_SimpleStringFlags = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyRun_SimpleStringFlags), GetUnmanagedDll(_PythonDll)); + PyRun_StringFlags = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyRun_StringFlags), GetUnmanagedDll(_PythonDll)); + PyEval_EvalCode = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_EvalCode), GetUnmanagedDll(_PythonDll)); + Py_CompileStringObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_CompileStringObject), GetUnmanagedDll(_PythonDll)); + PyImport_ExecCodeModule = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_ExecCodeModule), GetUnmanagedDll(_PythonDll)); + PyObject_HasAttrString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_HasAttrString), GetUnmanagedDll(_PythonDll)); + PyObject_GetAttrString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetAttrString), GetUnmanagedDll(_PythonDll)); + PyObject_SetAttrString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_SetAttrString), GetUnmanagedDll(_PythonDll)); + PyObject_HasAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_HasAttr), GetUnmanagedDll(_PythonDll)); + PyObject_GetAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetAttr), GetUnmanagedDll(_PythonDll)); + PyObject_SetAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_SetAttr), GetUnmanagedDll(_PythonDll)); + PyObject_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetItem), GetUnmanagedDll(_PythonDll)); + PyObject_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_SetItem), GetUnmanagedDll(_PythonDll)); + PyObject_DelItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_DelItem), GetUnmanagedDll(_PythonDll)); + PyObject_GetIter = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetIter), GetUnmanagedDll(_PythonDll)); + PyObject_Call = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Call), GetUnmanagedDll(_PythonDll)); + PyObject_CallObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_CallObject), GetUnmanagedDll(_PythonDll)); + PyObject_RichCompareBool = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_RichCompareBool), GetUnmanagedDll(_PythonDll)); + PyObject_IsInstance = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_IsInstance), GetUnmanagedDll(_PythonDll)); + PyObject_IsSubclass = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_IsSubclass), GetUnmanagedDll(_PythonDll)); + PyCallable_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCallable_Check), GetUnmanagedDll(_PythonDll)); + PyObject_IsTrue = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_IsTrue), GetUnmanagedDll(_PythonDll)); + PyObject_Not = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Not), GetUnmanagedDll(_PythonDll)); + PyObject_Size = (delegate* unmanaged[Cdecl])GetFunctionByName("PyObject_Size", GetUnmanagedDll(_PythonDll)); + PyObject_Hash = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Hash), GetUnmanagedDll(_PythonDll)); + PyObject_Repr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Repr), GetUnmanagedDll(_PythonDll)); + PyObject_Str = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Str), GetUnmanagedDll(_PythonDll)); + PyObject_Type = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Type), GetUnmanagedDll(_PythonDll)); + PyObject_Dir = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Dir), GetUnmanagedDll(_PythonDll)); + PyObject_GetBuffer = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetBuffer), GetUnmanagedDll(_PythonDll)); + PyBuffer_Release = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_Release), GetUnmanagedDll(_PythonDll)); + try + { + PyBuffer_SizeFromFormat = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_SizeFromFormat), GetUnmanagedDll(_PythonDll)); + } + catch (MissingMethodException) + { + // only in 3.9+ + } + PyBuffer_IsContiguous = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_IsContiguous), GetUnmanagedDll(_PythonDll)); + PyBuffer_GetPointer = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_GetPointer), GetUnmanagedDll(_PythonDll)); + PyBuffer_FromContiguous = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_FromContiguous), GetUnmanagedDll(_PythonDll)); + PyBuffer_ToContiguous = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_ToContiguous), GetUnmanagedDll(_PythonDll)); + PyBuffer_FillContiguousStrides = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_FillContiguousStrides), GetUnmanagedDll(_PythonDll)); + PyBuffer_FillInfo = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_FillInfo), GetUnmanagedDll(_PythonDll)); + PyNumber_Long = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Long), GetUnmanagedDll(_PythonDll)); + PyNumber_Float = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Float), GetUnmanagedDll(_PythonDll)); + PyNumber_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Check), GetUnmanagedDll(_PythonDll)); + PyLong_FromLongLong = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_FromLongLong), GetUnmanagedDll(_PythonDll)); + PyLong_FromUnsignedLongLong = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_FromUnsignedLongLong), GetUnmanagedDll(_PythonDll)); + PyLong_FromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_FromString), GetUnmanagedDll(_PythonDll)); + PyLong_AsLongLong = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_AsLongLong), GetUnmanagedDll(_PythonDll)); + PyLong_AsUnsignedLongLong = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_AsUnsignedLongLong), GetUnmanagedDll(_PythonDll)); + PyLong_FromVoidPtr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_FromVoidPtr), GetUnmanagedDll(_PythonDll)); + PyLong_AsVoidPtr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_AsVoidPtr), GetUnmanagedDll(_PythonDll)); + PyFloat_FromDouble = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyFloat_FromDouble), GetUnmanagedDll(_PythonDll)); + PyFloat_FromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyFloat_FromString), GetUnmanagedDll(_PythonDll)); + PyFloat_AsDouble = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyFloat_AsDouble), GetUnmanagedDll(_PythonDll)); + PyNumber_Add = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Add), GetUnmanagedDll(_PythonDll)); + PyNumber_Subtract = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Subtract), GetUnmanagedDll(_PythonDll)); + PyNumber_Multiply = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Multiply), GetUnmanagedDll(_PythonDll)); + PyNumber_TrueDivide = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_TrueDivide), GetUnmanagedDll(_PythonDll)); + PyNumber_And = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_And), GetUnmanagedDll(_PythonDll)); + PyNumber_Xor = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Xor), GetUnmanagedDll(_PythonDll)); + PyNumber_Or = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Or), GetUnmanagedDll(_PythonDll)); + PyNumber_Lshift = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Lshift), GetUnmanagedDll(_PythonDll)); + PyNumber_Rshift = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Rshift), GetUnmanagedDll(_PythonDll)); + PyNumber_Power = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Power), GetUnmanagedDll(_PythonDll)); + PyNumber_Remainder = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Remainder), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceAdd = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceAdd), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceSubtract = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceSubtract), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceMultiply = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceMultiply), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceTrueDivide = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceTrueDivide), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceAnd = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceAnd), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceXor = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceXor), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceOr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceOr), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceLshift = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceLshift), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceRshift = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceRshift), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlacePower = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlacePower), GetUnmanagedDll(_PythonDll)); + PyNumber_InPlaceRemainder = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceRemainder), GetUnmanagedDll(_PythonDll)); + PyNumber_Negative = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Negative), GetUnmanagedDll(_PythonDll)); + PyNumber_Positive = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Positive), GetUnmanagedDll(_PythonDll)); + PyNumber_Invert = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Invert), GetUnmanagedDll(_PythonDll)); + PySequence_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Check), GetUnmanagedDll(_PythonDll)); + PySequence_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_GetItem), GetUnmanagedDll(_PythonDll)); + PySequence_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_SetItem), GetUnmanagedDll(_PythonDll)); + PySequence_DelItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_DelItem), GetUnmanagedDll(_PythonDll)); + PySequence_GetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_GetSlice), GetUnmanagedDll(_PythonDll)); + PySequence_SetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_SetSlice), GetUnmanagedDll(_PythonDll)); + PySequence_DelSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_DelSlice), GetUnmanagedDll(_PythonDll)); + PySequence_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Size), GetUnmanagedDll(_PythonDll)); + PySequence_Contains = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Contains), GetUnmanagedDll(_PythonDll)); + PySequence_Concat = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Concat), GetUnmanagedDll(_PythonDll)); + PySequence_Repeat = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Repeat), GetUnmanagedDll(_PythonDll)); + PySequence_Index = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Index), GetUnmanagedDll(_PythonDll)); + PySequence_Count = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Count), GetUnmanagedDll(_PythonDll)); + PySequence_Tuple = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Tuple), GetUnmanagedDll(_PythonDll)); + PySequence_List = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_List), GetUnmanagedDll(_PythonDll)); + PyBytes_AsString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBytes_AsString), GetUnmanagedDll(_PythonDll)); + PyBytes_FromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBytes_FromString), GetUnmanagedDll(_PythonDll)); + PyByteArray_FromStringAndSize = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyByteArray_FromStringAndSize), GetUnmanagedDll(_PythonDll)); + PyBytes_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBytes_Size), GetUnmanagedDll(_PythonDll)); + PyUnicode_AsUTF8 = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUTF8), GetUnmanagedDll(_PythonDll)); + PyUnicode_DecodeUTF16 = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_DecodeUTF16), GetUnmanagedDll(_PythonDll)); + PyUnicode_GetLength = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_GetLength), GetUnmanagedDll(_PythonDll)); + PyUnicode_AsUnicode = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUnicode), GetUnmanagedDll(_PythonDll)); + PyUnicode_AsUTF16String = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUTF16String), GetUnmanagedDll(_PythonDll)); + PyUnicode_FromOrdinal = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_FromOrdinal), GetUnmanagedDll(_PythonDll)); + PyUnicode_InternFromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_InternFromString), GetUnmanagedDll(_PythonDll)); + PyUnicode_Compare = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_Compare), GetUnmanagedDll(_PythonDll)); + PyDict_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_New), GetUnmanagedDll(_PythonDll)); + PyDict_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_GetItem), GetUnmanagedDll(_PythonDll)); + PyDict_GetItemString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_GetItemString), GetUnmanagedDll(_PythonDll)); + PyDict_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_SetItem), GetUnmanagedDll(_PythonDll)); + PyDict_SetItemString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_SetItemString), GetUnmanagedDll(_PythonDll)); + PyDict_DelItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_DelItem), GetUnmanagedDll(_PythonDll)); + PyDict_DelItemString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_DelItemString), GetUnmanagedDll(_PythonDll)); + PyMapping_HasKey = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyMapping_HasKey), GetUnmanagedDll(_PythonDll)); + PyDict_Keys = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Keys), GetUnmanagedDll(_PythonDll)); + PyDict_Values = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Values), GetUnmanagedDll(_PythonDll)); + PyDict_Items = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Items), GetUnmanagedDll(_PythonDll)); + PyDict_Copy = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Copy), GetUnmanagedDll(_PythonDll)); + PyDict_Update = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Update), GetUnmanagedDll(_PythonDll)); + PyDict_Clear = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Clear), GetUnmanagedDll(_PythonDll)); + PyDict_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Size), GetUnmanagedDll(_PythonDll)); + PySet_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySet_New), GetUnmanagedDll(_PythonDll)); + PySet_Add = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySet_Add), GetUnmanagedDll(_PythonDll)); + PySet_Contains = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySet_Contains), GetUnmanagedDll(_PythonDll)); + PyList_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_New), GetUnmanagedDll(_PythonDll)); + PyList_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_GetItem), GetUnmanagedDll(_PythonDll)); + PyList_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_SetItem), GetUnmanagedDll(_PythonDll)); + PyList_Insert = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Insert), GetUnmanagedDll(_PythonDll)); + PyList_Append = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Append), GetUnmanagedDll(_PythonDll)); + PyList_Reverse = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Reverse), GetUnmanagedDll(_PythonDll)); + PyList_Sort = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Sort), GetUnmanagedDll(_PythonDll)); + PyList_GetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_GetSlice), GetUnmanagedDll(_PythonDll)); + PyList_SetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_SetSlice), GetUnmanagedDll(_PythonDll)); + PyList_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Size), GetUnmanagedDll(_PythonDll)); + PyTuple_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_New), GetUnmanagedDll(_PythonDll)); + PyTuple_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_GetItem), GetUnmanagedDll(_PythonDll)); + PyTuple_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_SetItem), GetUnmanagedDll(_PythonDll)); + PyTuple_GetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_GetSlice), GetUnmanagedDll(_PythonDll)); + PyTuple_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_Size), GetUnmanagedDll(_PythonDll)); + try + { + PyIter_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyIter_Check), GetUnmanagedDll(_PythonDll)); + } + catch (MissingMethodException) { } + PyIter_Next = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyIter_Next), GetUnmanagedDll(_PythonDll)); + PyModule_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyModule_New), GetUnmanagedDll(_PythonDll)); + PyModule_GetDict = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyModule_GetDict), GetUnmanagedDll(_PythonDll)); + PyModule_AddObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyModule_AddObject), GetUnmanagedDll(_PythonDll)); + PyImport_Import = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_Import), GetUnmanagedDll(_PythonDll)); + PyImport_ImportModule = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_ImportModule), GetUnmanagedDll(_PythonDll)); + PyImport_ReloadModule = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_ReloadModule), GetUnmanagedDll(_PythonDll)); + PyImport_AddModule = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_AddModule), GetUnmanagedDll(_PythonDll)); + PyImport_GetModuleDict = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_GetModuleDict), GetUnmanagedDll(_PythonDll)); + PySys_SetArgvEx = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySys_SetArgvEx), GetUnmanagedDll(_PythonDll)); + PySys_GetObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySys_GetObject), GetUnmanagedDll(_PythonDll)); + PySys_SetObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySys_SetObject), GetUnmanagedDll(_PythonDll)); + PyType_Modified = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_Modified), GetUnmanagedDll(_PythonDll)); + PyType_IsSubtype = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_IsSubtype), GetUnmanagedDll(_PythonDll)); + PyType_GenericNew = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_GenericNew), GetUnmanagedDll(_PythonDll)); + PyType_GenericAlloc = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_GenericAlloc), GetUnmanagedDll(_PythonDll)); + PyType_Ready = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_Ready), GetUnmanagedDll(_PythonDll)); + _PyType_Lookup = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_PyType_Lookup), GetUnmanagedDll(_PythonDll)); + PyObject_GenericGetAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GenericGetAttr), GetUnmanagedDll(_PythonDll)); + PyObject_GenericGetDict = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GenericGetDict), GetUnmanagedDll(PythonDLL)); + PyObject_GenericSetAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GenericSetAttr), GetUnmanagedDll(_PythonDll)); + PyObject_GC_Del = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GC_Del), GetUnmanagedDll(_PythonDll)); + try + { + PyObject_GC_IsTracked = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GC_IsTracked), GetUnmanagedDll(_PythonDll)); + } + catch (MissingMethodException) { } + PyObject_GC_Track = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GC_Track), GetUnmanagedDll(_PythonDll)); + PyObject_GC_UnTrack = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GC_UnTrack), GetUnmanagedDll(_PythonDll)); + _PyObject_Dump = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_PyObject_Dump), GetUnmanagedDll(_PythonDll)); + PyMem_Malloc = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyMem_Malloc), GetUnmanagedDll(_PythonDll)); + PyMem_Realloc = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyMem_Realloc), GetUnmanagedDll(_PythonDll)); + PyMem_Free = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyMem_Free), GetUnmanagedDll(_PythonDll)); + PyErr_SetString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_SetString), GetUnmanagedDll(_PythonDll)); + PyErr_SetObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_SetObject), GetUnmanagedDll(_PythonDll)); + PyErr_ExceptionMatches = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_ExceptionMatches), GetUnmanagedDll(_PythonDll)); + PyErr_GivenExceptionMatches = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_GivenExceptionMatches), GetUnmanagedDll(_PythonDll)); + PyErr_NormalizeException = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_NormalizeException), GetUnmanagedDll(_PythonDll)); + PyErr_Occurred = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Occurred), GetUnmanagedDll(_PythonDll)); + PyErr_Fetch = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Fetch), GetUnmanagedDll(_PythonDll)); + PyErr_Restore = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Restore), GetUnmanagedDll(_PythonDll)); + PyErr_Clear = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Clear), GetUnmanagedDll(_PythonDll)); + PyErr_Print = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Print), GetUnmanagedDll(_PythonDll)); + PyCell_Get = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCell_Get), GetUnmanagedDll(_PythonDll)); + PyCell_Set = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCell_Set), GetUnmanagedDll(_PythonDll)); + PyGC_Collect = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGC_Collect), GetUnmanagedDll(_PythonDll)); + PyCapsule_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCapsule_New), GetUnmanagedDll(_PythonDll)); + PyCapsule_GetPointer = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCapsule_GetPointer), GetUnmanagedDll(_PythonDll)); + PyCapsule_SetPointer = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCapsule_SetPointer), GetUnmanagedDll(_PythonDll)); + PyLong_AsUnsignedSize_t = (delegate* unmanaged[Cdecl])GetFunctionByName("PyLong_AsSize_t", GetUnmanagedDll(_PythonDll)); + PyLong_AsSignedSize_t = (delegate* unmanaged[Cdecl])GetFunctionByName("PyLong_AsSsize_t", GetUnmanagedDll(_PythonDll)); + PyDict_GetItemWithError = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_GetItemWithError), GetUnmanagedDll(_PythonDll)); + PyException_GetCause = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyException_GetCause), GetUnmanagedDll(_PythonDll)); + PyException_GetTraceback = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyException_GetTraceback), GetUnmanagedDll(_PythonDll)); + PyException_SetCause = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyException_SetCause), GetUnmanagedDll(_PythonDll)); + PyException_SetTraceback = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyException_SetTraceback), GetUnmanagedDll(_PythonDll)); + PyThreadState_SetAsyncExcLLP64 = (delegate* unmanaged[Cdecl])GetFunctionByName("PyThreadState_SetAsyncExc", GetUnmanagedDll(_PythonDll)); + PyThreadState_SetAsyncExcLP64 = (delegate* unmanaged[Cdecl])GetFunctionByName("PyThreadState_SetAsyncExc", GetUnmanagedDll(_PythonDll)); + PyType_GetSlot = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_GetSlot), GetUnmanagedDll(_PythonDll)); + PyType_FromSpecWithBases = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_FromSpecWithBases), GetUnmanagedDll(PythonDLL)); + + try + { + _Py_NewReference = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_Py_NewReference), GetUnmanagedDll(_PythonDll)); + } + catch (MissingMethodException) { } + try + { + _Py_IsFinalizing = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_Py_IsFinalizing), GetUnmanagedDll(_PythonDll)); + } + 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) + { + if (libraryName is null) return IntPtr.Zero; + return libraryLoader.Load(libraryName); + } + + static global::System.IntPtr GetFunctionByName(string functionName, global::System.IntPtr libraryHandle) + { + try + { + return libraryLoader.GetFunction(libraryHandle, functionName); + } + catch (MissingMethodException e) when (libraryHandle == IntPtr.Zero) + { + throw new BadPythonDllException( + "Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL." + + " See https://github.com/pythonnet/pythonnet#embedding-python-in-net", + e); + } + } + + internal static delegate* unmanaged[Cdecl] Py_IncRef { get; } + internal static delegate* unmanaged[Cdecl] Py_DecRef { get; } + internal static delegate* unmanaged[Cdecl] Py_Initialize { get; } + internal static delegate* unmanaged[Cdecl] Py_InitializeEx { get; } + internal static delegate* unmanaged[Cdecl] Py_IsInitialized { get; } + internal static delegate* unmanaged[Cdecl] Py_Finalize { get; } + internal static delegate* unmanaged[Cdecl] Py_NewInterpreter { get; } + internal static delegate* unmanaged[Cdecl] Py_EndInterpreter { get; } + internal static delegate* unmanaged[Cdecl] PyThreadState_New { get; } + internal static delegate* unmanaged[Cdecl] PyThreadState_Get { get; } + internal static delegate* unmanaged[Cdecl] _PyThreadState_UncheckedGet { get; } + internal static delegate* unmanaged[Cdecl] PyGILState_Check { get; } + internal static delegate* unmanaged[Cdecl] PyGILState_Ensure { get; } + internal static delegate* unmanaged[Cdecl] PyGILState_Release { get; } + internal static delegate* unmanaged[Cdecl] PyGILState_GetThisThreadState { get; } + internal static delegate* unmanaged[Cdecl] Py_Main { get; } + internal static delegate* unmanaged[Cdecl] PyEval_InitThreads { get; } + internal static delegate* unmanaged[Cdecl] PyEval_ThreadsInitialized { get; } + internal static delegate* unmanaged[Cdecl] PyEval_AcquireLock { get; } + internal static delegate* unmanaged[Cdecl] PyEval_ReleaseLock { get; } + internal static delegate* unmanaged[Cdecl] PyEval_AcquireThread { get; } + internal static delegate* unmanaged[Cdecl] PyEval_ReleaseThread { get; } + internal static delegate* unmanaged[Cdecl] PyEval_SaveThread { get; } + internal static delegate* unmanaged[Cdecl] PyEval_RestoreThread { get; } + internal static delegate* unmanaged[Cdecl] PyEval_GetBuiltins { get; } + internal static delegate* unmanaged[Cdecl] PyEval_GetGlobals { get; } + internal static delegate* unmanaged[Cdecl] PyEval_GetLocals { get; } + internal static delegate* unmanaged[Cdecl] Py_GetProgramName { get; } + internal static delegate* unmanaged[Cdecl] Py_SetProgramName { get; } + internal static delegate* unmanaged[Cdecl] Py_GetPythonHome { get; } + internal static delegate* unmanaged[Cdecl] Py_SetPythonHome { get; } + internal static delegate* unmanaged[Cdecl] Py_GetPath { get; } + internal static delegate* unmanaged[Cdecl] Py_SetPath { get; } + internal static delegate* unmanaged[Cdecl] Py_GetVersion { get; } + internal static delegate* unmanaged[Cdecl] Py_GetPlatform { get; } + internal static delegate* unmanaged[Cdecl] Py_GetCopyright { get; } + internal static delegate* unmanaged[Cdecl] Py_GetCompiler { get; } + internal static delegate* unmanaged[Cdecl] Py_GetBuildInfo { get; } + internal static delegate* unmanaged[Cdecl] PyRun_SimpleStringFlags { get; } + internal static delegate* unmanaged[Cdecl] PyRun_StringFlags { get; } + internal static delegate* unmanaged[Cdecl] PyEval_EvalCode { get; } + internal static delegate* unmanaged[Cdecl] Py_CompileStringObject { get; } + internal static delegate* unmanaged[Cdecl] PyImport_ExecCodeModule { get; } + internal static delegate* unmanaged[Cdecl] PyObject_HasAttrString { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GetAttrString { get; } + internal static delegate* unmanaged[Cdecl] PyObject_SetAttrString { get; } + internal static delegate* unmanaged[Cdecl] PyObject_HasAttr { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GetAttr { get; } + internal static delegate* unmanaged[Cdecl] PyObject_SetAttr { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GetItem { get; } + internal static delegate* unmanaged[Cdecl] PyObject_SetItem { get; } + internal static delegate* unmanaged[Cdecl] PyObject_DelItem { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GetIter { get; } + internal static delegate* unmanaged[Cdecl] PyObject_Call { get; } + internal static delegate* unmanaged[Cdecl] PyObject_CallObject { get; } + internal static delegate* unmanaged[Cdecl] PyObject_RichCompareBool { get; } + internal static delegate* unmanaged[Cdecl] PyObject_IsInstance { get; } + internal static delegate* unmanaged[Cdecl] PyObject_IsSubclass { get; } + internal static delegate* unmanaged[Cdecl] PyCallable_Check { get; } + internal static delegate* unmanaged[Cdecl] PyObject_IsTrue { get; } + internal static delegate* unmanaged[Cdecl] PyObject_Not { get; } + internal static delegate* unmanaged[Cdecl] PyObject_Size { get; } + internal static delegate* unmanaged[Cdecl] PyObject_Hash { get; } + internal static delegate* unmanaged[Cdecl] PyObject_Repr { get; } + internal static delegate* unmanaged[Cdecl] PyObject_Str { get; } + internal static delegate* unmanaged[Cdecl] PyObject_Type { get; } + internal static delegate* unmanaged[Cdecl] PyObject_Dir { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GetBuffer { get; } + internal static delegate* unmanaged[Cdecl] PyBuffer_Release { get; } + internal static delegate* unmanaged[Cdecl] PyBuffer_SizeFromFormat { get; } + internal static delegate* unmanaged[Cdecl] PyBuffer_IsContiguous { get; } + internal static delegate* unmanaged[Cdecl] PyBuffer_GetPointer { get; } + internal static delegate* unmanaged[Cdecl] PyBuffer_FromContiguous { get; } + internal static delegate* unmanaged[Cdecl] PyBuffer_ToContiguous { get; } + internal static delegate* unmanaged[Cdecl] PyBuffer_FillContiguousStrides { get; } + internal static delegate* unmanaged[Cdecl] PyBuffer_FillInfo { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Long { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Float { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Check { get; } + internal static delegate* unmanaged[Cdecl] PyLong_FromLongLong { get; } + internal static delegate* unmanaged[Cdecl] PyLong_FromUnsignedLongLong { get; } + internal static delegate* unmanaged[Cdecl] PyLong_FromString { get; } + internal static delegate* unmanaged[Cdecl] PyLong_AsLongLong { get; } + internal static delegate* unmanaged[Cdecl] PyLong_AsUnsignedLongLong { get; } + internal static delegate* unmanaged[Cdecl] PyLong_FromVoidPtr { get; } + internal static delegate* unmanaged[Cdecl] PyLong_AsVoidPtr { get; } + internal static delegate* unmanaged[Cdecl] PyFloat_FromDouble { get; } + internal static delegate* unmanaged[Cdecl] PyFloat_FromString { get; } + internal static delegate* unmanaged[Cdecl] PyFloat_AsDouble { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Add { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Subtract { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Multiply { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_TrueDivide { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_And { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Xor { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Or { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Lshift { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Rshift { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Power { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Remainder { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceAdd { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceSubtract { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceMultiply { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceTrueDivide { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceAnd { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceXor { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceOr { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceLshift { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceRshift { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlacePower { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceRemainder { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Negative { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Positive { get; } + internal static delegate* unmanaged[Cdecl] PyNumber_Invert { get; } + internal static delegate* unmanaged[Cdecl] PySequence_Check { get; } + internal static delegate* unmanaged[Cdecl] PySequence_GetItem { get; } + internal static delegate* unmanaged[Cdecl] PySequence_SetItem { get; } + internal static delegate* unmanaged[Cdecl] PySequence_DelItem { get; } + internal static delegate* unmanaged[Cdecl] PySequence_GetSlice { get; } + internal static delegate* unmanaged[Cdecl] PySequence_SetSlice { get; } + internal static delegate* unmanaged[Cdecl] PySequence_DelSlice { get; } + internal static delegate* unmanaged[Cdecl] PySequence_Size { get; } + internal static delegate* unmanaged[Cdecl] PySequence_Contains { get; } + internal static delegate* unmanaged[Cdecl] PySequence_Concat { get; } + internal static delegate* unmanaged[Cdecl] PySequence_Repeat { get; } + internal static delegate* unmanaged[Cdecl] PySequence_Index { get; } + internal static delegate* unmanaged[Cdecl] PySequence_Count { get; } + internal static delegate* unmanaged[Cdecl] PySequence_Tuple { get; } + internal static delegate* unmanaged[Cdecl] PySequence_List { get; } + internal static delegate* unmanaged[Cdecl] PyBytes_AsString { get; } + internal static delegate* unmanaged[Cdecl] PyBytes_FromString { get; } + internal static delegate* unmanaged[Cdecl] PyByteArray_FromStringAndSize { get; } + internal static delegate* unmanaged[Cdecl] PyBytes_Size { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_AsUTF8 { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_DecodeUTF16 { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_GetLength { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_AsUnicode { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_AsUTF16String { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_FromOrdinal { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_InternFromString { get; } + internal static delegate* unmanaged[Cdecl] PyUnicode_Compare { get; } + internal static delegate* unmanaged[Cdecl] PyDict_New { get; } + internal static delegate* unmanaged[Cdecl] PyDict_GetItem { get; } + internal static delegate* unmanaged[Cdecl] PyDict_GetItemString { get; } + internal static delegate* unmanaged[Cdecl] PyDict_SetItem { get; } + internal static delegate* unmanaged[Cdecl] PyDict_SetItemString { get; } + internal static delegate* unmanaged[Cdecl] PyDict_DelItem { get; } + internal static delegate* unmanaged[Cdecl] PyDict_DelItemString { get; } + internal static delegate* unmanaged[Cdecl] PyMapping_HasKey { get; } + internal static delegate* unmanaged[Cdecl] PyDict_Keys { get; } + internal static delegate* unmanaged[Cdecl] PyDict_Values { get; } + internal static delegate* unmanaged[Cdecl] PyDict_Items { get; } + internal static delegate* unmanaged[Cdecl] PyDict_Copy { get; } + internal static delegate* unmanaged[Cdecl] PyDict_Update { get; } + internal static delegate* unmanaged[Cdecl] PyDict_Clear { get; } + internal static delegate* unmanaged[Cdecl] PyDict_Size { get; } + internal static delegate* unmanaged[Cdecl] PySet_New { get; } + internal static delegate* unmanaged[Cdecl] PySet_Add { get; } + internal static delegate* unmanaged[Cdecl] PySet_Contains { get; } + internal static delegate* unmanaged[Cdecl] PyList_New { get; } + internal static delegate* unmanaged[Cdecl] PyList_GetItem { get; } + internal static delegate* unmanaged[Cdecl] PyList_SetItem { get; } + internal static delegate* unmanaged[Cdecl] PyList_Insert { get; } + internal static delegate* unmanaged[Cdecl] PyList_Append { get; } + internal static delegate* unmanaged[Cdecl] PyList_Reverse { get; } + internal static delegate* unmanaged[Cdecl] PyList_Sort { get; } + internal static delegate* unmanaged[Cdecl] PyList_GetSlice { get; } + internal static delegate* unmanaged[Cdecl] PyList_SetSlice { get; } + internal static delegate* unmanaged[Cdecl] PyList_Size { get; } + internal static delegate* unmanaged[Cdecl] PyTuple_New { get; } + internal static delegate* unmanaged[Cdecl] PyTuple_GetItem { get; } + internal static delegate* unmanaged[Cdecl] PyTuple_SetItem { get; } + internal static delegate* unmanaged[Cdecl] PyTuple_GetSlice { get; } + internal static delegate* unmanaged[Cdecl] PyTuple_Size { get; } + internal static delegate* unmanaged[Cdecl] PyIter_Check { get; } + internal static delegate* unmanaged[Cdecl] PyIter_Next { get; } + internal static delegate* unmanaged[Cdecl] PyModule_New { get; } + internal static delegate* unmanaged[Cdecl] PyModule_GetDict { get; } + internal static delegate* unmanaged[Cdecl] PyModule_AddObject { get; } + internal static delegate* unmanaged[Cdecl] PyImport_Import { get; } + internal static delegate* unmanaged[Cdecl] PyImport_ImportModule { get; } + internal static delegate* unmanaged[Cdecl] PyImport_ReloadModule { get; } + internal static delegate* unmanaged[Cdecl] PyImport_AddModule { get; } + internal static delegate* unmanaged[Cdecl] PyImport_GetModuleDict { get; } + internal static delegate* unmanaged[Cdecl] PySys_SetArgvEx { get; } + internal static delegate* unmanaged[Cdecl] PySys_GetObject { get; } + internal static delegate* unmanaged[Cdecl] PySys_SetObject { get; } + internal static delegate* unmanaged[Cdecl] PyType_Modified { get; } + internal static delegate* unmanaged[Cdecl] PyType_IsSubtype { get; } + internal static delegate* unmanaged[Cdecl] PyType_GenericNew { get; } + internal static delegate* unmanaged[Cdecl] PyType_GenericAlloc { get; } + internal static delegate* unmanaged[Cdecl] PyType_Ready { get; } + internal static delegate* unmanaged[Cdecl] _PyType_Lookup { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GenericGetAttr { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GenericSetAttr { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GC_Del { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GC_IsTracked { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GC_Track { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GC_UnTrack { get; } + internal static delegate* unmanaged[Cdecl] _PyObject_Dump { get; } + internal static delegate* unmanaged[Cdecl] PyMem_Malloc { get; } + internal static delegate* unmanaged[Cdecl] PyMem_Realloc { get; } + internal static delegate* unmanaged[Cdecl] PyMem_Free { get; } + internal static delegate* unmanaged[Cdecl] PyErr_SetString { get; } + internal static delegate* unmanaged[Cdecl] PyErr_SetObject { get; } + internal static delegate* unmanaged[Cdecl] PyErr_ExceptionMatches { get; } + internal static delegate* unmanaged[Cdecl] PyErr_GivenExceptionMatches { get; } + internal static delegate* unmanaged[Cdecl] PyErr_NormalizeException { get; } + internal static delegate* unmanaged[Cdecl] PyErr_Occurred { get; } + internal static delegate* unmanaged[Cdecl] PyErr_Fetch { get; } + internal static delegate* unmanaged[Cdecl] PyErr_Restore { get; } + internal static delegate* unmanaged[Cdecl] PyErr_Clear { get; } + internal static delegate* unmanaged[Cdecl] PyErr_Print { get; } + internal static delegate* unmanaged[Cdecl] PyCell_Get { get; } + internal static delegate* unmanaged[Cdecl] PyCell_Set { get; } + internal static delegate* unmanaged[Cdecl] PyGC_Collect { get; } + internal static delegate* unmanaged[Cdecl] PyCapsule_New { get; } + internal static delegate* unmanaged[Cdecl] PyCapsule_GetPointer { get; } + internal static delegate* unmanaged[Cdecl] PyCapsule_SetPointer { get; } + internal static delegate* unmanaged[Cdecl] PyLong_AsUnsignedSize_t { get; } + internal static delegate* unmanaged[Cdecl] PyLong_AsSignedSize_t { get; } + internal static delegate* unmanaged[Cdecl] PyDict_GetItemWithError { get; } + internal static delegate* unmanaged[Cdecl] PyException_GetCause { get; } + internal static delegate* unmanaged[Cdecl] PyException_GetTraceback { get; } + internal static delegate* unmanaged[Cdecl] PyException_SetCause { get; } + internal static delegate* unmanaged[Cdecl] PyException_SetTraceback { get; } + internal static delegate* unmanaged[Cdecl] PyThreadState_SetAsyncExcLLP64 { get; } + internal static delegate* unmanaged[Cdecl] PyThreadState_SetAsyncExcLP64 { get; } + internal static delegate* unmanaged[Cdecl] PyObject_GenericGetDict { get; } + internal static delegate* unmanaged[Cdecl] PyType_GetSlot { get; } + internal static delegate* unmanaged[Cdecl] PyType_FromSpecWithBases { get; } + internal static delegate* unmanaged[Cdecl] _Py_NewReference { get; } + internal static delegate* unmanaged[Cdecl] _Py_IsFinalizing { get; } + internal static IntPtr PyType_Type { get; } + internal static int* Py_NoSiteFlag { get; } + } +} diff --git a/src/runtime/runtime.cs b/src/runtime/Runtime.cs similarity index 51% rename from src/runtime/runtime.cs rename to src/runtime/Runtime.cs index c8489f7cf..7806c3156 100644 --- a/src/runtime/runtime.cs +++ b/src/runtime/Runtime.cs @@ -6,7 +6,6 @@ using System.Threading; using System.Collections.Generic; using Python.Runtime.Native; -using Python.Runtime.Platform; using System.Linq; using static System.FormattableString; @@ -17,7 +16,7 @@ namespace Python.Runtime /// the responsibility of the caller to have acquired the GIL /// before calling any of these methods. /// - public unsafe class Runtime + public unsafe partial class Runtime { public static string? PythonDLL { @@ -538,26 +537,6 @@ internal static void CheckExceptionOccurred() } } - internal static NewReference ExtendTuple(BorrowedReference t, params PyObject[] args) - { - var size = PyTuple_Size(t); - int add = args.Length; - - NewReference items = PyTuple_New(size + add); - for (var i = 0; i < size; i++) - { - var item = PyTuple_GetItem(t, i); - PyTuple_SetItem(items.Borrow(), i, item); - } - - for (var n = 0; n < add; n++) - { - PyTuple_SetItem(items.Borrow(), size + n, args[n]); - } - - return items; - } - internal static Type[]? PythonArgsToTypeArray(BorrowedReference arg) { return PythonArgsToTypeArray(arg, false); @@ -1832,17 +1811,6 @@ internal static int PyException_SetTraceback(BorrowedReference ex, BorrowedRefer internal static int PyCell_Set(BorrowedReference cell, BorrowedReference value) => Delegates.PyCell_Set(cell, value); - //==================================================================== - // Python GC API - //==================================================================== - - internal const int _PyGC_REFS_SHIFT = 1; - internal const long _PyGC_REFS_UNTRACKED = -2; - internal const long _PyGC_REFS_REACHABLE = -3; - internal const long _PyGC_REFS_TENTATIVELY_UNREACHABLE = -4; - - - internal static nint PyGC_Collect() => Delegates.PyGC_Collect(); internal static void Py_CLEAR(BorrowedReference ob, int offset) => ReplaceReference(ob, offset, default); internal static void Py_CLEAR(ref T? ob) @@ -1892,537 +1860,6 @@ internal static void SetNoSiteFlag() return *Delegates.Py_NoSiteFlag; }); } - - internal static class Delegates - { - static readonly ILibraryLoader libraryLoader = LibraryLoader.Instance; - - static Delegates() - { - Py_IncRef = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_IncRef), GetUnmanagedDll(_PythonDll)); - Py_DecRef = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_DecRef), GetUnmanagedDll(_PythonDll)); - Py_Initialize = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_Initialize), GetUnmanagedDll(_PythonDll)); - Py_InitializeEx = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_InitializeEx), GetUnmanagedDll(_PythonDll)); - Py_IsInitialized = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_IsInitialized), GetUnmanagedDll(_PythonDll)); - Py_Finalize = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_Finalize), GetUnmanagedDll(_PythonDll)); - Py_NewInterpreter = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_NewInterpreter), GetUnmanagedDll(_PythonDll)); - Py_EndInterpreter = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_EndInterpreter), GetUnmanagedDll(_PythonDll)); - PyThreadState_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyThreadState_New), GetUnmanagedDll(_PythonDll)); - PyThreadState_Get = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyThreadState_Get), GetUnmanagedDll(_PythonDll)); - _PyThreadState_UncheckedGet = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_PyThreadState_UncheckedGet), GetUnmanagedDll(_PythonDll)); - try - { - PyGILState_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGILState_Check), GetUnmanagedDll(_PythonDll)); - } - catch (MissingMethodException e) - { - throw new NotSupportedException(Util.MinimalPythonVersionRequired, innerException: e); - } - PyGILState_Ensure = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGILState_Ensure), GetUnmanagedDll(_PythonDll)); - PyGILState_Release = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGILState_Release), GetUnmanagedDll(_PythonDll)); - PyGILState_GetThisThreadState = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGILState_GetThisThreadState), GetUnmanagedDll(_PythonDll)); - Py_Main = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_Main), GetUnmanagedDll(_PythonDll)); - PyEval_InitThreads = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_InitThreads), GetUnmanagedDll(_PythonDll)); - PyEval_ThreadsInitialized = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_ThreadsInitialized), GetUnmanagedDll(_PythonDll)); - PyEval_AcquireLock = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_AcquireLock), GetUnmanagedDll(_PythonDll)); - PyEval_ReleaseLock = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_ReleaseLock), GetUnmanagedDll(_PythonDll)); - PyEval_AcquireThread = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_AcquireThread), GetUnmanagedDll(_PythonDll)); - PyEval_ReleaseThread = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_ReleaseThread), GetUnmanagedDll(_PythonDll)); - PyEval_SaveThread = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_SaveThread), GetUnmanagedDll(_PythonDll)); - PyEval_RestoreThread = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_RestoreThread), GetUnmanagedDll(_PythonDll)); - PyEval_GetBuiltins = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_GetBuiltins), GetUnmanagedDll(_PythonDll)); - PyEval_GetGlobals = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_GetGlobals), GetUnmanagedDll(_PythonDll)); - PyEval_GetLocals = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_GetLocals), GetUnmanagedDll(_PythonDll)); - Py_GetProgramName = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetProgramName), GetUnmanagedDll(_PythonDll)); - Py_SetProgramName = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_SetProgramName), GetUnmanagedDll(_PythonDll)); - Py_GetPythonHome = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetPythonHome), GetUnmanagedDll(_PythonDll)); - Py_SetPythonHome = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_SetPythonHome), GetUnmanagedDll(_PythonDll)); - Py_GetPath = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetPath), GetUnmanagedDll(_PythonDll)); - Py_SetPath = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_SetPath), GetUnmanagedDll(_PythonDll)); - Py_GetVersion = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetVersion), GetUnmanagedDll(_PythonDll)); - Py_GetPlatform = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetPlatform), GetUnmanagedDll(_PythonDll)); - Py_GetCopyright = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetCopyright), GetUnmanagedDll(_PythonDll)); - Py_GetCompiler = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetCompiler), GetUnmanagedDll(_PythonDll)); - Py_GetBuildInfo = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_GetBuildInfo), GetUnmanagedDll(_PythonDll)); - PyRun_SimpleStringFlags = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyRun_SimpleStringFlags), GetUnmanagedDll(_PythonDll)); - PyRun_StringFlags = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyRun_StringFlags), GetUnmanagedDll(_PythonDll)); - PyEval_EvalCode = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyEval_EvalCode), GetUnmanagedDll(_PythonDll)); - Py_CompileStringObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(Py_CompileStringObject), GetUnmanagedDll(_PythonDll)); - PyImport_ExecCodeModule = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_ExecCodeModule), GetUnmanagedDll(_PythonDll)); - PyObject_HasAttrString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_HasAttrString), GetUnmanagedDll(_PythonDll)); - PyObject_GetAttrString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetAttrString), GetUnmanagedDll(_PythonDll)); - PyObject_SetAttrString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_SetAttrString), GetUnmanagedDll(_PythonDll)); - PyObject_HasAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_HasAttr), GetUnmanagedDll(_PythonDll)); - PyObject_GetAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetAttr), GetUnmanagedDll(_PythonDll)); - PyObject_SetAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_SetAttr), GetUnmanagedDll(_PythonDll)); - PyObject_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetItem), GetUnmanagedDll(_PythonDll)); - PyObject_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_SetItem), GetUnmanagedDll(_PythonDll)); - PyObject_DelItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_DelItem), GetUnmanagedDll(_PythonDll)); - PyObject_GetIter = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetIter), GetUnmanagedDll(_PythonDll)); - PyObject_Call = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Call), GetUnmanagedDll(_PythonDll)); - PyObject_CallObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_CallObject), GetUnmanagedDll(_PythonDll)); - PyObject_RichCompareBool = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_RichCompareBool), GetUnmanagedDll(_PythonDll)); - PyObject_IsInstance = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_IsInstance), GetUnmanagedDll(_PythonDll)); - PyObject_IsSubclass = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_IsSubclass), GetUnmanagedDll(_PythonDll)); - PyCallable_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCallable_Check), GetUnmanagedDll(_PythonDll)); - PyObject_IsTrue = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_IsTrue), GetUnmanagedDll(_PythonDll)); - PyObject_Not = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Not), GetUnmanagedDll(_PythonDll)); - PyObject_Size = (delegate* unmanaged[Cdecl])GetFunctionByName("PyObject_Size", GetUnmanagedDll(_PythonDll)); - PyObject_Hash = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Hash), GetUnmanagedDll(_PythonDll)); - PyObject_Repr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Repr), GetUnmanagedDll(_PythonDll)); - PyObject_Str = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Str), GetUnmanagedDll(_PythonDll)); - PyObject_Type = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Type), GetUnmanagedDll(_PythonDll)); - PyObject_Dir = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_Dir), GetUnmanagedDll(_PythonDll)); - PyObject_GetBuffer = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GetBuffer), GetUnmanagedDll(_PythonDll)); - PyBuffer_Release = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_Release), GetUnmanagedDll(_PythonDll)); - try - { - PyBuffer_SizeFromFormat = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_SizeFromFormat), GetUnmanagedDll(_PythonDll)); - } - catch (MissingMethodException) - { - // only in 3.9+ - } - PyBuffer_IsContiguous = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_IsContiguous), GetUnmanagedDll(_PythonDll)); - PyBuffer_GetPointer = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_GetPointer), GetUnmanagedDll(_PythonDll)); - PyBuffer_FromContiguous = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_FromContiguous), GetUnmanagedDll(_PythonDll)); - PyBuffer_ToContiguous = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_ToContiguous), GetUnmanagedDll(_PythonDll)); - PyBuffer_FillContiguousStrides = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_FillContiguousStrides), GetUnmanagedDll(_PythonDll)); - PyBuffer_FillInfo = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBuffer_FillInfo), GetUnmanagedDll(_PythonDll)); - PyNumber_Long = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Long), GetUnmanagedDll(_PythonDll)); - PyNumber_Float = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Float), GetUnmanagedDll(_PythonDll)); - PyNumber_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Check), GetUnmanagedDll(_PythonDll)); - PyLong_FromLongLong = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_FromLongLong), GetUnmanagedDll(_PythonDll)); - PyLong_FromUnsignedLongLong = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_FromUnsignedLongLong), GetUnmanagedDll(_PythonDll)); - PyLong_FromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_FromString), GetUnmanagedDll(_PythonDll)); - PyLong_AsLongLong = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_AsLongLong), GetUnmanagedDll(_PythonDll)); - PyLong_AsUnsignedLongLong = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_AsUnsignedLongLong), GetUnmanagedDll(_PythonDll)); - PyLong_FromVoidPtr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_FromVoidPtr), GetUnmanagedDll(_PythonDll)); - PyLong_AsVoidPtr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyLong_AsVoidPtr), GetUnmanagedDll(_PythonDll)); - PyFloat_FromDouble = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyFloat_FromDouble), GetUnmanagedDll(_PythonDll)); - PyFloat_FromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyFloat_FromString), GetUnmanagedDll(_PythonDll)); - PyFloat_AsDouble = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyFloat_AsDouble), GetUnmanagedDll(_PythonDll)); - PyNumber_Add = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Add), GetUnmanagedDll(_PythonDll)); - PyNumber_Subtract = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Subtract), GetUnmanagedDll(_PythonDll)); - PyNumber_Multiply = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Multiply), GetUnmanagedDll(_PythonDll)); - PyNumber_TrueDivide = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_TrueDivide), GetUnmanagedDll(_PythonDll)); - PyNumber_And = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_And), GetUnmanagedDll(_PythonDll)); - PyNumber_Xor = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Xor), GetUnmanagedDll(_PythonDll)); - PyNumber_Or = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Or), GetUnmanagedDll(_PythonDll)); - PyNumber_Lshift = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Lshift), GetUnmanagedDll(_PythonDll)); - PyNumber_Rshift = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Rshift), GetUnmanagedDll(_PythonDll)); - PyNumber_Power = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Power), GetUnmanagedDll(_PythonDll)); - PyNumber_Remainder = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Remainder), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceAdd = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceAdd), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceSubtract = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceSubtract), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceMultiply = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceMultiply), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceTrueDivide = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceTrueDivide), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceAnd = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceAnd), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceXor = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceXor), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceOr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceOr), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceLshift = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceLshift), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceRshift = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceRshift), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlacePower = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlacePower), GetUnmanagedDll(_PythonDll)); - PyNumber_InPlaceRemainder = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_InPlaceRemainder), GetUnmanagedDll(_PythonDll)); - PyNumber_Negative = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Negative), GetUnmanagedDll(_PythonDll)); - PyNumber_Positive = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Positive), GetUnmanagedDll(_PythonDll)); - PyNumber_Invert = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyNumber_Invert), GetUnmanagedDll(_PythonDll)); - PySequence_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Check), GetUnmanagedDll(_PythonDll)); - PySequence_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_GetItem), GetUnmanagedDll(_PythonDll)); - PySequence_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_SetItem), GetUnmanagedDll(_PythonDll)); - PySequence_DelItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_DelItem), GetUnmanagedDll(_PythonDll)); - PySequence_GetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_GetSlice), GetUnmanagedDll(_PythonDll)); - PySequence_SetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_SetSlice), GetUnmanagedDll(_PythonDll)); - PySequence_DelSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_DelSlice), GetUnmanagedDll(_PythonDll)); - PySequence_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Size), GetUnmanagedDll(_PythonDll)); - PySequence_Contains = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Contains), GetUnmanagedDll(_PythonDll)); - PySequence_Concat = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Concat), GetUnmanagedDll(_PythonDll)); - PySequence_Repeat = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Repeat), GetUnmanagedDll(_PythonDll)); - PySequence_Index = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Index), GetUnmanagedDll(_PythonDll)); - PySequence_Count = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Count), GetUnmanagedDll(_PythonDll)); - PySequence_Tuple = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_Tuple), GetUnmanagedDll(_PythonDll)); - PySequence_List = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySequence_List), GetUnmanagedDll(_PythonDll)); - PyBytes_AsString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBytes_AsString), GetUnmanagedDll(_PythonDll)); - PyBytes_FromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBytes_FromString), GetUnmanagedDll(_PythonDll)); - PyByteArray_FromStringAndSize = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyByteArray_FromStringAndSize), GetUnmanagedDll(_PythonDll)); - PyBytes_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyBytes_Size), GetUnmanagedDll(_PythonDll)); - PyUnicode_AsUTF8 = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUTF8), GetUnmanagedDll(_PythonDll)); - PyUnicode_DecodeUTF16 = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_DecodeUTF16), GetUnmanagedDll(_PythonDll)); - PyUnicode_GetLength = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_GetLength), GetUnmanagedDll(_PythonDll)); - PyUnicode_AsUnicode = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUnicode), GetUnmanagedDll(_PythonDll)); - PyUnicode_AsUTF16String = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_AsUTF16String), GetUnmanagedDll(_PythonDll)); - PyUnicode_FromOrdinal = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_FromOrdinal), GetUnmanagedDll(_PythonDll)); - PyUnicode_InternFromString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_InternFromString), GetUnmanagedDll(_PythonDll)); - PyUnicode_Compare = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyUnicode_Compare), GetUnmanagedDll(_PythonDll)); - PyDict_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_New), GetUnmanagedDll(_PythonDll)); - PyDict_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_GetItem), GetUnmanagedDll(_PythonDll)); - PyDict_GetItemString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_GetItemString), GetUnmanagedDll(_PythonDll)); - PyDict_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_SetItem), GetUnmanagedDll(_PythonDll)); - PyDict_SetItemString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_SetItemString), GetUnmanagedDll(_PythonDll)); - PyDict_DelItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_DelItem), GetUnmanagedDll(_PythonDll)); - PyDict_DelItemString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_DelItemString), GetUnmanagedDll(_PythonDll)); - PyMapping_HasKey = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyMapping_HasKey), GetUnmanagedDll(_PythonDll)); - PyDict_Keys = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Keys), GetUnmanagedDll(_PythonDll)); - PyDict_Values = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Values), GetUnmanagedDll(_PythonDll)); - PyDict_Items = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Items), GetUnmanagedDll(_PythonDll)); - PyDict_Copy = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Copy), GetUnmanagedDll(_PythonDll)); - PyDict_Update = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Update), GetUnmanagedDll(_PythonDll)); - PyDict_Clear = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Clear), GetUnmanagedDll(_PythonDll)); - PyDict_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_Size), GetUnmanagedDll(_PythonDll)); - PySet_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySet_New), GetUnmanagedDll(_PythonDll)); - PySet_Add = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySet_Add), GetUnmanagedDll(_PythonDll)); - PySet_Contains = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySet_Contains), GetUnmanagedDll(_PythonDll)); - PyList_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_New), GetUnmanagedDll(_PythonDll)); - PyList_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_GetItem), GetUnmanagedDll(_PythonDll)); - PyList_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_SetItem), GetUnmanagedDll(_PythonDll)); - PyList_Insert = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Insert), GetUnmanagedDll(_PythonDll)); - PyList_Append = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Append), GetUnmanagedDll(_PythonDll)); - PyList_Reverse = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Reverse), GetUnmanagedDll(_PythonDll)); - PyList_Sort = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Sort), GetUnmanagedDll(_PythonDll)); - PyList_GetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_GetSlice), GetUnmanagedDll(_PythonDll)); - PyList_SetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_SetSlice), GetUnmanagedDll(_PythonDll)); - PyList_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyList_Size), GetUnmanagedDll(_PythonDll)); - PyTuple_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_New), GetUnmanagedDll(_PythonDll)); - PyTuple_GetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_GetItem), GetUnmanagedDll(_PythonDll)); - PyTuple_SetItem = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_SetItem), GetUnmanagedDll(_PythonDll)); - PyTuple_GetSlice = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_GetSlice), GetUnmanagedDll(_PythonDll)); - PyTuple_Size = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyTuple_Size), GetUnmanagedDll(_PythonDll)); - try - { - PyIter_Check = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyIter_Check), GetUnmanagedDll(_PythonDll)); - } catch (MissingMethodException) { } - PyIter_Next = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyIter_Next), GetUnmanagedDll(_PythonDll)); - PyModule_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyModule_New), GetUnmanagedDll(_PythonDll)); - PyModule_GetDict = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyModule_GetDict), GetUnmanagedDll(_PythonDll)); - PyModule_AddObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyModule_AddObject), GetUnmanagedDll(_PythonDll)); - PyImport_Import = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_Import), GetUnmanagedDll(_PythonDll)); - PyImport_ImportModule = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_ImportModule), GetUnmanagedDll(_PythonDll)); - PyImport_ReloadModule = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_ReloadModule), GetUnmanagedDll(_PythonDll)); - PyImport_AddModule = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_AddModule), GetUnmanagedDll(_PythonDll)); - PyImport_GetModuleDict = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyImport_GetModuleDict), GetUnmanagedDll(_PythonDll)); - PySys_SetArgvEx = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySys_SetArgvEx), GetUnmanagedDll(_PythonDll)); - PySys_GetObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySys_GetObject), GetUnmanagedDll(_PythonDll)); - PySys_SetObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PySys_SetObject), GetUnmanagedDll(_PythonDll)); - PyType_Modified = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_Modified), GetUnmanagedDll(_PythonDll)); - PyType_IsSubtype = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_IsSubtype), GetUnmanagedDll(_PythonDll)); - PyType_GenericNew = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_GenericNew), GetUnmanagedDll(_PythonDll)); - PyType_GenericAlloc = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_GenericAlloc), GetUnmanagedDll(_PythonDll)); - PyType_Ready = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_Ready), GetUnmanagedDll(_PythonDll)); - _PyType_Lookup = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_PyType_Lookup), GetUnmanagedDll(_PythonDll)); - PyObject_GenericGetAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GenericGetAttr), GetUnmanagedDll(_PythonDll)); - PyObject_GenericGetDict = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GenericGetDict), GetUnmanagedDll(PythonDLL)); - PyObject_GenericSetAttr = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GenericSetAttr), GetUnmanagedDll(_PythonDll)); - PyObject_GC_Del = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GC_Del), GetUnmanagedDll(_PythonDll)); - try - { - PyObject_GC_IsTracked = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GC_IsTracked), GetUnmanagedDll(_PythonDll)); - } catch (MissingMethodException) { } - PyObject_GC_Track = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GC_Track), GetUnmanagedDll(_PythonDll)); - PyObject_GC_UnTrack = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyObject_GC_UnTrack), GetUnmanagedDll(_PythonDll)); - _PyObject_Dump = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_PyObject_Dump), GetUnmanagedDll(_PythonDll)); - PyMem_Malloc = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyMem_Malloc), GetUnmanagedDll(_PythonDll)); - PyMem_Realloc = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyMem_Realloc), GetUnmanagedDll(_PythonDll)); - PyMem_Free = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyMem_Free), GetUnmanagedDll(_PythonDll)); - PyErr_SetString = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_SetString), GetUnmanagedDll(_PythonDll)); - PyErr_SetObject = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_SetObject), GetUnmanagedDll(_PythonDll)); - PyErr_ExceptionMatches = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_ExceptionMatches), GetUnmanagedDll(_PythonDll)); - PyErr_GivenExceptionMatches = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_GivenExceptionMatches), GetUnmanagedDll(_PythonDll)); - PyErr_NormalizeException = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_NormalizeException), GetUnmanagedDll(_PythonDll)); - PyErr_Occurred = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Occurred), GetUnmanagedDll(_PythonDll)); - PyErr_Fetch = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Fetch), GetUnmanagedDll(_PythonDll)); - PyErr_Restore = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Restore), GetUnmanagedDll(_PythonDll)); - PyErr_Clear = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Clear), GetUnmanagedDll(_PythonDll)); - PyErr_Print = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyErr_Print), GetUnmanagedDll(_PythonDll)); - PyCell_Get = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCell_Get), GetUnmanagedDll(_PythonDll)); - PyCell_Set = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCell_Set), GetUnmanagedDll(_PythonDll)); - PyGC_Collect = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyGC_Collect), GetUnmanagedDll(_PythonDll)); - PyCapsule_New = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCapsule_New), GetUnmanagedDll(_PythonDll)); - PyCapsule_GetPointer = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCapsule_GetPointer), GetUnmanagedDll(_PythonDll)); - PyCapsule_SetPointer = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyCapsule_SetPointer), GetUnmanagedDll(_PythonDll)); - PyLong_AsUnsignedSize_t = (delegate* unmanaged[Cdecl])GetFunctionByName("PyLong_AsSize_t", GetUnmanagedDll(_PythonDll)); - PyLong_AsSignedSize_t = (delegate* unmanaged[Cdecl])GetFunctionByName("PyLong_AsSsize_t", GetUnmanagedDll(_PythonDll)); - PyDict_GetItemWithError = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyDict_GetItemWithError), GetUnmanagedDll(_PythonDll)); - PyException_GetCause = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyException_GetCause), GetUnmanagedDll(_PythonDll)); - PyException_GetTraceback = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyException_GetTraceback), GetUnmanagedDll(_PythonDll)); - PyException_SetCause = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyException_SetCause), GetUnmanagedDll(_PythonDll)); - PyException_SetTraceback = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyException_SetTraceback), GetUnmanagedDll(_PythonDll)); - PyThreadState_SetAsyncExcLLP64 = (delegate* unmanaged[Cdecl])GetFunctionByName("PyThreadState_SetAsyncExc", GetUnmanagedDll(_PythonDll)); - PyThreadState_SetAsyncExcLP64 = (delegate* unmanaged[Cdecl])GetFunctionByName("PyThreadState_SetAsyncExc", GetUnmanagedDll(_PythonDll)); - PyType_GetSlot = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_GetSlot), GetUnmanagedDll(_PythonDll)); - PyType_FromSpecWithBases = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(PyType_FromSpecWithBases), GetUnmanagedDll(PythonDLL)); - - try - { - _Py_NewReference = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_Py_NewReference), GetUnmanagedDll(_PythonDll)); - } - catch (MissingMethodException) { } - try - { - _Py_IsFinalizing = (delegate* unmanaged[Cdecl])GetFunctionByName(nameof(_Py_IsFinalizing), GetUnmanagedDll(_PythonDll)); - } - 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) - { - if (libraryName is null) return IntPtr.Zero; - return libraryLoader.Load(libraryName); - } - - static global::System.IntPtr GetFunctionByName(string functionName, global::System.IntPtr libraryHandle) - { - try - { - return libraryLoader.GetFunction(libraryHandle, functionName); - } - catch (MissingMethodException e) when (libraryHandle == IntPtr.Zero) - { - throw new BadPythonDllException( - "Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL." + - " See https://github.com/pythonnet/pythonnet#embedding-python-in-net", - e); - } - } - - internal static delegate* unmanaged[Cdecl] Py_IncRef { get; } - internal static delegate* unmanaged[Cdecl] Py_DecRef { get; } - internal static delegate* unmanaged[Cdecl] Py_Initialize { get; } - internal static delegate* unmanaged[Cdecl] Py_InitializeEx { get; } - internal static delegate* unmanaged[Cdecl] Py_IsInitialized { get; } - internal static delegate* unmanaged[Cdecl] Py_Finalize { get; } - internal static delegate* unmanaged[Cdecl] Py_NewInterpreter { get; } - internal static delegate* unmanaged[Cdecl] Py_EndInterpreter { get; } - internal static delegate* unmanaged[Cdecl] PyThreadState_New { get; } - internal static delegate* unmanaged[Cdecl] PyThreadState_Get { get; } - internal static delegate* unmanaged[Cdecl] _PyThreadState_UncheckedGet { get; } - internal static delegate* unmanaged[Cdecl] PyGILState_Check { get; } - internal static delegate* unmanaged[Cdecl] PyGILState_Ensure { get; } - internal static delegate* unmanaged[Cdecl] PyGILState_Release { get; } - internal static delegate* unmanaged[Cdecl] PyGILState_GetThisThreadState { get; } - internal static delegate* unmanaged[Cdecl] Py_Main { get; } - internal static delegate* unmanaged[Cdecl] PyEval_InitThreads { get; } - internal static delegate* unmanaged[Cdecl] PyEval_ThreadsInitialized { get; } - internal static delegate* unmanaged[Cdecl] PyEval_AcquireLock { get; } - internal static delegate* unmanaged[Cdecl] PyEval_ReleaseLock { get; } - internal static delegate* unmanaged[Cdecl] PyEval_AcquireThread { get; } - internal static delegate* unmanaged[Cdecl] PyEval_ReleaseThread { get; } - internal static delegate* unmanaged[Cdecl] PyEval_SaveThread { get; } - internal static delegate* unmanaged[Cdecl] PyEval_RestoreThread { get; } - internal static delegate* unmanaged[Cdecl] PyEval_GetBuiltins { get; } - internal static delegate* unmanaged[Cdecl] PyEval_GetGlobals { get; } - internal static delegate* unmanaged[Cdecl] PyEval_GetLocals { get; } - internal static delegate* unmanaged[Cdecl] Py_GetProgramName { get; } - internal static delegate* unmanaged[Cdecl] Py_SetProgramName { get; } - internal static delegate* unmanaged[Cdecl] Py_GetPythonHome { get; } - internal static delegate* unmanaged[Cdecl] Py_SetPythonHome { get; } - internal static delegate* unmanaged[Cdecl] Py_GetPath { get; } - internal static delegate* unmanaged[Cdecl] Py_SetPath { get; } - internal static delegate* unmanaged[Cdecl] Py_GetVersion { get; } - internal static delegate* unmanaged[Cdecl] Py_GetPlatform { get; } - internal static delegate* unmanaged[Cdecl] Py_GetCopyright { get; } - internal static delegate* unmanaged[Cdecl] Py_GetCompiler { get; } - internal static delegate* unmanaged[Cdecl] Py_GetBuildInfo { get; } - internal static delegate* unmanaged[Cdecl] PyRun_SimpleStringFlags { get; } - internal static delegate* unmanaged[Cdecl] PyRun_StringFlags { get; } - internal static delegate* unmanaged[Cdecl] PyEval_EvalCode { get; } - internal static delegate* unmanaged[Cdecl] Py_CompileStringObject { get; } - internal static delegate* unmanaged[Cdecl] PyImport_ExecCodeModule { get; } - internal static delegate* unmanaged[Cdecl] PyObject_HasAttrString { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GetAttrString { get; } - internal static delegate* unmanaged[Cdecl] PyObject_SetAttrString { get; } - internal static delegate* unmanaged[Cdecl] PyObject_HasAttr { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GetAttr { get; } - internal static delegate* unmanaged[Cdecl] PyObject_SetAttr { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GetItem { get; } - internal static delegate* unmanaged[Cdecl] PyObject_SetItem { get; } - internal static delegate* unmanaged[Cdecl] PyObject_DelItem { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GetIter { get; } - internal static delegate* unmanaged[Cdecl] PyObject_Call { get; } - internal static delegate* unmanaged[Cdecl] PyObject_CallObject { get; } - internal static delegate* unmanaged[Cdecl] PyObject_RichCompareBool { get; } - internal static delegate* unmanaged[Cdecl] PyObject_IsInstance { get; } - internal static delegate* unmanaged[Cdecl] PyObject_IsSubclass { get; } - internal static delegate* unmanaged[Cdecl] PyCallable_Check { get; } - internal static delegate* unmanaged[Cdecl] PyObject_IsTrue { get; } - internal static delegate* unmanaged[Cdecl] PyObject_Not { get; } - internal static delegate* unmanaged[Cdecl] PyObject_Size { get; } - internal static delegate* unmanaged[Cdecl] PyObject_Hash { get; } - internal static delegate* unmanaged[Cdecl] PyObject_Repr { get; } - internal static delegate* unmanaged[Cdecl] PyObject_Str { get; } - internal static delegate* unmanaged[Cdecl] PyObject_Type { get; } - internal static delegate* unmanaged[Cdecl] PyObject_Dir { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GetBuffer { get; } - internal static delegate* unmanaged[Cdecl] PyBuffer_Release { get; } - internal static delegate* unmanaged[Cdecl] PyBuffer_SizeFromFormat { get; } - internal static delegate* unmanaged[Cdecl] PyBuffer_IsContiguous { get; } - internal static delegate* unmanaged[Cdecl] PyBuffer_GetPointer { get; } - internal static delegate* unmanaged[Cdecl] PyBuffer_FromContiguous { get; } - internal static delegate* unmanaged[Cdecl] PyBuffer_ToContiguous { get; } - internal static delegate* unmanaged[Cdecl] PyBuffer_FillContiguousStrides { get; } - internal static delegate* unmanaged[Cdecl] PyBuffer_FillInfo { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Long { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Float { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Check { get; } - internal static delegate* unmanaged[Cdecl] PyLong_FromLongLong { get; } - internal static delegate* unmanaged[Cdecl] PyLong_FromUnsignedLongLong { get; } - internal static delegate* unmanaged[Cdecl] PyLong_FromString { get; } - internal static delegate* unmanaged[Cdecl] PyLong_AsLongLong { get; } - internal static delegate* unmanaged[Cdecl] PyLong_AsUnsignedLongLong { get; } - internal static delegate* unmanaged[Cdecl] PyLong_FromVoidPtr { get; } - internal static delegate* unmanaged[Cdecl] PyLong_AsVoidPtr { get; } - internal static delegate* unmanaged[Cdecl] PyFloat_FromDouble { get; } - internal static delegate* unmanaged[Cdecl] PyFloat_FromString { get; } - internal static delegate* unmanaged[Cdecl] PyFloat_AsDouble { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Add { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Subtract { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Multiply { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_TrueDivide { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_And { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Xor { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Or { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Lshift { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Rshift { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Power { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Remainder { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceAdd { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceSubtract { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceMultiply { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceTrueDivide { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceAnd { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceXor { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceOr { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceLshift { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceRshift { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlacePower { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_InPlaceRemainder { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Negative { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Positive { get; } - internal static delegate* unmanaged[Cdecl] PyNumber_Invert { get; } - internal static delegate* unmanaged[Cdecl] PySequence_Check { get; } - internal static delegate* unmanaged[Cdecl] PySequence_GetItem { get; } - internal static delegate* unmanaged[Cdecl] PySequence_SetItem { get; } - internal static delegate* unmanaged[Cdecl] PySequence_DelItem { get; } - internal static delegate* unmanaged[Cdecl] PySequence_GetSlice { get; } - internal static delegate* unmanaged[Cdecl] PySequence_SetSlice { get; } - internal static delegate* unmanaged[Cdecl] PySequence_DelSlice { get; } - internal static delegate* unmanaged[Cdecl] PySequence_Size { get; } - internal static delegate* unmanaged[Cdecl] PySequence_Contains { get; } - internal static delegate* unmanaged[Cdecl] PySequence_Concat { get; } - internal static delegate* unmanaged[Cdecl] PySequence_Repeat { get; } - internal static delegate* unmanaged[Cdecl] PySequence_Index { get; } - internal static delegate* unmanaged[Cdecl] PySequence_Count { get; } - internal static delegate* unmanaged[Cdecl] PySequence_Tuple { get; } - internal static delegate* unmanaged[Cdecl] PySequence_List { get; } - internal static delegate* unmanaged[Cdecl] PyBytes_AsString { get; } - internal static delegate* unmanaged[Cdecl] PyBytes_FromString { get; } - internal static delegate* unmanaged[Cdecl] PyByteArray_FromStringAndSize { get; } - internal static delegate* unmanaged[Cdecl] PyBytes_Size { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_AsUTF8 { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_DecodeUTF16 { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_GetLength { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_AsUnicode { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_AsUTF16String { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_FromOrdinal { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_InternFromString { get; } - internal static delegate* unmanaged[Cdecl] PyUnicode_Compare { get; } - internal static delegate* unmanaged[Cdecl] PyDict_New { get; } - internal static delegate* unmanaged[Cdecl] PyDict_GetItem { get; } - internal static delegate* unmanaged[Cdecl] PyDict_GetItemString { get; } - internal static delegate* unmanaged[Cdecl] PyDict_SetItem { get; } - internal static delegate* unmanaged[Cdecl] PyDict_SetItemString { get; } - internal static delegate* unmanaged[Cdecl] PyDict_DelItem { get; } - internal static delegate* unmanaged[Cdecl] PyDict_DelItemString { get; } - internal static delegate* unmanaged[Cdecl] PyMapping_HasKey { get; } - internal static delegate* unmanaged[Cdecl] PyDict_Keys { get; } - internal static delegate* unmanaged[Cdecl] PyDict_Values { get; } - internal static delegate* unmanaged[Cdecl] PyDict_Items { get; } - internal static delegate* unmanaged[Cdecl] PyDict_Copy { get; } - internal static delegate* unmanaged[Cdecl] PyDict_Update { get; } - internal static delegate* unmanaged[Cdecl] PyDict_Clear { get; } - internal static delegate* unmanaged[Cdecl] PyDict_Size { get; } - internal static delegate* unmanaged[Cdecl] PySet_New { get; } - internal static delegate* unmanaged[Cdecl] PySet_Add { get; } - internal static delegate* unmanaged[Cdecl] PySet_Contains { get; } - internal static delegate* unmanaged[Cdecl] PyList_New { get; } - internal static delegate* unmanaged[Cdecl] PyList_GetItem { get; } - internal static delegate* unmanaged[Cdecl] PyList_SetItem { get; } - internal static delegate* unmanaged[Cdecl] PyList_Insert { get; } - internal static delegate* unmanaged[Cdecl] PyList_Append { get; } - internal static delegate* unmanaged[Cdecl] PyList_Reverse { get; } - internal static delegate* unmanaged[Cdecl] PyList_Sort { get; } - internal static delegate* unmanaged[Cdecl] PyList_GetSlice { get; } - internal static delegate* unmanaged[Cdecl] PyList_SetSlice { get; } - internal static delegate* unmanaged[Cdecl] PyList_Size { get; } - internal static delegate* unmanaged[Cdecl] PyTuple_New { get; } - internal static delegate* unmanaged[Cdecl] PyTuple_GetItem { get; } - internal static delegate* unmanaged[Cdecl] PyTuple_SetItem { get; } - internal static delegate* unmanaged[Cdecl] PyTuple_GetSlice { get; } - internal static delegate* unmanaged[Cdecl] PyTuple_Size { get; } - internal static delegate* unmanaged[Cdecl] PyIter_Check { get; } - internal static delegate* unmanaged[Cdecl] PyIter_Next { get; } - internal static delegate* unmanaged[Cdecl] PyModule_New { get; } - internal static delegate* unmanaged[Cdecl] PyModule_GetDict { get; } - internal static delegate* unmanaged[Cdecl] PyModule_AddObject { get; } - internal static delegate* unmanaged[Cdecl] PyImport_Import { get; } - internal static delegate* unmanaged[Cdecl] PyImport_ImportModule { get; } - internal static delegate* unmanaged[Cdecl] PyImport_ReloadModule { get; } - internal static delegate* unmanaged[Cdecl] PyImport_AddModule { get; } - internal static delegate* unmanaged[Cdecl] PyImport_GetModuleDict { get; } - internal static delegate* unmanaged[Cdecl] PySys_SetArgvEx { get; } - internal static delegate* unmanaged[Cdecl] PySys_GetObject { get; } - internal static delegate* unmanaged[Cdecl] PySys_SetObject { get; } - internal static delegate* unmanaged[Cdecl] PyType_Modified { get; } - internal static delegate* unmanaged[Cdecl] PyType_IsSubtype { get; } - internal static delegate* unmanaged[Cdecl] PyType_GenericNew { get; } - internal static delegate* unmanaged[Cdecl] PyType_GenericAlloc { get; } - internal static delegate* unmanaged[Cdecl] PyType_Ready { get; } - internal static delegate* unmanaged[Cdecl] _PyType_Lookup { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GenericGetAttr { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GenericSetAttr { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GC_Del { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GC_IsTracked { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GC_Track { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GC_UnTrack { get; } - internal static delegate* unmanaged[Cdecl] _PyObject_Dump { get; } - internal static delegate* unmanaged[Cdecl] PyMem_Malloc { get; } - internal static delegate* unmanaged[Cdecl] PyMem_Realloc { get; } - internal static delegate* unmanaged[Cdecl] PyMem_Free { get; } - internal static delegate* unmanaged[Cdecl] PyErr_SetString { get; } - internal static delegate* unmanaged[Cdecl] PyErr_SetObject { get; } - internal static delegate* unmanaged[Cdecl] PyErr_ExceptionMatches { get; } - internal static delegate* unmanaged[Cdecl] PyErr_GivenExceptionMatches { get; } - internal static delegate* unmanaged[Cdecl] PyErr_NormalizeException { get; } - internal static delegate* unmanaged[Cdecl] PyErr_Occurred { get; } - internal static delegate* unmanaged[Cdecl] PyErr_Fetch { get; } - internal static delegate* unmanaged[Cdecl] PyErr_Restore { get; } - internal static delegate* unmanaged[Cdecl] PyErr_Clear { get; } - internal static delegate* unmanaged[Cdecl] PyErr_Print { get; } - internal static delegate* unmanaged[Cdecl] PyCell_Get { get; } - internal static delegate* unmanaged[Cdecl] PyCell_Set { get; } - internal static delegate* unmanaged[Cdecl] PyGC_Collect { get; } - internal static delegate* unmanaged[Cdecl] PyCapsule_New { get; } - internal static delegate* unmanaged[Cdecl] PyCapsule_GetPointer { get; } - internal static delegate* unmanaged[Cdecl] PyCapsule_SetPointer { get; } - internal static delegate* unmanaged[Cdecl] PyLong_AsUnsignedSize_t { get; } - internal static delegate* unmanaged[Cdecl] PyLong_AsSignedSize_t { get; } - internal static delegate* unmanaged[Cdecl] PyDict_GetItemWithError { get; } - internal static delegate* unmanaged[Cdecl] PyException_GetCause { get; } - internal static delegate* unmanaged[Cdecl] PyException_GetTraceback { get; } - internal static delegate* unmanaged[Cdecl] PyException_SetCause { get; } - internal static delegate* unmanaged[Cdecl] PyException_SetTraceback { get; } - internal static delegate* unmanaged[Cdecl] PyThreadState_SetAsyncExcLLP64 { get; } - internal static delegate* unmanaged[Cdecl] PyThreadState_SetAsyncExcLP64 { get; } - internal static delegate* unmanaged[Cdecl] PyObject_GenericGetDict { get; } - internal static delegate* unmanaged[Cdecl] PyType_GetSlot { get; } - internal static delegate* unmanaged[Cdecl] PyType_FromSpecWithBases { get; } - internal static delegate* unmanaged[Cdecl] _Py_NewReference { get; } - internal static delegate* unmanaged[Cdecl] _Py_IsFinalizing { get; } - internal static IntPtr PyType_Type { get; } - internal static int* Py_NoSiteFlag { get; } - } } internal class BadPythonDllException : MissingMethodException diff --git a/src/runtime/runtime_state.cs b/src/runtime/RuntimeState.cs similarity index 96% rename from src/runtime/runtime_state.cs rename to src/runtime/RuntimeState.cs index 2bb78094a..8defe6e64 100644 --- a/src/runtime/runtime_state.cs +++ b/src/runtime/RuntimeState.cs @@ -28,10 +28,10 @@ public static void Save() public static void Restore() { - ResotreModules(); + RestoreModules(); } - private static void ResotreModules() + private static void RestoreModules() { var intialModules = PySys_GetObject("initial_modules"); Debug.Assert(!intialModules.IsNull); diff --git a/src/runtime/runtime_data.cs b/src/runtime/StateSerialization/RuntimeData.cs similarity index 100% rename from src/runtime/runtime_data.cs rename to src/runtime/StateSerialization/RuntimeData.cs diff --git a/src/runtime/UnloadedClass.cs b/src/runtime/StateSerialization/UnloadedClass.cs similarity index 100% rename from src/runtime/UnloadedClass.cs rename to src/runtime/StateSerialization/UnloadedClass.cs diff --git a/src/runtime/typemanager.cs b/src/runtime/TypeManager.cs similarity index 99% rename from src/runtime/typemanager.cs rename to src/runtime/TypeManager.cs index cc2874c96..6057ca830 100644 --- a/src/runtime/typemanager.cs +++ b/src/runtime/TypeManager.cs @@ -609,7 +609,6 @@ internal static PyType AllocateTypeObject(string name, PyType metatype) /// static void InheritSubstructs(IntPtr type) { - #warning dead code? IntPtr substructAddress = type + TypeOffset.nb_add; Marshal.WriteIntPtr(type, TypeOffset.tp_as_number, substructAddress); diff --git a/src/runtime/arrayobject.cs b/src/runtime/Types/ArrayObject.cs similarity index 100% rename from src/runtime/arrayobject.cs rename to src/runtime/Types/ArrayObject.cs diff --git a/src/runtime/classbase.cs b/src/runtime/Types/ClassBase.cs similarity index 99% rename from src/runtime/classbase.cs rename to src/runtime/Types/ClassBase.cs index 028788742..2493fd970 100644 --- a/src/runtime/classbase.cs +++ b/src/runtime/Types/ClassBase.cs @@ -550,9 +550,9 @@ public virtual void InitializeSlots(BorrowedReference pyType, SlotsHolder slotsH TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.tp_iter, new Interop.B_N(tp_iter_impl), slotsHolder); } - if (mp_length_slot.CanAssign(type.Value)) + if (MpLengthSlot.CanAssign(type.Value)) { - TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.mp_length, new Interop.B_P(mp_length_slot.impl), slotsHolder); + TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.mp_length, new Interop.B_P(MpLengthSlot.impl), slotsHolder); } } diff --git a/src/runtime/classderived.cs b/src/runtime/Types/ClassDerived.cs similarity index 100% rename from src/runtime/classderived.cs rename to src/runtime/Types/ClassDerived.cs diff --git a/src/runtime/classobject.cs b/src/runtime/Types/ClassObject.cs similarity index 100% rename from src/runtime/classobject.cs rename to src/runtime/Types/ClassObject.cs diff --git a/src/runtime/clrobject.cs b/src/runtime/Types/ClrObject.cs similarity index 100% rename from src/runtime/clrobject.cs rename to src/runtime/Types/ClrObject.cs diff --git a/src/runtime/delegateobject.cs b/src/runtime/Types/DelegateObject.cs similarity index 100% rename from src/runtime/delegateobject.cs rename to src/runtime/Types/DelegateObject.cs diff --git a/src/runtime/eventbinding.cs b/src/runtime/Types/EventBinding.cs similarity index 100% rename from src/runtime/eventbinding.cs rename to src/runtime/Types/EventBinding.cs diff --git a/src/runtime/eventobject.cs b/src/runtime/Types/EventObject.cs similarity index 100% rename from src/runtime/eventobject.cs rename to src/runtime/Types/EventObject.cs diff --git a/src/runtime/Types/ExceptionClassObject.cs b/src/runtime/Types/ExceptionClassObject.cs new file mode 100644 index 000000000..762c9255a --- /dev/null +++ b/src/runtime/Types/ExceptionClassObject.cs @@ -0,0 +1,78 @@ +using System; + +namespace Python.Runtime; + +/// +/// Base class for Python types that reflect managed exceptions based on +/// System.Exception +/// +[Serializable] +internal class ExceptionClassObject : ClassObject +{ + internal ExceptionClassObject(Type tp) : base(tp) + { + } + + internal static Exception? ToException(BorrowedReference ob) + { + var co = GetManagedObject(ob) as CLRObject; + return co?.inst as Exception; + } + + /// + /// Exception __repr__ implementation + /// + public new static NewReference tp_repr(BorrowedReference ob) + { + Exception? e = ToException(ob); + if (e == null) + { + return Exceptions.RaiseTypeError("invalid object"); + } + string name = e.GetType().Name; + string message; + if (e.Message != String.Empty) + { + message = String.Format("{0}('{1}')", name, e.Message); + } + else + { + message = String.Format("{0}()", name); + } + return Runtime.PyString_FromString(message); + } + + /// + /// Exception __str__ implementation + /// + public new static NewReference tp_str(BorrowedReference ob) + { + Exception? e = ToException(ob); + if (e == null) + { + return Exceptions.RaiseTypeError("invalid object"); + } + + string message = e.ToString(); + string fullTypeName = e.GetType().FullName; + string prefix = fullTypeName + ": "; + if (message.StartsWith(prefix)) + { + message = message.Substring(prefix.Length); + } + else if (message.StartsWith(fullTypeName)) + { + message = message.Substring(fullTypeName.Length); + } + return Runtime.PyString_FromString(message); + } + + public override bool Init(BorrowedReference obj, BorrowedReference args, BorrowedReference kw) + { + if (!base.Init(obj, args, kw)) return false; + + var e = (CLRObject)GetManagedObject(obj)!; + + return Exceptions.SetArgsAndCause(obj, (Exception)e.inst); + } +} diff --git a/src/runtime/extensiontype.cs b/src/runtime/Types/ExtensionType.cs similarity index 100% rename from src/runtime/extensiontype.cs rename to src/runtime/Types/ExtensionType.cs diff --git a/src/runtime/fieldobject.cs b/src/runtime/Types/FieldObject.cs similarity index 100% rename from src/runtime/fieldobject.cs rename to src/runtime/Types/FieldObject.cs diff --git a/src/runtime/generictype.cs b/src/runtime/Types/GenericType.cs similarity index 100% rename from src/runtime/generictype.cs rename to src/runtime/Types/GenericType.cs diff --git a/src/runtime/indexer.cs b/src/runtime/Types/Indexer.cs similarity index 100% rename from src/runtime/indexer.cs rename to src/runtime/Types/Indexer.cs diff --git a/src/runtime/interfaceobject.cs b/src/runtime/Types/InterfaceObject.cs similarity index 100% rename from src/runtime/interfaceobject.cs rename to src/runtime/Types/InterfaceObject.cs diff --git a/src/runtime/iterator.cs b/src/runtime/Types/Iterator.cs similarity index 100% rename from src/runtime/iterator.cs rename to src/runtime/Types/Iterator.cs diff --git a/src/runtime/managedtype.cs b/src/runtime/Types/ManagedType.cs similarity index 100% rename from src/runtime/managedtype.cs rename to src/runtime/Types/ManagedType.cs diff --git a/src/runtime/ManagedTypes.cd b/src/runtime/Types/ManagedTypes.cd similarity index 100% rename from src/runtime/ManagedTypes.cd rename to src/runtime/Types/ManagedTypes.cd diff --git a/src/runtime/metatype.cs b/src/runtime/Types/MetaType.cs similarity index 100% rename from src/runtime/metatype.cs rename to src/runtime/Types/MetaType.cs diff --git a/src/runtime/methodbinding.cs b/src/runtime/Types/MethodBinding.cs similarity index 100% rename from src/runtime/methodbinding.cs rename to src/runtime/Types/MethodBinding.cs diff --git a/src/runtime/methodobject.cs b/src/runtime/Types/MethodObject.cs similarity index 100% rename from src/runtime/methodobject.cs rename to src/runtime/Types/MethodObject.cs diff --git a/src/runtime/modulefunctionobject.cs b/src/runtime/Types/ModuleFunctionObject.cs similarity index 100% rename from src/runtime/modulefunctionobject.cs rename to src/runtime/Types/ModuleFunctionObject.cs diff --git a/src/runtime/moduleobject.cs b/src/runtime/Types/ModuleObject.cs similarity index 100% rename from src/runtime/moduleobject.cs rename to src/runtime/Types/ModuleObject.cs diff --git a/src/runtime/modulepropertyobject.cs b/src/runtime/Types/ModulePropertyObject.cs similarity index 100% rename from src/runtime/modulepropertyobject.cs rename to src/runtime/Types/ModulePropertyObject.cs diff --git a/src/runtime/slots/mp_length.cs b/src/runtime/Types/MpLengthSlot.cs similarity index 98% rename from src/runtime/slots/mp_length.cs rename to src/runtime/Types/MpLengthSlot.cs index 669285fe1..9e4865fe0 100644 --- a/src/runtime/slots/mp_length.cs +++ b/src/runtime/Types/MpLengthSlot.cs @@ -7,7 +7,7 @@ namespace Python.Runtime.Slots { - internal static class mp_length_slot + internal static class MpLengthSlot { public static bool CanAssign(Type clrType) { diff --git a/src/runtime/operatormethod.cs b/src/runtime/Types/OperatorMethod.cs similarity index 100% rename from src/runtime/operatormethod.cs rename to src/runtime/Types/OperatorMethod.cs diff --git a/src/runtime/overload.cs b/src/runtime/Types/OverloadMapper.cs similarity index 100% rename from src/runtime/overload.cs rename to src/runtime/Types/OverloadMapper.cs diff --git a/src/runtime/propertyobject.cs b/src/runtime/Types/PropertyObject.cs similarity index 100% rename from src/runtime/propertyobject.cs rename to src/runtime/Types/PropertyObject.cs diff --git a/src/runtime/ReflectedClrType.cs b/src/runtime/Types/ReflectedClrType.cs similarity index 100% rename from src/runtime/ReflectedClrType.cs rename to src/runtime/Types/ReflectedClrType.cs diff --git a/src/runtime/UnsafeReferenceWithRun.cs b/src/runtime/Types/UnsafeReferenceWithRun.cs similarity index 100% rename from src/runtime/UnsafeReferenceWithRun.cs rename to src/runtime/Types/UnsafeReferenceWithRun.cs diff --git a/src/runtime/codegenerator.cs b/src/runtime/Util/CodeGenerator.cs similarity index 100% rename from src/runtime/codegenerator.cs rename to src/runtime/Util/CodeGenerator.cs diff --git a/src/runtime/debughelper.cs b/src/runtime/Util/DebugUtil.cs similarity index 100% rename from src/runtime/debughelper.cs rename to src/runtime/Util/DebugUtil.cs diff --git a/src/runtime/EventHandlerCollection.cs b/src/runtime/Util/EventHandlerCollection.cs similarity index 100% rename from src/runtime/EventHandlerCollection.cs rename to src/runtime/Util/EventHandlerCollection.cs diff --git a/src/runtime/genericutil.cs b/src/runtime/Util/GenericUtil.cs similarity index 100% rename from src/runtime/genericutil.cs rename to src/runtime/Util/GenericUtil.cs diff --git a/src/runtime/tricks/InitOnly.cs b/src/runtime/Util/InitOnly.cs similarity index 100% rename from src/runtime/tricks/InitOnly.cs rename to src/runtime/Util/InitOnly.cs diff --git a/src/runtime/NonCopyableAttribute.cs b/src/runtime/Util/NonCopyableAttribute.cs similarity index 100% rename from src/runtime/NonCopyableAttribute.cs rename to src/runtime/Util/NonCopyableAttribute.cs diff --git a/src/runtime/tricks/NullOnly.cs b/src/runtime/Util/NullOnly.cs similarity index 100% rename from src/runtime/tricks/NullOnly.cs rename to src/runtime/Util/NullOnly.cs diff --git a/src/runtime/opshelper.cs b/src/runtime/Util/OpsHelper.cs similarity index 100% rename from src/runtime/opshelper.cs rename to src/runtime/Util/OpsHelper.cs diff --git a/src/runtime/Reflection/ParameterHelper.cs b/src/runtime/Util/ParameterHelper.cs similarity index 100% rename from src/runtime/Reflection/ParameterHelper.cs rename to src/runtime/Util/ParameterHelper.cs diff --git a/src/runtime/PythonReferenceComparer.cs b/src/runtime/Util/PythonReferenceComparer.cs similarity index 100% rename from src/runtime/PythonReferenceComparer.cs rename to src/runtime/Util/PythonReferenceComparer.cs diff --git a/src/runtime/polyfill/ReflectionPolyfills.cs b/src/runtime/Util/ReflectionPolyfills.cs similarity index 100% rename from src/runtime/polyfill/ReflectionPolyfills.cs rename to src/runtime/Util/ReflectionPolyfills.cs diff --git a/src/runtime/ReflectionUtil.cs b/src/runtime/Util/ReflectionUtil.cs similarity index 100% rename from src/runtime/ReflectionUtil.cs rename to src/runtime/Util/ReflectionUtil.cs diff --git a/src/runtime/Util.cs b/src/runtime/Util/Util.cs similarity index 100% rename from src/runtime/Util.cs rename to src/runtime/Util/Util.cs