[glib] Add G_SIGNAL_DEPRECATED
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add G_SIGNAL_DEPRECATED
- Date: Tue, 8 Nov 2011 10:10:23 +0000 (UTC)
commit fb95c20c965bc241fc9d519afede94d3bc7838a8
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Mon Nov 7 20:04:15 2011 +0100
Add G_SIGNAL_DEPRECATED
Similar to G_PARAM_DEPRECATED. It will warn only for users of the
signals, so a signal can still be emited without warning, for
compatibility reasons.
Apparently, there is no way user flags could have been used before,
so that shouldn't break anyone.
https://bugzilla.gnome.org/show_bug.cgi?id=663581
gobject/gobject.c | 2 +-
gobject/gsignal.c | 32 +++++++++++++++++++++++++++++++-
gobject/gsignal.h | 8 ++++++--
3 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index faf3cef..6e20aa0 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -1171,7 +1171,7 @@ object_set_property (GObject *object,
if (enable_diagnostic[0] == '1')
{
if (pspec->flags & G_PARAM_DEPRECATED)
- g_warning ("The property %s::%s is deprecated and shouldn't be used "
+ g_warning ("The property %s:%s is deprecated and shouldn't be used "
"anymore. It will be removed in a future version.",
G_OBJECT_TYPE_NAME (object), pspec->name);
}
diff --git a/gobject/gsignal.c b/gobject/gsignal.c
index 4ea57c5..5736732 100644
--- a/gobject/gsignal.c
+++ b/gobject/gsignal.c
@@ -180,6 +180,7 @@ static gboolean signal_emit_unlocked_R (SignalNode *node,
GValue *return_value,
const GValue *instance_and_params);
static const gchar * type_debug_name (GType type);
+static void node_check_deprecated (const SignalNode *node);
/* --- structures --- */
@@ -205,7 +206,7 @@ struct _SignalNode
/* reinitializable portion */
guint test_class_offset : 12;
- guint flags : 8;
+ guint flags : 9;
guint n_params : 8;
GType *param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
@@ -929,6 +930,9 @@ g_signal_add_emission_hook (guint signal_id,
g_hook_list_init (node->emission_hooks, sizeof (SignalHook));
node->emission_hooks->finalize_hook = signal_finalize_hook;
}
+
+ node_check_deprecated (node);
+
hook = g_hook_alloc (node->emission_hooks);
hook->data = hook_data;
hook->func = (gpointer) hook_func;
@@ -1804,6 +1808,7 @@ g_signal_override_class_closure (guint signal_id,
SIGNAL_LOCK ();
node = LOOKUP_SIGNAL_NODE (signal_id);
+ node_check_deprecated (node);
if (!g_type_is_a (instance_type, node->itype))
g_warning ("%s: type `%s' cannot be overridden for signal id `%u'", G_STRLOC, type_debug_name (instance_type), signal_id);
else
@@ -2229,6 +2234,29 @@ g_signal_connect_closure (gpointer instance,
return handler_seq_no;
}
+static void
+node_check_deprecated (const SignalNode *node)
+{
+ static const gchar * g_enable_diagnostic = NULL;
+
+ if (G_UNLIKELY (!g_enable_diagnostic))
+ {
+ g_enable_diagnostic = g_getenv ("G_ENABLE_DIAGNOSTIC");
+ if (!g_enable_diagnostic)
+ g_enable_diagnostic = "0";
+ }
+
+ if (g_enable_diagnostic[0] == '1')
+ {
+ if (node->flags & G_SIGNAL_DEPRECATED)
+ {
+ g_warning ("The signal %s::%s is deprecated and shouldn't be used "
+ "anymore. It will be removed in a future version.",
+ type_debug_name (node->itype), node->name);
+ }
+ }
+}
+
/**
* g_signal_connect_data:
* @instance: the instance to connect to.
@@ -2274,6 +2302,8 @@ g_signal_connect_data (gpointer instance,
{
SignalNode *node = LOOKUP_SIGNAL_NODE (signal_id);
+ node_check_deprecated (node);
+
if (detail && !(node->flags & G_SIGNAL_DETAILED))
g_warning ("%s: signal `%s' does not support details", G_STRLOC, detailed_signal);
else if (!g_type_is_a (itype, node->itype))
diff --git a/gobject/gsignal.h b/gobject/gsignal.h
index 0fae33e..5d8ead8 100644
--- a/gobject/gsignal.h
+++ b/gobject/gsignal.h
@@ -110,6 +110,9 @@ typedef gboolean (*GSignalAccumulator) (GSignalInvocationHint *ihint,
* @G_SIGNAL_NO_HOOKS: No emissions hooks are supported for this signal.
* @G_SIGNAL_MUST_COLLECT: Varargs signal emission will always collect the
* arguments, even if there are no signal handlers connected. Since 2.30.
+ * @G_SIGNAL_DEPRECATED: The signal is deprecated and will be removed
+ * in a future version. A warning will be generated if it is connected while
+ * running with G_ENABLE_DIAGNOSTIC=1. Since 2.32.
*
* The signal flags are used to specify a signal's behaviour, the overall
* signal description outlines how especially the RUN flags control the
@@ -124,14 +127,15 @@ typedef enum
G_SIGNAL_DETAILED = 1 << 4,
G_SIGNAL_ACTION = 1 << 5,
G_SIGNAL_NO_HOOKS = 1 << 6,
- G_SIGNAL_MUST_COLLECT = 1 << 7
+ G_SIGNAL_MUST_COLLECT = 1 << 7,
+ G_SIGNAL_DEPRECATED = 1 << 8,
} GSignalFlags;
/**
* G_SIGNAL_FLAGS_MASK:
*
* A mask for all #GSignalFlags bits.
*/
-#define G_SIGNAL_FLAGS_MASK 0xff
+#define G_SIGNAL_FLAGS_MASK 0x1ff
/**
* GConnectFlags:
* @G_CONNECT_AFTER: whether the handler should be called before or after the
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]