From dd81f1ccdb281f871ca2190b1c5021cc01135de0 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..520a194bf 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 := dlopen(PChar(FileName), RTLD_NOLOAD); + if (Result <> NilHandle) then + Exit; + {$ENDIF} + Result := LoadLibrary(FileName); if (Result = NilHandle) then