From 16e32acdd0a449e0a0c1779af9ed24be5b141c2a Mon Sep 17 00:00:00 2001 From: Olly Date: Tue, 26 Sep 2023 16:50:47 +0100 Subject: [PATCH] LoadPlugin: On Unix use RTLD_NOLOAD to check if library is already loaded --- Source/script/simba.script_pluginloader.pas | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/script/simba.script_pluginloader.pas b/Source/script/simba.script_pluginloader.pas index ee747842d..504ab02a3 100644 --- a/Source/script/simba.script_pluginloader.pas +++ b/Source/script/simba.script_pluginloader.pas @@ -12,13 +12,22 @@ function LoadPlugin(FileName: String; ExtraSearchDirs: TStringArray = nil): TLib implementation uses - simba.mufasatypes, simba.env; + simba.mufasatypes, simba.env + {$IFDEF UNIX}, + dl + {$ENDIF}; function LoadPlugin(FileName: String; ExtraSearchDirs: TStringArray): TLibHandle; begin if (not FindPlugin(FileName, ExtraSearchDirs)) then raise Exception.CreateFmt('Unable to find plugin "%s"', [FileName]); + {$IFDEF UNIX} + Result := TLibHandle(dlopen(PChar(FileName), RTLD_NOLOAD)); + if (Result <> NilHandle) then + Exit; + {$ENDIF} + Result := LoadLibrary(FileName); if (Result = NilHandle) then