/soc/2013/ankitkv/gobjectification: aba8b8e624c2: Replaced array...

Ankit Vani a at nevitus.org
Tue Oct 1 16:42:22 EDT 2013


Changeset: aba8b8e624c2d1b290d330899ff8c0a538dcd6dd
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-10-02 02:09 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/aba8b8e624c2

Description:

Replaced array with closure struct for registration callback

diffstat:

 libpurple/account.c           |  42 ++++++++++++++++++++++++------------------
 libpurple/protocols/msn/msn.c |   2 +-
 2 files changed, 25 insertions(+), 19 deletions(-)

diffs (84 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -188,23 +188,26 @@ purple_account_unregister_got_password_c
 	g_free(cbb);
 }
 
+struct register_completed_closure
+{
+	PurpleAccount *account;
+	gboolean succeeded;
+};
+
 static gboolean
-purple_account_register_completed_cb(gpointer *data)
+purple_account_register_completed_cb(gpointer data)
 {
-	PurpleAccount *account = PURPLE_ACCOUNT(data[0]);
-	gboolean succeeded = (data[1] != NULL);
+	struct register_completed_closure *closure = data;
 	PurpleAccountPrivate *priv;
 
-	g_free(data);
-
-	g_return_val_if_fail(account != NULL, FALSE);
-
-	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+	priv = PURPLE_ACCOUNT_GET_PRIVATE(closure->account);
 
 	if (priv->registration_cb)
-		(priv->registration_cb)(account, succeeded, priv->registration_cb_user_data);
-
-	g_object_unref(account);
+		(priv->registration_cb)(closure->account, closure->succeeded,
+				priv->registration_cb_user_data);
+
+	g_object_unref(closure->account);
+	g_free(closure);
 
 	return FALSE;
 }
@@ -212,12 +215,15 @@ purple_account_register_completed_cb(gpo
 void
 purple_account_register_completed(PurpleAccount *account, gboolean succeeded)
 {
-	gpointer *data = g_new0(gpointer, 2);
-	data[0] = g_object_ref(account);
-	data[1] = succeeded ? GINT_TO_POINTER(1) : NULL;
-
-	purple_timeout_add(0, (GSourceFunc)purple_account_register_completed_cb,
-			(gpointer)data);
+	struct register_completed_closure *closure;
+
+	g_return_if_fail(PURPLE_IS_ACCOUNT(account));
+
+	closure = g_new0(struct register_completed_closure, 1);
+	closure->account = g_object_ref(account);
+	closure->succeeded = succeeded;
+
+	purple_timeout_add(0, purple_account_register_completed_cb, closure);
 }
 
 void
@@ -1065,7 +1071,7 @@ get_public_alias_unsupported(gpointer da
 	failure_cb(closure->account,
 	           _("This protocol does not support fetching the public alias."));
 
-	g_object_unref(account);
+	g_object_unref(closure->account);
 	g_free(closure);
 
 	return FALSE;
diff --git a/libpurple/protocols/msn/msn.c b/libpurple/protocols/msn/msn.c
--- a/libpurple/protocols/msn/msn.c
+++ b/libpurple/protocols/msn/msn.c
@@ -299,7 +299,7 @@ get_public_alias_cb(gpointer data)
 	                                  purple_account_get_username(closure->account));
 	success_cb(closure->account, alias);
 
-	g_object_unref(account);
+	g_object_unref(closure->account);
 	g_free(closure);
 
 	return FALSE;



More information about the Commits mailing list