/soc/2015/jgeboski/facebook: d6cb70301fea: facebook: refactored ...

James Geboski <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: d6cb70301feada5e305a0c4ed0edeab40db77ab7
Author:	 James Geboski <[email protected]>
Date:	 2015-08-01 17:26 -0400
Branch:	 facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/d6cb70301fea

Description:

facebook: refactored error propagation

diffstat:

 libpurple/glibcompat.h              |  19 +++++++++++++++++++
 libpurple/protocols/facebook/api.c  |  16 ++++++----------
 libpurple/protocols/facebook/mqtt.c |   9 +++------
 3 files changed, 28 insertions(+), 16 deletions(-)

diffs (110 lines):

diff --git a/libpurple/glibcompat.h b/libpurple/glibcompat.h
--- a/libpurple/glibcompat.h
+++ b/libpurple/glibcompat.h
@@ -168,6 +168,25 @@ static inline void g_object_class_instal
 		g_object_class_install_property(oclass, i, pspecs[i]);
 }
 
+#if !GLIB_CHECK_VERSION(2, 22, 0)
+
+#include <stdarg.h>
+
+static inline GError * g_error_new_valist(GQuark domain, gint code,
+	const gchar *format, va_list args)
+{
+	gchar *str;
+	GError *error;
+
+	str = g_strdup_vprintf(format, args);
+	error = g_error_new_literal(domain, code, str);
+
+	g_free(str);
+	return error;
+}
+
+#endif /* < 2.22.0 */
+
 #endif /* < 2.26.0 */
 
 #endif /* < 2.28.0 */
diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c
--- a/libpurple/protocols/facebook/api.c
+++ b/libpurple/protocols/facebook/api.c
@@ -23,8 +23,9 @@
 #include <stdarg.h>
 #include <string.h>
 
+#include "glibcompat.h"
+
 #include "api.h"
-#include "glibcompat.h"
 #include "http.h"
 #include "json.h"
 #include "marshal.h"
@@ -329,9 +330,8 @@ fb_api_json_chk(FbApi *api, gconstpointe
 	priv = api->priv;
 
 	if (G_UNLIKELY(size == 0)) {
-		g_set_error(&err, FB_API_ERROR, FB_API_ERROR_GENERAL,
-		            _("Invalid JSON data"));
-		FB_API_ERROR_CHK(api, err, return FALSE);
+		fb_api_error(api, FB_API_ERROR_GENERAL, _("Empty JSON data"));
+		return FALSE;
 	}
 
 	root = fb_json_node_new(data, size, &err);
@@ -1043,19 +1043,15 @@ fb_api_rehash(FbApi *api)
 void
 fb_api_error(FbApi *api, FbApiError error, const gchar *format, ...)
 {
-	gchar *str;
-	GError *err = NULL;
+	GError *err;
 	va_list ap;
 
 	g_return_if_fail(FB_IS_API(api));
 
 	va_start(ap, format);
-	str = g_strdup_vprintf(format, ap);
+	err = g_error_new_valist(FB_API_ERROR, error, format, ap);
 	va_end(ap);
 
-	g_set_error(&err, FB_API_ERROR, error, "%s", str);
-	g_free(str);
-
 	g_signal_emit_by_name(api, "error", err);
 	g_error_free(err);
 }
diff --git a/libpurple/protocols/facebook/mqtt.c b/libpurple/protocols/facebook/mqtt.c
--- a/libpurple/protocols/facebook/mqtt.c
+++ b/libpurple/protocols/facebook/mqtt.c
@@ -27,6 +27,7 @@
 
 #include "account.h"
 #include "eventloop.h"
+#include "glibcompat.h"
 #include "sslconn.h"
 
 #include "marshal.h"
@@ -237,19 +238,15 @@ fb_mqtt_close(FbMqtt *mqtt)
 void
 fb_mqtt_error(FbMqtt *mqtt, FbMqttError error, const gchar *format, ...)
 {
-	gchar *str;
-	GError *err = NULL;
+	GError *err;
 	va_list ap;
 
 	g_return_if_fail(FB_IS_MQTT(mqtt));
 
 	va_start(ap, format);
-	str = g_strdup_vprintf(format, ap);
+	err = g_error_new_valist(FB_MQTT_ERROR, error, format, ap);
 	va_end(ap);
 
-	g_set_error(&err, FB_MQTT_ERROR, error, "%s", str);
-	g_free(str);
-
 	g_signal_emit_by_name(mqtt, "error", err);
 	fb_mqtt_close(mqtt);
 	g_error_free(err);

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.