[Vala] lots of incorrect bindings for callbacks in gtk api



Hi everyone,

I've been working on a gtk app in vala which uses a GtkTreeView and I've noticed these two functions in the vapi are wrong:

public void set_row_separator_func (Gtk.TreeViewRowSeparatorFunc func, void* data, Gtk.DestroyNotify destroy);
public int insert_column_with_data_func (int position, string title, Gtk.CellRenderer cell, Gtk.TreeCellDataFunc func, void* data, GLib.DestroyNotify dnotify);

Using them makes compilation fail because the void* data part should be removed as it's part of the callback, as far as I can tell. However, the destroy function doesn't seem to make sense for vala, as it's for freeing the memory pointed to by "data", and I believe that's being used for the class instance to pass to the callback function, which gtk should never need to free. Does that mean the destroy function should always be passed null in vala applications?

I've noticed these kinds of callbacks are used a lot in the gtk API, and so I searched in the vapi for more occurances and I found these: (along with many more, too many to list here)

Gtk.Notebook:
public static void set_window_creation_hook (Gtk.NotebookWindowCreationFunc func, void* data, GLib.DestroyNotify destroy);

Gtk.TextBuffer:
public Gdk.Atom register_deserialize_format (string mime_type, Gtk.TextBufferDeserializeFunc function, GLib.DestroyNotify user_data_destroy);
public Gdk.Atom register_serialize_format (string mime_type, Gtk.TextBufferSerializeFunc function, GLib.DestroyNotify user_data_destroy);

Gtk.AboutDialog:
public static void set_email_hook (Gtk.AboutDialogActivateLinkFunc func, GLib.DestroyNotify? destroy);
public static void set_url_hook (Gtk.AboutDialogActivateLinkFunc func, GLib.DestroyNotify? destroy);

It looks like in other situations like these, there has been one of three things done:
1) Leave void* data and GLib.DestroyNotify destroy (which won't compile because vala will call it with too many arguments)
2) Remove void* data but leave GLib.DestroyNotify destroy (which would compile with a warning because of passing null to an argument that doesn't expect null)
3) Remove void* data and change GLib.DestroyNotify so that it can accept null (which compiles fine but requires you to always pass null to the last argument)

I looked at gtk+-2.0.metadata and I saw this:
gtk_about_dialog_set_email_hook.data hidden="1"
gtk_about_dialog_set_email_hook.destroy nullable="1"

So it looks like the data argument is hidden that way. The destroy argument says it's nullable which is true, but is there a way to say it should be both hidden from the user AND always passed null?



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