summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2019-02-06 16:05:48 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-02-14 15:59:26 +0100
commit96df6878ed521b7e744d703abb32a585500d3b94 (patch)
tree46a4e841574ab8782b02fbe083d5c1748c95c7dd
parent532ce0d20a8016c1270ea689de627da8aa4abfdd (diff)
downloadsamba-96df6878ed521b7e744d703abb32a585500d3b94.tar.gz
lib:util: Move discard_const(_p) to own header for libndr.h
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>
-rw-r--r--lib/util/discard.h51
-rw-r--r--lib/util/memory.h27
-rw-r--r--lib/util/samba_util.h1
-rw-r--r--lib/util/wscript_build2
-rw-r--r--librpc/ndr/libndr.h2
-rw-r--r--source3/libsmb/samlogon_cache.c1
6 files changed, 55 insertions, 29 deletions
diff --git a/lib/util/discard.h b/lib/util/discard.h
new file mode 100644
index 00000000000..d2b74ac989c
--- /dev/null
+++ b/lib/util/discard.h
@@ -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_ */
diff --git a/lib/util/memory.h b/lib/util/memory.h
index 3278f6b3c21..0e151cc5f66 100644
--- a/lib/util/memory.h
+++ b/lib/util/memory.h
@@ -94,31 +94,4 @@
#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_ */
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 8c21c30ebc9..615bb13d6c2 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -54,6 +54,7 @@ extern const char *panic_action;
#endif
#include "lib/util/memory.h"
+#include "lib/util/discard.h"
#include "fault.h"
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 64778b3e4c3..02ae378602f 100644
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -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',
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h
index 9c403319b6e..8a15fccfe09 100644
--- a/librpc/ndr/libndr.h
+++ b/librpc/ndr/libndr.h
@@ -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"
diff --git a/source3/libsmb/samlogon_cache.c b/source3/libsmb/samlogon_cache.c
index 494eb10a6a8..a9ddaab1a41 100644
--- a/source3/libsmb/samlogon_cache.c
+++ b/source3/libsmb/samlogon_cache.c
@@ -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"