Skip to content

Commit 7bfc7a8

Browse files
committed
Delphi MacOS support added.
1 parent 129b6d8 commit 7bfc7a8

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

PythonForDelphi/Components/Sources/Core/Definition.Inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,9 @@
189189
{$DEFINE EXTENDED_RTTI}
190190
{$ENDIF DELPHIXE_OR_HIGHER}
191191

192+
{$IFDEF DELPHIXE2_OR_HIGHER}
193+
{$IFDEF MACOS}
194+
{$DEFINE DARWIN}
195+
{$ENDIF MACOS}
196+
{$ENDIF DELPHIXE_OR_HIGHER}
197+

PythonForDelphi/Components/Sources/Core/PythonEngine.pas

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ interface
8080
DynLibs,
8181
{$ELSE}
8282
Posix.DLfcn,
83+
Posix.Pthread,
8384
{$ENDIF}
8485
{$ENDIF}
8586
Classes,
@@ -3363,19 +3364,17 @@ procedure TDynamicDll.OpenDll(const aDllName : string);
33633364
DoOpenDll(aDllName);
33643365

33653366
if not IsHandleValid then begin
3366-
{$IFDEF MSWINDOWS}
3367+
{$IFDEF MSWINDOWS}
33673368
s := Format('Error %d: Could not open Dll "%s"',[GetLastError, DllName]);
3368-
{$ENDIF}
3369-
{$IFDEF LINUX}
3369+
{ $ELSE}
33703370
s := Format('Error: Could not open Dll "%s"',[DllName]);
3371-
{$ENDIF}
3371+
{$ENDIF}
33723372
if FatalMsgDlg then
3373-
{$IFDEF MSWINDOWS}
3373+
{$IFDEF MSWINDOWS}
33743374
MessageBox( GetActiveWindow, PChar(s), 'Error', MB_TASKMODAL or MB_ICONSTOP );
3375-
{$ENDIF}
3376-
{$IFDEF LINUX}
3375+
{$ELSE}
33773376
WriteLn(ErrOutput, s);
3378-
{$ENDIF}
3377+
{$ENDIF}
33793378

33803379
if FatalAbort then
33813380
Quit;
@@ -3402,8 +3401,16 @@ destructor TDynamicDll.Destroy;
34023401
function TDynamicDll.Import(const funcname: AnsiString; canFail : Boolean = True): Pointer;
34033402
var
34043403
E : EDllImportError;
3404+
{$IF not Defined(FPC) and not Defined(MSWINDOWS)}
3405+
S : string;
3406+
{$IFEND}
34053407
begin
3408+
{$IF Defined(FPC) or Defined(MSWINDOWS)}
34063409
Result := GetProcAddress( FDLLHandle, PAnsiChar(funcname) );
3410+
{$ELSE}
3411+
S := string(funcname);
3412+
Result := GetProcAddress( FDLLHandle, PWideChar(S) );
3413+
{$IFEND}
34073414
if (Result = nil) and canFail then begin
34083415
{$IFDEF MSWINDOWS}
34093416
E := EDllImportError.CreateFmt('Error %d: could not map symbol "%s"', [GetLastError, funcname]);
@@ -3427,8 +3434,7 @@ function TDynamicDll.IsHandleValid : Boolean;
34273434
begin
34283435
{$IFDEF MSWINDOWS}
34293436
Result := (FDLLHandle >= 32);
3430-
{$ENDIF}
3431-
{$IFDEF LINUX}
3437+
{$ELSE}
34323438
Result := FDLLHandle <> 0;
34333439
{$ENDIF}
34343440
end;
@@ -3527,8 +3533,8 @@ procedure TPythonInterface.AfterLoad;
35273533
begin
35283534
inherited;
35293535
FIsPython3000 := Pos('PYTHON3', UpperCase(DLLName)) > 0;
3530-
FMajorVersion := StrToInt(DLLName[7 {$IFDEF LINUX}+3{$ENDIF}]);
3531-
FMinorVersion := StrToInt(DLLName[8{$IFDEF LINUX}+4{$ENDIF}]);
3536+
FMajorVersion := StrToInt(DLLName[7 {$IFNDEF MSWINDOWS}+3{$ENDIF}]);
3537+
FMinorVersion := StrToInt(DLLName[8{$IFNDEF MSWINDOWS}+4{$ENDIF}]);
35323538

35333539

35343540
if FIsPython3000 then
@@ -9743,17 +9749,21 @@ function PyType_HasFeature(AType : PPyTypeObject; AFlag : Integer) : Boolean;
97439749
procedure MaskFPUExceptions(ExceptionsMasked : boolean;
97449750
MatchPythonPrecision : Boolean);
97459751
begin
9752+
{$IF Defined(CPUX86) or Defined(CPUX64)}
97469753
if ExceptionsMasked then
97479754
SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide,
97489755
exOverflow, exUnderflow, exPrecision])
97499756
else
97509757
SetExceptionMask([exDenormalized, exUnderflow, exPrecision]);
9751-
{$IFNDEF NEXTGEN}{$WARN SYMBOL_PLATFORM OFF}
9758+
{$IFNDEF NEXTGEN}{$WARN SYMBOL_PLATFORM OFF}
9759+
{$IF Defined(FPC) or Defined(MSWINDOWS)}
97529760
if MatchPythonPrecision then
97539761
SetPrecisionMode(pmDouble)
97549762
else
97559763
SetPrecisionMode(pmExtended);
9756-
{$ENDIF !NEXTGEN}{$WARN SYMBOL_PLATFORM ON}
9764+
{$ENDIF !NEXTGEN}{$WARN SYMBOL_PLATFORM ON}
9765+
{$IFEND}
9766+
{$IFEND}
97579767
end;
97589768

97599769
function CleanString(const s : AnsiString; AppendLF : Boolean) : AnsiString;

PythonForDelphi/Components/Sources/Core/PythonVersions.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ implementation
8181
Uses
8282
{$IFDEF MSWINDOWS}
8383
Windows,
84+
Registry,
8485
{$ENDIF}
8586
SysUtils,
8687
Math,
87-
Registry,
8888
PythonEngine;
8989

9090
{ TPythonVersion }

0 commit comments

Comments
 (0)