[glib] Revert "Use g_return_val_if_fail() for developer-only messages"



commit ed6ca39d3bb3e23c332a5de2b2efbde0d8db21f0
Author: Colin Walters <walters verbum org>
Date:   Thu Oct 17 16:57:10 2013 -0400

    Revert "Use g_return_val_if_fail() for developer-only messages"
    
    This reverts commit 00f0795a84d23f2e2654a86f8bd3a233c8af3771.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=569017

 gio/gicon.c       |   70 ++++++++++++++++++++++++++++++++++++++++++++++------
 gio/gthemedicon.c |   13 +++++++++-
 2 files changed, 74 insertions(+), 9 deletions(-)
---
diff --git a/gio/gicon.c b/gio/gicon.c
index 95d47d4..0e998b1 100644
--- a/gio/gicon.c
+++ b/gio/gicon.c
@@ -284,9 +284,20 @@ g_icon_new_from_tokens (char   **tokens,
   int num_tokens;
   int i;
 
+  icon = NULL;
+  klass = NULL;
+
   num_tokens = g_strv_length (tokens);
 
-  g_return_val_if_fail (num_tokens >= 1, NULL);
+  if (num_tokens < 1)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Wrong number of tokens (%d)"),
+                   num_tokens);
+      goto out;
+    }
   
   typename = tokens[0];
   version_str = strchr (typename, '.');
@@ -298,23 +309,64 @@ g_icon_new_from_tokens (char   **tokens,
   
   
   type = g_type_from_name (tokens[0]);
-  g_return_val_if_fail (type != 0, NULL);
-  g_return_val_if_fail (g_type_is_a (type, G_TYPE_ICON), NULL);
+  if (type == 0)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("No type for class name %s"),
+                   tokens[0]);
+      goto out;
+    }
+
+  if (!g_type_is_a (type, G_TYPE_ICON))
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Type %s does not implement the GIcon interface"),
+                   tokens[0]);
+      goto out;
+    }
 
   klass = g_type_class_ref (type);
-  g_return_val_if_fail (klass, NULL);
+  if (klass == NULL)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Type %s is not classed"),
+                   tokens[0]);
+      goto out;
+    }
 
   version = 0;
   if (version_str)
     {
       version = strtol (version_str, &endp, 10);
-      g_return_val_if_fail (endp && *endp, NULL);
+      if (endp == NULL || *endp != '\0')
+       {
+         g_set_error (error,
+                      G_IO_ERROR,
+                      G_IO_ERROR_INVALID_ARGUMENT,
+                      _("Malformed version number: %s"),
+                      version_str);
+         goto out;
+       }
     }
 
   icon_iface = g_type_interface_peek (klass, G_TYPE_ICON);
   g_assert (icon_iface != NULL);
 
-  g_return_val_if_fail (icon_iface->from_tokens, NULL);
+  if (icon_iface->from_tokens == NULL)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Type %s does not implement from_tokens() on the GIcon interface"),
+                   tokens[0]);
+      goto out;
+    }
 
   for (i = 1;  i < num_tokens; i++)
     {
@@ -327,7 +379,9 @@ g_icon_new_from_tokens (char   **tokens,
   
   icon = icon_iface->from_tokens (tokens + 1, num_tokens - 1, version, error);
 
-  g_type_class_unref (klass);
+ out:
+  if (klass != NULL)
+    g_type_class_unref (klass);
   return icon;
 }
 
@@ -411,7 +465,7 @@ g_icon_new_for_string (const gchar   *str,
     g_set_error_literal (error,
                          G_IO_ERROR,
                          G_IO_ERROR_INVALID_ARGUMENT,
-                         "Can't handle the supplied version of the icon encoding");
+                         _("Can't handle the supplied version of the icon encoding"));
 
   return icon;
 }
diff --git a/gio/gthemedicon.c b/gio/gthemedicon.c
index ba658fa..37b7492 100644
--- a/gio/gthemedicon.c
+++ b/gio/gthemedicon.c
@@ -514,7 +514,17 @@ g_themed_icon_from_tokens (gchar  **tokens,
   gchar **names;
   int n;
 
-  g_return_val_if_fail (version == 0, NULL);
+  icon = NULL;
+
+  if (version != 0)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_ARGUMENT,
+                   _("Can't handle version %d of GThemedIcon encoding"),
+                   version);
+      goto out;
+    }
   
   names = g_new0 (gchar *, num_tokens + 1);
   for (n = 0; n < num_tokens; n++)
@@ -524,6 +534,7 @@ g_themed_icon_from_tokens (gchar  **tokens,
   icon = g_themed_icon_new_from_names (names, num_tokens);
   g_free (names);
 
+ out:
   return icon;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]