Recent

Author Topic: PascalScript bug with Lazarus x64  (Read 7432 times)

universe

  • New Member
  • *
  • Posts: 20
PascalScript bug with Lazarus x64
« on: December 21, 2015, 07:27:40 am »
Dear all,
I found a bug in Lazarus x64 and pascalscript with array types, the attached project works as expected either with Lazarus 1.4 or 1.6RC1 x86 but when compiled with Lazarus 1.4 or 1.6RC1 x64, the program shows wrong integers and enters infinite loop as (Length gives a wrong value).
Thanks

GetMem

  • Hero Member
  • *****
  • Posts: 3757
Re: PascalScript bug with Lazarus x64
« Reply #1 on: December 21, 2015, 08:43:16 am »
Hi universe,

What happens if you change:
Code: Pascal  [Select][+][-]
  1. type
  2.   TATest = record
  3.     Test1: NativeUInt;
  4.     Test2: NativeUInt;
  5.   end;
and
Code: Pascal  [Select][+][-]
  1. procedure Test(daValue:TATests);
  2. var
  3.   I: Integer
  4. begin
  5.   for I := Low(daValue) to High(daValue) do
  6.     ShowMessage(IntToStr(daValue[I].Test1));        
  7. end;
  8.  

regards,
GetMem

universe

  • New Member
  • *
  • Posts: 20
Re: PascalScript bug with Lazarus x64
« Reply #2 on: December 21, 2015, 09:00:34 am »
Hello GetMem,
Thanks for your reply, unfortunately nothing changed, wrong integers and infinite loop.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: PascalScript bug with Lazarus x64
« Reply #3 on: December 21, 2015, 09:22:21 am »
You can try to see what was changed in FPC compiler for dynamic arrays or you can try debug how it is handled:

trunk\compiler\x86_64\cpupara.pas

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/compiler/x86_64/cpupara.pas?sortby=file&view=log
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

tr_escape

  • Sr. Member
  • ****
  • Posts: 409
  • sector name toys | respect to spectre
    • Github:
Re: PascalScript bug with Lazarus x64
« Reply #4 on: December 21, 2015, 10:06:35 am »
Hello ,

I think pascal script's internals has got this bug.
I tried another way to avoid this problem with my software compiled with i386 and x86_64.

Some functions using by internal like as _showmessage but almost like as your codes.

And results are nice it is working:

"Len: 2 4 3"

Code: Pascal  [Select][+][-]
  1. program arr;
  2.  
  3. type
  4.   TATest = record
  5.     Test1:integer;
  6.     Test2:integer;
  7.   end;
  8.  
  9. type
  10.   TATests = array of TATest;
  11.  
  12. var
  13.   arr_byte : array of integer;
  14.  
  15.   da : TATests;
  16. begin
  17.   setlength(arr_byte,2);
  18.   arr_byte[0] := 2;
  19.   arr_byte[1] := 1;
  20.   _showmessage( inttostr(arr_byte[0]) +' '+ inttostr(arr_byte[1]));
  21.  
  22.  
  23.   setlength(da,2);
  24.   da[0].Test1 := 4;
  25.   da[1].Test1 := 3;
  26.  
  27.   _showmessage('Len: ' + inttostr(length(da)) +' '+
  28.                inttostr(da[0].Test1) +' '+
  29.                inttostr(da[1].Test1));
  30.  
  31. end.
  32.  
« Last Edit: December 21, 2015, 10:13:08 am by tr_escape »

universe

  • New Member
  • *
  • Posts: 20
Re: PascalScript bug with Lazarus x64
« Reply #5 on: December 21, 2015, 10:59:29 am »
Hello ,

I tried another way to avoid this problem with my software compiled with i386 and x86_64.

Thanks for your tips, but this way my real program script will be too big, and I wanted to keep the script as simple as possible

universe

  • New Member
  • *
  • Posts: 20
Re: PascalScript bug with Lazarus x64
« Reply #6 on: December 21, 2015, 11:01:43 am »
You can try to see what was changed in FPC compiler for dynamic arrays or you can try debug how it is handled:

trunk\compiler\x86_64\cpupara.pas

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/compiler/x86_64/cpupara.pas?sortby=file&view=log

Well, I'll dive into this direction, thanks for the path.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: PascalScript bug with Lazarus x64
« Reply #7 on: December 21, 2015, 07:22:29 pm »
Well, I'll dive into this direction, thanks for the path.

Bug fixed in FreeSparta branch r50964:

http://svn.freepascal.org/svn/lazarus/branches/free-sparta

Related bug report with patch:

http://bugs.freepascal.org/view.php?id=29230

Patch attached also with this post.
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6600
  • Debugger - SynEdit - and more
    • wiki
Re: PascalScript bug with Lazarus x64
« Reply #8 on: December 21, 2015, 08:06:43 pm »
is this fixed upstream too?


hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: PascalScript bug with Lazarus x64
« Reply #9 on: December 21, 2015, 10:15:50 pm »
is this fixed upstream too?

Arghhh... New patch attached, little adjustments for FPC_FULLVERSION. Should be ok for Lazarus + FPC 2.6.x, 3.0, 3.X and newer. Fixed also in Sparta Branch (r50964 + r50967).
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

universe

  • New Member
  • *
  • Posts: 20
Re: PascalScript bug with Lazarus x64
« Reply #10 on: December 22, 2015, 08:17:06 am »
Thanks, I downloaded and applied your last patch, but the problem seems to be partially solved, no infinite loops, but I have wrong integer values, only the first integer is correct.
I'm investigating in this direction, thanks again.

universe

  • New Member
  • *
  • Posts: 20
Re: PascalScript bug with Lazarus x64
« Reply #11 on: December 22, 2015, 08:40:23 am »
Well, it works, I needed to revert the NativeUInt to integer, thanks again, for your fast prompt answer.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: PascalScript bug with Lazarus x64
« Reply #12 on: December 22, 2015, 08:53:58 am »
Well, it works, I needed to revert the NativeUInt to integer, thanks again, for your fast prompt answer.
Phew. Do not stress me  ;). I tested this patch for FPC 2.6.4 , 3.0 and trunk version (both 32 and 64 bit version).
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

universe

  • New Member
  • *
  • Posts: 20
Re: PascalScript bug with Lazarus x64
« Reply #13 on: December 22, 2015, 09:06:13 am »
Hats off  :)

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: PascalScript bug with Lazarus x64
« Reply #14 on: December 22, 2015, 12:06:02 pm »
LOL, Sternas deleted my account on PilotLogic through this message:

Quote
IMO is better to mention author/or just source/link of patch, instead of writing "we" or "me". It is good practice and good karma. Anyway - enjoy, it is open source. Your choice.

PS. He copied attached patch.
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

 

TinyPortal © 2005-2018