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 601686 - Implement diagnostic mode
Implement diagnostic mode
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
unspecified
Other All
: Normal enhancement
: 3.0
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2009-11-12 13:17 UTC by Christian Dywan
Modified: 2016-05-30 23:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Implement GTK_ENABLE_DIAGNOSTIC, GTK_PARAM_DEPRECATED, GTK_OBJECT_WARN_UNSUPPORTED_PROPERTY (5.16 KB, patch)
2009-11-12 14:20 UTC, Christian Dywan
none Details | Review
Introduce G_PARAM_DEPRECATED and G_ENABLE_DIAGNOSTIC (2.57 KB, patch)
2010-06-18 14:32 UTC, Christian Dywan
reviewed Details | Review
Introduce G_PARAM_DEPRECATED and G_ENABLE_DIAGNOSTIC #2 (2.65 KB, patch)
2010-06-18 17:37 UTC, Christian Dywan
committed Details | Review
Introduce GTK_ENABLE_DIAGNOSTIC for containers (2.06 KB, patch)
2010-07-02 18:35 UTC, Christian Dywan
reviewed Details | Review
Introduce G_SIGNAL_DEPRECATED flag (3.07 KB, patch)
2010-07-02 19:14 UTC, Christian Dywan
reviewed Details | Review
Introduce G_SIGNAL_DEPRECATED flag #2 (3.09 KB, patch)
2010-07-13 15:44 UTC, Christian Dywan
reviewed Details | Review
Introduce GTK_ENABLE_DIAGNOSTIC for containers #2 (2.78 KB, patch)
2010-07-13 16:33 UTC, Christian Dywan
reviewed Details | Review
Introduce G_SIGNAL_DEPRECATED flag #3 (3.72 KB, patch)
2010-10-22 14:32 UTC, Christian Dywan
needs-work Details | Review

Description Christian Dywan 2009-11-12 13:17:32 UTC
One of the tasks for GTK 2.90 is a diagnostic mode that can be enabled at will and triggers warnings when using deprecated properties or accessing internal widgets.

http://live.gnome.org/GTK%2B/3.0/Tasks#P7
Comment 1 Christian Dywan 2009-11-12 14:20:23 UTC
Created attachment 147579 [details] [review]
Implement GTK_ENABLE_DIAGNOSTIC, GTK_PARAM_DEPRECATED, GTK_OBJECT_WARN_UNSUPPORTED_PROPERTY

This patch implements a what could be diagnostic mode. It's not usable as-is and mainly serves to evaluate the idea.

The environment variable GTK_ENABLE_DIAGNOSTIC is used to determine whether diagnostic mode should be enabled.

A new GParamFlag GTK_PARAM_DEPRECATED is introduced that can be used when installing properties to flag them as deprecated. In the patch it's used in GtkNotebook as an example.

The macro GTK_OBJECT_WARN_UNSUPPORTED_PROPERTY is to be inserted in _set_property and _get_property implementations. It will expand to a warning if diagnostic mode is enabled and either a deprecated property is being used or properties of an internal child are being modified.

GtkContainer emits a warning if an internal child is added to or removed. This needs work in individual widgets to unset the GTK_COMPOSITE_CHILD flag to prevent false positives.

GtkStatusbar is modified to mark its children as composite children. In conjunction with the above, it will emit warnings when for example Totem or Midori is run since they alter statusbar packing.
Comment 2 Javier Jardón (IRC: jjardon) 2010-03-24 00:54:47 UTC
punting to 3.0
Comment 3 Stefan Sauer (gstreamer, gtkdoc dev) 2010-06-06 18:54:47 UTC
Christian, could we please get GTK_PARAM_DEPRECATED + GTK_OBJECT_WARN_UNSUPPORTED_PROPERTY as a patch for glib. Then I could also do gtk-doc support for deprecated properties and people can use that (e.g. in gstreamer).

I also wonder if you would maybe want to hide
if (g_getenv ("GTK_ENABLE_DIAGNOSTIC"))
behine a macros, so that later on one could e.g. also add a commandlne option or cache the result in a global variable.
Comment 4 Christian Dywan 2010-06-18 14:32:34 UTC
Created attachment 164009 [details] [review]
Introduce G_PARAM_DEPRECATED and G_ENABLE_DIAGNOSTIC

This patch introduces G_PARAM_DEPRECATED and generates the warning internally in GObject.

We will still need something in GTK+ if we want composite container warnings.
Comment 5 Emmanuele Bassi (:ebassi) 2010-06-18 14:46:02 UTC
Review of attachment 164009 [details] [review]:

