From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 93BE63857C49 for ; Mon, 18 Apr 2022 20:56:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 93BE63857C49 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 23IKtKpw030634 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Apr 2022 16:55:25 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 23IKtKpw030634 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id EDC5B1E150; Mon, 18 Apr 2022 16:55:19 -0400 (EDT) Message-ID: Date: Mon, 18 Apr 2022 16:55:19 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH 5/5] gdbsupport: add path_join function Content-Language: en-US To: Pedro Alves , Lancelot SIX Cc: Simon Marchi , gdb-patches@sourceware.org References: <20220414200137.3479373-1-simon.marchi@polymtl.ca> <20220414200137.3479373-5-simon.marchi@polymtl.ca> <20220415143827.t2nlcfhmh2pondev@ubuntu.lan> <1343c861-94b4-d0e6-67af-dd6eb1f870c3@palves.net> <3f6204cc-514b-9bf7-6b9a-c89151075ede@polymtl.ca> From: Simon Marchi In-Reply-To: <3f6204cc-514b-9bf7-6b9a-c89151075ede@polymtl.ca> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 18 Apr 2022 20:55:20 +0000 X-Spam-Status: No, score=-3034.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Mon, 18 Apr 2022 20:56:33 -0000 > On 2022-04-18 15:09, Pedro Alves wrote: >> On 2022-04-18 19:43, Simon Marchi via Gdb-patches wrote: >>>> One implementation could be: >>>> >>>> /* The real worker can be compiled in a .cc file if you wish. */ >>>> extern std::string path_join_1 (std::string a, std::string b); >>>> >>>> template >>> std::string >>>> path_join (std::string a, std::string b, Args... comps) >>>> { >>>> return path_join (path_join (a, b), comps...); >>>> } >>>> >>>> template <> >>>> std::string >>>> path_join (std::string a, std::string b) >>>> { >>>> return path_join_1 (a, b); >>>> } >>>> >>>> I do not pretend this is optimal (it is not). In this POC I pass all >>>> arguments as std::string and by value, this is probably not what you >>>> want to do in a production grade implementation, but this just gives the >>>> overall idea. >>>> >>>> What do you think? >>> If you can make it work using gdb::string_view or const char *, I think >>> it would be ok. I'll give it a try. But otherwise, I am personally >>> fine with the sentinel nullptr, given that the compiler gives you a >>> warning if you forget it. >> >> I think it would just work as is you replace std::string with const char * >> in Lancelot's snippet above. FWIW, I had the same thought as Lancelot >> about using variable templates instead of varargs. >> >> OOC, is there any place in GDB that wants to pass more than two components >> to path_join? I skimmed the patch and didn't notice one. > > I am not aware of one, I'd be happy to make path_join just have two > parameters and be done with it. Actually, I have one use for it in my upcoming DWARF reader changes, where I join the CU's compilation directory, the directory (from the line header directory table) and the file name. I like Tom's proposal, here: https://sourceware.org/pipermail/gdb-patches/2022-April/188016.html It seems efficient (no extraneous string copies) and type-safe. I successfully changed my patch to use it. Simon