[gnome-builder/wip/gtk4-port: 1557/1774] libide/threading: add helper to merge with dest_fd check
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1557/1774] libide/threading: add helper to merge with dest_fd check
- Date: Mon, 11 Jul 2022 22:31:49 +0000 (UTC)
commit a6ccb60cf648dc3628f6d0451e7f4f62175cc4ee
Author: Christian Hergert <chergert redhat com>
Date: Fri Jun 17 01:01:34 2022 -0700
libide/threading: add helper to merge with dest_fd check
src/libide/threading/ide-unix-fd-map.c | 36 ++++++++++++++++++++++++++++++++++
src/libide/threading/ide-unix-fd-map.h | 6 +++++-
2 files changed, 41 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/threading/ide-unix-fd-map.c b/src/libide/threading/ide-unix-fd-map.c
index 75946f4b7..de839480b 100644
--- a/src/libide/threading/ide-unix-fd-map.c
+++ b/src/libide/threading/ide-unix-fd-map.c
@@ -382,3 +382,39 @@ ide_unix_fd_map_open_file (IdeUnixFDMap *self,
return TRUE;
}
+
+gboolean
+ide_unix_fd_map_steal_from (IdeUnixFDMap *self,
+ IdeUnixFDMap *other,
+ GError **error)
+{
+ g_return_val_if_fail (IDE_IS_UNIX_FD_MAP (self), FALSE);
+ g_return_val_if_fail (IDE_IS_UNIX_FD_MAP (other), FALSE);
+
+ for (guint i = 0; i < other->map->len; i++)
+ {
+ IdeUnixFDMapItem *item = &g_array_index (other->map, IdeUnixFDMapItem, i);
+
+ if (item->source_fd != -1)
+ {
+ for (guint j = 0; j < self->map->len; j++)
+ {
+ IdeUnixFDMapItem *ele = &g_array_index (self->map, IdeUnixFDMapItem, j);
+
+ if (ele->dest_fd == item->dest_fd && ele->source_fd != -1)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ "Attempt to merge overlapping destination FDs for %d",
+ item->dest_fd);
+ return FALSE;
+ }
+ }
+
+ ide_unix_fd_map_take (self, ide_steal_fd (&item->source_fd), item->dest_fd);
+ }
+ }
+
+ return TRUE;
+}
diff --git a/src/libide/threading/ide-unix-fd-map.h b/src/libide/threading/ide-unix-fd-map.h
index 1c13bdc07..c3c4f0e96 100644
--- a/src/libide/threading/ide-unix-fd-map.h
+++ b/src/libide/threading/ide-unix-fd-map.h
@@ -50,6 +50,10 @@ int ide_unix_fd_map_steal_stdout (IdeUnixFDMap *self);
IDE_AVAILABLE_IN_ALL
int ide_unix_fd_map_steal_stderr (IdeUnixFDMap *self);
IDE_AVAILABLE_IN_ALL
+gboolean ide_unix_fd_map_steal_from (IdeUnixFDMap *self,
+ IdeUnixFDMap *other,
+ GError **error);
+IDE_AVAILABLE_IN_ALL
int ide_unix_fd_map_peek (IdeUnixFDMap *self,
guint index,
int *dest_fd);
@@ -73,7 +77,7 @@ gboolean ide_unix_fd_map_open_file (IdeUnixFDMap *self,
int dest_fd,
GError **error);
IDE_AVAILABLE_IN_ALL
-int ide_unix_fd_map_get_max_dest_fd (IdeUnixFDMap *self);
+int ide_unix_fd_map_get_max_dest_fd (IdeUnixFDMap *self);
IDE_AVAILABLE_IN_ALL
gboolean ide_unix_fd_map_stdin_isatty (IdeUnixFDMap *self);
IDE_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]