2010-06-11 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / vec.h
index f6b7f07146ca2fd0355290c2a103617e39556b2e..e9d5a1583e96b6a82ba586b797d636592a413588 100644 (file)
--- a/gdb/vec.h
+++ b/gdb/vec.h
@@ -1,12 +1,13 @@
 /* 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,
@@ -15,9 +16,7 @@
    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_
@@ -458,7 +464,16 @@ static inline void VEC_OP (T,free)                                   \
      (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;                                                                  \
 }                                                                        \
                                                                          \
@@ -696,7 +711,16 @@ static inline void VEC_OP (T,free)                                   \
      (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;                                                                  \
 }                                                                        \
                                                                          \
@@ -954,7 +978,16 @@ static inline void VEC_OP (T,free)                                   \
      (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;                                                                  \
 }                                                                        \
                                                                          \
This page took 0.025795 seconds and 4 git commands to generate.