[gnome-software: 2/25] gs-desktop-data: Expose the number of elements in the array publicly




commit 468480f2632ed3b006a0a1bcc560ab22b030a94b
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Feb 3 17:36:10 2021 +0000

    gs-desktop-data: Expose the number of elements in the array publicly
    
    Since the array data is static, exposing the number of elements allows
    related data structures to be defined statically to the right size.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-desktop-data.c |  3 +++
 lib/gs-desktop-data.h | 12 ++++++++++++
 2 files changed, 15 insertions(+)
---
diff --git a/lib/gs-desktop-data.c b/lib/gs-desktop-data.c
index 7900b39c9..34e48238a 100644
--- a/lib/gs-desktop-data.c
+++ b/lib/gs-desktop-data.c
@@ -326,6 +326,9 @@ static const GsDesktopData msdata[] = {
        { NULL }
 };
 
+/* the -1 is for the NULL terminator */
+G_STATIC_ASSERT (G_N_ELEMENTS (msdata) - 1 == GS_DESKTOP_DATA_N_ENTRIES);
+
 const GsDesktopData *
 gs_desktop_get_data (void)
 {
diff --git a/lib/gs-desktop-data.h b/lib/gs-desktop-data.h
index 3f5d378dc..884f09292 100644
--- a/lib/gs-desktop-data.h
+++ b/lib/gs-desktop-data.h
@@ -28,4 +28,16 @@ typedef struct {
 
 const GsDesktopData    *gs_desktop_get_data            (void);
 
+/**
+ * GS_DESKTOP_DATA_N_ENTRIES:
+ *
+ * Number of entries in the array returned by gs_desktop_get_data(). This is
+ * static and guaranteed to be up to date. It’s intended to be used when
+ * defining static arrays which need to be the same size as the array returned
+ * by gs_desktop_get_data().
+ *
+ * Since: 40
+ */
+#define GS_DESKTOP_DATA_N_ENTRIES 10
+
 G_END_DECLS


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