/pidgin/main: 07dabf3c0022: PurpleImage: purple_image_get_data s...

Tomasz Wasilczyk twasilczyk at pidgin.im
Mon Apr 14 16:13:46 EDT 2014


Changeset: 07dabf3c0022d7dca340064e71419b7dc9e8a2d6
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-14 22:13 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/07dabf3c0022

Description:

PurpleImage: purple_image_get_data should return const buffer

diffstat:

 libpurple/image.c                |   8 ++++----
 libpurple/image.h                |   5 ++---
 libpurple/protocols/msn/slpmsg.c |  15 ++-------------
 libpurple/protocols/msn/slpmsg.h |   1 -
 4 files changed, 8 insertions(+), 21 deletions(-)

diffs (108 lines):

diff --git a/libpurple/image.c b/libpurple/image.c
--- a/libpurple/image.c
+++ b/libpurple/image.c
@@ -201,7 +201,7 @@ gboolean
 purple_image_save(PurpleImage *image, const gchar *path)
 {
 	PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
-	gpointer data;
+	gconstpointer data;
 	gsize len;
 	gboolean succ;
 
@@ -267,7 +267,7 @@ purple_image_get_size(PurpleImage *image
 	return priv->contents->len;
 }
 
-gpointer
+gconstpointer
 purple_image_get_data(PurpleImage *image)
 {
 	PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
@@ -285,7 +285,7 @@ const gchar *
 purple_image_get_extension(PurpleImage *image)
 {
 	PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
-	gpointer data;
+	gconstpointer data;
 
 	g_return_val_if_fail(priv != NULL, NULL);
 
@@ -349,7 +349,7 @@ const gchar *
 purple_image_generate_filename(PurpleImage *image)
 {
 	PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
-	gpointer data;
+	gconstpointer data;
 	gsize len;
 	const gchar *ext;
 	gchar *checksum;
diff --git a/libpurple/image.h b/libpurple/image.h
--- a/libpurple/image.h
+++ b/libpurple/image.h
@@ -184,10 +184,9 @@ purple_image_get_size(PurpleImage *image
  *
  * Returns the pointer to the buffer containing image data.
  *
- * Returns: (transfer none): the @image data. You should not modify
- *          its contents.
+ * Returns: (transfer none): the @image data.
  */
-gpointer
+gconstpointer
 purple_image_get_data(PurpleImage *image);
 
 /**
diff --git a/libpurple/protocols/msn/slpmsg.c b/libpurple/protocols/msn/slpmsg.c
--- a/libpurple/protocols/msn/slpmsg.c
+++ b/libpurple/protocols/msn/slpmsg.c
@@ -68,14 +68,7 @@ msn_slpmsg_destroy(MsnSlpMessage *slpmsg
 
 	slplink = slpmsg->slplink;
 
-
-	if (slpmsg->img)
-		g_object_unref(slpmsg->img);
-	else {
-		/* We don't want to free the data of the PurpleImage,
-		 * but to avoid code duplication, it's sharing buffer. */
-		g_free(slpmsg->buffer);
-	}
+	g_free(slpmsg->buffer);
 
 	for (cur = slpmsg->parts; cur != NULL; cur = g_list_delete_link(cur, cur))
 	{
@@ -115,7 +108,6 @@ msn_slpmsg_set_body(MsnSlpMessage *slpms
 {
 	/* We can only have one data source at a time. */
 	g_return_if_fail(slpmsg->buffer == NULL);
-	g_return_if_fail(slpmsg->img == NULL);
 	g_return_if_fail(slpmsg->ft == FALSE);
 
 	if (body != NULL)
@@ -131,13 +123,10 @@ msn_slpmsg_set_image(MsnSlpMessage *slpm
 {
 	/* We can only have one data source at a time. */
 	g_return_if_fail(slpmsg->buffer == NULL);
-	g_return_if_fail(slpmsg->img == NULL);
 	g_return_if_fail(slpmsg->ft == FALSE);
 
-	g_object_ref(img);
-	slpmsg->img = img;
-	slpmsg->buffer = purple_image_get_data(img);
 	slpmsg->size = purple_image_get_size(img);
+	slpmsg->buffer = g_memdup(purple_image_get_data(img), slpmsg->size);
 }
 
 
diff --git a/libpurple/protocols/msn/slpmsg.h b/libpurple/protocols/msn/slpmsg.h
--- a/libpurple/protocols/msn/slpmsg.h
+++ b/libpurple/protocols/msn/slpmsg.h
@@ -48,7 +48,6 @@ struct _MsnSlpMessage
 	long id;
 
 	gboolean ft;
-	PurpleImage *img;
 	guchar *buffer;
 
 	/**



More information about the Commits mailing list