Skip to content

Synchronize with upstream #70

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 14 commits into from
Aug 30, 2023
Merged
Next Next commit
changes to fix Lazarus and FreePascal compilation issues.
  • Loading branch information
norayr committed Mar 13, 2023
commit 8a726f56c4dcdf6f8b9ca2a33b6544b36d3dca69
6 changes: 5 additions & 1 deletion Source/PythonEngine.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6066,7 +6066,11 @@ function TPythonEngine.PyUnicodeAsString(obj : PPyObject): UnicodeString;
Exit;

// The second argument is the size of the destination (Result) including #0
NewSize := Utf8ToUnicode(PChar(Result), Cardinal(Size + 1), Buffer, Cardinal(Size));
{$IFDEF FPC}
NewSize := Utf8ToUnicode(PUnicodeChar(Result), Cardinal(Size + 1), Buffer, Cardinal(Size));
{$ELSE}
NewSize := Utf8ToUnicode(PChar(Result), Cardinal(Size + 1), Buffer, Cardinal(Size));
{$ENDIF}
// NewSize includes #0
SetLength(Result, NewSize - 1);
end
Expand Down
3 changes: 3 additions & 0 deletions Source/WrapDelphi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2571,6 +2571,9 @@ function TPyDelphiObject.Dir_Wrapper(args: PPyObject): PPyObject;

var
PyType: PPyTypeObject;
{$IFDEF FPC}
i: longint;
{$ENDIF}
{$IFDEF EXTENDED_RTTI}
Context: TRttiContext;
RttiType: TRTTIType;
Expand Down
19 changes: 17 additions & 2 deletions Source/WrapDelphiClasses.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
interface

uses
Classes, SysUtils, PythonEngine, WrapDelphi;
Classes, SysUtils, PythonEngine, WrapDelphi
{$IFDEF FPC}, bufstream{$ENDIF};

type
{
Expand Down Expand Up @@ -367,6 +368,7 @@ implementation
uses
TypInfo {$IFNDEF FPC}, System.Rtti{$ENDIF};


{$IFNDEF FPC}
type
TPyReader = class(TReader)
Expand Down Expand Up @@ -2223,7 +2225,12 @@ TBufferedFileStreamClass = class of TBufferedFileStream;
DelphiObject := TBufferedFileStreamClass(DelphiObjectClass).Create(String(LFileName), LMode, LBufferSize);
end else if (LArgCount = 3) then begin
if (APythonType.Engine.PyArg_ParseTupleAndKeywords(args, kwds, 'sHI|i:Create', @LKwArgs2[0], @LFileName, @LMode, @LRights, @LBufferSize) <> 0) then
DelphiObject := TBufferedFileStreamClass(DelphiObjectClass).Create(String(LFileName), LMode, LRights, LBufferSize);
{$IFDEF FPC}
DelphiObject := TBufferedFileStreamClass(DelphiObjectClass).Create(String(LFileName), LMode, LRights);
DelphiObject.Size:= LBufferSize;
{$ELSE}
DelphiObject := TBufferedFileStreamClass(DelphiObjectClass).Create(String(LFileName), LMode, LRights, LBufferSize);
{$ENDIF}
end;

//Maybe it was created on the next attempt...
Expand Down Expand Up @@ -2385,14 +2392,22 @@ TResourceStreamClass = class of TResourceStream;
{$ELSE}
if APythonType.Engine.PyArg_ParseTuple(args, 'Iss:Create', @LHandle, @LResName, @LResType) <> 0 then
{$ENDIF}
{$IFDEF FPC}
DelphiObject := TResourceStreamClass(DelphiObjectClass).Create(LHandle, String(LResName), PChar(String(LResType)))
{$ELSE}
DelphiObject := TResourceStreamClass(DelphiObjectClass).Create(LHandle, String(LResName), PWideChar(String(LResType)))
{$ENDIF}
else
{$IFDEF CPUX64}
if APythonType.Engine.PyArg_ParseTuple(args, 'Kis:Create', @LHandle, @LResId, @LResType) <> 0 then
{$ELSE}
if APythonType.Engine.PyArg_ParseTuple(args, 'Iis:Create', @LHandle, @LResId, @LResType) <> 0 then
{$ENDIF}
{$IFDEF FPC}
DelphiObject := TResourceStreamClass(DelphiObjectClass).CreateFromID(LHandle, LResId, PChar(String(LResType)));
{$ELSE}
DelphiObject := TResourceStreamClass(DelphiObjectClass).CreateFromID(LHandle, LResId, PWideChar(String(LResType)));
{$ENDIF}
except
on E: Exception do
with GetPythonEngine do
Expand Down