bug-gnulib
[Top][All Lists]
Advanced

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

fix gcc warnings on 64-bit mode mingw


From: Bruno Haible
Subject: fix gcc warnings on 64-bit mode mingw
Date: Sat, 27 Apr 2019 16:26:35 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; )

On 64-bit mingw, I'm seeing a couple of warnings such as:

gl_array_list.c:50:30: warning: cast from pointer to integer of different size 
[-Wpointer-to-int-cast]
gl_array_list.c:50:30: warning: cast from pointer to integer of different size 
[-Wpointer-to-int-cast]
gl_array_list.c:50:30: warning: cast from pointer to integer of different size 
[-Wpointer-to-int-cast]
gl_array_list.c:49:30: warning: cast to pointer from integer of different size 
[-Wint-to-pointer-cast]

The reason is a definition of uintptr_t as 'unsigned long', which is wrong
for this platform (where 'long' is 32 bits wide and pointers are 64 bits wide).
This patch fixes it.


2019-04-27  Bruno Haible  <address@hidden>

        Fix gcc warnings on 64-bit mode mingw.
        * lib/clean-temp.c: Include <stdint.h> instead of defining uintptr_t.
        * lib/gl_array_list.c: Likewise.
        * lib/gl_array_map.c: Likewise.
        * lib/gl_array_set.c: Likewise.
        * lib/gl_carray_list.c: Likewise.
        * lib/gl_sublist.c: Likewise.
        * lib/gl_avltreehash_list.c (uintptr_t): Remove definition.
        * lib/gl_rbtreehash_list.c (uintptr_t): Likewise.
        * lib/gl_hash_map.c (uintptr_t): Likewise.
        * lib/gl_hash_set.c (uintptr_t): Likewise.
        * lib/gl_linkedhash_list.c (uintptr_t): Likewise.
        * lib/gl_linkedhash_map.c (uintptr_t): Likewise.
        * lib/gl_linkedhash_set.c (uintptr_t): Likewise.
        * lib/iconv.c (uintptr_t): Likewise.
        * lib/iconv_close.c (uintptr_t): Likewise.
        * tests/test-lock.c: Include <stdint.h>.
        (once_contender_thread, test_once): Cast through 'intptr_t' instead of
        'long'.
        * modules/clean-temp (Depends-on): Add stdint.
        * modules/array-list (Depends-on): Likewise.
        * modules/array-map (Depends-on): Likewise.
        * modules/array-set (Depends-on): Likewise.
        * modules/carray-list (Depends-on): Likewise.
        * modules/sublist (Depends-on): Likewise.
        * modules/lock-tests (Depends-on): Likewise.

diff --git a/lib/clean-temp.c b/lib/clean-temp.c
index d333f56..c3cc7da 100644
--- a/lib/clean-temp.c
+++ b/lib/clean-temp.c
@@ -26,6 +26,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <stdbool.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -65,10 +66,6 @@
 # define PATH_MAX 1024
 #endif
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 
 /* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
    ensure that while constructing or modifying the data structures, the field
diff --git a/lib/gl_array_list.c b/lib/gl_array_list.c
index 4ac743f..fa8cf1e 100644
--- a/lib/gl_array_list.c
+++ b/lib/gl_array_list.c
@@ -20,6 +20,7 @@
 /* Specification.  */
 #include "gl_array_list.h"
 
+#include <stdint.h>
 #include <stdlib.h>
 /* Get memcpy.  */
 #include <string.h>
@@ -27,10 +28,6 @@
 /* Checked size_t computations.  */
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* -------------------------- gl_list_t Data Type -------------------------- */
 
 /* Concrete gl_list_impl type, valid for this file only.  */
diff --git a/lib/gl_array_map.c b/lib/gl_array_map.c
index 33dc719..9302a00 100644
--- a/lib/gl_array_map.c
+++ b/lib/gl_array_map.c
@@ -20,15 +20,12 @@
 /* Specification.  */
 #include "gl_array_map.h"
 
+#include <stdint.h>
 #include <stdlib.h>
 
 /* Checked size_t computations.  */
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* --------------------------- gl_map_t Data Type --------------------------- 
*/
 
 struct pair
diff --git a/lib/gl_array_set.c b/lib/gl_array_set.c
index cb595fc..d88f495 100644
--- a/lib/gl_array_set.c
+++ b/lib/gl_array_set.c
@@ -20,15 +20,12 @@
 /* Specification.  */
 #include "gl_array_set.h"
 
+#include <stdint.h>
 #include <stdlib.h>
 
 /* Checked size_t computations.  */
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* --------------------------- gl_set_t Data Type --------------------------- 
*/
 
 /* Concrete gl_set_impl type, valid for this file only.  */
