From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0BE003858C1F for ; Fri, 11 Aug 2023 11:02:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BE003858C1F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691751759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=X98wELpN3XlJ3FXCmIeHHjtHxIV44zA/Bn+W1RIaF+Q=; b=iJL2rzp6w1n3Taik28LkAS3/5zghTqdP2h/FdnAfHm465w5GVwqT6yWiL1MOw6MgWfoNdF BkqQMnbV7sqHtBCgBZtPfKl4y0ZV36WBOKKx3gRGmZNiUSjy4NJtI8EB1aeQskm/c/ptjj uOaslKRU2S2xux/OP94KR5ol6Mm1X5Y= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-FWFEqIfgMlWr64NwI7OYjQ-1; Fri, 11 Aug 2023 07:02:38 -0400 X-MC-Unique: FWFEqIfgMlWr64NwI7OYjQ-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-313c930ee0eso1091030f8f.0 for ; Fri, 11 Aug 2023 04:02:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691751757; x=1692356557; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X98wELpN3XlJ3FXCmIeHHjtHxIV44zA/Bn+W1RIaF+Q=; b=es7O9/T78+o/iYvBGmrJJTdcq9K7jp3IU/TdvzBkrAxSoly73rK+JIAiCECUCyy+88 O471POnIWB+jJimjnzKMaharxuKYvrn6IxmiiocMaW3GRly2ICxFPIuhJoppJ8k7yoVO RfxNlSO9d5RV0wmhbDxug7JgbU0nCNQGDagi0MVXkoX0RDJJotaYiSuXW/QqPrtOjvTS T6fXOYoXYi3MyTC6jeTFuWT96twCp3Z/4D0k7irKxtpowjzGABjueY3kpdTdC/sJ1oIw Rsp8iPDgNmkw6n3q+7QVfb14RBbnBG4VNEALhdRjYSgjvyn5N/n4NXst7XbSd0C9Rmn7 dEGg== X-Gm-Message-State: AOJu0YzFdGPCp31dh2H6jS8B3xOrqd6zDb9220QTC1DdvQvEGywUxSeo nSrugnJvfsimrHJ7BrIDIkocJ29WB7jKcDv06l0/0fqPnvhDQ2qpgH2MlEnCu/jR7puLtpucbgc 6csj6ZMMasLr7zbAhao1koUZ8KJItAQ== X-Received: by 2002:a05:6000:1950:b0:314:1443:7fbe with SMTP id e16-20020a056000195000b0031414437fbemr978165wry.36.1691751757233; Fri, 11 Aug 2023 04:02:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7S4HPIwoGDMLIHy8T0to7tg9nSEtdKJhCxgqyjrHFirYatPgss9rJcg4hTfAkmD9WB0YkBw== X-Received: by 2002:a05:6000:1950:b0:314:1443:7fbe with SMTP id e16-20020a056000195000b0031414437fbemr978132wry.36.1691751756190; Fri, 11 Aug 2023 04:02:36 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id p1-20020adfcc81000000b003179b3fd837sm5048513wrj.33.2023.08.11.04.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 04:02:35 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH v2 5/9] Introduce "static constructor" for mi_parse In-Reply-To: <20230404-dap-loaded-sources-v2-5-93f229095e03@adacore.com> References: <20230404-dap-loaded-sources-v2-0-93f229095e03@adacore.com> <20230404-dap-loaded-sources-v2-5-93f229095e03@adacore.com> Date: Fri, 11 Aug 2023 12:02:34 +0100 Message-ID: <875y5let9x.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.8 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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tom Tromey via Gdb-patches writes: > Change the mi_parse function to be a static method of mi_parse. This > lets us remove the 'set_args' setter function. Hi Tom, Sorry to respond to such an old thread, but I ran into the mi_parse::make code today. From your commit message I don't see the connection for why we need a static mi_parse::make function in order to get rid of the set_args method. For reference, I switched the code back to using constructors (but didn't add back set_args), and I'm not seeing any regressions in gdb.mi/* and gdb.python/*. Could you expand on why this change is needed? Thanks, Andrew > --- > gdb/mi/mi-main.c | 2 +- > gdb/mi/mi-parse.c | 6 +++--- > gdb/mi/mi-parse.h | 28 +++++++++++++--------------- > 3 files changed, 17 insertions(+), 19 deletions(-) > > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c > index aaebce40fac..b430115daea 100644 > --- a/gdb/mi/mi-main.c > +++ b/gdb/mi/mi-main.c > @@ -1919,7 +1919,7 @@ mi_execute_command (const char *cmd, int from_tty) > > try > { > - command = mi_parse (cmd, &token); > + command = mi_parse::make (cmd, &token); > } > catch (const gdb_exception &exception) > { > diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c > index f077eb36a7c..b7c5a8cecdf 100644 > --- a/gdb/mi/mi-parse.c > +++ b/gdb/mi/mi-parse.c > @@ -109,7 +109,7 @@ mi_parse_escape (const char **string_ptr) > void > mi_parse::parse_argv () > { > - const char *chp = m_args.get (); > + const char *chp = m_args.c_str (); > int argc = 0; > char **argv = XNEWVEC (char *, argc + 1); > > @@ -216,7 +216,7 @@ mi_parse::~mi_parse () > } > > std::unique_ptr > -mi_parse (const char *cmd, char **token) > +mi_parse::make (const char *cmd, char **token) > { > const char *chp; > > @@ -345,7 +345,7 @@ mi_parse (const char *cmd, char **token) > } > > /* Save the rest of the arguments for the command. */ > - parse->set_args (chp); > + parse->m_args = chp; > > /* Fully parsed, flag as an MI command. */ > parse->op = MI_COMMAND; > diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h > index edb61547354..6f1da6e6eb5 100644 > --- a/gdb/mi/mi-parse.h > +++ b/gdb/mi/mi-parse.h > @@ -41,7 +41,17 @@ enum mi_command_type > > struct mi_parse > { > - mi_parse () = default; > + /* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is > + invalid, an exception is thrown. For an MI_COMMAND COMMAND, ARGS > + and OP are initialized. Un-initialized fields are zero. *TOKEN is > + set to the token, even if an exception is thrown. It is allocated > + with xmalloc; it must either be freed with xfree, or assigned to > + the TOKEN field of the resultant mi_parse object, to be freed by > + mi_parse_free. */ > + > + static std::unique_ptr make (const char *cmd, > + char **token); > + > ~mi_parse (); > > DISABLE_COPY_AND_ASSIGN (mi_parse); > @@ -54,9 +64,6 @@ struct mi_parse > const char *args () const > { return m_args.c_str (); } > > - void set_args (const char *args) > - { m_args = args; } > - > enum mi_command_type op = MI_COMMAND; > char *command = nullptr; > char *token = nullptr; > @@ -75,20 +82,11 @@ struct mi_parse > > private: > > + mi_parse () = default; > + > std::string m_args; > }; > > -/* Attempts to parse CMD returning a ``struct mi_parse''. If CMD is > - invalid, an exception is thrown. For an MI_COMMAND COMMAND, ARGS > - and OP are initialized. Un-initialized fields are zero. *TOKEN is > - set to the token, even if an exception is thrown. It is allocated > - with xmalloc; it must either be freed with xfree, or assigned to > - the TOKEN field of the resultant mi_parse object, to be freed by > - mi_parse_free. */ > - > -extern std::unique_ptr mi_parse (const char *cmd, > - char **token); > - > /* Parse a string argument into a print_values value. */ > > enum print_values mi_parse_print_values (const char *name); > > -- > 2.40.0