After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 103589 - const return values causes trouble for python bindings
const return values causes trouble for python bindings
Status: RESOLVED NOTABUG
Product: gnome-print
Classification: Deprecated
Component: general
0.20
Other Linux
: Normal normal
: ---
Assigned To: Chema Celorio
Chema Celorio
Depends on:
Blocks:
 
 
Reported: 2003-01-15 18:58 UTC by Johan (not receiving bugmail) Dahlin
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Johan (not receiving bugmail) Dahlin 2003-01-15 18:58:12 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
Comment 1 Johan (not receiving bugmail) Dahlin 2003-01-15 18:59:34 UTC
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.
Comment 2 Chema Celorio 2003-01-15 19:20:48 UTC
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.
Comment 3 Johan (not receiving bugmail) Dahlin 2003-01-15 19:25:54 UTC
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.
Comment 4 Chema Celorio 2003-01-16 03:01:22 UTC
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.
Comment 5 Chema Celorio 2003-01-19 04:15:15 UTC
I really don't want to change this inside libgnomeprint.

Jamesh: ?
Comment 6 James Henstridge 2003-01-19 11:33:34 UTC
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).
Comment 7 Chema Celorio 2003-01-19 22:01:19 UTC
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. 
Comment 8 James Henstridge 2003-01-20 03:49:28 UTC
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
Comment 9 Chema Celorio 2003-01-20 17:08:01 UTC
Closing as NOTABUG.