/pidgin/main: e76677ed819c: connection: Add purple_connection_ta...

Mike Ruprecht <[email protected]> Sun, 28 Aug 2016 23:58:01 -0400
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: e76677ed819c68023c3b14fcf0d582f296b45e8a
Author:	 Mike Ruprecht <[email protected]>
Date:	 2016-08-27 18:16 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/e76677ed819c

Description:

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.

diffstat:

 libpurple/connection.c |   7 +++++++
 libpurple/connection.h |  15 +++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diffs (42 lines):

diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -579,6 +579,13 @@ purple_connection_g_error(PurpleConnecti
 	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)
 {
diff --git a/libpurple/connection.h b/libpurple/connection.h
--- a/libpurple/connection.h
+++ b/libpurple/connection.h
@@ -524,6 +524,21 @@ void
 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:
  *

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits