Use new/delete instead of malloc/free-based functions
[deliverable/binutils-gdb.git] / gdb / symtab.h
index 9b1dbb449eda497b2d43cd056f0be72aea33a344..a6bf65598c4d501860e9c08a24442a177274e774 100644 (file)
@@ -1637,8 +1637,43 @@ void iterate_over_symbols (const struct block *block, const char *name,
                           symbol_found_callback_ftype *callback,
                           void *data);
 
-struct cleanup *demangle_for_lookup (const char *name, enum language lang,
-                                    const char **result_name);
+/* Storage type used by demangle_for_lookup.  demangle_for_lookup
+   either returns a const char * pointer that points to either of the
+   fields of this type, or a pointer to the input NAME.  This is done
+   this way because the underlying functions that demangle_for_lookup
+   calls either return a std::string (e.g., cp_canonicalize_string) or
+   a malloc'ed buffer (libiberty's demangled), and we want to avoid
+   unnecessary reallocation/string copying.  */
+class demangle_result_storage
+{
+public:
+
+  /* Swap the std::string storage with STR, and return a pointer to
+     the beginning of the new string.  */
+  const char *swap_string (std::string &str)
+  {
+    std::swap (m_string, str);
+    return m_string.c_str ();
+  }
+
+  /* Set the malloc storage to now point at PTR.  Any previous malloc
+     storage is released.  */
+  const char *set_malloc_ptr (char *ptr)
+  {
+    m_malloc.reset (ptr);
+    return ptr;
+  }
+
+private:
+
+  /* The storage.  */
+  std::string m_string;
+  gdb::unique_xmalloc_ptr<char> m_malloc;
+};
+
+const char *
+  demangle_for_lookup (const char *name, enum language lang,
+                      demangle_result_storage &storage);
 
 struct symbol *allocate_symbol (struct objfile *);
 
This page took 0.038524 seconds and 4 git commands to generate.