add new list type simple_oid_string_list to fe-utils/simple_list
authorAndrew Dunstan <[email protected]>
Fri, 28 Mar 2025 22:10:24 +0000 (18:10 -0400)
committerAndrew Dunstan <[email protected]>
Fri, 4 Apr 2025 20:01:22 +0000 (16:01 -0400)
This type contains both an oid and a string.

This will be used in forthcoming changes to pg_restore.

Author: Andrew Dunstan <[email protected]>

src/fe_utils/simple_list.c
src/include/fe_utils/simple_list.h
src/tools/pgindent/typedefs.list

index 483d5455594b392884bec93096193cabddfc7224..b0686e57c4a742329995708cb0fc27e8f3b5749e 100644 (file)
@@ -192,3 +192,44 @@ simple_ptr_list_destroy(SimplePtrList *list)
        cell = next;
    }
 }
+
+/*
+ * Add to an oid_string list
+ */
+void
+simple_oid_string_list_append(SimpleOidStringList *list, Oid oid, const char *str)
+{
+   SimpleOidStringListCell *cell;
+
+   cell = (SimpleOidStringListCell *)
+       pg_malloc(offsetof(SimpleOidStringListCell, str) + strlen(str) + 1);
+
+   cell->next = NULL;
+   cell->oid = oid;
+   strcpy(cell->str, str);
+
+   if (list->tail)
+       list->tail->next = cell;
+   else
+       list->head = cell;
+   list->tail = cell;
+}
+
+/*
+ * Destroy an oid_string list
+ */
+void
+simple_oid_string_list_destroy(SimpleOidStringList *list)
+{
+   SimpleOidStringListCell *cell;
+
+   cell = list->head;
+   while (cell != NULL)
+   {
+       SimpleOidStringListCell *next;
+
+       next = cell->next;
+       pg_free(cell);
+       cell = next;
+   }
+}
index 3b8e38414ecde53b600c57ff10df00ea1b678e08..a5373932555223b69ab1531dbd626a83c61f69d2 100644 (file)
@@ -55,6 +55,19 @@ typedef struct SimplePtrList
    SimplePtrListCell *tail;
 } SimplePtrList;
 
+typedef struct SimpleOidStringListCell
+{
+   struct SimpleOidStringListCell *next;
+   Oid         oid;
+   char        str[FLEXIBLE_ARRAY_MEMBER]; /* null-terminated string here */
+}          SimpleOidStringListCell;
+
+typedef struct SimpleOidStringList
+{
+   SimpleOidStringListCell *head;
+   SimpleOidStringListCell *tail;
+} SimpleOidStringList;
+
 extern void simple_oid_list_append(SimpleOidList *list, Oid val);
 extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
 extern void simple_oid_list_destroy(SimpleOidList *list);
@@ -68,4 +81,7 @@ extern const char *simple_string_list_not_touched(SimpleStringList *list);
 extern void simple_ptr_list_append(SimplePtrList *list, void *ptr);
 extern void simple_ptr_list_destroy(SimplePtrList *list);
 
+extern void simple_oid_string_list_append(SimpleOidStringList *list, Oid oid, const char *str);
+extern void simple_oid_string_list_destroy(SimpleOidStringList *list);
+
 #endif                         /* SIMPLE_LIST_H */
index b69b3b1520cb33858ecb020804ba94db2e2b86c1..0c81d03950d354b012c2ec8fc69314064a90d04c 100644 (file)
@@ -2747,6 +2747,8 @@ SimpleActionListCell
 SimpleEcontextStackEntry
 SimpleOidList
 SimpleOidListCell
+SimpleOidStringList
+SimpleOidListStringCell
 SimplePtrList
 SimplePtrListCell
 SimpleStats