lib:util: Move discard_const(_p) to own header for libndr.h
authorAndreas Schneider <asn@samba.org>
Wed, 6 Feb 2019 15:05:48 +0000 (16:05 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 14 Feb 2019 14:59:26 +0000 (15:59 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13778

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/util/discard.h [new file with mode: 0644]
lib/util/memory.h
lib/util/samba_util.h
lib/util/wscript_build
librpc/ndr/libndr.h
source3/libsmb/samlogon_cache.c

diff --git a/lib/util/discard.h b/lib/util/discard.h
new file mode 100644 (file)
index 0000000..d2b74ac
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Andrew Tridgell 1992-1999
+   Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _SAMBA_DISCARD_H_
+#define _SAMBA_DISCARD_H_
+
+/**
+  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.
+*/
+#ifndef discard_const
+#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
+#endif
+
+/** Type-safe version of discard_const */
+#ifndef discard_const_p
+#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
+#endif
+
+#endif /* _SAMBA_DISCARD_H_ */
index 3278f6b3c2178287abf49723aa2d20658fcd7b23..0e151cc5f66dc02c6424de7017d91382936c1aeb 100644 (file)
 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2)))
 #endif
 
-/**
-  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.
-*/
-#ifndef discard_const
-#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
-#endif
-
-/** Type-safe version of discard_const */
-#ifndef discard_const_p
-#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
-#endif
-
 #endif /* _SAMBA_MEMORY_H_ */
index 8c21c30ebc9c048d3afd257758897064982fabc1..615bb13d6c26496c1d9d33f78c187c6496a64371 100644 (file)
@@ -54,6 +54,7 @@ extern const char *panic_action;
 #endif
 
 #include "lib/util/memory.h"
+#include "lib/util/discard.h"
 
 #include "fault.h"
 
index 64778b3e4c3bac6e5f32740633040a700853287c..02ae378602f826bceaf4943df05bdb1fa1997f45 100644 (file)
@@ -127,7 +127,7 @@ else:
                     tftw.c''',
                   deps='samba-util-core DYNCONFIG close-low-fd tiniparser genrand util_str_hex',
                   public_deps='talloc tevent execinfo pthread LIBCRYPTO charset util_setid',
-                  public_headers='debug.h attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h string_wrappers.h idtree.h idtree_random.h blocking.h signal.h substitute.h fault.h genrand.h tfork.h',
+                  public_headers='debug.h attr.h byteorder.h data_blob.h discard.h memory.h safe_string.h time.h talloc_stack.h string_wrappers.h idtree.h idtree_random.h blocking.h signal.h substitute.h fault.h genrand.h tfork.h',
                   header_path= [ ('dlinklist.h samba_util.h', '.'), ('*', 'util') ],
                   local_include=False,
                   vnum='0.0.1',
index 9c403319b6ed87f6db28d596914a5947534627ac..8a15fccfe09ae6846cee4ee26ab5409be9f9ab40 100644 (file)
@@ -26,7 +26,7 @@
 #define __LIBNDR_H__
 
 #include <talloc.h>
-#include "../lib/util/memory.h" /* for discard_const */
+#include "../lib/util/discard.h" /* for discard_const */
 #include "../lib/util/byteorder.h"
 #include "../lib/util/data_blob.h"
 #include "../lib/util/time.h"
index 494eb10a6a8aac58c04c75ba46c61b6b71e24d11..a9ddaab1a419c104e40827a5e3e624a314047ab3 100644 (file)
@@ -27,6 +27,7 @@
 #include "system/time.h"
 #include "lib/util/debug.h"
 #include "lib/util/talloc_stack.h"
+#include "lib/util/memory.h" /* for SAFE_FREE() */
 #include "source3/lib/util_path.h"
 #include "librpc/gen_ndr/ndr_krb5pac.h"
 #include "../libcli/security/security.h"