Skip to content

changes to fix Lazarus and FreePascal compilation issues. #413

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 3 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewSize := Utf8ToUnicode(PWideChar(Result), Cardinal(Size + 1), Buffer, Cardinal(Size));

Would work both in Delphi and Fpc.
PUnicodeChar is an alias to PWideChar;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true!

// 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}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i: Integer
should be in the {$ELSE} part of the the IFDEF below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I addressed all the comments.

Thank you for those. You can take a look at another commit.

Copy link
Owner

@pyscripter pyscripter Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant in the ELSE part of EXTENDED_RTTI! You don't need IFDEF FPC. And use Integer instead of longint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, now I see.

Thank you for comments and your patience.

Now I did it, but PR contains 3 commits.

Do you want me to figure the way to change it for 1 commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, do you like the current state of it?
would you merge? or should i change something else?

{$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}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DelphiObject := TResourceStreamClass(DelphiObjectClass).Create(LHandle, String(LResName), PChar(String(LResType)))

Should work in both fpc and Delphi.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

DelphiObject := TResourceStreamClass(DelphiObjectClass).CreateFromID(LHandle, LResId, PWideChar(String(LResType)));
{$ENDIF}
except
on E: Exception do
with GetPythonEngine do
Expand Down