Hi! On Wed, 2016-04-20 at 08:34 +0000, PICCA Frederic-Emmanuel wrote:
Hello,
here my C struct
typedef struct _HklQuaternion HklQuaternion;
struct _HklQuaternion
{
double data[4];
};
I want to annotate a method which return an HklQuaternion
HklQuaternion hkl_geometry_sample_rotation_get(const HklGeometry
*self, const HklSample *sample);
[...]
You cannot return structs by value in gobject-introspection: if you
return a struct, it's expected to be a pointer to a heap allocated
object.
You have three options:
If heap allocation is not a problem:
/**
* @self:
* @sample:
*
* Returns: (transfer full)
*/
HklQuaternion *hkl_geometry_sample_rotation_get(const HklGeometry
*self, const HklSample *sample) {
return hkl_quaternion_dup(&darray_item(self->holders, 0)->q);
}
If you're ok with tying lifetimes to the container:
(for C/Vala only - in Python or gjs a copy is always made for memory
safety)
/**
* @self:
* @sample:
*
* Returns: (transfer none)
*/
HklQuaternion
*hkl_geometry_sample_rotation_get(const HklGeometry *self, const
HklSample *sample) {
return &darray_item(self->holders, 0)->q;
}
If you're ok with a slightly more awkward API from C (with no
difference from introspection):
/**
* @self:
* @sample:
* @quat: (out caller-allocates)
*/
void
hkl_geometry_sample_rotation_get(const HklGeometry *self, const
HklSample *sample, HklQuaternion *quat) {
*quat = darray_item(self-
holders, 0)->q;
} Hope this helps, Giovanni
Frédéric _______________________________________________ gir-devel-list mailing list gir-devel-list gnome org https://mail.gnome.org/mailman/listinfo/gir-devel-list
Attachment:
signature.asc
Description: This is a digitally signed message part