binding of a C struct
- From: PICCA Frederic-Emmanuel <frederic-emmanuel picca synchrotron-soleil fr>
- To: "gir-devel-list gnome org" <gir-devel-list gnome org>
- Subject: binding of a C struct
- Date: Wed, 20 Apr 2016 08:34:34 +0000
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);
So I have this
/**
* hkl_geometry_sample_rotation_get:
* @self: the self @HklGeometry@
* @sample: the rotated sample.
*
* return the rotation part of the given sample in the laboratory basis.
*
* Returns: the rotation express as a quaternion.
**/
HklQuaternion hkl_geometry_sample_rotation_get(const HklGeometry *self,
const HklSample *sample)
{
return darray_item(self->holders, 0)->q;
}
this produce in the gir
<record name="Quaternion"
c:type="HklQuaternion"
glib:type-name="HklQuaternion"
glib:get-type="hkl_quaternion_get_type"
c:symbol-prefix="quaternion">
<field name="data" writable="1">
<array zero-terminated="0" c:type="double" fixed-size="4">
<type name="gdouble" c:type="double"/>
</array>
</field>
</record>
and
<method name="sample_rotation_get"
c:identifier="hkl_geometry_sample_rotation_get">
<doc xml:space="preserve">return the rotation part of the given sample in the laboratory basis.</doc>
<return-value transfer-ownership="full">
<doc xml:space="preserve">the rotation express as a quaternion.</doc>
<type name="Quaternion" c:type="HklQuaternion"/>
</return-value>
<parameters>
<instance-parameter name="self" transfer-ownership="none">
<doc xml:space="preserve">the self @HklGeometry@</doc>
<type name="Geometry" c:type="const HklGeometry*"/>
</instance-parameter>
<parameter name="sample" transfer-ownership="none">
<doc xml:space="preserve">the rotated sample.</doc>
<type name="Sample" c:type="const HklSample*"/>
</parameter>
</parameters>
</method>
the hkl_quaternion_get_type method is here
#define HKL_TYPE(type, camelcase_type, copy, free) \
GType hkl_## type ## _get_type (void) { \
static volatile gsize hkl_type_id__volatile = 0; \
if (g_once_init_enter (&hkl_type_id__volatile)) { \
GType hkl_type_id; \
hkl_type_id = g_boxed_type_register_static ( \
#camelcase_type, \
(GBoxedCopyFunc) copy, \
(GBoxedFreeFunc) free); \
g_once_init_leave (&hkl_type_id__volatile, hkl_type_id); \
} \
return hkl_type_id__volatile; \
}
HKL_TYPE(quaternion, HklQuaternion, hkl_quaternion_dup, hkl_quaternion_free);
BUT
When I I using this from python I get a segfault.
#0 0xb681b5ab in hkl_geometry_sample_rotation_get (self=0x872a740, sample=0xb6bfb119 <g_private_get+9>) at
hkl-geometry.c:807
#1 0xb6d8ba82 in ffi_call_SYSV () from /usr/lib/i386-linux-gnu/libffi.so.6
#2 0xb6d8b556 in ffi_call () from /usr/lib/i386-linux-gnu/libffi.so.6
#3 0xb6d5a6df in ?? () from /usr/lib/python2.7/dist-packages/gi/_gi.so
#4 0xb6d5b214 in ?? () from /usr/lib/python2.7/dist-packages/gi/_gi.so
#5 0xb6d5c160 in ?? () from /usr/lib/python2.7/dist-packages/gi/_gi.so
#6 0xb6d5aeb0 in ?? () from /usr/lib/python2.7/dist-packages/gi/_gi.so
#7 0xb6d5aef1 in ?? () from /usr/lib/python2.7/dist-packages/gi/_gi.so
#8 0xb6d4ed1e in ?? () from /usr/lib/python2.7/dist-packages/gi/_gi.so
#9 0x08107d5f in PyObject_Call (kw=<optimized out>, arg=<optimized out>, func=<optimized out>) at
../Objects/abstract.c:2529
#10 do_call (nk=<optimized out>, na=<optimized out>, pp_stack=<optimized out>, func=<optimized out>) at
../Python/ceval.c:4251
#11 call_function (oparg=<optimized out>, pp_stack=<optimized out>) at ../Python/ceval.c:4056
#12 PyEval_EvalFrameEx () at ../Python/ceval.c:2679
#13 0x081078bb in fast_function (nk=<optimized out>, na=<optimized out>, n=<optimized out>,
pp_stack=<optimized out>, func=<optimized out>) at ../Python/ceval.c:4119
#14 call_function (oparg=<optimized out>, pp_stack=<optimized out>) at ../Python/ceval.c:4054
#15 PyEval_EvalFrameEx () at ../Python/ceval.c:2679
so my question is what is the right way to expose a struc in a binding with gobject.
thanks for your help
Frédéric
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]