gfile: Add g_file_{copy,move}_async_with_closures

g_file_copy_async() and g_file_move_async() are written in a way that is
not bindable with gobject-introspection. The progress callback data can
be freed once the async callback has been called, which is convenient
for C, but in language bindings the progress callback closure is
currently just leaked.

There is no scope annotation that fits how the progress callback should
be treated:

- (scope call) is correct for the sync versions of the functions, but
  incorrect for the async functions; the progress callback is called
  after the async functions return.
- (scope notified) is incorrect because there is no GDestroyNotify
  parameter, meaning the callback will always leak.
- (scope async) is incorrect because the callback is called more than
  once.
- (scope forever) is incorrect because the callback closure could be
  freed after the async callback runs.

This adds g_file_copy_async_with_closures() and
g_file_move_async_with_closures() for the benefit of language bindings.

See: GNOME/gjs#590
This commit is contained in:
Philip Chimento
2024-02-25 17:31:35 -08:00
committed by Philip Withnall
parent afcb839121
commit 64b06c633a
3 changed files with 358 additions and 0 deletions

View File

@@ -944,6 +944,14 @@ void g_file_copy_async (GFile
gpointer progress_callback_data,
GAsyncReadyCallback callback,
gpointer user_data);
GIO_AVAILABLE_IN_2_82
void g_file_copy_async_with_closures (GFile *source,
GFile *destination,
GFileCopyFlags flags,
int io_priority,
GCancellable *cancellable,
GClosure *progress_callback_closure,
GClosure *ready_callback_closure);
GIO_AVAILABLE_IN_ALL
gboolean g_file_copy_finish (GFile *file,
GAsyncResult *res,
@@ -966,6 +974,14 @@ void g_file_move_async (GFile
gpointer progress_callback_data,
GAsyncReadyCallback callback,
gpointer user_data);
GIO_AVAILABLE_IN_2_82
void g_file_move_async_with_closures (GFile *source,
GFile *destination,
GFileCopyFlags flags,
int io_priority,
GCancellable *cancellable,
GClosure *progress_callback_closure,
GClosure *ready_callback_closure);
GIO_AVAILABLE_IN_2_72
gboolean g_file_move_finish (GFile *file,
GAsyncResult *result,