Skip to content

Commit 8a726f5

Browse files
committed
changes to fix Lazarus and FreePascal compilation issues.
1 parent 1cd6621 commit 8a726f5

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Source/PythonEngine.pas

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6066,7 +6066,11 @@ function TPythonEngine.PyUnicodeAsString(obj : PPyObject): UnicodeString;
60666066
Exit;
60676067

60686068
// The second argument is the size of the destination (Result) including #0
6069-
NewSize := Utf8ToUnicode(PChar(Result), Cardinal(Size + 1), Buffer, Cardinal(Size));
6069+
{$IFDEF FPC}
6070+
NewSize := Utf8ToUnicode(PUnicodeChar(Result), Cardinal(Size + 1), Buffer, Cardinal(Size));
6071+
{$ELSE}
6072+
NewSize := Utf8ToUnicode(PChar(Result), Cardinal(Size + 1), Buffer, Cardinal(Size));
6073+
{$ENDIF}
60706074
// NewSize includes #0
60716075
SetLength(Result, NewSize - 1);
60726076
end

Source/WrapDelphi.pas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,9 @@ function TPyDelphiObject.Dir_Wrapper(args: PPyObject): PPyObject;
25712571

25722572
var
25732573
PyType: PPyTypeObject;
2574+
{$IFDEF FPC}
2575+
i: longint;
2576+
{$ENDIF}
25742577
{$IFDEF EXTENDED_RTTI}
25752578
Context: TRttiContext;
25762579
RttiType: TRTTIType;

Source/WrapDelphiClasses.pas

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
interface
66

77
uses
8-
Classes, SysUtils, PythonEngine, WrapDelphi;
8+
Classes, SysUtils, PythonEngine, WrapDelphi
9+
{$IFDEF FPC}, bufstream{$ENDIF};
910

1011
type
1112
{
@@ -367,6 +368,7 @@ implementation
367368
uses
368369
TypInfo {$IFNDEF FPC}, System.Rtti{$ENDIF};
369370

371+
370372
{$IFNDEF FPC}
371373
type
372374
TPyReader = class(TReader)
@@ -2223,7 +2225,12 @@ TBufferedFileStreamClass = class of TBufferedFileStream;
22232225
DelphiObject := TBufferedFileStreamClass(DelphiObjectClass).Create(String(LFileName), LMode, LBufferSize);
22242226
end else if (LArgCount = 3) then begin
22252227
if (APythonType.Engine.PyArg_ParseTupleAndKeywords(args, kwds, 'sHI|i:Create', @LKwArgs2[0], @LFileName, @LMode, @LRights, @LBufferSize) <> 0) then
2226-
DelphiObject := TBufferedFileStreamClass(DelphiObjectClass).Create(String(LFileName), LMode, LRights, LBufferSize);
2228+
{$IFDEF FPC}
2229+
DelphiObject := TBufferedFileStreamClass(DelphiObjectClass).Create(String(LFileName), LMode, LRights);
2230+
DelphiObject.Size:= LBufferSize;
2231+
{$ELSE}
2232+
DelphiObject := TBufferedFileStreamClass(DelphiObjectClass).Create(String(LFileName), LMode, LRights, LBufferSize);
2233+
{$ENDIF}
22272234
end;
22282235

22292236
//Maybe it was created on the next attempt...
@@ -2385,14 +2392,22 @@ TResourceStreamClass = class of TResourceStream;
23852392
{$ELSE}
23862393
if APythonType.Engine.PyArg_ParseTuple(args, 'Iss:Create', @LHandle, @LResName, @LResType) <> 0 then
23872394
{$ENDIF}
2395+
{$IFDEF FPC}
2396+
DelphiObject := TResourceStreamClass(DelphiObjectClass).Create(LHandle, String(LResName), PChar(String(LResType)))
2397+
{$ELSE}
23882398
DelphiObject := TResourceStreamClass(DelphiObjectClass).Create(LHandle, String(LResName), PWideChar(String(LResType)))
2399+
{$ENDIF}
23892400
else
23902401
{$IFDEF CPUX64}
23912402
if APythonType.Engine.PyArg_ParseTuple(args, 'Kis:Create', @LHandle, @LResId, @LResType) <> 0 then
23922403
{$ELSE}
23932404
if APythonType.Engine.PyArg_ParseTuple(args, 'Iis:Create', @LHandle, @LResId, @LResType) <> 0 then
23942405
{$ENDIF}
2406+
{$IFDEF FPC}
2407+
DelphiObject := TResourceStreamClass(DelphiObjectClass).CreateFromID(LHandle, LResId, PChar(String(LResType)));
2408+
{$ELSE}
23952409
DelphiObject := TResourceStreamClass(DelphiObjectClass).CreateFromID(LHandle, LResId, PWideChar(String(LResType)));
2410+
{$ENDIF}
23962411
except
23972412
on E: Exception do
23982413
with GetPythonEngine do

0 commit comments

Comments
 (0)