connection: Add purple_connection_take_error()

Sat, 27 Aug 2016 18:16:01 -0500

author
Mike Ruprecht <cmaiku@gmail.com>
date
Sat, 27 Aug 2016 18:16:01 -0500
changeset 37959
e76677ed819c
parent 37958
e03cbceed96a
child 37960
3ead1b62bc55

connection: Add purple_connection_take_error()

This patch adds a purple_connection_take_error() function, which
is functionally equivalent to purple_connection_g_error(), except
that it takes ownership of the passed GError.

This is useful to simplify error handling so that the GError doesn't
have to be freed, or, in the future potentially copied, if it's no
longer needed where it's generated. It can also allow for GErrors
being generated without storing them in a variable. This would be
reasonably common if/when all PurpleConnection errors are passed
in via GError.

libpurple/connection.c file | annotate | diff | comparison | revisions
libpurple/connection.h file | annotate | diff | comparison | revisions
--- a/libpurple/connection.c	Fri Aug 26 03:04:41 2016 -0500
+++ b/libpurple/connection.c	Sat Aug 27 18:16:01 2016 -0500
@@ -579,6 +579,13 @@
 	purple_connection_error(pc, reason, error->message);
 }
 
+void
+purple_connection_take_error(PurpleConnection *pc, GError *error)
+{
+	purple_connection_g_error(pc, error);
+	g_error_free(error);
+}
+
 gboolean
 purple_connection_error_is_fatal (PurpleConnectionError reason)
 {
--- a/libpurple/connection.h	Fri Aug 26 03:04:41 2016 -0500
+++ b/libpurple/connection.h	Sat Aug 27 18:16:01 2016 -0500
@@ -524,6 +524,21 @@
 purple_connection_g_error(PurpleConnection *pc,
                           const GError *error);
 
+/*
+ * purple_connection_take_error
+ * @gc: Connection the error is associated with
+ * @error: (transfer full): Error information
+ *
+ * Closes a connection similar to purple_connection_error(), but
+ * takes a GError which is then converted to purple error codes.
+ *
+ * This function is equivalent to purple_connection_g_error(),
+ * except that it takes ownership of the GError.
+ */
+void
+purple_connection_take_error(PurpleConnection *pc,
+                             GError *error);
+
 /**
  * purple_connection_error_is_fatal:
  *

mercurial