From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 56055 invoked by alias); 20 Dec 2016 14:49:12 -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 55346 invoked by uid 89); 20 Dec 2016 14:49:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=tromey, Headers, offsetof, Tromey 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 14:49:10 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 3CC7467BC8; Tue, 20 Dec 2016 14:49:09 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBKEn7LC027085; Tue, 20 Dec 2016 09:49:08 -0500 Subject: Re: [RFA 6/8] Use value_freer in dwarf2_evaluate_loc_desc_full To: Tom Tromey References: <1480395946-10924-1-git-send-email-tom@tromey.com> <1480395946-10924-7-git-send-email-tom@tromey.com> <06e2b7b1-feca-29f7-7e49-e05f01d05485@redhat.com> <87bmwgez57.fsf@tromey.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Tue, 20 Dec 2016 14:49: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: <87bmwgez57.fsf@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-12/txt/msg00354.txt.bz2 On 12/13/2016 01:28 PM, Tom Tromey wrote: >>>>>> "Pedro" == Pedro Alves writes: > > Pedro> Or "reset ()", following the naming used in the standard smart pointers? > > I went with reset since I think "free" can be a macro sometimes. > Or at least it could in C... not actually sure if C++ removed this > possibility. I always assumed it has, but had never went looking for the specific wording. Looking at the C++14 draft N4140, I see: 17.6.1.2 - Headers: 5 - Names which are defined as macros in C shall be defined as macros in the C ++ standard library, even if C grants license for implementation as functions. [ Note: The names defined as macros in C include the following: assert, offsetof, setjmp, va_arg, va_end, and va_start. - end note ] 6 - Names that are defined as functions in C shall be defined as functions in the C ++ standard library." (175) And then footnote 175 clarifies: "175) This disallows the practice, allowed in C, of providing a masking macro in addition to the function prototype. The only way to achieve equivalent inline behavior in C ++ is to provide a definition as an extern inline function." So I think the answer is yes, C++ removes that possibility. BTW, I meanwhile realized that "release" would also be a naming/concept conflict with release_value / value_release_to_mark too. Really best to avoid it here. In pondering a bit more over this, I wonder whether adding a "scoped_" to go with scoped_restore etc., would make it a bit clearer to readers that this is a RAII type. Then also considering value_release_to_mark, I wonder would an API/naming like this: struct scoped_value_mark { scoped_value_mark () : m_value (value_mark ()) {} ~scoped_value_mark () { free_to_mark ()} void free_to_mark () { if (m_value) value_free_to_mark (m_value); } void release_to_mark () { if (m_value) value_release_to_mark (m_value); } /* Get the mark value. */ struct value *get () { return m_value; } }; Uses would look like: scoped_value_mark value_mark; ... value_mark.free_to_mark (); // some path than wants an explicit "free_to_mark". In eval.c:fetch_subexp_value we'd use it like: /* Evaluate the expression. */ scoped_value_mark mark; [...] result = evaluate_subexp (NULL_TYPE, exp, pc, EVAL_NORMAL); [...] new_mark = value_mark (); if (mark.get () == new_mark) return; /* Make sure it's not lazy, so that after the target stops again we have a non-lazy previous value to compare with. */ [...] if (val_chain) { /* Return the chain of intermediate values. We use this to decide which addresses to watch. */ *val_chain = new_mark; mark.release_to_mark (); } } Would this result in clearer client code? IMHO, yes, but WDYT? Thanks, Pedro Alves