From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id k+jaHR/CAWEVKQAAWB0awg (envelope-from ) for ; Wed, 28 Jul 2021 16:46:23 -0400 Received: by simark.ca (Postfix, from userid 112) id 6AA891EDFB; Wed, 28 Jul 2021 16:46:23 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B93F41E813 for ; Wed, 28 Jul 2021 16:46:22 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E72B393AC01 for ; Wed, 28 Jul 2021 20:46:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E72B393AC01 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627505182; bh=0KGPrKsqwDNTtpHV3Xm8rhWGF8JnwqSR8sxtv7xxNDc=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=AtHgtdZfbTzdDJoxPyVFPnMaKg72reh7rZMoaNd24PDds1Fia1zQYiGiHiCX/bwSe JlPM+myZMac2JV80pVPY3KZ56Ivxome7PEwKxn8cEZtc9lK5Y5uxDCILvl+Mmf1I7P /VEfXs4ic5z5OWjhhCLbUIHhGbmaQzUeFTlRTqSw= 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 To: Tom Tromey 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-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: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Cc: Lancelot SIX via Gdb-patches Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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