]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use make_unique_xstrdup in more places
authorTom Tromey <tromey@adacore.com>
Thu, 15 Jan 2026 15:27:58 +0000 (08:27 -0700)
committerTom Tromey <tromey@adacore.com>
Fri, 16 Jan 2026 14:44:32 +0000 (07:44 -0700)
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.

Approved-By: Andrew Burgess <aburgess@redhat.com>
12 files changed:
gdb/breakpoint.c
gdb/buildsym.h
gdb/cli/cli-dump.c
gdb/mi/mi-cmd-env.c
gdb/python/py-framefilter.c
gdb/python/py-function.c
gdb/python/py-lazy-string.c
gdb/python/py-param.c
gdb/solib.c
gdb/source.c
gdb/stack.c
gdb/tracectf.c

index af4de248ab60b82acab18fa53064393f46bdb0b4..a4ccad32a8b90346d5c5f9ce5933c5361880b11c 100644 (file)
@@ -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.  */
index 7ca5e57c7f4a0b841a7a34fe60b70249b3377e15..eca248df79e845ca95cdb982a167307db1421f69 100644 (file)
@@ -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 ()
index 16559a72068e0dd2d87111d94601bbdabffb2fba..3084aa111288b21c513b61624e7b5b8ff4e8694b 100644 (file)
@@ -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
     {
index fdfa3b002cfa9f6b6df520fd4d518284fac61abd..8fb952f8ee19e8be25024e58dcd4d16b4615584d 100644 (file)
@@ -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 */ );
     }
 }
index d26b0a4fc9924b90d0e81760032fbd69e0f2824e..7e54286abbc98cdeff574b18c3d69da602a16477 100644 (file)
@@ -102,7 +102,7 @@ extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr<char> *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
index 7f072bcee0d2878bb6d2378f5a2899a7786ffca3..ee60f08b65ce9e5ba25cc256ce593d3136ea5fc4 100644 (file)
@@ -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 ());
index caa42e5f0c05ec68ec5fe98b04167ccb1cd6b7d4..41f958744c1d5e13b0d389cf34591f4d895ed4eb 100644 (file)
@@ -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.  */
index 09cd3b9e3909cd9811d5e198a03359d120b49538..f305661fa4318fcf027fa40fcbb5f7b041325d3c 100644 (file)
@@ -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)
index 492ff5580c924b3e7cda91914d300ee4b73749a4..06330de7e91eb295d256539150bab49edf25c2cc 100644 (file)
@@ -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;
     }
index 84f3fdc8a67aa0bf5426abfef5daadd8e7e1204f..ade1bb2789f953aa4305851f4fface47f06de4fc 100644 (file)
@@ -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));
index 9d8e9da6aa89377d8d2e1b1a39939304385cf617..a0abf4cda186a4ae82b080b43b38d899b885cc82 100644 (file)
@@ -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 ();
        }
     }
index 9fcb56bf2ff9ab1b869e6361fd5643c831284e85..3c6bf6cb5a98686b5277e96803a9a1b9b5beb1cb 100644 (file)
@@ -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)