[glib] Use g_simple_async_result_{new_,}take_error



commit 9e0c07870af1dac84c033031cf301671779c8328
Author: Christian Persch <chpe gnome org>
Date:   Thu Sep 23 13:02:50 2010 +0200

    Use g_simple_async_result_{new_,}take_error
    
    Bug #633685.

 gio/gasyncinitable.c           |    5 +--
 gio/gbufferedinputstream.c     |   32 ++++++---------
 gio/gbufferedoutputstream.c    |    5 +--
 gio/gdatainputstream.c         |    3 +-
 gio/gdbusaddress.c             |    5 +--
 gio/gdbusconnection.c          |   23 +++--------
 gio/gdbusprivate.c             |    9 +---
 gio/gdbusproxy.c               |   13 ++----
 gio/gdummyproxyresolver.c      |    3 +-
 gio/gfile.c                    |   80 +++++++++-------------------------------
 gio/gfileenumerator.c          |    5 +--
 gio/gfileicon.c                |    3 +-
 gio/gfileinputstream.c         |    5 +--
 gio/gfileoutputstream.c        |    5 +--
 gio/ginputstream.c             |   26 ++++---------
 gio/giostream.c                |    5 +--
 gio/gloadableicon.c            |    3 +-
 gio/gnetworkaddress.c          |    3 +-
 gio/gnetworkservice.c          |    6 +--
 gio/goutputstream.c            |   23 +++--------
 gio/gproxyaddressenumerator.c  |   17 ++------
 gio/gsocketaddressenumerator.c |    6 +--
 gio/gsocketclient.c            |    3 +-
 gio/gsocketinputstream.c       |    5 +--
 gio/gsocketlistener.c          |    3 +-
 gio/gsocketoutputstream.c      |    5 +--
 gio/gsocks4aproxy.c            |    8 +---
 gio/gsocks5proxy.c             |    4 +-
 gio/gtcpconnection.c           |   11 +----
 gio/gunixinputstream.c         |   10 +----
 gio/gunixmount.c               |    3 +-
 gio/gunixoutputstream.c        |   10 +----
 gio/gunixresolver.c            |   18 ++-------
 gio/gunixvolume.c              |    3 +-
 34 files changed, 98 insertions(+), 270 deletions(-)
