Re: [Vala] How to get the size of structure?



On Mon, Feb 15, 2010 at 15:50:37 -0600, Sandino Flores Moreno wrote:
Hello.

I'm wrapping a non-glib library.

That library makes use of lot of structures,
and any instance of those structures must be initialized
with the size of the structure, and the version of the API used.

    http://github.com/tigrux/omx-vala/blob/master/libomxil-bellagio.vapi#L197

For example:

    Omx.Audio.Param.Mp3 param = {};
    param.size = sizeof (Omx.Audio.Param.Mp3);
    param.version = API_VERSION;

Vala restricts the use of sizeof to types only, so it fails
to compile when I try:

    param.size = sizeof (param);

So, the question is:

How to make Vala automatically assign the size of the structure to the
field `size`
of those structures?

Well, not automatically, but you can do it in the bindings. The trick is,
that the .vapi file can contain function definitions. So for each of these
structures you define an init function that assigns the size, maybe the API
version and clears the rest as appropriate. Than it should be possible to set
it as initialization function for the structure via some [CCode(...)]
annotation, but I don't currently know which. Try digging in the existing
.vapis.

The idea is that something like:

    Omx.Audio.Param.Mp3 param = Omx.Audio.Param.Mp3();

is automatically expanded to something like:

    OMX_AUDIO_PARAM_MP3 param;
    memset(&param, 0, sizeof(param));
    param.nSize = sizeof(param);
    param.nVersion = API_VERSION

Thanks in advance.
_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list
-- 
                                                 Jan 'Bulb' Hudec <bulb ucw cz>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]