[fpc-pascal] FPC and GTK2: problems with GTKCombo

Michalis Kamburelis michalis at camelot.homedns.org
Sat Apr 23 12:08:31 CEST 2005


Hi

I found the problem: TGtkBox record layout and size is not correct for 
Win32 GTK 2 libraries. This causes that "PGtkCombo(c)^.entry" does not 
work as it should, because address of "entry" field in "TGtkCombo" is 
different than it should be. TGtkBox is currently defined as

    TGtkBox = record
         container : TGtkContainer;
         children : PGList;
         spacing: gint16;
         flag0: word;
      end;

and with "packing C" FPC understands that spacing and flag0 are packed
together into one 32 bit value. And this is correct for GTK 2 Linux
libraries, but surprisingly inside GTK 2 Win32 dlls GtkBox record (even
though declared the same way in C headers) has different layout, namely
both spacing and flag0 are expanded into 32-bit values. This means that
correct definition of TGtkBox should be

    TGtkBox = record
         container : TGtkContainer;
         children : PGList;
         spacing: {$ifdef WIN32} LongInt {$else} gint16 {$endif};
         flag0: {$ifdef WIN32} LongInt {$else} word {$endif};
      end;

No, this is *not* a bug somewhere in general FPC record aligning
algorithm. You can treat it as a bug in FPC GTK 2 bindings, or you can
treat it as a bug in Win32 GTK 2 libraries (because they apparently are
compiled in such way that struct alignment is different than in Linux).

I'm attaching test program test_align_differ.pas, compile and run this 
under Win32 and Linux and watch what it prints on stdout under each OS. 
Results prove that

1. sizes of all three records (TGtkContainer, TGtkBoxModified, TGtkBox)
are the same under Win32 and Linux. So it's not a bug inside FPC 
compiler with aligning records, because both under Win32 and Linux 
records are aligned the same in FPC units.

2. At the same time, you can see that definition of TGtkBoxModified does
not work as it should under Linux and definition of TGtkBox does not
work as it should under Win32.

This proves that structures are aligned differently in Linux and Win32
libraries.

Michalis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_align_differ.pas
Type: text/x-pascal
Size: 2201 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20050423/e77659e1/attachment.pas>


More information about the fpc-pascal mailing list