@@ -38,6 +38,8 @@ String *FindSourceInPaths(const Import *imp, String *mod_path, String *mod_name)
38
38
39
39
String *GetModuleName (String *path, const String *sep);
40
40
41
+ String *SanitizeModulePath (String *name, const String *path_sep);
42
+
41
43
void DelModuleFromCache (Import *imp, String *name);
42
44
43
45
// EOF
@@ -645,24 +647,33 @@ Module *argon::vm::importer::LoadModule(Import *imp, const char *name, ImportSpe
645
647
Module *argon::vm::importer::LoadModule (Import *imp, String *name, ImportSpec *hint) {
646
648
ImportModuleCacheEntry *entry;
647
649
650
+ if ((name = SanitizeModulePath (name, imp->path_sep )) == nullptr )
651
+ return nullptr ;
652
+
648
653
std::unique_lock lock (imp->lock );
649
654
650
655
if ((entry = imp->module_cache .Lookup (name)) != nullptr ) {
651
656
if (!AR_TYPEOF (entry->value , type_module_)) {
652
657
ErrorFormat (kModuleImportError [0 ], kModuleImportError [2 ], ARGON_RAW_STRING (name));
658
+
659
+ Release (name);
653
660
return nullptr ;
654
661
}
655
662
663
+ Release (name);
656
664
return (Module *) IncRef (entry->value );
657
665
}
658
666
659
667
auto *spec = Locate (imp, name, hint);
660
668
if (spec == nullptr ) {
661
669
ErrorFormat (kModuleImportError [0 ], kModuleImportError [0 ], ARGON_RAW_STRING (name));
670
+
671
+ Release (name);
662
672
return nullptr ;
663
673
}
664
674
665
675
if (!AddModule2Cache (imp, name, nullptr )) {
676
+ Release (name);
666
677
Release (spec);
667
678
return nullptr ;
668
679
}
@@ -675,12 +686,15 @@ Module *argon::vm::importer::LoadModule(Import *imp, String *name, ImportSpec *h
675
686
676
687
if (mod != nullptr ) {
677
688
if (!AddModule2Cache (imp, name, mod)) {
689
+ Release (name);
678
690
Release (mod);
679
691
return nullptr ;
680
692
}
681
693
} else
682
694
DelModuleFromCache (imp, name);
683
695
696
+ Release (name);
697
+
684
698
return mod;
685
699
}
686
700
@@ -819,6 +833,25 @@ String *GetModuleName(String *path, const String *sep) {
819
833
return IncRef (path);
820
834
}
821
835
836
+ String *SanitizeModulePath (String *name, const String *path_sep) {
837
+ String *altsep;
838
+
839
+ #ifdef _ARGON_PLATFORM_WINDOWS
840
+ altsep = StringIntern (" /" );
841
+ #else
842
+ altsep = StringIntern (" \\ " );
843
+ #endif
844
+
845
+ if (altsep == nullptr )
846
+ return nullptr ;
847
+
848
+ auto *res = StringReplace (name, altsep, path_sep, -1 );
849
+
850
+ Release (altsep);
851
+
852
+ return res;
853
+ }
854
+
822
855
void DelModuleFromCache (Import *imp, String *name) {
823
856
auto *entry = imp->module_cache .Remove (name);
824
857
0 commit comments