/* Vector API for GDB.
- Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
+ Free Software Foundation, Inc.
Contributed by Nathan Sidwell <nathan@codesourcery.com>
This file is part of GDB.
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 2 of the License, or
+ 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,
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, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#if !defined (GDB_VEC_H)
#define GDB_VEC_H
#define VEC_free(T,V) (VEC_OP(T,free)(&V))
+/* A cleanup function for a vector.
+ void VEC_T_cleanup(void *);
+
+ Clean up a vector. */
+
+#define VEC_cleanup(T) (VEC_OP(T,cleanup))
+
/* Use these to determine the required size and initialization of a
vector embedded within another structure (as the final member).
/* Reallocate an array of elements with prefix. */
extern void *vec_p_reserve (void *, int);
extern void *vec_o_reserve (void *, int, size_t, size_t);
-#define vec_free(V) xfree (V)
+#define vec_free_(V) xfree (V)
#define VEC_ASSERT_INFO ,__FILE__,__LINE__
#define VEC_ASSERT_DECL ,const char *file_,unsigned line_
(VEC(T) **vec_) \
{ \
if (*vec_) \
- vec_free (*vec_); \
+ vec_free_ (*vec_); \
+ *vec_ = NULL; \
+} \
+ \
+static inline void VEC_OP (T,cleanup) \
+ (void *arg_) \
+{ \
+ VEC(T) **vec_ = arg_; \
+ if (*vec_) \
+ vec_free_ (*vec_); \
*vec_ = NULL; \
} \
\
(VEC(T) **vec_) \
{ \
if (*vec_) \
- vec_free (*vec_); \
+ vec_free_ (*vec_); \
+ *vec_ = NULL; \
+} \
+ \
+static inline void VEC_OP (T,cleanup) \
+ (void *arg_) \
+{ \
+ VEC(T) **vec_ = arg_; \
+ if (*vec_) \
+ vec_free_ (*vec_); \
*vec_ = NULL; \
} \
\
(VEC(T) **vec_) \
{ \
if (*vec_) \
- vec_free (*vec_); \
+ vec_free_ (*vec_); \
+ *vec_ = NULL; \
+} \
+ \
+static inline void VEC_OP (T,cleanup) \
+ (void *arg_) \
+{ \
+ VEC(T) **vec_ = arg_; \
+ if (*vec_) \
+ vec_free_ (*vec_); \
*vec_ = NULL; \
} \
\