GNOME Bugzilla – Bug 695970
gchar** struct members cannot be set
Last modified: 2014-12-19 07:06:11 UTC
I cannot use Gtk.RecentData because I cannot set the needed properties. GtkRecentData is a struct but I cannot access to the struct fields using python gir
You should be able to access them as attributes, something like: rd = Gtk.RecentData() print rd.display_name
With PyGObject 3.7.x you actually can set all the string (gchar*) fields, and is_private as well. The only struct field you can't set is the groups list (gchar**). In general it is really hard for an introspection language to correctly set pointer fields in structs, as it has little control and knowledge about its lifecycle and references, so this might not be fixable at all in PyGObject. It would be better if Gtk had a method/constructor for initializing a Gtk.RecentData struct then. But I keep this open as we might be able to handle the gchar** special case with GStrv. You don't need to set a value to .groups, though. I successfully called Gtk.RecentManager.add_full() with a struct with an empty groups.
(In reply to comment #2) > You don't need to set a value to .groups, though. I successfully called > Gtk.RecentManager.add_full() with a struct with an empty groups. This is also an issue for Gtk.RecentFilterInfo. I have a use case for filtering by application, which is another gchar **. Fortunately, the MIME type in my case is unique, so this isn't a big deal. Constructors for Gtk.RecentData and Gtk.RecentFilterInfo would fix the problem nicely however, and would be consistent with other API.
This is pretty much looking like "won't fix" to me. I'm even a bit skeptical about the current support for setting string members because I can only guess they are leaking... We might be able to track members which have been set and free them on PyObject destruction, but it would be tricky. I suggest logging an additional ticket with GTK+ to box these structs and add constructors which take arguments that require memory management.
Marking as won't fix because I think the complexity of tracking assignments for freeing would be overly complicated. Please log bugs for adding constructors and accessor APIs for the structs in question.