diff --git a/lib/gl_avltreehash_list.c b/lib/gl_avltreehash_list.c
index d72f149..21876be 100644
--- a/lib/gl_avltreehash_list.c
+++ b/lib/gl_avltreehash_list.c
@@ -20,16 +20,12 @@
 /* Specification.  */
 #include "gl_avltreehash_list.h"
 
-#include <stdint.h> /* for SIZE_MAX */
+#include <stdint.h> /* for uintptr_t, SIZE_MAX */
 #include <stdlib.h>
 
 #include "gl_avltree_oset.h"
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 #define WITH_HASHTABLE 1
 
 /* Which kind of binary trees to use for ordered sets.  Quite arbitrary.  */
diff --git a/lib/gl_carray_list.c b/lib/gl_carray_list.c
index 24aa466..6a54689 100644
--- a/lib/gl_carray_list.c
+++ b/lib/gl_carray_list.c
@@ -20,6 +20,7 @@
 /* Specification.  */
 #include "gl_carray_list.h"
 
+#include <stdint.h>
 #include <stdlib.h>
 /* Get memcpy.  */
 #include <string.h>
@@ -27,10 +28,6 @@
 /* Checked size_t computations.  */
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* -------------------------- gl_list_t Data Type -------------------------- */
 
 /* Concrete gl_list_impl type, valid for this file only.  */
diff --git a/lib/gl_hash_map.c b/lib/gl_hash_map.c
index 534b472..ef3224d 100644
--- a/lib/gl_hash_map.c
+++ b/lib/gl_hash_map.c
@@ -20,15 +20,11 @@
 /* Specification.  */
 #include "gl_hash_map.h"
 
-#include <stdint.h> /* for SIZE_MAX */
+#include <stdint.h> /* for uintptr_t, SIZE_MAX */
 #include <stdlib.h>
 
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* --------------------------- gl_map_t Data Type --------------------------- 
*/
 
 #include "gl_anyhash1.h"
diff --git a/lib/gl_hash_set.c b/lib/gl_hash_set.c
index 303d137..64356e1 100644
--- a/lib/gl_hash_set.c
+++ b/lib/gl_hash_set.c
@@ -20,15 +20,11 @@
 /* Specification.  */
 #include "gl_hash_set.h"
 
-#include <stdint.h> /* for SIZE_MAX */
+#include <stdint.h> /* for uintptr_t, SIZE_MAX */
 #include <stdlib.h>
 
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* --------------------------- gl_set_t Data Type --------------------------- 
*/
 
 #include "gl_anyhash1.h"
diff --git a/lib/gl_linkedhash_list.c b/lib/gl_linkedhash_list.c
index efe4996..d148d5b 100644
--- a/lib/gl_linkedhash_list.c
+++ b/lib/gl_linkedhash_list.c
@@ -20,15 +20,11 @@
 /* Specification.  */
 #include "gl_linkedhash_list.h"
 
-#include <stdint.h> /* for SIZE_MAX */
+#include <stdint.h> /* for uintptr_t, SIZE_MAX */
 #include <stdlib.h>
 
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 #define WITH_HASHTABLE 1
 
 /* -------------------------- gl_list_t Data Type -------------------------- */
diff --git a/lib/gl_linkedhash_map.c b/lib/gl_linkedhash_map.c
index 9e16971..c2697d0 100644
--- a/lib/gl_linkedhash_map.c
+++ b/lib/gl_linkedhash_map.c
@@ -20,15 +20,11 @@
 /* Specification.  */
 #include "gl_linkedhash_map.h"
 
-#include <stdint.h> /* for SIZE_MAX */
+#include <stdint.h> /* for uintptr_t, SIZE_MAX */
 #include <stdlib.h>
 
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* --------------------------- gl_map_t Data Type --------------------------- 
*/
 
 #include "gl_anyhash1.h"
diff --git a/lib/gl_linkedhash_set.c b/lib/gl_linkedhash_set.c
index fb1ca00..55fffc4 100644
--- a/lib/gl_linkedhash_set.c
+++ b/lib/gl_linkedhash_set.c
@@ -20,15 +20,11 @@
 /* Specification.  */
 #include "gl_linkedhash_set.h"
 
-#include <stdint.h> /* for SIZE_MAX */
+#include <stdint.h> /* for uintptr_t, SIZE_MAX */
 #include <stdlib.h>
 
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* --------------------------- gl_set_t Data Type --------------------------- 
*/
 
 #include "gl_anyhash1.h"
diff --git a/lib/gl_rbtreehash_list.c b/lib/gl_rbtreehash_list.c
index dc86757..bc40345 100644
--- a/lib/gl_rbtreehash_list.c
+++ b/lib/gl_rbtreehash_list.c
@@ -20,16 +20,12 @@
 /* Specification.  */
 #include "gl_rbtreehash_list.h"
 
