libctf: fixes for systems on which sizeof (void *) > sizeof (long)
authorNick Alcock <nick.alcock@oracle.com>
Tue, 21 Jul 2020 14:38:08 +0000 (15:38 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Wed, 22 Jul 2020 17:05:32 +0000 (18:05 +0100)
Systems like mingw64 have pointers that can only be represented by 'long
long'.  Consistently cast integers stored in pointers through uintptr_t
to cater for this.

libctf/
* ctf-create.c (ctf_dtd_insert): Add uintptr_t casts.
(ctf_dtd_delete): Likewise.
(ctf_dtd_lookup): Likewise.
(ctf_rollback): Likewise.
* ctf-hash.c (ctf_hash_lookup_type): Likewise.
* ctf-types.c (ctf_lookup_by_rawhash): Likewise.

libctf/ChangeLog
libctf/ctf-create.c
libctf/ctf-hash.c
libctf/ctf-types.c

index 9183d2b7d6538e5d3f62999c12a93f418fb8e73d..6887c3ff869ab24a96c25c0a0fd28fc0ad6e2928 100644 (file)
@@ -1,3 +1,12 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-create.c (ctf_dtd_insert): Add uintptr_t casts.
+       (ctf_dtd_delete): Likewise.
+       (ctf_dtd_lookup): Likewise.
+       (ctf_rollback): Likewise.
+       * ctf-hash.c (ctf_hash_lookup_type): Likewise.
+       * ctf-types.c (ctf_lookup_by_rawhash): Likewise.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-lookup.c (ctf_lookup_by_name): Adjust.
index 35c286c3b4064be9603975e1bd64d6f6c1ce3ee0..ee8757549feb6f2cd528d682c13e6f07f4c29e1e 100644 (file)
@@ -617,16 +617,19 @@ int
 ctf_dtd_insert (ctf_file_t *fp, ctf_dtdef_t *dtd, int flag, int kind)
 {
   const char *name;
-  if (ctf_dynhash_insert (fp->ctf_dthash, (void *) dtd->dtd_type, dtd) < 0)
+  if (ctf_dynhash_insert (fp->ctf_dthash, (void *) (uintptr_t) dtd->dtd_type,
+                         dtd) < 0)
     return -1;
 
   if (flag == CTF_ADD_ROOT && dtd->dtd_data.ctt_name
       && (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL)
     {
       if (ctf_dynhash_insert (ctf_name_table (fp, kind)->ctn_writable,
-                             (char *) name, (void *) dtd->dtd_type) < 0)
+                             (char *) name, (void *) (uintptr_t)
+                             dtd->dtd_type) < 0)
        {
-         ctf_dynhash_remove (fp->ctf_dthash, (void *) dtd->dtd_type);
+         ctf_dynhash_remove (fp->ctf_dthash, (void *) (uintptr_t)
+                             dtd->dtd_type);
          return -1;
        }
     }
@@ -642,7 +645,7 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd)
   int name_kind = kind;
   const char *name;
 
-  ctf_dynhash_remove (fp->ctf_dthash, (void *) dtd->dtd_type);
+  ctf_dynhash_remove (fp->ctf_dthash, (void *) (uintptr_t) dtd->dtd_type);
 
   switch (kind)
     {
@@ -682,7 +685,8 @@ ctf_dtd_delete (ctf_file_t *fp, ctf_dtdef_t *dtd)
 ctf_dtdef_t *
 ctf_dtd_lookup (const ctf_file_t *fp, ctf_id_t type)
 {
-  return (ctf_dtdef_t *) ctf_dynhash_lookup (fp->ctf_dthash, (void *) type);
+  return (ctf_dtdef_t *)
+    ctf_dynhash_lookup (fp->ctf_dthash, (void *) (uintptr_t) type);
 }
 
 ctf_dtdef_t *
@@ -794,7 +798,7 @@ ctf_rollback (ctf_file_t *fp, ctf_snapshot_id_t id)
          ctf_str_remove_ref (fp, name, &dtd->dtd_data.ctt_name);
        }
 
-      ctf_dynhash_remove (fp->ctf_dthash, (void *) dtd->dtd_type);
+      ctf_dynhash_remove (fp->ctf_dthash, (void *) (uintptr_t) dtd->dtd_type);
       ctf_dtd_delete (fp, dtd);
     }
 
index 297526094cc11bc063c027da549cf0cc59ba3c8b..d6e9f5e3b6e2f2a993bf5a9b38e800264733372b 100644 (file)
@@ -829,7 +829,7 @@ ctf_hash_lookup_type (ctf_hash_t *hp, ctf_file_t *fp __attribute__ ((__unused__)
   slot = ctf_hashtab_lookup ((struct htab *) hp, key, NO_INSERT);
 
   if (slot)
-    return (ctf_id_t) ((*slot)->value);
+    return (ctf_id_t) (uintptr_t) ((*slot)->value);
 
   return 0;
 }
index ddcca66a282446592f1ed6eb696fb19b4e4b80b9..4843de38d92f9a4268d9dd985b514cdb4483c943 100644 (file)
@@ -658,7 +658,7 @@ ctf_id_t ctf_lookup_by_rawhash (ctf_file_t *fp, ctf_names_t *np, const char *nam
   ctf_id_t id;
 
   if (fp->ctf_flags & LCTF_RDWR)
-    id = (ctf_id_t) ctf_dynhash_lookup (np->ctn_writable, name);
+    id = (ctf_id_t) (uintptr_t) ctf_dynhash_lookup (np->ctn_writable, name);
   else
     id = ctf_hash_lookup_type (np->ctn_readonly, fp, name);
   return id;