From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lndn.lancelotsix.com (lndn.lancelotsix.com [51.195.220.111]) by sourceware.org (Postfix) with ESMTPS id 4B9D4398AC29 for ; Wed, 28 Jul 2021 20:45:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4B9D4398AC29 Received: from ubuntu.lan (unknown [IPv6:2a02:390:9086::635]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 6465F818FD; Wed, 28 Jul 2021 20:45:43 +0000 (UTC) Date: Wed, 28 Jul 2021 20:45:38 +0000 From: Lancelot SIX To: Tom Tromey Cc: Lancelot SIX via Gdb-patches Subject: Re: [PATCH 15/16] gdb: make cmd_list_element var an optional union Message-ID: <20210728204538.z3iqkcfp7yenehms@ubuntu.lan> References: <20210714045520.1623120-1-simon.marchi@polymtl.ca> <20210714045520.1623120-16-simon.marchi@polymtl.ca> <20210714120851.3pfew5pgcdp6ezn6@ubuntu.lan> <20210714171238.vzccwpurh2izbkps@ubuntu.lan> <20210714232112.wsn7pits6uuz3nf5@ubuntu.lan> <20210720230335.dcpfxbol2uwjre3b@Plymouth> <87sfzyci3i.fsf@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87sfzyci3i.fsf@tromey.com> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Wed, 28 Jul 2021 20:45:43 +0000 (UTC) X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jul 2021 20:45:46 -0000 On Wed, Jul 28, 2021 at 02:13:21PM -0600, Tom Tromey wrote: > >>>>> "Lancelot" == Lancelot SIX via Gdb-patches writes: > > Lancelot> This patch proposes to add an abstraction around the pair of the > Lancelot> var_type and the void* pointer in order to prevent the user having to > Lancelot> handle the cast. This is achieved by introducing the setting struct, > Lancelot> and a set of templated member functions. The template parameter is the > Lancelot> VAR_TYPES we want to the access the data for. The template ensures the > Lancelot> return type of the get method and the parameter type of the set method > Lancelot> matches the data type used to store the actual data. > > Seems nice. > > Lancelot> int get () > > It seems to me that it might be better if the get<> template itself knew > about the storage equivalence between different var_ types and so code > like this: > > Lancelot> + var = cmd->var.get Lancelot> + var_string_noescape, > Lancelot> + var_optional_filename, > Lancelot> + var_filename> (); > > ... could be simplified. > > Tom Hi, Would you prefer to have something like var.get () return a string happily if var is lets say a var_filename but fail if it is a var_boolean? I guess it is possible, but I did intentionally went for a very explicit approach. The idea is to have the user of the class state that he is aware he will access a data of a given type that can be interpreted in different ways. This kind of makes more sense when dealing with the various var_*integer* types where the same value can have different meaning depending on the effective var_type. In a way, I guess this is covered by the various fall through of the switch / case statement where this call is typically used. The limitation of this is that the switch will not complain if you try to share a code path for incompatible types, you will need to wait for a runtime error instead of a compile time error. Anyway, if you find it more practical, I can try rework the interface this way. By the way, I just posted a complete series that contains this proposal, plus other improvements[1]. I’ll probably wait a bit to see if I get different feedbacks and come up with something I fill will work for the most. Thanks, Lancelot. [1] https://sourceware.org/pipermail/gdb-patches/2021-July/181183.html