-#include <stdint.h> /* for SIZE_MAX */
+#include <stdint.h> /* for uintptr_t, SIZE_MAX */
 #include <stdlib.h>
 
 #include "gl_rbtree_oset.h"
 #include "xsize.h"
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 #define WITH_HASHTABLE 1
 
 /* Which kind of binary trees to use for ordered sets.  Quite arbitrary.  */
diff --git a/lib/gl_sublist.c b/lib/gl_sublist.c
index 31ffcdc..9a1f266 100644
--- a/lib/gl_sublist.c
+++ b/lib/gl_sublist.c
@@ -20,12 +20,9 @@
 /* Specification.  */
 #include "gl_sublist.h"
 
+#include <stdint.h>
 #include <stdlib.h>
 
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
-
 /* -------------------------- gl_list_t Data Type -------------------------- */
 
 /* Concrete gl_list_impl type, valid for this file only.  */
diff --git a/lib/iconv.c b/lib/iconv.c
index ebe56f6..9ac43bf 100644
--- a/lib/iconv.c
+++ b/lib/iconv.c
@@ -26,9 +26,6 @@
 # include <stdint.h>
 # include <stdlib.h>
 # include "unistr.h"
-# ifndef uintptr_t
-#  define uintptr_t unsigned long
-# endif
 #endif
 
 #if REPLACE_ICONV_UTF
diff --git a/lib/iconv_close.c b/lib/iconv_close.c
index 9a6da01..cc0e118 100644
--- a/lib/iconv_close.c
+++ b/lib/iconv_close.c
@@ -20,9 +20,6 @@
 #include <iconv.h>
 
 #include <stdint.h>
-#ifndef uintptr_t
-# define uintptr_t unsigned long
-#endif
 
 int
 rpl_iconv_close (iconv_t cd)
diff --git a/modules/array-list b/modules/array-list
index 340bb8f..6064671 100644
--- a/modules/array-list
+++ b/modules/array-list
@@ -7,6 +7,7 @@ lib/gl_array_list.c
 
 Depends-on:
 list
+stdint
 xsize
 
 configure.ac:
diff --git a/modules/array-map b/modules/array-map
index abdef16..46ae89a 100644
--- a/modules/array-map
+++ b/modules/array-map
@@ -7,6 +7,7 @@ lib/gl_array_map.c
 
 Depends-on:
 map
+stdint
 xsize
 
 configure.ac:
diff --git a/modules/array-set b/modules/array-set
index bb03425..a8eb33f 100644
--- a/modules/array-set
+++ b/modules/array-set
@@ -7,6 +7,7 @@ lib/gl_array_set.c
 
 Depends-on:
 set
+stdint
 xsize
 
 configure.ac:
diff --git a/modules/carray-list b/modules/carray-list
index 4a1f66f..da14c83 100644
--- a/modules/carray-list
+++ b/modules/carray-list
@@ -7,6 +7,7 @@ lib/gl_carray_list.c
 
 Depends-on:
 list
+stdint
 xsize
 
 configure.ac:
diff --git a/modules/clean-temp b/modules/clean-temp
index 951e0c5..d5c44ee 100644
--- a/modules/clean-temp
+++ b/modules/clean-temp
@@ -7,6 +7,7 @@ lib/clean-temp.c
 
 Depends-on:
 stdbool
+stdint
 unistd
 error
 fatal-signal
diff --git a/modules/lock-tests b/modules/lock-tests
index 52858f7..802471e 100644
--- a/modules/lock-tests
+++ b/modules/lock-tests
@@ -5,6 +5,7 @@ tests/test-once.c
 
 Depends-on:
 thread
+stdint
 usleep
 yield
 
diff --git a/modules/sublist b/modules/sublist
index 0691443..6c856cb 100644
--- a/modules/sublist
+++ b/modules/sublist
@@ -7,6 +7,7 @@ lib/gl_sublist.c
 
 Depends-on:
 list
+stdint
 
 configure.ac:
 
diff --git a/tests/test-lock.c b/tests/test-lock.c
index 081cbf7..1ad0c72 100644
--- a/tests/test-lock.c
+++ b/tests/test-lock.c
@@ -83,6 +83,7 @@
    an "OK" result even without ENABLE_LOCKING (on Linux/x86).  */
 #define REPEAT_COUNT 50000
 
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -587,7 +588,7 @@ once_execute (void)
 static void *
 once_contender_thread (void *arg)
 {
-  int id = (int) (long) arg;
+  int id = (int) (intptr_t) arg;
   int repeat;
 
   for (repeat = 0; repeat <= REPEAT_COUNT; repeat++)
@@ -647,7 +648,8 @@ test_once (void)
 
   /* Spawn the threads.  */
   for (i = 0; i < THREAD_COUNT; i++)
-    threads[i] = gl_thread_create (once_contender_thread, (void *) (long) i);
+    threads[i] =
+      gl_thread_create (once_contender_thread, (void *) (intptr_t) i);
 
   for (repeat = 0; repeat <= REPEAT_COUNT; repeat++)
     {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]