Alexey-T / Python-for-Lazarus

Fork of Python4Delphi for Lazarus, supports Windows/Linux/macOS/*BSD/Solaris
MIT License
127 stars 42 forks source link

LongInt size on non-Windows 64bit platforms #22

Closed pyscripter closed 4 years ago

pyscripter commented 4 years ago

In FPC LongInt is always 4bytes. In Delphi LongInt is 4bytes on Windows (32 and 64bits) but 8 bytes on MacOS and Linux 64bits. Same is true about Python and gcc's long type.

As it stands FPC programs will fail on MacOS and Linux 64bits when they use Python interface functions that have LongInt or LongWord arguments. (Search for LongInt in PythonEngine.pas).

LongInt should be replaced with a typedef that behaves as Delphi and Python.

Alexey-T commented 4 years ago

what type in Delphi is always 32 bit? i will use it in

$ifdef fpc int32=longint $else int32=.....

pyscripter commented 4 years ago

Integer is always 32bit.

But I think you missed my point. LongInt works fine with Delphi.
you need something like:

{$ifdef fpc}
  {$ifdef mswindows} 
    long = integer
  {$else} 
    long= NativeInt
  {$endif}
{$else} 
  long= LongInt
{$Endif}
pyscripter commented 4 years ago
  {$ifdef mswindows} 
    long = integer
  {$else} 
    long= NativeInt
  {$endif}

should work with both delphi and fpc

pyscripter commented 4 years ago

By the way I am adding support for MacOS and Linux on the Delphi side. There will be a number of changes that are relevant to FPC, so do check in a few days.

Alexey-T commented 4 years ago

IMO your code above is not ok. for FPC we need Longint. for Delphi we need integer (which is always 32bit?) so ur code is not ok.

Alexey-T commented 4 years ago

maybe {$ifdef fpc} long = longint {$else} long = integer {$endif} ?

http://docwiki.embarcadero.com/RADStudio/Rio/en/Simple_Types_(Delphi) or maybe use Int32?

pyscripter commented 4 years ago

I am not sure you understood the issue. The python c api for certain functions uses long. This has been translated as longint in P4D.

In C, long is 4 bytes on Windows 32bit and 64bit but 8 bytes in MacOS and Linux 64bits. Same for Delphi longint. So Delphi is OK as it is. LongInt works fine in Delphi P4D.

The problem is that in fpc longint is always 4 bytes including in MacOs and Linux 64bits.

This is what my suggestion above tries to fix.

Alexey-T commented 4 years ago

now I understood. but how CudaText with Python-for-Lazaruus works on Linux x64 and macOS x64? it works ok.

pyscripter commented 4 years ago

You probably do not use the relevant API.

Alexey-T commented 4 years ago

Maybe you can help? By changing type in needed places to new name. Eg TPyLong. Which is =Longint.

I will redefine it ltr

Alexey-T commented 4 years ago

I fear I can change unneeded places:(

pyscripter commented 4 years ago

Will implement it in the pyscripter/Python4Delphi.