diff --git a/.gitignore b/.gitignore index 1e494b12d..3de297c78 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,5 @@ cov-int/ !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json + +pythonnet/dlls diff --git a/NuGet.config b/NuGet.config deleted file mode 100644 index 5210cd6c9..000000000 --- a/NuGet.config +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/Python.Runtime.Interfaces/ILibPython.cs b/Python.Runtime.Interfaces/ILibPython.cs new file mode 100644 index 000000000..3709b6cdd --- /dev/null +++ b/Python.Runtime.Interfaces/ILibPython.cs @@ -0,0 +1,353 @@ +using System; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using System.Threading; +using System.Collections.Generic; + +namespace Python.Runtime.Interfaces +{ + public interface ILibPython + { + /// + /// Export of Macro Py_XIncRef. Use XIncref instead. + /// Limit this function usage for Testing and Py_Debug builds + /// + /// PyObject Ptr + void Py_IncRef(IntPtr ob); + + /// + /// Export of Macro Py_XDecRef. Use XDecref instead. + /// Limit this function usage for Testing and Py_Debug builds + /// + /// PyObject Ptr + void Py_DecRef(IntPtr ob); + + void Py_InitializeEx(int initsigs); + int Py_IsInitialized(); + void Py_Finalize(); + + IntPtr PyGILState_Ensure(); + void PyGILState_Release(IntPtr gs); + + + void PyEval_InitThreads(); + int PyEval_ThreadsInitialized(); + + void PyEval_AcquireLock(); + void PyEval_ReleaseLock(); + + IntPtr PyEval_SaveThread(); + void PyEval_RestoreThread(IntPtr tstate); + + IntPtr PyEval_GetBuiltins(); + IntPtr PyEval_GetGlobals(); + IntPtr PyEval_GetLocals(); + + IntPtr Py_GetProgramName(); + void Py_SetProgramName(IntPtr name); + + IntPtr Py_GetPythonHome(); + void Py_SetPythonHome(IntPtr home); + + IntPtr Py_GetPath(); + void Py_SetPath(IntPtr home); + + IntPtr Py_GetVersion(); + IntPtr Py_GetPlatform(); + IntPtr Py_GetCopyright(); + IntPtr Py_GetCompiler(); + IntPtr Py_GetBuildInfo(); + + int PyRun_SimpleString(string code); + IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals); + IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals); + IntPtr Py_CompileString(string code, string file, IntPtr tok); + + IntPtr PyImport_ExecCodeModule(string name, IntPtr code); + + IntPtr PyCFunction_NewEx(IntPtr ml, IntPtr self, IntPtr mod); + IntPtr PyCFunction_Call(IntPtr func, IntPtr args, IntPtr kw); + +#if PYTHON2 + IntPtr PyClass_New(IntPtr bases, IntPtr dict, IntPtr name); +#endif + + IntPtr PyInstance_New(IntPtr cls, IntPtr args, IntPtr kw); + IntPtr PyInstance_NewRaw(IntPtr cls, IntPtr dict); + IntPtr PyMethod_New(IntPtr func, IntPtr self, IntPtr cls); + + //==================================================================== + // Python abstract object API + //==================================================================== + + int PyObject_HasAttrString(IntPtr pointer, string name); + IntPtr PyObject_GetAttrString(IntPtr pointer, string name); + int PyObject_SetAttrString(IntPtr pointer, string name, IntPtr value); + int PyObject_HasAttr(IntPtr pointer, IntPtr name); + IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name); + int PyObject_SetAttr(IntPtr pointer, IntPtr name, IntPtr value); + IntPtr PyObject_GetItem(IntPtr pointer, IntPtr key); + int PyObject_SetItem(IntPtr pointer, IntPtr key, IntPtr value); + int PyObject_DelItem(IntPtr pointer, IntPtr key); + IntPtr PyObject_GetIter(IntPtr op); + IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw); + IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args); + int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid); + int PyObject_IsInstance(IntPtr ob, IntPtr type); + int PyObject_IsSubclass(IntPtr ob, IntPtr type); + int PyCallable_Check(IntPtr pointer); + int PyObject_IsTrue(IntPtr pointer); + int PyObject_Not(IntPtr pointer); + + IntPtr _PyObject_Size(IntPtr pointer); + IntPtr PyObject_Hash(IntPtr op); + IntPtr PyObject_Repr(IntPtr pointer); + IntPtr PyObject_Str(IntPtr pointer); + IntPtr PyObject_Unicode(IntPtr pointer); + IntPtr PyObject_Dir(IntPtr pointer); + + + //==================================================================== + // Python number API + //==================================================================== + + IntPtr PyNumber_Int(IntPtr ob); + IntPtr PyNumber_Long(IntPtr ob); + IntPtr PyNumber_Float(IntPtr ob); + bool PyNumber_Check(IntPtr ob); + + IntPtr PyInt_FromLong(IntPtr value); + int PyInt_AsLong(IntPtr value); + IntPtr PyInt_FromString(string value, IntPtr end, int radix); + + IntPtr PyLong_FromLong(long value); + IntPtr PyLong_FromUnsignedLong32(uint value); + IntPtr PyLong_FromUnsignedLong64(ulong value); + IntPtr PyLong_FromDouble(double value); + IntPtr PyLong_FromLongLong(long value); + IntPtr PyLong_FromUnsignedLongLong(ulong value); + IntPtr PyLong_FromString(string value, IntPtr end, int radix); + int PyLong_AsLong(IntPtr value); + uint PyLong_AsUnsignedLong32(IntPtr value); + ulong PyLong_AsUnsignedLong64(IntPtr value); + long PyLong_AsLongLong(IntPtr value); + ulong PyLong_AsUnsignedLongLong(IntPtr value); + + IntPtr PyFloat_FromDouble(double value); + IntPtr PyFloat_FromString(IntPtr value, IntPtr junk); + double PyFloat_AsDouble(IntPtr ob); + + IntPtr PyNumber_Add(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Subtract(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Multiply(IntPtr o1, IntPtr o2); + IntPtr PyNumber_TrueDivide(IntPtr o1, IntPtr o2); + IntPtr PyNumber_And(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Xor(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Or(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Lshift(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Rshift(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Power(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Remainder(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceAdd(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceSubtract(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceMultiply(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceTrueDivide(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceAnd(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceXor(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceOr(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceLshift(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceRshift(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlacePower(IntPtr o1, IntPtr o2); + IntPtr PyNumber_InPlaceRemainder(IntPtr o1, IntPtr o2); + IntPtr PyNumber_Negative(IntPtr o1); + IntPtr PyNumber_Positive(IntPtr o1); + IntPtr PyNumber_Invert(IntPtr o1); + + + //==================================================================== + // Python sequence API + //==================================================================== + + bool PySequence_Check(IntPtr pointer); + IntPtr PySequence_GetItem(IntPtr pointer, IntPtr index); + int PySequence_SetItem(IntPtr pointer, IntPtr index, IntPtr value); + int PySequence_DelItem(IntPtr pointer, IntPtr index); + IntPtr PySequence_GetSlice(IntPtr pointer, IntPtr i1, IntPtr i2); + int PySequence_SetSlice(IntPtr pointer, IntPtr i1, IntPtr i2, IntPtr v); + int PySequence_DelSlice(IntPtr pointer, IntPtr i1, IntPtr i2); + IntPtr _PySequence_Size(IntPtr pointer); + int PySequence_Contains(IntPtr pointer, IntPtr item); + IntPtr PySequence_Concat(IntPtr pointer, IntPtr other); + IntPtr PySequence_Repeat(IntPtr pointer, IntPtr count); + int PySequence_Index(IntPtr pointer, IntPtr item); + IntPtr _PySequence_Count(IntPtr pointer, IntPtr value); + IntPtr PySequence_Tuple(IntPtr pointer); + IntPtr PySequence_List(IntPtr pointer); + + + //==================================================================== + // Python string API + //==================================================================== + +#if !PYTHON2 + IntPtr PyBytes_FromString(string op); + IntPtr _PyBytes_Size(IntPtr op); + IntPtr _PyString_FromStringAndSize(string value, IntPtr size); + IntPtr PyUnicode_FromStringAndSize(IntPtr value, IntPtr size); +#else + IntPtr PyString_FromStringAndSize(string value, IntPtr size); + IntPtr PyString_AsString(IntPtr op); + int PyString_Size(IntPtr pointer); +#endif + + IntPtr PyUnicode_FromOrdinal(int c); + IntPtr PyUnicode_AsUnicode(IntPtr ob); + IntPtr PyUnicode_FromObject(IntPtr ob); + IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err); + IntPtr _PyUnicode_GetSize(IntPtr ob); +#if !PYTHON2 + IntPtr PyUnicode_FromKindAndData(int kind, string s, IntPtr size); +#else + IntPtr PyUnicode_FromUnicode(string s, IntPtr size); +#endif + + + //==================================================================== + // Python dictionary API + //==================================================================== + + IntPtr PyDict_New(); + IntPtr PyDictProxy_New(IntPtr dict); + IntPtr PyDict_GetItem(IntPtr pointer, IntPtr key); + IntPtr PyDict_GetItemString(IntPtr pointer, string key); + int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value); + int PyDict_SetItemString(IntPtr pointer, string key, IntPtr value); + int PyDict_DelItem(IntPtr pointer, IntPtr key); + int PyDict_DelItemString(IntPtr pointer, string key); + int PyMapping_HasKey(IntPtr pointer, IntPtr key); + IntPtr PyDict_Keys(IntPtr pointer); + IntPtr PyDict_Values(IntPtr pointer); + IntPtr PyDict_Items(IntPtr pointer); + IntPtr PyDict_Copy(IntPtr pointer); + int PyDict_Update(IntPtr pointer, IntPtr other); + void PyDict_Clear(IntPtr pointer); + IntPtr _PyDict_Size(IntPtr pointer); + + + //==================================================================== + // Python list API + //==================================================================== + + IntPtr PyList_New(IntPtr size); + IntPtr PyList_AsTuple(IntPtr pointer); + IntPtr PyList_GetItem(IntPtr pointer, IntPtr index); + int PyList_SetItem(IntPtr pointer, IntPtr index, IntPtr value); + int PyList_Insert(IntPtr pointer, IntPtr index, IntPtr value); + int PyList_Append(IntPtr pointer, IntPtr value); + int PyList_Reverse(IntPtr pointer); + int PyList_Sort(IntPtr pointer); + IntPtr PyList_GetSlice(IntPtr pointer, IntPtr start, IntPtr end); + int PyList_SetSlice(IntPtr pointer, IntPtr start, IntPtr end, IntPtr value); + IntPtr _PyList_Size(IntPtr pointer); + + //==================================================================== + // Python tuple API + //==================================================================== + + IntPtr PyTuple_New(IntPtr size); + IntPtr PyTuple_GetItem(IntPtr pointer, IntPtr index); + int PyTuple_SetItem(IntPtr pointer, IntPtr index, IntPtr value); + IntPtr PyTuple_GetSlice(IntPtr pointer, IntPtr start, IntPtr end); + IntPtr _PyTuple_Size(IntPtr pointer); + + + //==================================================================== + // Python iterator API + //==================================================================== + + IntPtr PyIter_Next(IntPtr pointer); + + //==================================================================== + // Python module API + //==================================================================== + + IntPtr PyModule_New(string name); + string PyModule_GetName(IntPtr module); + IntPtr PyModule_GetDict(IntPtr module); + string PyModule_GetFilename(IntPtr module); +#if !PYTHON2 + IntPtr PyModule_Create2(IntPtr module, int apiver); +#endif + + IntPtr PyImport_Import(IntPtr name); + IntPtr PyImport_ImportModule(string name); + IntPtr PyImport_ReloadModule(IntPtr module); + IntPtr PyImport_AddModule(string name); + IntPtr PyImport_GetModuleDict(); + + void PySys_SetArgvEx(int argc, string[] argv, int updatepath); + IntPtr PySys_GetObject(string name); + int PySys_SetObject(string name, IntPtr ob); + + + //==================================================================== + // Python type object API + //==================================================================== + + void PyType_Modified(IntPtr type); + bool PyType_IsSubtype(IntPtr t1, IntPtr t2); + IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw); + IntPtr PyType_GenericAlloc(IntPtr type, IntPtr n); + int PyType_Ready(IntPtr type); + IntPtr _PyType_Lookup(IntPtr type, IntPtr name); + + IntPtr PyObject_GenericGetAttr(IntPtr obj, IntPtr name); + int PyObject_GenericSetAttr(IntPtr obj, IntPtr name, IntPtr value); + IntPtr _PyObject_GetDictPtr(IntPtr obj); + IntPtr PyObject_GC_New(IntPtr tp); + void PyObject_GC_Del(IntPtr tp); + void PyObject_GC_Track(IntPtr tp); + void PyObject_GC_UnTrack(IntPtr tp); + + + //==================================================================== + // Python memory API + //==================================================================== + + IntPtr PyMem_Malloc(IntPtr size); + IntPtr PyMem_Realloc(IntPtr ptr, IntPtr size); + void PyMem_Free(IntPtr ptr); + + + //==================================================================== + // Python exception API + //==================================================================== + + void PyErr_SetString(IntPtr ob, string message); + void PyErr_SetObject(IntPtr ob, IntPtr message); + IntPtr PyErr_SetFromErrno(IntPtr ob); + void PyErr_SetNone(IntPtr ob); + int PyErr_ExceptionMatches(IntPtr exception); + int PyErr_GivenExceptionMatches(IntPtr ob, IntPtr val); + void PyErr_NormalizeException(IntPtr ob, IntPtr val, IntPtr tb); + IntPtr PyErr_Occurred(); + void PyErr_Fetch(ref IntPtr ob, ref IntPtr val, ref IntPtr tb); + void PyErr_Restore(IntPtr ob, IntPtr val, IntPtr tb); + void PyErr_Clear(); + void PyErr_Print(); + + + //==================================================================== + // Miscellaneous + //==================================================================== + + IntPtr PyMethod_Self(IntPtr ob); + IntPtr PyMethod_Function(IntPtr ob); + int Py_AddPendingCall(IntPtr func, IntPtr arg); + int Py_MakePendingCalls(); + + int GetPyNoSiteFlag(); + void SetPyNoSiteFlag(int val); + } +} diff --git a/Python.Runtime.Interfaces/Python.Runtime.Interfaces.csproj b/Python.Runtime.Interfaces/Python.Runtime.Interfaces.csproj new file mode 100644 index 000000000..72764a664 --- /dev/null +++ b/Python.Runtime.Interfaces/Python.Runtime.Interfaces.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/src/runtime/CustomMarshaler.cs b/Python.Runtime.Native/CustomMarshaler.cs similarity index 88% rename from src/runtime/CustomMarshaler.cs rename to Python.Runtime.Native/CustomMarshaler.cs index b51911816..5d2a00294 100644 --- a/src/runtime/CustomMarshaler.cs +++ b/Python.Runtime.Native/CustomMarshaler.cs @@ -3,7 +3,7 @@ using System.Runtime.InteropServices; using System.Text; -namespace Python.Runtime +namespace Python.Runtime.Native { /// /// Abstract class defining boiler plate methods that @@ -11,6 +11,14 @@ namespace Python.Runtime /// internal abstract class MarshalerBase : ICustomMarshaler { + #if UCS2 && PYTHON2 + internal static Encoding PyEncoding = Encoding.Unicode; + internal static int UCS = 2; + #else + internal static Encoding PyEncoding = Encoding.UTF32; + internal static int UCS = 4; + #endif + public object MarshalNativeToManaged(IntPtr pNativeData) { throw new NotImplementedException(); @@ -42,7 +50,6 @@ public int GetNativeDataSize() internal class UcsMarshaler : MarshalerBase { private static readonly MarshalerBase Instance = new UcsMarshaler(); - private static readonly Encoding PyEncoding = Runtime.PyEncoding; public override IntPtr MarshalManagedToNative(object managedObj) { @@ -91,13 +98,15 @@ public static int GetUnicodeByteLength(IntPtr p) var len = 0; while (true) { - int c = Runtime._UCS == 2 - ? Marshal.ReadInt16(p, len * 2) - : Marshal.ReadInt32(p, len * 4); +#if UCS2 && PYTHON2 + int c = Marshal.ReadInt16(p, len * 2); +#else + int c = Marshal.ReadInt32(p, len * 4); +#endif if (c == 0) { - return len * Runtime._UCS; + return len * UCS; } checked { @@ -120,9 +129,11 @@ public static int GetUnicodeByteLength(IntPtr p) /// public static IntPtr Py3UnicodePy2StringtoPtr(string s) { - return Runtime.IsPython3 - ? Instance.MarshalManagedToNative(s) - : Marshal.StringToHGlobalAnsi(s); +#if PYTHON2 + return Marshal.StringToHGlobalAnsi(s); +#else + return Instance.MarshalManagedToNative(s); +#endif } /// @@ -137,9 +148,11 @@ public static IntPtr Py3UnicodePy2StringtoPtr(string s) /// public static string PtrToPy3UnicodePy2String(IntPtr p) { - return Runtime.IsPython3 - ? PtrToStringUni(p) - : Marshal.PtrToStringAnsi(p); +#if PYTHON2 + return Marshal.PtrToStringAnsi(p); +#else + return PtrToStringUni(p); +#endif } } @@ -151,7 +164,6 @@ public static string PtrToPy3UnicodePy2String(IntPtr p) internal class StrArrayMarshaler : MarshalerBase { private static readonly MarshalerBase Instance = new StrArrayMarshaler(); - private static readonly Encoding PyEncoding = Runtime.PyEncoding; public override IntPtr MarshalManagedToNative(object managedObj) { @@ -163,7 +175,7 @@ public override IntPtr MarshalManagedToNative(object managedObj) } int totalStrLength = argv.Sum(arg => arg.Length + 1); - int memSize = argv.Length * IntPtr.Size + totalStrLength * Runtime._UCS; + int memSize = argv.Length * IntPtr.Size + totalStrLength * UCS; IntPtr mem = Marshal.AllocHGlobal(memSize); try @@ -206,7 +218,7 @@ public static ICustomMarshaler GetInstance(string cookie) internal class Utf8Marshaler : MarshalerBase { private static readonly MarshalerBase Instance = new Utf8Marshaler(); - private static readonly Encoding PyEncoding = Encoding.UTF8; + private static new readonly Encoding PyEncoding = Encoding.UTF8; public override IntPtr MarshalManagedToNative(object managedObj) { diff --git a/src/runtime/runtime.cs b/Python.Runtime.Native/LibPythonPInvoke.cs similarity index 62% rename from src/runtime/runtime.cs rename to Python.Runtime.Native/LibPythonPInvoke.cs index 7a78cd6e1..798b25968 100644 --- a/src/runtime/runtime.cs +++ b/Python.Runtime.Native/LibPythonPInvoke.cs @@ -4,17 +4,11 @@ using System.Text; using System.Threading; using System.Collections.Generic; -using Python.Runtime.Platform; +using Python.Runtime.Interfaces; -namespace Python.Runtime +namespace Python.Runtime.Native { - - /// - /// Encapsulates the low-level Python C API. Note that it is - /// the responsibility of the caller to have acquired the GIL - /// before calling any of these methods. - /// - public class Runtime + public partial class LibPythonPInvoke : ILibPython { // C# compiler copies constants to the assemblies that references this library. // We needs to replace all public constants to static readonly fields to allow @@ -22,7 +16,7 @@ public class Runtime public static int UCS => _UCS; -#if UCS4 +#if !UCS2 internal const int _UCS = 4; /// @@ -30,7 +24,7 @@ public class Runtime /// methods prior to PEP393. Only used for PY27. /// private const string PyUnicodeEntryPoint = "PyUnicodeUCS4_"; -#elif UCS2 +#else internal const int _UCS = 2; /// @@ -38,583 +32,21 @@ public class Runtime /// methods prior to PEP393. Only used for PY27. /// private const string PyUnicodeEntryPoint = "PyUnicodeUCS2_"; -#else -#error You must define either UCS2 or UCS4! -#endif - - // C# compiler copies constants to the assemblies that references this library. - // We needs to replace all public constants to static readonly fields to allow - // binary substitution of different Python.Runtime.dll builds in a target application. - - public static string pyversion => _pyversion; - public static string pyver => _pyver; - -#if PYTHON27 - internal const string _pyversion = "2.7"; - internal const string _pyver = "27"; -#elif PYTHON34 - internal const string _pyversion = "3.4"; - internal const string _pyver = "34"; -#elif PYTHON35 - internal const string _pyversion = "3.5"; - internal const string _pyver = "35"; -#elif PYTHON36 - internal const string _pyversion = "3.6"; - internal const string _pyver = "36"; -#elif PYTHON37 - internal const string _pyversion = "3.7"; - internal const string _pyver = "37"; -#elif PYTHON38 - internal const string _pyversion = "3.8"; - internal const string _pyver = "38"; -#else -#error You must define one of PYTHON34 to PYTHON38 or PYTHON27 -#endif - -#if MONO_LINUX || MONO_OSX // Linux/macOS use dotted version string - internal const string dllBase = "python" + _pyversion; -#else // Windows - internal const string dllBase = "python" + _pyver; -#endif - -#if PYTHON_WITH_PYDEBUG - internal const string dllWithPyDebug = "d"; -#else - internal const string dllWithPyDebug = ""; #endif -#if PYTHON_WITH_PYMALLOC - internal const string dllWithPyMalloc = "m"; -#else - internal const string dllWithPyMalloc = ""; -#endif - - // C# compiler copies constants to the assemblies that references this library. - // We needs to replace all public constants to static readonly fields to allow - // binary substitution of different Python.Runtime.dll builds in a target application. - public static readonly string PythonDLL = _PythonDll; - -#if PYTHON_WITHOUT_ENABLE_SHARED && !NETSTANDARD internal const string _PythonDll = "__Internal"; -#else - internal const string _PythonDll = dllBase + dllWithPyDebug + dllWithPyMalloc; -#endif - - public static readonly int pyversionnumber = Convert.ToInt32(_pyver); // set to true when python is finalizing - internal static object IsFinalizingLock = new object(); - internal static bool IsFinalizing; - internal static bool Is32Bit = IntPtr.Size == 4; // .NET core: System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows) internal static bool IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT; - static readonly Dictionary OperatingSystemTypeMapping = new Dictionary() - { - { "Windows", OperatingSystemType.Windows }, - { "Darwin", OperatingSystemType.Darwin }, - { "Linux", OperatingSystemType.Linux }, - }; - - /// - /// Gets the operating system as reported by python's platform.system(). - /// - public static OperatingSystemType OperatingSystem { get; private set; } - - /// - /// Gets the operating system as reported by python's platform.system(). - /// - public static string OperatingSystemName { get; private set; } - - - /// - /// Map lower-case version of the python machine name to the processor - /// type. There are aliases, e.g. x86_64 and amd64 are two names for - /// the same thing. Make sure to lower-case the search string, because - /// capitalization can differ. - /// - static readonly Dictionary MachineTypeMapping = new Dictionary() - { - ["i386"] = MachineType.i386, - ["i686"] = MachineType.i386, - ["x86"] = MachineType.i386, - ["x86_64"] = MachineType.x86_64, - ["amd64"] = MachineType.x86_64, - ["x64"] = MachineType.x86_64, - ["em64t"] = MachineType.x86_64, - ["armv7l"] = MachineType.armv7l, - ["armv8"] = MachineType.armv8, - ["aarch64"] = MachineType.aarch64, - }; - - /// - /// Gets the machine architecture as reported by python's platform.machine(). - /// - public static MachineType Machine { get; private set; }/* set in Initialize using python's platform.machine */ - - /// - /// Gets the machine architecture as reported by python's platform.machine(). - /// - public static string MachineName { get; private set; } - - internal static bool IsPython2 = pyversionnumber < 30; - internal static bool IsPython3 = pyversionnumber >= 30; - - public static int MainManagedThreadId { get; private set; } - /// /// Encoding to use to convert Unicode to/from Managed to Native /// internal static readonly Encoding PyEncoding = _UCS == 2 ? Encoding.Unicode : Encoding.UTF32; - /// - /// Initialize the runtime... - /// - internal static void Initialize(bool initSigs = false) - { - if (Py_IsInitialized() == 0) - { - Py_InitializeEx(initSigs ? 1 : 0); - MainManagedThreadId = Thread.CurrentThread.ManagedThreadId; - } - - if (PyEval_ThreadsInitialized() == 0) - { - PyEval_InitThreads(); - } - - IsFinalizing = false; - - CLRModule.Reset(); - GenericUtil.Reset(); - PyScopeManager.Reset(); - ClassManager.Reset(); - ClassDerivedObject.Reset(); - TypeManager.Reset(); - - IntPtr op; - IntPtr dict; - if (IsPython3) - { - op = PyImport_ImportModule("builtins"); - dict = PyObject_GetAttrString(op, "__dict__"); - } - else // Python2 - { - dict = PyImport_GetModuleDict(); - op = PyDict_GetItemString(dict, "__builtin__"); - } - PyNotImplemented = PyObject_GetAttrString(op, "NotImplemented"); - PyBaseObjectType = PyObject_GetAttrString(op, "object"); - - PyNone = PyObject_GetAttrString(op, "None"); - PyTrue = PyObject_GetAttrString(op, "True"); - PyFalse = PyObject_GetAttrString(op, "False"); - - PyBoolType = PyObject_Type(PyTrue); - PyNoneType = PyObject_Type(PyNone); - PyTypeType = PyObject_Type(PyNoneType); - - op = PyObject_GetAttrString(dict, "keys"); - PyMethodType = PyObject_Type(op); - XDecref(op); - - // For some arcane reason, builtins.__dict__.__setitem__ is *not* - // a wrapper_descriptor, even though dict.__setitem__ is. - // - // object.__init__ seems safe, though. - op = PyObject_GetAttrString(PyBaseObjectType, "__init__"); - PyWrapperDescriptorType = PyObject_Type(op); - XDecref(op); - -#if PYTHON3 - XDecref(dict); -#endif - - op = PyString_FromString("string"); - PyStringType = PyObject_Type(op); - XDecref(op); - - op = PyUnicode_FromString("unicode"); - PyUnicodeType = PyObject_Type(op); - XDecref(op); - -#if PYTHON3 - op = PyBytes_FromString("bytes"); - PyBytesType = PyObject_Type(op); - XDecref(op); -#endif - - op = PyTuple_New(0); - PyTupleType = PyObject_Type(op); - XDecref(op); - - op = PyList_New(0); - PyListType = PyObject_Type(op); - XDecref(op); - - op = PyDict_New(); - PyDictType = PyObject_Type(op); - XDecref(op); - - op = PyInt_FromInt32(0); - PyIntType = PyObject_Type(op); - XDecref(op); - - op = PyLong_FromLong(0); - PyLongType = PyObject_Type(op); - XDecref(op); - - op = PyFloat_FromDouble(0); - PyFloatType = PyObject_Type(op); - XDecref(op); - -#if PYTHON3 - PyClassType = IntPtr.Zero; - PyInstanceType = IntPtr.Zero; -#elif PYTHON2 - IntPtr s = PyString_FromString("_temp"); - IntPtr d = PyDict_New(); - - IntPtr c = PyClass_New(IntPtr.Zero, d, s); - PyClassType = PyObject_Type(c); - - IntPtr i = PyInstance_New(c, IntPtr.Zero, IntPtr.Zero); - PyInstanceType = PyObject_Type(i); - - XDecref(s); - XDecref(i); - XDecref(c); - XDecref(d); -#endif - - Error = new IntPtr(-1); - - // Initialize data about the platform we're running on. We need - // this for the type manager and potentially other details. Must - // happen after caching the python types, above. - InitializePlatformData(); - - IntPtr dllLocal = IntPtr.Zero; - var loader = LibraryLoader.Get(OperatingSystem); - - if (_PythonDll != "__Internal") - { - dllLocal = loader.Load(_PythonDll); - } - _PyObject_NextNotImplemented = loader.GetFunction(dllLocal, "_PyObject_NextNotImplemented"); - PyModuleType = loader.GetFunction(dllLocal, "PyModule_Type"); - - if (dllLocal != IntPtr.Zero) - { - loader.Free(dllLocal); - } - - // Initialize modules that depend on the runtime class. - AssemblyManager.Initialize(); - PyCLRMetaType = MetaType.Initialize(); - Exceptions.Initialize(); - ImportHook.Initialize(); - - // Need to add the runtime directory to sys.path so that we - // can find built-in assemblies like System.Data, et. al. - string rtdir = RuntimeEnvironment.GetRuntimeDirectory(); - IntPtr path = PySys_GetObject("path"); - IntPtr item = PyString_FromString(rtdir); - PyList_Append(path, item); - XDecref(item); - AssemblyManager.UpdatePath(); - } - - /// - /// Initializes the data about platforms. - /// - /// This must be the last step when initializing the runtime: - /// GetManagedString needs to have the cached values for types. - /// But it must run before initializing anything outside the runtime - /// because those rely on the platform data. - /// - private static void InitializePlatformData() - { - IntPtr op; - IntPtr fn; - IntPtr platformModule = PyImport_ImportModule("platform"); - IntPtr emptyTuple = PyTuple_New(0); - - fn = PyObject_GetAttrString(platformModule, "system"); - op = PyObject_Call(fn, emptyTuple, IntPtr.Zero); - OperatingSystemName = GetManagedString(op); - XDecref(op); - XDecref(fn); - - fn = PyObject_GetAttrString(platformModule, "machine"); - op = PyObject_Call(fn, emptyTuple, IntPtr.Zero); - MachineName = GetManagedString(op); - XDecref(op); - XDecref(fn); - - XDecref(emptyTuple); - XDecref(platformModule); - - // Now convert the strings into enum values so we can do switch - // statements rather than constant parsing. - OperatingSystemType OSType; - if (!OperatingSystemTypeMapping.TryGetValue(OperatingSystemName, out OSType)) - { - OSType = OperatingSystemType.Other; - } - OperatingSystem = OSType; - - MachineType MType; - if (!MachineTypeMapping.TryGetValue(MachineName.ToLower(), out MType)) - { - MType = MachineType.Other; - } - Machine = MType; - } - - internal static void Shutdown() - { - AssemblyManager.Shutdown(); - Exceptions.Shutdown(); - ImportHook.Shutdown(); - Finalizer.Shutdown(); - Py_Finalize(); - } - - // called *without* the GIL acquired by clr._AtExit - internal static int AtExit() - { - lock (IsFinalizingLock) - { - IsFinalizing = true; - } - return 0; - } - - internal static IntPtr Py_single_input = (IntPtr)256; - internal static IntPtr Py_file_input = (IntPtr)257; - internal static IntPtr Py_eval_input = (IntPtr)258; - - internal static IntPtr PyBaseObjectType; - internal static IntPtr PyModuleType; - internal static IntPtr PyClassType; - internal static IntPtr PyInstanceType; - internal static IntPtr PyCLRMetaType; - internal static IntPtr PyMethodType; - internal static IntPtr PyWrapperDescriptorType; - - internal static IntPtr PyUnicodeType; - internal static IntPtr PyStringType; - internal static IntPtr PyTupleType; - internal static IntPtr PyListType; - internal static IntPtr PyDictType; - internal static IntPtr PyIntType; - internal static IntPtr PyLongType; - internal static IntPtr PyFloatType; - internal static IntPtr PyBoolType; - internal static IntPtr PyNoneType; - internal static IntPtr PyTypeType; - - internal static IntPtr Py_NoSiteFlag; - -#if PYTHON3 - internal static IntPtr PyBytesType; -#endif - internal static IntPtr _PyObject_NextNotImplemented; - - internal static IntPtr PyNotImplemented; - internal const int Py_LT = 0; - internal const int Py_LE = 1; - internal const int Py_EQ = 2; - internal const int Py_NE = 3; - internal const int Py_GT = 4; - internal const int Py_GE = 5; - - internal static IntPtr PyTrue; - internal static IntPtr PyFalse; - internal static IntPtr PyNone; - internal static IntPtr Error; - - /// - /// Check if any Python Exceptions occurred. - /// If any exist throw new PythonException. - /// - /// - /// Can be used instead of `obj == IntPtr.Zero` for example. - /// - internal static void CheckExceptionOccurred() - { - if (PyErr_Occurred() != IntPtr.Zero) - { - throw new PythonException(); - } - } - - internal static IntPtr ExtendTuple(IntPtr t, params IntPtr[] args) - { - var size = PyTuple_Size(t); - int add = args.Length; - IntPtr item; - - IntPtr items = PyTuple_New(size + add); - for (var i = 0; i < size; i++) - { - item = PyTuple_GetItem(t, i); - XIncref(item); - PyTuple_SetItem(items, i, item); - } - - for (var n = 0; n < add; n++) - { - item = args[n]; - XIncref(item); - PyTuple_SetItem(items, size + n, item); - } - - return items; - } - - internal static Type[] PythonArgsToTypeArray(IntPtr arg) - { - return PythonArgsToTypeArray(arg, false); - } - - internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects) - { - // Given a PyObject * that is either a single type object or a - // tuple of (managed or unmanaged) type objects, return a Type[] - // containing the CLR Type objects that map to those types. - IntPtr args = arg; - var free = false; - - if (!PyTuple_Check(arg)) - { - args = PyTuple_New(1); - XIncref(arg); - PyTuple_SetItem(args, 0, arg); - free = true; - } - - var n = PyTuple_Size(args); - var types = new Type[n]; - Type t = null; - - for (var i = 0; i < n; i++) - { - IntPtr op = PyTuple_GetItem(args, i); - if (mangleObjects && (!PyType_Check(op))) - { - op = PyObject_TYPE(op); - } - ManagedType mt = ManagedType.GetManagedObject(op); - - if (mt is ClassBase) - { - t = ((ClassBase)mt).type; - } - else if (mt is CLRObject) - { - object inst = ((CLRObject)mt).inst; - if (inst is Type) - { - t = inst as Type; - } - } - else - { - t = Converter.GetTypeByAlias(op); - } - - if (t == null) - { - types = null; - break; - } - types[i] = t; - } - if (free) - { - XDecref(args); - } - return types; - } - - /// - /// Managed exports of the Python C API. Where appropriate, we do - /// some optimization to avoid managed <--> unmanaged transitions - /// (mostly for heavily used methods). - /// - internal static unsafe void XIncref(IntPtr op) - { -#if PYTHON_WITH_PYDEBUG || NETSTANDARD - Py_IncRef(op); - return; -#else - var p = (void*)op; - if ((void*)0 != p) - { - if (Is32Bit) - { - (*(int*)p)++; - } - else - { - (*(long*)p)++; - } - } -#endif - } - - internal static unsafe void XDecref(IntPtr op) - { -#if PYTHON_WITH_PYDEBUG || NETSTANDARD - Py_DecRef(op); - return; -#else - var p = (void*)op; - if ((void*)0 != p) - { - if (Is32Bit) - { - --(*(int*)p); - } - else - { - --(*(long*)p); - } - if ((*(int*)p) == 0) - { - // PyObject_HEAD: struct _typeobject *ob_type - void* t = Is32Bit - ? (void*)(*((uint*)p + 1)) - : (void*)(*((ulong*)p + 1)); - // PyTypeObject: destructor tp_dealloc - void* f = Is32Bit - ? (void*)(*((uint*)t + 6)) - : (void*)(*((ulong*)t + 6)); - if ((void*)0 == f) - { - return; - } - NativeCall.Impl.Void_Call_1(new IntPtr(f), op); - } - } -#endif - } - - internal static unsafe long Refcount(IntPtr op) - { - var p = (void*)op; - if ((void*)0 == p) - { - return 0; - } - return Is32Bit ? (*(int*)p) : (*(long*)p); - } - /// /// Export of Macro Py_XIncRef. Use XIncref instead. /// Limit this function usage for Testing and Py_Debug builds @@ -677,13 +109,13 @@ internal static unsafe long Refcount(IntPtr op) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyGILState_GetThisThreadState(); -#if PYTHON3 +#if !PYTHON2 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] public static extern int Py_Main( int argc, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrArrayMarshaler))] string[] argv ); -#elif PYTHON2 +#else [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] public static extern int Py_Main(int argc, string[] argv); #endif @@ -816,40 +248,6 @@ internal static unsafe IntPtr PyObject_TYPE(IntPtr op) : new IntPtr((void*)(*((ulong*)p + n))); } - /// - /// Managed version of the standard Python C API PyObject_Type call. - /// This version avoids a managed <-> unmanaged transition. - /// This one does incref the returned type object. - /// - internal static IntPtr PyObject_Type(IntPtr op) - { - IntPtr tp = PyObject_TYPE(op); - XIncref(tp); - return tp; - } - - internal static string PyObject_GetTypeName(IntPtr op) - { - IntPtr pyType = Marshal.ReadIntPtr(op, ObjectOffset.ob_type); - IntPtr ppName = Marshal.ReadIntPtr(pyType, TypeOffset.tp_name); - return Marshal.PtrToStringAnsi(ppName); - } - - /// - /// Test whether the Python object is an iterable. - /// - internal static bool PyObject_IsIterable(IntPtr pointer) - { - var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type); -#if PYTHON2 - long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags); - if ((tp_flags & TypeFlags.HaveIter) == 0) - return false; -#endif - IntPtr tp_iter = Marshal.ReadIntPtr(ob_type, TypeOffset.tp_iter); - return tp_iter != IntPtr.Zero; - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern int PyObject_HasAttrString(IntPtr pointer, string name); @@ -886,39 +284,9 @@ internal static bool PyObject_IsIterable(IntPtr pointer) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyObject_CallObject(IntPtr pointer, IntPtr args); -#if PYTHON3 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern int PyObject_RichCompareBool(IntPtr value1, IntPtr value2, int opid); - internal static int PyObject_Compare(IntPtr value1, IntPtr value2) - { - int res; - res = PyObject_RichCompareBool(value1, value2, Py_LT); - if (-1 == res) - return -1; - else if (1 == res) - return -1; - - res = PyObject_RichCompareBool(value1, value2, Py_EQ); - if (-1 == res) - return -1; - else if (1 == res) - return 0; - - res = PyObject_RichCompareBool(value1, value2, Py_GT); - if (-1 == res) - return -1; - else if (1 == res) - return 1; - - Exceptions.SetError(Exceptions.SystemError, "Error comparing objects"); - return -1; - } -#elif PYTHON2 - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] - internal static extern int PyObject_Compare(IntPtr value1, IntPtr value2); -#endif - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern int PyObject_IsInstance(IntPtr ob, IntPtr type); @@ -934,11 +302,6 @@ internal static int PyObject_Compare(IntPtr value1, IntPtr value2) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern int PyObject_Not(IntPtr pointer); - internal static long PyObject_Size(IntPtr pointer) - { - return (long) _PyObject_Size(pointer); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyObject_Size")] private static extern IntPtr _PyObject_Size(IntPtr pointer); @@ -951,11 +314,11 @@ internal static long PyObject_Size(IntPtr pointer) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyObject_Str(IntPtr pointer); -#if PYTHON3 +#if !PYTHON2 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyObject_Str")] internal static extern IntPtr PyObject_Unicode(IntPtr pointer); -#elif PYTHON2 +#else [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyObject_Unicode(IntPtr pointer); #endif @@ -968,11 +331,11 @@ internal static long PyObject_Size(IntPtr pointer) // Python number API //==================================================================== -#if PYTHON3 +#if !PYTHON2 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyNumber_Long")] internal static extern IntPtr PyNumber_Int(IntPtr ob); -#elif PYTHON2 +#else [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyNumber_Int(IntPtr ob); #endif @@ -986,29 +349,7 @@ internal static long PyObject_Size(IntPtr pointer) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern bool PyNumber_Check(IntPtr ob); - internal static bool PyInt_Check(IntPtr ob) - { - return PyObject_TypeCheck(ob, PyIntType); - } - - internal static bool PyBool_Check(IntPtr ob) - { - return PyObject_TypeCheck(ob, PyBoolType); - } - - internal static IntPtr PyInt_FromInt32(int value) - { - var v = new IntPtr(value); - return PyInt_FromLong(v); - } - - internal static IntPtr PyInt_FromInt64(long value) - { - var v = new IntPtr(value); - return PyInt_FromLong(v); - } - -#if PYTHON3 +#if !PYTHON2 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyLong_FromLong")] private static extern IntPtr PyInt_FromLong(IntPtr value); @@ -1020,7 +361,7 @@ internal static IntPtr PyInt_FromInt64(long value) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyLong_FromString")] internal static extern IntPtr PyInt_FromString(string value, IntPtr end, int radix); -#elif PYTHON2 +#else [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyInt_FromLong(IntPtr value); @@ -1034,11 +375,6 @@ internal static IntPtr PyInt_FromInt64(long value) internal static extern int PyInt_GetMax(); #endif - internal static bool PyLong_Check(IntPtr ob) - { - return PyObject_TYPE(ob) == PyLongType; - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyLong_FromLong(long value); @@ -1095,11 +431,6 @@ internal static object PyLong_AsUnsignedLong(IntPtr value) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern ulong PyLong_AsUnsignedLongLong(IntPtr value); - internal static bool PyFloat_Check(IntPtr ob) - { - return PyObject_TYPE(ob) == PyFloatType; - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyFloat_FromDouble(double value); @@ -1284,48 +615,22 @@ internal static long PySequence_Count(IntPtr pointer, IntPtr value) // Python string API //==================================================================== - internal static bool IsStringType(IntPtr op) - { - IntPtr t = PyObject_TYPE(op); - return (t == PyStringType) || (t == PyUnicodeType); - } - - internal static bool PyString_Check(IntPtr ob) - { - return PyObject_TYPE(ob) == PyStringType; - } - internal static IntPtr PyString_FromString(string value) { -#if PYTHON3 +#if !PYTHON2 return PyUnicode_FromKindAndData(_UCS, value, value.Length); -#elif PYTHON2 +#else return PyString_FromStringAndSize(value, value.Length); #endif } -#if PYTHON3 +#if !PYTHON2 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyBytes_FromString(string op); - internal static long PyBytes_Size(IntPtr op) - { - return (long) _PyBytes_Size(op); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyBytes_Size")] private static extern IntPtr _PyBytes_Size(IntPtr op); - internal static IntPtr PyBytes_AS_STRING(IntPtr ob) - { - return ob + BytesOffset.ob_sval; - } - - internal static IntPtr PyString_FromStringAndSize(string value, long size) - { - return _PyString_FromStringAndSize(value, new IntPtr(size)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyUnicode_FromStringAndSize")] internal static extern IntPtr _PyString_FromStringAndSize( @@ -1340,7 +645,7 @@ internal static IntPtr PyUnicode_FromStringAndSize(IntPtr value, long size) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyUnicode_FromStringAndSize(IntPtr value, IntPtr size); -#elif PYTHON2 +#else internal static IntPtr PyString_FromStringAndSize(string value, long size) { return PyString_FromStringAndSize(value, new IntPtr(size)); @@ -1356,12 +661,7 @@ internal static IntPtr PyString_FromStringAndSize(string value, long size) internal static extern int PyString_Size(IntPtr pointer); #endif - internal static bool PyUnicode_Check(IntPtr ob) - { - return PyObject_TYPE(ob) == PyUnicodeType; - } - -#if PYTHON3 +#if !PYTHON2 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyUnicode_FromObject(IntPtr ob); @@ -1398,7 +698,7 @@ internal static long PyUnicode_GetSize(IntPtr ob) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyUnicode_FromOrdinal(int c); -#elif PYTHON2 +#else [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = PyUnicodeEntryPoint + "FromObject")] internal static extern IntPtr PyUnicode_FromObject(IntPtr ob); @@ -1437,59 +737,10 @@ internal static long PyUnicode_GetSize(IntPtr ob) internal static extern IntPtr PyUnicode_FromOrdinal(int c); #endif - internal static IntPtr PyUnicode_FromString(string s) - { - return PyUnicode_FromUnicode(s, s.Length); - } - - /// - /// Function to access the internal PyUnicode/PyString object and - /// convert it to a managed string with the correct encoding. - /// - /// - /// We can't easily do this through through the CustomMarshaler's on - /// the returns because will have access to the IntPtr but not size. - /// - /// For PyUnicodeType, we can't convert with Marshal.PtrToStringUni - /// since it only works for UCS2. - /// - /// PyStringType or PyUnicodeType object to convert - /// Managed String - internal static string GetManagedString(IntPtr op) - { - IntPtr type = PyObject_TYPE(op); - -#if PYTHON2 // Python 3 strings are all Unicode - if (type == PyStringType) - { - return Marshal.PtrToStringAnsi(PyString_AsString(op), PyString_Size(op)); - } -#endif - - if (type == PyUnicodeType) - { - IntPtr p = PyUnicode_AsUnicode(op); - int length = (int)PyUnicode_GetSize(op); - - int size = length * _UCS; - var buffer = new byte[size]; - Marshal.Copy(p, buffer, 0, size); - return PyEncoding.GetString(buffer, 0, size); - } - - return null; - } - - //==================================================================== // Python dictionary API //==================================================================== - internal static bool PyDict_Check(IntPtr ob) - { - return PyObject_TYPE(ob) == PyDictType; - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyDict_New(); @@ -1548,43 +799,18 @@ internal static long PyDict_Size(IntPtr pointer) // Python list API //==================================================================== - internal static bool PyList_Check(IntPtr ob) - { - return PyObject_TYPE(ob) == PyListType; - } - - internal static IntPtr PyList_New(long size) - { - return PyList_New(new IntPtr(size)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyList_New(IntPtr size); [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyList_AsTuple(IntPtr pointer); - internal static IntPtr PyList_GetItem(IntPtr pointer, long index) - { - return PyList_GetItem(pointer, new IntPtr(index)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyList_GetItem(IntPtr pointer, IntPtr index); - internal static int PyList_SetItem(IntPtr pointer, long index, IntPtr value) - { - return PyList_SetItem(pointer, new IntPtr(index), value); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern int PyList_SetItem(IntPtr pointer, IntPtr index, IntPtr value); - internal static int PyList_Insert(IntPtr pointer, long index, IntPtr value) - { - return PyList_Insert(pointer, new IntPtr(index), value); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern int PyList_Insert(IntPtr pointer, IntPtr index, IntPtr value); @@ -1597,27 +823,12 @@ internal static int PyList_Insert(IntPtr pointer, long index, IntPtr value) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern int PyList_Sort(IntPtr pointer); - internal static IntPtr PyList_GetSlice(IntPtr pointer, long start, long end) - { - return PyList_GetSlice(pointer, new IntPtr(start), new IntPtr(end)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyList_GetSlice(IntPtr pointer, IntPtr start, IntPtr end); - internal static int PyList_SetSlice(IntPtr pointer, long start, long end, IntPtr value) - { - return PyList_SetSlice(pointer, new IntPtr(start), new IntPtr(end), value); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern int PyList_SetSlice(IntPtr pointer, IntPtr start, IntPtr end, IntPtr value); - internal static long PyList_Size(IntPtr pointer) - { - return (long) _PyList_Size(pointer); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyList_Size")] private static extern IntPtr _PyList_Size(IntPtr pointer); @@ -1625,48 +836,18 @@ internal static long PyList_Size(IntPtr pointer) // Python tuple API //==================================================================== - internal static bool PyTuple_Check(IntPtr ob) - { - return PyObject_TYPE(ob) == PyTupleType; - } - - internal static IntPtr PyTuple_New(long size) - { - return PyTuple_New(new IntPtr(size)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyTuple_New(IntPtr size); - internal static IntPtr PyTuple_GetItem(IntPtr pointer, long index) - { - return PyTuple_GetItem(pointer, new IntPtr(index)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyTuple_GetItem(IntPtr pointer, IntPtr index); - internal static int PyTuple_SetItem(IntPtr pointer, long index, IntPtr value) - { - return PyTuple_SetItem(pointer, new IntPtr(index), value); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern int PyTuple_SetItem(IntPtr pointer, IntPtr index, IntPtr value); - internal static IntPtr PyTuple_GetSlice(IntPtr pointer, long start, long end) - { - return PyTuple_GetSlice(pointer, new IntPtr(start), new IntPtr(end)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyTuple_GetSlice(IntPtr pointer, IntPtr start, IntPtr end); - internal static long PyTuple_Size(IntPtr pointer) - { - return (long) _PyTuple_Size(pointer); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PyTuple_Size")] private static extern IntPtr _PyTuple_Size(IntPtr pointer); @@ -1675,18 +856,6 @@ internal static long PyTuple_Size(IntPtr pointer) // Python iterator API //==================================================================== - internal static bool PyIter_Check(IntPtr pointer) - { - var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type); -#if PYTHON2 - long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags); - if ((tp_flags & TypeFlags.HaveIter) == 0) - return false; -#endif - IntPtr tp_iternext = Marshal.ReadIntPtr(ob_type, TypeOffset.tp_iternext); - return tp_iternext != IntPtr.Zero && tp_iternext != _PyObject_NextNotImplemented; - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyIter_Next(IntPtr pointer); @@ -1707,7 +876,7 @@ internal static bool PyIter_Check(IntPtr pointer) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern string PyModule_GetFilename(IntPtr module); -#if PYTHON3 +#if !PYTHON2 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyModule_Create2(IntPtr module, int apiver); #endif @@ -1727,14 +896,14 @@ internal static bool PyIter_Check(IntPtr pointer) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyImport_GetModuleDict(); -#if PYTHON3 +#if !PYTHON2 [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern void PySys_SetArgvEx( int argc, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrArrayMarshaler))] string[] argv, int updatepath ); -#elif PYTHON2 +#else [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern void PySys_SetArgvEx( int argc, @@ -1754,31 +923,15 @@ int updatepath // Python type object API //==================================================================== - internal static bool PyType_Check(IntPtr ob) - { - return PyObject_TypeCheck(ob, PyTypeType); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern void PyType_Modified(IntPtr type); [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern bool PyType_IsSubtype(IntPtr t1, IntPtr t2); - internal static bool PyObject_TypeCheck(IntPtr ob, IntPtr tp) - { - IntPtr t = PyObject_TYPE(ob); - return (t == tp) || PyType_IsSubtype(t, tp); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw); - internal static IntPtr PyType_GenericAlloc(IntPtr type, long n) - { - return PyType_GenericAlloc(type, new IntPtr(n)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyType_GenericAlloc(IntPtr type, IntPtr n); @@ -1814,19 +967,9 @@ internal static IntPtr PyType_GenericAlloc(IntPtr type, long n) // Python memory API //==================================================================== - internal static IntPtr PyMem_Malloc(long size) - { - return PyMem_Malloc(new IntPtr(size)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyMem_Malloc(IntPtr size); - internal static IntPtr PyMem_Realloc(IntPtr ptr, long size) - { - return PyMem_Realloc(ptr, new IntPtr(size)); - } - [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr PyMem_Realloc(IntPtr ptr, IntPtr size); @@ -1891,28 +1034,21 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size) [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] internal static extern int Py_MakePendingCalls(); - internal static void SetNoSiteFlag() - { - var loader = LibraryLoader.Get(OperatingSystem); - IntPtr dllLocal; - if (_PythonDll != "__Internal") - { - dllLocal = loader.Load(_PythonDll); - } + static void SetPyNoSiteFlag(int val) { - try - { - Py_NoSiteFlag = loader.GetFunction(dllLocal, "Py_NoSiteFlag"); - Marshal.WriteInt32(Py_NoSiteFlag, 1); - } - finally - { - if (dllLocal != IntPtr.Zero) - { - loader.Free(dllLocal); - } - } } + + static int GetPyNoSiteFlag() { + return 0; + } + + /* + { + var loader = LibraryLoader.Get(OperatingSystem); + + Py_NoSiteFlag = loader.GetFunction(IntPtr.Zero, "Py_NoSiteFlag"); + Marshal.WriteInt32(Py_NoSiteFlag, 1); + } */ } } diff --git a/Python.Runtime.Native/LibPythonPInvoke_.cs b/Python.Runtime.Native/LibPythonPInvoke_.cs new file mode 100644 index 000000000..a0e643b20 --- /dev/null +++ b/Python.Runtime.Native/LibPythonPInvoke_.cs @@ -0,0 +1,220 @@ +using Python.Runtime.Interfaces; + +namespace Python.Runtime.Native { + + public partial class LibPythonPInvoke { + void ILibPython.Py_IncRef(System.IntPtr ob) => LibPythonPInvoke.Py_IncRef(ob); + void ILibPython.Py_DecRef(System.IntPtr ob) => LibPythonPInvoke.Py_DecRef(ob); + void ILibPython.Py_InitializeEx(System.Int32 initsigs) => LibPythonPInvoke.Py_InitializeEx(initsigs); + System.Int32 ILibPython.Py_IsInitialized() => LibPythonPInvoke.Py_IsInitialized(); + void ILibPython.Py_Finalize() => LibPythonPInvoke.Py_Finalize(); + System.IntPtr ILibPython.PyGILState_Ensure() => LibPythonPInvoke.PyGILState_Ensure(); + void ILibPython.PyGILState_Release(System.IntPtr gs) => LibPythonPInvoke.PyGILState_Release(gs); + void ILibPython.PyEval_InitThreads() => LibPythonPInvoke.PyEval_InitThreads(); + System.Int32 ILibPython.PyEval_ThreadsInitialized() => LibPythonPInvoke.PyEval_ThreadsInitialized(); + void ILibPython.PyEval_AcquireLock() => LibPythonPInvoke.PyEval_AcquireLock(); + void ILibPython.PyEval_ReleaseLock() => LibPythonPInvoke.PyEval_ReleaseLock(); + System.IntPtr ILibPython.PyEval_SaveThread() => LibPythonPInvoke.PyEval_SaveThread(); + void ILibPython.PyEval_RestoreThread(System.IntPtr tstate) => LibPythonPInvoke.PyEval_RestoreThread(tstate); + System.IntPtr ILibPython.PyEval_GetBuiltins() => LibPythonPInvoke.PyEval_GetBuiltins(); + System.IntPtr ILibPython.PyEval_GetGlobals() => LibPythonPInvoke.PyEval_GetGlobals(); + System.IntPtr ILibPython.PyEval_GetLocals() => LibPythonPInvoke.PyEval_GetLocals(); + System.IntPtr ILibPython.Py_GetProgramName() => LibPythonPInvoke.Py_GetProgramName(); + void ILibPython.Py_SetProgramName(System.IntPtr name) => LibPythonPInvoke.Py_SetProgramName(name); + System.IntPtr ILibPython.Py_GetPythonHome() => LibPythonPInvoke.Py_GetPythonHome(); + void ILibPython.Py_SetPythonHome(System.IntPtr home) => LibPythonPInvoke.Py_SetPythonHome(home); + System.IntPtr ILibPython.Py_GetPath() => LibPythonPInvoke.Py_GetPath(); + void ILibPython.Py_SetPath(System.IntPtr home) => LibPythonPInvoke.Py_SetPath(home); + System.IntPtr ILibPython.Py_GetVersion() => LibPythonPInvoke.Py_GetVersion(); + System.IntPtr ILibPython.Py_GetPlatform() => LibPythonPInvoke.Py_GetPlatform(); + System.IntPtr ILibPython.Py_GetCopyright() => LibPythonPInvoke.Py_GetCopyright(); + System.IntPtr ILibPython.Py_GetCompiler() => LibPythonPInvoke.Py_GetCompiler(); + System.IntPtr ILibPython.Py_GetBuildInfo() => LibPythonPInvoke.Py_GetBuildInfo(); + System.Int32 ILibPython.PyRun_SimpleString(System.String code) => LibPythonPInvoke.PyRun_SimpleString(code); + System.IntPtr ILibPython.PyRun_String(System.String code, System.IntPtr st, System.IntPtr globals, System.IntPtr locals) => LibPythonPInvoke.PyRun_String(code, st, globals, locals); + System.IntPtr ILibPython.PyEval_EvalCode(System.IntPtr co, System.IntPtr globals, System.IntPtr locals) => LibPythonPInvoke.PyEval_EvalCode(co, globals, locals); + System.IntPtr ILibPython.Py_CompileString(System.String code, System.String file, System.IntPtr tok) => LibPythonPInvoke.Py_CompileString(code, file, tok); + System.IntPtr ILibPython.PyImport_ExecCodeModule(System.String name, System.IntPtr code) => LibPythonPInvoke.PyImport_ExecCodeModule(name, code); + System.IntPtr ILibPython.PyCFunction_NewEx(System.IntPtr ml, System.IntPtr self, System.IntPtr mod) => LibPythonPInvoke.PyCFunction_NewEx(ml, self, mod); + System.IntPtr ILibPython.PyCFunction_Call(System.IntPtr func, System.IntPtr args, System.IntPtr kw) => LibPythonPInvoke.PyCFunction_Call(func, args, kw); + System.IntPtr ILibPython.PyInstance_New(System.IntPtr cls, System.IntPtr args, System.IntPtr kw) => LibPythonPInvoke.PyInstance_New(cls, args, kw); + System.IntPtr ILibPython.PyInstance_NewRaw(System.IntPtr cls, System.IntPtr dict) => LibPythonPInvoke.PyInstance_NewRaw(cls, dict); + System.IntPtr ILibPython.PyMethod_New(System.IntPtr func, System.IntPtr self, System.IntPtr cls) => LibPythonPInvoke.PyMethod_New(func, self, cls); + System.Int32 ILibPython.PyObject_HasAttrString(System.IntPtr pointer, System.String name) => LibPythonPInvoke.PyObject_HasAttrString(pointer, name); + System.IntPtr ILibPython.PyObject_GetAttrString(System.IntPtr pointer, System.String name) => LibPythonPInvoke.PyObject_GetAttrString(pointer, name); + System.Int32 ILibPython.PyObject_SetAttrString(System.IntPtr pointer, System.String name, System.IntPtr value) => LibPythonPInvoke.PyObject_SetAttrString(pointer, name, value); + System.Int32 ILibPython.PyObject_HasAttr(System.IntPtr pointer, System.IntPtr name) => LibPythonPInvoke.PyObject_HasAttr(pointer, name); + System.IntPtr ILibPython.PyObject_GetAttr(System.IntPtr pointer, System.IntPtr name) => LibPythonPInvoke.PyObject_GetAttr(pointer, name); + System.Int32 ILibPython.PyObject_SetAttr(System.IntPtr pointer, System.IntPtr name, System.IntPtr value) => LibPythonPInvoke.PyObject_SetAttr(pointer, name, value); + System.IntPtr ILibPython.PyObject_GetItem(System.IntPtr pointer, System.IntPtr key) => LibPythonPInvoke.PyObject_GetItem(pointer, key); + System.Int32 ILibPython.PyObject_SetItem(System.IntPtr pointer, System.IntPtr key, System.IntPtr value) => LibPythonPInvoke.PyObject_SetItem(pointer, key, value); + System.Int32 ILibPython.PyObject_DelItem(System.IntPtr pointer, System.IntPtr key) => LibPythonPInvoke.PyObject_DelItem(pointer, key); + System.IntPtr ILibPython.PyObject_GetIter(System.IntPtr op) => LibPythonPInvoke.PyObject_GetIter(op); + System.IntPtr ILibPython.PyObject_Call(System.IntPtr pointer, System.IntPtr args, System.IntPtr kw) => LibPythonPInvoke.PyObject_Call(pointer, args, kw); + System.IntPtr ILibPython.PyObject_CallObject(System.IntPtr pointer, System.IntPtr args) => LibPythonPInvoke.PyObject_CallObject(pointer, args); + System.Int32 ILibPython.PyObject_RichCompareBool(System.IntPtr value1, System.IntPtr value2, System.Int32 opid) => LibPythonPInvoke.PyObject_RichCompareBool(value1, value2, opid); + System.Int32 ILibPython.PyObject_IsInstance(System.IntPtr ob, System.IntPtr type) => LibPythonPInvoke.PyObject_IsInstance(ob, type); + System.Int32 ILibPython.PyObject_IsSubclass(System.IntPtr ob, System.IntPtr type) => LibPythonPInvoke.PyObject_IsSubclass(ob, type); + System.Int32 ILibPython.PyCallable_Check(System.IntPtr pointer) => LibPythonPInvoke.PyCallable_Check(pointer); + System.Int32 ILibPython.PyObject_IsTrue(System.IntPtr pointer) => LibPythonPInvoke.PyObject_IsTrue(pointer); + System.Int32 ILibPython.PyObject_Not(System.IntPtr pointer) => LibPythonPInvoke.PyObject_Not(pointer); + System.IntPtr ILibPython._PyObject_Size(System.IntPtr pointer) => LibPythonPInvoke._PyObject_Size(pointer); + System.IntPtr ILibPython.PyObject_Hash(System.IntPtr op) => LibPythonPInvoke.PyObject_Hash(op); + System.IntPtr ILibPython.PyObject_Repr(System.IntPtr pointer) => LibPythonPInvoke.PyObject_Repr(pointer); + System.IntPtr ILibPython.PyObject_Str(System.IntPtr pointer) => LibPythonPInvoke.PyObject_Str(pointer); + System.IntPtr ILibPython.PyObject_Unicode(System.IntPtr pointer) => LibPythonPInvoke.PyObject_Unicode(pointer); + System.IntPtr ILibPython.PyObject_Dir(System.IntPtr pointer) => LibPythonPInvoke.PyObject_Dir(pointer); + System.IntPtr ILibPython.PyNumber_Int(System.IntPtr ob) => LibPythonPInvoke.PyNumber_Int(ob); + System.IntPtr ILibPython.PyNumber_Long(System.IntPtr ob) => LibPythonPInvoke.PyNumber_Long(ob); + System.IntPtr ILibPython.PyNumber_Float(System.IntPtr ob) => LibPythonPInvoke.PyNumber_Float(ob); + System.Boolean ILibPython.PyNumber_Check(System.IntPtr ob) => LibPythonPInvoke.PyNumber_Check(ob); + System.IntPtr ILibPython.PyInt_FromLong(System.IntPtr value) => LibPythonPInvoke.PyInt_FromLong(value); + System.Int32 ILibPython.PyInt_AsLong(System.IntPtr value) => LibPythonPInvoke.PyInt_AsLong(value); + System.IntPtr ILibPython.PyInt_FromString(System.String value, System.IntPtr end, System.Int32 radix) => LibPythonPInvoke.PyInt_FromString(value, end, radix); + System.IntPtr ILibPython.PyLong_FromLong(System.Int64 value) => LibPythonPInvoke.PyLong_FromLong(value); + System.IntPtr ILibPython.PyLong_FromUnsignedLong32(System.UInt32 value) => LibPythonPInvoke.PyLong_FromUnsignedLong32(value); + System.IntPtr ILibPython.PyLong_FromUnsignedLong64(System.UInt64 value) => LibPythonPInvoke.PyLong_FromUnsignedLong64(value); + System.IntPtr ILibPython.PyLong_FromDouble(System.Double value) => LibPythonPInvoke.PyLong_FromDouble(value); + System.IntPtr ILibPython.PyLong_FromLongLong(System.Int64 value) => LibPythonPInvoke.PyLong_FromLongLong(value); + System.IntPtr ILibPython.PyLong_FromUnsignedLongLong(System.UInt64 value) => LibPythonPInvoke.PyLong_FromUnsignedLongLong(value); + System.IntPtr ILibPython.PyLong_FromString(System.String value, System.IntPtr end, System.Int32 radix) => LibPythonPInvoke.PyLong_FromString(value, end, radix); + System.Int32 ILibPython.PyLong_AsLong(System.IntPtr value) => LibPythonPInvoke.PyLong_AsLong(value); + System.UInt32 ILibPython.PyLong_AsUnsignedLong32(System.IntPtr value) => LibPythonPInvoke.PyLong_AsUnsignedLong32(value); + System.UInt64 ILibPython.PyLong_AsUnsignedLong64(System.IntPtr value) => LibPythonPInvoke.PyLong_AsUnsignedLong64(value); + System.Int64 ILibPython.PyLong_AsLongLong(System.IntPtr value) => LibPythonPInvoke.PyLong_AsLongLong(value); + System.UInt64 ILibPython.PyLong_AsUnsignedLongLong(System.IntPtr value) => LibPythonPInvoke.PyLong_AsUnsignedLongLong(value); + System.IntPtr ILibPython.PyFloat_FromDouble(System.Double value) => LibPythonPInvoke.PyFloat_FromDouble(value); + System.IntPtr ILibPython.PyFloat_FromString(System.IntPtr value, System.IntPtr junk) => LibPythonPInvoke.PyFloat_FromString(value, junk); + System.Double ILibPython.PyFloat_AsDouble(System.IntPtr ob) => LibPythonPInvoke.PyFloat_AsDouble(ob); + System.IntPtr ILibPython.PyNumber_Add(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Add(o1, o2); + System.IntPtr ILibPython.PyNumber_Subtract(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Subtract(o1, o2); + System.IntPtr ILibPython.PyNumber_Multiply(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Multiply(o1, o2); + System.IntPtr ILibPython.PyNumber_TrueDivide(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_TrueDivide(o1, o2); + System.IntPtr ILibPython.PyNumber_And(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_And(o1, o2); + System.IntPtr ILibPython.PyNumber_Xor(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Xor(o1, o2); + System.IntPtr ILibPython.PyNumber_Or(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Or(o1, o2); + System.IntPtr ILibPython.PyNumber_Lshift(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Lshift(o1, o2); + System.IntPtr ILibPython.PyNumber_Rshift(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Rshift(o1, o2); + System.IntPtr ILibPython.PyNumber_Power(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Power(o1, o2); + System.IntPtr ILibPython.PyNumber_Remainder(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_Remainder(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceAdd(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceAdd(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceSubtract(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceSubtract(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceMultiply(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceMultiply(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceTrueDivide(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceTrueDivide(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceAnd(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceAnd(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceXor(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceXor(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceOr(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceOr(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceLshift(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceLshift(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceRshift(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceRshift(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlacePower(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlacePower(o1, o2); + System.IntPtr ILibPython.PyNumber_InPlaceRemainder(System.IntPtr o1, System.IntPtr o2) => LibPythonPInvoke.PyNumber_InPlaceRemainder(o1, o2); + System.IntPtr ILibPython.PyNumber_Negative(System.IntPtr o1) => LibPythonPInvoke.PyNumber_Negative(o1); + System.IntPtr ILibPython.PyNumber_Positive(System.IntPtr o1) => LibPythonPInvoke.PyNumber_Positive(o1); + System.IntPtr ILibPython.PyNumber_Invert(System.IntPtr o1) => LibPythonPInvoke.PyNumber_Invert(o1); + System.Boolean ILibPython.PySequence_Check(System.IntPtr pointer) => LibPythonPInvoke.PySequence_Check(pointer); + System.IntPtr ILibPython.PySequence_GetItem(System.IntPtr pointer, System.IntPtr index) => LibPythonPInvoke.PySequence_GetItem(pointer, index); + System.Int32 ILibPython.PySequence_SetItem(System.IntPtr pointer, System.IntPtr index, System.IntPtr value) => LibPythonPInvoke.PySequence_SetItem(pointer, index, value); + System.Int32 ILibPython.PySequence_DelItem(System.IntPtr pointer, System.IntPtr index) => LibPythonPInvoke.PySequence_DelItem(pointer, index); + System.IntPtr ILibPython.PySequence_GetSlice(System.IntPtr pointer, System.IntPtr i1, System.IntPtr i2) => LibPythonPInvoke.PySequence_GetSlice(pointer, i1, i2); + System.Int32 ILibPython.PySequence_SetSlice(System.IntPtr pointer, System.IntPtr i1, System.IntPtr i2, System.IntPtr v) => LibPythonPInvoke.PySequence_SetSlice(pointer, i1, i2, v); + System.Int32 ILibPython.PySequence_DelSlice(System.IntPtr pointer, System.IntPtr i1, System.IntPtr i2) => LibPythonPInvoke.PySequence_DelSlice(pointer, i1, i2); + System.IntPtr ILibPython._PySequence_Size(System.IntPtr pointer) => LibPythonPInvoke._PySequence_Size(pointer); + System.Int32 ILibPython.PySequence_Contains(System.IntPtr pointer, System.IntPtr item) => LibPythonPInvoke.PySequence_Contains(pointer, item); + System.IntPtr ILibPython.PySequence_Concat(System.IntPtr pointer, System.IntPtr other) => LibPythonPInvoke.PySequence_Concat(pointer, other); + System.IntPtr ILibPython.PySequence_Repeat(System.IntPtr pointer, System.IntPtr count) => LibPythonPInvoke.PySequence_Repeat(pointer, count); + System.Int32 ILibPython.PySequence_Index(System.IntPtr pointer, System.IntPtr item) => LibPythonPInvoke.PySequence_Index(pointer, item); + System.IntPtr ILibPython._PySequence_Count(System.IntPtr pointer, System.IntPtr value) => LibPythonPInvoke._PySequence_Count(pointer, value); + System.IntPtr ILibPython.PySequence_Tuple(System.IntPtr pointer) => LibPythonPInvoke.PySequence_Tuple(pointer); + System.IntPtr ILibPython.PySequence_List(System.IntPtr pointer) => LibPythonPInvoke.PySequence_List(pointer); + System.IntPtr ILibPython.PyBytes_FromString(System.String op) => LibPythonPInvoke.PyBytes_FromString(op); + System.IntPtr ILibPython._PyBytes_Size(System.IntPtr op) => LibPythonPInvoke._PyBytes_Size(op); + System.IntPtr ILibPython._PyString_FromStringAndSize(System.String value, System.IntPtr size) => LibPythonPInvoke._PyString_FromStringAndSize(value, size); + System.IntPtr ILibPython.PyUnicode_FromStringAndSize(System.IntPtr value, System.IntPtr size) => LibPythonPInvoke.PyUnicode_FromStringAndSize(value, size); + System.IntPtr ILibPython.PyUnicode_FromOrdinal(System.Int32 c) => LibPythonPInvoke.PyUnicode_FromOrdinal(c); + System.IntPtr ILibPython.PyUnicode_AsUnicode(System.IntPtr ob) => LibPythonPInvoke.PyUnicode_AsUnicode(ob); + System.IntPtr ILibPython.PyUnicode_FromObject(System.IntPtr ob) => LibPythonPInvoke.PyUnicode_FromObject(ob); + System.IntPtr ILibPython.PyUnicode_FromEncodedObject(System.IntPtr ob, System.IntPtr enc, System.IntPtr err) => LibPythonPInvoke.PyUnicode_FromEncodedObject(ob, enc, err); + System.IntPtr ILibPython._PyUnicode_GetSize(System.IntPtr ob) => LibPythonPInvoke._PyUnicode_GetSize(ob); + System.IntPtr ILibPython.PyUnicode_FromKindAndData(System.Int32 kind, System.String s, System.IntPtr size) => LibPythonPInvoke.PyUnicode_FromKindAndData(kind, s, size); + System.IntPtr ILibPython.PyDict_New() => LibPythonPInvoke.PyDict_New(); + System.IntPtr ILibPython.PyDictProxy_New(System.IntPtr dict) => LibPythonPInvoke.PyDictProxy_New(dict); + System.IntPtr ILibPython.PyDict_GetItem(System.IntPtr pointer, System.IntPtr key) => LibPythonPInvoke.PyDict_GetItem(pointer, key); + System.IntPtr ILibPython.PyDict_GetItemString(System.IntPtr pointer, System.String key) => LibPythonPInvoke.PyDict_GetItemString(pointer, key); + System.Int32 ILibPython.PyDict_SetItem(System.IntPtr pointer, System.IntPtr key, System.IntPtr value) => LibPythonPInvoke.PyDict_SetItem(pointer, key, value); + System.Int32 ILibPython.PyDict_SetItemString(System.IntPtr pointer, System.String key, System.IntPtr value) => LibPythonPInvoke.PyDict_SetItemString(pointer, key, value); + System.Int32 ILibPython.PyDict_DelItem(System.IntPtr pointer, System.IntPtr key) => LibPythonPInvoke.PyDict_DelItem(pointer, key); + System.Int32 ILibPython.PyDict_DelItemString(System.IntPtr pointer, System.String key) => LibPythonPInvoke.PyDict_DelItemString(pointer, key); + System.Int32 ILibPython.PyMapping_HasKey(System.IntPtr pointer, System.IntPtr key) => LibPythonPInvoke.PyMapping_HasKey(pointer, key); + System.IntPtr ILibPython.PyDict_Keys(System.IntPtr pointer) => LibPythonPInvoke.PyDict_Keys(pointer); + System.IntPtr ILibPython.PyDict_Values(System.IntPtr pointer) => LibPythonPInvoke.PyDict_Values(pointer); + System.IntPtr ILibPython.PyDict_Items(System.IntPtr pointer) => LibPythonPInvoke.PyDict_Items(pointer); + System.IntPtr ILibPython.PyDict_Copy(System.IntPtr pointer) => LibPythonPInvoke.PyDict_Copy(pointer); + System.Int32 ILibPython.PyDict_Update(System.IntPtr pointer, System.IntPtr other) => LibPythonPInvoke.PyDict_Update(pointer, other); + void ILibPython.PyDict_Clear(System.IntPtr pointer) => LibPythonPInvoke.PyDict_Clear(pointer); + System.IntPtr ILibPython._PyDict_Size(System.IntPtr pointer) => LibPythonPInvoke._PyDict_Size(pointer); + System.IntPtr ILibPython.PyList_New(System.IntPtr size) => LibPythonPInvoke.PyList_New(size); + System.IntPtr ILibPython.PyList_AsTuple(System.IntPtr pointer) => LibPythonPInvoke.PyList_AsTuple(pointer); + System.IntPtr ILibPython.PyList_GetItem(System.IntPtr pointer, System.IntPtr index) => LibPythonPInvoke.PyList_GetItem(pointer, index); + System.Int32 ILibPython.PyList_SetItem(System.IntPtr pointer, System.IntPtr index, System.IntPtr value) => LibPythonPInvoke.PyList_SetItem(pointer, index, value); + System.Int32 ILibPython.PyList_Insert(System.IntPtr pointer, System.IntPtr index, System.IntPtr value) => LibPythonPInvoke.PyList_Insert(pointer, index, value); + System.Int32 ILibPython.PyList_Append(System.IntPtr pointer, System.IntPtr value) => LibPythonPInvoke.PyList_Append(pointer, value); + System.Int32 ILibPython.PyList_Reverse(System.IntPtr pointer) => LibPythonPInvoke.PyList_Reverse(pointer); + System.Int32 ILibPython.PyList_Sort(System.IntPtr pointer) => LibPythonPInvoke.PyList_Sort(pointer); + System.IntPtr ILibPython.PyList_GetSlice(System.IntPtr pointer, System.IntPtr start, System.IntPtr end) => LibPythonPInvoke.PyList_GetSlice(pointer, start, end); + System.Int32 ILibPython.PyList_SetSlice(System.IntPtr pointer, System.IntPtr start, System.IntPtr end, System.IntPtr value) => LibPythonPInvoke.PyList_SetSlice(pointer, start, end, value); + System.IntPtr ILibPython._PyList_Size(System.IntPtr pointer) => LibPythonPInvoke._PyList_Size(pointer); + System.IntPtr ILibPython.PyTuple_New(System.IntPtr size) => LibPythonPInvoke.PyTuple_New(size); + System.IntPtr ILibPython.PyTuple_GetItem(System.IntPtr pointer, System.IntPtr index) => LibPythonPInvoke.PyTuple_GetItem(pointer, index); + System.Int32 ILibPython.PyTuple_SetItem(System.IntPtr pointer, System.IntPtr index, System.IntPtr value) => LibPythonPInvoke.PyTuple_SetItem(pointer, index, value); + System.IntPtr ILibPython.PyTuple_GetSlice(System.IntPtr pointer, System.IntPtr start, System.IntPtr end) => LibPythonPInvoke.PyTuple_GetSlice(pointer, start, end); + System.IntPtr ILibPython._PyTuple_Size(System.IntPtr pointer) => LibPythonPInvoke._PyTuple_Size(pointer); + System.IntPtr ILibPython.PyIter_Next(System.IntPtr pointer) => LibPythonPInvoke.PyIter_Next(pointer); + System.IntPtr ILibPython.PyModule_New(System.String name) => LibPythonPInvoke.PyModule_New(name); + System.String ILibPython.PyModule_GetName(System.IntPtr module) => LibPythonPInvoke.PyModule_GetName(module); + System.IntPtr ILibPython.PyModule_GetDict(System.IntPtr module) => LibPythonPInvoke.PyModule_GetDict(module); + System.String ILibPython.PyModule_GetFilename(System.IntPtr module) => LibPythonPInvoke.PyModule_GetFilename(module); + System.IntPtr ILibPython.PyModule_Create2(System.IntPtr module, System.Int32 apiver) => LibPythonPInvoke.PyModule_Create2(module, apiver); + System.IntPtr ILibPython.PyImport_Import(System.IntPtr name) => LibPythonPInvoke.PyImport_Import(name); + System.IntPtr ILibPython.PyImport_ImportModule(System.String name) => LibPythonPInvoke.PyImport_ImportModule(name); + System.IntPtr ILibPython.PyImport_ReloadModule(System.IntPtr module) => LibPythonPInvoke.PyImport_ReloadModule(module); + System.IntPtr ILibPython.PyImport_AddModule(System.String name) => LibPythonPInvoke.PyImport_AddModule(name); + System.IntPtr ILibPython.PyImport_GetModuleDict() => LibPythonPInvoke.PyImport_GetModuleDict(); + void ILibPython.PySys_SetArgvEx(System.Int32 argc, System.String[] argv, System.Int32 updatepath) => LibPythonPInvoke.PySys_SetArgvEx(argc, argv, updatepath); + System.IntPtr ILibPython.PySys_GetObject(System.String name) => LibPythonPInvoke.PySys_GetObject(name); + System.Int32 ILibPython.PySys_SetObject(System.String name, System.IntPtr ob) => LibPythonPInvoke.PySys_SetObject(name, ob); + void ILibPython.PyType_Modified(System.IntPtr type) => LibPythonPInvoke.PyType_Modified(type); + System.Boolean ILibPython.PyType_IsSubtype(System.IntPtr t1, System.IntPtr t2) => LibPythonPInvoke.PyType_IsSubtype(t1, t2); + System.IntPtr ILibPython.PyType_GenericNew(System.IntPtr type, System.IntPtr args, System.IntPtr kw) => LibPythonPInvoke.PyType_GenericNew(type, args, kw); + System.IntPtr ILibPython.PyType_GenericAlloc(System.IntPtr type, System.IntPtr n) => LibPythonPInvoke.PyType_GenericAlloc(type, n); + System.Int32 ILibPython.PyType_Ready(System.IntPtr type) => LibPythonPInvoke.PyType_Ready(type); + System.IntPtr ILibPython._PyType_Lookup(System.IntPtr type, System.IntPtr name) => LibPythonPInvoke._PyType_Lookup(type, name); + System.IntPtr ILibPython.PyObject_GenericGetAttr(System.IntPtr obj, System.IntPtr name) => LibPythonPInvoke.PyObject_GenericGetAttr(obj, name); + System.Int32 ILibPython.PyObject_GenericSetAttr(System.IntPtr obj, System.IntPtr name, System.IntPtr value) => LibPythonPInvoke.PyObject_GenericSetAttr(obj, name, value); + System.IntPtr ILibPython._PyObject_GetDictPtr(System.IntPtr obj) => LibPythonPInvoke._PyObject_GetDictPtr(obj); + System.IntPtr ILibPython.PyObject_GC_New(System.IntPtr tp) => LibPythonPInvoke.PyObject_GC_New(tp); + void ILibPython.PyObject_GC_Del(System.IntPtr tp) => LibPythonPInvoke.PyObject_GC_Del(tp); + void ILibPython.PyObject_GC_Track(System.IntPtr tp) => LibPythonPInvoke.PyObject_GC_Track(tp); + void ILibPython.PyObject_GC_UnTrack(System.IntPtr tp) => LibPythonPInvoke.PyObject_GC_UnTrack(tp); + System.IntPtr ILibPython.PyMem_Malloc(System.IntPtr size) => LibPythonPInvoke.PyMem_Malloc(size); + System.IntPtr ILibPython.PyMem_Realloc(System.IntPtr ptr, System.IntPtr size) => LibPythonPInvoke.PyMem_Realloc(ptr, size); + void ILibPython.PyMem_Free(System.IntPtr ptr) => LibPythonPInvoke.PyMem_Free(ptr); + void ILibPython.PyErr_SetString(System.IntPtr ob, System.String message) => LibPythonPInvoke.PyErr_SetString(ob, message); + void ILibPython.PyErr_SetObject(System.IntPtr ob, System.IntPtr message) => LibPythonPInvoke.PyErr_SetObject(ob, message); + System.IntPtr ILibPython.PyErr_SetFromErrno(System.IntPtr ob) => LibPythonPInvoke.PyErr_SetFromErrno(ob); + void ILibPython.PyErr_SetNone(System.IntPtr ob) => LibPythonPInvoke.PyErr_SetNone(ob); + System.Int32 ILibPython.PyErr_ExceptionMatches(System.IntPtr exception) => LibPythonPInvoke.PyErr_ExceptionMatches(exception); + System.Int32 ILibPython.PyErr_GivenExceptionMatches(System.IntPtr ob, System.IntPtr val) => LibPythonPInvoke.PyErr_GivenExceptionMatches(ob, val); + void ILibPython.PyErr_NormalizeException(System.IntPtr ob, System.IntPtr val, System.IntPtr tb) => LibPythonPInvoke.PyErr_NormalizeException(ob, val, tb); + System.IntPtr ILibPython.PyErr_Occurred() => LibPythonPInvoke.PyErr_Occurred(); + void ILibPython.PyErr_Fetch(ref System.IntPtr ob, ref System.IntPtr val, ref System.IntPtr tb) => LibPythonPInvoke.PyErr_Fetch(ref ob, ref val, ref tb); + void ILibPython.PyErr_Restore(System.IntPtr ob, System.IntPtr val, System.IntPtr tb) => LibPythonPInvoke.PyErr_Restore(ob, val, tb); + void ILibPython.PyErr_Clear() => LibPythonPInvoke.PyErr_Clear(); + void ILibPython.PyErr_Print() => LibPythonPInvoke.PyErr_Print(); + System.IntPtr ILibPython.PyMethod_Self(System.IntPtr ob) => LibPythonPInvoke.PyMethod_Self(ob); + System.IntPtr ILibPython.PyMethod_Function(System.IntPtr ob) => LibPythonPInvoke.PyMethod_Function(ob); + System.Int32 ILibPython.Py_AddPendingCall(System.IntPtr func, System.IntPtr arg) => LibPythonPInvoke.Py_AddPendingCall(func, arg); + System.Int32 ILibPython.Py_MakePendingCalls() => LibPythonPInvoke.Py_MakePendingCalls(); + System.Int32 ILibPython.GetPyNoSiteFlag() => LibPythonPInvoke.GetPyNoSiteFlag(); + void ILibPython.SetPyNoSiteFlag(System.Int32 val) => LibPythonPInvoke.SetPyNoSiteFlag(val); + } +} diff --git a/Python.Runtime.Native/LibPythonPInvoke_.tt b/Python.Runtime.Native/LibPythonPInvoke_.tt new file mode 100644 index 000000000..8cc1eadcf --- /dev/null +++ b/Python.Runtime.Native/LibPythonPInvoke_.tt @@ -0,0 +1,41 @@ +<#@ template hostspecific="false" language="C#" #> +<#@ output extension=".cs" #> +<#@ assembly name="System.Core" #> +<#@ assembly name="System.Linq" #> +<#@ import namespace="System.Reflection" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.IO" #> +using Python.Runtime.Interfaces; + +namespace Python.Runtime.Native { + + public partial class LibPythonPInvoke { +<# + string FormatType(Type type) { + if (type == typeof(void)) + return "void"; + + if (type.IsByRef) + return $"ref {type.GetElementType().ToString()}"; + + return type.ToString(); + } + + var path = $"{Directory.GetCurrentDirectory()}/Python.Runtime.Interfaces/bin/Debug/netstandard2.0/Python.Runtime.Interfaces.dll"; + var assembly = Assembly.LoadFile(path); + var type = assembly.GetType("Python.Runtime.Interfaces.ILibPython"); + const BindingFlags flags = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance; + var methods = type.GetMethods(flags); + + foreach (var method in methods) { +#> + <#= FormatType(method.ReturnParameter.ParameterType) #> ILibPython.<#= method.Name #>(<#= + string.Join(", ", method.GetParameters().Select(x => $"{FormatType(x.ParameterType)} {x.Name}")) + #>) => LibPythonPInvoke.<#= method.Name #>(<#= + string.Join(", ", method.GetParameters().Select(x => (x.ParameterType.IsByRef ? "ref " : "") + x.Name)) + #>); +<# + } +#> + } +} diff --git a/Python.Runtime.Native/Python.Runtime.Native.csproj b/Python.Runtime.Native/Python.Runtime.Native.csproj new file mode 100644 index 000000000..bc0ded96f --- /dev/null +++ b/Python.Runtime.Native/Python.Runtime.Native.csproj @@ -0,0 +1,16 @@ + + + + netstandard2.0 + true + + + + + + + + + + + diff --git a/Python.Runtime/AssemblyInfo.cs b/Python.Runtime/AssemblyInfo.cs new file mode 100644 index 000000000..a369d6c8e --- /dev/null +++ b/Python.Runtime/AssemblyInfo.cs @@ -0,0 +1,5 @@ +using System; +using System.Runtime.CompilerServices; + +[assembly: CLSCompliant(true)] +[assembly: InternalsVisibleTo("Python.Test.Embed")] diff --git a/Python.Runtime/CustomMarshaler.cs b/Python.Runtime/CustomMarshaler.cs new file mode 100644 index 000000000..5d2a00294 --- /dev/null +++ b/Python.Runtime/CustomMarshaler.cs @@ -0,0 +1,252 @@ +using System; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace Python.Runtime.Native +{ + /// + /// Abstract class defining boiler plate methods that + /// Custom Marshalers will use. + /// + internal abstract class MarshalerBase : ICustomMarshaler + { + #if UCS2 && PYTHON2 + internal static Encoding PyEncoding = Encoding.Unicode; + internal static int UCS = 2; + #else + internal static Encoding PyEncoding = Encoding.UTF32; + internal static int UCS = 4; + #endif + + public object MarshalNativeToManaged(IntPtr pNativeData) + { + throw new NotImplementedException(); + } + + public abstract IntPtr MarshalManagedToNative(object managedObj); + + public void CleanUpNativeData(IntPtr pNativeData) + { + Marshal.FreeHGlobal(pNativeData); + } + + public void CleanUpManagedData(object managedObj) + { + // Let GC deal with it + } + + public int GetNativeDataSize() + { + return IntPtr.Size; + } + } + + + /// + /// Custom Marshaler to deal with Managed String to Native + /// conversion differences on UCS2/UCS4. + /// + internal class UcsMarshaler : MarshalerBase + { + private static readonly MarshalerBase Instance = new UcsMarshaler(); + + public override IntPtr MarshalManagedToNative(object managedObj) + { + var s = managedObj as string; + + if (s == null) + { + return IntPtr.Zero; + } + + byte[] bStr = PyEncoding.GetBytes(s + "\0"); + IntPtr mem = Marshal.AllocHGlobal(bStr.Length); + try + { + Marshal.Copy(bStr, 0, mem, bStr.Length); + } + catch (Exception) + { + Marshal.FreeHGlobal(mem); + throw; + } + + return mem; + } + + public static ICustomMarshaler GetInstance(string cookie) + { + return Instance; + } + + public static string PtrToStringUni(IntPtr p) + { + if (p == IntPtr.Zero) + { + return null; + } + + int size = GetUnicodeByteLength(p); + var buffer = new byte[size]; + Marshal.Copy(p, buffer, 0, size); + return PyEncoding.GetString(buffer, 0, size); + } + + public static int GetUnicodeByteLength(IntPtr p) + { + var len = 0; + while (true) + { +#if UCS2 && PYTHON2 + int c = Marshal.ReadInt16(p, len * 2); +#else + int c = Marshal.ReadInt32(p, len * 4); +#endif + + if (c == 0) + { + return len * UCS; + } + checked + { + ++len; + } + } + } + + /// + /// Utility function for Marshaling Unicode on PY3 and AnsiStr on PY2. + /// Use on functions whose Input signatures changed between PY2/PY3. + /// Ex. Py_SetPythonHome + /// + /// Managed String + /// + /// Ptr to Native String ANSI(PY2)/Unicode(PY3/UCS2)/UTF32(PY3/UCS4. + /// + /// + /// You MUST deallocate the IntPtr of the Return when done with it. + /// + public static IntPtr Py3UnicodePy2StringtoPtr(string s) + { +#if PYTHON2 + return Marshal.StringToHGlobalAnsi(s); +#else + return Instance.MarshalManagedToNative(s); +#endif + } + + /// + /// Utility function for Marshaling Unicode IntPtr on PY3 and + /// AnsiStr IntPtr on PY2 to Managed Strings. Use on Python functions + /// whose return type changed between PY2/PY3. + /// Ex. Py_GetPythonHome + /// + /// Native Ansi/Unicode/UTF32 String + /// + /// Managed String + /// + public static string PtrToPy3UnicodePy2String(IntPtr p) + { +#if PYTHON2 + return Marshal.PtrToStringAnsi(p); +#else + return PtrToStringUni(p); +#endif + } + } + + + /// + /// Custom Marshaler to deal with Managed String Arrays to Native + /// conversion differences on UCS2/UCS4. + /// + internal class StrArrayMarshaler : MarshalerBase + { + private static readonly MarshalerBase Instance = new StrArrayMarshaler(); + + public override IntPtr MarshalManagedToNative(object managedObj) + { + var argv = managedObj as string[]; + + if (argv == null) + { + return IntPtr.Zero; + } + + int totalStrLength = argv.Sum(arg => arg.Length + 1); + int memSize = argv.Length * IntPtr.Size + totalStrLength * UCS; + + IntPtr mem = Marshal.AllocHGlobal(memSize); + try + { + // Preparing array of pointers to strings + IntPtr curStrPtr = mem + argv.Length * IntPtr.Size; + for (var i = 0; i < argv.Length; i++) + { + byte[] bStr = PyEncoding.GetBytes(argv[i] + "\0"); + Marshal.Copy(bStr, 0, curStrPtr, bStr.Length); + Marshal.WriteIntPtr(mem + i * IntPtr.Size, curStrPtr); + curStrPtr += bStr.Length; + } + } + catch (Exception) + { + Marshal.FreeHGlobal(mem); + throw; + } + + return mem; + } + + public static ICustomMarshaler GetInstance(string cookie) + { + return Instance; + } + } + + + /// + /// Custom Marshaler to deal with Managed String to Native + /// conversion on UTF-8. Use on functions that expect UTF-8 encoded + /// strings like `PyUnicode_FromStringAndSize` + /// + /// + /// If instead we used `MarshalAs(UnmanagedType.LPWStr)` the output to + /// `foo` would be `f\x00o\x00o\x00`. + /// + internal class Utf8Marshaler : MarshalerBase + { + private static readonly MarshalerBase Instance = new Utf8Marshaler(); + private static new readonly Encoding PyEncoding = Encoding.UTF8; + + public override IntPtr MarshalManagedToNative(object managedObj) + { + var s = managedObj as string; + + if (s == null) + { + return IntPtr.Zero; + } + + byte[] bStr = PyEncoding.GetBytes(s + "\0"); + IntPtr mem = Marshal.AllocHGlobal(bStr.Length); + try + { + Marshal.Copy(bStr, 0, mem, bStr.Length); + } + catch (Exception) + { + Marshal.FreeHGlobal(mem); + throw; + } + + return mem; + } + + public static ICustomMarshaler GetInstance(string cookie) + { + return Instance; + } + } +} diff --git a/Python.Runtime/Python.Runtime.csproj b/Python.Runtime/Python.Runtime.csproj new file mode 100644 index 000000000..0a9b17594 --- /dev/null +++ b/Python.Runtime/Python.Runtime.csproj @@ -0,0 +1,18 @@ + + + + netstandard2.0 + true + + + + + + + + + + + + + diff --git a/src/runtime/Util.cs b/Python.Runtime/Util.cs similarity index 100% rename from src/runtime/Util.cs rename to Python.Runtime/Util.cs diff --git a/src/runtime/arrayobject.cs b/Python.Runtime/arrayobject.cs similarity index 100% rename from src/runtime/arrayobject.cs rename to Python.Runtime/arrayobject.cs diff --git a/src/runtime/assemblymanager.cs b/Python.Runtime/assemblymanager.cs similarity index 100% rename from src/runtime/assemblymanager.cs rename to Python.Runtime/assemblymanager.cs diff --git a/src/runtime/classbase.cs b/Python.Runtime/classbase.cs similarity index 100% rename from src/runtime/classbase.cs rename to Python.Runtime/classbase.cs diff --git a/src/runtime/classderived.cs b/Python.Runtime/classderived.cs similarity index 100% rename from src/runtime/classderived.cs rename to Python.Runtime/classderived.cs diff --git a/src/runtime/classmanager.cs b/Python.Runtime/classmanager.cs similarity index 100% rename from src/runtime/classmanager.cs rename to Python.Runtime/classmanager.cs diff --git a/src/runtime/classobject.cs b/Python.Runtime/classobject.cs similarity index 100% rename from src/runtime/classobject.cs rename to Python.Runtime/classobject.cs diff --git a/src/runtime/clrobject.cs b/Python.Runtime/clrobject.cs similarity index 100% rename from src/runtime/clrobject.cs rename to Python.Runtime/clrobject.cs diff --git a/src/runtime/codegenerator.cs b/Python.Runtime/codegenerator.cs similarity index 57% rename from src/runtime/codegenerator.cs rename to Python.Runtime/codegenerator.cs index dc466bafb..d5c03aa18 100644 --- a/src/runtime/codegenerator.cs +++ b/Python.Runtime/codegenerator.cs @@ -13,16 +13,40 @@ namespace Python.Runtime /// internal class CodeGenerator { - private AssemblyBuilder aBuilder; - private ModuleBuilder mBuilder; + private AssemblyBuilder _aBuilder = null; - internal CodeGenerator() + private AssemblyBuilder aBuilder + { + get + { + if (_aBuilder == null) + { + var aname = new AssemblyName { Name = "__CodeGenerator_Assembly" }; + var aa = AssemblyBuilderAccess.Run; + + _aBuilder = Thread.GetDomain().DefineDynamicAssembly(aname, aa); + } + + return _aBuilder; + } + } + + private ModuleBuilder _mBuilder = null; + private ModuleBuilder mBuilder { - var aname = new AssemblyName { Name = "__CodeGenerator_Assembly" }; - var aa = AssemblyBuilderAccess.Run; + get + { + if (_mBuilder == null) + { + _mBuilder = aBuilder.DefineDynamicModule("__CodeGenerator_Module"); + } + + return _mBuilder; + } + } - aBuilder = Thread.GetDomain().DefineDynamicAssembly(aname, aa); - mBuilder = aBuilder.DefineDynamicModule("__CodeGenerator_Module"); + internal CodeGenerator() + { } /// diff --git a/src/runtime/constructorbinder.cs b/Python.Runtime/constructorbinder.cs similarity index 100% rename from src/runtime/constructorbinder.cs rename to Python.Runtime/constructorbinder.cs diff --git a/src/runtime/constructorbinding.cs b/Python.Runtime/constructorbinding.cs similarity index 100% rename from src/runtime/constructorbinding.cs rename to Python.Runtime/constructorbinding.cs diff --git a/src/runtime/converter.cs b/Python.Runtime/converter.cs similarity index 97% rename from src/runtime/converter.cs rename to Python.Runtime/converter.cs index e7e047419..2e88065ed 100644 --- a/src/runtime/converter.cs +++ b/Python.Runtime/converter.cs @@ -86,8 +86,10 @@ internal static IntPtr GetPythonTypeByAlias(Type op) if (op == int32Type) return Runtime.PyIntType; - if (op == int64Type && Runtime.IsPython2) +#if PYTHON2 + if (op == int64Type) return Runtime.PyLongType; +#endif if (op == int64Type) return Runtime.PyIntType; @@ -156,15 +158,7 @@ internal static IntPtr ToPython(object value, Type type) var pyderived = value as IPythonDerivedType; if (null != pyderived) { - #if NETSTANDARD return ClassDerivedObject.ToPython(pyderived); - #else - // if object is remote don't do this - if (!System.Runtime.Remoting.RemotingServices.IsTransparentProxy(pyderived)) - { - return ClassDerivedObject.ToPython(pyderived); - } - #endif } // hmm - from Python, we almost never care what the declared @@ -463,8 +457,9 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.Int32: +#if PYTHON2 // Trickery to support 64-bit platforms. - if (Runtime.IsPython2 && Runtime.Is32Bit) + if (Runtime.Is32Bit) { op = Runtime.PyNumber_Int(value); @@ -488,7 +483,8 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo result = ival; return true; } - else // Python3 always use PyLong API +#else + // Python3 always use PyLong API { op = Runtime.PyNumber_Long(value); if (op == IntPtr.Zero) @@ -513,13 +509,14 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo result = (int)ll; return true; } +#endif case TypeCode.Boolean: result = Runtime.PyObject_IsTrue(value) != 0; return true; case TypeCode.Byte: -#if PYTHON3 +#if !PYTHON2 if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) { if (Runtime.PyBytes_Size(value) == 1) @@ -530,7 +527,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } -#elif PYTHON2 +#else if (Runtime.PyObject_TypeCheck(value, Runtime.PyStringType)) { if (Runtime.PyString_Size(value) == 1) @@ -564,7 +561,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.SByte: -#if PYTHON3 +#if !PYTHON2 if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) { if (Runtime.PyBytes_Size(value) == 1) @@ -575,7 +572,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } -#elif PYTHON2 +#else if (Runtime.PyObject_TypeCheck(value, Runtime.PyStringType)) { if (Runtime.PyString_Size(value) == 1) @@ -609,7 +606,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo return true; case TypeCode.Char: -#if PYTHON3 +#if !PYTHON2 if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) { if (Runtime.PyBytes_Size(value) == 1) @@ -620,7 +617,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } -#elif PYTHON2 +#else if (Runtime.PyObject_TypeCheck(value, Runtime.PyStringType)) { if (Runtime.PyString_Size(value) == 1) @@ -728,20 +725,20 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo } goto type_error; } - + uint ui; - try + try { ui = Convert.ToUInt32(Runtime.PyLong_AsUnsignedLong(op)); } catch (OverflowException) { // Probably wasn't an overflow in python but was in C# (e.g. if cpython - // longs are 64 bit then 0xFFFFFFFF + 1 will not overflow in + // longs are 64 bit then 0xFFFFFFFF + 1 will not overflow in // PyLong_AsUnsignedLong) Runtime.XDecref(op); goto overflow; } - + if (Exceptions.ErrorOccurred()) { @@ -875,7 +872,7 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s var listType = typeof(List<>); var constructedListType = listType.MakeGenericType(elementType); - IList list = IsSeqObj ? (IList) Activator.CreateInstance(constructedListType, new Object[] {(int) len}) : + IList list = IsSeqObj ? (IList) Activator.CreateInstance(constructedListType, new Object[] {(int) len}) : (IList) Activator.CreateInstance(constructedListType); IntPtr item; @@ -896,7 +893,7 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s items = Array.CreateInstance(elementType, list.Count); list.CopyTo(items, 0); - + result = items; return true; } diff --git a/src/runtime/debughelper.cs b/Python.Runtime/debughelper.cs similarity index 100% rename from src/runtime/debughelper.cs rename to Python.Runtime/debughelper.cs diff --git a/src/runtime/delegatemanager.cs b/Python.Runtime/delegatemanager.cs similarity index 100% rename from src/runtime/delegatemanager.cs rename to Python.Runtime/delegatemanager.cs diff --git a/src/runtime/delegateobject.cs b/Python.Runtime/delegateobject.cs similarity index 93% rename from src/runtime/delegateobject.cs rename to Python.Runtime/delegateobject.cs index e1103cbc7..c9aad9898 100644 --- a/src/runtime/delegateobject.cs +++ b/Python.Runtime/delegateobject.cs @@ -96,7 +96,6 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) /// /// Implements __cmp__ for reflected delegate types. /// -#if PYTHON3 // TODO: Doesn't PY2 implement tp_richcompare too? public new static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) { if (op != Runtime.Py_EQ && op != Runtime.Py_NE) @@ -126,13 +125,5 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) Runtime.XIncref(pyfalse); return pyfalse; } -#elif PYTHON2 - public static int tp_compare(IntPtr ob, IntPtr other) - { - Delegate d1 = GetTrueDelegate(ob); - Delegate d2 = GetTrueDelegate(other); - return d1 == d2 ? 0 : -1; - } -#endif } } diff --git a/src/runtime/eventbinding.cs b/Python.Runtime/eventbinding.cs similarity index 100% rename from src/runtime/eventbinding.cs rename to Python.Runtime/eventbinding.cs diff --git a/src/runtime/eventobject.cs b/Python.Runtime/eventobject.cs similarity index 100% rename from src/runtime/eventobject.cs rename to Python.Runtime/eventobject.cs diff --git a/src/runtime/exceptions.cs b/Python.Runtime/exceptions.cs similarity index 99% rename from src/runtime/exceptions.cs rename to Python.Runtime/exceptions.cs index 31c367eb2..e4e823a9a 100644 --- a/src/runtime/exceptions.cs +++ b/Python.Runtime/exceptions.cs @@ -103,7 +103,12 @@ private Exceptions() /// internal static void Initialize() { - string exceptionsModuleName = Runtime.IsPython3 ? "builtins" : "exceptions"; + string exceptionsModuleName = +#if PYTHON2 + "exceptions"; +#else + "builtins"; +#endif exceptions_module = Runtime.PyImport_ImportModule(exceptionsModuleName); Exceptions.ErrorCheck(exceptions_module); @@ -180,7 +185,7 @@ internal static void SetArgsAndCause(IntPtr ob) Marshal.WriteIntPtr(ob, ExceptionOffset.args, args); -#if PYTHON3 +#if !PYTHON2 if (e.InnerException != null) { IntPtr cause = CLRObject.GetInstHandle(e.InnerException); diff --git a/src/runtime/extensiontype.cs b/Python.Runtime/extensiontype.cs similarity index 100% rename from src/runtime/extensiontype.cs rename to Python.Runtime/extensiontype.cs diff --git a/src/runtime/fieldobject.cs b/Python.Runtime/fieldobject.cs similarity index 100% rename from src/runtime/fieldobject.cs rename to Python.Runtime/fieldobject.cs diff --git a/src/runtime/finalizer.cs b/Python.Runtime/finalizer.cs similarity index 100% rename from src/runtime/finalizer.cs rename to Python.Runtime/finalizer.cs diff --git a/src/runtime/generictype.cs b/Python.Runtime/generictype.cs similarity index 100% rename from src/runtime/generictype.cs rename to Python.Runtime/generictype.cs diff --git a/src/runtime/genericutil.cs b/Python.Runtime/genericutil.cs similarity index 100% rename from src/runtime/genericutil.cs rename to Python.Runtime/genericutil.cs diff --git a/src/runtime/importhook.cs b/Python.Runtime/importhook.cs similarity index 95% rename from src/runtime/importhook.cs rename to Python.Runtime/importhook.cs index 06ba7a56d..5458a932a 100644 --- a/src/runtime/importhook.cs +++ b/Python.Runtime/importhook.cs @@ -13,7 +13,6 @@ internal class ImportHook private static MethodWrapper hook; private static IntPtr py_clr_module; -#if PYTHON3 private static IntPtr module_def = IntPtr.Zero; internal static void InitializeModuleDef() @@ -23,27 +22,23 @@ internal static void InitializeModuleDef() module_def = ModuleDefOffset.AllocModuleDef("clr"); } } -#endif /// /// Get a New reference to the builtins module. /// static IntPtr GetNewRefToBuiltins() { - if (Runtime.IsPython3) - { - return Runtime.PyImport_ImportModule("builtins"); - } - else - { - // dict is a borrowed ref, no need to decref - IntPtr dict = Runtime.PyImport_GetModuleDict(); +#if !PYTHON2 + return Runtime.PyImport_ImportModule("builtins"); +#else + // dict is a borrowed ref, no need to decref + IntPtr dict = Runtime.PyImport_GetModuleDict(); - // GetItemString is a borrowed ref; incref to get a new ref - IntPtr builtins = Runtime.PyDict_GetItemString(dict, "__builtin__"); - Runtime.XIncref(builtins); - return builtins; - } + // GetItemString is a borrowed ref; incref to get a new ref + IntPtr builtins = Runtime.PyDict_GetItemString(dict, "__builtin__"); + Runtime.XIncref(builtins); + return builtins; +#endif } /// @@ -86,7 +81,7 @@ internal static void Initialize() // Initialize the clr module and tell Python about it. root = new CLRModule(); -#if PYTHON3 +#if !PYTHON2 // create a python module with the same methods as the clr module-like object InitializeModuleDef(); py_clr_module = Runtime.PyModule_Create2(module_def, 3); @@ -97,7 +92,7 @@ internal static void Initialize() clr_dict = (IntPtr)Marshal.PtrToStructure(clr_dict, typeof(IntPtr)); Runtime.PyDict_Update(mod_dict, clr_dict); -#elif PYTHON2 +#else Runtime.XIncref(root.pyHandle); // we are using the module two times py_clr_module = root.pyHandle; // Alias handle for PY2/PY3 #endif @@ -128,11 +123,10 @@ public static IntPtr GetCLRModule(IntPtr? fromList = null) { root.InitializePreload(); - if (Runtime.IsPython2) - { - Runtime.XIncref(py_clr_module); - return py_clr_module; - } +#if PYTHON2 + Runtime.XIncref(py_clr_module); + return py_clr_module; +#endif // Python 3 // update the module dictionary with the contents of the root dictionary diff --git a/src/runtime/indexer.cs b/Python.Runtime/indexer.cs similarity index 100% rename from src/runtime/indexer.cs rename to Python.Runtime/indexer.cs diff --git a/src/runtime/interfaceobject.cs b/Python.Runtime/interfaceobject.cs similarity index 100% rename from src/runtime/interfaceobject.cs rename to Python.Runtime/interfaceobject.cs diff --git a/src/runtime/interfaces.cs b/Python.Runtime/interfaces.cs similarity index 100% rename from src/runtime/interfaces.cs rename to Python.Runtime/interfaces.cs diff --git a/src/runtime/interop.cs b/Python.Runtime/interop.cs similarity index 99% rename from src/runtime/interop.cs rename to Python.Runtime/interop.cs index 4ae4b61e0..69d7637b4 100644 --- a/src/runtime/interop.cs +++ b/Python.Runtime/interop.cs @@ -155,7 +155,7 @@ public static int Size() public static int args = 0; #if PYTHON2 public static int message = 0; -#elif PYTHON3 +#else public static int traceback = 0; public static int context = 0; public static int cause = 0; @@ -168,7 +168,6 @@ public static int Size() } -#if PYTHON3 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] internal class BytesOffset { @@ -259,7 +258,6 @@ public static void FreeModuleDef(IntPtr ptr) public static int name = 0; } -#endif // PYTHON3 /// /// TypeFlags(): The actual bit values for the Type Flags stored @@ -269,17 +267,6 @@ public static void FreeModuleDef(IntPtr ptr) /// internal class TypeFlags { -#if PYTHON2 // these flags were removed in Python 3 - public static int HaveGetCharBuffer = (1 << 0); - public static int HaveSequenceIn = (1 << 1); - public static int GC = 0; - public static int HaveInPlaceOps = (1 << 3); - public static int CheckTypes = (1 << 4); - public static int HaveRichCompare = (1 << 5); - public static int HaveWeakRefs = (1 << 6); - public static int HaveIter = (1 << 7); - public static int HaveClass = (1 << 8); -#endif public static int HeapType = (1 << 9); public static int BaseType = (1 << 10); public static int Ready = (1 << 12); @@ -308,6 +295,15 @@ internal class TypeFlags public static int TypeSubclass = (1 << 31); #if PYTHON2 // Default flags for Python 2 + public static int HaveGetCharBuffer = (1 << 0); + public static int HaveSequenceIn = (1 << 1); + public static int GC = 0; + public static int HaveInPlaceOps = (1 << 3); + public static int CheckTypes = (1 << 4); + public static int HaveRichCompare = (1 << 5); + public static int HaveWeakRefs = (1 << 6); + public static int HaveIter = (1 << 7); + public static int HaveClass = (1 << 8); public static int Default = ( HaveGetCharBuffer | HaveSequenceIn | @@ -319,7 +315,7 @@ internal class TypeFlags HaveStacklessExtension | HaveIndex | 0); -#elif PYTHON3 // Default flags for Python 3 +#else // Default flags for Python 3 public static int Default = ( HaveStacklessExtension | HaveVersionTag); diff --git a/src/runtime/interop27.cs b/Python.Runtime/interop/interop2.cs similarity index 99% rename from src/runtime/interop27.cs rename to Python.Runtime/interop/interop2.cs index 4782e9d3b..1a561fd80 100644 --- a/src/runtime/interop27.cs +++ b/Python.Runtime/interop/interop2.cs @@ -2,7 +2,7 @@ // DO NOT MODIFIY BY HAND. -#if PYTHON27 +#if PYTHON2 using System; using System.Collections; using System.Collections.Specialized; diff --git a/src/runtime/interop38.cs b/Python.Runtime/interop/interop3.cs similarity index 97% rename from src/runtime/interop38.cs rename to Python.Runtime/interop/interop3.cs index 8f2e32afe..3f284894b 100644 --- a/src/runtime/interop38.cs +++ b/Python.Runtime/interop/interop3.cs @@ -1,9 +1,10 @@ // Auto-generated by geninterop.py. -// DO NOT MODIFIY BY HAND. +// DO NOT MODIFY BY HAND. -#if PYTHON38 +#if !PYTHON2 +// TODO: Need new dynamic version of this from Python 3.8 onwards using System; using System.Collections; using System.Collections.Specialized; @@ -84,6 +85,7 @@ public static int magic() public static int tp_version_tag = 0; public static int tp_finalize = 0; public static int tp_vectorcall = 0; + public static int tp_print = 0; public static int am_await = 0; public static int am_aiter = 0; public static int am_anext = 0; @@ -149,4 +151,3 @@ public static int magic() } #endif - diff --git a/src/runtime/iterator.cs b/Python.Runtime/iterator.cs similarity index 100% rename from src/runtime/iterator.cs rename to Python.Runtime/iterator.cs diff --git a/src/runtime/managedtype.cs b/Python.Runtime/managedtype.cs similarity index 100% rename from src/runtime/managedtype.cs rename to Python.Runtime/managedtype.cs diff --git a/src/runtime/metatype.cs b/Python.Runtime/metatype.cs similarity index 100% rename from src/runtime/metatype.cs rename to Python.Runtime/metatype.cs diff --git a/src/runtime/methodbinder.cs b/Python.Runtime/methodbinder.cs similarity index 100% rename from src/runtime/methodbinder.cs rename to Python.Runtime/methodbinder.cs diff --git a/src/runtime/methodbinding.cs b/Python.Runtime/methodbinding.cs similarity index 100% rename from src/runtime/methodbinding.cs rename to Python.Runtime/methodbinding.cs diff --git a/src/runtime/methodobject.cs b/Python.Runtime/methodobject.cs similarity index 100% rename from src/runtime/methodobject.cs rename to Python.Runtime/methodobject.cs diff --git a/src/runtime/methodwrapper.cs b/Python.Runtime/methodwrapper.cs similarity index 100% rename from src/runtime/methodwrapper.cs rename to Python.Runtime/methodwrapper.cs diff --git a/src/runtime/modulefunctionobject.cs b/Python.Runtime/modulefunctionobject.cs similarity index 100% rename from src/runtime/modulefunctionobject.cs rename to Python.Runtime/modulefunctionobject.cs diff --git a/src/runtime/moduleobject.cs b/Python.Runtime/moduleobject.cs similarity index 100% rename from src/runtime/moduleobject.cs rename to Python.Runtime/moduleobject.cs diff --git a/src/runtime/modulepropertyobject.cs b/Python.Runtime/modulepropertyobject.cs similarity index 100% rename from src/runtime/modulepropertyobject.cs rename to Python.Runtime/modulepropertyobject.cs diff --git a/Python.Runtime/nativecall.cs b/Python.Runtime/nativecall.cs new file mode 100644 index 000000000..eea4b6fae --- /dev/null +++ b/Python.Runtime/nativecall.cs @@ -0,0 +1,51 @@ +using System; +using System.Reflection; +using System.Reflection.Emit; +using System.Runtime.InteropServices; +using System.Threading; + +namespace Python.Runtime +{ + /// + /// Provides support for calling native code indirectly through + /// function pointers. Most of the important parts of the Python + /// C API can just be wrapped with p/invoke, but there are some + /// situations (specifically, calling functions through Python + /// type structures) where we need to call functions indirectly. + /// This class uses Reflection.Emit to generate IJW thunks that + /// support indirect calls to native code using various common + /// call signatures. This is mainly a workaround for the fact + /// that you can't spell an indirect call in C# (but can in IL). + /// Another approach that would work is for this to be turned + /// into a separate utility program that could be run during the + /// build process to generate the thunks as a separate assembly + /// that could then be referenced by the main Python runtime. + /// + internal class NativeCall + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate void Void_1_Delegate(IntPtr a1); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate int Int_3_Delegate(IntPtr a1, IntPtr a2, IntPtr a3); + + public static void Void_Call_1(IntPtr fp, IntPtr a1) + { + var d = Marshal.GetDelegateForFunctionPointer(fp); + d(a1); + } + + public static IntPtr Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) + { + var d = Marshal.GetDelegateForFunctionPointer(fp); + return d(a1, a2, a3); + } + + + public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) + { + var d = Marshal.GetDelegateForFunctionPointer(fp); + return d(a1, a2, a3); + } + } +} diff --git a/src/runtime/overload.cs b/Python.Runtime/overload.cs similarity index 100% rename from src/runtime/overload.cs rename to Python.Runtime/overload.cs diff --git a/Python.Runtime/platform/InternalLoadContext.cs b/Python.Runtime/platform/InternalLoadContext.cs new file mode 100644 index 000000000..566d4000a --- /dev/null +++ b/Python.Runtime/platform/InternalLoadContext.cs @@ -0,0 +1,19 @@ +using System; +using System.Reflection; +using System.Runtime.Loader; + +namespace Python.Runtime.Platform +{ + class InternalLoadContext : AssemblyLoadContext + { + protected override Assembly Load(AssemblyName name) => null; + + protected override IntPtr LoadUnmanagedDll(string name) + { + var filtered = name == "__Internal" ? null : name; + return LibraryLoader.Instance.Load(filtered); + } + + public static AssemblyLoadContext Instance { get; } = new InternalLoadContext(); + } +} diff --git a/src/runtime/platform/LibraryLoader.cs b/Python.Runtime/platform/LibraryLoader.cs similarity index 82% rename from src/runtime/platform/LibraryLoader.cs rename to Python.Runtime/platform/LibraryLoader.cs index a6d88cd19..8a2b56d79 100644 --- a/src/runtime/platform/LibraryLoader.cs +++ b/Python.Runtime/platform/LibraryLoader.cs @@ -15,18 +15,27 @@ interface ILibraryLoader static class LibraryLoader { - public static ILibraryLoader Get(OperatingSystemType os) + static ILibraryLoader _instance = null; + + public static ILibraryLoader Instance { - switch (os) + get { - case OperatingSystemType.Windows: - return new WindowsLoader(); - case OperatingSystemType.Darwin: - return new DarwinLoader(); - case OperatingSystemType.Linux: - return new LinuxLoader(); - default: - throw new PlatformNotSupportedException($"This operating system ({os}) is not supported"); + if (_instance == null) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + _instance = new WindowsLoader(); + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + _instance = new DarwinLoader(); + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + _instance = new LinuxLoader(); + else + throw new PlatformNotSupportedException( + $"This operating system is not supported" + ); + } + + return _instance; } } } @@ -40,7 +49,15 @@ class LinuxLoader : ILibraryLoader public IntPtr Load(string dllToLoad) { - var filename = $"lib{dllToLoad}.so"; + string filename; + if (dllToLoad != null) + { + filename = $"lib{dllToLoad}.so"; + } + else + { + filename = null; + } ClearError(); var res = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); if (res == IntPtr.Zero) @@ -111,7 +128,15 @@ class DarwinLoader : ILibraryLoader public IntPtr Load(string dllToLoad) { - var filename = $"lib{dllToLoad}.dylib"; + string filename; + if (dllToLoad != null) + { + filename = $"lib{dllToLoad}.dylib"; + } + else + { + filename = null; + } ClearError(); var res = dlopen(filename, RTLD_NOW | RTLD_GLOBAL); if (res == IntPtr.Zero) diff --git a/src/runtime/platform/Types.cs b/Python.Runtime/platform/Types.cs similarity index 100% rename from src/runtime/platform/Types.cs rename to Python.Runtime/platform/Types.cs diff --git a/src/runtime/polyfill/ReflectionPolifills.cs b/Python.Runtime/polyfill/ReflectionPolyfills.cs similarity index 88% rename from src/runtime/polyfill/ReflectionPolifills.cs rename to Python.Runtime/polyfill/ReflectionPolyfills.cs index a7e9c879a..a44a15f72 100644 --- a/src/runtime/polyfill/ReflectionPolifills.cs +++ b/Python.Runtime/polyfill/ReflectionPolyfills.cs @@ -4,8 +4,7 @@ namespace Python.Runtime { -#if NETSTANDARD - public static class ReflectionPolifills + public static class ReflectionPolyfills { public static AssemblyBuilder DefineDynamicAssembly(this AppDomain appDomain, AssemblyName assemblyName, AssemblyBuilderAccess assemblyBuilderAccess) { @@ -17,5 +16,4 @@ public static Type CreateType(this TypeBuilder typeBuilder) return typeBuilder.GetTypeInfo().GetType(); } } -#endif } diff --git a/src/runtime/propertyobject.cs b/Python.Runtime/propertyobject.cs similarity index 98% rename from src/runtime/propertyobject.cs rename to Python.Runtime/propertyobject.cs index f2c97f163..893fbe54b 100644 --- a/src/runtime/propertyobject.cs +++ b/Python.Runtime/propertyobject.cs @@ -13,7 +13,6 @@ internal class PropertyObject : ExtensionType private MethodInfo getter; private MethodInfo setter; - [StrongNameIdentityPermission(SecurityAction.Assert)] public PropertyObject(PropertyInfo md) { getter = md.GetGetMethod(true); diff --git a/src/runtime/pyansistring.cs b/Python.Runtime/pyansistring.cs similarity index 100% rename from src/runtime/pyansistring.cs rename to Python.Runtime/pyansistring.cs diff --git a/src/runtime/pydict.cs b/Python.Runtime/pydict.cs similarity index 100% rename from src/runtime/pydict.cs rename to Python.Runtime/pydict.cs diff --git a/src/runtime/pyfloat.cs b/Python.Runtime/pyfloat.cs similarity index 100% rename from src/runtime/pyfloat.cs rename to Python.Runtime/pyfloat.cs diff --git a/src/runtime/pyint.cs b/Python.Runtime/pyint.cs similarity index 100% rename from src/runtime/pyint.cs rename to Python.Runtime/pyint.cs diff --git a/src/runtime/pyiter.cs b/Python.Runtime/pyiter.cs similarity index 100% rename from src/runtime/pyiter.cs rename to Python.Runtime/pyiter.cs diff --git a/src/runtime/pylist.cs b/Python.Runtime/pylist.cs similarity index 100% rename from src/runtime/pylist.cs rename to Python.Runtime/pylist.cs diff --git a/src/runtime/pylong.cs b/Python.Runtime/pylong.cs similarity index 100% rename from src/runtime/pylong.cs rename to Python.Runtime/pylong.cs diff --git a/src/runtime/pynumber.cs b/Python.Runtime/pynumber.cs similarity index 100% rename from src/runtime/pynumber.cs rename to Python.Runtime/pynumber.cs diff --git a/src/runtime/pyobject.cs b/Python.Runtime/pyobject.cs similarity index 100% rename from src/runtime/pyobject.cs rename to Python.Runtime/pyobject.cs diff --git a/src/runtime/pyscope.cs b/Python.Runtime/pyscope.cs similarity index 100% rename from src/runtime/pyscope.cs rename to Python.Runtime/pyscope.cs diff --git a/src/runtime/pysequence.cs b/Python.Runtime/pysequence.cs similarity index 100% rename from src/runtime/pysequence.cs rename to Python.Runtime/pysequence.cs diff --git a/src/runtime/pystring.cs b/Python.Runtime/pystring.cs similarity index 100% rename from src/runtime/pystring.cs rename to Python.Runtime/pystring.cs diff --git a/src/runtime/pythonengine.cs b/Python.Runtime/pythonengine.cs similarity index 95% rename from src/runtime/pythonengine.cs rename to Python.Runtime/pythonengine.cs index 700543839..0033928ea 100644 --- a/src/runtime/pythonengine.cs +++ b/Python.Runtime/pythonengine.cs @@ -1,9 +1,13 @@ +using System.Runtime.CompilerServices; +using System.Runtime.Loader; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; +using Python.Runtime.Native; +using Python.Runtime.Interfaces; namespace Python.Runtime { @@ -95,13 +99,13 @@ public static string PythonPath } set { - if (Runtime.IsPython2) - { - throw new NotSupportedException("Set PythonPath not supported on Python 2"); - } +#if PYTHON2 + throw new NotSupportedException("Set PythonPath not supported on Python 2"); +#else Marshal.FreeHGlobal(_pythonPath); _pythonPath = UcsMarshaler.Py3UnicodePy2StringtoPtr(value); Runtime.Py_SetPath(_pythonPath); +#endif } } @@ -115,11 +119,6 @@ public static string BuildInfo get { return Marshal.PtrToStringAnsi(Runtime.Py_GetBuildInfo()); } } - public static string Platform - { - get { return Marshal.PtrToStringAnsi(Runtime.Py_GetPlatform()); } - } - public static string Copyright { get { return Marshal.PtrToStringAnsi(Runtime.Py_GetCopyright()); } @@ -254,14 +253,19 @@ static void OnDomainUnload(object _, EventArgs __) /// CPython interpreter process - this bootstraps the managed runtime /// when it is imported by the CLR extension module. /// -#if PYTHON3 - public static IntPtr InitExt() -#elif PYTHON2 - public static void InitExt() -#endif + public static int InternalInitialize(IntPtr data, int size) { + + try { + Console.WriteLine("Running on {0}", RuntimeInformation.FrameworkDescription); + + var ass = Platform.InternalLoadContext.Instance.LoadFromAssemblyName(new AssemblyName("Python.Runtime.Native")); + + var typ = ass.GetType("Python.Runtime.Native.LibPythonPInvoke"); + Runtime.LibPython = (ILibPython)Activator.CreateInstance(typ); + Initialize(setSysArgv: false); // Trickery - when the import hook is installed into an already @@ -281,6 +285,9 @@ public static void InitExt() // still doesn't work if you use the interactive interpreter, // since there is no line info to get the import line ;( + // Console.WriteLine("Initialized"); + // Console.Out.Flush(); + string code = "import traceback\n" + "for item in traceback.extract_stack():\n" + @@ -294,18 +301,23 @@ public static void InitExt() " break\n"; PythonEngine.Exec(code); + + // Console.WriteLine("Exec'd traceback hack"); + // Console.Out.Flush(); + + return 0; } catch (PythonException e) { e.Restore(); -#if PYTHON3 - return IntPtr.Zero; -#endif + return -1; + } + catch (Exception e) + { + Console.Error.WriteLine(e.ToString()); + Console.Error.Write(e.StackTrace); + return -2; } - -#if PYTHON3 - return Python.Runtime.ImportHook.GetCLRModule(); -#endif } /// @@ -321,7 +333,7 @@ public static void Shutdown() if (initialized) { PyScopeManager.Global.Clear(); - + // If the shutdown handlers trigger a domain unload, // don't call shutdown again. AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload; @@ -584,7 +596,7 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals, borrowedGlobals = false; } } - + if (locals == null) { locals = globals; @@ -640,7 +652,7 @@ public static PyScope CreateScope(string name) var scope = PyScopeManager.Global.Create(name); return scope; } - + public class GILState : IDisposable { private IntPtr state; @@ -737,7 +749,7 @@ public static void SetArgv(IEnumerable argv) public static void With(PyObject obj, Action Body) { - // Behavior described here: + // Behavior described here: // https://docs.python.org/2/reference/datamodel.html#with-statement-context-managers IntPtr type = Runtime.PyNone; diff --git a/src/runtime/pythonexception.cs b/Python.Runtime/pythonexception.cs similarity index 100% rename from src/runtime/pythonexception.cs rename to Python.Runtime/pythonexception.cs diff --git a/src/runtime/pytuple.cs b/Python.Runtime/pytuple.cs similarity index 100% rename from src/runtime/pytuple.cs rename to Python.Runtime/pytuple.cs diff --git a/src/runtime/resources/clr.py b/Python.Runtime/resources/clr.py similarity index 100% rename from src/runtime/resources/clr.py rename to Python.Runtime/resources/clr.py diff --git a/Python.Runtime/runtime.cs b/Python.Runtime/runtime.cs new file mode 100644 index 000000000..f781158aa --- /dev/null +++ b/Python.Runtime/runtime.cs @@ -0,0 +1,861 @@ +using System; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using System.Threading; +using System.Collections.Generic; +using Python.Runtime.Platform; + +namespace Python.Runtime +{ + + /// + /// Encapsulates the low-level Python C API. Note that it is + /// the responsibility of the caller to have acquired the GIL + /// before calling any of these methods. + /// + public static partial class Runtime + { + // C# compiler copies constants to the assemblies that references this library. + // We needs to replace all public constants to static readonly fields to allow + // binary substitution of different Python.Runtime.dll builds in a target application. + + // set to true when python is finalizing + internal static object IsFinalizingLock = new object(); + internal static bool IsFinalizing; + + internal static bool Is32Bit = IntPtr.Size == 4; + + internal static bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + +#if PYTHON2 + internal static bool IsPython2 = true; +#else + internal static bool IsPython2 = false; +#endif + + internal static bool IsPython3 = !IsPython2; + + public static int MainManagedThreadId { get; private set; } + + #if UCS2 && PYTHON2 + static int _UCS = 2; + #else + static int _UCS = 4; + #endif + + /// + /// Encoding to use to convert Unicode to/from Managed to Native + /// + internal static readonly Encoding PyEncoding = _UCS == 2 ? Encoding.Unicode : Encoding.UTF32; + + /// + /// Initialize the runtime... + /// + internal static void Initialize(bool initSigs = false) + { + if (Py_IsInitialized() == 0) + { + Py_InitializeEx(initSigs ? 1 : 0); + MainManagedThreadId = Thread.CurrentThread.ManagedThreadId; + } + + if (PyEval_ThreadsInitialized() == 0) + { + PyEval_InitThreads(); + } + + IsFinalizing = false; + + CLRModule.Reset(); + GenericUtil.Reset(); + PyScopeManager.Reset(); + ClassManager.Reset(); + ClassDerivedObject.Reset(); + TypeManager.Reset(); + + IntPtr op; + IntPtr dict; + if (IsPython3) + { + op = PyImport_ImportModule("builtins"); + dict = PyObject_GetAttrString(op, "__dict__"); + } + else // Python2 + { + dict = PyImport_GetModuleDict(); + op = PyDict_GetItemString(dict, "__builtin__"); + } + PyNotImplemented = PyObject_GetAttrString(op, "NotImplemented"); + PyBaseObjectType = PyObject_GetAttrString(op, "object"); + + PyNone = PyObject_GetAttrString(op, "None"); + PyTrue = PyObject_GetAttrString(op, "True"); + PyFalse = PyObject_GetAttrString(op, "False"); + + PyBoolType = PyObject_Type(PyTrue); + PyNoneType = PyObject_Type(PyNone); + PyTypeType = PyObject_Type(PyNoneType); + + op = PyObject_GetAttrString(dict, "keys"); + PyMethodType = PyObject_Type(op); + XDecref(op); + + // For some arcane reason, builtins.__dict__.__setitem__ is *not* + // a wrapper_descriptor, even though dict.__setitem__ is. + // + // object.__init__ seems safe, though. + op = PyObject_GetAttrString(PyBaseObjectType, "__init__"); + PyWrapperDescriptorType = PyObject_Type(op); + XDecref(op); + +#if !PYTHON2 + XDecref(dict); +#endif + + op = PyString_FromString("string"); + PyStringType = PyObject_Type(op); + XDecref(op); + + op = PyUnicode_FromString("unicode"); + PyUnicodeType = PyObject_Type(op); + XDecref(op); + +#if !PYTHON2 + op = PyBytes_FromString("bytes"); + PyBytesType = PyObject_Type(op); + XDecref(op); +#endif + + op = PyTuple_New(0); + PyTupleType = PyObject_Type(op); + XDecref(op); + + op = PyList_New(0); + PyListType = PyObject_Type(op); + XDecref(op); + + op = PyDict_New(); + PyDictType = PyObject_Type(op); + XDecref(op); + + op = PyInt_FromInt32(0); + PyIntType = PyObject_Type(op); + XDecref(op); + + op = PyLong_FromLong(0); + PyLongType = PyObject_Type(op); + XDecref(op); + + op = PyFloat_FromDouble(0); + PyFloatType = PyObject_Type(op); + XDecref(op); + + PyClassType = IntPtr.Zero; + PyInstanceType = IntPtr.Zero; + +#if PYTHON2 + IntPtr s = PyString_FromString("_temp"); + IntPtr d = PyDict_New(); + + IntPtr c = PyClass_New(IntPtr.Zero, d, s); + PyClassType = PyObject_Type(c); + + IntPtr i = PyInstance_New(c, IntPtr.Zero, IntPtr.Zero); + PyInstanceType = PyObject_Type(i); + + XDecref(s); + XDecref(i); + XDecref(c); + XDecref(d); +#endif + + Error = new IntPtr(-1); + + IntPtr dllLocal = IntPtr.Zero; + var loader = LibraryLoader.Instance; + + _PyObject_NextNotImplemented = loader.GetFunction(dllLocal, "_PyObject_NextNotImplemented"); + PyModuleType = loader.GetFunction(dllLocal, "PyModule_Type"); + + // Initialize modules that depend on the runtime class. + AssemblyManager.Initialize(); + PyCLRMetaType = MetaType.Initialize(); + Exceptions.Initialize(); + ImportHook.Initialize(); + + // Need to add the runtime directory to sys.path so that we + // can find built-in assemblies like System.Data, et. al. + string rtdir = RuntimeEnvironment.GetRuntimeDirectory(); + IntPtr path = PySys_GetObject("path"); + IntPtr item = PyString_FromString(rtdir); + PyList_Append(path, item); + XDecref(item); + AssemblyManager.UpdatePath(); + } + + internal static void Shutdown() + { + AssemblyManager.Shutdown(); + Exceptions.Shutdown(); + ImportHook.Shutdown(); + Finalizer.Shutdown(); + Py_Finalize(); + } + + // called *without* the GIL acquired by clr._AtExit + internal static int AtExit() + { + lock (IsFinalizingLock) + { + IsFinalizing = true; + } + return 0; + } + + internal static IntPtr Py_single_input = (IntPtr)256; + internal static IntPtr Py_file_input = (IntPtr)257; + internal static IntPtr Py_eval_input = (IntPtr)258; + + internal static IntPtr PyBaseObjectType; + internal static IntPtr PyModuleType; + internal static IntPtr PyClassType; + internal static IntPtr PyInstanceType; + internal static IntPtr PyCLRMetaType; + internal static IntPtr PyMethodType; + internal static IntPtr PyWrapperDescriptorType; + + internal static IntPtr PyUnicodeType; + internal static IntPtr PyStringType; + internal static IntPtr PyTupleType; + internal static IntPtr PyListType; + internal static IntPtr PyDictType; + internal static IntPtr PyIntType; + internal static IntPtr PyLongType; + internal static IntPtr PyFloatType; + internal static IntPtr PyBoolType; + internal static IntPtr PyNoneType; + internal static IntPtr PyTypeType; + + + internal static IntPtr PyBytesType; + internal static IntPtr _PyObject_NextNotImplemented; + + internal static IntPtr PyNotImplemented; + internal const int Py_LT = 0; + internal const int Py_LE = 1; + internal const int Py_EQ = 2; + internal const int Py_NE = 3; + internal const int Py_GT = 4; + internal const int Py_GE = 5; + + internal static IntPtr PyTrue; + internal static IntPtr PyFalse; + internal static IntPtr PyNone; + internal static IntPtr Error; + + /// + /// Check if any Python Exceptions occurred. + /// If any exist throw new PythonException. + /// + /// + /// Can be used instead of `obj == IntPtr.Zero` for example. + /// + internal static void CheckExceptionOccurred() + { + if (PyErr_Occurred() != IntPtr.Zero) + { + throw new PythonException(); + } + } + + internal static IntPtr ExtendTuple(IntPtr t, params IntPtr[] args) + { + var size = PyTuple_Size(t); + int add = args.Length; + IntPtr item; + + IntPtr items = PyTuple_New(size + add); + for (var i = 0; i < size; i++) + { + item = PyTuple_GetItem(t, i); + XIncref(item); + PyTuple_SetItem(items, i, item); + } + + for (var n = 0; n < add; n++) + { + item = args[n]; + XIncref(item); + PyTuple_SetItem(items, size + n, item); + } + + return items; + } + + internal static Type[] PythonArgsToTypeArray(IntPtr arg) + { + return PythonArgsToTypeArray(arg, false); + } + + internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects) + { + // Given a PyObject * that is either a single type object or a + // tuple of (managed or unmanaged) type objects, return a Type[] + // containing the CLR Type objects that map to those types. + IntPtr args = arg; + var free = false; + + if (!PyTuple_Check(arg)) + { + args = PyTuple_New(1); + XIncref(arg); + PyTuple_SetItem(args, 0, arg); + free = true; + } + + var n = PyTuple_Size(args); + var types = new Type[n]; + Type t = null; + + for (var i = 0; i < n; i++) + { + IntPtr op = PyTuple_GetItem(args, i); + if (mangleObjects && (!PyType_Check(op))) + { + op = PyObject_TYPE(op); + } + ManagedType mt = ManagedType.GetManagedObject(op); + + if (mt is ClassBase) + { + t = ((ClassBase)mt).type; + } + else if (mt is CLRObject) + { + object inst = ((CLRObject)mt).inst; + if (inst is Type) + { + t = inst as Type; + } + } + else + { + t = Converter.GetTypeByAlias(op); + } + + if (t == null) + { + types = null; + break; + } + types[i] = t; + } + if (free) + { + XDecref(args); + } + return types; + } + + /// + /// Managed exports of the Python C API. Where appropriate, we do + /// some optimization to avoid managed <--> unmanaged transitions + /// (mostly for heavily used methods). + /// + internal static unsafe void XIncref(IntPtr op) + { + Py_IncRef(op); + return; + } + + internal static unsafe void XDecref(IntPtr op) + { + Py_DecRef(op); + return; + } + + internal static unsafe long Refcount(IntPtr op) + { + var p = (void*)op; + if ((void*)0 == p) + { + return 0; + } + return Is32Bit ? (*(int*)p) : (*(long*)p); + } + + + //==================================================================== + // Python abstract object API + //==================================================================== + + /// + /// A macro-like method to get the type of a Python object. This is + /// designed to be lean and mean in IL & avoid managed <-> unmanaged + /// transitions. Note that this does not incref the type object. + /// + internal static unsafe IntPtr PyObject_TYPE(IntPtr op) + { + var p = (void*)op; + if ((void*)0 == p) + { + return IntPtr.Zero; + } +#if PYTHON_WITH_PYDEBUG // TODO: Only for Python <3.8 + var n = 3; +#else + var n = 1; +#endif + return Is32Bit + ? new IntPtr((void*)(*((uint*)p + n))) + : new IntPtr((void*)(*((ulong*)p + n))); + } + + /// + /// Managed version of the standard Python C API PyObject_Type call. + /// This version avoids a managed <-> unmanaged transition. + /// This one does incref the returned type object. + /// + internal static IntPtr PyObject_Type(IntPtr op) + { + IntPtr tp = PyObject_TYPE(op); + XIncref(tp); + return tp; + } + + internal static string PyObject_GetTypeName(IntPtr op) + { + IntPtr pyType = Marshal.ReadIntPtr(op, ObjectOffset.ob_type); + IntPtr ppName = Marshal.ReadIntPtr(pyType, TypeOffset.tp_name); + return Marshal.PtrToStringAnsi(ppName); + } + + /// + /// Test whether the Python object is an iterable. + /// + internal static bool PyObject_IsIterable(IntPtr pointer) + { + var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type); +#if PYTHON2 + long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags); + if ((tp_flags & TypeFlags.HaveIter) == 0) + return false; +#endif + IntPtr tp_iter = Marshal.ReadIntPtr(ob_type, TypeOffset.tp_iter); + return tp_iter != IntPtr.Zero; + } + + internal static int PyObject_Compare(IntPtr value1, IntPtr value2) + { + int res; + res = PyObject_RichCompareBool(value1, value2, Py_LT); + if (-1 == res) + return -1; + else if (1 == res) + return -1; + + res = PyObject_RichCompareBool(value1, value2, Py_EQ); + if (-1 == res) + return -1; + else if (1 == res) + return 0; + + res = PyObject_RichCompareBool(value1, value2, Py_GT); + if (-1 == res) + return -1; + else if (1 == res) + return 1; + + Exceptions.SetError(Exceptions.SystemError, "Error comparing objects"); + return -1; + } + + internal static long PyObject_Size(IntPtr pointer) + { + return (long) _PyObject_Size(pointer); + } + + //==================================================================== + // Python number API + //==================================================================== + + internal static bool PyInt_Check(IntPtr ob) + { + return PyObject_TypeCheck(ob, PyIntType); + } + + internal static bool PyBool_Check(IntPtr ob) + { + return PyObject_TypeCheck(ob, PyBoolType); + } + + internal static IntPtr PyInt_FromInt32(int value) + { + var v = new IntPtr(value); + return PyInt_FromLong(v); + } + + internal static IntPtr PyInt_FromInt64(long value) + { + var v = new IntPtr(value); + return PyInt_FromLong(v); + } + + internal static bool PyLong_Check(IntPtr ob) + { + return PyObject_TYPE(ob) == PyLongType; + } + + internal static IntPtr PyLong_FromUnsignedLong(object value) + { + if(Is32Bit || IsWindows) + return PyLong_FromUnsignedLong32(Convert.ToUInt32(value)); + else + return PyLong_FromUnsignedLong64(Convert.ToUInt64(value)); + } + + internal static object PyLong_AsUnsignedLong(IntPtr value) + { + if (Is32Bit || IsWindows) + return PyLong_AsUnsignedLong32(value); + else + return PyLong_AsUnsignedLong64(value); + } + + internal static bool PyFloat_Check(IntPtr ob) + { + return PyObject_TYPE(ob) == PyFloatType; + } + + //==================================================================== + // Python sequence API + //==================================================================== + + internal static IntPtr PySequence_GetItem(IntPtr pointer, long index) + { + return PySequence_GetItem(pointer, new IntPtr(index)); + } + + internal static int PySequence_SetItem(IntPtr pointer, long index, IntPtr value) + { + return PySequence_SetItem(pointer, new IntPtr(index), value); + } + + internal static int PySequence_DelItem(IntPtr pointer, long index) + { + return PySequence_DelItem(pointer, new IntPtr(index)); + } + + internal static IntPtr PySequence_GetSlice(IntPtr pointer, long i1, long i2) + { + return PySequence_GetSlice(pointer, new IntPtr(i1), new IntPtr(i2)); + } + + internal static int PySequence_SetSlice(IntPtr pointer, long i1, long i2, IntPtr v) + { + return PySequence_SetSlice(pointer, new IntPtr(i1), new IntPtr(i2), v); + } + + internal static int PySequence_DelSlice(IntPtr pointer, long i1, long i2) + { + return PySequence_DelSlice(pointer, new IntPtr(i1), new IntPtr(i2)); + } + + internal static long PySequence_Size(IntPtr pointer) + { + return (long) _PySequence_Size(pointer); + } + + internal static IntPtr PySequence_Repeat(IntPtr pointer, long count) + { + return PySequence_Repeat(pointer, new IntPtr(count)); + } + + internal static long PySequence_Count(IntPtr pointer, IntPtr value) + { + return (long) _PySequence_Count(pointer, value); + } + + //==================================================================== + // Python string API + //==================================================================== + + internal static bool IsStringType(IntPtr op) + { + IntPtr t = PyObject_TYPE(op); + return (t == PyStringType) || (t == PyUnicodeType); + } + + internal static bool PyString_Check(IntPtr ob) + { + return PyObject_TYPE(ob) == PyStringType; + } + + internal static IntPtr PyString_FromString(string value) + { +#if !PYTHON2 + return PyUnicode_FromKindAndData(_UCS, value, value.Length); +#else + return PyString_FromStringAndSize(value, value.Length); +#endif + } + +#if !PYTHON2 + internal static long PyBytes_Size(IntPtr op) + { + return (long) _PyBytes_Size(op); + } + + internal static IntPtr PyBytes_AS_STRING(IntPtr ob) + { + return ob + BytesOffset.ob_sval; + } + + internal static IntPtr PyString_FromStringAndSize(string value, long size) + { + return _PyString_FromStringAndSize(value, new IntPtr(size)); + } + + internal static IntPtr PyUnicode_FromStringAndSize(IntPtr value, long size) + { + return PyUnicode_FromStringAndSize(value, new IntPtr(size)); + } +#else + internal static IntPtr PyString_FromStringAndSize(string value, long size) + { + return PyString_FromStringAndSize(value, new IntPtr(size)); + } +#endif + + internal static bool PyUnicode_Check(IntPtr ob) + { + return PyObject_TYPE(ob) == PyUnicodeType; + } + +#if !PYTHON2 + internal static IntPtr PyUnicode_FromKindAndData(int kind, string s, long size) + { + return PyUnicode_FromKindAndData(kind, s, new IntPtr(size)); + } + + internal static IntPtr PyUnicode_FromUnicode(string s, long size) + { + return PyUnicode_FromKindAndData(_UCS, s, size); + } + + internal static long PyUnicode_GetSize(IntPtr ob) + { + return (long)_PyUnicode_GetSize(ob); + } + +#else + internal static IntPtr PyUnicode_FromUnicode(string s, long size) + { + return PyUnicode_FromUnicode(s, new IntPtr(size)); + } + + internal static long PyUnicode_GetSize(IntPtr ob) + { + return (long) _PyUnicode_GetSize(ob); + } +#endif + + internal static IntPtr PyUnicode_FromString(string s) + { + return PyUnicode_FromUnicode(s, s.Length); + } + + /// + /// Function to access the internal PyUnicode/PyString object and + /// convert it to a managed string with the correct encoding. + /// + /// + /// We can't easily do this through through the CustomMarshaler's on + /// the returns because will have access to the IntPtr but not size. + /// + /// For PyUnicodeType, we can't convert with Marshal.PtrToStringUni + /// since it only works for UCS2. + /// + /// PyStringType or PyUnicodeType object to convert + /// Managed String + internal static string GetManagedString(IntPtr op) + { + IntPtr type = PyObject_TYPE(op); + +#if PYTHON2 // Python 3 strings are all Unicode + if (type == PyStringType) + { + return Marshal.PtrToStringAnsi(PyString_AsString(op), PyString_Size(op)); + } +#endif + + if (type == PyUnicodeType) + { + IntPtr p = PyUnicode_AsUnicode(op); + int length = (int)PyUnicode_GetSize(op); + + int size = length * _UCS; + var buffer = new byte[size]; + Marshal.Copy(p, buffer, 0, size); + return PyEncoding.GetString(buffer, 0, size); + } + + return null; + } + + + //==================================================================== + // Python dictionary API + //==================================================================== + + internal static bool PyDict_Check(IntPtr ob) + { + return PyObject_TYPE(ob) == PyDictType; + } + + internal static long PyDict_Size(IntPtr pointer) + { + return (long) _PyDict_Size(pointer); + } + + + //==================================================================== + // Python list API + //==================================================================== + + internal static bool PyList_Check(IntPtr ob) + { + return PyObject_TYPE(ob) == PyListType; + } + + internal static IntPtr PyList_New(long size) + { + return PyList_New(new IntPtr(size)); + } + + internal static IntPtr PyList_GetItem(IntPtr pointer, long index) + { + return PyList_GetItem(pointer, new IntPtr(index)); + } + + internal static int PyList_SetItem(IntPtr pointer, long index, IntPtr value) + { + return PyList_SetItem(pointer, new IntPtr(index), value); + } + + internal static int PyList_Insert(IntPtr pointer, long index, IntPtr value) + { + return PyList_Insert(pointer, new IntPtr(index), value); + } + + internal static IntPtr PyList_GetSlice(IntPtr pointer, long start, long end) + { + return PyList_GetSlice(pointer, new IntPtr(start), new IntPtr(end)); + } + + internal static int PyList_SetSlice(IntPtr pointer, long start, long end, IntPtr value) + { + return PyList_SetSlice(pointer, new IntPtr(start), new IntPtr(end), value); + } + + internal static long PyList_Size(IntPtr pointer) + { + return (long) _PyList_Size(pointer); + } + + //==================================================================== + // Python tuple API + //==================================================================== + + internal static bool PyTuple_Check(IntPtr ob) + { + return PyObject_TYPE(ob) == PyTupleType; + } + + internal static IntPtr PyTuple_New(long size) + { + return PyTuple_New(new IntPtr(size)); + } + + internal static IntPtr PyTuple_GetItem(IntPtr pointer, long index) + { + return PyTuple_GetItem(pointer, new IntPtr(index)); + } + + internal static int PyTuple_SetItem(IntPtr pointer, long index, IntPtr value) + { + return PyTuple_SetItem(pointer, new IntPtr(index), value); + } + + internal static IntPtr PyTuple_GetSlice(IntPtr pointer, long start, long end) + { + return PyTuple_GetSlice(pointer, new IntPtr(start), new IntPtr(end)); + } + + internal static long PyTuple_Size(IntPtr pointer) + { + return (long) _PyTuple_Size(pointer); + } + + //==================================================================== + // Python iterator API + //==================================================================== + + internal static bool PyIter_Check(IntPtr pointer) + { + var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type); +#if PYTHON2 + long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags); + if ((tp_flags & TypeFlags.HaveIter) == 0) + return false; +#endif + IntPtr tp_iternext = Marshal.ReadIntPtr(ob_type, TypeOffset.tp_iternext); + return tp_iternext != IntPtr.Zero && tp_iternext != _PyObject_NextNotImplemented; + } + + + //==================================================================== + // Python type object API + //==================================================================== + + internal static bool PyType_Check(IntPtr ob) + { + return PyObject_TypeCheck(ob, PyTypeType); + } + + internal static bool PyObject_TypeCheck(IntPtr ob, IntPtr tp) + { + IntPtr t = PyObject_TYPE(ob); + return (t == tp) || PyType_IsSubtype(t, tp); + } + + internal static IntPtr PyType_GenericAlloc(IntPtr type, long n) + { + return PyType_GenericAlloc(type, new IntPtr(n)); + } + + + //==================================================================== + // Python memory API + //==================================================================== + + internal static IntPtr PyMem_Malloc(long size) + { + return PyMem_Malloc(new IntPtr(size)); + } + + internal static IntPtr PyMem_Realloc(IntPtr ptr, long size) + { + return PyMem_Realloc(ptr, new IntPtr(size)); + } + + + internal static void SetNoSiteFlag() + { + SetPyNoSiteFlag(1); + } + + internal static Interfaces.ILibPython LibPython; + } +} diff --git a/Python.Runtime/runtime_.cs b/Python.Runtime/runtime_.cs new file mode 100644 index 000000000..38ad9e6ad --- /dev/null +++ b/Python.Runtime/runtime_.cs @@ -0,0 +1,219 @@ + +namespace Python.Runtime { + + partial class Runtime { + internal static void Py_IncRef(System.IntPtr ob) => LibPython.Py_IncRef(ob); + internal static void Py_DecRef(System.IntPtr ob) => LibPython.Py_DecRef(ob); + internal static void Py_InitializeEx(System.Int32 initsigs) => LibPython.Py_InitializeEx(initsigs); + internal static System.Int32 Py_IsInitialized() => LibPython.Py_IsInitialized(); + internal static void Py_Finalize() => LibPython.Py_Finalize(); + internal static System.IntPtr PyGILState_Ensure() => LibPython.PyGILState_Ensure(); + internal static void PyGILState_Release(System.IntPtr gs) => LibPython.PyGILState_Release(gs); + internal static void PyEval_InitThreads() => LibPython.PyEval_InitThreads(); + internal static System.Int32 PyEval_ThreadsInitialized() => LibPython.PyEval_ThreadsInitialized(); + internal static void PyEval_AcquireLock() => LibPython.PyEval_AcquireLock(); + internal static void PyEval_ReleaseLock() => LibPython.PyEval_ReleaseLock(); + internal static System.IntPtr PyEval_SaveThread() => LibPython.PyEval_SaveThread(); + internal static void PyEval_RestoreThread(System.IntPtr tstate) => LibPython.PyEval_RestoreThread(tstate); + internal static System.IntPtr PyEval_GetBuiltins() => LibPython.PyEval_GetBuiltins(); + internal static System.IntPtr PyEval_GetGlobals() => LibPython.PyEval_GetGlobals(); + internal static System.IntPtr PyEval_GetLocals() => LibPython.PyEval_GetLocals(); + internal static System.IntPtr Py_GetProgramName() => LibPython.Py_GetProgramName(); + internal static void Py_SetProgramName(System.IntPtr name) => LibPython.Py_SetProgramName(name); + internal static System.IntPtr Py_GetPythonHome() => LibPython.Py_GetPythonHome(); + internal static void Py_SetPythonHome(System.IntPtr home) => LibPython.Py_SetPythonHome(home); + internal static System.IntPtr Py_GetPath() => LibPython.Py_GetPath(); + internal static void Py_SetPath(System.IntPtr home) => LibPython.Py_SetPath(home); + internal static System.IntPtr Py_GetVersion() => LibPython.Py_GetVersion(); + internal static System.IntPtr Py_GetPlatform() => LibPython.Py_GetPlatform(); + internal static System.IntPtr Py_GetCopyright() => LibPython.Py_GetCopyright(); + internal static System.IntPtr Py_GetCompiler() => LibPython.Py_GetCompiler(); + internal static System.IntPtr Py_GetBuildInfo() => LibPython.Py_GetBuildInfo(); + internal static System.Int32 PyRun_SimpleString(System.String code) => LibPython.PyRun_SimpleString(code); + internal static System.IntPtr PyRun_String(System.String code, System.IntPtr st, System.IntPtr globals, System.IntPtr locals) => LibPython.PyRun_String(code, st, globals, locals); + internal static System.IntPtr PyEval_EvalCode(System.IntPtr co, System.IntPtr globals, System.IntPtr locals) => LibPython.PyEval_EvalCode(co, globals, locals); + internal static System.IntPtr Py_CompileString(System.String code, System.String file, System.IntPtr tok) => LibPython.Py_CompileString(code, file, tok); + internal static System.IntPtr PyImport_ExecCodeModule(System.String name, System.IntPtr code) => LibPython.PyImport_ExecCodeModule(name, code); + internal static System.IntPtr PyCFunction_NewEx(System.IntPtr ml, System.IntPtr self, System.IntPtr mod) => LibPython.PyCFunction_NewEx(ml, self, mod); + internal static System.IntPtr PyCFunction_Call(System.IntPtr func, System.IntPtr args, System.IntPtr kw) => LibPython.PyCFunction_Call(func, args, kw); + internal static System.IntPtr PyInstance_New(System.IntPtr cls, System.IntPtr args, System.IntPtr kw) => LibPython.PyInstance_New(cls, args, kw); + internal static System.IntPtr PyInstance_NewRaw(System.IntPtr cls, System.IntPtr dict) => LibPython.PyInstance_NewRaw(cls, dict); + internal static System.IntPtr PyMethod_New(System.IntPtr func, System.IntPtr self, System.IntPtr cls) => LibPython.PyMethod_New(func, self, cls); + internal static System.Int32 PyObject_HasAttrString(System.IntPtr pointer, System.String name) => LibPython.PyObject_HasAttrString(pointer, name); + internal static System.IntPtr PyObject_GetAttrString(System.IntPtr pointer, System.String name) => LibPython.PyObject_GetAttrString(pointer, name); + internal static System.Int32 PyObject_SetAttrString(System.IntPtr pointer, System.String name, System.IntPtr value) => LibPython.PyObject_SetAttrString(pointer, name, value); + internal static System.Int32 PyObject_HasAttr(System.IntPtr pointer, System.IntPtr name) => LibPython.PyObject_HasAttr(pointer, name); + internal static System.IntPtr PyObject_GetAttr(System.IntPtr pointer, System.IntPtr name) => LibPython.PyObject_GetAttr(pointer, name); + internal static System.Int32 PyObject_SetAttr(System.IntPtr pointer, System.IntPtr name, System.IntPtr value) => LibPython.PyObject_SetAttr(pointer, name, value); + internal static System.IntPtr PyObject_GetItem(System.IntPtr pointer, System.IntPtr key) => LibPython.PyObject_GetItem(pointer, key); + internal static System.Int32 PyObject_SetItem(System.IntPtr pointer, System.IntPtr key, System.IntPtr value) => LibPython.PyObject_SetItem(pointer, key, value); + internal static System.Int32 PyObject_DelItem(System.IntPtr pointer, System.IntPtr key) => LibPython.PyObject_DelItem(pointer, key); + internal static System.IntPtr PyObject_GetIter(System.IntPtr op) => LibPython.PyObject_GetIter(op); + internal static System.IntPtr PyObject_Call(System.IntPtr pointer, System.IntPtr args, System.IntPtr kw) => LibPython.PyObject_Call(pointer, args, kw); + internal static System.IntPtr PyObject_CallObject(System.IntPtr pointer, System.IntPtr args) => LibPython.PyObject_CallObject(pointer, args); + internal static System.Int32 PyObject_RichCompareBool(System.IntPtr value1, System.IntPtr value2, System.Int32 opid) => LibPython.PyObject_RichCompareBool(value1, value2, opid); + internal static System.Int32 PyObject_IsInstance(System.IntPtr ob, System.IntPtr type) => LibPython.PyObject_IsInstance(ob, type); + internal static System.Int32 PyObject_IsSubclass(System.IntPtr ob, System.IntPtr type) => LibPython.PyObject_IsSubclass(ob, type); + internal static System.Int32 PyCallable_Check(System.IntPtr pointer) => LibPython.PyCallable_Check(pointer); + internal static System.Int32 PyObject_IsTrue(System.IntPtr pointer) => LibPython.PyObject_IsTrue(pointer); + internal static System.Int32 PyObject_Not(System.IntPtr pointer) => LibPython.PyObject_Not(pointer); + internal static System.IntPtr _PyObject_Size(System.IntPtr pointer) => LibPython._PyObject_Size(pointer); + internal static System.IntPtr PyObject_Hash(System.IntPtr op) => LibPython.PyObject_Hash(op); + internal static System.IntPtr PyObject_Repr(System.IntPtr pointer) => LibPython.PyObject_Repr(pointer); + internal static System.IntPtr PyObject_Str(System.IntPtr pointer) => LibPython.PyObject_Str(pointer); + internal static System.IntPtr PyObject_Unicode(System.IntPtr pointer) => LibPython.PyObject_Unicode(pointer); + internal static System.IntPtr PyObject_Dir(System.IntPtr pointer) => LibPython.PyObject_Dir(pointer); + internal static System.IntPtr PyNumber_Int(System.IntPtr ob) => LibPython.PyNumber_Int(ob); + internal static System.IntPtr PyNumber_Long(System.IntPtr ob) => LibPython.PyNumber_Long(ob); + internal static System.IntPtr PyNumber_Float(System.IntPtr ob) => LibPython.PyNumber_Float(ob); + internal static System.Boolean PyNumber_Check(System.IntPtr ob) => LibPython.PyNumber_Check(ob); + internal static System.IntPtr PyInt_FromLong(System.IntPtr value) => LibPython.PyInt_FromLong(value); + internal static System.Int32 PyInt_AsLong(System.IntPtr value) => LibPython.PyInt_AsLong(value); + internal static System.IntPtr PyInt_FromString(System.String value, System.IntPtr end, System.Int32 radix) => LibPython.PyInt_FromString(value, end, radix); + internal static System.IntPtr PyLong_FromLong(System.Int64 value) => LibPython.PyLong_FromLong(value); + internal static System.IntPtr PyLong_FromUnsignedLong32(System.UInt32 value) => LibPython.PyLong_FromUnsignedLong32(value); + internal static System.IntPtr PyLong_FromUnsignedLong64(System.UInt64 value) => LibPython.PyLong_FromUnsignedLong64(value); + internal static System.IntPtr PyLong_FromDouble(System.Double value) => LibPython.PyLong_FromDouble(value); + internal static System.IntPtr PyLong_FromLongLong(System.Int64 value) => LibPython.PyLong_FromLongLong(value); + internal static System.IntPtr PyLong_FromUnsignedLongLong(System.UInt64 value) => LibPython.PyLong_FromUnsignedLongLong(value); + internal static System.IntPtr PyLong_FromString(System.String value, System.IntPtr end, System.Int32 radix) => LibPython.PyLong_FromString(value, end, radix); + internal static System.Int32 PyLong_AsLong(System.IntPtr value) => LibPython.PyLong_AsLong(value); + internal static System.UInt32 PyLong_AsUnsignedLong32(System.IntPtr value) => LibPython.PyLong_AsUnsignedLong32(value); + internal static System.UInt64 PyLong_AsUnsignedLong64(System.IntPtr value) => LibPython.PyLong_AsUnsignedLong64(value); + internal static System.Int64 PyLong_AsLongLong(System.IntPtr value) => LibPython.PyLong_AsLongLong(value); + internal static System.UInt64 PyLong_AsUnsignedLongLong(System.IntPtr value) => LibPython.PyLong_AsUnsignedLongLong(value); + internal static System.IntPtr PyFloat_FromDouble(System.Double value) => LibPython.PyFloat_FromDouble(value); + internal static System.IntPtr PyFloat_FromString(System.IntPtr value, System.IntPtr junk) => LibPython.PyFloat_FromString(value, junk); + internal static System.Double PyFloat_AsDouble(System.IntPtr ob) => LibPython.PyFloat_AsDouble(ob); + internal static System.IntPtr PyNumber_Add(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Add(o1, o2); + internal static System.IntPtr PyNumber_Subtract(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Subtract(o1, o2); + internal static System.IntPtr PyNumber_Multiply(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Multiply(o1, o2); + internal static System.IntPtr PyNumber_TrueDivide(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_TrueDivide(o1, o2); + internal static System.IntPtr PyNumber_And(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_And(o1, o2); + internal static System.IntPtr PyNumber_Xor(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Xor(o1, o2); + internal static System.IntPtr PyNumber_Or(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Or(o1, o2); + internal static System.IntPtr PyNumber_Lshift(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Lshift(o1, o2); + internal static System.IntPtr PyNumber_Rshift(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Rshift(o1, o2); + internal static System.IntPtr PyNumber_Power(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Power(o1, o2); + internal static System.IntPtr PyNumber_Remainder(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_Remainder(o1, o2); + internal static System.IntPtr PyNumber_InPlaceAdd(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceAdd(o1, o2); + internal static System.IntPtr PyNumber_InPlaceSubtract(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceSubtract(o1, o2); + internal static System.IntPtr PyNumber_InPlaceMultiply(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceMultiply(o1, o2); + internal static System.IntPtr PyNumber_InPlaceTrueDivide(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceTrueDivide(o1, o2); + internal static System.IntPtr PyNumber_InPlaceAnd(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceAnd(o1, o2); + internal static System.IntPtr PyNumber_InPlaceXor(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceXor(o1, o2); + internal static System.IntPtr PyNumber_InPlaceOr(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceOr(o1, o2); + internal static System.IntPtr PyNumber_InPlaceLshift(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceLshift(o1, o2); + internal static System.IntPtr PyNumber_InPlaceRshift(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceRshift(o1, o2); + internal static System.IntPtr PyNumber_InPlacePower(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlacePower(o1, o2); + internal static System.IntPtr PyNumber_InPlaceRemainder(System.IntPtr o1, System.IntPtr o2) => LibPython.PyNumber_InPlaceRemainder(o1, o2); + internal static System.IntPtr PyNumber_Negative(System.IntPtr o1) => LibPython.PyNumber_Negative(o1); + internal static System.IntPtr PyNumber_Positive(System.IntPtr o1) => LibPython.PyNumber_Positive(o1); + internal static System.IntPtr PyNumber_Invert(System.IntPtr o1) => LibPython.PyNumber_Invert(o1); + internal static System.Boolean PySequence_Check(System.IntPtr pointer) => LibPython.PySequence_Check(pointer); + internal static System.IntPtr PySequence_GetItem(System.IntPtr pointer, System.IntPtr index) => LibPython.PySequence_GetItem(pointer, index); + internal static System.Int32 PySequence_SetItem(System.IntPtr pointer, System.IntPtr index, System.IntPtr value) => LibPython.PySequence_SetItem(pointer, index, value); + internal static System.Int32 PySequence_DelItem(System.IntPtr pointer, System.IntPtr index) => LibPython.PySequence_DelItem(pointer, index); + internal static System.IntPtr PySequence_GetSlice(System.IntPtr pointer, System.IntPtr i1, System.IntPtr i2) => LibPython.PySequence_GetSlice(pointer, i1, i2); + internal static System.Int32 PySequence_SetSlice(System.IntPtr pointer, System.IntPtr i1, System.IntPtr i2, System.IntPtr v) => LibPython.PySequence_SetSlice(pointer, i1, i2, v); + internal static System.Int32 PySequence_DelSlice(System.IntPtr pointer, System.IntPtr i1, System.IntPtr i2) => LibPython.PySequence_DelSlice(pointer, i1, i2); + internal static System.IntPtr _PySequence_Size(System.IntPtr pointer) => LibPython._PySequence_Size(pointer); + internal static System.Int32 PySequence_Contains(System.IntPtr pointer, System.IntPtr item) => LibPython.PySequence_Contains(pointer, item); + internal static System.IntPtr PySequence_Concat(System.IntPtr pointer, System.IntPtr other) => LibPython.PySequence_Concat(pointer, other); + internal static System.IntPtr PySequence_Repeat(System.IntPtr pointer, System.IntPtr count) => LibPython.PySequence_Repeat(pointer, count); + internal static System.Int32 PySequence_Index(System.IntPtr pointer, System.IntPtr item) => LibPython.PySequence_Index(pointer, item); + internal static System.IntPtr _PySequence_Count(System.IntPtr pointer, System.IntPtr value) => LibPython._PySequence_Count(pointer, value); + internal static System.IntPtr PySequence_Tuple(System.IntPtr pointer) => LibPython.PySequence_Tuple(pointer); + internal static System.IntPtr PySequence_List(System.IntPtr pointer) => LibPython.PySequence_List(pointer); + internal static System.IntPtr PyBytes_FromString(System.String op) => LibPython.PyBytes_FromString(op); + internal static System.IntPtr _PyBytes_Size(System.IntPtr op) => LibPython._PyBytes_Size(op); + internal static System.IntPtr _PyString_FromStringAndSize(System.String value, System.IntPtr size) => LibPython._PyString_FromStringAndSize(value, size); + internal static System.IntPtr PyUnicode_FromStringAndSize(System.IntPtr value, System.IntPtr size) => LibPython.PyUnicode_FromStringAndSize(value, size); + internal static System.IntPtr PyUnicode_FromOrdinal(System.Int32 c) => LibPython.PyUnicode_FromOrdinal(c); + internal static System.IntPtr PyUnicode_AsUnicode(System.IntPtr ob) => LibPython.PyUnicode_AsUnicode(ob); + internal static System.IntPtr PyUnicode_FromObject(System.IntPtr ob) => LibPython.PyUnicode_FromObject(ob); + internal static System.IntPtr PyUnicode_FromEncodedObject(System.IntPtr ob, System.IntPtr enc, System.IntPtr err) => LibPython.PyUnicode_FromEncodedObject(ob, enc, err); + internal static System.IntPtr _PyUnicode_GetSize(System.IntPtr ob) => LibPython._PyUnicode_GetSize(ob); + internal static System.IntPtr PyUnicode_FromKindAndData(System.Int32 kind, System.String s, System.IntPtr size) => LibPython.PyUnicode_FromKindAndData(kind, s, size); + internal static System.IntPtr PyDict_New() => LibPython.PyDict_New(); + internal static System.IntPtr PyDictProxy_New(System.IntPtr dict) => LibPython.PyDictProxy_New(dict); + internal static System.IntPtr PyDict_GetItem(System.IntPtr pointer, System.IntPtr key) => LibPython.PyDict_GetItem(pointer, key); + internal static System.IntPtr PyDict_GetItemString(System.IntPtr pointer, System.String key) => LibPython.PyDict_GetItemString(pointer, key); + internal static System.Int32 PyDict_SetItem(System.IntPtr pointer, System.IntPtr key, System.IntPtr value) => LibPython.PyDict_SetItem(pointer, key, value); + internal static System.Int32 PyDict_SetItemString(System.IntPtr pointer, System.String key, System.IntPtr value) => LibPython.PyDict_SetItemString(pointer, key, value); + internal static System.Int32 PyDict_DelItem(System.IntPtr pointer, System.IntPtr key) => LibPython.PyDict_DelItem(pointer, key); + internal static System.Int32 PyDict_DelItemString(System.IntPtr pointer, System.String key) => LibPython.PyDict_DelItemString(pointer, key); + internal static System.Int32 PyMapping_HasKey(System.IntPtr pointer, System.IntPtr key) => LibPython.PyMapping_HasKey(pointer, key); + internal static System.IntPtr PyDict_Keys(System.IntPtr pointer) => LibPython.PyDict_Keys(pointer); + internal static System.IntPtr PyDict_Values(System.IntPtr pointer) => LibPython.PyDict_Values(pointer); + internal static System.IntPtr PyDict_Items(System.IntPtr pointer) => LibPython.PyDict_Items(pointer); + internal static System.IntPtr PyDict_Copy(System.IntPtr pointer) => LibPython.PyDict_Copy(pointer); + internal static System.Int32 PyDict_Update(System.IntPtr pointer, System.IntPtr other) => LibPython.PyDict_Update(pointer, other); + internal static void PyDict_Clear(System.IntPtr pointer) => LibPython.PyDict_Clear(pointer); + internal static System.IntPtr _PyDict_Size(System.IntPtr pointer) => LibPython._PyDict_Size(pointer); + internal static System.IntPtr PyList_New(System.IntPtr size) => LibPython.PyList_New(size); + internal static System.IntPtr PyList_AsTuple(System.IntPtr pointer) => LibPython.PyList_AsTuple(pointer); + internal static System.IntPtr PyList_GetItem(System.IntPtr pointer, System.IntPtr index) => LibPython.PyList_GetItem(pointer, index); + internal static System.Int32 PyList_SetItem(System.IntPtr pointer, System.IntPtr index, System.IntPtr value) => LibPython.PyList_SetItem(pointer, index, value); + internal static System.Int32 PyList_Insert(System.IntPtr pointer, System.IntPtr index, System.IntPtr value) => LibPython.PyList_Insert(pointer, index, value); + internal static System.Int32 PyList_Append(System.IntPtr pointer, System.IntPtr value) => LibPython.PyList_Append(pointer, value); + internal static System.Int32 PyList_Reverse(System.IntPtr pointer) => LibPython.PyList_Reverse(pointer); + internal static System.Int32 PyList_Sort(System.IntPtr pointer) => LibPython.PyList_Sort(pointer); + internal static System.IntPtr PyList_GetSlice(System.IntPtr pointer, System.IntPtr start, System.IntPtr end) => LibPython.PyList_GetSlice(pointer, start, end); + internal static System.Int32 PyList_SetSlice(System.IntPtr pointer, System.IntPtr start, System.IntPtr end, System.IntPtr value) => LibPython.PyList_SetSlice(pointer, start, end, value); + internal static System.IntPtr _PyList_Size(System.IntPtr pointer) => LibPython._PyList_Size(pointer); + internal static System.IntPtr PyTuple_New(System.IntPtr size) => LibPython.PyTuple_New(size); + internal static System.IntPtr PyTuple_GetItem(System.IntPtr pointer, System.IntPtr index) => LibPython.PyTuple_GetItem(pointer, index); + internal static System.Int32 PyTuple_SetItem(System.IntPtr pointer, System.IntPtr index, System.IntPtr value) => LibPython.PyTuple_SetItem(pointer, index, value); + internal static System.IntPtr PyTuple_GetSlice(System.IntPtr pointer, System.IntPtr start, System.IntPtr end) => LibPython.PyTuple_GetSlice(pointer, start, end); + internal static System.IntPtr _PyTuple_Size(System.IntPtr pointer) => LibPython._PyTuple_Size(pointer); + internal static System.IntPtr PyIter_Next(System.IntPtr pointer) => LibPython.PyIter_Next(pointer); + internal static System.IntPtr PyModule_New(System.String name) => LibPython.PyModule_New(name); + internal static System.String PyModule_GetName(System.IntPtr module) => LibPython.PyModule_GetName(module); + internal static System.IntPtr PyModule_GetDict(System.IntPtr module) => LibPython.PyModule_GetDict(module); + internal static System.String PyModule_GetFilename(System.IntPtr module) => LibPython.PyModule_GetFilename(module); + internal static System.IntPtr PyModule_Create2(System.IntPtr module, System.Int32 apiver) => LibPython.PyModule_Create2(module, apiver); + internal static System.IntPtr PyImport_Import(System.IntPtr name) => LibPython.PyImport_Import(name); + internal static System.IntPtr PyImport_ImportModule(System.String name) => LibPython.PyImport_ImportModule(name); + internal static System.IntPtr PyImport_ReloadModule(System.IntPtr module) => LibPython.PyImport_ReloadModule(module); + internal static System.IntPtr PyImport_AddModule(System.String name) => LibPython.PyImport_AddModule(name); + internal static System.IntPtr PyImport_GetModuleDict() => LibPython.PyImport_GetModuleDict(); + internal static void PySys_SetArgvEx(System.Int32 argc, System.String[] argv, System.Int32 updatepath) => LibPython.PySys_SetArgvEx(argc, argv, updatepath); + internal static System.IntPtr PySys_GetObject(System.String name) => LibPython.PySys_GetObject(name); + internal static System.Int32 PySys_SetObject(System.String name, System.IntPtr ob) => LibPython.PySys_SetObject(name, ob); + internal static void PyType_Modified(System.IntPtr type) => LibPython.PyType_Modified(type); + internal static System.Boolean PyType_IsSubtype(System.IntPtr t1, System.IntPtr t2) => LibPython.PyType_IsSubtype(t1, t2); + internal static System.IntPtr PyType_GenericNew(System.IntPtr type, System.IntPtr args, System.IntPtr kw) => LibPython.PyType_GenericNew(type, args, kw); + internal static System.IntPtr PyType_GenericAlloc(System.IntPtr type, System.IntPtr n) => LibPython.PyType_GenericAlloc(type, n); + internal static System.Int32 PyType_Ready(System.IntPtr type) => LibPython.PyType_Ready(type); + internal static System.IntPtr _PyType_Lookup(System.IntPtr type, System.IntPtr name) => LibPython._PyType_Lookup(type, name); + internal static System.IntPtr PyObject_GenericGetAttr(System.IntPtr obj, System.IntPtr name) => LibPython.PyObject_GenericGetAttr(obj, name); + internal static System.Int32 PyObject_GenericSetAttr(System.IntPtr obj, System.IntPtr name, System.IntPtr value) => LibPython.PyObject_GenericSetAttr(obj, name, value); + internal static System.IntPtr _PyObject_GetDictPtr(System.IntPtr obj) => LibPython._PyObject_GetDictPtr(obj); + internal static System.IntPtr PyObject_GC_New(System.IntPtr tp) => LibPython.PyObject_GC_New(tp); + internal static void PyObject_GC_Del(System.IntPtr tp) => LibPython.PyObject_GC_Del(tp); + internal static void PyObject_GC_Track(System.IntPtr tp) => LibPython.PyObject_GC_Track(tp); + internal static void PyObject_GC_UnTrack(System.IntPtr tp) => LibPython.PyObject_GC_UnTrack(tp); + internal static System.IntPtr PyMem_Malloc(System.IntPtr size) => LibPython.PyMem_Malloc(size); + internal static System.IntPtr PyMem_Realloc(System.IntPtr ptr, System.IntPtr size) => LibPython.PyMem_Realloc(ptr, size); + internal static void PyMem_Free(System.IntPtr ptr) => LibPython.PyMem_Free(ptr); + internal static void PyErr_SetString(System.IntPtr ob, System.String message) => LibPython.PyErr_SetString(ob, message); + internal static void PyErr_SetObject(System.IntPtr ob, System.IntPtr message) => LibPython.PyErr_SetObject(ob, message); + internal static System.IntPtr PyErr_SetFromErrno(System.IntPtr ob) => LibPython.PyErr_SetFromErrno(ob); + internal static void PyErr_SetNone(System.IntPtr ob) => LibPython.PyErr_SetNone(ob); + internal static System.Int32 PyErr_ExceptionMatches(System.IntPtr exception) => LibPython.PyErr_ExceptionMatches(exception); + internal static System.Int32 PyErr_GivenExceptionMatches(System.IntPtr ob, System.IntPtr val) => LibPython.PyErr_GivenExceptionMatches(ob, val); + internal static void PyErr_NormalizeException(System.IntPtr ob, System.IntPtr val, System.IntPtr tb) => LibPython.PyErr_NormalizeException(ob, val, tb); + internal static System.IntPtr PyErr_Occurred() => LibPython.PyErr_Occurred(); + internal static void PyErr_Fetch(ref System.IntPtr ob, ref System.IntPtr val, ref System.IntPtr tb) => LibPython.PyErr_Fetch(ref ob, ref val, ref tb); + internal static void PyErr_Restore(System.IntPtr ob, System.IntPtr val, System.IntPtr tb) => LibPython.PyErr_Restore(ob, val, tb); + internal static void PyErr_Clear() => LibPython.PyErr_Clear(); + internal static void PyErr_Print() => LibPython.PyErr_Print(); + internal static System.IntPtr PyMethod_Self(System.IntPtr ob) => LibPython.PyMethod_Self(ob); + internal static System.IntPtr PyMethod_Function(System.IntPtr ob) => LibPython.PyMethod_Function(ob); + internal static System.Int32 Py_AddPendingCall(System.IntPtr func, System.IntPtr arg) => LibPython.Py_AddPendingCall(func, arg); + internal static System.Int32 Py_MakePendingCalls() => LibPython.Py_MakePendingCalls(); + internal static System.Int32 GetPyNoSiteFlag() => LibPython.GetPyNoSiteFlag(); + internal static void SetPyNoSiteFlag(System.Int32 val) => LibPython.SetPyNoSiteFlag(val); + } +} diff --git a/Python.Runtime/runtime_.tt b/Python.Runtime/runtime_.tt new file mode 100644 index 000000000..7239594f4 --- /dev/null +++ b/Python.Runtime/runtime_.tt @@ -0,0 +1,40 @@ +<#@ template hostspecific="false" language="C#" #> +<#@ output extension=".cs" #> +<#@ assembly name="System.Core" #> +<#@ assembly name="System.Linq" #> +<#@ import namespace="System.Reflection" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.IO" #> + +namespace Python.Runtime { + + partial class Runtime { +<# + string FormatType(Type type) { + if (type == typeof(void)) + return "void"; + + if (type.IsByRef) + return $"ref {type.GetElementType().ToString()}"; + + return type.ToString(); + } + + var path = $"{Directory.GetCurrentDirectory()}/Python.Runtime.Interfaces/bin/Debug/netstandard2.0/Python.Runtime.Interfaces.dll"; + var assembly = Assembly.LoadFile(path); + var type = assembly.GetType("Python.Runtime.Interfaces.ILibPython"); + const BindingFlags flags = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance; + var methods = type.GetMethods(flags); + + foreach (var method in methods) { +#> + internal static <#= FormatType(method.ReturnParameter.ParameterType) #> <#= method.Name #>(<#= + string.Join(", ", method.GetParameters().Select(x => $"{FormatType(x.ParameterType)} {x.Name}")) + #>) => LibPython.<#= method.Name #>(<#= + string.Join(", ", method.GetParameters().Select(x => (x.ParameterType.IsByRef ? "ref " : "") + x.Name)) + #>); +<# + } +#> + } +} diff --git a/src/runtime/typemanager.cs b/Python.Runtime/typemanager.cs similarity index 96% rename from src/runtime/typemanager.cs rename to Python.Runtime/typemanager.cs index 9a98e9ebb..f424c9a86 100644 --- a/src/runtime/typemanager.cs +++ b/Python.Runtime/typemanager.cs @@ -414,24 +414,21 @@ internal static IntPtr AllocateTypeObject(string name) // Cheat a little: we'll set tp_name to the internal char * of // the Python version of the type name - otherwise we'd have to // allocate the tp_name and would have no way to free it. -#if PYTHON3 +#if !PYTHON2 // For python3 we leak two objects. One for the ASCII representation // required for tp_name, and another for the Unicode representation // for ht_name. IntPtr temp = Runtime.PyBytes_FromString(name); IntPtr raw = Runtime.PyBytes_AS_STRING(temp); temp = Runtime.PyUnicode_FromString(name); -#elif PYTHON2 + Marshal.WriteIntPtr(type, TypeOffset.qualname, temp); +#else IntPtr temp = Runtime.PyString_FromString(name); IntPtr raw = Runtime.PyString_AsString(temp); #endif Marshal.WriteIntPtr(type, TypeOffset.tp_name, raw); Marshal.WriteIntPtr(type, TypeOffset.name, temp); -#if PYTHON3 - Marshal.WriteIntPtr(type, TypeOffset.qualname, temp); -#endif - long ptr = type.ToInt64(); // 64-bit safe temp = new IntPtr(ptr + TypeOffset.nb_add); @@ -443,9 +440,9 @@ internal static IntPtr AllocateTypeObject(string name) temp = new IntPtr(ptr + TypeOffset.mp_length); Marshal.WriteIntPtr(type, TypeOffset.tp_as_mapping, temp); -#if PYTHON3 +#if !PYTHON2 temp = new IntPtr(ptr + TypeOffset.bf_getbuffer); -#elif PYTHON2 +#else temp = new IntPtr(ptr + TypeOffset.bf_getreadbuffer); #endif Marshal.WriteIntPtr(type, TypeOffset.tp_as_buffer, temp); @@ -506,11 +503,11 @@ public static NativeCode Active { get { - switch (Runtime.Machine) + switch (RuntimeInformation.ProcessArchitecture) { - case MachineType.i386: + case Architecture.X86: return I386; - case MachineType.x86_64: + case Architecture.X64: return X86_64; default: return null; @@ -603,15 +600,12 @@ int MAP_ANONYMOUS { get { - switch (Runtime.OperatingSystem) - { - case OperatingSystemType.Darwin: - return 0x1000; - case OperatingSystemType.Linux: - return 0x20; - default: - throw new NotImplementedException($"mmap is not supported on {Runtime.OperatingSystemName}"); - } + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + return 0x1000; + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + return 0x20; + else + throw new NotImplementedException($"mmap is not supported on this operating system"); } } @@ -636,16 +630,10 @@ public void SetReadExec(IntPtr mappedMemory, int numBytes) internal static IMemoryMapper CreateMemoryMapper() { - switch (Runtime.OperatingSystem) - { - case OperatingSystemType.Darwin: - case OperatingSystemType.Linux: - return new UnixMemoryMapper(); - case OperatingSystemType.Windows: - return new WindowsMemoryMapper(); - default: - throw new NotImplementedException($"No support for {Runtime.OperatingSystemName}"); - } + if (Runtime.IsWindows) + return new WindowsMemoryMapper(); + else + return new UnixMemoryMapper(); } /// diff --git a/src/runtime/typemethod.cs b/Python.Runtime/typemethod.cs similarity index 100% rename from src/runtime/typemethod.cs rename to Python.Runtime/typemethod.cs diff --git a/src/embed_tests/GlobalTestsSetup.cs b/Python.Test.Embed/GlobalTestsSetup.cs similarity index 100% rename from src/embed_tests/GlobalTestsSetup.cs rename to Python.Test.Embed/GlobalTestsSetup.cs diff --git a/src/embed_tests/Python.EmbeddingTest.csproj b/Python.Test.Embed/Python.Test.Embed similarity index 100% rename from src/embed_tests/Python.EmbeddingTest.csproj rename to Python.Test.Embed/Python.Test.Embed diff --git a/Python.Test.Embed/Python.Test.Embed.csproj b/Python.Test.Embed/Python.Test.Embed.csproj new file mode 100644 index 000000000..6ed446c5b --- /dev/null +++ b/Python.Test.Embed/Python.Test.Embed.csproj @@ -0,0 +1,25 @@ + + + + netcoreapp3.0;net472 + true + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + diff --git a/src/embed_tests/TestCallbacks.cs b/Python.Test.Embed/TestCallbacks.cs similarity index 86% rename from src/embed_tests/TestCallbacks.cs rename to Python.Test.Embed/TestCallbacks.cs index 220b0a86a..3d1946c78 100644 --- a/src/embed_tests/TestCallbacks.cs +++ b/Python.Test.Embed/TestCallbacks.cs @@ -25,9 +25,12 @@ public void TestNoOverloadException() { dynamic callWith42 = PythonEngine.Eval("lambda f: f([42])"); var error = Assert.Throws(() => callWith42(aFunctionThatCallsIntoPython.ToPython())); Assert.AreEqual("TypeError", error.PythonTypeName); - string expectedArgTypes = Runtime.IsPython2 - ? "()" - : "()"; + string expectedArgTypes = +#if PYTHON2 + "()"; +#else + "()"; +#endif StringAssert.EndsWith(expectedArgTypes, error.Message); } } diff --git a/src/embed_tests/TestConverter.cs b/Python.Test.Embed/TestConverter.cs similarity index 100% rename from src/embed_tests/TestConverter.cs rename to Python.Test.Embed/TestConverter.cs diff --git a/src/embed_tests/TestCustomMarshal.cs b/Python.Test.Embed/TestCustomMarshal.cs similarity index 100% rename from src/embed_tests/TestCustomMarshal.cs rename to Python.Test.Embed/TestCustomMarshal.cs diff --git a/src/embed_tests/TestDomainReload.cs b/Python.Test.Embed/TestDomainReload.cs similarity index 99% rename from src/embed_tests/TestDomainReload.cs rename to Python.Test.Embed/TestDomainReload.cs index b162d4eb0..e925d761b 100644 --- a/src/embed_tests/TestDomainReload.cs +++ b/Python.Test.Embed/TestDomainReload.cs @@ -11,7 +11,7 @@ // // Unfortunately this means no continuous integration testing for this case. // -#if !NETSTANDARD && !NETCOREAPP +#if NETFX namespace Python.EmbeddingTest { class TestDomainReload diff --git a/src/embed_tests/TestExample.cs b/Python.Test.Embed/TestExample.cs similarity index 100% rename from src/embed_tests/TestExample.cs rename to Python.Test.Embed/TestExample.cs diff --git a/src/embed_tests/TestFinalizer.cs b/Python.Test.Embed/TestFinalizer.cs similarity index 100% rename from src/embed_tests/TestFinalizer.cs rename to Python.Test.Embed/TestFinalizer.cs diff --git a/src/embed_tests/TestNamedArguments.cs b/Python.Test.Embed/TestNamedArguments.cs similarity index 100% rename from src/embed_tests/TestNamedArguments.cs rename to Python.Test.Embed/TestNamedArguments.cs diff --git a/src/embed_tests/TestPyAnsiString.cs b/Python.Test.Embed/TestPyAnsiString.cs similarity index 100% rename from src/embed_tests/TestPyAnsiString.cs rename to Python.Test.Embed/TestPyAnsiString.cs diff --git a/src/embed_tests/TestPyFloat.cs b/Python.Test.Embed/TestPyFloat.cs similarity index 100% rename from src/embed_tests/TestPyFloat.cs rename to Python.Test.Embed/TestPyFloat.cs diff --git a/src/embed_tests/TestPyInt.cs b/Python.Test.Embed/TestPyInt.cs similarity index 100% rename from src/embed_tests/TestPyInt.cs rename to Python.Test.Embed/TestPyInt.cs diff --git a/src/embed_tests/TestPyList.cs b/Python.Test.Embed/TestPyList.cs similarity index 100% rename from src/embed_tests/TestPyList.cs rename to Python.Test.Embed/TestPyList.cs diff --git a/src/embed_tests/TestPyLong.cs b/Python.Test.Embed/TestPyLong.cs similarity index 100% rename from src/embed_tests/TestPyLong.cs rename to Python.Test.Embed/TestPyLong.cs diff --git a/src/embed_tests/TestPyNumber.cs b/Python.Test.Embed/TestPyNumber.cs similarity index 100% rename from src/embed_tests/TestPyNumber.cs rename to Python.Test.Embed/TestPyNumber.cs diff --git a/src/embed_tests/TestPyObject.cs b/Python.Test.Embed/TestPyObject.cs similarity index 100% rename from src/embed_tests/TestPyObject.cs rename to Python.Test.Embed/TestPyObject.cs diff --git a/src/embed_tests/TestPyScope.cs b/Python.Test.Embed/TestPyScope.cs similarity index 100% rename from src/embed_tests/TestPyScope.cs rename to Python.Test.Embed/TestPyScope.cs diff --git a/src/embed_tests/TestPySequence.cs b/Python.Test.Embed/TestPySequence.cs similarity index 100% rename from src/embed_tests/TestPySequence.cs rename to Python.Test.Embed/TestPySequence.cs diff --git a/src/embed_tests/TestPyString.cs b/Python.Test.Embed/TestPyString.cs similarity index 100% rename from src/embed_tests/TestPyString.cs rename to Python.Test.Embed/TestPyString.cs diff --git a/src/embed_tests/TestPyTuple.cs b/Python.Test.Embed/TestPyTuple.cs similarity index 100% rename from src/embed_tests/TestPyTuple.cs rename to Python.Test.Embed/TestPyTuple.cs diff --git a/src/embed_tests/TestPyWith.cs b/Python.Test.Embed/TestPyWith.cs similarity index 100% rename from src/embed_tests/TestPyWith.cs rename to Python.Test.Embed/TestPyWith.cs diff --git a/src/embed_tests/TestPythonEngineProperties.cs b/Python.Test.Embed/TestPythonEngineProperties.cs similarity index 100% rename from src/embed_tests/TestPythonEngineProperties.cs rename to Python.Test.Embed/TestPythonEngineProperties.cs diff --git a/src/embed_tests/TestPythonException.cs b/Python.Test.Embed/TestPythonException.cs similarity index 100% rename from src/embed_tests/TestPythonException.cs rename to Python.Test.Embed/TestPythonException.cs diff --git a/src/embed_tests/TestRuntime.cs b/Python.Test.Embed/TestRuntime.cs similarity index 100% rename from src/embed_tests/TestRuntime.cs rename to Python.Test.Embed/TestRuntime.cs diff --git a/src/embed_tests/TestTypeManager.cs b/Python.Test.Embed/TestTypeManager.cs similarity index 100% rename from src/embed_tests/TestTypeManager.cs rename to Python.Test.Embed/TestTypeManager.cs diff --git a/src/embed_tests/dynamic.cs b/Python.Test.Embed/dynamic.cs similarity index 100% rename from src/embed_tests/dynamic.cs rename to Python.Test.Embed/dynamic.cs diff --git a/src/embed_tests/fixtures/PyImportTest/__init__.py b/Python.Test.Embed/fixtures/PyImportTest/__init__.py similarity index 100% rename from src/embed_tests/fixtures/PyImportTest/__init__.py rename to Python.Test.Embed/fixtures/PyImportTest/__init__.py diff --git a/src/embed_tests/fixtures/PyImportTest/cast_global_var.py b/Python.Test.Embed/fixtures/PyImportTest/cast_global_var.py similarity index 100% rename from src/embed_tests/fixtures/PyImportTest/cast_global_var.py rename to Python.Test.Embed/fixtures/PyImportTest/cast_global_var.py diff --git a/src/embed_tests/fixtures/PyImportTest/sysargv.py b/Python.Test.Embed/fixtures/PyImportTest/sysargv.py similarity index 100% rename from src/embed_tests/fixtures/PyImportTest/sysargv.py rename to Python.Test.Embed/fixtures/PyImportTest/sysargv.py diff --git a/src/embed_tests/fixtures/PyImportTest/test/__init__.py b/Python.Test.Embed/fixtures/PyImportTest/test/__init__.py similarity index 100% rename from src/embed_tests/fixtures/PyImportTest/test/__init__.py rename to Python.Test.Embed/fixtures/PyImportTest/test/__init__.py diff --git a/src/embed_tests/fixtures/PyImportTest/test/one.py b/Python.Test.Embed/fixtures/PyImportTest/test/one.py similarity index 100% rename from src/embed_tests/fixtures/PyImportTest/test/one.py rename to Python.Test.Embed/fixtures/PyImportTest/test/one.py diff --git a/src/embed_tests/packages.config b/Python.Test.Embed/packages.config similarity index 100% rename from src/embed_tests/packages.config rename to Python.Test.Embed/packages.config diff --git a/src/embed_tests/pyimport.cs b/Python.Test.Embed/pyimport.cs similarity index 100% rename from src/embed_tests/pyimport.cs rename to Python.Test.Embed/pyimport.cs diff --git a/src/embed_tests/pyinitialize.cs b/Python.Test.Embed/pyinitialize.cs similarity index 100% rename from src/embed_tests/pyinitialize.cs rename to Python.Test.Embed/pyinitialize.cs diff --git a/src/embed_tests/pyrunstring.cs b/Python.Test.Embed/pyrunstring.cs similarity index 100% rename from src/embed_tests/pyrunstring.cs rename to Python.Test.Embed/pyrunstring.cs diff --git a/src/testing/InheritanceTest.cs b/Python.Test.Helper/InheritanceTest.cs similarity index 100% rename from src/testing/InheritanceTest.cs rename to Python.Test.Helper/InheritanceTest.cs diff --git a/Python.Test.Helper/Python.Test.Helper.csproj b/Python.Test.Helper/Python.Test.Helper.csproj new file mode 100644 index 000000000..32a5e7129 --- /dev/null +++ b/Python.Test.Helper/Python.Test.Helper.csproj @@ -0,0 +1,15 @@ + + + + + + + + + + + + netstandard2.0 + + + diff --git a/src/testing/ReprTest.cs b/Python.Test.Helper/ReprTest.cs similarity index 100% rename from src/testing/ReprTest.cs rename to Python.Test.Helper/ReprTest.cs diff --git a/src/testing/arraytest.cs b/Python.Test.Helper/arraytest.cs similarity index 100% rename from src/testing/arraytest.cs rename to Python.Test.Helper/arraytest.cs diff --git a/src/testing/callbacktest.cs b/Python.Test.Helper/callbacktest.cs similarity index 100% rename from src/testing/callbacktest.cs rename to Python.Test.Helper/callbacktest.cs diff --git a/src/testing/classtest.cs b/Python.Test.Helper/classtest.cs similarity index 100% rename from src/testing/classtest.cs rename to Python.Test.Helper/classtest.cs diff --git a/src/testing/constructortests.cs b/Python.Test.Helper/constructortests.cs similarity index 100% rename from src/testing/constructortests.cs rename to Python.Test.Helper/constructortests.cs diff --git a/src/testing/conversiontest.cs b/Python.Test.Helper/conversiontest.cs similarity index 100% rename from src/testing/conversiontest.cs rename to Python.Test.Helper/conversiontest.cs diff --git a/src/testing/delegatetest.cs b/Python.Test.Helper/delegatetest.cs similarity index 100% rename from src/testing/delegatetest.cs rename to Python.Test.Helper/delegatetest.cs diff --git a/src/testing/doctest.cs b/Python.Test.Helper/doctest.cs similarity index 100% rename from src/testing/doctest.cs rename to Python.Test.Helper/doctest.cs diff --git a/src/testing/enumtest.cs b/Python.Test.Helper/enumtest.cs similarity index 100% rename from src/testing/enumtest.cs rename to Python.Test.Helper/enumtest.cs diff --git a/src/testing/eventtest.cs b/Python.Test.Helper/eventtest.cs similarity index 100% rename from src/testing/eventtest.cs rename to Python.Test.Helper/eventtest.cs diff --git a/src/testing/exceptiontest.cs b/Python.Test.Helper/exceptiontest.cs similarity index 100% rename from src/testing/exceptiontest.cs rename to Python.Test.Helper/exceptiontest.cs diff --git a/src/testing/fieldtest.cs b/Python.Test.Helper/fieldtest.cs similarity index 100% rename from src/testing/fieldtest.cs rename to Python.Test.Helper/fieldtest.cs diff --git a/src/testing/generictest.cs b/Python.Test.Helper/generictest.cs similarity index 100% rename from src/testing/generictest.cs rename to Python.Test.Helper/generictest.cs diff --git a/src/testing/globaltest.cs b/Python.Test.Helper/globaltest.cs similarity index 100% rename from src/testing/globaltest.cs rename to Python.Test.Helper/globaltest.cs diff --git a/src/testing/indexertest.cs b/Python.Test.Helper/indexertest.cs similarity index 100% rename from src/testing/indexertest.cs rename to Python.Test.Helper/indexertest.cs diff --git a/src/testing/interfacetest.cs b/Python.Test.Helper/interfacetest.cs similarity index 100% rename from src/testing/interfacetest.cs rename to Python.Test.Helper/interfacetest.cs diff --git a/src/testing/methodtest.cs b/Python.Test.Helper/methodtest.cs similarity index 100% rename from src/testing/methodtest.cs rename to Python.Test.Helper/methodtest.cs diff --git a/src/testing/moduletest.cs b/Python.Test.Helper/moduletest.cs similarity index 100% rename from src/testing/moduletest.cs rename to Python.Test.Helper/moduletest.cs diff --git a/src/testing/propertytest.cs b/Python.Test.Helper/propertytest.cs similarity index 100% rename from src/testing/propertytest.cs rename to Python.Test.Helper/propertytest.cs diff --git a/src/testing/subclasstest.cs b/Python.Test.Helper/subclasstest.cs similarity index 100% rename from src/testing/subclasstest.cs rename to Python.Test.Helper/subclasstest.cs diff --git a/src/testing/threadtest.cs b/Python.Test.Helper/threadtest.cs similarity index 100% rename from src/testing/threadtest.cs rename to Python.Test.Helper/threadtest.cs diff --git a/src/perf_tests/BaselineComparisonBenchmarkBase.cs b/Python.Test.Performance/BaselineComparisonBenchmarkBase.cs similarity index 100% rename from src/perf_tests/BaselineComparisonBenchmarkBase.cs rename to Python.Test.Performance/BaselineComparisonBenchmarkBase.cs diff --git a/src/perf_tests/BaselineComparisonConfig.cs b/Python.Test.Performance/BaselineComparisonConfig.cs similarity index 100% rename from src/perf_tests/BaselineComparisonConfig.cs rename to Python.Test.Performance/BaselineComparisonConfig.cs diff --git a/src/perf_tests/BenchmarkTests.cs b/Python.Test.Performance/BenchmarkTests.cs similarity index 100% rename from src/perf_tests/BenchmarkTests.cs rename to Python.Test.Performance/BenchmarkTests.cs diff --git a/src/perf_tests/Python.PerformanceTests.csproj b/Python.Test.Performance/Python.Test.Performance.csproj similarity index 56% rename from src/perf_tests/Python.PerformanceTests.csproj rename to Python.Test.Performance/Python.Test.Performance.csproj index 33949fdc1..2c857c938 100644 --- a/src/perf_tests/Python.PerformanceTests.csproj +++ b/Python.Test.Performance/Python.Test.Performance.csproj @@ -1,24 +1,21 @@ - + - net461 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 - + net472 false - - - + + compile - + diff --git a/src/perf_tests/PythonCallingNetBenchmark.cs b/Python.Test.Performance/PythonCallingNetBenchmark.cs similarity index 100% rename from src/perf_tests/PythonCallingNetBenchmark.cs rename to Python.Test.Performance/PythonCallingNetBenchmark.cs diff --git a/pythonnet.15.sln b/pythonnet.15.sln deleted file mode 100644 index 096dfbe9a..000000000 --- a/pythonnet.15.sln +++ /dev/null @@ -1,371 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29102.190 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime.15", "src\runtime\Python.Runtime.15.csproj", "{2759F4FF-716B-4828-916F-50FA86613DFC}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest.15", "src\embed_tests\Python.EmbeddingTest.15.csproj", "{66B8D01A-9906-452A-B09E-BF75EA76468F}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule.15", "src\clrmodule\clrmodule.15.csproj", "{E08678D4-9A52-4AD5-B63D-8EBC7399981B}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.15", "src\console\Console.15.csproj", "{CDAD305F-8E72-492C-A314-64CF58D472A0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test.15", "src\testing\Python.Test.15.csproj", "{F94B547A-E97E-4500-8D53-B4D64D076E5F}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.PerformanceTests", "src\perf_tests\Python.PerformanceTests.csproj", "{6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Repo", "Repo", "{441A0123-F4C6-4EE4-9AEE-315FD79BE2D5}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - DebugMono|Any CPU = DebugMono|Any CPU - DebugMono|x64 = DebugMono|x64 - DebugMono|x86 = DebugMono|x86 - DebugMonoPY3|Any CPU = DebugMonoPY3|Any CPU - DebugMonoPY3|x64 = DebugMonoPY3|x64 - DebugMonoPY3|x86 = DebugMonoPY3|x86 - DebugWin|Any CPU = DebugWin|Any CPU - DebugWin|x64 = DebugWin|x64 - DebugWin|x86 = DebugWin|x86 - DebugWinPY3|Any CPU = DebugWinPY3|Any CPU - DebugWinPY3|x64 = DebugWinPY3|x64 - DebugWinPY3|x86 = DebugWinPY3|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 - ReleaseMono|Any CPU = ReleaseMono|Any CPU - ReleaseMono|x64 = ReleaseMono|x64 - ReleaseMono|x86 = ReleaseMono|x86 - ReleaseMonoPY3|Any CPU = ReleaseMonoPY3|Any CPU - ReleaseMonoPY3|x64 = ReleaseMonoPY3|x64 - ReleaseMonoPY3|x86 = ReleaseMonoPY3|x86 - ReleaseWin|Any CPU = ReleaseWin|Any CPU - ReleaseWin|x64 = ReleaseWin|x64 - ReleaseWin|x86 = ReleaseWin|x86 - ReleaseWinPY3|Any CPU = ReleaseWinPY3|Any CPU - ReleaseWinPY3|x64 = ReleaseWinPY3|x64 - ReleaseWinPY3|x86 = ReleaseWinPY3|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|Any CPU.ActiveCfg = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|Any CPU.Build.0 = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x64.ActiveCfg = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x64.Build.0 = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x86.ActiveCfg = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Debug|x86.Build.0 = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|Any CPU.ActiveCfg = DebugMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|Any CPU.Build.0 = DebugMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|x64.ActiveCfg = DebugMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|x64.Build.0 = DebugMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|x86.ActiveCfg = DebugMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMono|x86.Build.0 = DebugMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|Any CPU.Build.0 = DebugMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|Any CPU.ActiveCfg = DebugWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|Any CPU.Build.0 = DebugWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|x64.ActiveCfg = DebugWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|x64.Build.0 = DebugWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|x86.ActiveCfg = DebugWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWin|x86.Build.0 = DebugWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|Any CPU.Build.0 = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|x64.Build.0 = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.DebugWinPY3|x86.Build.0 = DebugWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|Any CPU.Build.0 = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x64.ActiveCfg = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x64.Build.0 = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x86.ActiveCfg = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.Release|x86.Build.0 = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|Any CPU.Build.0 = ReleaseMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|x64.ActiveCfg = ReleaseMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|x64.Build.0 = ReleaseMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|x86.ActiveCfg = ReleaseMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMono|x86.Build.0 = ReleaseMono|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|Any CPU.Build.0 = ReleaseMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|Any CPU.Build.0 = ReleaseWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|x64.ActiveCfg = ReleaseWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|x64.Build.0 = ReleaseWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|x86.ActiveCfg = ReleaseWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWin|x86.Build.0 = ReleaseWin|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|Any CPU.Build.0 = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|Any CPU - {2759F4FF-716B-4828-916F-50FA86613DFC}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|Any CPU - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|Any CPU.Build.0 = ReleaseWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x64.ActiveCfg = DebugWinPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x64.Build.0 = DebugWinPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x86.ActiveCfg = DebugWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Debug|x86.Build.0 = DebugWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|x64.Build.0 = DebugMono|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMono|x86.Build.0 = DebugMono|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|x64.Build.0 = DebugWin|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWin|x86.Build.0 = DebugWin|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|Any CPU.Build.0 = ReleaseWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x64.ActiveCfg = ReleaseWinPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x64.Build.0 = ReleaseWinPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x86.ActiveCfg = ReleaseWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.Release|x86.Build.0 = ReleaseWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|x64.Build.0 = ReleaseMono|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMono|x86.Build.0 = ReleaseMono|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {66B8D01A-9906-452A-B09E-BF75EA76468F}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|Any CPU.Build.0 = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x64.ActiveCfg = DebugWinPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x64.Build.0 = DebugWinPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x86.ActiveCfg = DebugWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Debug|x86.Build.0 = DebugWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|x64.Build.0 = DebugWin|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWin|x86.Build.0 = DebugWin|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|Any CPU.Build.0 = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x64.ActiveCfg = ReleaseWinPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x64.Build.0 = ReleaseWinPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x86.ActiveCfg = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.Release|x86.Build.0 = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {E08678D4-9A52-4AD5-B63D-8EBC7399981B}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|Any CPU.Build.0 = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x64.ActiveCfg = DebugWinPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x64.Build.0 = DebugWinPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x86.ActiveCfg = DebugWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Debug|x86.Build.0 = DebugWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|x64.Build.0 = DebugMono|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMono|x86.Build.0 = DebugMono|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|x64.Build.0 = DebugWin|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWin|x86.Build.0 = DebugWin|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|Any CPU.Build.0 = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x64.ActiveCfg = ReleaseWinPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x64.Build.0 = ReleaseWinPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x86.ActiveCfg = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.Release|x86.Build.0 = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|x64.Build.0 = ReleaseMono|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMono|x86.Build.0 = ReleaseMono|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {CDAD305F-8E72-492C-A314-64CF58D472A0}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|Any CPU.Build.0 = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x64.ActiveCfg = DebugWinPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x64.Build.0 = DebugWinPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x86.ActiveCfg = DebugWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Debug|x86.Build.0 = DebugWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|Any CPU.ActiveCfg = DebugMono|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|x64.Build.0 = DebugMono|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMono|x86.Build.0 = DebugMono|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|Any CPU.ActiveCfg = DebugWin|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|x64.Build.0 = DebugWin|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWin|x86.Build.0 = DebugWin|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|Any CPU.Build.0 = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x64.ActiveCfg = ReleaseWinPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x64.Build.0 = ReleaseWinPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x86.ActiveCfg = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.Release|x86.Build.0 = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|x64.Build.0 = ReleaseMono|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMono|x86.Build.0 = ReleaseMono|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {F94B547A-E97E-4500-8D53-B4D64D076E5F}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|Any CPU.ActiveCfg = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|Any CPU.Build.0 = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|x64.ActiveCfg = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|x64.Build.0 = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|x86.ActiveCfg = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Debug|x86.Build.0 = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMono|Any CPU.ActiveCfg = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMono|x64.ActiveCfg = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMono|x86.ActiveCfg = DebugMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMonoPY3|Any CPU.ActiveCfg = DebugMonoPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|Any CPU.ActiveCfg = DebugWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|Any CPU.Build.0 = DebugWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|x64.ActiveCfg = DebugWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|x64.Build.0 = DebugWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|x86.ActiveCfg = DebugWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWin|x86.Build.0 = DebugWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|Any CPU.ActiveCfg = DebugWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|Any CPU.Build.0 = DebugWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|x64.Build.0 = DebugWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.DebugWinPY3|x86.Build.0 = DebugWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|Any CPU.ActiveCfg = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|Any CPU.Build.0 = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|x64.ActiveCfg = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|x64.Build.0 = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|x86.ActiveCfg = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.Release|x86.Build.0 = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMono|Any CPU.ActiveCfg = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMono|x64.ActiveCfg = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMono|x86.ActiveCfg = ReleaseMono|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMonoPY3|Any CPU.ActiveCfg = ReleaseMonoPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|Any CPU.ActiveCfg = ReleaseWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|Any CPU.Build.0 = ReleaseWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|x64.ActiveCfg = ReleaseWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|x64.Build.0 = ReleaseWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|x86.ActiveCfg = ReleaseWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWin|x86.Build.0 = ReleaseWin|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|Any CPU.ActiveCfg = ReleaseWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|Any CPU.Build.0 = ReleaseWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|Any CPU - {6FB0D091-9CEC-4DCC-8701-C40F9BFC9EDE}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {A6347B90-BBE6-4E45-90BF-1BD8B76069E3} - EndGlobalSection -EndGlobal diff --git a/pythonnet.sln b/pythonnet.sln index c5afd66c3..602bb4dd7 100644 --- a/pythonnet.sln +++ b/pythonnet.sln @@ -1,202 +1,76 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Runtime", "src\runtime\Python.Runtime.csproj", "{097B4AC0-74E9-4C58-BCF8-C69746EC8271}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Test", "src\testing\Python.Test.csproj", "{6F401A34-273B-450F-9A4C-13550BE0767B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.EmbeddingTest", "src\embed_tests\Python.EmbeddingTest.csproj", "{4165C59D-2822-499F-A6DB-EACA4C331EB5}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "src\console\Console.csproj", "{E29DCF0A-5114-4A98-B1DD-71264B6EA349}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "clrmodule", "src\clrmodule\clrmodule.csproj", "{86E834DE-1139-4511-96CC-69636A56E7AC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - DebugMono|x64 = DebugMono|x64 - DebugMono|x86 = DebugMono|x86 - DebugMonoPY3|x64 = DebugMonoPY3|x64 - DebugMonoPY3|x86 = DebugMonoPY3|x86 - DebugWin|x64 = DebugWin|x64 - DebugWin|x86 = DebugWin|x86 - DebugWinPY3|x64 = DebugWinPY3|x64 - DebugWinPY3|x86 = DebugWinPY3|x86 - ReleaseMono|x64 = ReleaseMono|x64 - ReleaseMono|x86 = ReleaseMono|x86 - ReleaseMonoPY3|x64 = ReleaseMonoPY3|x64 - ReleaseMonoPY3|x86 = ReleaseMonoPY3|x86 - ReleaseWin|x64 = ReleaseWin|x64 - ReleaseWin|x86 = ReleaseWin|x86 - ReleaseWinPY3|x64 = ReleaseWinPY3|x64 - ReleaseWinPY3|x86 = ReleaseWinPY3|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMono|x64.Build.0 = DebugMono|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMono|x86.Build.0 = DebugMono|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWin|x64.Build.0 = DebugWin|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWin|x86.Build.0 = DebugWin|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMono|x64.Build.0 = ReleaseMono|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMono|x86.Build.0 = ReleaseMono|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {097B4AC0-74E9-4C58-BCF8-C69746EC8271}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMono|x64.Build.0 = DebugMono|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMono|x86.Build.0 = DebugMono|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWin|x64.Build.0 = DebugWin|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWin|x86.Build.0 = DebugWin|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMono|x64.Build.0 = ReleaseMono|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMono|x86.Build.0 = ReleaseMono|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {6F401A34-273B-450F-9A4C-13550BE0767B}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMono|x64.Build.0 = DebugMono|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMono|x86.Build.0 = DebugMono|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWin|x64.Build.0 = DebugWin|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWin|x86.Build.0 = DebugWin|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMono|x64.Build.0 = ReleaseMono|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMono|x86.Build.0 = ReleaseMono|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {4165C59D-2822-499F-A6DB-EACA4C331EB5}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMono|x64.Build.0 = DebugMono|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMono|x86.Build.0 = DebugMono|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMonoPY3|x64.Build.0 = DebugMonoPY3|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugMonoPY3|x86.Build.0 = DebugMonoPY3|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWin|x64.Build.0 = DebugWin|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWin|x86.Build.0 = DebugWin|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMono|x64.Build.0 = ReleaseMono|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMono|x86.Build.0 = ReleaseMono|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMonoPY3|x64.Build.0 = ReleaseMonoPY3|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseMonoPY3|x86.Build.0 = ReleaseMonoPY3|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {E29DCF0A-5114-4A98-B1DD-71264B6EA349}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMono|x64.ActiveCfg = DebugMono|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMono|x86.ActiveCfg = DebugMono|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMonoPY3|x64.ActiveCfg = DebugMonoPY3|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugMonoPY3|x86.ActiveCfg = DebugMonoPY3|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x64.ActiveCfg = DebugWin|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x64.Build.0 = DebugWin|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x86.ActiveCfg = DebugWin|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWin|x86.Build.0 = DebugWin|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWinPY3|x64.ActiveCfg = DebugWinPY3|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWinPY3|x64.Build.0 = DebugWinPY3|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWinPY3|x86.ActiveCfg = DebugWinPY3|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.DebugWinPY3|x86.Build.0 = DebugWinPY3|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMono|x64.ActiveCfg = ReleaseMono|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMono|x86.ActiveCfg = ReleaseMono|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMonoPY3|x64.ActiveCfg = ReleaseMonoPY3|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseMonoPY3|x86.ActiveCfg = ReleaseMonoPY3|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x64.ActiveCfg = ReleaseWin|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x64.Build.0 = ReleaseWin|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x86.ActiveCfg = ReleaseWin|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWin|x86.Build.0 = ReleaseWin|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWinPY3|x64.ActiveCfg = ReleaseWinPY3|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWinPY3|x64.Build.0 = ReleaseWinPY3|x64 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWinPY3|x86.ActiveCfg = ReleaseWinPY3|x86 - {86E834DE-1139-4511-96CC-69636A56E7AC}.ReleaseWinPY3|x86.Build.0 = ReleaseWinPY3|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = src\console\Console.csproj - Policies = $0 - $0.VersionControlPolicy = $1 - $1.inheritsSet = Mono - $0.ChangeLogPolicy = $2 - $2.UpdateMode = None - $2.MessageStyle = $3 - $3.LineAlign = 0 - $2.inheritsSet = Mono - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Runtime", "Python.Runtime\Python.Runtime.csproj", "{C9E02762-3DD2-4669-81DA-6A64C80D07E0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Test.Embed", "Python.Test.Embed\Python.Test.Embed.csproj", "{298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Test.Helper", "Python.Test.Helper\Python.Test.Helper.csproj", "{23C09493-58CD-4B50-A24E-64B56A967DCC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Python.Test.Performance", "Python.Test.Performance\Python.Test.Performance.csproj", "{A232F9F5-3A03-431F-8863-0BA177D650BA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Debug|x64.ActiveCfg = Debug|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Debug|x64.Build.0 = Debug|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Debug|x86.ActiveCfg = Debug|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Debug|x86.Build.0 = Debug|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Release|Any CPU.Build.0 = Release|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Release|x64.ActiveCfg = Release|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Release|x64.Build.0 = Release|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Release|x86.ActiveCfg = Release|Any CPU + {C9E02762-3DD2-4669-81DA-6A64C80D07E0}.Release|x86.Build.0 = Release|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Debug|x64.ActiveCfg = Debug|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Debug|x64.Build.0 = Debug|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Debug|x86.ActiveCfg = Debug|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Debug|x86.Build.0 = Debug|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Release|Any CPU.Build.0 = Release|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Release|x64.ActiveCfg = Release|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Release|x64.Build.0 = Release|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Release|x86.ActiveCfg = Release|Any CPU + {298D6A0A-C41B-4B6D-ABF6-1E24A1BF223C}.Release|x86.Build.0 = Release|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Debug|x64.ActiveCfg = Debug|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Debug|x64.Build.0 = Debug|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Debug|x86.ActiveCfg = Debug|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Debug|x86.Build.0 = Debug|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Release|Any CPU.Build.0 = Release|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Release|x64.ActiveCfg = Release|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Release|x64.Build.0 = Release|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Release|x86.ActiveCfg = Release|Any CPU + {23C09493-58CD-4B50-A24E-64B56A967DCC}.Release|x86.Build.0 = Release|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Debug|x64.ActiveCfg = Debug|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Debug|x64.Build.0 = Debug|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Debug|x86.ActiveCfg = Debug|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Debug|x86.Build.0 = Debug|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Release|Any CPU.Build.0 = Release|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Release|x64.ActiveCfg = Release|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Release|x64.Build.0 = Release|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Release|x86.ActiveCfg = Release|Any CPU + {A232F9F5-3A03-431F-8863-0BA177D650BA}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/pythonnet/__init__.py b/pythonnet/__init__.py new file mode 100644 index 000000000..97e60239d --- /dev/null +++ b/pythonnet/__init__.py @@ -0,0 +1,18 @@ +import os + +_RUNTIME = None + + +def set_runtime(runtime): + global _RUNTIME + _RUNTIME = runtime + + +def load(): + dll_path = os.path.join(os.path.dirname(__file__), "dlls", "Python.Runtime.dll") + + assembly = _RUNTIME.get_assembly(dll_path) + func = assembly["Python.Runtime.PythonEngine.InternalInitialize"] + + if func(b"") != 0: + raise RuntimeError("Failed to initialize Python.Runtime.dll") diff --git a/setup.cfg b/setup.cfg index 38aa3eb3d..0c9e0fc14 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,2 @@ -# [bumpversion] comments. bumpversion deleted all comments on its file. -# Don't combine `.bumpversion.cfg` with `setup.cfg`. Messes up formatting. -# Don't use `first_value = 1`. It will break `release` bump -# Keep `optional = dummy` needed to bump to release. -# See: https://github.com/peritus/bumpversion/issues/59 - -[tool:pytest] -xfail_strict = True -# -r fsxX: show extra summary info for: (f)ailed, (s)kip, (x)failed, (X)passed -addopts = -r fsxX --color=yes --durations=5 +[metadata] +license_file = LICENSE diff --git a/setup.py b/setup.py index c6e4007e6..5abe9ab0a 100644 --- a/setup.py +++ b/setup.py @@ -1,652 +1,68 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -""" -Setup script for building clr.pyd and dependencies using mono and into -an egg or wheel. -""" +from setuptools import setup, find_packages, Command, Extension +from wheel.bdist_wheel import bdist_wheel -import collections -import fnmatch -import glob -import os -import subprocess -import sys -import sysconfig -from distutils import spawn -from distutils.command import install, build, build_ext, install_data, install_lib -from setuptools import Extension, setup +class DotnetLib(Extension): + def __init__(self, name, path, **kwargs): + self.path = path + self.args = kwargs + super().__init__(name, sources=[]) -try: - from wheel import bdist_wheel -except ImportError: - bdist_wheel = None -# Allow config/verbosity to be set from cli -# http://stackoverflow.com/a/4792601/5208670 -CONFIG = "Release" # Release or Debug -VERBOSITY = "normal" # quiet, minimal, normal, detailed, diagnostic +class BuildDotnet(Command): + """Build command for dotnet-cli based builds""" -is_64bits = sys.maxsize > 2 ** 32 -DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono" -ARCH = "x64" if is_64bits else "x86" -PY_MAJOR = sys.version_info[0] -PY_MINOR = sys.version_info[1] - -############################################################################### -# Windows Keys Constants for MSBUILD tools -RegKey = collections.namedtuple("RegKey", "sdk_name key value_name suffix") -vs_python = "Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK" -vs_root = "SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\{0}" -sdks_root = "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v{0}Win32Tools" -kits_root = "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots" -kits_suffix = os.path.join("bin", ARCH) - -WIN_SDK_KEYS = [ - RegKey( - sdk_name="Windows Kit 10.0", - key=kits_root, - value_name="KitsRoot10", - suffix=os.path.join("bin", "10.0.16299.0", ARCH), - ), - RegKey( - sdk_name="Windows Kit 10.0", - key=kits_root, - value_name="KitsRoot10", - suffix=os.path.join("bin", "10.0.15063.0", ARCH), - ), - RegKey( - sdk_name="Windows Kit 10.0", - key=kits_root, - value_name="KitsRoot10", - suffix=kits_suffix, - ), - RegKey( - sdk_name="Windows Kit 8.1", - key=kits_root, - value_name="KitsRoot81", - suffix=kits_suffix, - ), - RegKey( - sdk_name="Windows Kit 8.0", - key=kits_root, - value_name="KitsRoot", - suffix=kits_suffix, - ), - RegKey( - sdk_name="Windows SDK 7.1A", - key=sdks_root.format("7.1A\\WinSDK-"), - value_name="InstallationFolder", - suffix="", - ), - RegKey( - sdk_name="Windows SDK 7.1", - key=sdks_root.format("7.1\\WinSDK"), - value_name="InstallationFolder", - suffix="", - ), - RegKey( - sdk_name="Windows SDK 7.0A", - key=sdks_root.format("7.0A\\WinSDK-"), - value_name="InstallationFolder", - suffix="", - ), - RegKey( - sdk_name="Windows SDK 7.0", - key=sdks_root.format("7.0\\WinSDK"), - value_name="InstallationFolder", - suffix="", - ), - RegKey( - sdk_name="Windows SDK 6.0A", - key=sdks_root.format("6.0A\\WinSDK"), - value_name="InstallationFolder", - suffix="", - ), -] - -VS_KEYS = ( - RegKey( - sdk_name="MSBuild 15", - key=vs_root.format("15.0"), - value_name="MSBuildToolsPath", - suffix="", - ), - RegKey( - sdk_name="MSBuild 14", - key=vs_root.format("14.0"), - value_name="MSBuildToolsPath", - suffix="", - ), - RegKey( - sdk_name="MSBuild 12", - key=vs_root.format("12.0"), - value_name="MSBuildToolsPath", - suffix="", - ), - RegKey( - sdk_name="MSBuild 4", - key=vs_root.format("4.0"), - value_name="MSBuildToolsPath", - suffix="", - ), - RegKey( - sdk_name="MSBuild 3.5", - key=vs_root.format("3.5"), - value_name="MSBuildToolsPath", - suffix="", - ), - RegKey( - sdk_name="MSBuild 2.0", - key=vs_root.format("2.0"), - value_name="MSBuildToolsPath", - suffix="", - ), -) - - -############################################################################### -def _check_output(*args, **kwargs): - """Check output wrapper for py2/py3 compatibility""" - output = subprocess.check_output(*args, **kwargs) - if PY_MAJOR == 2: - return output - return output.decode("ascii") - - -def _get_interop_filename(): - """interopXX.cs is auto-generated as part of the build. - For common windows platforms pre-generated files are included - as most windows users won't have Clang installed, which is - required to generate the file. - """ - interop_filename = "interop{0}{1}{2}.cs".format( - PY_MAJOR, PY_MINOR, getattr(sys, "abiflags", "") - ) - return os.path.join("src", "runtime", interop_filename) - - -def _get_source_files(): - """Walk project and collect the files needed for ext_module""" - for ext in (".sln",): - for path in glob.glob("*" + ext): - yield path - - for root, dirnames, filenames in os.walk("src"): - for ext in (".cs", ".csproj", ".snk", ".config", ".py", ".c", ".h", ".ico"): - for filename in fnmatch.filter(filenames, "*" + ext): - yield os.path.join(root, filename) - - for root, dirnames, filenames in os.walk("tools"): - for ext in (".exe", ".py", ".c", ".h"): - for filename in fnmatch.filter(filenames, "*" + ext): - yield os.path.join(root, filename) - - -def _get_long_description(): - """Helper to populate long_description for pypi releases""" - return open("README.rst").read() - - -def _update_xlat_devtools(): - global DEVTOOLS - if DEVTOOLS == "MsDev": - DEVTOOLS = "MsDev15" - elif DEVTOOLS == "Mono": - DEVTOOLS = "dotnet" - - -def _collect_installed_windows_kits_v10(winreg): - """Adds the installed Windows 10 kits to WIN_SDK_KEYS """ - global WIN_SDK_KEYS - installed_kits = [] - - with winreg.OpenKey( - winreg.HKEY_LOCAL_MACHINE, kits_root, 0, winreg.KEY_READ - ) as key: - i = 0 - while True: - try: - installed_kits.append(winreg.EnumKey(key, i)) - i += 1 - except WindowsError: - break - - def make_reg_key(version): - return RegKey( - sdk_name="Windows Kit 10.0", - key=kits_root, - value_name="KitsRoot10", - suffix=os.path.join("bin", version, ARCH), - ) - - WIN_SDK_KEYS += [make_reg_key(e) for e in installed_kits if e.startswith("10.")] - - # Make sure this function won't be called again - _collect_installed_windows_kits_v10 = lambda: None - - -class BuildExtPythonnet(build_ext.build_ext): - user_options = build_ext.build_ext.user_options + [("xplat", None, None)] + description = "Build DLLs with dotnet-cli" + user_options = [("dotnet-config", None, "dotnet build configuration")] def initialize_options(self): - build_ext.build_ext.initialize_options(self) - self.xplat = None + self.dotnet_config = "release" def finalize_options(self): - build_ext.build_ext.finalize_options(self) - - def build_extension(self, ext): - if self.xplat: - _update_xlat_devtools() - - """Builds the .pyd file using msbuild or xbuild""" - if ext.name != "clr": - return build_ext.build_ext.build_extension(self, ext) - - # install packages using nuget - self._install_packages() - - dest_file = self.get_ext_fullpath(ext.name) - dest_dir = os.path.dirname(dest_file) - if not os.path.exists(dest_dir): - os.makedirs(dest_dir) - - # Up to Python 3.2 sys.maxunicode is used to determine the size of - # Py_UNICODE, but from 3.3 onwards Py_UNICODE is a typedef of wchar_t. - # TODO: Is this doing the right check for Py27? - if sys.version_info[:2] <= (3, 2): - unicode_width = 2 if sys.maxunicode < 0x10FFFF else 4 - else: - import ctypes - - unicode_width = ctypes.sizeof(ctypes.c_wchar) - - defines = [ - "PYTHON{0}{1}".format(PY_MAJOR, PY_MINOR), - "PYTHON{0}".format(PY_MAJOR), # Python Major Version - "UCS{0}".format(unicode_width), - ] - - if CONFIG == "Debug": - defines.extend(["DEBUG", "TRACE"]) - - if sys.platform != "win32" and (DEVTOOLS == "Mono" or DEVTOOLS == "dotnet"): - on_darwin = sys.platform == "darwin" - defines.append("MONO_OSX" if on_darwin else "MONO_LINUX") - - # Check if --enable-shared was set when Python was built - enable_shared = sysconfig.get_config_var("Py_ENABLE_SHARED") - if enable_shared: - # Double-check if libpython is linked dynamically with python - ldd_cmd = ["otool", "-L"] if on_darwin else ["ldd"] - lddout = _check_output(ldd_cmd + [sys.executable]) - if "libpython" not in lddout: - enable_shared = False - - if not enable_shared: - defines.append("PYTHON_WITHOUT_ENABLE_SHARED") - - if hasattr(sys, "abiflags"): - if "d" in sys.abiflags: - defines.append("PYTHON_WITH_PYDEBUG") - if "m" in sys.abiflags: - defines.append("PYTHON_WITH_PYMALLOC") - - # check the interop file exists, and create it if it doesn't - interop_file = _get_interop_filename() - if not os.path.exists(interop_file): - self.debug_print("Creating {0}".format(interop_file)) - geninterop = os.path.join("tools", "geninterop", "geninterop.py") - subprocess.check_call([sys.executable, geninterop, interop_file]) - - if DEVTOOLS == "MsDev": - _xbuild = '"{0}"'.format(self._find_msbuild_tool("msbuild.exe")) - _config = "{0}Win".format(CONFIG) - _solution_file = "pythonnet.sln" - _custom_define_constants = False - elif DEVTOOLS == "MsDev15": - _xbuild = '"{0}"'.format(self._find_msbuild_tool_15()) - _config = "{0}Win".format(CONFIG) - _solution_file = "pythonnet.15.sln" - _custom_define_constants = True - elif DEVTOOLS == "Mono": - _xbuild = "xbuild" - _config = "{0}Mono".format(CONFIG) - _solution_file = "pythonnet.sln" - _custom_define_constants = False - elif DEVTOOLS == "dotnet": - _xbuild = "dotnet msbuild" - _config = "{0}Mono".format(CONFIG) - _solution_file = "pythonnet.15.sln" - _custom_define_constants = True - else: - raise NotImplementedError( - "DevTool {0} not supported (use MsDev/MsDev15/Mono/dotnet)".format( - DEVTOOLS - ) - ) - - cmd = [ - _xbuild, - _solution_file, - "/p:Configuration={}".format(_config), - "/p:Platform={}".format(ARCH), - '/p:{}DefineConstants="{}"'.format( - "Custom" if _custom_define_constants else "", "%3B".join(defines) - ), - '/p:PythonBuildDir="{}"'.format(os.path.abspath(dest_dir)), - '/p:PythonInteropFile="{}"'.format(os.path.basename(interop_file)), - "/p:PackageId=pythonnet_py{0}{1}_{2}".format(PY_MAJOR, PY_MINOR, ARCH), - "/verbosity:{}".format(VERBOSITY), - ] - - manifest = self._get_manifest(dest_dir) - if manifest: - cmd.append('/p:PythonManifest="{0}"'.format(manifest)) - - self.debug_print("Building: {0}".format(" ".join(cmd))) - use_shell = True if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet" else False - - subprocess.check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell) - subprocess.check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell) - if DEVTOOLS == "MsDev15" or DEVTOOLS == "dotnet": - subprocess.check_call( - " ".join( - cmd - + [ - '"/t:Console_15:publish;Python_EmbeddingTest_15:publish"', - "/p:TargetFramework=netcoreapp2.0", - ] - ), - shell=use_shell, - ) - if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet": - self._build_monoclr() + pass - def _get_manifest(self, build_dir): - if DEVTOOLS != "MsDev" and DEVTOOLS != "MsDev15": - return - mt = self._find_msbuild_tool("mt.exe", use_windows_sdk=True) - manifest = os.path.abspath(os.path.join(build_dir, "app.manifest")) - cmd = [ - mt, - '-inputresource:"{0}"'.format(sys.executable), - '-out:"{0}"'.format(manifest), - ] - self.debug_print("Extracting manifest from {}".format(sys.executable)) - subprocess.check_call(" ".join(cmd), shell=False) - return manifest + def get_source_files(self): + return [] - def _build_monoclr(self): - try: - mono_libs = _check_output("pkg-config --libs mono-2", shell=True) - except: - if DEVTOOLS == "dotnet": - print("Skipping building monoclr module...") - return - raise - mono_cflags = _check_output("pkg-config --cflags mono-2", shell=True) - glib_libs = _check_output("pkg-config --libs glib-2.0", shell=True) - glib_cflags = _check_output("pkg-config --cflags glib-2.0", shell=True) - cflags = mono_cflags.strip() + " " + glib_cflags.strip() - libs = mono_libs.strip() + " " + glib_libs.strip() - - # build the clr python module - clr_ext = Extension( - "clr", - sources=["src/monoclr/pynetinit.c", "src/monoclr/clrmod.c"], - extra_compile_args=cflags.split(" "), - extra_link_args=libs.split(" "), - ) - - build_ext.build_ext.build_extension(self, clr_ext) - - def _install_packages(self): - """install packages using nuget""" - use_shell = DEVTOOLS == "Mono" or DEVTOOLS == "dotnet" - - if DEVTOOLS == "MsDev15" or DEVTOOLS == "dotnet": - if DEVTOOLS == "MsDev15": - _config = "{0}Win".format(CONFIG) - elif DEVTOOLS == "dotnet": - _config = "{0}Mono".format(CONFIG) - - cmd = "dotnet msbuild /t:Restore pythonnet.15.sln /p:Configuration={0} /p:Platform={1}".format( - _config, ARCH - ) - self.debug_print("Updating packages with xplat: {0}".format(cmd)) - subprocess.check_call(cmd, shell=use_shell) - else: - nuget = os.path.join("tools", "nuget", "nuget.exe") - - if DEVTOOLS == "Mono": - nuget = "mono {0}".format(nuget) - - cmd = "{0} update -self".format(nuget) - self.debug_print("Updating NuGet: {0}".format(cmd)) - subprocess.check_call(cmd, shell=use_shell) - - try: - # msbuild=14 is mainly for Mono issues - cmd = "{0} restore pythonnet.sln -MSBuildVersion 14 -o packages".format( - nuget - ) - self.debug_print("Installing packages: {0}".format(cmd)) - subprocess.check_call(cmd, shell=use_shell) - except: - # when only VS 2017 is installed do not specify msbuild version - cmd = "{0} restore pythonnet.sln -o packages".format(nuget) - self.debug_print("Installing packages: {0}".format(cmd)) - subprocess.check_call(cmd, shell=use_shell) - - def _find_msbuild_tool(self, tool="msbuild.exe", use_windows_sdk=False): - """Return full path to one of the Microsoft build tools""" - - # trying to search path with help of vswhere when MSBuild 15.0 and higher installed. - if tool == "msbuild.exe" and use_windows_sdk == False: - try: - basePathes = subprocess.check_output( - [ - "tools\\vswhere\\vswhere.exe", - "-latest", - "-version", - "[15.0, 16.0)", - "-requires", - "Microsoft.Component.MSBuild", - "-property", - "InstallationPath", - ] - ).splitlines() - if len(basePathes): - return os.path.join( - basePathes[0].decode(sys.stdout.encoding or "utf-8"), - "MSBuild", - "15.0", - "Bin", - "MSBuild.exe", - ) - except: - pass # keep trying to search by old method. - - # Search in PATH first - path = spawn.find_executable(tool) - if path: - return path - - # Search within registry to find build tools - try: # PY2 - import _winreg as winreg - except ImportError: # PY3 - import winreg - - _collect_installed_windows_kits_v10(winreg) - - keys_to_check = WIN_SDK_KEYS if use_windows_sdk else VS_KEYS - hklm = winreg.HKEY_LOCAL_MACHINE - for rkey in keys_to_check: - try: - with winreg.OpenKey(hklm, rkey.key) as hkey: - val, type_ = winreg.QueryValueEx(hkey, rkey.value_name) - if type_ != winreg.REG_SZ: - continue - path = os.path.join(val, rkey.suffix, tool) - if os.path.exists(path): - self.debug_print( - "Using {0} from {1}".format(tool, rkey.sdk_name) - ) - return path - except WindowsError: - # Key doesn't exist - pass - - # Add Visual C++ for Python as a fall-back in case one - # of the other Windows SDKs isn't installed. - # TODO: Extend checking by using setuptools/msvc.py? - if use_windows_sdk: - sdk_name = "Visual C++ for Python" - localappdata = os.environ["LOCALAPPDATA"] - suffix = "Bin\\x64" if ARCH == "x64" else "Bin" - path = os.path.join(localappdata, vs_python, suffix, tool) - if os.path.exists(path): - self.debug_print("Using {0} from {1}".format(tool, sdk_name)) - return path - - raise RuntimeError("{0} could not be found".format(tool)) - - def _find_msbuild_tool_15(self): - """Return full path to one of the Microsoft build tools""" - try: - basePathes = subprocess.check_output( + def run(self): + for lib in self.distribution.ext_modules: + opts = sum( [ - "tools\\vswhere\\vswhere.exe", - "-latest", - "-version", - "[15.0, 16.0)", - "-requires", - "Microsoft.Component.MSBuild", - "-property", - "InstallationPath", - ] - ).splitlines() - if len(basePathes): - return os.path.join( - basePathes[0].decode(sys.stdout.encoding or "utf-8"), - "MSBuild", - "15.0", - "Bin", - "MSBuild.exe", - ) - else: - raise RuntimeError("MSBuild >=15.0 could not be found.") - except subprocess.CalledProcessError as e: - raise RuntimeError( - "MSBuild >=15.0 could not be found. {0}".format(e.output) - ) - - -class InstallLibPythonnet(install_lib.install_lib): - def install(self): - if not os.path.isdir(self.build_dir): - self.warn( - "'{0}' does not exist -- no Python modules" - " to install".format(self.build_dir) + ["--" + name.replace("_", "-"), value] + for name, value in lib.args.items() + ], + [], ) - return - if not os.path.exists(self.install_dir): - self.mkpath(self.install_dir) + opts.append("--configuration") + opts.append(self.dotnet_config) - # only copy clr.pyd/.so - for srcfile in glob.glob(os.path.join(self.build_dir, "clr.*")): - destfile = os.path.join(self.install_dir, os.path.basename(srcfile)) - self.copy_file(srcfile, destfile) + self.spawn(["dotnet", "build", lib.path] + opts) -class InstallDataPythonnet(install_data.install_data): - def run(self): - build_cmd = self.get_finalized_command("build_ext") - install_cmd = self.get_finalized_command("install") - build_lib = os.path.abspath(build_cmd.build_lib) - install_platlib = os.path.relpath(install_cmd.install_platlib, self.install_dir) - - for i, data_files in enumerate(self.data_files): - if isinstance(data_files, str): - self.data_files[i] = data_files[i].format(build_lib=build_lib) - else: - for j, filename in enumerate(data_files[1]): - data_files[1][j] = filename.format(build_lib=build_lib) - dest = data_files[0].format(install_platlib=install_platlib) - self.data_files[i] = dest, data_files[1] - - return install_data.install_data.run(self) - - -class InstallPythonnet(install.install): - user_options = install.install.user_options + [("xplat", None, None)] - - def initialize_options(self): - install.install.initialize_options(self) - self.xplat = None - +class bdist_wheel_patched(bdist_wheel): def finalize_options(self): - install.install.finalize_options(self) - - def run(self): - if self.xplat: - _update_xlat_devtools() - return install.install.run(self) - -if bdist_wheel: - class BDistWheelPythonnet(bdist_wheel.bdist_wheel): - user_options = bdist_wheel.bdist_wheel.user_options + [("xplat", None, None)] + # Monkey patch bdist_wheel to think the package is pure even though we + # include DLLs + super().finalize_options() + self.root_is_pure = True - def initialize_options(self): - bdist_wheel.bdist_wheel.initialize_options(self) - self.xplat = None - def finalize_options(self): - bdist_wheel.bdist_wheel.finalize_options(self) - - def run(self): - if self.xplat: - _update_xlat_devtools() - return bdist_wheel.bdist_wheel.run(self) - - ############################################################################### - - -setupdir = os.path.dirname(__file__) -if setupdir: - os.chdir(setupdir) - -setup_requires = [] -if not os.path.exists(_get_interop_filename()): - setup_requires.append("pycparser") - -cmdclass={ - "install": InstallPythonnet, - "build_ext": BuildExtPythonnet, - "install_lib": InstallLibPythonnet, - "install_data": InstallDataPythonnet, -} -if bdist_wheel: - cmdclass["bdist_wheel"] = BDistWheelPythonnet +with open("README.rst", "r") as f: + long_description = f.read() setup( name="pythonnet", - version="2.4.1-dev", - description=".Net and Mono integration for Python", - url="https://pythonnet.github.io/", - license="MIT", - author="The Python for .Net developers", + version="2.5.0", + description=".NET and Mono integration for Python", + author="The Python for .NET developers", author_email="pythondotnet@python.org", - setup_requires=setup_requires, - long_description=_get_long_description(), - ext_modules=[Extension("clr", sources=list(_get_source_files()))], - data_files=[("{install_platlib}", ["{build_lib}/Python.Runtime.dll"])], - cmdclass=cmdclass, + long_description=long_description, + license="MIT", + install_requires=["clr-loader"], + zip_safe=False, classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -658,9 +74,24 @@ def run(self): "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Operating System :: MacOS :: MacOS X", ], - zip_safe=False, + package_data={"pythonnet": ["dlls/*.dll"]}, + packages=find_packages(), + cmdclass={"build_ext": BuildDotnet, "bdist_wheel": bdist_wheel_patched}, + ext_modules={ + DotnetLib( + "python-runtime", + "Python.Runtime/", + output="pythonnet/dlls", + ), + DotnetLib( + "python-runtime-native", + "Python.Runtime.Native/", + output="pythonnet/dlls", + ), + }, ) diff --git a/src/SharedAssemblyInfo.cs b/src/SharedAssemblyInfo.cs deleted file mode 100644 index dc72b0bdf..000000000 --- a/src/SharedAssemblyInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Reflection; -using System.Resources; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("pythonnet")] -[assembly: AssemblyProduct("Python for .NET")] -[assembly: AssemblyCopyright("Copyright (c) 2006-2019 the contributors of the 'Python for .NET' project")] -[assembly: AssemblyTrademark("")] - -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("")] - -[assembly: CLSCompliant(true)] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// Version Information. Keeping it simple. May need to revisit for Nuget -// See: https://codingforsmarties.wordpress.com/2016/01/21/how-to-version-assemblies-destined-for-nuget/ -// AssemblyVersion can only be numeric -[assembly: AssemblyVersion("2.4.1")] diff --git a/src/clrmodule/ClrModule.cs b/src/clrmodule/ClrModule.cs deleted file mode 100644 index 7fc654fd6..000000000 --- a/src/clrmodule/ClrModule.cs +++ /dev/null @@ -1,126 +0,0 @@ -//============================================================================ -// This file replaces the hand-maintained stub that used to implement clr.dll. -// This is a line-by-line port from IL back to C#. -// We now use RGiesecke.DllExport on the required static init method so it can be -// loaded by a standard CPython interpreter as an extension module. When it -// is loaded, it bootstraps the managed runtime integration layer and defers -// to it to do initialization and put the clr module into sys.modules, etc. - -// The "USE_PYTHON_RUNTIME_*" defines control what extra evidence is used -// to help the CLR find the appropriate Python.Runtime assembly. - -// If defined, the "pythonRuntimeVersionString" variable must be set to -// Python.Runtime's current version. -#define USE_PYTHON_RUNTIME_VERSION - -// If defined, the "PythonRuntimePublicKeyTokenData" data array must be -// set to Python.Runtime's public key token. (sn -T Python.Runtin.dll) -#define USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN - -// If DEBUG is defined in the Build Properties, a few Console.WriteLine -// calls are made to indicate what's going on during the load... -//============================================================================ -using System; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; -using RGiesecke.DllExport; - -public class clrModule -{ -#if PYTHON3 - [DllExport("PyInit_clr", CallingConvention.StdCall)] - public static IntPtr PyInit_clr() -#elif PYTHON2 - [DllExport("initclr", CallingConvention.StdCall)] - public static void initclr() -#endif - { - DebugPrint("Attempting to load 'Python.Runtime' using standard binding rules."); -#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN - var pythonRuntimePublicKeyTokenData = new byte[] { 0x50, 0x00, 0xfe, 0xa6, 0xcb, 0xa7, 0x02, 0xdd }; -#endif - - // Attempt to find and load Python.Runtime using standard assembly binding rules. - // This roughly translates into looking in order: - // - GAC - // - ApplicationBase - // - A PrivateBinPath under ApplicationBase - // With an unsigned assembly, the GAC is skipped. - var pythonRuntimeName = new AssemblyName("Python.Runtime") - { -#if USE_PYTHON_RUNTIME_VERSION - // Has no effect until SNK works. Keep updated anyways. - Version = new Version("2.4.1"), -#endif - CultureInfo = CultureInfo.InvariantCulture - }; -#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN - pythonRuntimeName.SetPublicKeyToken(pythonRuntimePublicKeyTokenData); -#endif - // We've got the AssemblyName with optional features; try to load it. - Assembly pythonRuntime; - try - { - pythonRuntime = Assembly.Load(pythonRuntimeName); - DebugPrint("Success loading 'Python.Runtime' using standard binding rules."); - } - catch (IOException) - { - DebugPrint("'Python.Runtime' not found using standard binding rules."); - try - { - // If the above fails for any reason, we fallback to attempting to load "Python.Runtime.dll" - // from the directory this assembly is running in. "This assembly" is probably "clr.pyd", - // sitting somewhere in PYTHONPATH. This is using Assembly.LoadFrom, and inherits all the - // caveats of that call. See MSDN docs for details. - // Suzanne Cook's blog is also an excellent source of info on this: - // http://blogs.msdn.com/suzcook/ - // http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx - // http://blogs.msdn.com/suzcook/archive/2003/06/13/57180.aspx - - Assembly executingAssembly = Assembly.GetExecutingAssembly(); - string assemblyDirectory = Path.GetDirectoryName(executingAssembly.Location); - if (assemblyDirectory == null) - { - throw new InvalidOperationException(executingAssembly.Location); - } - string pythonRuntimeDllPath = Path.Combine(assemblyDirectory, "Python.Runtime.dll"); - DebugPrint($"Attempting to load Python.Runtime from: '{pythonRuntimeDllPath}'."); - pythonRuntime = Assembly.LoadFrom(pythonRuntimeDllPath); - DebugPrint($"Success loading 'Python.Runtime' from: '{pythonRuntimeDllPath}'."); - } - catch (InvalidOperationException) - { - DebugPrint("Could not load 'Python.Runtime'."); -#if PYTHON3 - return IntPtr.Zero; -#elif PYTHON2 - return; -#endif - } - } - - // Once here, we've successfully loaded SOME version of Python.Runtime - // So now we get the PythonEngine and execute the InitExt method on it. - Type pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine"); - -#if PYTHON3 - return (IntPtr)pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null); -#elif PYTHON2 - pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null); -#endif - } - - /// - /// Substitute for Debug.Writeline(...). Ideally we would use Debug.Writeline - /// but haven't been able to configure the TRACE from within Python. - /// - [Conditional("DEBUG")] - private static void DebugPrint(string str) - { - Console.WriteLine(str); - } -} diff --git a/src/clrmodule/Properties/AssemblyInfo.cs b/src/clrmodule/Properties/AssemblyInfo.cs deleted file mode 100644 index 939f4171f..000000000 --- a/src/clrmodule/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("clrmodule")] -[assembly: AssemblyDescription("")] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("ae10d6a4-55c2-482f-9716-9988e6c169e3")] diff --git a/src/clrmodule/clrmodule.15.csproj b/src/clrmodule/clrmodule.15.csproj deleted file mode 100644 index 326620c00..000000000 --- a/src/clrmodule/clrmodule.15.csproj +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - net40 - x64;x86 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 - clrmodule - clrmodule - clrmodule - 2.4.1 - false - false - false - false - false - false - bin\clrmodule.xml - bin\ - false - 1591 - ..\..\ - $(SolutionDir)\bin\ - $(PythonBuildDir)\$(TargetFramework)\ - 6 - prompt - $(PYTHONNET_DEFINE_CONSTANTS) - XPLAT - $(DefineConstants);$(CustomDefineConstants);$(BaseDefineConstants); - $(DefineConstants);TRACE;DEBUG - - - - x86 - - - x64 - - - - false - full - - - true - pdbonly - - - - $(DefineConstants);PYTHON2;TRACE;DEBUG - - - $(DefineConstants);PYTHON2 - - - $(DefineConstants);PYTHON2;TRACE;DEBUG - - - $(DefineConstants);PYTHON2 - - - $(DefineConstants);PYTHON3;TRACE;DEBUG - - - $(DefineConstants);PYTHON3 - - - $(DefineConstants);PYTHON3;TRACE;DEBUG - - - $(DefineConstants);PYTHON3 - - - - - - - - - - - - - - $(TargetPath) - $(TargetDir)$(TargetName).pdb - - - - - - - - diff --git a/src/clrmodule/clrmodule.csproj b/src/clrmodule/clrmodule.csproj deleted file mode 100644 index 6e5ff4966..000000000 --- a/src/clrmodule/clrmodule.csproj +++ /dev/null @@ -1,95 +0,0 @@ - - - - Debug - AnyCPU - {86E834DE-1139-4511-96CC-69636A56E7AC} - Library - clrmodule - clrmodule - bin\clrmodule.xml - bin\ - v4.0 - - 1591 - ..\..\ - $(SolutionDir)\bin\ - Properties - 6 - true - prompt - - - x86 - - - x64 - - - true - PYTHON2;TRACE;DEBUG - full - - - PYTHON2 - true - pdbonly - - - true - PYTHON2;TRACE;DEBUG - full - - - PYTHON2 - true - pdbonly - - - true - PYTHON3;TRACE;DEBUG - full - - - PYTHON3 - true - pdbonly - - - true - PYTHON3;TRACE;DEBUG - full - - - PYTHON3 - true - pdbonly - - - - ..\..\packages\UnmanagedExports.1.2.7\lib\net\RGiesecke.DllExport.Metadata.dll - False - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - - - $(TargetPath) - $(TargetDir)$(TargetName).pdb - - - - - - - diff --git a/src/clrmodule/packages.config b/src/clrmodule/packages.config deleted file mode 100644 index 2a95dc54d..000000000 --- a/src/clrmodule/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/console/Console.15.csproj b/src/console/Console.15.csproj deleted file mode 100644 index 4e765fea4..000000000 --- a/src/console/Console.15.csproj +++ /dev/null @@ -1,94 +0,0 @@ - - - - net40;netcoreapp2.0 - x64;x86 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 - Exe - nPython - Python.Runtime - nPython - 2.4.1 - false - false - false - false - false - false - bin\ - false - $(OutputPath)\$(AssemblyName).xml - $(OutputPath)\$(TargetFramework)\$(AssemblyName).xml - 1591 - ..\..\ - $(SolutionDir)\bin\ - $(PythonBuildDir)\$(TargetFramework)\ - 6 - python-clear.ico - prompt - $(PYTHONNET_DEFINE_CONSTANTS) - XPLAT - $(DefineConstants);$(CustomDefineConstants);$(BaseDefineConstants); - $(DefineConstants);TRACE;DEBUG - $(NuGetPackageRoot)\microsoft.targetingpack.netframework.v4.5\1.0.1\lib\net45\ - - - x86 - - - x64 - - - - false - full - - - true - pdbonly - - - true - false - full - - - true - true - portable - - - - $(DefineConstants);DEBUG;TRACE - - - $(DefineConstants) - - - - $(PythonManifest) - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - Python.Runtime.dll - - - - - - - - - - - - diff --git a/src/console/Console.csproj b/src/console/Console.csproj deleted file mode 100644 index ea88b6356..000000000 --- a/src/console/Console.csproj +++ /dev/null @@ -1,101 +0,0 @@ - - - - Debug - AnyCPU - {E29DCF0A-5114-4A98-B1DD-71264B6EA349} - Exe - nPython - Python.Runtime - bin\nPython.xml - bin\ - v4.0 - - 1591 - ..\..\ - $(SolutionDir)\bin\ - Properties - 6 - python-clear.ico - prompt - - - x86 - - - x64 - - - true - DEBUG;TRACE - full - - - - - true - pdbonly - - - true - DEBUG;TRACE - full - - - - - true - pdbonly - - - true - DEBUG;TRACE - full - - - - - true - pdbonly - - - true - DEBUG;TRACE - full - - - - - true - pdbonly - - - $(PythonManifest) - - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - Python.Runtime.dll - - - - - {097b4ac0-74e9-4c58-bcf8-c69746ec8271} - Python.Runtime - - - - - - - diff --git a/src/console/Properties/AssemblyInfo.cs b/src/console/Properties/AssemblyInfo.cs deleted file mode 100644 index 081ae0c94..000000000 --- a/src/console/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Reflection; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Python Console")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyDefaultAlias("python.exe")] diff --git a/src/console/python-clear.ico b/src/console/python-clear.ico deleted file mode 100644 index b37050cce..000000000 Binary files a/src/console/python-clear.ico and /dev/null differ diff --git a/src/console/pythonconsole.cs b/src/console/pythonconsole.cs deleted file mode 100644 index 912e9bb0d..000000000 --- a/src/console/pythonconsole.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Python.Runtime; - -namespace Python.Runtime -{ - /// - /// Example of Embedding Python inside of a .NET program. - /// - /// - /// It has similar functionality to doing `import clr` from within Python, but this does it - /// the other way around; That is, it loads Python inside of .NET program. - /// See https://github.com/pythonnet/pythonnet/issues/358 for more info. - /// - public sealed class PythonConsole - { -#if NET40 - private static AssemblyLoader assemblyLoader = new AssemblyLoader(); -#endif - private PythonConsole() - { - } - - [STAThread] - public static int Main(string[] args) - { - // Only net40 is capable to safely inject python.runtime.dll into resources. -#if NET40 - // reference the static assemblyLoader to stop it being optimized away - AssemblyLoader a = assemblyLoader; -#endif - string[] cmd = Environment.GetCommandLineArgs(); - PythonEngine.Initialize(); - - int i = Runtime.Py_Main(cmd.Length, cmd); - PythonEngine.Shutdown(); - - return i; - } - -#if NET40 - // Register a callback function to load embedded assemblies. - // (Python.Runtime.dll is included as a resource) - private sealed class AssemblyLoader - { - private Dictionary loadedAssemblies; - - public AssemblyLoader() - { - loadedAssemblies = new Dictionary(); - - AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => - { - string shortName = args.Name.Split(',')[0]; - string resourceName = $"{shortName}.dll"; - - if (loadedAssemblies.ContainsKey(resourceName)) - { - return loadedAssemblies[resourceName]; - } - - // looks for the assembly from the resources and load it - using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) - { - if (stream != null) - { - var assemblyData = new byte[stream.Length]; - stream.Read(assemblyData, 0, assemblyData.Length); - Assembly assembly = Assembly.Load(assemblyData); - loadedAssemblies[resourceName] = assembly; - return assembly; - } - } - return null; - }; - } - } -#endif - } -} diff --git a/src/embed_tests/Program.cs b/src/embed_tests/Program.cs deleted file mode 100644 index b4439e3e4..000000000 --- a/src/embed_tests/Program.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -using NUnit.Common; - -using NUnitLite; - -namespace Python.EmbeddingTest -{ - public class Program - { - public static int Main(string[] args) - { - return new AutoRun(typeof(Program).Assembly).Execute( - args, - new ExtendedTextWrapper(Console.Out), - Console.In); - } - } -} diff --git a/src/embed_tests/Python.EmbeddingTest.15.csproj b/src/embed_tests/Python.EmbeddingTest.15.csproj deleted file mode 100644 index 4f6b2de46..000000000 --- a/src/embed_tests/Python.EmbeddingTest.15.csproj +++ /dev/null @@ -1,116 +0,0 @@ - - - - - net40;netcoreapp2.0 - x64;x86 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 - Exe - false - Python.EmbeddingTest - Python.EmbeddingTest - Python.EmbeddingTest - 2.4.1 - false - false - false - false - bin\ - false - $(OutputPath)\$(AssemblyName).xml - $(OutputPath)\$(TargetFramework)\$(AssemblyName).xml - 1591 - ..\..\ - $(SolutionDir)\bin\ - $(OutputPath)\$(TargetFramework)_publish - 6 - prompt - $(PYTHONNET_DEFINE_CONSTANTS) - XPLAT - $(DefineConstants);$(CustomDefineConstants);$(BaseDefineConstants); - $(DefineConstants);NETCOREAPP - $(DefineConstants);NETSTANDARD - $(DefineConstants);TRACE;DEBUG - $(NuGetPackageRoot)\microsoft.targetingpack.netframework.v4.5\1.0.1\lib\net45\ - - - x86 - - - x64 - - - - false - full - - - true - pdbonly - - - true - false - full - - - true - true - portable - - - - $(DefineConstants);DEBUG;TRACE - - - $(DefineConstants) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $(TargetPath) - $(TargetDir)$(TargetName).pdb - - - - - - - - diff --git a/src/monoclr/clrmod.c b/src/monoclr/clrmod.c deleted file mode 100644 index 4e8027e3a..000000000 --- a/src/monoclr/clrmod.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "pynetclr.h" - -/* List of functions defined in the module */ -static PyMethodDef clr_methods[] = { - {NULL, NULL, 0, NULL} /* Sentinel */ -}; - -PyDoc_STRVAR(clr_module_doc, - "clr facade module to initialize the CLR. It's later " - "replaced by the real clr module. This module has a facade " - "attribute to make it distinguishable from the real clr module." -); - -static PyNet_Args *pn_args; -char **environ = NULL; - -#if PY_MAJOR_VERSION >= 3 -static struct PyModuleDef clrdef = { - PyModuleDef_HEAD_INIT, - "clr", /* m_name */ - clr_module_doc, /* m_doc */ - -1, /* m_size */ - clr_methods, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL, /* m_free */ -}; -#endif - -static PyObject *_initclr() -{ - PyObject *m; - - /* Create the module and add the functions */ -#if PY_MAJOR_VERSION >= 3 - m = PyModule_Create(&clrdef); -#else - m = Py_InitModule3("clr", clr_methods, clr_module_doc); -#endif - if (m == NULL) - return NULL; - PyModule_AddObject(m, "facade", Py_True); - Py_INCREF(Py_True); - - pn_args = PyNet_Init(1); - if (pn_args->error) - { - return NULL; - } - - if (NULL != pn_args->module) - return pn_args->module; - - return m; -} - -#if PY_MAJOR_VERSION >= 3 -PyMODINIT_FUNC -PyInit_clr(void) -{ - return _initclr(); -} -#else -PyMODINIT_FUNC -initclr(void) -{ - _initclr(); -} -#endif diff --git a/src/monoclr/pynetclr.h b/src/monoclr/pynetclr.h deleted file mode 100644 index c5e181156..000000000 --- a/src/monoclr/pynetclr.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef PYNET_CLR_H -#define PYNET_CLR_H - -#include -#include -#include -#include -#include -#include -#include - -#define MONO_VERSION "v4.0.30319.1" -#define MONO_DOMAIN "Python.Runtime" -#define PR_ASSEMBLY "Python.Runtime.dll" - -typedef struct -{ - MonoDomain *domain; - MonoAssembly *pr_assm; - MonoMethod *shutdown; - char *pr_file; - char *error; - char *init_name; - char *shutdown_name; - PyObject *module; -} PyNet_Args; - -PyNet_Args *PyNet_Init(int); -void PyNet_Finalize(PyNet_Args *); -void main_thread_handler(gpointer user_data); -char *PyNet_ExceptionToString(MonoObject *); - -#endif // PYNET_CLR_H diff --git a/src/monoclr/pynetinit.c b/src/monoclr/pynetinit.c deleted file mode 100644 index 8b49ddae3..000000000 --- a/src/monoclr/pynetinit.c +++ /dev/null @@ -1,252 +0,0 @@ -#include "pynetclr.h" -#include "stdlib.h" - -#ifndef _WIN32 -#include "dirent.h" -#include "dlfcn.h" -#include "libgen.h" -#include "alloca.h" -#endif - - -// initialize Mono and PythonNet -PyNet_Args *PyNet_Init(int ext) -{ - PyNet_Args *pn_args; - pn_args = (PyNet_Args *)malloc(sizeof(PyNet_Args)); - pn_args->pr_file = PR_ASSEMBLY; - pn_args->error = NULL; - pn_args->shutdown = NULL; - pn_args->module = NULL; - - if (ext == 0) - { - pn_args->init_name = "Python.Runtime:Initialize()"; - } - else - { - pn_args->init_name = "Python.Runtime:InitExt()"; - } - pn_args->shutdown_name = "Python.Runtime:Shutdown()"; - - pn_args->domain = mono_jit_init_version(MONO_DOMAIN, MONO_VERSION); - mono_domain_set_config(pn_args->domain, ".", "Python.Runtime.dll.config"); - - /* - * Load the default Mono configuration file, this is needed - * if you are planning on using the dllmaps defined on the - * system configuration - */ - mono_config_parse(NULL); - - /* I can't use this call to run the main_thread_handler. The function - * runs it in another thread but *this* thread holds the Python - * import lock -> DEAD LOCK. - * - * mono_runtime_exec_managed_code(pn_args->domain, main_thread_handler, - * pn_args); - */ - - main_thread_handler(pn_args); - - if (pn_args->error != NULL) - { - PyErr_SetString(PyExc_ImportError, pn_args->error); - } - return pn_args; -} - -// Shuts down PythonNet and cleans up Mono -void PyNet_Finalize(PyNet_Args *pn_args) -{ - MonoObject *exception = NULL; - - if (pn_args->shutdown) - { - mono_runtime_invoke(pn_args->shutdown, NULL, NULL, &exception); - if (exception) - { - pn_args->error = PyNet_ExceptionToString(exception); - } - pn_args->shutdown = NULL; - } - - if (pn_args->domain) - { - mono_jit_cleanup(pn_args->domain); - pn_args->domain = NULL; - } - free(pn_args); -} - -MonoMethod *getMethodFromClass(MonoClass *cls, char *name) -{ - MonoMethodDesc *mdesc; - MonoMethod *method; - - mdesc = mono_method_desc_new(name, 1); - method = mono_method_desc_search_in_class(mdesc, cls); - mono_method_desc_free(mdesc); - - return method; -} - -void main_thread_handler(gpointer user_data) -{ - PyNet_Args *pn_args = (PyNet_Args *)user_data; - MonoMethod *init; - MonoImage *pr_image; - MonoClass *pythonengine; - MonoObject *exception = NULL; - MonoObject *init_result; - -#ifndef _WIN32 - // Get the filename of the python shared object and set - // LD_LIBRARY_PATH so Mono can find it. - Dl_info dlinfo = {0}; - if (0 != dladdr(&Py_Initialize, &dlinfo)) - { - char *fname = alloca(strlen(dlinfo.dli_fname) + 1); - strcpy(fname, dlinfo.dli_fname); - char *py_libdir = dirname(fname); - char *ld_library_path = getenv("LD_LIBRARY_PATH"); - if (NULL == ld_library_path) - { - setenv("LD_LIBRARY_PATH", py_libdir, 1); - } - else - { - char *new_ld_library_path = alloca(strlen(py_libdir) - + strlen(ld_library_path) - + 2); - strcpy(new_ld_library_path, py_libdir); - strcat(new_ld_library_path, ":"); - strcat(new_ld_library_path, ld_library_path); - setenv("LD_LIBRARY_PATH", py_libdir, 1); - } - } - - //get python path system variable - PyObject *syspath = PySys_GetObject("path"); - char *runtime_full_path = (char*) malloc(1024); - const char *slash = "/"; - int found = 0; - - int ii = 0; - for (ii = 0; ii < PyList_Size(syspath); ++ii) - { -#if PY_MAJOR_VERSION >= 3 - Py_ssize_t wlen; - wchar_t *wstr = PyUnicode_AsWideCharString(PyList_GetItem(syspath, ii), &wlen); - char *pydir = (char*)malloc(wlen + 1); - size_t mblen = wcstombs(pydir, wstr, wlen + 1); - if (mblen > wlen) - pydir[wlen] = '\0'; - PyMem_Free(wstr); -#else - const char *pydir = PyString_AsString(PyList_GetItem(syspath, ii)); -#endif - char *curdir = (char*) malloc(1024); - strncpy(curdir, strlen(pydir) > 0 ? pydir : ".", 1024); - strncat(curdir, slash, 1024); - -#if PY_MAJOR_VERSION >= 3 - free(pydir); -#endif - - //look in this directory for the pn_args->pr_file - DIR *dirp = opendir(curdir); - if (dirp != NULL) - { - struct dirent *dp; - while ((dp = readdir(dirp)) != NULL) - { - if (strcmp(dp->d_name, pn_args->pr_file) == 0) - { - strcpy(runtime_full_path, curdir); - strcat(runtime_full_path, pn_args->pr_file); - found = 1; - break; - } - } - closedir(dirp); - } - free(curdir); - - if (found) - { - pn_args->pr_file = runtime_full_path; - break; - } - } - - if (!found) - { - fprintf(stderr, "Could not find assembly %s. \n", pn_args->pr_file); - return; - } -#endif - - pn_args->pr_assm = mono_domain_assembly_open(pn_args->domain, pn_args->pr_file); - if (!pn_args->pr_assm) - { - pn_args->error = "Unable to load assembly"; - return; - } -#ifndef _WIN32 - free(runtime_full_path); -#endif - - pr_image = mono_assembly_get_image(pn_args->pr_assm); - if (!pr_image) - { - pn_args->error = "Unable to get image"; - return; - } - - pythonengine = mono_class_from_name(pr_image, "Python.Runtime", "PythonEngine"); - if (!pythonengine) - { - pn_args->error = "Unable to load class PythonEngine from Python.Runtime"; - return; - } - - init = getMethodFromClass(pythonengine, pn_args->init_name); - if (!init) - { - pn_args->error = "Unable to fetch Init method from PythonEngine"; - return; - } - - pn_args->shutdown = getMethodFromClass(pythonengine, pn_args->shutdown_name); - if (!pn_args->shutdown) - { - pn_args->error = "Unable to fetch shutdown method from PythonEngine"; - return; - } - - init_result = mono_runtime_invoke(init, NULL, NULL, &exception); - if (exception) - { - pn_args->error = PyNet_ExceptionToString(exception); - return; - } - -#if PY_MAJOR_VERSION >= 3 - if (NULL != init_result) - pn_args->module = *(PyObject**)mono_object_unbox(init_result); -#endif -} - -// Get string from a Mono exception -char *PyNet_ExceptionToString(MonoObject *e) -{ - MonoMethodDesc *mdesc = mono_method_desc_new(":ToString()", FALSE); - MonoMethod *mmethod = mono_method_desc_search_in_class(mdesc, mono_get_object_class()); - mono_method_desc_free(mdesc); - - mmethod = mono_object_get_virtual_method(e, mmethod); - MonoString *monoString = (MonoString*) mono_runtime_invoke(mmethod, e, NULL, NULL); - mono_runtime_invoke(mmethod, e, NULL, NULL); - return mono_string_to_utf8(monoString); -} diff --git a/src/pythonnet.snk b/src/pythonnet.snk deleted file mode 100644 index 90e3d6f41..000000000 Binary files a/src/pythonnet.snk and /dev/null differ diff --git a/src/runtime/Properties/AssemblyInfo.cs b/src/runtime/Properties/AssemblyInfo.cs deleted file mode 100644 index a5d33c7ab..000000000 --- a/src/runtime/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Python for .NET")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyDefaultAlias("Python.Runtime.dll")] - -[assembly: InternalsVisibleTo("Python.EmbeddingTest")] diff --git a/src/runtime/Python.Runtime.15.csproj b/src/runtime/Python.Runtime.15.csproj deleted file mode 100644 index c31d4bf91..000000000 --- a/src/runtime/Python.Runtime.15.csproj +++ /dev/null @@ -1,147 +0,0 @@ - - - - net40;netstandard2.0 - AnyCPU - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 - net45 - Python.Runtime - Python.Runtime - pythonnet - 2.4.1 - true - false - Python for .NET - Copyright (c) 2006-2019 the contributors of the 'Python for .NET' project - Python and CLR (.NET and Mono) cross-platform language interop - pythonnet - https://github.com/pythonnet/pythonnet/blob/master/LICENSE - https://github.com/pythonnet/pythonnet - git - - python interop dynamic dlr Mono pinvoke - https://raw.githubusercontent.com/pythonnet/pythonnet/master/src/console/python-clear.ico - https://pythonnet.github.io/ - bin\ - false - $(OutputPath)\$(AssemblyName).xml - $(OutputPath)\$(TargetFramework)\$(AssemblyName).xml - 1591;NU1701 - ..\..\ - $(SolutionDir)\bin\ - $(PythonBuildDir)\$(TargetFramework)\ - 7.3 - True - ..\pythonnet.snk - $(PYTHONNET_DEFINE_CONSTANTS) - XPLAT - $(DefineConstants);$(CustomDefineConstants);$(BaseDefineConstants); - $(DefineConstants);NETSTANDARD - $(DefineConstants);TRACE;DEBUG - $(NuGetPackageRoot)\microsoft.targetingpack.netframework.v4.5\1.0.1\lib\net45\ - $(PYTHONNET_PY2_VERSION) - PYTHON27 - $(PYTHONNET_PY3_VERSION) - PYTHON38 - $(PYTHONNET_WIN_DEFINE_CONSTANTS) - UCS2 - $(PYTHONNET_MONO_DEFINE_CONSTANTS) - UCS4;MONO_LINUX;PYTHON_WITH_PYMALLOC - $(PYTHONNET_INTEROP_FILE) - - - false - full - - - true - pdbonly - - - true - false - full - - - true - true - portable - - - - $(DefineConstants);PYTHON2;$(Python2Version);$(PythonMonoDefineConstants) - - - $(DefineConstants);PYTHON3;$(Python3Version);$(PythonMonoDefineConstants) - - - $(DefineConstants);PYTHON2;$(Python2Version);$(PythonMonoDefineConstants);FINALIZER_CHECK;TRACE;DEBUG - - - $(DefineConstants);PYTHON3;$(Python3Version);$(PythonMonoDefineConstants);FINALIZER_CHECK;TRACE;DEBUG - - - $(DefineConstants);PYTHON2;$(Python2Version);$(PythonWinDefineConstants) - - - $(DefineConstants);PYTHON3;$(Python3Version);$(PythonWinDefineConstants) - - - $(DefineConstants);PYTHON2;$(Python2Version);$(PythonWinDefineConstants);FINALIZER_CHECK;TRACE;DEBUG - - - $(DefineConstants);PYTHON3;$(Python3Version);$(PythonWinDefineConstants);FINALIZER_CHECK;TRACE;DEBUG - - - - - - - - - - - - - - - - - - - - - - clr.py - - - - - - - - - - - - - - - - - - - - $(TargetPath) - $(TargetDir)$(TargetName).pdb - - - - - - - - - - - diff --git a/src/runtime/Python.Runtime.csproj b/src/runtime/Python.Runtime.csproj deleted file mode 100644 index 02656e51e..000000000 --- a/src/runtime/Python.Runtime.csproj +++ /dev/null @@ -1,174 +0,0 @@ - - - - Debug - AnyCPU - {097B4AC0-74E9-4C58-BCF8-C69746EC8271} - Library - Python.Runtime - Python.Runtime - bin\Python.Runtime.xml - bin\ - v4.0 - - 1591 - ..\..\ - $(SolutionDir)\bin\ - Properties - 7.3 - true - false - ..\pythonnet.snk - - - - - - PYTHON2;PYTHON27;UCS4 - true - pdbonly - - - PYTHON3;PYTHON38;UCS4 - true - pdbonly - - - true - PYTHON2;PYTHON27;UCS4;TRACE;DEBUG - false - full - - - true - PYTHON3;PYTHON38;UCS4;TRACE;DEBUG - false - full - - - PYTHON2;PYTHON27;UCS2 - true - pdbonly - - - PYTHON3;PYTHON38;UCS2 - true - pdbonly - - - true - PYTHON2;PYTHON27;UCS2;TRACE;DEBUG - false - full - - - true - PYTHON3;PYTHON38;UCS2;TRACE;DEBUG - false - full - - - - - - - - - Properties\SharedAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - clr.py - - - - - $(TargetPath) - $(TargetDir)$(TargetName).pdb - - - - - - diff --git a/src/runtime/interop34.cs b/src/runtime/interop34.cs deleted file mode 100644 index 6857ff2d0..000000000 --- a/src/runtime/interop34.cs +++ /dev/null @@ -1,144 +0,0 @@ -// Auto-generated by geninterop.py. -// DO NOT MODIFIY BY HAND. - - -#if PYTHON34 -using System; -using System.Collections; -using System.Collections.Specialized; -using System.Runtime.InteropServices; -using System.Reflection; -using System.Text; - -namespace Python.Runtime -{ - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - internal class TypeOffset - { - static TypeOffset() - { - Type type = typeof(TypeOffset); - FieldInfo[] fi = type.GetFields(); - int size = IntPtr.Size; - for (int i = 0; i < fi.Length; i++) - { - fi[i].SetValue(null, i * size); - } - } - - public static int magic() - { - return ob_size; - } - - // Auto-generated from PyHeapTypeObject in Python.h - public static int ob_refcnt = 0; - public static int ob_type = 0; - public static int ob_size = 0; - public static int tp_name = 0; - public static int tp_basicsize = 0; - public static int tp_itemsize = 0; - public static int tp_dealloc = 0; - public static int tp_print = 0; - public static int tp_getattr = 0; - public static int tp_setattr = 0; - public static int tp_reserved = 0; - public static int tp_repr = 0; - public static int tp_as_number = 0; - public static int tp_as_sequence = 0; - public static int tp_as_mapping = 0; - public static int tp_hash = 0; - public static int tp_call = 0; - public static int tp_str = 0; - public static int tp_getattro = 0; - public static int tp_setattro = 0; - public static int tp_as_buffer = 0; - public static int tp_flags = 0; - public static int tp_doc = 0; - public static int tp_traverse = 0; - public static int tp_clear = 0; - public static int tp_richcompare = 0; - public static int tp_weaklistoffset = 0; - public static int tp_iter = 0; - public static int tp_iternext = 0; - public static int tp_methods = 0; - public static int tp_members = 0; - public static int tp_getset = 0; - public static int tp_base = 0; - public static int tp_dict = 0; - public static int tp_descr_get = 0; - public static int tp_descr_set = 0; - public static int tp_dictoffset = 0; - public static int tp_init = 0; - public static int tp_alloc = 0; - public static int tp_new = 0; - public static int tp_free = 0; - public static int tp_is_gc = 0; - public static int tp_bases = 0; - public static int tp_mro = 0; - public static int tp_cache = 0; - public static int tp_subclasses = 0; - public static int tp_weaklist = 0; - public static int tp_del = 0; - public static int tp_version_tag = 0; - public static int tp_finalize = 0; - public static int nb_add = 0; - public static int nb_subtract = 0; - public static int nb_multiply = 0; - public static int nb_remainder = 0; - public static int nb_divmod = 0; - public static int nb_power = 0; - public static int nb_negative = 0; - public static int nb_positive = 0; - public static int nb_absolute = 0; - public static int nb_bool = 0; - public static int nb_invert = 0; - public static int nb_lshift = 0; - public static int nb_rshift = 0; - public static int nb_and = 0; - public static int nb_xor = 0; - public static int nb_or = 0; - public static int nb_int = 0; - public static int nb_reserved = 0; - public static int nb_float = 0; - public static int nb_inplace_add = 0; - public static int nb_inplace_subtract = 0; - public static int nb_inplace_multiply = 0; - public static int nb_inplace_remainder = 0; - public static int nb_inplace_power = 0; - public static int nb_inplace_lshift = 0; - public static int nb_inplace_rshift = 0; - public static int nb_inplace_and = 0; - public static int nb_inplace_xor = 0; - public static int nb_inplace_or = 0; - public static int nb_floor_divide = 0; - public static int nb_true_divide = 0; - public static int nb_inplace_floor_divide = 0; - public static int nb_inplace_true_divide = 0; - public static int nb_index = 0; - public static int mp_length = 0; - public static int mp_subscript = 0; - public static int mp_ass_subscript = 0; - public static int sq_length = 0; - public static int sq_concat = 0; - public static int sq_repeat = 0; - public static int sq_item = 0; - public static int was_sq_slice = 0; - public static int sq_ass_item = 0; - public static int was_sq_ass_slice = 0; - public static int sq_contains = 0; - public static int sq_inplace_concat = 0; - public static int sq_inplace_repeat = 0; - public static int bf_getbuffer = 0; - public static int bf_releasebuffer = 0; - public static int name = 0; - public static int ht_slots = 0; - public static int qualname = 0; - public static int ht_cached_keys = 0; - - /* here are optional user slots, followed by the members. */ - public static int members = 0; - } -} - -#endif diff --git a/src/runtime/interop35.cs b/src/runtime/interop35.cs deleted file mode 100644 index a30bfa4fd..000000000 --- a/src/runtime/interop35.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Auto-generated by geninterop.py. -// DO NOT MODIFIY BY HAND. - - -#if PYTHON35 -using System; -using System.Collections; -using System.Collections.Specialized; -using System.Runtime.InteropServices; -using System.Reflection; -using System.Text; - -namespace Python.Runtime -{ - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - internal class TypeOffset - { - static TypeOffset() - { - Type type = typeof(TypeOffset); - FieldInfo[] fi = type.GetFields(); - int size = IntPtr.Size; - for (int i = 0; i < fi.Length; i++) - { - fi[i].SetValue(null, i * size); - } - } - - public static int magic() - { - return ob_size; - } - - // Auto-generated from PyHeapTypeObject in Python.h - public static int ob_refcnt = 0; - public static int ob_type = 0; - public static int ob_size = 0; - public static int tp_name = 0; - public static int tp_basicsize = 0; - public static int tp_itemsize = 0; - public static int tp_dealloc = 0; - public static int tp_print = 0; - public static int tp_getattr = 0; - public static int tp_setattr = 0; - public static int tp_as_async = 0; - public static int tp_repr = 0; - public static int tp_as_number = 0; - public static int tp_as_sequence = 0; - public static int tp_as_mapping = 0; - public static int tp_hash = 0; - public static int tp_call = 0; - public static int tp_str = 0; - public static int tp_getattro = 0; - public static int tp_setattro = 0; - public static int tp_as_buffer = 0; - public static int tp_flags = 0; - public static int tp_doc = 0; - public static int tp_traverse = 0; - public static int tp_clear = 0; - public static int tp_richcompare = 0; - public static int tp_weaklistoffset = 0; - public static int tp_iter = 0; - public static int tp_iternext = 0; - public static int tp_methods = 0; - public static int tp_members = 0; - public static int tp_getset = 0; - public static int tp_base = 0; - public static int tp_dict = 0; - public static int tp_descr_get = 0; - public static int tp_descr_set = 0; - public static int tp_dictoffset = 0; - public static int tp_init = 0; - public static int tp_alloc = 0; - public static int tp_new = 0; - public static int tp_free = 0; - public static int tp_is_gc = 0; - public static int tp_bases = 0; - public static int tp_mro = 0; - public static int tp_cache = 0; - public static int tp_subclasses = 0; - public static int tp_weaklist = 0; - public static int tp_del = 0; - public static int tp_version_tag = 0; - public static int tp_finalize = 0; - public static int am_await = 0; - public static int am_aiter = 0; - public static int am_anext = 0; - public static int nb_add = 0; - public static int nb_subtract = 0; - public static int nb_multiply = 0; - public static int nb_remainder = 0; - public static int nb_divmod = 0; - public static int nb_power = 0; - public static int nb_negative = 0; - public static int nb_positive = 0; - public static int nb_absolute = 0; - public static int nb_bool = 0; - public static int nb_invert = 0; - public static int nb_lshift = 0; - public static int nb_rshift = 0; - public static int nb_and = 0; - public static int nb_xor = 0; - public static int nb_or = 0; - public static int nb_int = 0; - public static int nb_reserved = 0; - public static int nb_float = 0; - public static int nb_inplace_add = 0; - public static int nb_inplace_subtract = 0; - public static int nb_inplace_multiply = 0; - public static int nb_inplace_remainder = 0; - public static int nb_inplace_power = 0; - public static int nb_inplace_lshift = 0; - public static int nb_inplace_rshift = 0; - public static int nb_inplace_and = 0; - public static int nb_inplace_xor = 0; - public static int nb_inplace_or = 0; - public static int nb_floor_divide = 0; - public static int nb_true_divide = 0; - public static int nb_inplace_floor_divide = 0; - public static int nb_inplace_true_divide = 0; - public static int nb_index = 0; - public static int nb_matrix_multiply = 0; - public static int nb_inplace_matrix_multiply = 0; - public static int mp_length = 0; - public static int mp_subscript = 0; - public static int mp_ass_subscript = 0; - public static int sq_length = 0; - public static int sq_concat = 0; - public static int sq_repeat = 0; - public static int sq_item = 0; - public static int was_sq_slice = 0; - public static int sq_ass_item = 0; - public static int was_sq_ass_slice = 0; - public static int sq_contains = 0; - public static int sq_inplace_concat = 0; - public static int sq_inplace_repeat = 0; - public static int bf_getbuffer = 0; - public static int bf_releasebuffer = 0; - public static int name = 0; - public static int ht_slots = 0; - public static int qualname = 0; - public static int ht_cached_keys = 0; - - /* here are optional user slots, followed by the members. */ - public static int members = 0; - } -} - -#endif diff --git a/src/runtime/interop36.cs b/src/runtime/interop36.cs deleted file mode 100644 index c46bcc2f5..000000000 --- a/src/runtime/interop36.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Auto-generated by geninterop.py. -// DO NOT MODIFIY BY HAND. - - -#if PYTHON36 -using System; -using System.Collections; -using System.Collections.Specialized; -using System.Runtime.InteropServices; -using System.Reflection; -using System.Text; - -namespace Python.Runtime -{ - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - internal class TypeOffset - { - static TypeOffset() - { - Type type = typeof(TypeOffset); - FieldInfo[] fi = type.GetFields(); - int size = IntPtr.Size; - for (int i = 0; i < fi.Length; i++) - { - fi[i].SetValue(null, i * size); - } - } - - public static int magic() - { - return ob_size; - } - - // Auto-generated from PyHeapTypeObject in Python.h - public static int ob_refcnt = 0; - public static int ob_type = 0; - public static int ob_size = 0; - public static int tp_name = 0; - public static int tp_basicsize = 0; - public static int tp_itemsize = 0; - public static int tp_dealloc = 0; - public static int tp_print = 0; - public static int tp_getattr = 0; - public static int tp_setattr = 0; - public static int tp_as_async = 0; - public static int tp_repr = 0; - public static int tp_as_number = 0; - public static int tp_as_sequence = 0; - public static int tp_as_mapping = 0; - public static int tp_hash = 0; - public static int tp_call = 0; - public static int tp_str = 0; - public static int tp_getattro = 0; - public static int tp_setattro = 0; - public static int tp_as_buffer = 0; - public static int tp_flags = 0; - public static int tp_doc = 0; - public static int tp_traverse = 0; - public static int tp_clear = 0; - public static int tp_richcompare = 0; - public static int tp_weaklistoffset = 0; - public static int tp_iter = 0; - public static int tp_iternext = 0; - public static int tp_methods = 0; - public static int tp_members = 0; - public static int tp_getset = 0; - public static int tp_base = 0; - public static int tp_dict = 0; - public static int tp_descr_get = 0; - public static int tp_descr_set = 0; - public static int tp_dictoffset = 0; - public static int tp_init = 0; - public static int tp_alloc = 0; - public static int tp_new = 0; - public static int tp_free = 0; - public static int tp_is_gc = 0; - public static int tp_bases = 0; - public static int tp_mro = 0; - public static int tp_cache = 0; - public static int tp_subclasses = 0; - public static int tp_weaklist = 0; - public static int tp_del = 0; - public static int tp_version_tag = 0; - public static int tp_finalize = 0; - public static int am_await = 0; - public static int am_aiter = 0; - public static int am_anext = 0; - public static int nb_add = 0; - public static int nb_subtract = 0; - public static int nb_multiply = 0; - public static int nb_remainder = 0; - public static int nb_divmod = 0; - public static int nb_power = 0; - public static int nb_negative = 0; - public static int nb_positive = 0; - public static int nb_absolute = 0; - public static int nb_bool = 0; - public static int nb_invert = 0; - public static int nb_lshift = 0; - public static int nb_rshift = 0; - public static int nb_and = 0; - public static int nb_xor = 0; - public static int nb_or = 0; - public static int nb_int = 0; - public static int nb_reserved = 0; - public static int nb_float = 0; - public static int nb_inplace_add = 0; - public static int nb_inplace_subtract = 0; - public static int nb_inplace_multiply = 0; - public static int nb_inplace_remainder = 0; - public static int nb_inplace_power = 0; - public static int nb_inplace_lshift = 0; - public static int nb_inplace_rshift = 0; - public static int nb_inplace_and = 0; - public static int nb_inplace_xor = 0; - public static int nb_inplace_or = 0; - public static int nb_floor_divide = 0; - public static int nb_true_divide = 0; - public static int nb_inplace_floor_divide = 0; - public static int nb_inplace_true_divide = 0; - public static int nb_index = 0; - public static int nb_matrix_multiply = 0; - public static int nb_inplace_matrix_multiply = 0; - public static int mp_length = 0; - public static int mp_subscript = 0; - public static int mp_ass_subscript = 0; - public static int sq_length = 0; - public static int sq_concat = 0; - public static int sq_repeat = 0; - public static int sq_item = 0; - public static int was_sq_slice = 0; - public static int sq_ass_item = 0; - public static int was_sq_ass_slice = 0; - public static int sq_contains = 0; - public static int sq_inplace_concat = 0; - public static int sq_inplace_repeat = 0; - public static int bf_getbuffer = 0; - public static int bf_releasebuffer = 0; - public static int name = 0; - public static int ht_slots = 0; - public static int qualname = 0; - public static int ht_cached_keys = 0; - - /* here are optional user slots, followed by the members. */ - public static int members = 0; - } -} - -#endif diff --git a/src/runtime/interop37.cs b/src/runtime/interop37.cs deleted file mode 100644 index d5fc76ad3..000000000 --- a/src/runtime/interop37.cs +++ /dev/null @@ -1,149 +0,0 @@ -// Auto-generated by geninterop.py. -// DO NOT MODIFIY BY HAND. - - -#if PYTHON37 -using System; -using System.Collections; -using System.Collections.Specialized; -using System.Runtime.InteropServices; -using System.Reflection; -using System.Text; - -namespace Python.Runtime -{ - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - internal class TypeOffset - { - static TypeOffset() - { - Type type = typeof(TypeOffset); - FieldInfo[] fi = type.GetFields(); - int size = IntPtr.Size; - for (int i = 0; i < fi.Length; i++) - { - fi[i].SetValue(null, i * size); - } - } - - public static int magic() - { - return ob_size; - } - - // Auto-generated from PyHeapTypeObject in Python.h - public static int ob_refcnt = 0; - public static int ob_type = 0; - public static int ob_size = 0; - public static int tp_name = 0; - public static int tp_basicsize = 0; - public static int tp_itemsize = 0; - public static int tp_dealloc = 0; - public static int tp_print = 0; - public static int tp_getattr = 0; - public static int tp_setattr = 0; - public static int tp_as_async = 0; - public static int tp_repr = 0; - public static int tp_as_number = 0; - public static int tp_as_sequence = 0; - public static int tp_as_mapping = 0; - public static int tp_hash = 0; - public static int tp_call = 0; - public static int tp_str = 0; - public static int tp_getattro = 0; - public static int tp_setattro = 0; - public static int tp_as_buffer = 0; - public static int tp_flags = 0; - public static int tp_doc = 0; - public static int tp_traverse = 0; - public static int tp_clear = 0; - public static int tp_richcompare = 0; - public static int tp_weaklistoffset = 0; - public static int tp_iter = 0; - public static int tp_iternext = 0; - public static int tp_methods = 0; - public static int tp_members = 0; - public static int tp_getset = 0; - public static int tp_base = 0; - public static int tp_dict = 0; - public static int tp_descr_get = 0; - public static int tp_descr_set = 0; - public static int tp_dictoffset = 0; - public static int tp_init = 0; - public static int tp_alloc = 0; - public static int tp_new = 0; - public static int tp_free = 0; - public static int tp_is_gc = 0; - public static int tp_bases = 0; - public static int tp_mro = 0; - public static int tp_cache = 0; - public static int tp_subclasses = 0; - public static int tp_weaklist = 0; - public static int tp_del = 0; - public static int tp_version_tag = 0; - public static int tp_finalize = 0; - public static int am_await = 0; - public static int am_aiter = 0; - public static int am_anext = 0; - public static int nb_add = 0; - public static int nb_subtract = 0; - public static int nb_multiply = 0; - public static int nb_remainder = 0; - public static int nb_divmod = 0; - public static int nb_power = 0; - public static int nb_negative = 0; - public static int nb_positive = 0; - public static int nb_absolute = 0; - public static int nb_bool = 0; - public static int nb_invert = 0; - public static int nb_lshift = 0; - public static int nb_rshift = 0; - public static int nb_and = 0; - public static int nb_xor = 0; - public static int nb_or = 0; - public static int nb_int = 0; - public static int nb_reserved = 0; - public static int nb_float = 0; - public static int nb_inplace_add = 0; - public static int nb_inplace_subtract = 0; - public static int nb_inplace_multiply = 0; - public static int nb_inplace_remainder = 0; - public static int nb_inplace_power = 0; - public static int nb_inplace_lshift = 0; - public static int nb_inplace_rshift = 0; - public static int nb_inplace_and = 0; - public static int nb_inplace_xor = 0; - public static int nb_inplace_or = 0; - public static int nb_floor_divide = 0; - public static int nb_true_divide = 0; - public static int nb_inplace_floor_divide = 0; - public static int nb_inplace_true_divide = 0; - public static int nb_index = 0; - public static int nb_matrix_multiply = 0; - public static int nb_inplace_matrix_multiply = 0; - public static int mp_length = 0; - public static int mp_subscript = 0; - public static int mp_ass_subscript = 0; - public static int sq_length = 0; - public static int sq_concat = 0; - public static int sq_repeat = 0; - public static int sq_item = 0; - public static int was_sq_slice = 0; - public static int sq_ass_item = 0; - public static int was_sq_ass_slice = 0; - public static int sq_contains = 0; - public static int sq_inplace_concat = 0; - public static int sq_inplace_repeat = 0; - public static int bf_getbuffer = 0; - public static int bf_releasebuffer = 0; - public static int name = 0; - public static int ht_slots = 0; - public static int qualname = 0; - public static int ht_cached_keys = 0; - - /* here are optional user slots, followed by the members. */ - public static int members = 0; - } -} - -#endif diff --git a/src/runtime/nativecall.cs b/src/runtime/nativecall.cs deleted file mode 100644 index 4a7bf05c8..000000000 --- a/src/runtime/nativecall.cs +++ /dev/null @@ -1,179 +0,0 @@ -using System; -using System.Reflection; -using System.Reflection.Emit; -using System.Runtime.InteropServices; -using System.Threading; - -namespace Python.Runtime -{ - /// - /// Provides support for calling native code indirectly through - /// function pointers. Most of the important parts of the Python - /// C API can just be wrapped with p/invoke, but there are some - /// situations (specifically, calling functions through Python - /// type structures) where we need to call functions indirectly. - /// This class uses Reflection.Emit to generate IJW thunks that - /// support indirect calls to native code using various common - /// call signatures. This is mainly a workaround for the fact - /// that you can't spell an indirect call in C# (but can in IL). - /// Another approach that would work is for this to be turned - /// into a separate utility program that could be run during the - /// build process to generate the thunks as a separate assembly - /// that could then be referenced by the main Python runtime. - /// - internal class NativeCall - { -#if NETSTANDARD - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void Void_1_Delegate(IntPtr a1); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int Int_3_Delegate(IntPtr a1, IntPtr a2, IntPtr a3); - - public static void Void_Call_1(IntPtr fp, IntPtr a1) - { - var d = Marshal.GetDelegateForFunctionPointer(fp); - d(a1); - } - - public static IntPtr Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) - { - var d = Marshal.GetDelegateForFunctionPointer(fp); - return d(a1, a2, a3); - } - - - public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) - { - var d = Marshal.GetDelegateForFunctionPointer(fp); - return d(a1, a2, a3); - } -#else - private static AssemblyBuilder aBuilder; - private static ModuleBuilder mBuilder; - - public static INativeCall Impl; - - static NativeCall() - { - // The static constructor is responsible for generating the - // assembly and the methods that implement the IJW thunks. - // - // To do this, we actually use reflection on the INativeCall - // interface (defined below) and generate the required thunk - // code based on the method signatures. - - var aname = new AssemblyName { Name = "e__NativeCall_Assembly" }; - var aa = AssemblyBuilderAccess.Run; - - aBuilder = Thread.GetDomain().DefineDynamicAssembly(aname, aa); - mBuilder = aBuilder.DefineDynamicModule("e__NativeCall_Module"); - - var ta = TypeAttributes.Public; - TypeBuilder tBuilder = mBuilder.DefineType("e__NativeCall", ta); - - Type iType = typeof(INativeCall); - tBuilder.AddInterfaceImplementation(iType); - - // Use reflection to loop over the INativeCall interface methods, - // calling GenerateThunk to create a managed thunk for each one. - - foreach (MethodInfo method in iType.GetMethods()) - { - GenerateThunk(tBuilder, method); - } - - Type theType = tBuilder.CreateType(); - - Impl = (INativeCall)Activator.CreateInstance(theType); - } - - private static void GenerateThunk(TypeBuilder tb, MethodInfo method) - { - ParameterInfo[] pi = method.GetParameters(); - int count = pi.Length; - int argc = count - 1; - - var args = new Type[count]; - for (var i = 0; i < count; i++) - { - args[i] = pi[i].ParameterType; - } - - MethodBuilder mb = tb.DefineMethod( - method.Name, - MethodAttributes.Public | - MethodAttributes.Virtual, - method.ReturnType, - args - ); - - // Build the method signature for the actual native function. - // This is essentially the signature of the wrapper method - // minus the first argument (the passed in function pointer). - - var nargs = new Type[argc]; - for (var i = 1; i < count; i++) - { - nargs[i - 1] = args[i]; - } - - // IL generation: the (implicit) first argument of the method - // is the 'this' pointer and the second is the function pointer. - // This code pushes the real args onto the stack, followed by - // the function pointer, then the calli opcode to make the call. - - ILGenerator il = mb.GetILGenerator(); - - for (var i = 0; i < argc; i++) - { - il.Emit(OpCodes.Ldarg_S, i + 2); - } - - il.Emit(OpCodes.Ldarg_1); - - il.EmitCalli(OpCodes.Calli, - CallingConvention.Cdecl, - method.ReturnType, - nargs - ); - - il.Emit(OpCodes.Ret); - - tb.DefineMethodOverride(mb, method); - } - - - public static void Void_Call_1(IntPtr fp, IntPtr a1) - { - Impl.Void_Call_1(fp, a1); - } - - public static IntPtr Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) - { - return Impl.Call_3(fp, a1, a2, a3); - } - - public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3) - { - return Impl.Int_Call_3(fp, a1, a2, a3); - } -#endif - } - -#if !NETSTANDARD - /// - /// Defines native call signatures to be generated by NativeCall. - /// - public interface INativeCall - { - void Void_Call_0(IntPtr funcPtr); - - void Void_Call_1(IntPtr funcPtr, IntPtr arg1); - - int Int_Call_3(IntPtr funcPtr, IntPtr t, IntPtr n, IntPtr v); - - IntPtr Call_3(IntPtr funcPtr, IntPtr a1, IntPtr a2, IntPtr a3); - } -#endif -} diff --git a/src/testing/Python.Test.15.csproj b/src/testing/Python.Test.15.csproj deleted file mode 100644 index 8c23fe4b5..000000000 --- a/src/testing/Python.Test.15.csproj +++ /dev/null @@ -1,86 +0,0 @@ - - - - net40;netstandard2.0 - x64;x86 - DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3 - Python.Test - Python.Test - Python.Test - 2.4.1 - bin\ - false - $(OutputPath)\$(AssemblyName).xml - $(OutputPath)\$(TargetFramework)\$(AssemblyName).xml - 1591,0067 - ..\..\ - $(SolutionDir)\bin\ - $(PythonBuildDir)\$(TargetFramework)\ - 6 - false - ..\pythonnet.snk - prompt - $(PYTHONNET_DEFINE_CONSTANTS) - XPLAT - $(DefineConstants);$(CustomDefineConstants);$(BaseDefineConstants); - $(DefineConstants);TRACE;DEBUG - $(NuGetPackageRoot)\microsoft.targetingpack.netframework.v4.5\1.0.1\lib\net45\ - - - x86 - - - x64 - - - - false - full - - - true - pdbonly - - - true - false - full - - - true - true - portable - - - - $(DefineConstants);DEBUG;TRACE - - - $(DefineConstants) - - - - - - - - - - - - - - - - - - - $(TargetPath) - $(TargetDir)$(TargetName).pdb - - - - - - - diff --git a/src/testing/Python.Test.csproj b/src/testing/Python.Test.csproj deleted file mode 100644 index 6bf5c2d22..000000000 --- a/src/testing/Python.Test.csproj +++ /dev/null @@ -1,115 +0,0 @@ - - - - Debug - AnyCPU - {6F401A34-273B-450F-9A4C-13550BE0767B} - Library - Python.Test - Python.Test - bin\Python.Test.xml - bin\ - v4.0 - - 1591,0067 - ..\..\ - $(SolutionDir)\bin\ - 6 - false - ..\pythonnet.snk - prompt - - - x86 - - - x64 - - - true - DEBUG;TRACE - full - - - - - true - pdbonly - - - true - DEBUG;TRACE - full - - - - - true - pdbonly - - - true - DEBUG;TRACE - full - - - - - true - pdbonly - - - true - DEBUG;TRACE - full - - - - - true - pdbonly - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {097B4AC0-74E9-4C58-BCF8-C69746EC8271} - Python.Runtime - - - - - $(TargetPath) - $(TargetDir)$(TargetName).pdb - - - - - - diff --git a/src/tests/__init__.py b/tests/__init__.py similarity index 100% rename from src/tests/__init__.py rename to tests/__init__.py diff --git a/src/tests/_compat.py b/tests/_compat.py similarity index 100% rename from src/tests/_compat.py rename to tests/_compat.py diff --git a/src/tests/_missing_import.py b/tests/_missing_import.py similarity index 100% rename from src/tests/_missing_import.py rename to tests/_missing_import.py diff --git a/src/tests/conftest.py b/tests/conftest.py similarity index 100% rename from src/tests/conftest.py rename to tests/conftest.py diff --git a/src/tests/fixtures/.gitkeep b/tests/fixtures/.gitkeep similarity index 100% rename from src/tests/fixtures/.gitkeep rename to tests/fixtures/.gitkeep diff --git a/src/tests/fixtures/argv-fixture.py b/tests/fixtures/argv-fixture.py similarity index 100% rename from src/tests/fixtures/argv-fixture.py rename to tests/fixtures/argv-fixture.py diff --git a/src/tests/fixtures/netstandard2.0/.gitkeep b/tests/fixtures/netstandard2.0/.gitkeep similarity index 100% rename from src/tests/fixtures/netstandard2.0/.gitkeep rename to tests/fixtures/netstandard2.0/.gitkeep diff --git a/src/tests/importtest.py b/tests/importtest.py similarity index 100% rename from src/tests/importtest.py rename to tests/importtest.py diff --git a/src/tests/leaktest.py b/tests/leaktest.py similarity index 100% rename from src/tests/leaktest.py rename to tests/leaktest.py diff --git a/src/tests/profile.py b/tests/profile.py similarity index 100% rename from src/tests/profile.py rename to tests/profile.py diff --git a/src/tests/runtests.py b/tests/runtests.py similarity index 100% rename from src/tests/runtests.py rename to tests/runtests.py diff --git a/src/tests/stress.py b/tests/stress.py similarity index 100% rename from src/tests/stress.py rename to tests/stress.py diff --git a/src/tests/stresstest.py b/tests/stresstest.py similarity index 100% rename from src/tests/stresstest.py rename to tests/stresstest.py diff --git a/src/tests/test_array.py b/tests/test_array.py similarity index 100% rename from src/tests/test_array.py rename to tests/test_array.py diff --git a/src/tests/test_callback.py b/tests/test_callback.py similarity index 100% rename from src/tests/test_callback.py rename to tests/test_callback.py diff --git a/src/tests/test_class.py b/tests/test_class.py similarity index 100% rename from src/tests/test_class.py rename to tests/test_class.py diff --git a/src/tests/test_clrmethod.py b/tests/test_clrmethod.py similarity index 100% rename from src/tests/test_clrmethod.py rename to tests/test_clrmethod.py diff --git a/src/tests/test_compat.py b/tests/test_compat.py similarity index 100% rename from src/tests/test_compat.py rename to tests/test_compat.py diff --git a/src/tests/test_constructors.py b/tests/test_constructors.py similarity index 100% rename from src/tests/test_constructors.py rename to tests/test_constructors.py diff --git a/src/tests/test_conversion.py b/tests/test_conversion.py similarity index 100% rename from src/tests/test_conversion.py rename to tests/test_conversion.py diff --git a/src/tests/test_delegate.py b/tests/test_delegate.py similarity index 100% rename from src/tests/test_delegate.py rename to tests/test_delegate.py diff --git a/src/tests/test_docstring.py b/tests/test_docstring.py similarity index 100% rename from src/tests/test_docstring.py rename to tests/test_docstring.py diff --git a/src/tests/test_engine.py b/tests/test_engine.py similarity index 100% rename from src/tests/test_engine.py rename to tests/test_engine.py diff --git a/src/tests/test_enum.py b/tests/test_enum.py similarity index 100% rename from src/tests/test_enum.py rename to tests/test_enum.py diff --git a/src/tests/test_event.py b/tests/test_event.py similarity index 100% rename from src/tests/test_event.py rename to tests/test_event.py diff --git a/src/tests/test_exceptions.py b/tests/test_exceptions.py similarity index 100% rename from src/tests/test_exceptions.py rename to tests/test_exceptions.py diff --git a/src/tests/test_field.py b/tests/test_field.py similarity index 100% rename from src/tests/test_field.py rename to tests/test_field.py diff --git a/src/tests/test_generic.py b/tests/test_generic.py similarity index 100% rename from src/tests/test_generic.py rename to tests/test_generic.py diff --git a/src/tests/test_import.py b/tests/test_import.py similarity index 100% rename from src/tests/test_import.py rename to tests/test_import.py diff --git a/src/tests/test_indexer.py b/tests/test_indexer.py similarity index 100% rename from src/tests/test_indexer.py rename to tests/test_indexer.py diff --git a/src/tests/test_interface.py b/tests/test_interface.py similarity index 100% rename from src/tests/test_interface.py rename to tests/test_interface.py diff --git a/src/tests/test_method.py b/tests/test_method.py similarity index 100% rename from src/tests/test_method.py rename to tests/test_method.py diff --git a/src/tests/test_module.py b/tests/test_module.py similarity index 100% rename from src/tests/test_module.py rename to tests/test_module.py diff --git a/src/tests/test_property.py b/tests/test_property.py similarity index 100% rename from src/tests/test_property.py rename to tests/test_property.py diff --git a/src/tests/test_recursive_types.py b/tests/test_recursive_types.py similarity index 100% rename from src/tests/test_recursive_types.py rename to tests/test_recursive_types.py diff --git a/src/tests/test_repr.py b/tests/test_repr.py similarity index 100% rename from src/tests/test_repr.py rename to tests/test_repr.py diff --git a/src/tests/test_subclass.py b/tests/test_subclass.py similarity index 100% rename from src/tests/test_subclass.py rename to tests/test_subclass.py diff --git a/src/tests/test_sysargv.py b/tests/test_sysargv.py similarity index 100% rename from src/tests/test_sysargv.py rename to tests/test_sysargv.py diff --git a/src/tests/test_thread.py b/tests/test_thread.py similarity index 100% rename from src/tests/test_thread.py rename to tests/test_thread.py diff --git a/src/tests/tests.pyproj b/tests/tests.pyproj similarity index 100% rename from src/tests/tests.pyproj rename to tests/tests.pyproj diff --git a/src/tests/utils.py b/tests/utils.py similarity index 100% rename from src/tests/utils.py rename to tests/utils.py diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 3c9be5c63..000000000 --- a/tox.ini +++ /dev/null @@ -1,27 +0,0 @@ -[tox] -skip_missing_interpreters=True -envlist = - py27 - py33 - py34 - py35 - py36 - py37 - check - -[testenv] -deps = - pytest -commands = - {posargs:py.test} - -[testenv:check] -ignore_errors=True -skip_install=True -basepython=python3.5 -deps = - check-manifest - flake8 -commands = - flake8 src setup.py - python setup.py check --strict --metadata