From 9bf434a941be2f3b13b5cc59b5ad6f77f0c0fb8d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 6 Feb 2019 16:05:48 +0100 Subject: [PATCH] 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 Reviewed-by: Guenther Deschner Reviewed-by: Stefan Metzmacher (cherry picked from commit 96df6878ed521b7e744d703abb32a585500d3b94) --- lib/util/discard.h | 51 +++++++++++++++++++++++++++++++++++++++++ lib/util/memory.h | 27 ---------------------- lib/util/samba_util.h | 1 + lib/util/wscript_build | 2 +- librpc/ndr/libndr.h | 2 +- source3/libsmb/samlogon_cache.c | 1 + 6 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 lib/util/discard.h 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 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 . +*/ + +#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 7b96a595d43..11c95b5bfe3 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 8fc402062fb..9c9652b26cd 100644 --- a/lib/util/wscript_build +++ b/lib/util/wscript_build @@ -126,7 +126,7 @@ else: tevent_debug.c memcache.c unix_match.c tfork.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 -#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" -- 2.11.4.GIT