From ec79d20673fec487bfcc5b13cf7558b605b9eb8c Mon Sep 17 00:00:00 2001 From: jacopodl Date: Fri, 7 Jun 2024 15:43:16 +0200 Subject: [PATCH] fix: resolved issue causing the same module to be loaded twice when loaded once with the full path and once with only the package path --- argon/vm/datatype/arobject.cpp | 2 +- argon/vm/importer/import.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/argon/vm/datatype/arobject.cpp b/argon/vm/datatype/arobject.cpp index 1a97b75e..d4161033 100644 --- a/argon/vm/datatype/arobject.cpp +++ b/argon/vm/datatype/arobject.cpp @@ -273,7 +273,7 @@ const TypeInfo TypeTrait = { nullptr, nullptr, nullptr, - nullptr, + type_compare, nullptr, nullptr, nullptr, diff --git a/argon/vm/importer/import.cpp b/argon/vm/importer/import.cpp index 3a7ad3d2..0dcfa305 100644 --- a/argon/vm/importer/import.cpp +++ b/argon/vm/importer/import.cpp @@ -856,6 +856,30 @@ String *SanitizeModulePath(String *name, const String *path_sep) { Release(altsep); + auto last_sep = StringRFind(res, path_sep); + if (last_sep < 0) + return res; + + auto mname_length = ARGON_RAW_STRING_LENGTH(res) - (last_sep + 1); + if (mname_length >= ARGON_RAW_STRING_LENGTH(res) - mname_length) + return res; + + auto ok = argon::vm::memory::MemoryCompare( + (ARGON_RAW_STRING(name) + last_sep) - mname_length, + (ARGON_RAW_STRING(name) + last_sep + 1), + mname_length); + + if (ok == 0) { + if ((name = StringSubs(res, 0, last_sep)) == nullptr) { + Release(res); + return nullptr; + } + + Release(res); + + return name; + } + return res; }