gobjectification: 384c9329: Fixed some macros and some finalize stuf...
aluink at soc.pidgin.im
aluink at soc.pidgin.im
Thu Jun 25 02:11:26 EDT 2009
-----------------------------------------------------------------
Revision: 384c932971a5733966b387978e8303acaf0210cf
Ancestor: 32f1df15e5100856048894f960bc5df4e71e3c46
Author: aluink at soc.pidgin.im
Date: 2009-06-25T05:04:55
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/384c932971a5733966b387978e8303acaf0210cf
Modified files:
libpurple/blist-node.c libpurple/blist.c libpurple/blist.h
libpurple/buddy.c libpurple/chat.c libpurple/contact.c
libpurple/group.c
ChangeLog:
Fixed some macros and some finalize stuff
-------------- next part --------------
============================================================
--- libpurple/blist-node.c 1d9d69456effeb49a012b9e649f08d4f721f1d72
+++ libpurple/blist-node.c 58c61b581f038045ae30ec3033caa68b7d6639e4
@@ -430,33 +430,8 @@ purple_blist_node_destroy(PurpleBlistNod
void
purple_blist_node_destroy(PurpleBlistNode *node)
{
- PurpleBlistUiOps *ui_ops;
- PurpleBlistNode *child, *next_child;
-
- ui_ops = purple_blist_get_ui_ops();
- child = node->child;
- while (child) {
- next_child = child->next;
- purple_blist_node_destroy(child);
- child = next_child;
- }
-
- /* Allow the UI to free data */
- node->parent = NULL;
- node->child = NULL;
- node->next = NULL;
- node->prev = NULL;
- if (ui_ops && ui_ops->remove)
- ui_ops->remove(purplebuddylist, node);
-
- if (PURPLE_BLIST_NODE_IS_BUDDY(node))
- purple_buddy_destroy((PurpleBuddy*)node);
- else if (PURPLE_BLIST_NODE_IS_CHAT(node))
- purple_chat_destroy((PurpleChat*)node);
- else if (PURPLE_BLIST_NODE_IS_CONTACT(node))
- purple_contact_destroy((PurpleContact*)node);
- else if (PURPLE_BLIST_NODE_IS_GROUP(node))
- purple_group_destroy((PurpleGroup*)node);
+ g_return_if_fail(PURPLE_IS_BLIST_NODE(node));
+ g_object_unref(G_OBJECT(node));
}
void purple_blist_node_initialize_settings(PurpleBlistNode *node)
@@ -638,10 +613,49 @@ purple_blist_node_get_extended_menu(Purp
/* GObject Code */
/******************/
+static GObjectClass *parent_class = NULL;
+
static void
+purple_blist_node_finalize(GObject *object)
+{
+ PurpleBlistNode *node = PURPLE_BLIST_NODE(object);
+ PurpleBlistUiOps *ui_ops;
+ PurpleBlistNode *child, *next_child;
+
+ ui_ops = purple_blist_get_ui_ops();
+ child = node->child;
+ while (child) {
+ next_child = child->next;
+ purple_blist_node_destroy(child);
+ child = next_child;
+ }
+
+ /* Allow the UI to free data */
+ node->parent = NULL;
+ node->child = NULL;
+ node->next = NULL;
+ node->prev = NULL;
+ if (ui_ops && ui_ops->remove)
+ ui_ops->remove(purplebuddylist, node);
+
+ if (PURPLE_BLIST_NODE_IS_BUDDY(node))
+ purple_buddy_destroy((PurpleBuddy*)node);
+ else if (PURPLE_BLIST_NODE_IS_CHAT(node))
+ purple_chat_destroy((PurpleChat*)node);
+ else if (PURPLE_BLIST_NODE_IS_CONTACT(node))
+ purple_contact_destroy((PurpleContact*)node);
+ else if (PURPLE_BLIST_NODE_IS_GROUP(node))
+ purple_group_destroy((PurpleGroup*)node);
+ parent_class->finalize(object);
+}
+
+static void
purple_blist_node_class_init(PurpleBlistNodeClass *klass)
{
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+ parent_class = g_type_class_peek_parent(klass);
+ obj_class->finalize = purple_blist_node_finalize;
}
static void
============================================================
--- libpurple/blist.c 3ed468d3720696344d5595d653fb2618c853a501
+++ libpurple/blist.c 9a66ede74678fc25f37e51adc1cd091eb482ce88
@@ -317,7 +317,7 @@ PurpleBuddyList *purple_blist_new()
ui_ops = purple_blist_get_ui_ops();
- #warning: This has to be set here or we can't add the buddies cache
+ #warning: This has to be set here or we can\'t add the buddies cache
if(purplebuddylist) /* In case we're creating a replacement list */
purple_blist_destroy();
purple_set_blist(gbl);
============================================================
--- libpurple/blist.h 2180898a33a62073ef708d22edf3c01bce1fa301
+++ libpurple/blist.h 0d9aef53101652de66001fb977897ba6d5dcc0ca
@@ -76,60 +76,60 @@ typedef struct _PurpleBlistNodeClass Pur
typedef struct _PurpleBlistNodeClass PurpleBlistNodeClass;
#define PURPLE_BLIST_NODE_TYPE (purple_blist_node_get_gtype ())
#define PURPLE_BLIST_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_BLIST_NODE_TYPE, PurpleBlistNode))
-#define PURPLE_BLIST_NODE_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_BLIST_NODE_TYPE))
+#define PURPLE_IS_BLIST_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_BLIST_NODE_TYPE))
#define PURPLE_BLIST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_BLIST_NODE_TYPE, PurpleBlistNodeClass))
-#define PURPLE_BLIST_NODE_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_BLIST_NODE_TYPE))
-#define PURPLE_BLIST_NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_BLIST_NODE_TYPE, PurpleBlistNodeClass))
+#define PURPLE_IS_BLIST_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_BLIST_NODE_TYPE))
+#define PURPLE_GET_BLIST_NODE_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_BLIST_NODE_TYPE, PurpleBlistNodeClass))
/** @copydoc _PurpleBuddy */
typedef struct _PurpleBuddy PurpleBuddy;
typedef struct _PurpleBuddyClass PurpleBuddyClass;
#define PURPLE_BUDDY_TYPE (purple_buddy_get_gtype ())
#define PURPLE_BUDDY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_BUDDY_TYPE, PurpleBuddy))
-#define PURPLE_BUDDY_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_BUDDY_TYPE))
+#define PURPLE_IS_BUDDY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_BUDDY_TYPE))
#define PURPLE_BUDDY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_BUDDY_TYPE, PurpleBuddyClass))
-#define PURPLE_BUDDY_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_BUDDY_TYPE))
-#define PURPLE_BUDDY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_BUDDY_TYPE, PurpleBuddyClass))
+#define PURPLE_IS_BUDDY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_BUDDY_TYPE))
+#define PURPLE_GET_BUDDY_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_BUDDY_TYPE, PurpleBuddyClass))
/** @copydoc _PurpleContact */
typedef struct _PurpleContact PurpleContact;
typedef struct _PurpleContactClass PurpleContactClass;
#define PURPLE_CONTACT_TYPE (purple_contact_get_gtype ())
#define PURPLE_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_CONTACT_TYPE, PurpleContact))
-#define PURPLE_CONTACT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_CONTACT_TYPE))
+#define PURPLE_IS_CONTACT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_CONTACT_TYPE))
#define PURPLE_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_CONTACT_TYPE, PurpleContactClass))
-#define PURPLE_CONTACT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_CONTACT_TYPE))
-#define PURPLE_CONTACT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_CONTACT_TYPE, PurpleContactClass))
+#define PURPLE_IS_CONTACT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_CONTACT_TYPE))
+#define PURPLE_GET_CONTACT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_CONTACT_TYPE, PurpleContactClass))
/** @copydoc _PurpleGroup */
typedef struct _PurpleGroup PurpleGroup;
typedef struct _PurpleGroupClass PurpleGroupClass;
#define PURPLE_GROUP_TYPE (purple_group_get_gtype ())
#define PURPLE_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_GROUP_TYPE, PurpleGroup))
-#define PURPLE_GROUP_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_GROUP_TYPE))
+#define PURPLE_IS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_GROUP_TYPE))
#define PURPLE_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_GROUP_TYPE, PurpleGroupClass))
-#define PURPLE_GROUP_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_GROUP_TYPE))
-#define PURPLE_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_GROUP_TYPE, PurpleGroupClass))
+#define PURPLE_IS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_GROUP_TYPE))
+#define PURPLE_GET_GROUP_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_GROUP_TYPE, PurpleGroupClass))
/** @copydoc _PurpleChat */
typedef struct _PurpleChat PurpleChat;
typedef struct _PurpleChatClass PurpleChatClass;
#define PURPLE_CHAT_TYPE (purple_chat_get_gtype ())
#define PURPLE_CHAT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_CHAT_TYPE, PurpleChat))
-#define PURPLE_CHAT_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_CHAT_TYPE))
+#define PURPLE_IS_CHAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_CHAT_TYPE))
#define PURPLE_CHAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_CHAT_TYPE, PurpleChatClass))
-#define PURPLE_CHAT_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_CHAT_TYPE))
-#define PURPLE_CHAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_CHAT_TYPE, PurpleChatClass))
+#define PURPLE_IS_CHAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_CHAT_TYPE))
+#define PURPLE_GET_CHAT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_CHAT_TYPE, PurpleChatClass))
/** @copydoc _PurpleBlist */
typedef struct _PurpleBuddyList PurpleBuddyList;
typedef struct _PurpleBuddyListClass PurpleBuddyListClass;
#define PURPLE_BLIST_TYPE (purple_blist_get_gtype ())
#define PURPLE_BLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_BLIST_TYPE, PurpleBlist))
-#define PURPLE_BLIST_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_BLIST_TYPE))
+#define PURPLE_IS_BLIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_BLIST_TYPE))
#define PURPLE_BLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_BLIST_TYPE, PurpleBlistClass))
-#define PURPLE_BLIST_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_BLIST_TYPE))
-#define PURPLE_BLIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_BLIST_TYPE, PurpleBlistClass))
+#define PURPLE_IS_BLIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_BLIST_TYPE))
+#define PURPLE_GET_BLIST_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_BLIST_TYPE, PurpleBlistClass))
#include "account.h"
============================================================
--- libpurple/buddy.c dd51d3f0b19622d335e7c252a185eda9d61d9723
+++ libpurple/buddy.c ffcb0c137bd59d9ce90a0ada19c238b9a2bf872b
@@ -293,6 +293,7 @@ PurpleBuddy *purple_buddy_new(PurpleAcco
g_return_val_if_fail(name != NULL, NULL);
buddy = g_object_new(PURPLE_BUDDY_TYPE, NULL);
+ g_object_ref(buddy);
buddy->account = account;
buddy->name = purple_utf8_strip_unprintables(name);
buddy->alias = purple_utf8_strip_unprintables(alias);
@@ -313,37 +314,8 @@ purple_buddy_destroy(PurpleBuddy *buddy)
void
purple_buddy_destroy(PurpleBuddy *buddy)
{
- PurplePlugin *prpl;
- PurplePluginProtocolInfo *prpl_info;
-
- /*
- * Tell the owner PRPL that we're about to free the buddy so it
- * can free proto_data
- */
- prpl = purple_find_prpl(purple_account_get_protocol_id(buddy->account));
- if (prpl) {
- prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
- if (prpl_info && prpl_info->buddy_free)
- prpl_info->buddy_free(buddy);
- }
-
- /* Delete the node */
- purple_buddy_icon_unref(buddy->icon);
- g_hash_table_destroy(buddy->node.settings);
- purple_presence_destroy(buddy->presence);
- g_free(buddy->name);
- g_free(buddy->alias);
- g_free(buddy->server_alias);
-
- PURPLE_DBUS_UNREGISTER_POINTER(buddy);
- g_free(buddy);
-
- /* FIXME: Once PurpleBuddy is a GObject, timeout callbacks can
- * g_object_ref() it when connecting the callback and
- * g_object_unref() it in the handler. That way, it won't
- * get freed while the timeout is pending and this line can
- * be removed. */
- while (g_source_remove_by_user_data((gpointer *)buddy));
+ g_return_if_fail(PURPLE_IS_BUDDY(buddy));
+ g_object_unref(G_OBJECT(buddy));
}
void
@@ -568,10 +540,54 @@ buddy_to_xmlnode(PurpleBlistNode *bnode)
/* GObject Code */
/******************/
+static GObjectClass *parent_class = NULL;
+
+/* GObject destructor function */
static void
+purple_buddy_finalize(GObject *object)
+{
+ PurpleBuddy *buddy = PURPLE_BUDDY(object);
+ PurplePlugin *prpl;
+ PurplePluginProtocolInfo *prpl_info;
+
+ /*
+ * Tell the owner PRPL that we're about to free the buddy so it
+ * can free proto_data
+ */
+ prpl = purple_find_prpl(purple_account_get_protocol_id(buddy->account));
+ if (prpl) {
+ prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+ if (prpl_info && prpl_info->buddy_free)
+ prpl_info->buddy_free(buddy);
+ }
+
+ /* Delete the node */
+ purple_buddy_icon_unref(buddy->icon);
+ g_hash_table_destroy(buddy->node.settings);
+ purple_presence_destroy(buddy->presence);
+ g_free(buddy->name);
+ g_free(buddy->alias);
+ g_free(buddy->server_alias);
+
+ PURPLE_DBUS_UNREGISTER_POINTER(buddy);
+
+ #warning: Uhh, need some explanation here. -Aluink
+ /* FIXME: Once PurpleBuddy is a GObject, timeout callbacks can
+ * g_object_ref() it when connecting the callback and
+ * g_object_unref() it in the handler. That way, it won't
+ * get freed while the timeout is pending and this line can
+ * be removed. */
+ while (g_source_remove_by_user_data((gpointer *)buddy));
+ parent_class->finalize(object);
+}
+
+static void
purple_buddy_class_init(PurpleBuddyClass *klass)
{
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+ parent_class = g_type_class_peek_parent(klass);
+ obj_class->finalize = purple_buddy_finalize;
}
static void
============================================================
--- libpurple/chat.c 114e664a4636a78c1487dc388864b86d13021c62
+++ libpurple/chat.c 1b9468151a2c401151193d5ed130d02e6824ab68
@@ -191,11 +191,8 @@ purple_chat_destroy(PurpleChat *chat)
void
purple_chat_destroy(PurpleChat *chat)
{
- g_hash_table_destroy(chat->components);
- g_hash_table_destroy(chat->node.settings);
- g_free(chat->alias);
- PURPLE_DBUS_UNREGISTER_POINTER(chat);
- g_free(chat);
+ g_return_if_fail(PURPLE_IS_CHAT(chat));
+ g_object_unref(G_OBJECT(chat));
}
const char *purple_chat_get_name(PurpleChat *chat)
@@ -308,10 +305,26 @@ purple_chat_get_components(PurpleChat *c
/* GObject Code */
/******************/
+static GObjectClass *parent_class = NULL;
+
static void
+purple_chat_finalize(GObject *object)
+{
+ PurpleChat *chat = PURPLE_CHAT(object);
+ g_hash_table_destroy(chat->components);
+ g_hash_table_destroy(chat->node.settings);
+ g_free(chat->alias);
+ PURPLE_DBUS_UNREGISTER_POINTER(chat);
+ parent_class->finalize(object);
+}
+
+static void
purple_chat_class_init(PurpleChatClass *klass)
{
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+ parent_class = g_type_class_peek_parent(klass);
+ obj_class->finalize = purple_chat_finalize;
}
static void
============================================================
--- libpurple/contact.c f8391ddd1af9fad839852fe12fd8e621e54b53de
+++ libpurple/contact.c 44e39f3b210eaea218d0c442a2ec909fad68be68
@@ -216,10 +216,8 @@ purple_contact_destroy(PurpleContact *co
void
purple_contact_destroy(PurpleContact *contact)
{
- g_hash_table_destroy(contact->node.settings);
- g_free(contact->alias);
- PURPLE_DBUS_UNREGISTER_POINTER(contact);
- g_free(contact);
+ g_return_if_fail(PURPLE_IS_ACCOUNT(contact));
+ g_object_unref(G_OBJECT(contact));
}
void purple_contact_set_alias(PurpleContact *contact, const char *alias)
@@ -278,10 +276,25 @@ PurpleBuddy *purple_contact_get_priority
/* GObject Code */
/****************/
+static GObjectClass *parent_class = NULL;
+
static void
+purple_contact_finalize(GObject *object)
+{
+ PurpleContact *contact = PURPLE_CONTACT(object);
+ g_hash_table_destroy(contact->node.settings);
+ g_free(contact->alias);
+ PURPLE_DBUS_UNREGISTER_POINTER(contact);
+ parent_class->finalize(object);
+}
+
+static void
purple_contact_class_init(PurpleContactClass *klass)
{
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+ parent_class = g_type_class_peek_parent(klass);
+ obj_class->finalize = purple_contact_finalize;
}
static void
============================================================
--- libpurple/group.c 7ea460951fe9f707ac512e7b31d766e9bce795b4
+++ libpurple/group.c 7b675abdf8d57b510cb2d3bd95d7384761de1c7e
@@ -239,10 +239,8 @@ purple_group_destroy(PurpleGroup *group)
void
purple_group_destroy(PurpleGroup *group)
{
- g_hash_table_destroy(group->node.settings);
- g_free(group->name);
- PURPLE_DBUS_UNREGISTER_POINTER(group);
- g_free(group);
+ g_return_if_fail(PURPLE_IS_GROUP(group));
+ g_object_unref(G_OBJECT(group));
}
PurpleGroup *purple_find_group(const char *name)
@@ -315,10 +313,25 @@ PurpleGroup *purple_group_new(const char
/* GObject Code */
/******************/
+static GObjectClass *parent_class = NULL;
+
static void
+purple_group_finalize(GObject *object)
+{
+ PurpleGroup *group = PURPLE_GROUP(object);
+ g_hash_table_destroy(group->node.settings);
+ g_free(group->name);
+ PURPLE_DBUS_UNREGISTER_POINTER(group);
+ parent_class->finalize(object);
+}
+
+static void
purple_group_class_init(PurpleGroupClass *klass)
{
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+ parent_class = g_type_class_peek_parent(klass);
+ obj_class->finalize = purple_group_finalize;
}
static void
More information about the Commits
mailing list