From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20080 invoked by alias); 20 Dec 2016 17:48:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 20070 invoked by uid 89); 20 Dec 2016 17:48:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=topic, tom@tromey.com, U*tom, D*tromey.com X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Dec 2016 17:48:46 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C011E7F7C0; Tue, 20 Dec 2016 17:48:45 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBKHmiPU004944; Tue, 20 Dec 2016 12:48:45 -0500 Subject: Re: [RFA 7/8] Use unique_xmalloc_ptr in execute_gdb_command To: Tom Tromey References: <1480395946-10924-1-git-send-email-tom@tromey.com> <1480395946-10924-8-git-send-email-tom@tromey.com> <878ts2yi5m.fsf@tromey.com> <87inqletsw.fsf@tromey.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <7f11b7bb-bebb-1cd3-1e92-266638272443@redhat.com> Date: Tue, 20 Dec 2016 17:48:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <87inqletsw.fsf@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-12/txt/msg00359.txt.bz2 On 12/15/2016 03:48 AM, Tom Tromey wrote: >>>>>> "Tom" == Tom Tromey writes: > > Tom> To my surprise, this patch is broken. > Tom> I must not have re-run the python tests locally after writing it :( > > Tom> The problem is that prevent_dont_repeat returns a cleanup, which is then > Tom> left dangling after this patch. > > Here's the updated patch. > I ran this one through the buildbot. > In some other local patch that I hadn't posted, I handled a similar situation of save/restoring some global that we don't want to expose by making the "make_cleanup_..." function return a scoped_restore, which avoids having to create a new class. It seems a bit simpler that creating a class to me, and maybe a tiny bit more efficient code-space wise (rtti?) Did you consider this approach? In this case, it'd look like this: >From 3138a3fb72f76d0d1bb5a2e1db57e450c37dd43a Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 20 Dec 2016 17:30:56 +0000 Subject: [PATCH] Return scoped_restore instead of cleanup --- gdb/breakpoint.c | 2 +- gdb/command.h | 2 +- gdb/top.c | 16 ++++++---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index d737cad..dc72986 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4685,7 +4685,7 @@ bpstat_do_actions_1 (bpstat *bsp) executing_breakpoint_commands = 1; old_chain = make_cleanup (cleanup_executing_breakpoints, 0); - prevent_dont_repeat (); + scoped_restore save_dont_repeat = prevent_dont_repeat (); /* This pointer will iterate over the list of bpstat's. */ bs = *bsp; diff --git a/gdb/command.h b/gdb/command.h index 965d91f..7b87814 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -408,7 +408,7 @@ extern void error_no_arg (const char *) ATTRIBUTE_NORETURN; extern void dont_repeat (void); -extern struct cleanup *prevent_dont_repeat (void); +extern scoped_restore_tmpl prevent_dont_repeat (); /* Used to mark commands that don't do anything. If we just leave the function field NULL, the command is interpreted as a help topic, or diff --git a/gdb/top.c b/gdb/top.c index 7d8b6e8..280af71 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -732,10 +732,10 @@ execute_command_to_string (char *p, int from_tty) } -/* When nonzero, cause dont_repeat to do nothing. This should only be +/* When true, cause dont_repeat to do nothing. This should only be set via prevent_dont_repeat. */ -static int suppress_dont_repeat = 0; +static bool suppress_dont_repeat = false; /* Commands call this if they do not want to be repeated by null lines. */ @@ -754,16 +754,12 @@ dont_repeat (void) *saved_command_line = 0; } -/* Prevent dont_repeat from working, and return a cleanup that +/* Prevent dont_repeat from working, and return a scoped restore that restores the previous state. */ - -struct cleanup * -prevent_dont_repeat (void) +scoped_restore_tmpl +prevent_dont_repeat () { - struct cleanup *result = make_cleanup_restore_integer (&suppress_dont_repeat); - - suppress_dont_repeat = 1; - return result; + return make_scoped_restore (&suppress_dont_repeat, true); } -- 2.5.5