-
Notifications
You must be signed in to change notification settings - Fork 105
Open
Description
Sorry, this issue is for ClojureCLR (https://github.com/arcadia-unity/clojure-clr), but that project does not accept issue, so i write it here.
When ClojureCLR invoke a clojure code, it iterate over all assemblies and find the type with initClassName matched. source code here:
internal static bool TryLoadInitType(string relativePath)
{
var initClassName = InitClassName(relativePath);
Type initType = null;
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
#if CLR2
if(asm.ManifestModule is ModuleBuilder)
#else
if (asm.IsDynamic)
#endif
continue;
initType = asm.GetType(initClassName);
if (initType != null)
break;
}
if (initType == null)
return false;
InvokeInitType(initType.Assembly, initType);
return true;
}But it's not safe, as there may be another type have a same name , and would be wrongly loaded.
To prevent this situation, we could double check using excepted assembly name, like this:
internal static bool TryLoadInitType(string relativePath)
{
var initClassName = InitClassName(relativePath);
Type initType = null;
var asmName = relativePath.Replace('/', '.') + ".clj";
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
#if CLR2
if(asm.ManifestModule is ModuleBuilder)
#else
if (asm.IsDynamic)
#endif
continue;
if(!asm.GetName(false).Name.StartsWith(asmName))
continue;
initType = asm.GetType(initClassName);
if (initType != null)
break;
}
if (initType == null)
return false;
InvokeInitType(initType.Assembly, initType);
return true;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels