diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2006-10-31 21:51:45 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2006-10-31 21:51:45 +0000 |
commit | 08262434df55b5f3c509d2afacb1a39d36e340c4 (patch) | |
tree | b0884cfb310c9d169b1dff153b29bd2ca24d441c /lib/xalloc.h | |
parent | 20668199737bb0bf121381fa0ffa197f0aafcfd1 (diff) | |
download | gnulib-08262434df55b5f3c509d2afacb1a39d36e340c4.tar.gz |
Avoid some C++ diagnostics reported by Bruno Haible.
* lib/quotearg.c (clone_quoting_options): Use xmemdup rather than
xmalloc.
(quotearg_alloc): Use xcharalloc rather than xmalloc.
(struct slotvec): Move to top level.
(quotearg_n_options): Rewrite to avoid xmalloc.
* lib/xalloc.h (xcharalloc): New function.
* (xrealloc, xnrealloc, x2realloc, x2nrealloc, xmemdup):
[defined __cplusplus]: Add function template that provides result
type propagation. This part of the change is from Bruno Haible.
Diffstat (limited to 'lib/xalloc.h')
-rw-r--r-- | lib/xalloc.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/xalloc.h b/lib/xalloc.h index f80977e309..9c397aa752 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -71,8 +71,51 @@ char *xstrdup (char const *str); # define xalloc_oversized(n, s) \ ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) +/* Return a pointer to a new buffer of S bytes. This is like xmalloc, + except it returns char *. */ +static inline char * +xcharalloc (size_t s) +{ + return (char *) xmalloc (s); +} + # ifdef __cplusplus } + +/* C++ does not allow conversions from void * to other pointer types + without a cast. Use templates to work around the problem when + possible. */ + +template <typename T> inline T * +xrealloc (T *p, size_t s) +{ + return (T *) xrealloc ((void *) p, s); +} + +template <typename T> inline T * +xnrealloc (T *p, size_t n, size_t s) +{ + return (T *) xnrealloc ((void *) p, n, s); +} + +template <typename T> inline T * +x2realloc (T *p, size_t *pn) +{ + return (T *) x2realloc ((void *) p, pn); +} + +template <typename T> inline T * +x2nrealloc (T *p, size_t *pn, size_t s) +{ + return (T *) x2nrealloc ((void *) p, pn, s); +} + +template <typename T> inline T * +xmemdup (T const *p, size_t s) +{ + return (T *) xmemdup ((void const *) p, s); +} + # endif |