From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1828 invoked by alias); 14 May 2013 20:42:07 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 1805 invoked by uid 306); 14 May 2013 20:42:07 -0000 Date: Tue, 14 May 2013 20:42:00 -0000 Message-ID: <20130514204207.1776.qmail@sourceware.org> From: tromey@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] tromey/cleanup-checker: introduce scoped cleanups X-Git-Refname: refs/heads/tromey/cleanup-checker X-Git-Reftype: branch X-Git-Oldrev: 212f7dae72349005357393d8c3b80e88c2e2c46b X-Git-Newrev: 8a08c1b0d1feef7543005325d453a9efdcb4b7dc X-SW-Source: 2013-q2/txt/msg00071.txt.bz2 List-Id: The branch, tromey/cleanup-checker has been updated discards 212f7dae72349005357393d8c3b80e88c2e2c46b (commit) via 8a08c1b0d1feef7543005325d453a9efdcb4b7dc (commit) from 212f7dae72349005357393d8c3b80e88c2e2c46b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 8a08c1b0d1feef7543005325d453a9efdcb4b7dc Author: Tom Tromey Date: Thu May 9 11:44:45 2013 -0600 introduce scoped cleanups This adds scoped cleanups to gdb. A scoped cleanup is a more efficient, and checkable, alternative to the common idiom: cleanup = make_cleanup (null_cleanup, NULL); ... do_cleanups (cleanup); ... where the cleanup is always run when exiting the scope. The efficiency comes from stack allocating the scoped cleanup. This is probably minor. However, I've noticed myself sometimes avoiding null cleanups on this basis, and it is nice to erase that bias. The checking comes from using a GCC extension when available. This check ensures that the scoped cleanup was either run or discarded when the scope exits. ----------------------------------------------------------------------- Summary of changes: gdb/cleanups.c | 6 ++++-- gdb/cleanups.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) First 500 lines of diff: diff --git a/gdb/cleanups.c b/gdb/cleanups.c index 76d28c4..6d6d78c 100644 --- a/gdb/cleanups.c +++ b/gdb/cleanups.c @@ -324,13 +324,15 @@ init_scoped_cleanup (struct scoped_cleanup *cl) return old_chain; } +#ifdef SCOPED_CLEANUP_CHECKING + /* Verify that a scoped cleanup was in fact handled. */ void cleanup_close_scope (struct scoped_cleanup *cl) { -#ifdef SCOPED_CLEANUP_CHECKING if (!cl->base.cleaned_up) internal_warning (__FILE__, __LINE__, "scoped cleanup leaked"); -#endif /* SCOPED_CLEANUP_CHECKING */ } + +#endif /* SCOPED_CLEANUP_CHECKING */ diff --git a/gdb/cleanups.h b/gdb/cleanups.h index 9f8cbd4..e16a9fa 100644 --- a/gdb/cleanups.h +++ b/gdb/cleanups.h @@ -94,8 +94,6 @@ struct scoped_cleanup extern struct cleanup *init_scoped_cleanup (struct scoped_cleanup *); -extern void cleanup_close_scope (struct scoped_cleanup *); - #if defined (__GNUC__) && __GNUC__ >= 4 /* Define this to consolidate #if checking with the @@ -106,6 +104,8 @@ extern void cleanup_close_scope (struct scoped_cleanup *); #define SCOPED_CLEANUP_ATTRIBUTE \ __attribute__ ((cleanup (cleanup_close_scope))) +extern void cleanup_close_scope (struct scoped_cleanup *); + #else #define SCOPED_CLEANUP_ATTRIBUTE hooks/post-receive -- Repository for Project Archer.