GNOME Bugzilla – Bug 103589
const return values causes trouble for python bindings
Last modified: 2004-12-22 21:47:04 UTC
gnome_font_face_get_stdbbox gnome_print_unit_get_identity gnome_print_unit_get_default gnome_print_unit_get_by_name gnome_print_unit_get_by_abbreviation
Bah, i clicked too early. However, the 5 functions i mentioned return const values and this caused trouble for the python bindings. As far as a i know all functions that return objects in Gtk/Gnome etc return non-const objects.
But this functions are not returning object but structures which should not be freed. It seems to me that we have to fix the python bindings, not gnome-print. Removing const from those functions is wrong.
Well, it's not a normal plain C struct. It's a GBoxed type. It's the same for boxed types in Gtk+ too (GtkTextIter,GtkIconSet,GtkTreePath etc) None of them should be freed using g_free, instead a special custom function should be used to "free" them and in the case of GnomePrintUnit , nothing is done. So there is nothing wrong in removing const, it's self explainatory that should should use the free func. I still think it's a bug in gnome-print and not in the python bindings.
The only reason it is a boxed type is because the bindings required it. I would like to fix this on the bindings side, it helps development having "const GnomePrintUnit *u;" in the application side. People free this structure all the time, and if you have to declare them as const in your code, you get the compiler to catch this errors. Same goes for the face_stdbox one.
I really don't want to change this inside libgnomeprint. Jamesh: ?
due to the way the "const" keyword works in C, it is not really appropriate to indicate that the function is returning a borrowed reference (ie. the function doesn't g_object_ref() the return value). With a GObject, it should always be okay to g_object_ref() it to get a reference of your own. However, the const keyword in this case indicates that you shouldn't be modifying the memory the pointer points at. As this includes the reference count field, it doesn't make sense to have a const GObject (C++ has syntax to handle this sort of thing with the mutable attribute, iirc).
I agree with that. But the only reason this structures are a Boxed object is because the bindings needed them to be. They where a C struct before the first patch for the python bindings. gnome_font_face_get_stdbbox returns a ArtDRect we have tons of const retuns of libart structures in other modules as well.
My mistake. I thought we were talking about some GObjects :) The GnomePrintUnit things should be fine as they are. It looks entirely correct to mark them as const. The same goes for the ArtDRect thing. This is probably NOTABUG
Closing as NOTABUG.