[Python-Dev] example of module interface to a varargs function?

Skip Montanaro skip@pobox.com (Skip Montanaro)
Tue, 19 Jun 2001 12:44:47 -0500


I am trying to add a module interface to some of the bits missing from
PyGtk2.  Some functions I'm interested in have varargs signatures, e.g.:

    void
    gtk_binding_entry_add_signal (GtkBindingSet  *binding_set,
				  guint           keyval,
				  guint           modifiers,
				  const gchar    *signal_name,
				  guint           n_args,
				  ...)

>From Python, this would be called something like

    bs = gtk.GtkBindingSet("somename")
    bs.add_signal(gtk.GDK.K_Up, 0, "scroll_vertical",
                  gtk.TYPE_ENUM, gtk.SCROLL_STEP_BACKWARD,
		  gtk.TYPE_FLOAT, 0.0)

with n_args inferred from the number of arguments following the
"scroll_vertical" parameter.  I'm a bit stumped how to handle this with the
PyArg_Parse* routines.  (I'll worry about calling
gtk_binding_entry_add_signal after I figure out how to marshal the args.)
The only place in the standard modules I saw that processed a truly
arbitrary number of arguments is the struct_pack method of the struct
module, and it doesn't use PyArg_Parse* to process them.  Can someone point
me to an example of marshalling arbitrary numbers of arguments then calling
a varargs function?

Thx,

Skip