From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yay+HRslaWmxDgUAWB0awg (envelope-from ) for ; Thu, 15 Jan 2026 12:34:19 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=FJBSsSd7; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6D2691E0E1; Thu, 15 Jan 2026 12:34:19 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7F3281E070 for ; Thu, 15 Jan 2026 12:34:18 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id F418A4BA23DC for ; Thu, 15 Jan 2026 17:34:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F418A4BA23DC Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=FJBSsSd7 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 647F14BA2E1E for ; Thu, 15 Jan 2026 17:33:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 647F14BA2E1E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 647F14BA2E1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768498402; cv=none; b=WFXXLuYcBdFIJPT0V90XKHJsN5yC/jwIkKh+1wDEnxB2JSjPzMQe/4zLE4SoHxyXoxgwycOLD/GLHKrni2Unos1etsusylumctYxuXscPavZX5CS25ViBXV/kHKI9PefNCGmgYj4umT4GhDBqeCNrhuByRmff8R2EPXSjXEAnE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768498402; c=relaxed/simple; bh=7w6yghwYS89HEX2iswSwaXmAR1j+u7ALbGe6FjpXWq8=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=iowF37x+tAjKvLcEX7Q4FcvqqSqLarJQNM8rV5kJIHz8bZ4ZHuD0UPVTiYsgDxBuw+xzCR7xskVxLC8fKieUXLg+Fm5wSJtaaTu7QiChqAIhbcLcHNsNGSXf5fllHRin7j5WOzBamHaEBlFWTuZgeqnVipocVX/gNMor+OEfU2Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 647F14BA2E1E Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-7cfcbf34124so788753a34.0 for ; Thu, 15 Jan 2026 09:33:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1768498402; x=1769103202; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=AYOEulcdn1ksIRbzvFkMqx0xxiokuQyTEodVHuAoE9g=; b=FJBSsSd71ZdHD5oAeh8uJj5AgMab5f2CVxuXFXoxL9Wpj8V2iF181v8paizveOY/9T ouC5ssCP/OJqgV+FCGiaZG4c31wKjt29ysvBrpAo/VUOP4wlE4AGtkeLIpjcggSWt/8I ZdsYoxgn5NF4uKfN1AERBTvb5YjbtKWz6phsC1rwCxMr0agUsa4UKIU22qrRYFKadcsK dJ7wei7v13yfJOGxrXihAKNWitMcekHdUdLRnIQL2uBNGlQVRZasCmDgcUtSfC6HCb9c sPxRHXsBIT4nQtAFUz0CfG5xnNLwq80VBjYcvejSMW/9qZqEifSBb0tCGLsMXT4YX9Fi v2Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768498402; x=1769103202; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=AYOEulcdn1ksIRbzvFkMqx0xxiokuQyTEodVHuAoE9g=; b=KJx5v9tGaBM9AtE2IlU/zHdrhBJaFegdGGM6UHLDk6P/kwThL3fgxuVnPjtJN+Y2BT mmicKLIetT6N4djnyWYPNB4FCR6DHBxSyLvxxngVf8Dv/aWzjOx/OnhRiwC+VHH2F8De nBYCQ1cuFUMRicZxq+aSxF2U8fJkx4Ayd7/lstylVs2DQcvzK656RDfvVBM8gbNTIm7F 1Wl1II7W6VNgxFtRyEYO3MW7abjEFojJ3Tuwo2ov84qZ70Ea58F66D+HUASZI42APuod IbCzGhfiYEI9rH//X0rRfP1ur5YjdM+EzHPO80S/j0sCi3ImqEoVNSU/W+Dqv4GJCBR/ 00Og== X-Gm-Message-State: AOJu0YxPfnpXWwDVG+ee3OTrARXdn3BGmLmqqOD+dn33gAMb/ZGxdrIu Ye274bNCvZ13EDY2YB8fngH/vJekI0U6ifysw899MckXN1o4SZg/RKlRhXbAlBAuMg== X-Gm-Gg: AY/fxX4oI3gxJejIDuL05WZLiA9UMchvkIGeevDAAbxv4KWqjlGo9QO/Du9mNP4E5YZ TAagnFbnpdJw36Z4RVNydRLNxTRh98kdfdRbLQOE7hpBpCly+3h6+VdReM39TFqabIL0cQFsYzW FDWccpEFSj7en0VcyTVexBJrEDKn+hfYVcyKpjvvffWKt/IsKuhR73nfOLazcjX2yxVwAY/CiR1 w+n+cj4jmS6S3dyszNHW8CgeErplSCoz6KhQhifTFqDpy/H9n3zwIiSVli0wOoxfx6I5PmHMEZd nu4JAkJ7nNn5oOAwN26rUg3fLYOv4SP6+D9aoAXAAjSdVCUUlur0suNTi8DqmBD7VI/LZ93Urpr 1ScB/EN0uJ17NUM64rbiNOkir6FlTu/cOx412jx4OzaoQe05kDSAwGyOPmi2GHhzMMtVOSSsu9J 9ltAqpjWBsyo9nsOMLzE2gv/MqiLav60Ob2Nx65HkDXg== X-Received: by 2002:a05:6830:6d23:b0:7c7:52e0:9f69 with SMTP id 46e09a7af769-7cfdee5f93fmr133973a34.31.1768498401626; Thu, 15 Jan 2026 09:33:21 -0800 (PST) Received: from [192.168.0.26] (97-122-114-32.hlrn.qwest.net. [97.122.114.32]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7cfdf0e92d3sm67743a34.9.2026.01.15.09.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 09:33:21 -0800 (PST) From: Tom Tromey Date: Thu, 15 Jan 2026 10:33:18 -0700 Subject: [PATCH 1/2] Use make_unique_xstrdup in more places MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260115-xstrdup-v1-1-72e13ba99851@adacore.com> References: <20260115-xstrdup-v1-0-72e13ba99851@adacore.com> In-Reply-To: <20260115-xstrdup-v1-0-72e13ba99851@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This replaces a number of uses of 'ptr.reset (xstrdup ())' with 'ptr = make_unique_xstrdup ()'. The main motivation for this is that, IMO, it's better to avoid the reset method when possible. --- gdb/breakpoint.c | 4 ++-- gdb/buildsym.h | 8 +++++--- gdb/cli/cli-dump.c | 2 +- gdb/mi/mi-cmd-env.c | 2 +- gdb/python/py-framefilter.c | 2 +- gdb/python/py-function.c | 2 +- gdb/python/py-lazy-string.c | 5 ++++- gdb/python/py-param.c | 2 +- gdb/solib.c | 4 ++-- gdb/source.c | 4 ++-- gdb/stack.c | 16 +++++++++++----- gdb/tracectf.c | 4 ++-- 12 files changed, 33 insertions(+), 22 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index af4de248ab6..a4ccad32a8b 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -9296,9 +9296,9 @@ create_breakpoint (struct gdbarch *gdbarch, else { if (cond_string != nullptr) - cond_string_copy.reset (xstrdup (cond_string)); + cond_string_copy = make_unique_xstrdup (cond_string); if (extra_string != nullptr) - extra_string_copy.reset (xstrdup (extra_string)); + extra_string_copy = make_unique_xstrdup (extra_string); } /* Clear these. Updated values are now held in the *_copy locals. */ diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 7ca5e57c7f4..eca248df79e 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -152,7 +152,7 @@ struct buildsym_compunit const char *comp_dir_, enum language language_, CORE_ADDR last_addr, struct compunit_symtab *cust) : m_objfile (objfile_), - m_last_source_file (name == nullptr ? nullptr : xstrdup (name)), + m_last_source_file (name == nullptr ? nullptr : make_unique_xstrdup (name)), m_comp_dir (comp_dir_ == nullptr ? "" : comp_dir_), m_compunit_symtab (cust), m_language (language_), @@ -166,8 +166,10 @@ struct buildsym_compunit void set_last_source_file (const char *name) { - char *new_name = name == NULL ? NULL : xstrdup (name); - m_last_source_file.reset (new_name); + if (name == nullptr) + m_last_source_file = nullptr; + else + m_last_source_file = make_unique_xstrdup (name); } const char *get_last_source_file () diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c index 16559a72068..3084aa11128 100644 --- a/gdb/cli/cli-dump.c +++ b/gdb/cli/cli-dump.c @@ -62,7 +62,7 @@ scan_filename (const char **cmd, const char *defname) { if (defname == NULL) error (_("Missing filename.")); - filename.reset (xstrdup (defname)); + filename = make_unique_xstrdup (defname); } else { diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c index fdfa3b002cf..8fb952f8ee1 100644 --- a/gdb/mi/mi-cmd-env.c +++ b/gdb/mi/mi-cmd-env.c @@ -47,7 +47,7 @@ env_execute_cli_command (const char *cmd, const char *args) if (args != NULL) run = xstrprintf ("%s %s", cmd, args); else - run.reset (xstrdup (cmd)); + run = make_unique_xstrdup (cmd); execute_command ( /*ui */ run.get (), 0 /*from_tty */ ); } } diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index d26b0a4fc99..7e54286abbc 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -102,7 +102,7 @@ extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr *name, /* Duplicate the symbol name, so the caller has consistency in garbage collection. */ - name->reset (xstrdup ((*sym)->print_name ())); + *name = make_unique_xstrdup ((*sym)->print_name ()); /* If a symbol is specified attempt to determine the language from the symbol. If mode is not "auto", then the language diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c index 7f072bcee0d..ee60f08b65c 100644 --- a/gdb/python/py-function.c +++ b/gdb/python/py-function.c @@ -125,7 +125,7 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds) } } if (! docstring) - docstring.reset (xstrdup (_("This function is not documented."))); + docstring = make_unique_xstrdup (_("This function is not documented.")); add_internal_function (make_unique_xstrdup (name), std::move (docstring), fnpy_call, self_ref.release ()); diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c index caa42e5f0c0..41f958744c1 100644 --- a/gdb/python/py-lazy-string.c +++ b/gdb/python/py-lazy-string.c @@ -294,7 +294,10 @@ gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr, *addr = lazy->address; *str_elt_type = stpy_lazy_string_elt_type (lazy); *length = lazy->length; - encoding->reset (lazy->encoding ? xstrdup (lazy->encoding) : NULL); + if (lazy->encoding == nullptr) + *encoding = nullptr; + else + *encoding = make_unique_xstrdup (lazy->encoding); } /* __str__ for LazyString. */ diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c index 09cd3b9e390..f305661fa43 100644 --- a/gdb/python/py-param.c +++ b/gdb/python/py-param.c @@ -501,7 +501,7 @@ get_doc_string (PyObject *object, enum doc_string_type doc_type, || (doc_type != doc_string_description && *result == '\0')) { if (doc_type == doc_string_description) - result.reset (xstrdup (_("This command is not documented."))); + result = make_unique_xstrdup (_("This command is not documented.")); else { if (doc_type == doc_string_show) diff --git a/gdb/solib.c b/gdb/solib.c index 492ff5580c9..06330de7e91 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -174,7 +174,7 @@ solib_find_1 (const char *in_pathname, int *fd, bool is_solib) */ if (!IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname) || sysroot == NULL) - temp_pathname.reset (xstrdup (in_pathname)); + temp_pathname = make_unique_xstrdup (in_pathname); else { bool need_dir_separator; @@ -357,7 +357,7 @@ exec_file_find (const char *in_pathname, int *fd) filename. Not much more we can do...) */ if (!source_full_path_of (in_pathname, &result)) - result.reset (xstrdup (in_pathname)); + result = make_unique_xstrdup (in_pathname); if (fd != NULL) *fd = -1; } diff --git a/gdb/source.c b/gdb/source.c index 84f3fdc8a67..ade1bb2789f 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1180,7 +1180,7 @@ find_source_or_rewrite (const char *filename, const char *dirname) should report the pathname where GDB tried to find the file. */ if (dirname == nullptr || IS_ABSOLUTE_PATH (filename)) - fullname.reset (xstrdup (filename)); + fullname = make_unique_xstrdup (filename); else fullname.reset (concat (dirname, SLASH_STRING, filename, (char *) nullptr)); @@ -1222,7 +1222,7 @@ symtab_to_fullname (struct symtab *s) if (s->compunit ()->dirname () == nullptr || IS_ABSOLUTE_PATH (s->filename ())) - fullname.reset (xstrdup (s->filename ())); + fullname = make_unique_xstrdup (s->filename ()); else fullname.reset (concat (s->compunit ()->dirname (), SLASH_STRING, s->filename (), (char *) NULL)); diff --git a/gdb/stack.c b/gdb/stack.c index 9d8e9da6aa8..a0abf4cda18 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -511,7 +511,7 @@ read_frame_local (struct symbol *sym, const frame_info_ptr &frame, } catch (const gdb_exception_error &except) { - argp->error.reset (xstrdup (except.what ())); + argp->error = make_unique_xstrdup (except.what ()); } } @@ -682,7 +682,10 @@ read_frame_arg (const frame_print_options &fp_opts, argp->sym = sym; argp->val = val; - argp->error.reset (val_error ? xstrdup (val_error) : NULL); + if (val_error == nullptr) + argp->error = nullptr; + else + argp->error = make_unique_xstrdup (val_error); if (!val && !val_error) argp->entry_kind = print_entry_values_only; else if ((fp_opts.print_entry_values == print_entry_values_compact @@ -697,7 +700,10 @@ read_frame_arg (const frame_print_options &fp_opts, entryargp->sym = sym; entryargp->val = entryval; - entryargp->error.reset (entryval_error ? xstrdup (entryval_error) : NULL); + if (entryval_error == nullptr) + entryargp->error = nullptr; + else + entryargp->error = make_unique_xstrdup (entryval_error); if (!entryval && !entryval_error) entryargp->entry_kind = print_entry_values_no; else @@ -1294,7 +1300,7 @@ find_frame_funname (const frame_info_ptr &frame, enum language *funlang, /* If we didn't hit the C++ case above, set *funname here. */ if (funname == NULL) - funname.reset (xstrdup (print_name)); + funname = make_unique_xstrdup (print_name); } else { @@ -1306,7 +1312,7 @@ find_frame_funname (const frame_info_ptr &frame, enum language *funlang, bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc); if (msymbol.minsym != NULL) { - funname.reset (xstrdup (msymbol.minsym->print_name ())); + funname = make_unique_xstrdup (msymbol.minsym->print_name ()); *funlang = msymbol.minsym->language (); } } diff --git a/gdb/tracectf.c b/gdb/tracectf.c index 9fcb56bf2ff..3c6bf6cb5a9 100644 --- a/gdb/tracectf.c +++ b/gdb/tracectf.c @@ -1042,9 +1042,9 @@ ctf_read_tsv (struct uploaded_tsv **uploaded_tsvs) #FIELD)); \ \ if (strlen (p) > 0) \ - (VAR)->FIELD.reset (xstrdup (p)); \ + (VAR)->FIELD = make_unique_xstrdup (p); \ else \ - (VAR)->FIELD = NULL; \ + (VAR)->FIELD = nullptr; \ } \ while (0) -- 2.52.0