The Wayback Machine - https://web.archive.org/web/20201210131909/https://github.com/pyscripter/python4delphi/issues/197
Skip to content
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

FPC - LongInt size on non-Windows 64bit platforms #197

Open
pyscripter opened this issue Oct 12, 2020 · 14 comments
Open

FPC - LongInt size on non-Windows 64bit platforms #197

pyscripter opened this issue Oct 12, 2020 · 14 comments

Comments

@pyscripter
Copy link
Owner

@pyscripter pyscripter commented Oct 12, 2020

@pyscripter
Copy link
Owner Author

@pyscripter pyscripter commented Oct 17, 2020

@Alexey-T Before I provide a fix, could you please do a test to make sure that the error exists?

All you need is, using fpc, to create a python engine at MacOS64 / Linunx 64, call
PyInt_FromLong and
PyInt_AsLong
and check whether they provide the correct results..

@Alexey-T
Copy link

@Alexey-T Alexey-T commented Oct 18, 2020

Ok
In Lazarus console demo, I did

procedure TfmMain.PythonEngineAfterInit(Sender: TObject);
const
  NTest: Longint = 1 shl 30;
var
  dir: string;
begin
  dir:= ExtractFilePath(Application.ExeName);
  {$ifdef windows}
  Py_SetSysPath([dir+'DLLs', dir+cPyZipWindows], false);
  {$endif}
  Py_SetSysPath([dir+'Py'], true);

  Caption:= BoolToStr(PythonEngine.PyInt_AsLong(PythonEngine.PyInt_FromLong(NTest)) = NTest, true);
end;  

app start in Ubuntu 20 x64 - caption is True

@Alexey-T
Copy link

@Alexey-T Alexey-T commented Oct 18, 2020

(Ubuntu has Py 3.8)

@pyscripter
Copy link
Owner Author

@pyscripter pyscripter commented Oct 18, 2020

Thanks. Could you please try the following:

var
  P1, P2: PPyObject;
with PythonEngine do begin
  P1 := PyInt_AsLong(1);
  P2 := PyNumber_Negative(P1);
  Assert(PyInt_AsLong(P2) = -1);
end;
@pyscripter
Copy link
Owner Author

@pyscripter pyscripter commented Oct 19, 2020

@Alexey-T So what is the verdict?

@Alexey-T
Copy link

@Alexey-T Alexey-T commented Oct 19, 2020

I was busy, will test today

@Alexey-T
Copy link

@Alexey-T Alexey-T commented Oct 19, 2020

It didnt compile, fixed to


  with PythonEngine do begin
    P1 := PyInt_FromLong(1);
    P2 := PyNumber_Negative(P1);
    Assert(PyInt_AsLong(P2) = -1);
  end; 

and it runs OK here.
no error.

@pyscripter
Copy link
Owner Author

@pyscripter pyscripter commented Oct 19, 2020

@Alexey-T
Is your fpc program 64 bits?
Very weird:
https://usrmisc.wordpress.com/2012/12/27/integer-sizes-in-c-on-32-bit-and-64-bit-linux/
https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models
https://stackoverflow.com/questions/35844586/can-i-assume-the-size-of-long-int-is-always-4-bytes
and other documentations say that, in Linux and MacOS 64bits, long is 8 bits (like Int64).
FPC longInt is 4 bits everywhere. Can you confirm that?

The discrepancy should cause the above to fail. Shouldn't it?
Any thoughts?

Unless fpc takes account of that and does automatic conversions. Does looking at the generated assembly code shed some light?

@pyscripter
Copy link
Owner Author

@pyscripter pyscripter commented Oct 19, 2020

@Alexey-T

Could you please try the following as well:


  with PythonEngine do begin
    P1 := PyInt_FromLong(-1);
    P2 := PyNumber_Negative(P1);
    Assert(PyInt_AsLong(P2) = 1);
  end; 
@Alexey-T
Copy link

@Alexey-T Alexey-T commented Oct 20, 2020

Yes, it is Linux x64, Py 3.8.
Last snippet also works ok! ie no exception. even BoolToStr() shows True.

@pyscripter
Copy link
Owner Author

@pyscripter pyscripter commented Oct 20, 2020

@Alexey-T Can you confirm that FPC longInt is 32 bits (4 bytes) in Ubuntu 64 bits?
Shall I close this issue then?

@Alexey-T
Copy link

@Alexey-T Alexey-T commented Oct 20, 2020

It shows 4

procedure TForm1.FormCreate(Sender: TObject);
begin
  caption:= inttostr(sizeof(Longint))
end;
       

ubuntu x64

@Alexey-T
Copy link

@Alexey-T Alexey-T commented Oct 20, 2020

App is for linux x64

@pyscripter
Copy link
Owner Author

@pyscripter pyscripter commented Oct 23, 2020

@Alexey-T Could you please try the above tests on a Mac, so that I can close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.