Re: [Vala] A struct in a vapi file with undefined contents?



And, naturally, if I'd just not made a silly typo when I had tried
this, I would have seen valac doesn't complain at all and it works the
way I want, allocating the correct space in memory. Hooray!

So, I have the following in my vapi file now…

[CCode (cname = "FIT_CONVERT_STATE")]
public struct State {
// Private
}

Sorry about the noise. Of course, please do point out if this is going
to end poorly :)

--
Dylan

On 28 July 2013 22:28, Dylan McCall <dylanmccall gmail com> wrote:
Sometimes, when I find myself working with a (plain) C library through
Vala, I end up using a pattern like this. I really don't like it:

void * convert_state = Fit.create_convert_state();
Fit.Convert.init(convert_state, true);

In this case, Fit.Convert.init is part of the original library, which
I made a vapi file for. It takes a reference to convert_state, which
it writes to. Fit.create_convert_state() is a function I created in a
small C wrapper library. The entire point of it is to allocate space
for a struct on the heap (for Fit.Convert.init), and then return a
pointer to that struct. The struct isn't in the vapi file because it's
huge and complicated and it's really internal to that library. Its
contents aren't _interesting_ to the Vala program - just that it's of
a particular size.

Is there a way to add a struct with undefined contents in a vapi file?
That way I can maybe do something like this with the example?

ConvertState convert_state = ConvertState();
Fit.Convert.init(convert_state, true);

We wouldn't be able to access any members in convert_state, but we'd
be spared ugly void pointers.

…or am I looking at this the wrong way? I probably am. Any help is
appreciated :)

--
Dylan


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