[libdmapsharing] Revert to using guint, rather than gpointer, for id where possible



commit b2fba67b932fe69f2daafb9291f4b6defd8ba116
Author: W. Michael Petullo <mike flyn org>
Date:   Fri May 17 23:02:33 2019 -0400

    Revert to using guint, rather than gpointer, for id where possible
    
    Signed-off-by: W. Michael Petullo <mike flyn org>

 libdmapsharing/dmap-av-share.c          | 10 +++++-----
 libdmapsharing/dmap-container-db.h      |  4 +++-
 libdmapsharing/dmap-db.c                |  9 ++++-----
 libdmapsharing/dmap-db.h                |  2 +-
 libdmapsharing/dmap-image-share.c       |  6 +++---
 libdmapsharing/dmap-share-private.h     |  6 +++---
 libdmapsharing/dmap-share.c             | 22 ++++++++++++++++------
 libdmapsharing/dmap-share.h             |  2 +-
 libdmapsharing/test-dmap-container-db.c |  2 +-
 libdmapsharing/test-dmap-db.c           | 22 ++++++++++++++++++----
 tests/dmapcopy.c                        | 31 +++++++++++++------------------
 tests/dmapcopy.vala                     |  4 +---
 tests/dpapview.vala                     |  4 +---
 13 files changed, 70 insertions(+), 54 deletions(-)
---
diff --git a/libdmapsharing/dmap-av-share.c b/libdmapsharing/dmap-av-share.c
index e955a19..0dedb6e 100644
--- a/libdmapsharing/dmap-av-share.c
+++ b/libdmapsharing/dmap-av-share.c
@@ -60,7 +60,7 @@ static void _databases_items_xxx (DmapShare * share,
                                   SoupMessage * msg,
                                   const char *path);
 static struct DmapMetaDataMap *_get_meta_data_map (DmapShare * share);
-static void _add_entry_to_mlcl (gpointer id, DmapRecord * record, gpointer mb);
+static void _add_entry_to_mlcl (guint id, DmapRecord * record, gpointer mb);
 
 #define DAAP_TYPE_OF_SERVICE "_daap._tcp"
 #define DAAP_PORT 3689
@@ -501,7 +501,7 @@ done:
 }
 
 static void
