Re: [Vala] A struct in a vapi file with undefined contents?
- From: Tal Hadad <tal_hd hotmail com>
- To: Vala Mail List <vala-list gnome org>
- Subject: Re: [Vala] A struct in a vapi file with undefined contents?
- Date: Tue, 30 Jul 2013 18:46:19 +0300
It's sounds like what you want is a compact class:
[CCode (cname = "FIT_CONVERT_STATE")]
[Compact]
public class a {
}
Compact class is better, since it's always treated like pointer.
In struct you may accidentally copy memory(zero in your case) if you do
a value assignment.
Tal
From: dylanmccall gmail com
Date: Mon, 29 Jul 2013 23:37:03 -0700
To: vala-list gnome org
Subject: 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
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]