[epiphany] Update gvdb and fix scan build issue



commit ac9158b8d1fd31e3a9e7766039e25815219019b1
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Fri Jan 8 20:18:40 2021 +0100

    Update gvdb and fix scan build issue
    
    Update to latest gvdb version and fix scan build finding.
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/1038

 third-party/gvdb/README.epiphany | 10 ++--------
 third-party/gvdb/gvdb-builder.c  | 25 +++++++++++++++----------
 third-party/gvdb/gvdb-builder.h  | 14 +++++++++-----
 third-party/gvdb/gvdb-reader.c   |  4 ++--
 third-party/gvdb/gvdb-reader.h   | 34 +++++++++++++++++++++++++---------
 5 files changed, 53 insertions(+), 34 deletions(-)
---
diff --git a/third-party/gvdb/README.epiphany b/third-party/gvdb/README.epiphany
index 638f796f4..a3d3f4b2d 100644
--- a/third-party/gvdb/README.epiphany
+++ b/third-party/gvdb/README.epiphany
@@ -1,10 +1,4 @@
 GVariant Database
 
- * Copied from https://git.gnome.org/browse/gvdb commit a6f0eadb51aae5351a0cfd6b9da3dcba6b134e1a
- * Removed G_GNUC_INTERNAL and GVDB_GNUC_WEAK
- * Fix -Wsign-compare
- * Add clang ifdef guards (#ifndef __clang_analyzer__) around:
-   - file_builder_allocate_for_hash
-   - file_builder_add_hash
- * Removed G_FILE_CREATE_REPLACE_DESTINATION in gvdb_table_write_contents_async
- * Fix valgrind warnings (gvdb#2)
+ * Copied from https://gitlab.gnome.org/GNOME/gvdb commit 3d50fe28e8e8f8b215a36581c6b4c9b199b60eb6
+ * scan-build fix https://gitlab.gnome.org/GNOME/gvdb/-/merge_requests/14
diff --git a/third-party/gvdb/gvdb-builder.c b/third-party/gvdb/gvdb-builder.c
index 5f59e7cb3..dcde43f10 100644
--- a/third-party/gvdb/gvdb-builder.c
+++ b/third-party/gvdb/gvdb-builder.c
@@ -206,7 +206,7 @@ item_to_index (GvdbItem *item)
   if (item != NULL)
     return item->assigned_index;
 
-  return guint32_to_le (-1u);
+  return guint32_to_le ((guint32) -1);
 }
 
 typedef struct
@@ -234,7 +234,7 @@ file_builder_allocate (FileBuilder         *fb,
   if (size == 0)
     return NULL;
 
-  fb->offset += (-fb->offset) & (alignment - 1);
+  fb->offset += (guint64) (-fb->offset) & (alignment - 1);
   chunk = g_slice_new (FileChunk);
   chunk->offset = fb->offset;
   chunk->size = size;
@@ -312,7 +312,6 @@ file_builder_allocate_for_hash (FileBuilder            *fb,
                                 struct gvdb_hash_item **hash_items,
                                 struct gvdb_pointer    *pointer)
 {
-#ifndef __clang_analyzer__
   guint32_le bloom_hdr, table_hdr;
   guchar *data;
   gsize size;
@@ -328,6 +327,7 @@ file_builder_allocate_for_hash (FileBuilder            *fb,
          n_items       * sizeof (struct gvdb_hash_item);
 
   data = file_builder_allocate (fb, 4, size, pointer);
+  g_assert (data);
 
 #define chunk(s) (size -= (s), data += (s), data - (s))
   memcpy (chunk (sizeof bloom_hdr), &bloom_hdr, sizeof bloom_hdr);
@@ -349,7 +349,6 @@ file_builder_allocate_for_hash (FileBuilder            *fb,
    * http://en.wikipedia.org/wiki/Bloom_filter
    * http://0pointer.de/blog/projects/bloom.html
    */
-#endif
 }
 
 static void
@@ -357,7 +356,6 @@ file_builder_add_hash (FileBuilder         *fb,
                        GHashTable          *table,
                        struct gvdb_pointer *pointer)
 {
-#ifndef __clang_analyzer__
   guint32_le *buckets, *bloom_filter;
   struct gvdb_hash_item *items;
   HashTable *mytable;
@@ -440,7 +438,6 @@ file_builder_add_hash (FileBuilder         *fb,
     }
 
   hash_table_free (mytable);
-#endif
 }
 
 static FileBuilder *
@@ -456,13 +453,22 @@ file_builder_new (gboolean byteswap)
   return builder;
 }
 
+static void
+file_builder_free (FileBuilder *fb)
+{
+  g_queue_free (fb->chunks);
+  g_slice_free (FileBuilder, fb);
+}
+
 static GString *
 file_builder_serialise (FileBuilder          *fb,
                         struct gvdb_pointer   root)
 {
-  struct gvdb_header header = { { 0, }, };
+  struct gvdb_header header;
   GString *result;
 
+  memset (&header, 0, sizeof (header));
+
   if (fb->byteswap)
     {
       header.signature[0] = GVDB_SWAPPED_SIGNATURE0;
@@ -500,9 +506,6 @@ file_builder_serialise (FileBuilder          *fb,
       g_slice_free (FileChunk, chunk);
     }
 
-  g_queue_free (fb->chunks);
-  g_slice_free (FileBuilder, fb);
-
   return result;
 }
 
@@ -524,6 +527,7 @@ gvdb_table_write_contents (GHashTable   *table,
   fb = file_builder_new (byteswap);
   file_builder_add_hash (fb, table, &root);
   str = file_builder_serialise (fb, root);
+  file_builder_free (fb);
 
   status = g_file_set_contents (filename, str->str, str->len, error);
   g_string_free (str, TRUE);
@@ -600,6 +604,7 @@ gvdb_table_write_contents_async (GHashTable          *table,
   file_builder_add_hash (fb, table, &root);
   str = file_builder_serialise (fb, root);
   bytes = g_string_free_to_bytes (str);
+  file_builder_free (fb);
 
   file = g_file_new_for_path (filename);
   data = write_contents_data_new (bytes, file);
diff --git a/third-party/gvdb/gvdb-builder.h b/third-party/gvdb/gvdb-builder.h
index 41ba957dd..30757d039 100644
--- a/third-party/gvdb/gvdb-builder.h
+++ b/third-party/gvdb/gvdb-builder.h
@@ -24,37 +24,41 @@
 
 typedef struct _GvdbItem GvdbItem;
 
+G_GNUC_INTERNAL
 GHashTable *            gvdb_hash_table_new                             (GHashTable    *parent,
                                                                          const gchar   *key);
 
+G_GNUC_INTERNAL
 GvdbItem *              gvdb_hash_table_insert                          (GHashTable    *table,
                                                                          const gchar   *key);
-
+G_GNUC_INTERNAL
 void                    gvdb_hash_table_insert_string                   (GHashTable    *table,
                                                                          const gchar   *key,
                                                                          const gchar   *value);
 
+G_GNUC_INTERNAL
 void                    gvdb_item_set_value                             (GvdbItem      *item,
                                                                          GVariant      *value);
-
+G_GNUC_INTERNAL
 void                    gvdb_item_set_hash_table                        (GvdbItem      *item,
                                                                          GHashTable    *table);
-
+G_GNUC_INTERNAL
 void                    gvdb_item_set_parent                            (GvdbItem      *item,
                                                                          GvdbItem      *parent);
 
+G_GNUC_INTERNAL
 gboolean                gvdb_table_write_contents                       (GHashTable     *table,
                                                                          const gchar    *filename,
                                                                          gboolean        byteswap,
                                                                          GError        **error);
-
+G_GNUC_INTERNAL
 void                    gvdb_table_write_contents_async                 (GHashTable          *table,
                                                                          const gchar         *filename,
                                                                          gboolean             byteswap,
                                                                          GCancellable        *cancellable,
                                                                          GAsyncReadyCallback  callback,
                                                                          gpointer             user_data);
-
+G_GNUC_INTERNAL
 gboolean                gvdb_table_write_contents_finish                (GHashTable          *table,
                                                                          GAsyncResult        *result,
                                                                          GError             **error);
diff --git a/third-party/gvdb/gvdb-reader.c b/third-party/gvdb/gvdb-reader.c
index 2dbb5b414..820ce4c3d 100644
--- a/third-party/gvdb/gvdb-reader.c
+++ b/third-party/gvdb/gvdb-reader.c
@@ -332,7 +332,7 @@ gvdb_table_list_from_item (GvdbTable                    *table,
 /**
  * gvdb_table_get_names:
  * @table: a #GvdbTable
- * @length: (optional): the number of items returned, or %NULL
+ * @length: (out) (optional): the number of items returned, or %NULL
  *
  * Gets a list of all names contained in @table.
  *
@@ -379,7 +379,7 @@ gvdb_table_get_names (GvdbTable *table,
    * a pass that fills in no additional items.
    *
    * This takes an O(n) algorithm and turns it into O(n*m) where m is
-   * the depth of the tree, but in all sane cases the tree won't be very
+   * the depth of the tree, but typically the tree won't be very
    * deep and the constant factor of this algorithm is lower (and the
    * complexity of coding it, as well).
    */
diff --git a/third-party/gvdb/gvdb-reader.h b/third-party/gvdb/gvdb-reader.h
index c3fc64613..79a97d358 100644
--- a/third-party/gvdb/gvdb-reader.h
+++ b/third-party/gvdb/gvdb-reader.h
@@ -22,39 +22,55 @@
 
 #include <glib.h>
 
+/* We cannot enable the weak attribute unconditionally here because both
+ * gvdb/gvdb-reader.c and tests/dconf-mock-gvdb.c include this file. The
+ * intention of using weak symbols here is to allow the latter to override
+ * functions defined in the former, so functions in tests/dconf-mock-gvdb.c
+ * must have strong bindings. */
+#ifdef GVDB_USE_WEAK_SYMBOLS
+# ifdef __GNUC__
+#  define GVDB_GNUC_WEAK __attribute__((weak))
+# else
+#  define GVDB_GNUC_WEAK
+# endif
+#else
+# define GVDB_GNUC_WEAK
+#endif
+
 typedef struct _GvdbTable GvdbTable;
 
 G_BEGIN_DECLS
 
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 GvdbTable *             gvdb_table_new_from_bytes                       (GBytes       *bytes,
                                                                          gboolean      trusted,
                                                                          GError      **error);
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 GvdbTable *             gvdb_table_new                                  (const gchar  *filename,
                                                                          gboolean      trusted,
                                                                          GError      **error);
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 void                    gvdb_table_free                                 (GvdbTable    *table);
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 gchar **                gvdb_table_get_names                            (GvdbTable    *table,
                                                                          gsize        *length);
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 gchar **                gvdb_table_list                                 (GvdbTable    *table,
                                                                          const gchar  *key);
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 GvdbTable *             gvdb_table_get_table                            (GvdbTable    *table,
                                                                          const gchar  *key);
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 GVariant *              gvdb_table_get_raw_value                        (GvdbTable    *table,
                                                                          const gchar  *key);
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 GVariant *              gvdb_table_get_value                            (GvdbTable    *table,
                                                                          const gchar  *key);
 
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 gboolean                gvdb_table_has_value                            (GvdbTable    *table,
                                                                          const gchar  *key);
-
+G_GNUC_INTERNAL GVDB_GNUC_WEAK
 gboolean                gvdb_table_is_valid                             (GvdbTable    *table);
 
 G_END_DECLS


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