[pygtk] Auxiliary argument for array (from GI)

Damien Caliste damien.caliste at cea.fr
Tue Aug 17 22:35:24 WST 2010


Hello,

   I'm porting my application to use GObject Introspection, and thus
testing the Python bindings provided by pygobject-2.21.5. Thanks a lot
for all these pieces of code, it really brings exciting new
possibilities.

   My issue is when using a prototype of function like this:
/**
 * setPlanetData:
 * @nPlanets: number of planets in the solar system.
 * @arrayDiameter: (in) (array length=nPlanets): diameters of planets.
 * @arrayMass: (in) (array length=nPlanets): masses of planets.
 *
 * Set-up the number of planets and their characteristics.
 */
gboolean setPlanetData(gint nPlanets, gfloat *arrayDiameter, gflaot
*arrayMass);

The .gir file is properly created with a method, a return value and
three parameters, two of them being arrays which length is given by
parameter id=0.

But, when using gi.repository in Python, my method setPlanetData takes
exactly one argument while I was waiting for two.

It cames from the method '_prepare_invocation_state' (file
pygi-invoke.c) which counts the number of in auxiliary arguments. In
case of an array, line 184, the argument positioned at
length_arg_pos, is set auxiliary and n_aux_in_args is increased. But in
my function case, the argument nPlanets in used twice and thus
n_aux_in_args is incremented twice while nPlanets is a unique argument.

There are two possibilities:
- one should not write C functions with such a prototype, I may then
suggest the attached patch1, adding a warn_if_fail when the argument
has already the auxiliary flag.
- one should count the argument as auxiliary, only if it is not already
auxiliary, see the attached patch2.

Thanks for reviewing this and giving your opinion. If this issue is
relevant, I can open a bug and attached whatever patch is adapted.

Regards,

Damien.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch1
Type: application/octet-stream
Size: 518 bytes
Desc: not available
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20100817/2fc6c088/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch2
Type: application/octet-stream
Size: 1061 bytes
Desc: not available
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20100817/2fc6c088/attachment-0001.obj>


More information about the pygtk mailing list