[gtk+/wip/otte/clipboard: 96/117] clipboard: Make value getters set the passed in value
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/clipboard: 96/117] clipboard: Make value getters set the passed in value
- Date: Tue, 28 Nov 2017 02:24:36 +0000 (UTC)
commit 4bd509c32f65a32d56b11841d732b52c4b615a08
Author: Benjamin Otte <otte redhat com>
Date: Fri Nov 24 06:07:09 2017 +0100
clipboard: Make value getters set the passed in value
Don't return a const GValue, that's ugly API. Instead require people to
pass in a preinitialized GValue and set that one.
gdk/gdkclipboard.c | 23 +++++++++++++++++------
gdk/gdkcontentdeserializer.c | 14 ++++++++------
gdk/gdkcontentdeserializer.h | 3 ++-
3 files changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/gdk/gdkclipboard.c b/gdk/gdkclipboard.c
index 2b37270..bd21362 100644
--- a/gdk/gdkclipboard.c
+++ b/gdk/gdkclipboard.c
@@ -347,13 +347,14 @@ gdk_clipboard_read_value_done (GObject *source,
{
GTask *task = data;
GError *error = NULL;
- const GValue *value;
+ GValue *value;
+
+ value = g_task_get_task_data (task);
- value = gdk_content_deserialize_finish (result, &error);
- if (value == NULL)
+ if (!gdk_content_deserialize_finish (result, value, &error))
g_task_return_error (task, error);
else
- g_task_return_pointer (task, (gpointer) value, NULL);
+ g_task_return_pointer (task, value, NULL);
g_object_unref (task);
}
@@ -377,7 +378,7 @@ gdk_clipboard_read_value_got_stream (GObject *source,
gdk_content_deserialize_async (stream,
mime_type,
- GPOINTER_TO_SIZE (g_task_get_task_data (task)),
+ G_VALUE_TYPE (g_task_get_task_data (task)),
g_task_get_priority (task),
g_task_get_cancellable (task),
gdk_clipboard_read_value_done,
@@ -386,6 +387,13 @@ gdk_clipboard_read_value_got_stream (GObject *source,
}
static void
+free_value (gpointer value)
+{
+ g_value_unset (value);
+ g_slice_free (GValue, value);
+}
+
+static void
gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
GType type,
gpointer source_tag,
@@ -396,6 +404,7 @@ gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
{
GdkContentFormatsBuilder *builder;
GdkContentFormats *formats;
+ GValue *value;
GTask *task;
builder = gdk_content_formats_builder_new ();
@@ -406,7 +415,9 @@ gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
task = g_task_new (clipboard, cancellable, callback, user_data);
g_task_set_priority (task, io_priority);
g_task_set_source_tag (task, source_tag);
- g_task_set_task_data (task, GSIZE_TO_POINTER (type), NULL);
+ value = g_slice_new0 (GValue);
+ g_value_init (value, type);
+ g_task_set_task_data (task, value, free_value);
gdk_clipboard_read_internal (clipboard,
formats,
diff --git a/gdk/gdkcontentdeserializer.c b/gdk/gdkcontentdeserializer.c
index bcfc11e..6c931e0 100644
--- a/gdk/gdkcontentdeserializer.c
+++ b/gdk/gdkcontentdeserializer.c
@@ -380,25 +380,27 @@ gdk_content_deserialize_async (GInputStream *stream,
user_data);
}
-const GValue *
+gboolean
gdk_content_deserialize_finish (GAsyncResult *result,
+ GValue *value,
GError **error)
{
GdkContentDeserializer *deserializer;
- g_return_val_if_fail (GDK_IS_CONTENT_DESERIALIZER (result), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
+ g_return_val_if_fail (GDK_IS_CONTENT_DESERIALIZER (result), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
deserializer = GDK_CONTENT_DESERIALIZER (result);
+ g_return_val_if_fail (G_VALUE_HOLDS (value, G_VALUE_TYPE (&deserializer->value)), FALSE);
if (deserializer->error)
{
if (error)
*error = g_error_copy (deserializer->error);
- return NULL;
+ return FALSE;
}
- return &deserializer->value;
+ g_value_copy (&deserializer->value, value);
+ return TRUE;
}
/*** DESERIALIZERS ***/
diff --git a/gdk/gdkcontentdeserializer.h b/gdk/gdkcontentdeserializer.h
index 481f15a..102a4bc 100644
--- a/gdk/gdkcontentdeserializer.h
+++ b/gdk/gdkcontentdeserializer.h
@@ -81,7 +81,8 @@ void gdk_content_deserialize_async (GInputS
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_3_94
-const GValue * gdk_content_deserialize_finish (GAsyncResult *result,
+gboolean gdk_content_deserialize_finish (GAsyncResult *result,
+ GValue *value,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]