This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: add an obstack cleanup
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 19 Mar 2009 11:38:57 -0600
- Subject: FYI: add an obstack cleanup
- Reply-to: Tom Tromey <tromey at redhat dot com>
I'm checking this in.
This patch adds a function to create a cleanup that frees an obstack.
I'm splitting up the charset patch for checkin, and this is the first
(and smallest) piece.
Tom
2009-03-19 Tom Tromey <tromey@redhat.com>
* utils.c (do_obstack_free): New function.
(make_cleanup_obstack_free): Likewise.
* defs.h (make_cleanup_obstack_free): Declare.
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.246
diff -u -r1.246 defs.h
--- defs.h 13 Mar 2009 02:34:13 -0000 1.246
+++ defs.h 19 Mar 2009 17:32:54 -0000
@@ -366,6 +366,9 @@
extern struct cleanup *make_cleanup_bfd_close (bfd *abfd);
+struct obstack;
+extern struct cleanup *make_cleanup_obstack_free (struct obstack *obstack);
+
extern struct cleanup *make_cleanup_restore_integer (int *variable);
extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *);
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.206
diff -u -r1.206 utils.c
--- utils.c 21 Feb 2009 16:14:49 -0000 1.206
+++ utils.c 19 Mar 2009 17:32:55 -0000
@@ -271,6 +271,23 @@
return make_cleanup (do_fclose_cleanup, file);
}
+/* Helper function which does the work for make_cleanup_obstack_free. */
+
+static void
+do_obstack_free (void *arg)
+{
+ struct obstack *ob = arg;
+ obstack_free (ob, NULL);
+}
+
+/* Return a new cleanup that frees OBSTACK. */
+
+struct cleanup *
+make_cleanup_obstack_free (struct obstack *obstack)
+{
+ return make_cleanup (do_obstack_free, obstack);
+}
+
static void
do_ui_file_delete (void *arg)
{