[Gambas-user] Distribution of custom shared libraries

Cedron Dawg cedron at exede.net
Sat Feb 23 00:47:46 CET 2019


[...snip...]

> Notes about that:
> 
> I was using the GTK2.  When I upgraded, the Form_Keypress event failed to fire.  I switched to QT4, and it now works fine.  This problem is reproducible with a simple test program.

This has been fixed in commit 
https://gitlab.com/gambas/gambas/commit/aa66e9bcd5f10719428d77014fda3c6df2093f26.

> 
> I have a Struct defined in my code to share with the shared library.
> 
> Public Struct InfoBlock
>      AxisCount As Integer
>      ButtonCount As Integer
>      DriverVersion As Integer
>      Filler As Integer
>      GamepadName[128] As Byte
> End Struct
> 
> typedef struct
> {
>      int     AxisCount;
>      int     ButtonCount;
>      int     DriverVersion;
>      int     Filler;
>      char    GamepadName[128];
> } InfoBlock;
> 
> 
> In the 3.1.1 version, the Filler was not there.  When I upgraded, I needed to add the Filler to make the alignment correct.  I know you mention in the docs that this is a tricky issue, so this is meant to be informative, I'm not looking for any kind of resolution.

Without your full source code, I can't tell you. It's just that a 
structure may be aligned differently by the C compiler, whereas Gambas 
has a deterministic algorithm for that. And the result may not be the 
same as soon as there are holes or unaligned fields in your structure.

AFAIK, there is no norm for structure implementation in C: the compiler 
can reorder the fields and add memory holes as it wants, changing its 
mind between 32 bits / 64 bits and between versions.

So it's almost impossible for an interpreter to deal with that in all 
cases. :-(

-- 
Benoît Minisini

----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----


Thank you.

That was quick.  I figured it was a simple fix.

I am fine with using Qt4.  I am running Linux Mint 17, and both Qt4 and Gtk seem to work.  I originally chose Gtk because I have previously used Tkinter.  I have not found any guidance in the documentation, or web searches, on which I should use.  I get the idea that Qt is preferred, so that is what I will using.

I mentioned the Struct issue because it changed between Gambas versions.  I've gotten burned by this in the past writing C programs to read predefined binaries.  The solution I found then was to use "#pragma pack(1)".  This forces the C compiler to build the struct exactly as specified.

I've added a #pragma pack(1) to my library source and it still works.  :-)

Unrelated question:  Should this mailing list be top posting or bottom posting?



More information about the User mailing list