svn commit: samba r2632 - in branches/SAMBA_4_0/source: include lib

tridge at samba.org tridge at samba.org
Sat Sep 25 12:36:36 GMT 2004


Author: tridge
Date: 2004-09-25 12:36:36 +0000 (Sat, 25 Sep 2004)
New Revision: 2632

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=2632&nolog=1

Log:
a new approach to handling const errors. We have had huge numbers of
const warnings for a long time, and no real way to approach a
solution. Some of them are unavoidable due to the way the C standard
works (for example, any function that provides strchr() like
functionality _must_ produce a const warning)

I will be converting a bunch of places that currently produce const
warnings to use the discard_const_p(). Some of these will be
unavoidable const problems, some of them will be ones we will fix up
over time. At least this change means we will no longer be swamped
with const warnings, and we will easily be able to see when new
problems emerge.


Modified:
   branches/SAMBA_4_0/source/include/includes.h
   branches/SAMBA_4_0/source/lib/util.c
   branches/SAMBA_4_0/source/lib/util_str.c


Changeset:
Modified: branches/SAMBA_4_0/source/include/includes.h
===================================================================
--- branches/SAMBA_4_0/source/include/includes.h	2004-09-25 12:31:49 UTC (rev 2631)
+++ branches/SAMBA_4_0/source/include/includes.h	2004-09-25 12:36:36 UTC (rev 2632)
@@ -1068,5 +1068,7 @@
 #include <sys/xattr.h>
 #endif
 
+#define discard_const_p(type, ptr) (type *)discard_const(ptr)
+
 #endif /* _INCLUDES_H */
 

Modified: branches/SAMBA_4_0/source/lib/util.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util.c	2004-09-25 12:31:49 UTC (rev 2631)
+++ branches/SAMBA_4_0/source/lib/util.c	2004-09-25 12:36:36 UTC (rev 2632)
@@ -931,3 +931,23 @@
 	return True;
 }
 
+
+/*
+  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 not
+  need this function at all,
+*/
+void *discard_const(const void *ptr)
+{
+	return (void *)ptr;
+}

Modified: branches/SAMBA_4_0/source/lib/util_str.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util_str.c	2004-09-25 12:31:49 UTC (rev 2631)
+++ branches/SAMBA_4_0/source/lib/util_str.c	2004-09-25 12:36:36 UTC (rev 2632)
@@ -703,7 +703,7 @@
 		return NULL;
 	*p = 0;
 	pull_ucs2_pstring(s2, ws);
-	return (char *)(s+strlen(s2));
+	return discard_const_p(char, s+strlen(s2));
 }
 
 char *strrchr_m(const char *s, char c)
@@ -724,7 +724,7 @@
 		return NULL;
 	*p = 0;
 	pull_ucs2_pstring(s2, ws);
-	return (char *)(s+strlen(s2));
+	return discard_const_p(char, s+strlen(s2));
 }
 
 /**



More information about the samba-cvs mailing list