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 446874 - g_type_ensure()
g_type_ensure()
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-06-12 20:38 UTC by Behdad Esfahbod
Modified: 2007-06-14 20:50 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Behdad Esfahbod 2007-06-12 20:38:50 UTC
Works around the G_GNUC_CONST in declaration of get_type() functions by forcing a call:

#define g_type_ensure(type) \
  G_STMT_START { volatile GType __dummy = (type); } G_STMT_END

So you write:

  g_type_ensure (GTK_TYPE_MESAGE_DIALOG);

and be safe.

Ref: http://wingolog.org/archives/2005/03/24/98 and others.
Logs of #gtk+ from few minutes ago.
Comment 1 Tim Janik 2007-06-14 20:50:47 UTC
i don't like the idea of adding such a thing to glib at all.
the flagging of _get_type functions as GNUC_CONST is *wrong* in the first place, glib is abusing gcc there, and i'd personally prefer to get rid of all such abuses. adding API for users to work around glib's own insanity is taking it too far.

if you really want to "fix" this abuse the right way, not forgo GNUC_CONST flagging and make the world a better place, please file a bug against gcc for __attribute__((constant_registry)) or a similar name, that offers the semantics of pure/const but guarantees to ever only optimize calls that gcc can prove are *successive* and not initial calls to a function.