Skip to content

Commit 5b3677f

Browse files
authored
Merge pull request #63 from Embarcadero/aptfix
Aptfix
2 parents ba0565e + 0a099ae commit 5b3677f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Source/PythonEngine.pas

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,8 @@ TDynamicDll = class(TComponent)
12371237

12381238
procedure LoadPythonInfoFromModule;
12391239
function GetPythonModuleFromProcess(): NativeUInt;
1240-
function HasHostSymbols(): boolean;
1240+
// Check for Python symbols in the current loaded library (FDLLHandle)
1241+
function HasPythonSymbolsInLibrary(): boolean;
12411242
procedure LoadFromHostSymbols();
12421243
//Loading strategies
12431244
function TryLoadFromHostSymbols(): boolean;
@@ -3097,16 +3098,10 @@ function TDynamicDll.GetPythonModuleFromProcess(): NativeUInt;
30973098
{$IFNDEF FPC}
30983099

30993100
function HasSymbols(const AModule: NativeUInt): boolean;
3100-
var
3101-
LPy_GetBuildInfo: function : PAnsiChar; cdecl;
3102-
LPy_IsInitialized: function: integer; cdecl;
31033101
begin
31043102
FDLLHandle := AModule;
31053103
try
3106-
LPy_GetBuildInfo := Import('Py_GetBuildInfo', false);
3107-
LPy_IsInitialized := Import('Py_IsInitialized', false);
3108-
Result := Assigned(LPy_GetBuildInfo) and Assigned(LPy_GetBuildInfo())
3109-
and Assigned(LPy_IsInitialized) and (LPy_IsInitialized() <> 0);
3104+
Result := HasPythonSymbolsInLibrary();
31103105
finally
31113106
FDLLHandle := 0;
31123107
end;
@@ -3312,10 +3307,16 @@ function TDynamicDll.TryLoadFromCurrentProcess: boolean;
33123307
function TDynamicDll.TryLoadFromHostSymbols: boolean;
33133308
begin
33143309
//We want to look in for host symbols at first
3310+
{$IFNDEF FPC}
3311+
FDLLHandle := LoadLibrary('');
3312+
{$ELSE}
33153313
FDLLHandle := 0;
3316-
Result := HasHostSymbols();
3314+
{$ENDIF}
3315+
Result := HasPythonSymbolsInLibrary();
33173316
if Result then
3318-
LoadFromHostSymbols();
3317+
LoadFromHostSymbols()
3318+
else
3319+
FDLLHandle := 0;
33193320
end;
33203321

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

3419-
function TDynamicDll.HasHostSymbols: boolean;
3420+
function TDynamicDll.HasPythonSymbolsInLibrary: boolean;
34203421
var
3422+
LPy_GetBuildInfo: function: PAnsiChar; cdecl;
34213423
LPy_IsInitialized: function: integer; cdecl;
34223424
begin
3425+
LPy_GetBuildInfo := Import('Py_GetBuildInfo', false);
34233426
LPy_IsInitialized := Import('Py_IsInitialized', false);
3424-
Result := Assigned(LPy_IsInitialized) and (LPy_IsInitialized() <> 0);
3427+
Result := Assigned(LPy_GetBuildInfo) and Assigned(LPy_GetBuildInfo())
3428+
and Assigned(LPy_IsInitialized) and (LPy_IsInitialized() <> 0);
34253429
end;
34263430

34273431
procedure TDynamicDll.Quit;

0 commit comments

Comments
 (0)