mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 12:41:50 +01:00
gio: handle GSimpleAsyncResult errors in _finish vmethods
Originally, the standard idiom with GSimpleAsyncResult was to handle all errors in the _finish wrapper function, so that vmethods only had to deal with successful results. But this means that chaining up to a parent _finish vmethod won't work correctly. Fix this by also checking for errors in all the relevant vmethods. (We have to redundantly check in both the vmethod and the wrapper to preserve compatibility.) https://bugzilla.gnome.org/show_bug.cgi?id=667375 https://bugzilla.gnome.org/show_bug.cgi?id=661767
This commit is contained in:
parent
a98d26c9bb
commit
538b2f106d
@ -294,18 +294,15 @@ g_async_initable_real_init_finish (GAsyncInitable *initable,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
/* Although g_async_initable_init_finish() does this error handling
|
||||
* as well, we do it here too, so that a class that reimplements
|
||||
* GAsyncInitable can properly run its parent class's implementation
|
||||
* by directly invoking its ->init_async() and ->init_finish().
|
||||
*/
|
||||
if (G_IS_SIMPLE_ASYNC_RESULT (res))
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
||||
GSimpleAsyncResult *simple;
|
||||
|
||||
g_return_val_if_fail (g_simple_async_result_is_valid (res, G_OBJECT (initable),
|
||||
g_async_initable_real_init_async),
|
||||
FALSE);
|
||||
|
||||
simple = G_SIMPLE_ASYNC_RESULT (res);
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1131,6 +1131,9 @@ g_buffered_input_stream_real_fill_finish (GBufferedInputStream *stream,
|
||||
simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_buffered_input_stream_real_fill_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return -1;
|
||||
|
||||
nread = g_simple_async_result_get_op_res_gssize (simple);
|
||||
return nread;
|
||||
}
|
||||
|
42
gio/gfile.c
42
gio/gfile.c
@ -4889,6 +4889,9 @@ g_file_real_query_info_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_info_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (data->info)
|
||||
return g_object_ref (data->info);
|
||||
@ -4960,6 +4963,9 @@ g_file_real_query_filesystem_info_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_query_filesystem_info_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (data->info)
|
||||
return g_object_ref (data->info);
|
||||
@ -5034,6 +5040,9 @@ g_file_real_enumerate_children_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_enumerate_children_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (data->enumerator)
|
||||
return g_object_ref (data->enumerator);
|
||||
@ -5096,6 +5105,9 @@ g_file_real_read_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_read_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (op)
|
||||
return g_object_ref (op);
|
||||
@ -5156,6 +5168,9 @@ g_file_real_append_to_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_append_to_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (op)
|
||||
return g_object_ref (op);
|
||||
@ -5216,6 +5231,9 @@ g_file_real_create_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (op)
|
||||
return g_object_ref (op);
|
||||
@ -5301,6 +5319,9 @@ g_file_real_replace_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (data->stream)
|
||||
return g_object_ref (data->stream);
|
||||
@ -5363,6 +5384,9 @@ g_file_real_open_readwrite_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_open_readwrite_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (op)
|
||||
return g_object_ref (op);
|
||||
@ -5434,6 +5458,9 @@ g_file_real_create_readwrite_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_create_readwrite_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (op)
|
||||
return g_object_ref (op);
|
||||
@ -5519,6 +5546,9 @@ g_file_real_replace_readwrite_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_replace_readwrite_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (data->stream)
|
||||
return g_object_ref (data->stream);
|
||||
@ -5590,6 +5620,9 @@ g_file_real_set_display_name_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_set_display_name_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (data->file)
|
||||
return g_object_ref (data->file);
|
||||
@ -5717,6 +5750,9 @@ g_file_real_find_enclosing_mount_finish (GFile *file,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_real_find_enclosing_mount_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
mount = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
return g_object_ref (mount);
|
||||
}
|
||||
@ -5840,7 +5876,11 @@ g_file_real_copy_finish (GFile *file,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
/* Error handled in g_file_copy_finish() */
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -693,6 +693,9 @@ g_file_enumerator_real_next_files_finish (GFileEnumerator *enumer
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) ==
|
||||
g_file_enumerator_real_next_files_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
|
||||
res = op->files;
|
||||
@ -750,7 +753,12 @@ g_file_enumerator_real_close_finish (GFileEnumerator *enumerator,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) ==
|
||||
g_file_enumerator_real_close_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -456,6 +456,9 @@ g_file_input_stream_real_query_info_finish (GFileInputStream *stream,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_input_stream_real_query_info_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (data->info)
|
||||
return g_object_ref (data->info);
|
||||
|
@ -559,6 +559,9 @@ g_file_output_stream_real_query_info_finish (GFileOutputStream *stream,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_output_stream_real_query_info_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
if (data->info)
|
||||
return g_object_ref (data->info);
|
||||
|
@ -1227,6 +1227,9 @@ g_input_stream_real_read_finish (GInputStream *stream,
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) ==
|
||||
g_input_stream_real_read_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return -1;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
|
||||
return op->count_read;
|
||||
@ -1378,6 +1381,10 @@ g_input_stream_real_skip_finish (GInputStream *stream,
|
||||
SkipData *op;
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_input_stream_real_skip_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return -1;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
return op->count_skipped;
|
||||
}
|
||||
@ -1434,6 +1441,11 @@ g_input_stream_real_close_finish (GInputStream *stream,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_input_stream_real_close_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -588,8 +588,13 @@ g_io_stream_real_close_finish (GIOStream *stream,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) ==
|
||||
g_io_stream_real_close_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -229,6 +229,9 @@ g_loadable_icon_real_load_finish (GLoadableIcon *icon,
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_loadable_icon_real_load_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return NULL;
|
||||
|
||||
data = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
|
||||
if (type)
|
||||
|
@ -1546,6 +1546,10 @@ g_output_stream_real_write_finish (GOutputStream *stream,
|
||||
WriteData *op;
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_output_stream_real_write_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return -1;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
return op->count_written;
|
||||
}
|
||||
@ -1613,6 +1617,10 @@ g_output_stream_real_splice_finish (GOutputStream *stream,
|
||||
SpliceData *op;
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_output_stream_real_splice_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return -1;
|
||||
|
||||
op = g_simple_async_result_get_op_res_gpointer (simple);
|
||||
return op->bytes_copied;
|
||||
}
|
||||
@ -1656,6 +1664,10 @@ g_output_stream_real_flush_finish (GOutputStream *stream,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -1720,6 +1732,10 @@ g_output_stream_real_close_finish (GOutputStream *stream,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
||||
|
||||
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_output_stream_real_close_async);
|
||||
|
||||
if (g_simple_async_result_propagate_error (simple, error))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user