-_add_entry_to_mlcl (gpointer id, DmapRecord * record, gpointer _mb)
+_add_entry_to_mlcl (guint id, DmapRecord * record, gpointer _mb)
 {
        GNode *mlit;
        gboolean has_video = 0;
@@ -516,7 +516,7 @@ _add_entry_to_mlcl (gpointer id, DmapRecord * record, gpointer _mb)
        }
 
        if (dmap_share_client_requested (mb->bits, ITEM_ID)) {
-               dmap_structure_add (mlit, DMAP_CC_MIID, GPOINTER_TO_UINT(id));
+               dmap_structure_add (mlit, DMAP_CC_MIID, id);
        }
 
        if (dmap_share_client_requested (mb->bits, ITEM_NAME)) {
@@ -532,11 +532,11 @@ _add_entry_to_mlcl (gpointer id, DmapRecord * record, gpointer _mb)
        }
 
        if (dmap_share_client_requested (mb->bits, PERSISTENT_ID)) {
-               dmap_structure_add (mlit, DMAP_CC_MPER, GPOINTER_TO_UINT(id));
+               dmap_structure_add (mlit, DMAP_CC_MPER, id);
        }
 
        if (dmap_share_client_requested (mb->bits, CONTAINER_ITEM_ID)) {
-               dmap_structure_add (mlit, DMAP_CC_MCTI, GPOINTER_TO_UINT(id));
+               dmap_structure_add (mlit, DMAP_CC_MCTI, id);
        }
 
        if (dmap_share_client_requested (mb->bits, SONG_DATA_KIND)) {
diff --git a/libdmapsharing/dmap-container-db.h b/libdmapsharing/dmap-container-db.h
index a89ec58..e76bb05 100644
--- a/libdmapsharing/dmap-container-db.h
+++ b/libdmapsharing/dmap-container-db.h
@@ -72,7 +72,9 @@ typedef struct _DmapContainerDbInterface DmapContainerDbInterface;
  *
  * The type of function passed to dmap_container_db_foreach().
  */
-typedef void (*DmapIdContainerRecordFunc) (gpointer id, DmapContainerRecord *record, gpointer user_data);
+typedef void (*DmapIdContainerRecordFunc) (guint id,
+                                           DmapContainerRecord *record,
+                                           gpointer user_data);
 
 struct _DmapContainerDbInterface
 {
diff --git a/libdmapsharing/dmap-db.c b/libdmapsharing/dmap-db.c
index 621f705..62a88e1 100644
--- a/libdmapsharing/dmap-db.c
+++ b/libdmapsharing/dmap-db.c
@@ -170,7 +170,7 @@ done:
 }
 
 static void
-_apply_filter (gpointer id, DmapRecord * record, gpointer data)
+_apply_filter (guint id, DmapRecord * record, gpointer data)
 {
        g_assert(IS_DMAP_RECORD (record));
 
@@ -182,7 +182,7 @@ _apply_filter (gpointer id, DmapRecord * record, gpointer data)
 
        fd = data;
        if (fd->filter_def == NULL) {
-               g_hash_table_insert (fd->ht, id, g_object_ref (record));
+               g_hash_table_insert (fd->ht, GUINT_TO_POINTER(id), g_object_ref (record));
                goto done;
        }
 
@@ -198,8 +198,7 @@ _apply_filter (gpointer id, DmapRecord * record, gpointer data)
                        query_value = def->value;
 
                        if (g_strcmp0 (query_key, "dmap.itemid") == 0) {
-                               if (GPOINTER_TO_UINT (id) ==
-                                   strtoul (query_value, NULL, 10)) {
+                               if (id == strtoul (query_value, NULL, 10)) {
                                        accept = TRUE;
                                        break;
                                }
@@ -236,7 +235,7 @@ _apply_filter (gpointer id, DmapRecord * record, gpointer data)
                }
        }
        if (accept) {
-               g_hash_table_insert (fd->ht, id,
+               g_hash_table_insert (fd->ht, GUINT_TO_POINTER(id),
                                     g_object_ref (record));
        }
 
diff --git a/libdmapsharing/dmap-db.h b/libdmapsharing/dmap-db.h
index ac6b292..25b64df 100644
--- a/libdmapsharing/dmap-db.h
+++ b/libdmapsharing/dmap-db.h
@@ -83,7 +83,7 @@ typedef struct _DmapDbInterface DmapDbInterface;
  *
  * The type of function passed to dmap_db_foreach().
  */
-typedef void (*DmapIdRecordFunc) (gpointer id, DmapRecord *record, gpointer user_data);
+typedef void (*DmapIdRecordFunc) (guint id, DmapRecord *record, gpointer user_data);
 
 struct _DmapDbInterface
 {
diff --git a/libdmapsharing/dmap-image-share.c b/libdmapsharing/dmap-image-share.c
index 55062c1..a98bc9e 100644
--- a/libdmapsharing/dmap-image-share.c
+++ b/libdmapsharing/dmap-image-share.c
@@ -157,7 +157,7 @@ done:
 }
 
 static void
-_add_entry_to_mlcl (gpointer id, DmapRecord * record, gpointer _mb)
+_add_entry_to_mlcl (guint id, DmapRecord * record, gpointer _mb)
 {
        GNode *mlit;
        struct DmapMlclBits *mb = (struct DmapMlclBits *) _mb;
@@ -170,7 +170,7 @@ _add_entry_to_mlcl (gpointer id, DmapRecord * record, gpointer _mb)
        }
 
        if (dmap_share_client_requested (mb->bits, ITEM_ID)) {
-               dmap_structure_add (mlit, DMAP_CC_MIID, GPOINTER_TO_UINT(id));
+               dmap_structure_add (mlit, DMAP_CC_MIID, id);
        }
 
        if (dmap_share_client_requested (mb->bits, ITEM_NAME)) {
@@ -186,7 +186,7 @@ _add_entry_to_mlcl (gpointer id, DmapRecord * record, gpointer _mb)
        }
 
        if (dmap_share_client_requested (mb->bits, PERSISTENT_ID)) {
-               dmap_structure_add (mlit, DMAP_CC_MPER, GPOINTER_TO_UINT(id));
+               dmap_structure_add (mlit, DMAP_CC_MPER, id);
        }
 
        if (TRUE) {
diff --git a/libdmapsharing/dmap-share-private.h b/libdmapsharing/dmap-share-private.h
index 1ab955a..38f4a8a 100644
--- a/libdmapsharing/dmap-share-private.h
+++ b/libdmapsharing/dmap-share-private.h
@@ -70,9 +70,9 @@ DmapBits dmap_share_parse_meta (GHashTable * query,
 DmapBits dmap_share_parse_meta_str (const char *attrs,
                                    struct DmapMetaDataMap *mdm);
 
-void dmap_share_add_playlist_to_mlcl (gpointer id,
-                                      DmapContainerRecord * record,
-                                      gpointer mb);
+void dmap_share_add_playlist_to_mlcl (guint id,
+                                      DmapContainerRecord * record,
+                                      gpointer mb);
 
 GSList *dmap_share_build_filter (gchar * filterstr);
 
diff --git a/libdmapsharing/dmap-share.c b/libdmapsharing/dmap-share.c
index 8c4fe27..310fe7c 100644
--- a/libdmapsharing/dmap-share.c
+++ b/libdmapsharing/dmap-share.c
@@ -1182,7 +1182,7 @@ done:
 }
 
 void
-dmap_share_add_playlist_to_mlcl (G_GNUC_UNUSED gpointer id,
+dmap_share_add_playlist_to_mlcl (G_GNUC_UNUSED guint id,
                                  DmapContainerRecord * record,
                                  gpointer _mb)
 {
@@ -1535,11 +1535,11 @@ dmap_share_ctrl_int (G_GNUC_UNUSED DmapShare * share,
 }
 
 static void
-_accumulate_mlcl_size_and_ids (gpointer id,
+_accumulate_mlcl_size_and_ids (guint id,
                                DmapRecord * record,
                                struct share_bitwise_t *share_bitwise)
 {
-       share_bitwise->id_list = g_slist_append (share_bitwise->id_list, id);
+       share_bitwise->id_list = g_slist_append (share_bitwise->id_list, GUINT_TO_POINTER(id));
 
        /* Make copy and set mlcl to NULL so real MLCL does not get changed */
        struct DmapMlclBits mb_copy = share_bitwise->mb;
@@ -1560,6 +1560,16 @@ _accumulate_mlcl_size_and_ids (gpointer id,
        dmap_structure_destroy (mb_copy.mlcl);
 }
 
+static void
+_accumulate_mlcl_size_and_ids_adapter (gpointer id,
+                                       DmapRecord * record,
+                                       struct share_bitwise_t *share_bitwise)
+{
+       _accumulate_mlcl_size_and_ids(GPOINTER_TO_UINT(id),
+                                     record,
+                                     share_bitwise);
+}
+
 static void
 _write_dmap_preamble (SoupMessage * message, GNode * node)
 {
@@ -1593,7 +1603,7 @@ _write_next_mlit (SoupMessage * message, struct share_bitwise_t *share_bitwise)
                mb.share = share_bitwise->mb.share;
 
                DMAP_SHARE_GET_CLASS (share_bitwise->mb.share)->
-                       add_entry_to_mlcl (share_bitwise->id_list->data, record, &mb);
+                       add_entry_to_mlcl (GPOINTER_TO_UINT(share_bitwise->id_list->data), record, &mb);
                data = dmap_structure_serialize (g_node_first_child (mb.mlcl),
                                                 &length);
 
@@ -1852,7 +1862,7 @@ dmap_share_databases (DmapShare * share,
                                _lookup_adapter;
                        share_bitwise->destroy = (ShareBitwiseDestroyFunc) g_hash_table_destroy;
                        g_hash_table_foreach (records,
-                                            (GHFunc) _accumulate_mlcl_size_and_ids,
+                                            (GHFunc) _accumulate_mlcl_size_and_ids_adapter,
                                              share_bitwise);
                } else {
                        share_bitwise->db = share->priv->db;
@@ -2040,7 +2050,7 @@ dmap_share_databases (DmapShare * share,
                        for (id = keys; id; id = id->next) {
                                (*
                                 (DMAP_SHARE_GET_CLASS (share)->
-                                 add_entry_to_mlcl)) (id->data,
+                                 add_entry_to_mlcl)) (GPOINTER_TO_UINT(id->data),
                                                       g_hash_table_lookup
                                                       (records, id->data),
                                                       &mb);
diff --git a/libdmapsharing/dmap-share.h b/libdmapsharing/dmap-share.h
index 0c534fc..7b9bc7c 100644
--- a/libdmapsharing/dmap-share.h
+++ b/libdmapsharing/dmap-share.h
@@ -111,7 +111,7 @@ typedef struct {
        void (*message_add_standard_headers) (DmapShare * share,
                                              SoupMessage * msg);
        struct DmapMetaDataMap *(*get_meta_data_map) (DmapShare * share);
-       void (*add_entry_to_mlcl) (gpointer id, DmapRecord * record, gpointer mb);
+       void (*add_entry_to_mlcl) (guint id, DmapRecord * record, gpointer mb);
        void (*databases_browse_xxx) (DmapShare * share,
                                      SoupMessage * msg,
                                      const char *path,
diff --git a/libdmapsharing/test-dmap-container-db.c b/libdmapsharing/test-dmap-container-db.c
index d88f542..3ecd658 100644
--- a/libdmapsharing/test-dmap-container-db.c
+++ b/libdmapsharing/test-dmap-container-db.c
@@ -40,7 +40,7 @@ test_dmap_container_db_foreach (G_GNUC_UNUSED DmapContainerDb *db,
                                gpointer data)
 {
        /* In reality, pull each record from the db and execute func on it. */
-        func (GUINT_TO_POINTER(1), _record, data);
+        func (1, _record, data);
 }
 
 static gint64
diff --git a/libdmapsharing/test-dmap-db.c b/libdmapsharing/test-dmap-db.c
index b396676..bb89787 100644
--- a/libdmapsharing/test-dmap-db.c
+++ b/libdmapsharing/test-dmap-db.c
@@ -35,12 +35,26 @@ test_dmap_db_lookup_by_id (const DmapDb *db, guint id)
        return g_object_ref(record);
 }
 
+struct package {
+       DmapIdRecordFunc func;
+       gpointer data;
+};
+
+static void
+_adapter(gpointer id, DmapRecord *record, gpointer user_data)
+{
+       struct package *p = user_data;
+       return p->func(GPOINTER_TO_UINT(id), record, p->data);
+}
+
 static void
-test_dmap_db_foreach        (const DmapDb *db,
-                             DmapIdRecordFunc func,
-                             gpointer data)
+test_dmap_db_foreach(const DmapDb *db,
+                     DmapIdRecordFunc func,
+                     gpointer data)
 {
-       g_hash_table_foreach (TEST_DMAP_DB (db)->priv->db, (GHFunc) func, data);
+       g_hash_table_foreach (TEST_DMAP_DB (db)->priv->db,
+                             (GHFunc) _adapter,
+                             &(struct package) { func, data });
 }
 
 static gint64
diff --git a/tests/dmapcopy.c b/tests/dmapcopy.c
index 8faca36..972e467 100644
--- a/tests/dmapcopy.c
+++ b/tests/dmapcopy.c
@@ -117,10 +117,10 @@ gpointer value_get_dpap_copy (const GValue* value);
 GType dpap_copy_get_type (void) G_GNUC_CONST;
 GType vala_dmap_db_get_type (void) G_GNUC_CONST;
 GType vala_image_record_factory_get_type (void) G_GNUC_CONST;
-static gboolean dpap_copy_connected_cb (DPAPCopy* self,
-                                 DmapConnection* connection,
-                                 gboolean _result_,
-                                 const gchar* reason);
+static void dpap_copy_connected_cb (DPAPCopy* self,
+                             DmapConnection* connection,
+                             gboolean _result_,
+                             const gchar* reason);
 static void __lambda4_ (DPAPCopy* self,
                  guint k,
                  DmapRecord* v);
@@ -139,10 +139,10 @@ ValaImageRecordFactory* vala_image_record_factory_construct (GType object_type);
 static void __lambda5_ (DPAPCopy* self,
                  DmapMdnsBrowser* browser,
                  DmapMdnsService* service);
-static gboolean _dpap_copy_connected_cb_dmap_connection_func (DmapConnection* connection,
-                                                       gboolean _result_,
-                                                       const gchar* reason,
-                                                       gpointer self);
+static void _dpap_copy_connected_cb_dmap_connection_func (DmapConnection* connection,
+                                                   gboolean _result_,
+                                                   const gchar* reason,
+                                                   gpointer self);
 static void ___lambda5__dmap_mdns_browser_service_added (DmapMdnsBrowser* _sender,
                                                   DmapMdnsService* service,
                                                   gpointer self);
@@ -189,34 +189,29 @@ ___lambda4__dmap_id_record_func (guint id,
        __lambda4_ ((DPAPCopy*) self, id, record);
 }
 
-static gboolean
+static void
 dpap_copy_connected_cb (DPAPCopy* self,
                         DmapConnection* connection,
                         gboolean _result_,
                         const gchar* reason)
 {
-       gboolean result = FALSE;
        ValaDmapDb* _tmp0_;
        ValaDmapDb* _tmp1_;
-       g_return_val_if_fail (self != NULL, FALSE);
-       g_return_val_if_fail (connection != NULL, FALSE);
+       g_return_if_fail (self != NULL);
+       g_return_if_fail (connection != NULL);
        _tmp0_ = self->priv->db;
        g_debug ("%" G_GINT64_FORMAT " entries\n", dmap_db_count ((DmapDb*) _tmp0_));
        _tmp1_ = self->priv->db;
        dmap_db_foreach ((DmapDb*) _tmp1_, ___lambda4__dmap_id_record_func, self);
-       result = TRUE;
-       return result;
 }
 
-static gboolean
+static void
 _dpap_copy_connected_cb_dmap_connection_func (DmapConnection* connection,
                                               gboolean _result_,
                                               const gchar* reason,
                                               gpointer self)
 {
-       gboolean result;
-       result = dpap_copy_connected_cb ((DPAPCopy*) self, connection, _result_, reason);
-       return result;
+       dpap_copy_connected_cb ((DPAPCopy*) self, connection, _result_, reason);
 }
 
 static void
diff --git a/tests/dmapcopy.vala b/tests/dmapcopy.vala
index 60a48ea..c80c5a2 100644
--- a/tests/dmapcopy.vala
+++ b/tests/dmapcopy.vala
@@ -26,7 +26,7 @@ private class DPAPCopy {
        private ValaDmapDb db;
        private ValaImageRecordFactory factory;
 
-       private bool connected_cb (Dmap.Connection connection, bool result, string? reason) {
+       private void connected_cb (Dmap.Connection connection, bool result, string? reason) {
                GLib.debug ("%" + int64.FORMAT + " entries\n", db.count ());
 
                db.foreach ((k, v) => {
@@ -53,8 +53,6 @@ private class DPAPCopy {
                        data_stream.write (message.response_body.data, (size_t) message.response_body.length, 
null);
                        */
                });
-
-               return true;
        }
 
        public DPAPCopy () throws GLib.Error {
diff --git a/tests/dpapview.vala b/tests/dpapview.vala
index fc8d692..d319e8d 100644
--- a/tests/dpapview.vala
+++ b/tests/dpapview.vala
@@ -27,7 +27,7 @@ private class DpapViewer {
        private ValaDmapDb db;
        private ValaImageRecordFactory factory;
 
-       private bool connected_cb (Dmap.Connection connection, bool result, string? reason) {
+       private void connected_cb (Dmap.Connection connection, bool result, string? reason) {
                GLib.debug ("%" + int64.FORMAT + " entries\n", db.count ());
 
                db.foreach ((k, v) => {
@@ -45,8 +45,6 @@ private class DpapViewer {
                        liststore.append (out iter);
                        liststore.set (iter, 0, pixbuf, 1, ((ValaImageRecord) v).filename);
                });
-
-               return true;
        }
 
        public DpapViewer (Gtk.Builder builder) throws GLib.Error {


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