Skip to content

Aptfix #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions Source/PythonEngine.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,8 @@ TDynamicDll = class(TComponent)

procedure LoadPythonInfoFromModule;
function GetPythonModuleFromProcess(): NativeUInt;
function HasHostSymbols(): boolean;
// Check for Python symbols in the current loaded library (FDLLHandle)
function HasPythonSymbolsInLibrary(): boolean;
procedure LoadFromHostSymbols();
//Loading strategies
function TryLoadFromHostSymbols(): boolean;
Expand Down Expand Up @@ -3097,16 +3098,10 @@ function TDynamicDll.GetPythonModuleFromProcess(): NativeUInt;
{$IFNDEF FPC}

function HasSymbols(const AModule: NativeUInt): boolean;
var
LPy_GetBuildInfo: function : PAnsiChar; cdecl;
LPy_IsInitialized: function: integer; cdecl;
begin
FDLLHandle := AModule;
try
LPy_GetBuildInfo := Import('Py_GetBuildInfo', false);
LPy_IsInitialized := Import('Py_IsInitialized', false);
Result := Assigned(LPy_GetBuildInfo) and Assigned(LPy_GetBuildInfo())
and Assigned(LPy_IsInitialized) and (LPy_IsInitialized() <> 0);
Result := HasPythonSymbolsInLibrary();
finally
FDLLHandle := 0;
end;
Expand Down Expand Up @@ -3312,10 +3307,16 @@ function TDynamicDll.TryLoadFromCurrentProcess: boolean;
function TDynamicDll.TryLoadFromHostSymbols: boolean;
begin
//We want to look in for host symbols at first
{$IFNDEF FPC}
FDLLHandle := LoadLibrary('');
{$ELSE}
FDLLHandle := 0;
Result := HasHostSymbols();
{$ENDIF}
Result := HasPythonSymbolsInLibrary();
if Result then
LoadFromHostSymbols();
LoadFromHostSymbols()
else
FDLLHandle := 0;
end;

procedure TDynamicDll.LoadFromHostSymbols;
Expand Down Expand Up @@ -3416,12 +3417,15 @@ function TDynamicDll.GetQuitMessage : string;
Result := Format( 'Dll %s could not be loaded. We must quit.', [DllName]);
end;

function TDynamicDll.HasHostSymbols: boolean;
function TDynamicDll.HasPythonSymbolsInLibrary: boolean;
var
LPy_GetBuildInfo: function: PAnsiChar; cdecl;
LPy_IsInitialized: function: integer; cdecl;
begin
LPy_GetBuildInfo := Import('Py_GetBuildInfo', false);
LPy_IsInitialized := Import('Py_IsInitialized', false);
Result := Assigned(LPy_IsInitialized) and (LPy_IsInitialized() <> 0);
Result := Assigned(LPy_GetBuildInfo) and Assigned(LPy_GetBuildInfo())
and Assigned(LPy_IsInitialized) and (LPy_IsInitialized() <> 0);
end;

procedure TDynamicDll.Quit;
Expand Down