diff --git a/setup.py b/setup.py index f06b011d5..35c726d89 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from distutils.command.build_ext import build_ext from distutils.command.build_scripts import build_scripts from distutils.command.install_lib import install_lib -from distutils.sysconfig import get_config_vars +from distutils.sysconfig import get_config_var from platform import architecture from subprocess import Popen, CalledProcessError, PIPE, check_call from glob import glob @@ -183,15 +183,22 @@ def _build_monoclr(self, ext): depends=ext.depends) output_dir = os.path.dirname(self.get_ext_fullpath(ext.name)) - py_libs = get_config_vars("BLDLIBRARY")[0] + py_libs = get_config_var("BLDLIBRARY") libs += " " + py_libs + # Include the directories python's shared libs were installed to. This + # is case python was built with --enable-shared as then npython will need + # to be able to find libpythonX.X.so. + runtime_library_dirs = (get_config_var("DESTDIRS") or "").split(" ") + if ext.runtime_library_dirs: + runtime_library_dirs.extend(ext.runtime_library_dirs) + self.compiler.link_executable(objects, _npython_exe, output_dir=output_dir, libraries=self.get_libraries(ext), library_dirs=ext.library_dirs, - runtime_library_dirs=ext.runtime_library_dirs, + runtime_library_dirs=runtime_library_dirs, extra_postargs=libs.split(" "), debug=self.debug) diff --git a/src/runtime/assemblymanager.cs b/src/runtime/assemblymanager.cs index 291301466..583b5c945 100644 --- a/src/runtime/assemblymanager.cs +++ b/src/runtime/assemblymanager.cs @@ -30,7 +30,6 @@ internal class AssemblyManager { static ResolveEventHandler rhandler; static Dictionary probed; static List assemblies; - static Dictionary loadedAssemblies; internal static List pypath; private AssemblyManager() {} @@ -47,7 +46,6 @@ internal static void Initialize() { probed = new Dictionary(32); //generics = new Dictionary>(); assemblies = new List(16); - loadedAssemblies = new Dictionary(); pypath = new List(16); AppDomain domain = AppDomain.CurrentDomain; @@ -204,24 +202,25 @@ public static Assembly LoadAssemblyPath(string name) { string path = FindAssembly(name); Assembly assembly = null; if (path != null) { - if (loadedAssemblies.ContainsKey(path)) { - return loadedAssemblies[path]; - } - // Avoid using Assembly.LoadFrom as referenced assemblies that exist - // in the same path will be loaded directly from there, rather than - // using other versions already loaded. This is a problem if there - // is a Python.Runtime.dll in the same folder as the assembly being - // loaded, as that will result in two instances being loaded. - try { - byte[] bytes = System.IO.File.ReadAllBytes(path); - assembly = Assembly.Load(bytes); - loadedAssemblies[path] = assembly; - } + try { assembly = Assembly.LoadFrom(path); } catch {} } return assembly; } + //=================================================================== + // Returns an assembly that's already been loaded + //=================================================================== + + public static Assembly FindLoadedAssembly(string name) { + for (int i = 0; i < assemblies.Count; i++) { + Assembly a = (Assembly)assemblies[i]; + if (a.GetName().Name == name) { + return a; + } + } + return null; + } //=================================================================== // Given a qualified name of the form A.B.C.D, attempt to load @@ -247,7 +246,10 @@ public static bool LoadImplicit(string name, bool warn=true) { if (assemblies == null) { assemblies = new HashSet(AppDomain.CurrentDomain.GetAssemblies()); } - Assembly a = LoadAssemblyPath(s); + Assembly a = FindLoadedAssembly(s); + if (a == null) { + a = LoadAssemblyPath(s); + } if (a == null) { a = LoadAssembly(s); } diff --git a/src/runtime/moduleobject.cs b/src/runtime/moduleobject.cs index efa916464..c5735ca4a 100644 --- a/src/runtime/moduleobject.cs +++ b/src/runtime/moduleobject.cs @@ -385,7 +385,11 @@ public static Assembly AddReference(string name) { AssemblyManager.UpdatePath(); Assembly assembly = null; - assembly = AssemblyManager.LoadAssemblyPath(name); + assembly = AssemblyManager.FindLoadedAssembly(name); + if (assembly == null) + { + assembly = AssemblyManager.LoadAssemblyPath(name); + } if (assembly == null) { assembly = AssemblyManager.LoadAssembly(name);