Re: Introspecting functions taking variable arguments



On Mon, Feb 6, 2012 at 12:57, Daniel Trebbien <dtrebbien gmail com> wrote:
> I ended up looking through GTK+ 3 for some examples, of which there
> are a few ...v() functions that are introspectable.
>
> The pattern seems to be to copy the function signature, append `v` to
> the function name (sometimes with additional words), and replace the
> ... variable arguments list with two parameters: GValue *args and gint
> n_args. Also, in the GTK-Doc comment block for the ...v() variant,
> there is a "Rename to: " line.
>
> For example:
>
> void          gtk_tree_store_set              (GtkTreeStore *tree_store,
>                                               GtkTreeIter  *iter,
>                                               ...);
>
> /**
>  * gtk_tree_store_set_valuesv:
>  * ...
>  * Rename to: gtk_tree_store_set
>  **/
> void
> gtk_tree_store_set_valuesv (GtkTreeStore *tree_store,
>                            GtkTreeIter  *iter,
>                            gint         *columns,
>                            GValue       *values,
>                            gint          n_values);
>
> AFAIK, calling the set() method on a Gtk.TreeStore from a language
> binding actually invokes gtk_tree_store_set_valuesv().

Yes, in those cases I would consider the varargs variants as a C
convenience, so introspectable="0" could make sense.

But there's the case of API in GVariant (and maybe others) in which
the logic is implemented making use of valist, so there's no *v()
variant.

In order to call a variadic function deciding the actual arguments at
runtime, you have to know the layout of the call stack in that
particular platform and that's what FFI is for.

Regards,

Tomeu

> In #gedit, Ignacio "nacho" Casal Quinteiro wrote "Usually not
> introspectable means [varargs] or wrong annotations ... va_list is
> also not introspectable. You need to pass i.e an array."
>
> Daniel Trebbien
>
> On 2012-02-05, Daniel Trebbien <dtrebbien gmail com> wrote:
>> On
>> <http://live.gnome.org/PyGObject/IntrospectionPorting#Non-introspectable_functions.2BAC8-methods>,
>> there is the following note:
>>
>>> Varargs cannot be handled safely by libgirepository. In these cases there
>>> are
>>> often alternatives available (such as gtk_cell_area_cell_set_property()).
>>> For
>>> other cases libraries now often have a ..._v() counterpart which takes a
>>> list
>>> instead of variable arguments.
>>
>> What are some good examples of ..._v() counterparts? I thought that
>> all I needed to do was use a va_list, but that doesn't work.
>>
>> What are good ways of making variadic functions introspectable?
>>
>> Daniel Trebbien
>>
> _______________________________________________
> python-hackers-list mailing list
> python-hackers-list gnome org
> http://mail.gnome.org/mailman/listinfo/python-hackers-list


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