From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 0DEDF3857021 for ; Thu, 13 Aug 2020 21:55:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0DEDF3857021 Received: from mail-vk1-f197.google.com (mail-vk1-f197.google.com [209.85.221.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-yu9b8oVTN-SN1nPKwOQNFA-1; Thu, 13 Aug 2020 17:55:03 -0400 X-MC-Unique: yu9b8oVTN-SN1nPKwOQNFA-1 Received: by mail-vk1-f197.google.com with SMTP id y203so1991904vky.0 for ; Thu, 13 Aug 2020 14:55:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SR/GJqNN0j5UDn+FYf2pieM2qaeVyh3H0TE/ty/OqYY=; b=PWyPpO34HGCWsQDEs2yUuTrsyVrVDrKJcUVkLvFB85+iUJyb4T5z9pbXuN11WjKEjW OcoDmEnAGY/qHkGtNtFIS7GY56yrrchKegdb4QTLjZN+L2W02SBTVEQ3Vhy0xG4uIB0b 0g54+Q1KH9+hves0hrqGEws06UltsEJ9uBq5SwHbabD0VfSgOqfSihkmAJtyTlC8out9 sgWAy74h3OfIP8+/vK79qpKm8pwyOVliC3inhqXYH27syojCChXJPKG2YDtPQVV4Fi9O fFVOkeJ4q8ZW71MV4fflz6YfcwoRNEXBDaIdTXpRoRPpYjaMMNi97LmnJ/w5WCzSdFpE hZbw== X-Gm-Message-State: AOAM532aIFZoMo4cEr5kRe9C36b6/kYNQBrg9XHpaXyVgYvEMc4MuZ8o MfwuGCtsaZNF/bjdFHufb7qoY4pbUTU7VnEHieme45H7qAXiijVk0YFy3t/loqAVJjfzrX98oKo 6Lb58bNmBDVBjdmKTwL+5mv5xEv59Q3zSdz70 X-Received: by 2002:a9f:24ac:: with SMTP id 41mr5287346uar.137.1597355702533; Thu, 13 Aug 2020 14:55:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFlowqylldPgN6EN+g7/PjZ53K0/Zu7FaIQEmhyCp5BJPVO69QcdRYtISgPQ67dIpoCgpIaXw5iLxe0LlOwPc= X-Received: by 2002:a9f:24ac:: with SMTP id 41mr5287335uar.137.1597355702295; Thu, 13 Aug 2020 14:55:02 -0700 (PDT) MIME-Version: 1.0 References: <468f4240-a259-8ce0-1788-00b3d6e6146b@simark.ca> In-Reply-To: <468f4240-a259-8ce0-1788-00b3d6e6146b@simark.ca> From: Aaron Merey Date: Thu, 13 Aug 2020 17:54:51 -0400 Message-ID: Subject: Re: [PATCH] debuginfod-support.c: Replace globals with user_data To: Simon Marchi Cc: gdb-patches@sourceware.org X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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: Thu, 13 Aug 2020 21:55:06 -0000 On Wed, Aug 12, 2020 at 5:45 PM Simon Marchi wrote: > 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. Thanks Simon, I pushed the patch with these changes. Aaron