Recent

Author Topic: [SOLVED] {$push} and {$pop} on trunk [2024/02/13] doen't work  (Read 3630 times)

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
[SOLVED] {$push} and {$pop} on trunk [2024/02/13] doen't work
« on: February 13, 2024, 06:02:17 pm »
In the new Trunk 3.3.1, on a 64bit machine, the behavior with a an
 y : array [0..0] of xxx;
is changed :(

I have:
Code: Pascal  [Select][+][-]
  1. {$push}
  2. {$packrecords 4}
  3.         MIDIPacket = record
  4.                 timeStamp : MIDITimeStamp;
  5.                 length : UInt16;
  6.                 data : packed array [0..255] of Byte;
  7.         end;
  8.         MIDIPacketPtr = ^MIDIPacket;
  9. {$pop}
  10.  

this structure is 268 bytes long, this is correct


now i have:
Code: Pascal  [Select][+][-]
  1. {$push}
  2. {$packrecords 4}
  3.         MIDIPacketList = record
  4.                 numPackets: UInt32;    
  5.                 packet: array [0..0] of MIDIPacket;
  6.         end;
  7. {$pop}
  8.  

this structure is now 280 byte long!

in the old FPC Trunk 3.3.1 [about half a year ago]
this structure was 272 bytes long, and this is the correct size!
so I can work with a ABI...

As I understand it should be:
sizeof(Uint32) + sizeof(MIDIPacket) so 272 bytes, but its not.
something was changed in the compiler.

what was changed and how to fix(is there a compiler switch)?
« Last Edit: February 22, 2024, 11:07:40 am by Key-Real »

Fibonacci

  • Hero Member
  • *****
  • Posts: 669
  • Internal Error Hunter
IDK why, but:

If you remove your push/pop then it works. You can use {$packrecords DEFAULT} to restore default padding.

Code: Pascal  [Select][+][-]
  1. type
  2.   MIDITimeStamp = qword;
  3.  
  4.   //{$push}
  5.   {$packrecords 4}
  6.           MIDIPacket = record
  7.                   timeStamp : MIDITimeStamp;
  8.                   length : UInt16;
  9.                   data : packed array [0..255] of Byte;
  10.           end;
  11.           MIDIPacketPtr = ^MIDIPacket;
  12.   //{$pop}
  13.   {$packrecords DEFAULT}
  14.  
  15.   //{$push}
  16.   {$packrecords 4}
  17.           MIDIPacketList = record
  18.                   numPackets: UInt32;
  19.                   packet: array [0..0] of MIDIPacket;
  20.           end;
  21.   {$packrecords DEFAULT}
  22.   //{$pop}
  23.  
  24. begin
  25.   writeln('sizeof midi = ', sizeof(MIDIPacket));
  26.   writeln('sizeof list = ', sizeof(MIDIPacketList));

Code: Pascal  [Select][+][-]
  1. sizeof midi = 268
  2. sizeof list = 272

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
indeed!

now the MIDI stuff works.

but I think I can't live without
{$push} and {$pop}
!

because this affects the FPC Sources for cocoa

paule32

  • Sr. Member
  • ****
  • Posts: 404
Coco is Mac OS
So, you could involve {$IFDEF... to check the Compiler Version, and Platform
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
@Paule32:

this should work for every compiler version and every os!

The question is:

why {$push} and {$pop} doesn't work now as expected?

Bart

  • Hero Member
  • *****
  • Posts: 5558
    • Bart en Mariska's Webstek
On Windows the code (with the {$push}/{$pop} has the same output for i386 as x86_64, both with fpc 3.2.2 as fpc main (3.3.1-3157-g728be94328)
Code: [Select]
sizeof midi = 268
sizeof list = 272

My fpc is from 23-nov-2023.
I suggest to test with latest fpc main.
If it sill reporst the values as in your first example, either ask on fpc devel ML (if you're not certain this is indeed a bug), or file a bugreport in the fpc bugtracker.

Bart

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
OK on

Free Pascal Compiler version 3.3.1 [2024/02/13] for aarch64

this doesn't work!!!!!

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
I done a

git clone https://gitlab.com/freepascal.org/fpc/source.git fpc

and than compile it and than my app

5 min ago

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
seems to be an Error in the Compiler

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
can somebody verify this?

Awkward

  • Full Member
  • ***
  • Posts: 145
Re: {$push} and {$pop} on trunk [2024/02/13] for aarach64 doen't work
« Reply #10 on: February 13, 2024, 07:44:41 pm »
Sorry, can i ask, why you use packed array but not packed record?

Key-Real

  • Sr. Member
  • ****
  • Posts: 386
Re: {$push} and {$pop} on trunk [2024/02/13] for aarach64 doen't work
« Reply #11 on: February 13, 2024, 08:19:53 pm »
If You use packed record there have to be a Uint16 padding after length so i use normal record with {$packrecords 4}
the packed array is from original source, i don't knew but i think it can be whitout

rvk

  • Hero Member
  • *****
  • Posts: 6704
Re: {$push} and {$pop} on trunk [2024/02/13] for aarach64 doen't work
« Reply #12 on: February 13, 2024, 11:06:16 pm »
Latest x86_64 on Windows seems fine.
Also with aarch64 on Raspberry Pi 4, I can't reproduce this problem.

(Both latest trunk version from 1 hour ago)

Did you try what happens if you put both record definitions in the same {$packrecords 4} block?
( so don't {$pop} and {$push} until the last (MIDIPacketList) is declared )

Otherwise create a small test-file and also mention what compiler options you set with fpc.

Fibonacci

  • Hero Member
  • *****
  • Posts: 669
  • Internal Error Hunter
Re: {$push} and {$pop} on trunk [2024/02/13] for aarch64 mac doen't work
« Reply #13 on: February 13, 2024, 11:57:38 pm »
Ok, can someone explain this?

https://streamable.com/v1hl39

Fresh install of latest trunk.

Check yourself:
Code: Pascal  [Select][+][-]
  1. type
  2.   MIDITimeStamp = qword;
  3.  
  4.   {$push}
  5.   {$packrecords 4}
  6.           MIDIPacket = record
  7.                   timeStamp : MIDITimeStamp;
  8.                   length : UInt16;
  9.                   data : packed array [0..255] of Byte;
  10.           end;
  11.           MIDIPacketPtr = ^MIDIPacket;
  12.   {$pop}
  13.  
  14.   //  { comment and uncomment this comment }
  15.  
  16.   {$push}
  17.   {$packrecords 4}
  18.           MIDIPacketList = record
  19.                   numPackets: UInt32;
  20.                   packet: array [0..0] of MIDIPacket;
  21.           end;
  22.   {$pop}
  23.  
  24. begin
  25.   writeln('sizeof midi = ', sizeof(MIDIPacket));
  26.   writeln('sizeof list = ', sizeof(MIDIPacketList), ' <---- WATCH THIS');
  27.  
  28.   readln;
  29. end.

rvk

  • Hero Member
  • *****
  • Posts: 6704
Re: {$push} and {$pop} on trunk [2024/02/13] for aarch64 mac doen't work
« Reply #14 on: February 14, 2024, 04:12:01 am »
So no special options?

For me
Quote
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 6.1.0-rpi4-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.54-1+rpt2 (2023-10-05) aarch64 GNU/Linux
pi@raspberrypi:~ $ fpc a.pas
Free Pascal Compiler version 3.3.1 [2024/02/13] for aarch64
Copyright (c) 1993-2024 by Florian Klaempfl and others
Target OS: Linux for AArch64
Compiling a.pas
Assembling program
Linking a
17 lines compiled, 0.3 sec, 166500 bytes code, 62954 bytes data
pi@raspberrypi:~ $ ./a
sizeof midi = 268
sizeof list = 272 <---- WATCH THIS

pi@raspberrypi:~ $

What OS do you use exactly?

The only way I get 268/280 is if I remove the second packrecords and leave the first.

(17 lines is because my paste mest up a bit. Code is the same.)
« Last Edit: February 14, 2024, 04:14:27 am by rvk »

 

TinyPortal © 2005-2018