From 65d1eda707b0c5b948a55f7ec7d7384d032e65b1 Mon Sep 17 00:00:00 2001 From: dse Date: Thu, 29 Dec 2016 02:31:21 +0400 Subject: [PATCH] Cross compiled for NetStandard 1.5 and Net 4.6, + empty projects added. --- global.json | 6 +++ pythonnet.CoreCLR.sln | 16 +++++++ src/Python.Net/Properties/AssemblyInfo.cs | 19 ++++++++ src/Python.Net/Python.Net.xproj | 21 +++++++++ src/Python.Net/project.json | 21 +++++++++ .../Properties/AssemblyInfo.cs | 19 ++++++++ .../Python.Runtime.Contracts.xproj | 21 +++++++++ src/Python.Runtime.Contracts/project.json | 20 +++++++++ src/Python.Runtime/DelegateShim.cs | 30 +++++++++++++ src/Python.Runtime/arrayobject.cs | 2 +- src/Python.Runtime/assemblymanager.cs | 33 +++++++++++--- src/Python.Runtime/classbase.cs | 4 +- src/Python.Runtime/classderived.cs | 43 ++++++++----------- src/Python.Runtime/classmanager.cs | 14 +++--- src/Python.Runtime/classobject.cs | 8 ++-- src/Python.Runtime/codegenerator.cs | 2 +- src/Python.Runtime/constructorbinder.cs | 6 ++- src/Python.Runtime/converter.cs | 9 ++-- src/Python.Runtime/debughelper.cs | 4 +- src/Python.Runtime/delegatemanager.cs | 10 +++-- src/Python.Runtime/eventobject.cs | 8 ++-- src/Python.Runtime/indexer.cs | 3 +- src/Python.Runtime/interfaceobject.cs | 2 +- src/Python.Runtime/interop.cs | 17 ++++++-- src/Python.Runtime/methodbinder.cs | 8 +--- src/Python.Runtime/methodwrapper.cs | 2 + src/Python.Runtime/moduleobject.cs | 14 +++--- src/Python.Runtime/modulepropertyobject.cs | 3 +- src/Python.Runtime/nativecall.cs | 9 ++-- src/Python.Runtime/project.json | 26 ++++++++--- src/Python.Runtime/propertyobject.cs | 6 ++- src/Python.Runtime/pythonengine.cs | 2 +- src/Python.Runtime/runtime.cs | 11 +++-- src/Python.Runtime/typemanager.cs | 13 +++--- src/Python.Runtime/typemethod.cs | 3 +- src/console/assemblyinfo.cs | 4 ++ src/console/project.json | 19 ++++---- src/console/pythonconsole.cs | 10 ++++- src/embed_tests/project.json | 11 ++++- 39 files changed, 367 insertions(+), 112 deletions(-) create mode 100644 global.json create mode 100644 src/Python.Net/Properties/AssemblyInfo.cs create mode 100644 src/Python.Net/Python.Net.xproj create mode 100644 src/Python.Net/project.json create mode 100644 src/Python.Runtime.Contracts/Properties/AssemblyInfo.cs create mode 100644 src/Python.Runtime.Contracts/Python.Runtime.Contracts.xproj create mode 100644 src/Python.Runtime.Contracts/project.json create mode 100644 src/Python.Runtime/DelegateShim.cs diff --git a/global.json b/global.json new file mode 100644 index 000000000..2bc1df521 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "projects": ["src"], + "sdk": { + "version": "1.0.0-preview2-1-003177" + } +} \ No newline at end of file diff --git a/pythonnet.CoreCLR.sln b/pythonnet.CoreCLR.sln index 25916634c..858198448 100644 --- a/pythonnet.CoreCLR.sln +++ b/pythonnet.CoreCLR.sln @@ -9,6 +9,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Python.Runtime", "src\Pytho EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "embed_tests", "src\embed_tests\embed_tests.xproj", "{9F91A9DC-D7B3-45A9-96FF-57AACC1B959A}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Python.Runtime.Contracts", "src\Python.Runtime.Contracts\Python.Runtime.Contracts.xproj", "{3A75B887-30F2-4F42-B384-47F8D1E1DB65}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Python.Net", "src\Python.Net\Python.Net.xproj", "{F4E01C59-8951-451F-86F5-EF61CAAA786F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,6 +38,18 @@ Global {9F91A9DC-D7B3-45A9-96FF-57AACC1B959A}.Py35-UCS2-Win-Debug|Any CPU.Build.0 = Debug|Any CPU {9F91A9DC-D7B3-45A9-96FF-57AACC1B959A}.Release|Any CPU.ActiveCfg = Release|Any CPU {9F91A9DC-D7B3-45A9-96FF-57AACC1B959A}.Release|Any CPU.Build.0 = Release|Any CPU + {3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Py35-UCS2-Win-Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Py35-UCS2-Win-Debug|Any CPU.Build.0 = Debug|Any CPU + {3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Release|Any CPU.Build.0 = Release|Any CPU + {F4E01C59-8951-451F-86F5-EF61CAAA786F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F4E01C59-8951-451F-86F5-EF61CAAA786F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F4E01C59-8951-451F-86F5-EF61CAAA786F}.Py35-UCS2-Win-Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F4E01C59-8951-451F-86F5-EF61CAAA786F}.Py35-UCS2-Win-Debug|Any CPU.Build.0 = Debug|Any CPU + {F4E01C59-8951-451F-86F5-EF61CAAA786F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F4E01C59-8951-451F-86F5-EF61CAAA786F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Python.Net/Properties/AssemblyInfo.cs b/src/Python.Net/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f8e61da4f --- /dev/null +++ b/src/Python.Net/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +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("")] +[assembly: AssemblyProduct("Python.Net")] +[assembly: AssemblyTrademark("")] + +// 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)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f4e01c59-8951-451f-86f5-ef61caaa786f")] diff --git a/src/Python.Net/Python.Net.xproj b/src/Python.Net/Python.Net.xproj new file mode 100644 index 000000000..f116daec4 --- /dev/null +++ b/src/Python.Net/Python.Net.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + f4e01c59-8951-451f-86f5-ef61caaa786f + Python.Net + .\obj + .\bin\ + v4.5 + + + + 2.0 + + + diff --git a/src/Python.Net/project.json b/src/Python.Net/project.json new file mode 100644 index 000000000..a4804dfc7 --- /dev/null +++ b/src/Python.Net/project.json @@ -0,0 +1,21 @@ +{ + "version": "2.2.0-*", + + "dependencies": { + "NETStandard.Library": "1.6.0", + "Python.Runtime.Contracts": "2.2.0-*" + }, + + "frameworks": { + "netstandard1.5": { + "imports": "dnxcore50" + }, + "net46": { + + } + }, + "configurations": { + "Py35-UCS2-Win-Debug": { + } + } +} diff --git a/src/Python.Runtime.Contracts/Properties/AssemblyInfo.cs b/src/Python.Runtime.Contracts/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1e7499ee9 --- /dev/null +++ b/src/Python.Runtime.Contracts/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +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("")] +[assembly: AssemblyProduct("Python.Contracts")] +[assembly: AssemblyTrademark("")] + +// 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)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3a75b887-30f2-4f42-b384-47f8d1e1db65")] diff --git a/src/Python.Runtime.Contracts/Python.Runtime.Contracts.xproj b/src/Python.Runtime.Contracts/Python.Runtime.Contracts.xproj new file mode 100644 index 000000000..f729d380b --- /dev/null +++ b/src/Python.Runtime.Contracts/Python.Runtime.Contracts.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 3a75b887-30f2-4f42-b384-47f8d1e1db65 + Python.Contracts + .\obj + .\bin\ + v4.5 + + + + 2.0 + + + diff --git a/src/Python.Runtime.Contracts/project.json b/src/Python.Runtime.Contracts/project.json new file mode 100644 index 000000000..b03c1cc88 --- /dev/null +++ b/src/Python.Runtime.Contracts/project.json @@ -0,0 +1,20 @@ +{ + "version": "2.2.0-*", + + "dependencies": { + "NETStandard.Library": "1.6.0" + }, + + "frameworks": { + "netstandard1.5": { + "imports": "dnxcore50" + }, + "net46": { + + } + }, + "configurations": { + "Py35-UCS2-Win-Debug": { + } + } +} diff --git a/src/Python.Runtime/DelegateShim.cs b/src/Python.Runtime/DelegateShim.cs new file mode 100644 index 000000000..b10918d5e --- /dev/null +++ b/src/Python.Runtime/DelegateShim.cs @@ -0,0 +1,30 @@ +namespace Python.Runtime + { + using System; + using System.Linq; + using System.Reflection; + + public static class DelegateShim + { + public static Delegate CreateDelegate(Type dtype, object obj, string methodName) + { + if (obj == null) + { + throw new ArgumentNullException(nameof(obj)); + } + + var methods = obj.GetType().GetTypeInfo().GetMember(methodName, BindingFlags.Default); + if (!methods.Any()) + { + throw new InvalidOperationException("Method does not exist"); + } + + return CreateDelegate(dtype, (MethodInfo)methods[0]); + } + + internal static Delegate CreateDelegate(Type dtype, MethodInfo method) + { + return method.CreateDelegate(dtype); + } + } + } \ No newline at end of file diff --git a/src/Python.Runtime/arrayobject.cs b/src/Python.Runtime/arrayobject.cs index 2fe433e57..1344240e4 100644 --- a/src/Python.Runtime/arrayobject.cs +++ b/src/Python.Runtime/arrayobject.cs @@ -150,7 +150,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) int index = 0; object value; - if (items.IsReadOnly) + if (((IList)items).IsReadOnly) { Exceptions.RaiseTypeError("array is read-only"); return -1; diff --git a/src/Python.Runtime/assemblymanager.cs b/src/Python.Runtime/assemblymanager.cs index 5d9759375..87949793f 100644 --- a/src/Python.Runtime/assemblymanager.cs +++ b/src/Python.Runtime/assemblymanager.cs @@ -6,9 +6,14 @@ using System.Diagnostics; using System.Reflection; using System.Threading; +using ReflectionBridge.Extensions; +#if !NET46 +using System.Runtime.Loader; +#endif namespace Python.Runtime { + /// /// The AssemblyManager maintains information about loaded assemblies /// namespaces and provides an interface for name-based type lookup. @@ -19,7 +24,9 @@ internal class AssemblyManager // therefore this should be a ConcurrentDictionary static ConcurrentDictionary> namespaces; //static Dictionary> generics; +#if NET46 static AssemblyLoadEventHandler lhandler; +#endif static ResolveEventHandler rhandler; // updated only under GIL? static Dictionary probed; @@ -47,14 +54,15 @@ internal static void Initialize() pypath = new List(16); AppDomain domain = AppDomain.CurrentDomain; - +#if NET46 lhandler = new AssemblyLoadEventHandler(AssemblyLoadHandler); domain.AssemblyLoad += lhandler; - +#endif rhandler = new ResolveEventHandler(ResolveHandler); domain.AssemblyResolve += rhandler; Assembly[] items = domain.GetAssemblies(); + foreach (var a in items) { try @@ -77,11 +85,13 @@ internal static void Initialize() internal static void Shutdown() { AppDomain domain = AppDomain.CurrentDomain; +#if NET46 domain.AssemblyLoad -= lhandler; +#endif domain.AssemblyResolve -= rhandler; } - +#if NET46 //=================================================================== // Event handler for assembly load events. At the time the Python // runtime loads, we scan the app domain to map the assemblies that @@ -96,7 +106,7 @@ static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args) assemblies.Add(assembly); ScanAssembly(assembly); } - +#endif //=================================================================== // Event handler for assembly resolve events. This is needed because @@ -120,7 +130,6 @@ static Assembly ResolveHandler(Object ob, ResolveEventArgs args) return LoadAssemblyPath(args.Name); } - //=================================================================== // We __really__ want to avoid using Python objects or APIs when // probing for assemblies to load, since our ResolveHandler may be @@ -204,7 +213,11 @@ public static Assembly LoadAssembly(string name) Assembly assembly = null; try { +#if NET46 assembly = Assembly.Load(name); +#else + assembly = Assembly.Load(new AssemblyName(name)); +#endif } catch (System.Exception e) { @@ -228,7 +241,11 @@ public static Assembly LoadAssemblyPath(string name) { try { +#if NET46 assembly = Assembly.LoadFrom(path); +#else + assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(path); +#endif } catch { @@ -253,7 +270,11 @@ public static Assembly LoadAssemblyFullPath(string name) { try { +#if NET46 assembly = Assembly.LoadFrom(name); +#else + assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(name); +#endif } catch { @@ -373,7 +394,7 @@ internal static void ScanAssembly(Assembly assembly) namespaces[ns].TryAdd(assembly, String.Empty); } - if (ns != null && t.IsGenericTypeDefinition) + if (ns != null && t.GetTypeInfo().IsGenericTypeDefinition) { GenericUtil.Register(t); } diff --git a/src/Python.Runtime/classbase.cs b/src/Python.Runtime/classbase.cs index 3089465e3..83ce39a1c 100644 --- a/src/Python.Runtime/classbase.cs +++ b/src/Python.Runtime/classbase.cs @@ -3,9 +3,11 @@ using System.Reflection; using System.Security; using System.Runtime.InteropServices; +using ReflectionBridge.Extensions; namespace Python.Runtime { + /// /// Base class for Python types that reflect managed types / classes. /// Concrete subclasses include ClassObject and DelegateObject. This @@ -27,7 +29,7 @@ internal ClassBase(Type tp) : base() internal virtual bool CanSubclass() { - return (!this.type.IsEnum); + return (!this.type.IsEnum()); } //==================================================================== diff --git a/src/Python.Runtime/classderived.cs b/src/Python.Runtime/classderived.cs index 6a35d5497..1eeb7b531 100644 --- a/src/Python.Runtime/classderived.cs +++ b/src/Python.Runtime/classderived.cs @@ -7,9 +7,11 @@ using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; +using ReflectionBridge.Extensions; namespace Python.Runtime { + /// /// Managed class that provides the implementation for reflected types. /// Managed classes and value types are represented in Python by actual @@ -118,7 +120,7 @@ internal static Type CreateDerivedType(string name, name = namespaceStr + "." + name; if (null == assemblyName) - assemblyName = Assembly.GetExecutingAssembly().FullName; + assemblyName = Assembly.GetEntryAssembly().FullName; ModuleBuilder moduleBuilder = GetModuleBuilder(assemblyName, moduleName); TypeBuilder typeBuilder; @@ -128,7 +130,7 @@ internal static Type CreateDerivedType(string name, // if the base type is an interface then use System.Object as the base class // and add the base type to the list of interfaces this new class will implement. - if (baseType.IsInterface) + if (baseType.IsInterface()) { interfaces.Add(baseType); baseClass = typeof(System.Object); @@ -173,7 +175,7 @@ internal static Type CreateDerivedType(string name, } // override any virtual methods not already overriden by the properties above - MethodInfo[] methods = baseType.GetMethods(); + MethodInfo[] methods = ReflectionBridgeExtensions.GetMethods(baseType).ToArray(); HashSet virtualMethods = new HashSet(); foreach (MethodInfo method in methods) { @@ -233,15 +235,15 @@ internal static Type CreateDerivedType(string name, il.Emit(OpCodes.Call, baseClass.GetMethod("Finalize", BindingFlags.NonPublic | BindingFlags.Instance)); il.Emit(OpCodes.Ret); - Type type = typeBuilder.CreateType(); + TypeInfo type = typeBuilder.CreateTypeInfo(); // scan the assembly so the newly added class can be imported - Assembly assembly = Assembly.GetAssembly(type); + Assembly assembly = type.Assembly; AssemblyManager.ScanAssembly(assembly); AssemblyBuilder assemblyBuilder = assemblyBuilders[assemblyName]; - return type; + return type.GetType(); } /// @@ -290,7 +292,7 @@ private static void AddConstructor(ConstructorInfo ctor, Type baseType, TypeBuil il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Ldc_I4, i); il.Emit(OpCodes.Ldarg, i + 1); - if (parameterTypes[i].IsValueType) + if (parameterTypes[i].IsValueType()) il.Emit(OpCodes.Box, parameterTypes[i]); il.Emit(OpCodes.Stelem, typeof(Object)); } @@ -360,7 +362,7 @@ private static void AddVirtualMethod(MethodInfo method, Type baseType, TypeBuild il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Ldc_I4, i); il.Emit(OpCodes.Ldarg, i + 1); - if (parameterTypes[i].IsValueType) + if (parameterTypes[i].IsValueType()) il.Emit(OpCodes.Box, parameterTypes[i]); il.Emit(OpCodes.Stelem, typeof(Object)); } @@ -437,7 +439,7 @@ private static void AddPythonMethod(string methodName, PyObject func, TypeBuilde il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Ldc_I4, i); il.Emit(OpCodes.Ldarg, i + 1); - if (argTypes[i].IsValueType) + if (argTypes[i].IsValueType()) il.Emit(OpCodes.Box, argTypes[i]); il.Emit(OpCodes.Stelem, typeof(Object)); } @@ -546,8 +548,13 @@ private static ModuleBuilder GetModuleBuilder(string assemblyName, string module } else { +#if NET46 assemblyBuilder = domain.DefineDynamicAssembly(new AssemblyName(assemblyName), AssemblyBuilderAccess.Run); +#else + assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(assemblyName), + AssemblyBuilderAccess.Run); +#endif assemblyBuilders[assemblyName] = assemblyBuilder; } @@ -631,11 +638,7 @@ public static T InvokeMethod(IPythonDerivedType obj, string methodName, strin if (origMethodName == null) throw new NotImplementedException("Python object does not have a '" + methodName + "' method"); - return (T)obj.GetType().InvokeMember(origMethodName, - BindingFlags.InvokeMethod, - null, - obj, - args); + return (T)obj.GetType().GetMethods(BindingFlags.InvokeMethod)[0].Invoke(obj, args); } public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, string origMethodName, @@ -692,11 +695,7 @@ public static void InvokeMethodVoid(IPythonDerivedType obj, string methodName, s if (origMethodName == null) throw new NotImplementedException("Python object does not have a '" + methodName + "' method"); - obj.GetType().InvokeMember(origMethodName, - BindingFlags.InvokeMethod, - null, - obj, - args); + obj.GetType().GetMethods(BindingFlags.InvokeMethod)[0].Invoke(obj, args); } public static T InvokeGetProperty(IPythonDerivedType obj, string propertyName) @@ -746,11 +745,7 @@ public static void InvokeSetProperty(IPythonDerivedType obj, string propertyN public static void InvokeCtor(IPythonDerivedType obj, string origCtorName, Object[] args) { // call the base constructor - obj.GetType().InvokeMember(origCtorName, - BindingFlags.InvokeMethod, - null, - obj, - args); + obj.GetType().GetMethods(BindingFlags.InvokeMethod)[0].Invoke(obj, args); List disposeList = new List(); CLRObject self = null; diff --git a/src/Python.Runtime/classmanager.cs b/src/Python.Runtime/classmanager.cs index 52fecf39c..cb09bda21 100644 --- a/src/Python.Runtime/classmanager.cs +++ b/src/Python.Runtime/classmanager.cs @@ -4,9 +4,11 @@ using System.Collections; using System.Reflection; using System.Security; +using ReflectionBridge.Extensions; namespace Python.Runtime { + /// /// The ClassManager is responsible for creating and managing instances /// that implement the Python type objects that reflect managed classes. @@ -75,7 +77,7 @@ private static ClassBase CreateClass(Type type) // lets us check once (vs. on every lookup) in case we need to // wrap Exception-derived types in old-style classes - if (type.ContainsGenericParameters) + if (type.GetTypeInfo().ContainsGenericParameters) { impl = new GenericType(type); } @@ -90,7 +92,7 @@ private static ClassBase CreateClass(Type type) impl = new ArrayObject(type); } - else if (type.IsInterface) + else if (type.IsInterface()) { impl = new InterfaceObject(type); } @@ -241,7 +243,7 @@ private static ClassInfo GetClassInfo(Type type) } } - if (type.IsInterface) + if (type.IsInterface()) { // Interface inheritance seems to be a different animal: // more contractual, less structural. Thus, a Type that @@ -355,9 +357,9 @@ private static ClassInfo GetClassInfo(Type type) continue; case MemberTypes.NestedType: - tp = (Type)mi; - if (!(tp.IsNestedPublic || tp.IsNestedFamily || - tp.IsNestedFamORAssem)) + tp = ((TypeInfo)mi).AsType(); + if (!(tp.IsNestedPublic() || tp.GetTypeInfo().IsNestedFamily || + tp.GetTypeInfo().IsNestedFamORAssem)) continue; // Note the given instance might be uninitialized ob = ClassManager.GetClass(tp); diff --git a/src/Python.Runtime/classobject.cs b/src/Python.Runtime/classobject.cs index bd4702c20..68afa59ef 100644 --- a/src/Python.Runtime/classobject.cs +++ b/src/Python.Runtime/classobject.cs @@ -1,8 +1,10 @@ using System; using System.Reflection; +using ReflectionBridge.Extensions; namespace Python.Runtime { + /// /// Managed class that provides the implementation for reflected types. /// Managed classes and value types are represented in Python by actual @@ -67,7 +69,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) // they do from Python. If the ClassObject represents one of the // convertible primitive types, just convert the arg directly. - if (type.IsPrimitive || type == typeof(String)) + if (type.IsPrimitive() || type == typeof(String)) { if (Runtime.PyTuple_Size(args) != 1) { @@ -88,7 +90,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) return CLRObject.GetInstHandle(result, tp); } - if (type.IsAbstract) + if (type.IsAbstract()) { Exceptions.SetError(Exceptions.TypeError, "cannot instantiate abstract class" @@ -96,7 +98,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) return IntPtr.Zero; } - if (type.IsEnum) + if (type.IsEnum()) { Exceptions.SetError(Exceptions.TypeError, "cannot instantiate enumeration" diff --git a/src/Python.Runtime/codegenerator.cs b/src/Python.Runtime/codegenerator.cs index 01edd79ba..b283689fc 100644 --- a/src/Python.Runtime/codegenerator.cs +++ b/src/Python.Runtime/codegenerator.cs @@ -25,7 +25,7 @@ internal CodeGenerator() aname.Name = "__CodeGenerator_Assembly"; AssemblyBuilderAccess aa = AssemblyBuilderAccess.Run; - aBuilder = Thread.GetDomain().DefineDynamicAssembly(aname, aa); + aBuilder = AssemblyBuilder.DefineDynamicAssembly(aname, aa); mBuilder = aBuilder.DefineDynamicModule("__CodeGenerator_Module"); } diff --git a/src/Python.Runtime/constructorbinder.cs b/src/Python.Runtime/constructorbinder.cs index 7ea7602b8..8362d0b4f 100644 --- a/src/Python.Runtime/constructorbinder.cs +++ b/src/Python.Runtime/constructorbinder.cs @@ -1,8 +1,10 @@ using System; using System.Reflection; +using ReflectionBridge.Extensions; namespace Python.Runtime { + //======================================================================== // A ConstructorBinder encapsulates information about one or more managed // constructors, and is responsible for selecting the right constructor @@ -54,8 +56,8 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, { Object result; - if (_containingType.IsValueType && !_containingType.IsPrimitive && - !_containingType.IsEnum && _containingType != typeof(decimal) && + if (_containingType.IsValueType() && !_containingType.IsPrimitive() && + !_containingType.IsEnum() && _containingType != typeof(decimal) && Runtime.PyTuple_Size(args) == 0) { // If you are trying to construct an instance of a struct by diff --git a/src/Python.Runtime/converter.cs b/src/Python.Runtime/converter.cs index 1170efe7a..74a14d27c 100644 --- a/src/Python.Runtime/converter.cs +++ b/src/Python.Runtime/converter.cs @@ -4,14 +4,17 @@ using System.Globalization; using System.Security; using System.Collections; +using ReflectionBridge.Extensions; namespace Python.Runtime { + //======================================================================== // Performs data conversions between managed types and Python types. //======================================================================== - +#if NET46 [SuppressUnmanagedCodeSecurityAttribute()] +#endif internal class Converter { private Converter() @@ -307,7 +310,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType, return false; } - if (value == Runtime.PyNone && !obType.IsValueType) + if (value == Runtime.PyNone && !obType.IsValueType()) { result = null; return true; @@ -318,7 +321,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType, return ToArray(value, obType, out result, setError); } - if (obType.IsEnum) + if (obType.IsEnum()) { return ToEnum(value, obType, out result, setError); } diff --git a/src/Python.Runtime/debughelper.cs b/src/Python.Runtime/debughelper.cs index d65300e39..97ecacc12 100644 --- a/src/Python.Runtime/debughelper.cs +++ b/src/Python.Runtime/debughelper.cs @@ -107,8 +107,8 @@ internal static void DumpInst(IntPtr ob) [Conditional("DEBUG")] internal static void debug(string msg) { - StackTrace st = new StackTrace(1, true); - StackFrame sf = st.GetFrame(0); + StackTrace st = new StackTrace(new Exception(msg), true); + StackFrame sf = st.GetFrames()[0]; MethodBase mb = sf.GetMethod(); Type mt = mb.DeclaringType; string caller = mt.Name + "." + sf.GetMethod().Name; diff --git a/src/Python.Runtime/delegatemanager.cs b/src/Python.Runtime/delegatemanager.cs index 1e652214b..ae42f9a41 100644 --- a/src/Python.Runtime/delegatemanager.cs +++ b/src/Python.Runtime/delegatemanager.cs @@ -5,9 +5,11 @@ using System.Collections; using System.Reflection; using System.Reflection.Emit; +using ReflectionBridge.Extensions; namespace Python.Runtime { + /// /// The DelegateManager class manages the creation of true managed /// delegate instances that dispatch calls to Python methods. @@ -130,7 +132,7 @@ private Type GetDispatcher(Type dtype) il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Ldarg_S, (byte)(c + 1)); - if (t.IsValueType) + if (t.IsValueType()) { il.Emit(OpCodes.Box, t); } @@ -147,14 +149,14 @@ private Type GetDispatcher(Type dtype) { il.Emit(OpCodes.Pop); } - else if (method.ReturnType.IsValueType) + else if (method.ReturnType.IsValueType()) { il.Emit(OpCodes.Unbox_Any, method.ReturnType); } il.Emit(OpCodes.Ret); - Type disp = tb.CreateType(); + Type disp = tb.CreateTypeInfo().AsType(); cache[dtype] = disp; return disp; } @@ -170,7 +172,7 @@ internal Delegate GetDelegate(Type dtype, IntPtr callable) Type dispatcher = GetDispatcher(dtype); object[] args = { callable, dtype }; object o = Activator.CreateInstance(dispatcher, args); - return Delegate.CreateDelegate(dtype, o, "Invoke"); + return DelegateShim.CreateDelegate(dtype, o, "Invoke"); } } diff --git a/src/Python.Runtime/eventobject.cs b/src/Python.Runtime/eventobject.cs index 6523f7e20..87bc17c77 100644 --- a/src/Python.Runtime/eventobject.cs +++ b/src/Python.Runtime/eventobject.cs @@ -51,7 +51,7 @@ internal bool AddEventHandler(IntPtr target, IntPtr handler) { reg = new Hashtable(); } - object key = (obj != null) ? obj : this.info.ReflectedType; + object key = (obj != null) ? obj : this.info.DeclaringType; ArrayList list = reg[key] as ArrayList; if (list == null) { @@ -65,7 +65,7 @@ internal bool AddEventHandler(IntPtr target, IntPtr handler) object[] args = { d }; MethodInfo mi = this.info.GetAddMethod(true); - mi.Invoke(obj, BindingFlags.Default, null, args, null); + mi.Invoke(obj, args); return true; } @@ -93,7 +93,7 @@ internal bool RemoveEventHandler(IntPtr target, IntPtr handler) return false; } - object key = (obj != null) ? obj : this.info.ReflectedType; + object key = (obj != null) ? obj : this.info.DeclaringType; ArrayList list = reg[key] as ArrayList; if (list == null) @@ -117,7 +117,7 @@ internal bool RemoveEventHandler(IntPtr target, IntPtr handler) args[0] = item.del; try { - mi.Invoke(obj, BindingFlags.Default, null, args, null); + mi.Invoke(obj, args); } catch { diff --git a/src/Python.Runtime/indexer.cs b/src/Python.Runtime/indexer.cs index 86e290d5b..6b2cb86cd 100644 --- a/src/Python.Runtime/indexer.cs +++ b/src/Python.Runtime/indexer.cs @@ -1,8 +1,9 @@ using System; using System.Collections; using System.Reflection; +#if NET46 using System.Security.Permissions; - +#endif namespace Python.Runtime { //======================================================================== diff --git a/src/Python.Runtime/interfaceobject.cs b/src/Python.Runtime/interfaceobject.cs index f550a95a8..aa0ac2785 100644 --- a/src/Python.Runtime/interfaceobject.cs +++ b/src/Python.Runtime/interfaceobject.cs @@ -17,7 +17,7 @@ internal class InterfaceObject : ClassBase internal InterfaceObject(Type tp) : base(tp) { CoClassAttribute coclass = (CoClassAttribute) - Attribute.GetCustomAttribute(tp, cc_attr); + tp.GetTypeInfo().GetCustomAttribute(cc_attr); if (coclass != null) { ctor = coclass.CoClass.GetConstructor(Type.EmptyTypes); diff --git a/src/Python.Runtime/interop.cs b/src/Python.Runtime/interop.cs index 7288ff58c..60d3cd185 100644 --- a/src/Python.Runtime/interop.cs +++ b/src/Python.Runtime/interop.cs @@ -12,8 +12,9 @@ namespace Python.Runtime // runtime. Generally, the definitions here need to be kept up to date // when moving to new Python versions. //======================================================================= - +#if NET46 [Serializable()] +#endif [AttributeUsage(AttributeTargets.All)] public class DocStringAttribute : Attribute { @@ -31,7 +32,9 @@ public string DocString private string docStr; } +#if NET46 [Serializable()] +#endif [AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate)] internal class PythonMethodAttribute : Attribute { @@ -40,7 +43,9 @@ public PythonMethodAttribute() } } +#if NET46 [Serializable()] +#endif [AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate)] internal class ModuleFunctionAttribute : Attribute { @@ -49,7 +54,9 @@ public ModuleFunctionAttribute() } } +#if NET46 [Serializable()] +#endif [AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate)] internal class ForbidPythonThreadsAttribute : Attribute { @@ -59,7 +66,9 @@ public ForbidPythonThreadsAttribute() } +#if NET46 [Serializable()] +#endif [AttributeUsage(AttributeTargets.Property)] internal class ModulePropertyAttribute : Attribute { @@ -354,7 +363,7 @@ static Interop() // Here we build a mapping of PyTypeObject slot names to the // appropriate prototype (delegate) type to use for the slot. - Type[] items = typeof(Interop).GetNestedTypes(); + Type[] items = typeof(Interop).GetTypeInfo().GetNestedTypes(); Hashtable p = new Hashtable(); for (int i = 0; i < items.Length; i++) @@ -467,14 +476,14 @@ internal static IntPtr GetThunk(MethodInfo method, string funcType = null) { Type dt; if (funcType != null) - dt = typeof(Interop).GetNestedType(funcType) as Type; + dt = typeof(Interop).GetTypeInfo().GetNestedType(funcType) as Type; else dt = GetPrototype(method.Name); if (dt != null) { IntPtr tmp = Marshal.AllocHGlobal(IntPtr.Size); - Delegate d = Delegate.CreateDelegate(dt, method); + Delegate d = DelegateShim.CreateDelegate(dt, method); Thunk cb = new Thunk(d); Marshal.StructureToPtr(cb, tmp, false); IntPtr fp = Marshal.ReadIntPtr(tmp, 0); diff --git a/src/Python.Runtime/methodbinder.cs b/src/Python.Runtime/methodbinder.cs index c3b3e4a70..cf5ce1946 100644 --- a/src/Python.Runtime/methodbinder.cs +++ b/src/Python.Runtime/methodbinder.cs @@ -296,7 +296,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, } } else if ((pynargs > clrnargs) && (clrnargs > 0) && - Attribute.IsDefined(pi[clrnargs - 1], typeof(ParamArrayAttribute))) + pi[clrnargs - 1].IsDefined(typeof(ParamArrayAttribute))) { // This is a spam(params object[] egg) style method match = true; @@ -489,11 +489,7 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, try { - result = binding.info.Invoke(binding.inst, - BindingFlags.Default, - null, - binding.args, - null); + result = binding.info.Invoke(binding.inst, binding.args); } catch (Exception e) { diff --git a/src/Python.Runtime/methodwrapper.cs b/src/Python.Runtime/methodwrapper.cs index 53c0a3cc9..44fa9e225 100644 --- a/src/Python.Runtime/methodwrapper.cs +++ b/src/Python.Runtime/methodwrapper.cs @@ -1,9 +1,11 @@ using System; using System.Collections; using System.Runtime.InteropServices; +using System.Reflection; namespace Python.Runtime { + /// /// A MethodWrapper wraps a static method of a managed type, /// making it callable by Python as a PyCFunction object. This is diff --git a/src/Python.Runtime/moduleobject.cs b/src/Python.Runtime/moduleobject.cs index 87e3ed2f1..eef530c83 100644 --- a/src/Python.Runtime/moduleobject.cs +++ b/src/Python.Runtime/moduleobject.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.Collections; using System.Reflection; +using ReflectionBridge.Extensions; +using System.Linq; namespace Python.Runtime { @@ -113,7 +115,7 @@ public ManagedType GetAttribute(string name, bool guess) type = AssemblyManager.LookupType(qname); if (type != null) { - if (!type.IsPublic) + if (!type.IsPublic()) { return null; } @@ -139,7 +141,7 @@ public ManagedType GetAttribute(string name, bool guess) type = AssemblyManager.LookupType(qname); if (type != null) { - if (!type.IsPublic) + if (!type.IsPublic()) { return null; } @@ -224,8 +226,8 @@ internal void InitializeModuleMembers() for (int i = 0; i < methods.Length; i++) { MethodInfo method = methods[i]; - object[] attrs = method.GetCustomAttributes(funcmarker, false); - object[] forbid = method.GetCustomAttributes(ftmarker, false); + object[] attrs = method.GetCustomAttributes(funcmarker, false).ToArray(); + object[] forbid = method.GetCustomAttributes(ftmarker, false).ToArray(); bool allow_threads = (forbid.Length == 0); if (attrs.Length > 0) { @@ -241,7 +243,7 @@ internal void InitializeModuleMembers() for (int i = 0; i < properties.Length; i++) { PropertyInfo property = properties[i]; - object[] attrs = property.GetCustomAttributes(propmarker, false); + object[] attrs = property.GetCustomAttributes(propmarker, false).ToArray(); if (attrs.Length > 0) { string name = property.Name; @@ -249,7 +251,7 @@ internal void InitializeModuleMembers() StoreAttribute(name, p); } } - type = type.BaseType; + type = type.BaseType(); } } diff --git a/src/Python.Runtime/modulepropertyobject.cs b/src/Python.Runtime/modulepropertyobject.cs index 1f67f89ec..432195dab 100644 --- a/src/Python.Runtime/modulepropertyobject.cs +++ b/src/Python.Runtime/modulepropertyobject.cs @@ -1,8 +1,9 @@ using System; using System.Collections; using System.Reflection; +#if NET46 using System.Security.Permissions; - +#endif namespace Python.Runtime { /// diff --git a/src/Python.Runtime/nativecall.cs b/src/Python.Runtime/nativecall.cs index a37729ab2..f0154f60e 100644 --- a/src/Python.Runtime/nativecall.cs +++ b/src/Python.Runtime/nativecall.cs @@ -44,7 +44,7 @@ static NativeCall() aname.Name = "e__NativeCall_Assembly"; AssemblyBuilderAccess aa = AssemblyBuilderAccess.Run; - aBuilder = Thread.GetDomain().DefineDynamicAssembly(aname, aa); + aBuilder = AssemblyBuilder.DefineDynamicAssembly(aname, aa); mBuilder = aBuilder.DefineDynamicModule("e__NativeCall_Module"); TypeAttributes ta = TypeAttributes.Public; @@ -61,7 +61,7 @@ static NativeCall() GenerateThunk(tBuilder, method); } - Type theType = tBuilder.CreateType(); + Type theType = tBuilder.CreateTypeInfo().AsType(); Impl = (INativeCall)Activator.CreateInstance(theType); } @@ -110,10 +110,11 @@ private static void GenerateThunk(TypeBuilder tb, MethodInfo method) il.Emit(OpCodes.Ldarg_1); + //add null 5th arg il.EmitCalli(OpCodes.Calli, - CallingConvention.Cdecl, + System.Reflection.CallingConventions.ExplicitThis, //was cdecl method.ReturnType, - nargs + nargs, null ); il.Emit(OpCodes.Ret); diff --git a/src/Python.Runtime/project.json b/src/Python.Runtime/project.json index bb07458af..5c692aba0 100644 --- a/src/Python.Runtime/project.json +++ b/src/Python.Runtime/project.json @@ -1,5 +1,5 @@ -{ - "version": "0.1.0-*", +{ + "version": "2.2.0-*", "buildOptions": { "compile": { @@ -13,14 +13,26 @@ } }, "dependencies": { - "NETStandard.Library": "1.6.0" + "NETStandard.Library": "1.6.0", + "ReflectionBridge": "0.0.11", + "Python.Runtime.Contracts": "2.2.0-*", + "System.Collections.NonGeneric": "4.0.1", + "System.Data.Common": "4.1.0", + "System.Threading.Thread": "4.0.0", + "System.Diagnostics.StackTrace": "4.0.1" }, "frameworks": { - //"netstandard1.3": { - // "imports": "dnxcore50" - //}, + "netstandard1.5": { + "imports": "dnxcore50", + "dependencies": { + "System.AppDomain": "2.0.11", + "System.Runtime.Loader": "4.0.0", + "System.Reflection.Emit": "4.0.1", + "System.Dynamic.Runtime": "4.0.11", + "System.Reflection.TypeExtensions": "4.1.0" + } + }, "net46": { - } }, "configurations": { diff --git a/src/Python.Runtime/propertyobject.cs b/src/Python.Runtime/propertyobject.cs index 5bbf94d1a..5ecb68ac1 100644 --- a/src/Python.Runtime/propertyobject.cs +++ b/src/Python.Runtime/propertyobject.cs @@ -1,8 +1,9 @@ using System; using System.Collections; using System.Reflection; +#if NET46 using System.Security.Permissions; - +#endif namespace Python.Runtime { //======================================================================== @@ -14,8 +15,9 @@ internal class PropertyObject : ExtensionType PropertyInfo info; MethodInfo getter; MethodInfo setter; - +#if NET46 [StrongNameIdentityPermissionAttribute(SecurityAction.Assert)] +#endif public PropertyObject(PropertyInfo md) : base() { getter = md.GetGetMethod(true); diff --git a/src/Python.Runtime/pythonengine.cs b/src/Python.Runtime/pythonengine.cs index 504cbf167..78d3be87a 100644 --- a/src/Python.Runtime/pythonengine.cs +++ b/src/Python.Runtime/pythonengine.cs @@ -148,7 +148,7 @@ public static void Initialize() IntPtr builtins = Runtime.PyEval_GetBuiltins(); Runtime.PyDict_SetItemString(module_globals, "__builtins__", builtins); - var assembly = Assembly.GetExecutingAssembly(); + var assembly = Assembly.GetEntryAssembly(); using (Stream stream = assembly.GetManifestResourceStream("Python.Runtime.resources.clr.py")) using (StreamReader reader = new StreamReader(stream)) { diff --git a/src/Python.Runtime/runtime.cs b/src/Python.Runtime/runtime.cs index 7f5123012..2557d1d93 100644 --- a/src/Python.Runtime/runtime.cs +++ b/src/Python.Runtime/runtime.cs @@ -1,6 +1,8 @@ using System; using System.Runtime.InteropServices; using System.Security; +using ReflectionBridge.Extensions; + #if (UCS4) using System.Text; using Mono.Unix; @@ -13,7 +15,10 @@ namespace Python.Runtime { + +#if NET46 [SuppressUnmanagedCodeSecurityAttribute()] +#endif static class NativeMethods { #if (MONO_LINUX || MONO_OSX) @@ -99,7 +104,7 @@ public class Runtime #if (UCS2) public const int UCS = 2; #endif -#if ! (UCS2 || UCS4) +#if !(UCS2 || UCS4) #error You must define either UCS2 or UCS4! #endif @@ -139,7 +144,7 @@ public class Runtime public const string pyversion = "3.5"; public const int pyversionnumber = 35; #endif -#if ! (PYTHON23 || PYTHON24 || PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35) +#if !(PYTHON23 || PYTHON24 || PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35) #error You must define one of PYTHON23 to PYTHON35 #endif @@ -346,7 +351,7 @@ internal static void 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(); + string rtdir = typeof(string).GetAssembly().Location; IntPtr path = Runtime.PySys_GetObject("path"); IntPtr item = Runtime.PyString_FromString(rtdir); Runtime.PyList_Append(path, item); diff --git a/src/Python.Runtime/typemanager.cs b/src/Python.Runtime/typemanager.cs index ecac9203c..c6966c9eb 100644 --- a/src/Python.Runtime/typemanager.cs +++ b/src/Python.Runtime/typemanager.cs @@ -5,9 +5,12 @@ using System.Collections; using System.Reflection; using System.Threading; +using ReflectionBridge.Extensions; namespace Python.Runtime { + using System.Linq; + //======================================================================= // The TypeManager class is responsible for building binary-compatible // Python type objects that are implemented in managed code. @@ -138,9 +141,9 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType) { base_ = Exceptions.Exception; } - else if (clrType.BaseType != null) + else if (clrType.BaseType() != null) { - ClassBase bc = ClassManager.GetClass(clrType.BaseType); + ClassBase bc = ClassManager.GetClass(clrType.BaseType()); base_ = bc.pyHandle; } @@ -490,7 +493,7 @@ internal static void InitializeSlots(IntPtr type, Type impl) seen[name] = 1; } - impl = impl.BaseType; + impl = impl.BaseType(); } } @@ -517,7 +520,7 @@ private static void InitMethods(IntPtr pytype, Type type) MethodInfo method = methods[i]; if (!addedMethods.Contains(method.Name)) { - object[] attrs = method.GetCustomAttributes(marker, false); + object[] attrs = method.GetCustomAttributes(marker, false).ToArray(); if (attrs.Length > 0) { string method_name = method.Name; @@ -529,7 +532,7 @@ private static void InitMethods(IntPtr pytype, Type type) } } } - type = type.BaseType; + type = type.BaseType(); } } diff --git a/src/Python.Runtime/typemethod.cs b/src/Python.Runtime/typemethod.cs index 4e46da2da..eba0c2731 100644 --- a/src/Python.Runtime/typemethod.cs +++ b/src/Python.Runtime/typemethod.cs @@ -35,8 +35,7 @@ public override IntPtr Invoke(IntPtr ob, IntPtr args, IntPtr kw) { inst = GetManagedObject(ob); } - return (IntPtr)mi.Invoke(inst, BindingFlags.Default, null, arglist, - null); + return (IntPtr)mi.Invoke(inst, arglist); } catch (Exception e) { diff --git a/src/console/assemblyinfo.cs b/src/console/assemblyinfo.cs index 51a280e7a..935851bc4 100644 --- a/src/console/assemblyinfo.cs +++ b/src/console/assemblyinfo.cs @@ -1,6 +1,8 @@ using System; using System.Reflection; +#if NET46 using System.Security.Permissions; +#endif using System.Runtime.InteropServices; using System.Resources; @@ -10,8 +12,10 @@ [assembly: AssemblyDefaultAliasAttribute("python.exe")] [assembly: CLSCompliant(true)] [assembly: ComVisible(false)] +#if NET46 [assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, Name = "FullTrust")] +#endif [assembly: AssemblyDescriptionAttribute("")] [assembly: AssemblyCopyrightAttribute("Zope Public License, Version 2.0 (ZPL)")] [assembly: AssemblyFileVersionAttribute("2.0.0.4")] diff --git a/src/console/project.json b/src/console/project.json index 2ba1c946d..ebf05d7a5 100644 --- a/src/console/project.json +++ b/src/console/project.json @@ -1,27 +1,30 @@ { - "version": "0.1.0-*", + "version": "2.2.0-*", "buildOptions": { "emitEntryPoint": true }, "runtimes": { - "win7-x64": {} + "win7-x64": {}, + "ubuntu.16.04-x64": {} }, "dependencies": { "NETStandard.Library": "1.6.0", - "Python.Runtime": "0.1.0-*" + "Python.Runtime": "2.2.0-*" }, "frameworks": { - //"netstandard1.6": { - // "imports": "dnxcore50" - //}, + "netcoreapp1.1": { + "imports": "dnxcore50", + "dependencies": { + "System.Runtime.Loader": "4.0.0" + } + }, "net46": { - } }, "configurations": { "Py35-UCS2-Win-Debug": { "buildOptions": { - "define": [ "TRACE", "DEBUG"] + "define": [ "TRACE", "DEBUG" ] } } } diff --git a/src/console/pythonconsole.cs b/src/console/pythonconsole.cs index c97c0943b..cfd0cf639 100644 --- a/src/console/pythonconsole.cs +++ b/src/console/pythonconsole.cs @@ -2,7 +2,9 @@ using System.Reflection; using System.Collections.Generic; using Python.Runtime; - +#if !NET46 +using System.Runtime.Loader; +#endif namespace Python.Runtime { public sealed class PythonConsole @@ -47,13 +49,17 @@ public AssemblyLoader() } // looks for the assembly from the resources and load it - using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) + using (var stream = Assembly.GetEntryAssembly().GetManifestResourceStream(resourceName)) { if (stream != null) { +#if NET46 Byte[] assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); Assembly assembly = Assembly.Load(assemblyData); +#else + Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(stream); +#endif loadedAssemblies[resourceName] = assembly; return assembly; } diff --git a/src/embed_tests/project.json b/src/embed_tests/project.json index 162e26076..ba562a457 100644 --- a/src/embed_tests/project.json +++ b/src/embed_tests/project.json @@ -1,15 +1,22 @@ { - "version": "0.1.0-*", + "version": "2.2.0-*", + "runtimes": { + "win7-x64": {}, + "ubuntu.16.04-x64":{} + }, "dependencies": { "Microsoft.Net.Test.Sdk": { "version": "15.0.0-preview-20161216-01" }, "dotnet-test-nunit-teamcity": "3.4.0-beta-3", "NUnit": "3.5.0", - "Python.Runtime": "0.1.0-*" + "Python.Runtime": "2.2.0-*" }, "testRunner": "nunit-teamcity", "frameworks": { + "netcoreapp1.1": { + "imports": "dnxcore50" + }, "net46": { } },