🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
34 changes: 18 additions & 16 deletions src/runtime/assemblymanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ internal class AssemblyManager {
static ResolveEventHandler rhandler;
static Dictionary<string, int> probed;
static List<Assembly> assemblies;
static Dictionary<string, Assembly> loadedAssemblies;
internal static List<string> pypath;

private AssemblyManager() {}
Expand All @@ -47,7 +46,6 @@ internal static void Initialize() {
probed = new Dictionary<string, int>(32);
//generics = new Dictionary<string, Dictionary<string, string>>();
assemblies = new List<Assembly>(16);
loadedAssemblies = new Dictionary<string, Assembly>();
pypath = new List<string>(16);

AppDomain domain = AppDomain.CurrentDomain;
Expand Down Expand Up @@ -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
Expand All @@ -247,7 +246,10 @@ public static bool LoadImplicit(string name, bool warn=true) {
if (assemblies == null) {
assemblies = new HashSet<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
}
Assembly a = LoadAssemblyPath(s);
Assembly a = FindLoadedAssembly(s);
if (a == null) {
a = LoadAssemblyPath(s);
}
if (a == null) {
a = LoadAssembly(s);
}
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/moduleobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down