include: Safely discard the const qualifier using the discard_const macro

James Hawkins truiken at gmail.com
Fri Oct 6 21:06:03 CDT 2006


Hi,

This patch is based on a patch written by Stefan Huehner in 2005.
With the -Wcast-qual warning turned on, these five wine-internal
unicode functions produce over 1400 warnings:

strchrW, strrchrW, strpbrkW, memchrW, memrchrW

This patch gets rid of those warnings.  Any ideas about this guys?

Changelog:
* Safely discard the const qualifier using the discard_const macro
(based on a patch by Stefan Huehner).

 include/wine/unicode.h |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

-- 
James Hawkins
-------------- next part --------------
diff --git a/include/wine/unicode.h b/include/wine/unicode.h
index 7f723b0..d47695f 100644
--- a/include/wine/unicode.h
+++ b/include/wine/unicode.h
@@ -35,6 +35,9 @@ #ifndef WINE_UNICODE_API
 #define WINE_UNICODE_API DECLSPEC_IMPORT
 #endif
 
+#define discard_const(ptr) ((void *)((ULONG_PTR)(ptr)))
+#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
+
 /* code page info common to SBCS and DBCS */
 struct cp_info
 {
@@ -240,7 +243,7 @@ extern inline WCHAR *strcatW( WCHAR *dst
 extern inline WCHAR *strchrW( const WCHAR *str, WCHAR ch );
 extern inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
 {
-    do { if (*str == ch) return (WCHAR *)str; } while (*str++);
+    do { if (*str == ch) return discard_const_p(WCHAR, str); } while (*str++);
     return NULL;
 }
 
@@ -248,14 +251,14 @@ extern inline WCHAR *strrchrW( const WCH
 extern inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
 {
     WCHAR *ret = NULL;
-    do { if (*str == ch) ret = (WCHAR *)str; } while (*str++);
+    do { if (*str == ch) ret = discard_const_p(WCHAR, str); } while (*str++);
     return ret;
 }
 
 extern inline WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept );
 extern inline WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
 {
-    for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)str;
+    for ( ; *str; str++) if (strchrW( accept, *str )) return discard_const_p(WCHAR, str);
     return NULL;
 }
 
@@ -295,7 +298,7 @@ extern inline WCHAR *memchrW( const WCHA
 extern inline WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
 {
     const WCHAR *end;
-    for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return (WCHAR *)ptr;
+    for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return discard_const_p(WCHAR, ptr);
     return NULL;
 }
 
@@ -304,7 +307,7 @@ extern inline WCHAR *memrchrW( const WCH
 {
     const WCHAR *end, *ret = NULL;
     for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = ptr;
-    return (WCHAR *)ret;
+    return discard_const_p(WCHAR, ret);
 }
 
 extern inline long int atolW( const WCHAR *str );
-- 
1.4.2.1


More information about the wine-patches mailing list