From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 9880B3858D38 for ; Wed, 12 Aug 2020 21:45:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9880B3858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id EF1FC1E554; Wed, 12 Aug 2020 17:45:53 -0400 (EDT) Subject: Re: [PATCH] debuginfod-support.c: Replace globals with user_data To: Aaron Merey Cc: gdb-patches@sourceware.org References: From: Simon Marchi Message-ID: <468f4240-a259-8ce0-1788-00b3d6e6146b@simark.ca> Date: Wed, 12 Aug 2020 17:45:44 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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, 12 Aug 2020 21:45:55 -0000 On 2020-08-12 5:39 p.m., Aaron Merey wrote: > Hi Simon, > > Thanks for the review, I've updated the patch and moved the Makefile.in > change to a separate patch. > > Aaron > Hi Aaron, Thanks, just a few minor things, the patch LGTM with those fixed. > diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c > index f4a227b040..3f51aaaf43 100644 > --- a/gdb/debuginfod-support.c > +++ b/gdb/debuginfod-support.c > @@ -43,29 +43,37 @@ debuginfod_debuginfo_query (const unsigned char *build_id, > #else > #include > > -/* TODO: Use debuginfod API extensions instead of these globals. */ > -static std::string desc; > -static std::string fname; > -static bool has_printed; > +struct user_data > +{ > + user_data (const char *desc, const char *fname, bool has_printed) > + : desc (desc), fname (fname), has_printed (has_printed) There's no need for the `has_printed` parameter. Just initialize the `has_printed` field to false below. > + { } > + > + const char * const desc; > + const char * const fname; > + bool has_printed; > +}; > > static int > progressfn (debuginfod_client *c, long cur, long total) > { > + user_data *data = static_cast (debuginfod_get_user_data (c)); > + > if (check_quit_flag ()) > { > printf_filtered ("Cancelling download of %s %ps...\n", > - desc.c_str (), > - styled_string (file_name_style.style (), fname.c_str ())); > + data->desc, > + styled_string (file_name_style.style (), data->fname)); > return 1; > } > > - if (!has_printed && total != 0) > + if (!data->has_printed && total != 0) > { > /* Print this message only once. */ > - has_printed = true; > + data->has_printed = true; > printf_filtered ("Downloading %s %ps...\n", > - desc.c_str (), > - styled_string (file_name_style.style (), fname.c_str ())); > + data->desc, > + styled_string (file_name_style.style (), data->fname)); > } > > return 0; > @@ -98,10 +106,9 @@ debuginfod_source_query (const unsigned char *build_id, > if (c == nullptr) > return scoped_fd (-ENOMEM); > > - desc = std::string ("source file"); > - fname = std::string (srcpath); > - has_printed = false; > + struct user_data data ("source file", srcpath, false); Omit the `struct` keyword when referring to the new type. > > + debuginfod_set_user_data (c, &data); > scoped_fd fd (debuginfod_find_source (c, > build_id, > build_id_len, > @@ -136,11 +143,10 @@ debuginfod_debuginfo_query (const unsigned char *build_id, > if (c == nullptr) > return scoped_fd (-ENOMEM); > > - desc = std::string ("separate debug info for"); > - fname = std::string (filename); > - has_printed = false; > char *dname = nullptr; > + struct user_data data ("separate debug info for", filename, false); Same here. Simon