---
diff --git a/gio/gasyncinitable.c b/gio/gasyncinitable.c
index 64a89c2..e0e756f 100644
--- a/gio/gasyncinitable.c
+++ b/gio/gasyncinitable.c
@@ -266,10 +266,7 @@ async_init_thread (GSimpleAsyncResult *res,
   GError *error = NULL;
 
   if (!g_initable_init (G_INITABLE (object), cancellable, &error))
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 static void
diff --git a/gio/gbufferedinputstream.c b/gio/gbufferedinputstream.c
index f0f9124..78e61cb 100644
--- a/gio/gbufferedinputstream.c
+++ b/gio/gbufferedinputstream.c
@@ -937,8 +937,7 @@ fill_async_callback (GObject      *source_object,
   g_simple_async_result_set_op_res_gssize (simple, res);
   if (res == -1)
     {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
     }
   else
     {
@@ -1049,14 +1048,13 @@ large_read_callback (GObject *source_object,
 
   /* Only report the error if we've not already read some data */
   if (nread < 0 && data->bytes_read == 0)
-    g_simple_async_result_set_from_error (simple, error);
+    g_simple_async_result_take_error (simple, error);
+  else if (error)
+    g_error_free (error);
 
   if (nread > 0)
     data->bytes_read += nread;
 
-  if (error)
-    g_error_free (error);
-
   /* Complete immediately, not in idle, since we're already
    * in a mainloop callout
    */
@@ -1087,8 +1085,9 @@ read_fill_buffer_callback (GObject      *source_object,
                                                result, &error);
 
   if (nread < 0 && data->bytes_read == 0)
-    g_simple_async_result_set_from_error (simple, error);
-
+    g_simple_async_result_take_error (simple, error);
+  else if (error)
+    g_error_free (error);
 
   if (nread > 0)
     {
@@ -1100,9 +1099,6 @@ read_fill_buffer_callback (GObject      *source_object,
       priv->pos += data->count;
     }
 
-  if (error)
-    g_error_free (error);
-
   /* Complete immediately, not in idle, since we're already
    * in a mainloop callout
    */
@@ -1234,14 +1230,13 @@ large_skip_callback (GObject      *source_object,
 
   /* Only report the error if we've not already read some data */
   if (nread < 0 && data->bytes_skipped == 0)
-    g_simple_async_result_set_from_error (simple, error);
+    g_simple_async_result_take_error (simple, error);
+  else if (error)
+    g_error_free (error);
 
   if (nread > 0)
     data->bytes_skipped += nread;
 
-  if (error)
-    g_error_free (error);
-
   /* Complete immediately, not in idle, since we're already
    * in a mainloop callout
    */
@@ -1272,7 +1267,9 @@ skip_fill_buffer_callback (GObject      *source_object,
                                                result, &error);
 
   if (nread < 0 && data->bytes_skipped == 0)
-    g_simple_async_result_set_from_error (simple, error);
+    g_simple_async_result_take_error (simple, error);
+  else if (error)
+    g_error_free (error);
 
   if (nread > 0)
     {
@@ -1283,9 +1280,6 @@ skip_fill_buffer_callback (GObject      *source_object,
       priv->pos += data->count;
     }
 
-  if (error)
-    g_error_free (error);
-
   /* Complete immediately, not in idle, since we're already
    * in a mainloop callout
    */
diff --git a/gio/gbufferedoutputstream.c b/gio/gbufferedoutputstream.c
index 4d488ca..ffa8fbd 100644
--- a/gio/gbufferedoutputstream.c
+++ b/gio/gbufferedoutputstream.c
@@ -575,10 +575,7 @@ flush_buffer_thread (GSimpleAsyncResult *result,
     }
 
   if (res == FALSE)
-    {
-      g_simple_async_result_set_from_error (result, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (result, error);
 }
 
 typedef struct {
diff --git a/gio/gdatainputstream.c b/gio/gdatainputstream.c
index 3d4860e..7a7af9a 100644
--- a/gio/gdatainputstream.c
+++ b/gio/gdatainputstream.c
@@ -970,8 +970,7 @@ g_data_input_stream_read_line_ready (GObject      *object,
           if (bytes < 0)
             /* stream error. */
             {
-              g_simple_async_result_set_from_error (data->simple, error);
-              g_error_free (error);
+              g_simple_async_result_take_error (data->simple, error);
               data->checked = 0;
             }
 
diff --git a/gio/gdbusaddress.c b/gio/gdbusaddress.c
index 59b55d3..83e7699 100644
--- a/gio/gdbusaddress.c
+++ b/gio/gdbusaddress.c
@@ -806,10 +806,7 @@ get_stream_thread_func (GSimpleAsyncResult *res,
                                                  cancellable,
                                                  &error);
   if (data->stream == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 /**
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index 375ca3c..ef70031 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -1026,10 +1026,7 @@ flush_in_thread_func (GSimpleAsyncResult *res,
   if (!g_dbus_connection_flush_sync (G_DBUS_CONNECTION (object),
                                      cancellable,
                                      &error))
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 /**
@@ -1237,10 +1234,7 @@ close_in_thread_func (GSimpleAsyncResult *res,
   if (!g_dbus_connection_close_sync (G_DBUS_CONNECTION (object),
                                      cancellable,
                                      &error))
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 /**
@@ -1748,7 +1742,7 @@ g_dbus_connection_send_message_with_reply_unlocked (GDBusConnection     *connect
   error = NULL;
   if (!g_dbus_connection_send_message_unlocked (connection, message, flags, out_serial, &error))
     {
-      g_simple_async_result_set_from_error (simple, error);
+      g_simple_async_result_take_error (simple, error);
       g_simple_async_result_complete_in_idle (simple);
       g_object_unref (simple);
       goto out;
@@ -4974,10 +4968,7 @@ g_dbus_connection_call_done (GObject      *source,
     value = NULL;
 
   if (value == NULL)
-    {
-      g_simple_async_result_set_from_error (state->simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (state->simple, error);
   else
     g_simple_async_result_set_op_res_gpointer (state->simple, value,
                                                (GDestroyNotify) g_variant_unref);
@@ -6284,8 +6275,7 @@ bus_get_async_initable_cb (GObject      *source_object,
                                      &error))
     {
       g_assert (error != NULL);
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
       g_object_unref (source_object);
     }
   else
@@ -6335,8 +6325,7 @@ g_bus_get (GBusType             bus_type,
   if (connection == NULL)
     {
       g_assert (error != NULL);
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
       g_simple_async_result_complete_in_idle (simple);
       g_object_unref (simple);
     }
diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c
index dd9d58a..43804a4 100644
--- a/gio/gdbusprivate.c
+++ b/gio/gdbusprivate.c
@@ -153,8 +153,7 @@ _g_socket_read_with_control_messages_ready (GSocket      *socket,
   else
     {
       g_assert (error != NULL);
-      g_simple_async_result_set_from_error (data->simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (data->simple, error);
     }
 
   if (data->from_mainloop)
@@ -908,8 +907,7 @@ write_message_async_cb (GObject      *source_object,
                                                 &error);
   if (bytes_written == -1)
     {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
       g_simple_async_result_complete (simple);
       g_object_unref (simple);
       goto out;
@@ -1028,8 +1026,7 @@ write_message_continue_writing (MessageToWriteData *data)
               g_error_free (error);
               goto out;
             }
-          g_simple_async_result_set_from_error (simple, error);
-          g_error_free (error);
+          g_simple_async_result_take_error (simple, error);
           g_simple_async_result_complete (simple);
           g_object_unref (simple);
           goto out;
diff --git a/gio/gdbusproxy.c b/gio/gdbusproxy.c
index eaa422f..98bd758 100644
--- a/gio/gdbusproxy.c
+++ b/gio/gdbusproxy.c
@@ -1140,8 +1140,7 @@ async_init_get_name_owner_cb (GDBusConnection *connection,
             }
           else
             {
-              g_simple_async_result_set_from_error (data->simple, error);
-              g_error_free (error);
+              g_simple_async_result_take_error (data->simple, error);
               g_simple_async_result_complete_in_idle (data->simple);
               async_init_data_free (data);
               goto out;
@@ -1265,8 +1264,7 @@ async_init_start_service_by_name_cb (GDBusConnection *connection,
 
  failed:
   g_warn_if_fail (error != NULL);
-  g_simple_async_result_set_from_error (data->simple, error);
-  g_error_free (error);
+  g_simple_async_result_take_error (data->simple, error);
   g_simple_async_result_complete_in_idle (data->simple);
   async_init_data_free (data);
 }
@@ -1453,8 +1451,7 @@ get_connection_cb (GObject       *source_object,
                                           data->callback,
                                           data->user_data,
                                           NULL);
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
       g_simple_async_result_complete_in_idle (simple);
       g_object_unref (simple);
     }
@@ -2148,9 +2145,7 @@ reply_cb (GDBusConnection *connection,
                                          &error);
   if (error != NULL)
     {
-      g_simple_async_result_set_from_error (simple,
-                                            error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
     }
   else
     {
diff --git a/gio/gdummyproxyresolver.c b/gio/gdummyproxyresolver.c
index 5d4c347..e3ba2b5 100644
--- a/gio/gdummyproxyresolver.c
+++ b/gio/gdummyproxyresolver.c
@@ -105,8 +105,7 @@ g_dummy_proxy_resolver_lookup_async (GProxyResolver      *resolver,
 
   if (proxies == NULL)
     {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
     }
   else
     {
diff --git a/gio/gfile.c b/gio/gfile.c
index 54b0725..f84e592 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -4830,10 +4830,7 @@ query_info_async_thread (GSimpleAsyncResult *res,
   info = g_file_query_info (G_FILE (object), data->attributes, data->flags, cancellable, &error);
 
   if (info == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     data->info = info;
 }
@@ -4906,10 +4903,7 @@ query_filesystem_info_async_thread (GSimpleAsyncResult *res,
   info = g_file_query_filesystem_info (G_FILE (object), data->attributes, cancellable, &error);
 
   if (info == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     data->info = info;
 }
@@ -4981,10 +4975,7 @@ enumerate_children_async_thread (GSimpleAsyncResult *res,
   enumerator = g_file_enumerate_children (G_FILE (object), data->attributes, data->flags, cancellable, &error);
 
   if (enumerator == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     data->enumerator = enumerator;
 }
@@ -5046,8 +5037,7 @@ open_read_async_thread (GSimpleAsyncResult *res,
                            G_IO_ERROR_NOT_SUPPORTED,
                            _("Operation not supported"));
 
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (res, error);
 
       return;
     }
@@ -5055,10 +5045,7 @@ open_read_async_thread (GSimpleAsyncResult *res,
   stream = iface->read_fn (G_FILE (object), cancellable, &error);
 
   if (stream == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
 }
@@ -5112,10 +5099,7 @@ append_to_async_thread (GSimpleAsyncResult *res,
   stream = iface->append_to (G_FILE (object), *data, cancellable, &error);
 
   if (stream == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
 }
@@ -5175,10 +5159,7 @@ create_async_thread (GSimpleAsyncResult *res,
   stream = iface->create (G_FILE (object), *data, cancellable, &error);
 
   if (stream == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
 }
@@ -5259,10 +5240,7 @@ replace_async_thread (GSimpleAsyncResult *res,
 			   &error);
 
   if (stream == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     data->stream = stream;
 }
@@ -5326,8 +5304,7 @@ open_readwrite_async_thread (GSimpleAsyncResult *res,
                            G_IO_ERROR_NOT_SUPPORTED,
                            _("Operation not supported"));
 
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (res, error);
 
       return;
     }
@@ -5335,10 +5312,7 @@ open_readwrite_async_thread (GSimpleAsyncResult *res,
   stream = iface->open_readwrite (G_FILE (object), cancellable, &error);
 
   if (stream == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
 }
@@ -5395,8 +5369,7 @@ create_readwrite_async_thread (GSimpleAsyncResult *res,
                            G_IO_ERROR_NOT_SUPPORTED,
                            _("Operation not supported"));
 
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (res, error);
 
       return;
     }
@@ -5404,10 +5377,7 @@ create_readwrite_async_thread (GSimpleAsyncResult *res,
   stream = iface->create_readwrite (G_FILE (object), *data, cancellable, &error);
 
   if (stream == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     g_simple_async_result_set_op_res_gpointer (res, stream, g_object_unref);
 }
@@ -5488,10 +5458,7 @@ replace_readwrite_async_thread (GSimpleAsyncResult *res,
 				     &error);
 
   if (stream == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     data->stream = stream;
 }
@@ -5566,10 +5533,7 @@ set_display_name_async_thread (GSimpleAsyncResult *res,
   file = g_file_set_display_name (G_FILE (object), data->name, cancellable, &error);
 
   if (file == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     data->file = file;
 }
@@ -5702,10 +5666,7 @@ find_enclosing_mount_async_thread (GSimpleAsyncResult *res,
   mount = g_file_find_enclosing_mount (G_FILE (object), cancellable, &error);
 
   if (mount == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     g_simple_async_result_set_op_res_gpointer (res, mount, (GDestroyNotify)g_object_unref);
 }
@@ -5834,10 +5795,7 @@ copy_async_thread (GIOSchedulerJob *job,
 					 NULL, NULL);
   
   if (!result)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 
   g_simple_async_result_complete_in_idle (res);
 
@@ -6410,12 +6368,11 @@ load_contents_open_callback (GObject      *obj,
     }
   else
     {
-      res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
+      res = g_simple_async_result_new_take_error (G_OBJECT (data->file),
 						  data->callback,
 						  data->user_data,
 						  error);
       g_simple_async_result_complete (res);
-      g_error_free (error);
       load_contents_data_free (data);
       g_object_unref (res);
     }
@@ -6814,12 +6771,11 @@ replace_contents_open_callback (GObject      *obj,
     }
   else
     {
-      res = g_simple_async_result_new_from_error (G_OBJECT (data->file),
+      res = g_simple_async_result_new_take_error (G_OBJECT (data->file),
 						  data->callback,
 						  data->user_data,
 						  error);
       g_simple_async_result_complete (res);
-      g_error_free (error);
       replace_contents_data_free (data);
       g_object_unref (res);
     }
diff --git a/gio/gfileenumerator.c b/gio/gfileenumerator.c
index 8c01a87..ac7a724 100644
--- a/gio/gfileenumerator.c
+++ b/gio/gfileenumerator.c
@@ -718,10 +718,7 @@ close_async_thread (GSimpleAsyncResult *res,
   class = G_FILE_ENUMERATOR_GET_CLASS (object);
   result = class->close_fn (G_FILE_ENUMERATOR (object), cancellable, &error);
   if (!result)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 
diff --git a/gio/gfileicon.c b/gio/gfileicon.c
index 1017040..74d75b8 100644
--- a/gio/gfileicon.c
+++ b/gio/gfileicon.c
@@ -309,11 +309,10 @@ load_async_callback (GObject      *source_object,
   
   if (stream == NULL)
     {
-      simple = g_simple_async_result_new_from_error (G_OBJECT (data->icon),
+      simple = g_simple_async_result_new_take_error (G_OBJECT (data->icon),
 						     data->callback,
 						     data->user_data,
 						     error);
-      g_error_free (error);
     }
   else
     {
diff --git a/gio/gfileinputstream.c b/gio/gfileinputstream.c
index 771e8ef..74b17ba 100644
--- a/gio/gfileinputstream.c
+++ b/gio/gfileinputstream.c
@@ -421,10 +421,7 @@ query_info_async_thread (GSimpleAsyncResult *res,
                          _("Stream doesn't support query_info"));
 
   if (info == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     data->info = info;
 }
diff --git a/gio/gfileoutputstream.c b/gio/gfileoutputstream.c
index b3e16ec..735b6d8 100644
--- a/gio/gfileoutputstream.c
+++ b/gio/gfileoutputstream.c
@@ -524,10 +524,7 @@ query_info_async_thread (GSimpleAsyncResult *res,
                          _("Stream doesn't support query_info"));
 
   if (info == NULL)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
   else
     data->info = info;
 }
diff --git a/gio/ginputstream.c b/gio/ginputstream.c
index a66e9cf..7535bfa 100644
--- a/gio/ginputstream.c
+++ b/gio/ginputstream.c
@@ -947,10 +947,7 @@ read_async_thread (GSimpleAsyncResult *res,
 				   op->buffer, op->count_requested,
 				   cancellable, &error);
   if (op->count_read == -1)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 static void
@@ -1012,10 +1009,7 @@ skip_async_thread (GSimpleAsyncResult *res,
 				   op->count_requested,
 				   cancellable, &error);
   if (op->count_skipped == -1)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 typedef struct {
@@ -1066,13 +1060,12 @@ skip_callback_wrapper (GObject      *source_object,
 
   if (ret == -1)
     {
-      if (data->count_skipped && 
-	  error->domain == G_IO_ERROR &&
-	  error->code == G_IO_ERROR_CANCELLED)
-	{ /* No error, return partial read */ }
+      if (data->count_skipped &&
+          g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+	/* No error, return partial read */
+	g_error_free (error);
       else
-	g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+	g_simple_async_result_take_error (simple, error);
     }
 
   /* Complete immediately, not in idle, since we're already in a mainloop callout */
@@ -1164,10 +1157,7 @@ close_async_thread (GSimpleAsyncResult *res,
     {
       result = class->close_fn (G_INPUT_STREAM (object), cancellable, &error);
       if (!result)
-	{
-	  g_simple_async_result_set_from_error (res, error);
-	  g_error_free (error);
-	}
+        g_simple_async_result_take_error (res, error);
     }
 }
 
diff --git a/gio/giostream.c b/gio/giostream.c
index 38b4148..3f601a8 100644
--- a/gio/giostream.c
+++ b/gio/giostream.c
@@ -570,10 +570,7 @@ close_async_thread (GSimpleAsyncResult *res,
     {
       result = class->close_fn (G_IO_STREAM (object), cancellable, &error);
       if (!result)
-	{
-	  g_simple_async_result_set_from_error (res, error);
-	  g_error_free (error);
-	}
+        g_simple_async_result_take_error (res, error);
     }
 }
 
diff --git a/gio/gloadableicon.c b/gio/gloadableicon.c
index 2e53ce3..1cad7fc 100644
--- a/gio/gloadableicon.c
+++ b/gio/gloadableicon.c
@@ -188,8 +188,7 @@ load_async_thread (GSimpleAsyncResult *res,
 
   if (stream == NULL)
     {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (res, error);
     }
   else
     {
diff --git a/gio/gnetworkaddress.c b/gio/gnetworkaddress.c
index ad7a87b..3f3962d 100644
--- a/gio/gnetworkaddress.c
+++ b/gio/gnetworkaddress.c
@@ -855,8 +855,7 @@ got_addresses (GObject      *source_object,
     {
       if (error)
         {
-          g_simple_async_result_set_from_error (simple, error);
-          g_error_free (error);
+          g_simple_async_result_take_error (simple, error);
         }
       else
         {
diff --git a/gio/gnetworkservice.c b/gio/gnetworkservice.c
index c07d57a..a31433d 100644
--- a/gio/gnetworkservice.c
+++ b/gio/gnetworkservice.c
@@ -595,8 +595,7 @@ next_async_resolved_targets (GObject      *source_object,
       GSimpleAsyncResult *simple = srv_enum->result;
 
       srv_enum->result = NULL;
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
       g_simple_async_result_complete (simple);
       g_object_unref (simple);
     }
@@ -642,8 +641,7 @@ next_async_have_targets (GNetworkServiceAddressEnumerator *srv_enum)
 
       if (srv_enum->error)
         {
-          g_simple_async_result_set_from_error (simple, srv_enum->error);
-          g_error_free (srv_enum->error);
+          g_simple_async_result_take_error (simple, srv_enum->error);
           srv_enum->error = NULL;
         }
 
diff --git a/gio/goutputstream.c b/gio/goutputstream.c
index ff3486c..9bdc408 100644
--- a/gio/goutputstream.c
+++ b/gio/goutputstream.c
@@ -595,10 +595,11 @@ async_ready_close_callback_wrapper (GObject      *source_object,
         {
           GSimpleAsyncResult *err;
 
-          err = g_simple_async_result_new_from_error (source_object,
+          err = g_simple_async_result_new_take_error (source_object,
                                                       stream->priv->outstanding_callback,
                                                       data->user_data,
                                                       data->flush_error);
+          data->flush_error = NULL;
 
           (*stream->priv->outstanding_callback) (source_object,
                                                  G_ASYNC_RESULT (err),
@@ -1254,10 +1255,7 @@ write_async_thread (GSimpleAsyncResult *res,
   op->count_written = class->write_fn (G_OUTPUT_STREAM (object), op->buffer, op->count_requested,
 				       cancellable, &error);
   if (op->count_written == -1)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 static void
@@ -1321,10 +1319,7 @@ splice_async_thread (GSimpleAsyncResult *result,
 				    cancellable,
 				    &error);
   if (op->bytes_copied == -1)
-    {
-      g_simple_async_result_set_from_error (result, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (result, error);
 }
 
 static void
@@ -1381,10 +1376,7 @@ flush_async_thread (GSimpleAsyncResult *res,
     result = class->flush (G_OUTPUT_STREAM (object), cancellable, &error);
 
   if (!result)
-    {
-      g_simple_async_result_set_from_error (res, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (res, error);
 }
 
 static void
@@ -1444,10 +1436,7 @@ close_async_thread (GSimpleAsyncResult *res,
         result = class->close_fn (G_OUTPUT_STREAM (object), cancellable, &error);
 
       if (!result)
-	{
-	  g_simple_async_result_set_from_error (res, error);
-	  g_error_free (error);
-	}
+        g_simple_async_result_take_error (res, error);
     }
 }
 
diff --git a/gio/gproxyaddressenumerator.c b/gio/gproxyaddressenumerator.c
index 29604dc..460c30c 100644
--- a/gio/gproxyaddressenumerator.c
+++ b/gio/gproxyaddressenumerator.c
@@ -393,14 +393,9 @@ dest_hostname_lookup_cb (GObject           *object,
 						     result,
 						     &error);
   if (priv->dest_ips)
-    {
-      save_result (priv);
-    }
+    save_result (priv);
   else
-    {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (simple, error);
 
   complete_async (priv); 
 }
@@ -459,10 +454,7 @@ address_enumerate_cb (GObject	   *object,
     }
 
   if (error)
-    {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (simple, error);
 
   complete_async (priv); 
 }
@@ -483,8 +475,7 @@ proxy_lookup_cb (GObject      *object,
 
   if (error)
     {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (simple, error);
     }
   else
     {
diff --git a/gio/gsocketaddressenumerator.c b/gio/gsocketaddressenumerator.c
index 7ad1ccc..1886f36 100644
--- a/gio/gsocketaddressenumerator.c
+++ b/gio/gsocketaddressenumerator.c
@@ -106,10 +106,8 @@ g_socket_address_enumerator_real_next_async (GSocketAddressEnumerator *enumerato
   if (address)
     g_simple_async_result_set_op_res_gpointer (result, address, NULL);
   else if (error)
-    {
-      g_simple_async_result_set_from_error (result, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (result, error);
+
   g_simple_async_result_complete_in_idle (result);
   g_object_unref (result);
 }
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
index 7064fc8..b2cbcee 100644
--- a/gio/gsocketclient.c
+++ b/gio/gsocketclient.c
@@ -938,8 +938,7 @@ g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
 {
   if (data->last_error)
     {
-      g_simple_async_result_set_from_error (data->result, data->last_error);
-      g_error_free (data->last_error);
+      g_simple_async_result_take_error (data->result, data->last_error);
     }
   else
     {
diff --git a/gio/gsocketinputstream.c b/gio/gsocketinputstream.c
index 07c4740..4a27d90 100644
--- a/gio/gsocketinputstream.c
+++ b/gio/gsocketinputstream.c
@@ -142,10 +142,7 @@ g_socket_input_stream_read_ready (GSocket *socket,
     g_simple_async_result_set_op_res_gssize (simple, result);
 
   if (error)
-    {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (simple, error);
 
   if (stream->priv->cancellable)
     g_object_unref (stream->priv->cancellable);
diff --git a/gio/gsocketlistener.c b/gio/gsocketlistener.c
index 8bb5748..503fa31 100644
--- a/gio/gsocketlistener.c
+++ b/gio/gsocketlistener.c
@@ -710,8 +710,7 @@ accept_ready (GSocket      *accept_socket,
     }
   else
     {
-      g_simple_async_result_set_from_error (data->simple, error);
-      g_error_free (error);
+      g_simple_async_result_take_error (data->simple, error);
     }
 
   g_simple_async_result_complete_in_idle (data->simple);
diff --git a/gio/gsocketoutputstream.c b/gio/gsocketoutputstream.c
index b5d9412..4febf88 100644
--- a/gio/gsocketoutputstream.c
+++ b/gio/gsocketoutputstream.c
@@ -144,10 +144,7 @@ g_socket_output_stream_write_ready (GSocket *socket,
     g_simple_async_result_set_op_res_gssize (simple, result);
 
   if (error)
-    {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (simple, error);
 
   if (stream->priv->cancellable)
     g_object_unref (stream->priv->cancellable);
diff --git a/gio/gsocks4aproxy.c b/gio/gsocks4aproxy.c
index 097b534..91ca29d 100644
--- a/gio/gsocks4aproxy.c
+++ b/gio/gsocks4aproxy.c
@@ -288,9 +288,7 @@ static void
 complete_async_from_error (ConnectAsyncData *data, GError *error)
 {
   GSimpleAsyncResult *simple = data->simple;
-  g_simple_async_result_set_from_error (data->simple,
-					error);
-  g_error_free (error);
+  g_simple_async_result_take_error (data->simple, error);
   g_simple_async_result_set_op_res_gpointer (simple, NULL, NULL);
   g_simple_async_result_complete (simple);
   g_object_unref (simple);
@@ -364,9 +362,7 @@ g_socks4a_proxy_connect_async (GProxy               *proxy,
 
   if (data->length < 0)
     {
-      g_simple_async_result_set_from_error (data->simple,
-					    error);
-      g_error_free (error);
+      g_simple_async_result_take_error (data->simple, error);
       g_simple_async_result_set_op_res_gpointer (simple, NULL, NULL);
       g_simple_async_result_complete_in_idle (simple);
       g_object_unref (simple);
diff --git a/gio/gsocks5proxy.c b/gio/gsocks5proxy.c
index 431a13a..046f290 100644
--- a/gio/gsocks5proxy.c
+++ b/gio/gsocks5proxy.c
@@ -599,9 +599,7 @@ static void
 complete_async_from_error (ConnectAsyncData *data, GError *error)
 {
   GSimpleAsyncResult *simple = data->simple;
-  g_simple_async_result_set_from_error (data->simple,
-					error);
-  g_error_free (error);
+  g_simple_async_result_take_error (data->simple, error);
   g_simple_async_result_set_op_res_gpointer (simple, NULL, NULL);
   g_simple_async_result_complete (simple);
   g_object_unref (simple);
diff --git a/gio/gtcpconnection.c b/gio/gtcpconnection.c
index 89aeaba..08364c1 100644
--- a/gio/gtcpconnection.c
+++ b/gio/gtcpconnection.c
@@ -210,7 +210,7 @@ close_async_data_free (CloseAsyncData *data)
 
 static void
 async_close_finish (CloseAsyncData *data,
-                    GError         *error,
+                    GError         *error /* consumed */,
                     gboolean        in_mainloop)
 {
   GIOStreamClass *parent = G_IO_STREAM_CLASS (g_tcp_connection_parent_class);
@@ -223,17 +223,14 @@ async_close_finish (CloseAsyncData *data,
   if (error)
     {
       parent->close_fn (stream, data->cancellable, NULL);
-      g_simple_async_result_set_from_error (data->res, error);
+      g_simple_async_result_take_error (data->res, error);
     }
   else
     {
       my_error = NULL;
       parent->close_fn (stream, data->cancellable, &my_error);
       if (my_error)
-	{
-	  g_simple_async_result_set_from_error (data->res, my_error);
-	  g_error_free (my_error);
-	}
+        g_simple_async_result_take_error (data->res, my_error);
     }
 
   if (in_mainloop)
@@ -260,7 +257,6 @@ close_read_ready (GSocket        *socket,
       else
 	{
 	  async_close_finish (data, error, TRUE);
-	  g_error_free (error);
 	  return FALSE;
 	}
     }
@@ -306,7 +302,6 @@ g_tcp_connection_close_async (GIOStream           *stream,
       if (!g_socket_shutdown (socket, FALSE, TRUE, &error))
 	{
 	  async_close_finish (data, error, FALSE);
-	  g_error_free (error);
 	  close_async_data_free (data);
 	  return;
 	}
diff --git a/gio/gunixinputstream.c b/gio/gunixinputstream.c
index 84422fb..958d003 100644
--- a/gio/gunixinputstream.c
+++ b/gio/gunixinputstream.c
@@ -462,10 +462,7 @@ read_async_cb (ReadAsyncData *data,
   g_simple_async_result_set_op_res_gssize (simple, count_read);
 
   if (count_read == -1)
-    {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (simple, error);
 
   /* Complete immediately, not in idle, since we're already in a mainloop callout */
   g_simple_async_result_complete (simple);
@@ -601,10 +598,7 @@ close_async_cb (CloseAsyncData *data)
 				      g_unix_input_stream_close_async);
 
   if (!result)
-    {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (simple, error);
 
   /* Complete immediately, not in idle, since we're already in a mainloop callout */
   g_simple_async_result_complete (simple);
diff --git a/gio/gunixmount.c b/gio/gunixmount.c
index c030a04..9da2474 100644
--- a/gio/gunixmount.c
+++ b/gio/gunixmount.c
@@ -370,7 +370,7 @@ eject_unmount_do_cb (gpointer user_data)
 handle_error:
   if (error != NULL) {
     GSimpleAsyncResult *simple;
-    simple = g_simple_async_result_new_from_error (G_OBJECT (data->unix_mount),
+    simple = g_simple_async_result_new_take_error (G_OBJECT (data->unix_mount),
                                                    data->callback,
                                                    data->user_data,
                                                    error);
@@ -384,7 +384,6 @@ handle_error:
       g_io_channel_unref (data->error_channel);
 
     g_strfreev (data->argv);
-    g_error_free (error);
     g_free (data);
   }
 
diff --git a/gio/gunixoutputstream.c b/gio/gunixoutputstream.c
index 0d43c66..5bc1918 100644
--- a/gio/gunixoutputstream.c
+++ b/gio/gunixoutputstream.c
@@ -449,10 +449,7 @@ write_async_cb (WriteAsyncData *data,
   g_simple_async_result_set_op_res_gssize (simple, count_written);
 
   if (count_written == -1)
-    {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (simple, error);
 
   /* Complete immediately, not in idle, since we're already in a mainloop callout */
   g_simple_async_result_complete (simple);
@@ -557,10 +554,7 @@ close_async_cb (CloseAsyncData *data)
 				      g_unix_output_stream_close_async);
 
   if (!result)
-    {
-      g_simple_async_result_set_from_error (simple, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (simple, error);
 
   /* Complete immediately, not in idle, since we're already in a mainloop callout */
   g_simple_async_result_complete (simple);
diff --git a/gio/gunixresolver.c b/gio/gunixresolver.c
index ed5e2d1..9f430ec 100644
--- a/gio/gunixresolver.c
+++ b/gio/gunixresolver.c
@@ -232,8 +232,7 @@ request_cancelled (GCancellable *cancellable,
   req->qy = NULL;
 
   g_cancellable_set_error_if_cancelled (cancellable, &error);
-  g_simple_async_result_set_from_error (req->async_result, error);
-  g_error_free (error);
+  g_simple_async_result_take_error (req->async_result, error);
 
   g_unix_resolver_request_complete (req);
 }
@@ -303,10 +302,7 @@ lookup_by_name_process (GUnixResolverRequest *req)
     freeaddrinfo (res);
 
   if (error)
-    {
-      g_simple_async_result_set_from_error (req->async_result, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (req->async_result, error);
 }
 
 static void
@@ -373,10 +369,7 @@ lookup_by_address_process (GUnixResolverRequest *req)
                                     host, retval, &error);
 
   if (error)
-    {
-      g_simple_async_result_set_from_error (req->async_result, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (req->async_result, error);
 }
 
 static void
@@ -453,10 +446,7 @@ lookup_service_process (GUnixResolverRequest *req)
   _g_asyncns_freeanswer (answer);
 
   if (error)
-    {
-      g_simple_async_result_set_from_error (req->async_result, error);
-      g_error_free (error);
-    }
+    g_simple_async_result_take_error (req->async_result, error);
 }
 
 static void
diff --git a/gio/gunixvolume.c b/gio/gunixvolume.c
index 3cf6094..1dc840b 100644
--- a/gio/gunixvolume.c
+++ b/gio/gunixvolume.c
@@ -410,7 +410,7 @@ handle_error:
   if (error != NULL)
     {
       GSimpleAsyncResult *simple;
-      simple = g_simple_async_result_new_from_error (G_OBJECT (data->unix_volume),
+      simple = g_simple_async_result_new_take_error (G_OBJECT (data->unix_volume),
                                                      data->callback,
                                                      data->user_data,
                                                      error);
@@ -423,7 +423,6 @@ handle_error:
       if (data->error_channel != NULL)
         g_io_channel_unref (data->error_channel);
 
-      g_error_free (error);
       g_free (data);
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]