::: gobject/gobject.c
@@ +1029,3 @@
+      enable_diagnostic = g_getenv ("G_ENABLE_DIAGNOSTIC");
+    {
+  if (G_UNLIKELY (!enable_diagnostic))

why an 'else if'? it would be more clear if the conditions where split - the first one to initialize enable_diagnostic and the second one checking it.

also, I wonder if this block might go under a #if G_ENABLE_DEBUG ... #endif guard; though I'm not definitely sure.

::: gobject/gparam.h
@@ +184,2 @@
 #define	G_PARAM_USER_SHIFT	(8)
  */

shouldn't this be bumped to 9?
Comment 6 Christian Dywan 2010-06-18 17:37:05 UTC
Created attachment 164029 [details] [review]
Introduce G_PARAM_DEPRECATED and G_ENABLE_DIAGNOSTIC #2

Separated the if and bumped G_PARAM_USER_SHIFT.

I think the feature should always be there unconditionally because people who develop applications want to use it with their normal GLib installation and likely don't have a development build.
Comment 7 Emmanuele Bassi (:ebassi) 2010-06-18 17:45:01 UTC
(In reply to comment #6)

the patch looks good to me.

> I think the feature should always be there unconditionally because people who
> develop applications want to use it with their normal GLib installation and
> likely don't have a development build.

yeah, good point - I confused this with Clutter, which defines ENABLE_DEBUG even with the "minimum" debugging level.
Comment 8 Emmanuele Bassi (:ebassi) 2010-06-18 17:46:51 UTC
small tip: the message should say "any more", not "anymore". :-)
Comment 9 Matthias Clasen 2010-06-23 14:15:33 UTC
Review of attachment 164029 [details] [review]:

::: gobject/gparam.h
@@ +183,3 @@
  * #GParamSpec.flags.
  */
+#define	G_PARAM_USER_SHIFT	(9)

This is an abi break, unfortunately
Comment 10 Christian Dywan 2010-06-23 14:48:56 UTC
After discussion on IRC and looking for code out there extending GParamSpec flags, Gimp with its 8 + G_PARAM_USER_SHIFT appears to be on the extreme side, aside from being a rarity to do it at all.

So I updated the commit to use 1  << 31 and to leave G_PARAM_USER_SHIFT alone. I added a note to the docs that 30 is the limit.
Comment 11 Christian Dywan 2010-06-23 14:50:33 UTC
In the happiness I closed the report while we still need to see about GtkContainer warnings. Apologies for the annoyance.
Comment 12 Christian Dywan 2010-07-02 18:35:59 UTC
Created attachment 165132 [details] [review]
Introduce GTK_ENABLE_DIAGNOSTIC for containers

This is the GTK+ part split from the original patch. If the environment variable GTK_ENABLE_DIAGNOSTIC is set, gtk_container_add and gtk_container_remove will complain if called with composite children.
Included is a change to GtkStatusbar to use gtk_widget_push_composite_child(). Most other widgets already do that, so support will come "for free".
Comment 13 Christian Dywan 2010-07-02 19:14:01 UTC
Created attachment 165136 [details] [review]
Introduce G_SIGNAL_DEPRECATED flag

This patch introduces the new signal flag G_SIGNAL_DEPRECATED. If specified, connecting to the signal results in a warning much like the one for deprecated properties.
Comment 14 Emmanuele Bassi (:ebassi) 2010-07-10 07:36:55 UTC
Review of attachment 165132 [details] [review]:

::: gtk/gtkcontainer.c
@@ +1204,3 @@
+      g_warning ("A %s is being added to a %s. "
+    if (GTK_WIDGET_COMPOSITE_CHILD (widget))
+  if (g_getenv ("GTK_ENABLE_DIAGNOSTIC"))

I think you mean:

  Adding internal widgets to containers is not supported. Use gtk_widget_set_parent() instead.

@@ +1242,3 @@
+    if (GTK_WIDGET_COMPOSITE_CHILD (widget))
+  if (g_getenv ("GTK_ENABLE_DIAGNOSTIC"))
+

probably adding:

  Use gtk_widget_unparent() instead.

wouldn't hurt.
Comment 15 Emmanuele Bassi (:ebassi) 2010-07-10 07:39:28 UTC
Review of attachment 165136 [details] [review]:

looks good to me.

::: gobject/gsignal.c
@@ +2099,3 @@
 }
+signal_diagnostics (const gchar* detailed_signal,
+static void

I'd have probably inlined this, but could be premature optimization

@@ +2114,3 @@
+                    GSignalFlags flags)
+signal_diagnostics (const gchar* detailed_signal,
+static void

"and shouldn't be used any more, as it will be removed in a future version."
Comment 16 Christian Dywan 2010-07-13 15:28:55 UTC
(In reply to comment #14)
> Review of attachment 165132 [details] [review]:
> 
> ::: gtk/gtkcontainer.c
> @@ +1204,3 @@
> +      g_warning ("A %s is being added to a %s. "
> +    if (GTK_WIDGET_COMPOSITE_CHILD (widget))
> +  if (g_getenv ("GTK_ENABLE_DIAGNOSTIC"))
> 
> I think you mean:
> 
>   Adding internal widgets to containers is not supported. Use
> gtk_widget_set_parent() instead.

Hm.. I agree with the better wording, but I am not sure pointing to gtk_widget_set_parent is right to recommend. If an application developer sees that, he might think he used the wrong API call, while in fact he should not do this at all.
Comment 17 Emmanuele Bassi (:ebassi) 2010-07-13 15:37:54 UTC
(In reply to comment #16)
> (In reply to comment #14)
> > Review of attachment 165132 [details] [review] [details]:
> > 
> > ::: gtk/gtkcontainer.c
> > @@ +1204,3 @@
> > +      g_warning ("A %s is being added to a %s. "
> > +    if (GTK_WIDGET_COMPOSITE_CHILD (widget))
> > +  if (g_getenv ("GTK_ENABLE_DIAGNOSTIC"))
> > 
> > I think you mean:
> > 
> >   Adding internal widgets to containers is not supported. Use
> > gtk_widget_set_parent() instead.
> 
> Hm.. I agree with the better wording, but I am not sure pointing to
> gtk_widget_set_parent is right to recommend. If an application developer sees
> that, he might think he used the wrong API call, while in fact he should not do
> this at all.

if an app developer went out of her way to call push_composite()/pop_composite() then she would probably appreciate the hint to the right function to call. on the other hand, if we don't want this behaviour *at all* then we probably want to add some wording to that effect to the warning.
Comment 18 Christian Dywan 2010-07-13 15:44:00 UTC
Created attachment 165812 [details] [review]
Introduce G_SIGNAL_DEPRECATED flag #2

Updated wording.
Comment 19 Emmanuele Bassi (:ebassi) 2010-07-13 16:03:14 UTC
Review of attachment 165812 [details] [review]:

looks good to me.
Comment 20 Christian Dywan 2010-07-13 16:33:50 UTC
Created attachment 165816 [details] [review]
Introduce GTK_ENABLE_DIAGNOSTIC for containers #2

We definitely don't want to encourage developers to work around container warnings.

I added a sentence to the warning:
"See documentation on containers and composite children."

And I added a note about GTK_ENABLE_DIAGNOSTIC to gtk_widget_push_composite_child().

I avoided exact function names in the warning, since those would probably be confusing when not using C. Hopefully the wording is clear enough to find it in the reference.
Comment 21 Emmanuele Bassi (:ebassi) 2010-07-13 16:40:36 UTC
Review of attachment 165816 [details] [review]:

looks good to me
Comment 22 Emmanuele Bassi (:ebassi) 2010-07-13 16:41:09 UTC
Review of attachment 165816 [details] [review]:

looks good to me
Comment 23 Matthias Clasen 2010-10-19 17:43:55 UTC
Comment on attachment 164029 [details] [review]
Introduce G_PARAM_DEPRECATED and G_ENABLE_DIAGNOSTIC #2

This one got committed, afaics
Comment 24 Matthias Clasen 2010-10-19 17:52:09 UTC
Review of attachment 165812 [details] [review]:

Does the G_SIGNAL_FLAGS_MASK needs to be updated ?
Comment 25 Christian Dywan 2010-10-22 14:32:46 UTC
Created attachment 173010 [details] [review]
Introduce G_SIGNAL_DEPRECATED flag #3

Updated the mask and Since.
Comment 26 Matthias Clasen 2010-10-25 16:26:49 UTC
Review of attachment 173010 [details] [review]:

I don't think that mask is correct.

$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
ibase=16
obase=2
8F
10001111
Comment 27 Marc-Andre Lureau 2011-11-07 19:22:16 UTC
Just noticed that bug, but I already proposed a new patch for G_SIGNAL_DEPRECATED in bug 601686.
Comment 28 Matthias Clasen 2014-05-13 03:14:53 UTC
We have G_PARAM_DEPRECATED and G_SIGNAL_DEPRECATED; I think this should be considered complete.
Comment 29 Marc-Andre Lureau 2016-05-30 23:17:24 UTC
/usr/include/glib-2.0/gobject/gparam.h:166:26: error: result of ‘1 << 31’ requires 33 bits to represent, but ‘int’ only has 32 bits [-Werror=shift-overflow=]
   G_PARAM_DEPRECATED          = 1 << 31



Is it something glib could fix?
Comment 30 Emmanuele Bassi (:ebassi) 2016-05-30 23:25:03 UTC
Not until the ISO C standards group decides to plug the gaping hole in the C spec, and specify how enumerations should be sized.