Introduce G_PARAM_DEPRECATED and G_ENABLE_DIAGNOSTIC
authorChristian Dywan <christian@twotoasts.de>
Fri, 18 Jun 2010 14:14:27 +0000 (16:14 +0200)
committerChristian Dywan <christian@twotoasts.de>
Wed, 23 Jun 2010 14:45:12 +0000 (16:45 +0200)
See https://bugzilla.gnome.org/show_bug.cgi?id=601686

gobject/gobject.c
gobject/gparam.h

index 1b42070..41c70ee 100644 (file)
@@ -1016,11 +1016,27 @@ object_set_property (GObject             *object,
   GObjectClass *class = g_type_class_peek (pspec->owner_type);
   guint param_id = PARAM_SPEC_PARAM_ID (pspec);
   GParamSpec *redirect;
+  static gchar* enable_diagnostic = NULL;
 
   redirect = g_param_spec_get_redirect_target (pspec);
   if (redirect)
     pspec = redirect;
 
+  if (G_UNLIKELY (!enable_diagnostic))
+    {
+      enable_diagnostic = g_getenv ("G_ENABLE_DIAGNOSTIC");
+      if (!enable_diagnostic)
+        enable_diagnostic = "0";
+    }
+
+  if (enable_diagnostic[0] == '1')
+    {
+      if (pspec->flags & G_PARAM_DEPRECATED)
+        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);
+    }
+
   /* provide a copy to work from, convert (if necessary) and validate */
   g_value_init (&tmp_value, pspec->value_type);
   if (!g_value_transform (value, &tmp_value))
index 7fc4f61..9b93c0a 100644 (file)
@@ -132,6 +132,10 @@ G_BEGIN_DECLS
  *  unmodified for the lifetime of the parameter. 
  *  Since 2.8
  * @G_PARAM_PRIVATE: internal
+ * @G_PARAM_DEPRECATED: the parameter is deprecated and will be removed
+ *  in a future version. A warning will be generated if it is used
+ *  while running with G_ENABLE_DIAGNOSTIC=1.
+ *  Since: 2.26
  * 
  * Through the #GParamFlags flag values, certain aspects of parameters
  * can be configured.
@@ -148,7 +152,9 @@ typedef enum
   G_PARAM_PRIVATE            = G_PARAM_STATIC_NAME,
 #endif
   G_PARAM_STATIC_NICK        = 1 << 6,
-  G_PARAM_STATIC_BLURB       = 1 << 7
+  G_PARAM_STATIC_BLURB       = 1 << 7,
+  /* User defined flags go up to 30 */
+  G_PARAM_DEPRECATED          = 1 << 31
 } GParamFlags;
 /**
  * G_PARAM_READWRITE:
@@ -175,11 +181,10 @@ typedef enum
  * G_PARAM_USER_SHIFT:
  * 
  * Minimum shift count to be used for user defined flags, to be stored in
- * #GParamSpec.flags.
+ * #GParamSpec.flags. The maximum allowed is 30 + G_PARAM_USER_SHIFT.
  */
 #define        G_PARAM_USER_SHIFT      (8)
 
-
 /* --- typedefs & structures --- */
 typedef struct _GParamSpec      GParamSpec;
 typedef struct _GParamSpecClass GParamSpecClass;