r2900: rusty pointed out to me that discard_const() can be done via a macro
authorAndrew Tridgell <tridge@samba.org>
Mon, 11 Oct 2004 01:03:27 +0000 (01:03 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:59:46 +0000 (12:59 -0500)
on systems that have the intptr_t type, and for systems that don't
have it, they also almost certainly won't have -Wcast-qual, so we can use a
void* cast.
(This used to be commit 2132d38f9c5ba59825558d5ba084a514ebc2626b)

source4/build/m4/rewrite.m4
source4/include/includes.h
source4/lib/util.c

index ef75ba37a2e164b7e6852443b985274022a0da9b..8d55a5b40a8c4f9f90c78da3c24bd6132bb80b7a 100644 (file)
@@ -275,6 +275,7 @@ AC_CHECK_TYPE(ino_t,unsigned)
 AC_CHECK_TYPE(loff_t,off_t)
 AC_CHECK_TYPE(offset_t,loff_t)
 AC_CHECK_TYPE(ssize_t, int)
+AC_CHECK_TYPE(intptr_t, void*)
 
 
 ############################################
index 06e9b91347df99b2b0628fc7c5e4a04b80926405..94d15eff3fe4cb00da43e464f637a5e8d9b3842a 100644 (file)
@@ -1068,9 +1068,29 @@ time_t timegm(struct tm *tm);
 #include <sys/xattr.h>
 #endif
 
-#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
-
 #define TALLOC_ABORT(reason) smb_panic(reason)
 
+
+/*
+  this is a warning hack. The idea is to use this everywhere that we
+  get the "discarding const" warning from gcc. That doesn't actually
+  fix the problem of course, but it means that when we do get to
+  cleaning them up we can do it by searching the code for
+  discard_const.
+
+  It also means that other error types aren't as swamped by the noise
+  of hundreds of const warnings, so we are more likely to notice when
+  we get new errors.
+
+  Please only add more uses of this macro when you find it
+  _really_ hard to fix const warnings. Our aim is to eventually use
+  this function in only a very few places.
+
+  Also, please call this via the discard_const_p() macro interface, as that
+  makes the return type safe.
+*/
+#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
+#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
+
 #endif /* _INCLUDES_H */
 
index 94b01f7501e81f7a43db0dcf6f0c3b5d835afc77..fde53901279664ed43543ace2cecdd140e37e83e 100644 (file)
@@ -892,25 +892,3 @@ BOOL all_zero(const char *ptr, uint_t size)
 }
 
 
-/*
-  this is a warning hack. The idea is to use this everywhere that we
-  get the "discarding const" warning from gcc, effectively moving all
-  the warnings to this one place. That doesn't actually fix the
-  problem of course, but it means that when we do get to cleaning them
-  up we can do it by searching the code for discard_const.
-
-  It also means that other error types aren't as swamped by the noise
-  of hundreds of const warnings, so we are more likely to notice when
-  we get new errors.
-
-  Please only add more calls to this function when you find it
-  _really_ hard to fix const warnings. Our aim is to eventually use
-  this function in only a very few places.
-
-  Also, please call this via the discard_const_p() macro interface, as that
-  makes the return type safe.
-*/
-void *discard_const(const void *ptr)
-{
-       return (void *)ptr;
-}