+2020-07-02 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * macroexp.h (macro_stringify): Return
+ gdb::unique_xmalloc_ptr<char>.
+ * macroexp.c (macro_stringify): Likewise.
+ * macrotab.c (fixup_definition): Update.
+
2020-07-02 Simon Marchi <simon.marchi@polymtl.ca>
* c-exp.y (scan_macro_expansion): Don't free `expansion`.
/* See macroexp.h. */
-char *
+gdb::unique_xmalloc_ptr<char>
macro_stringify (const char *str)
{
int len = strlen (str);
stringify (&buffer, str, len);
buffer.appendc ('\0');
- return buffer.release ().release ();
+ return buffer.release ();
}
\f
int macro_is_digit (int c);
-/* Stringify STR according to C rules and return an xmalloc'd pointer
- to the result. */
-
-char *macro_stringify (const char *str);
+/* Stringify STR according to C rules and return a null-terminated string. */
+gdb::unique_xmalloc_ptr<char> macro_stringify (const char *str);
#endif /* MACROEXP_H */
static struct macro_definition *
fixup_definition (const char *filename, int line, struct macro_definition *def)
{
- static char *saved_expansion;
-
- if (saved_expansion)
- {
- xfree (saved_expansion);
- saved_expansion = NULL;
- }
+ static gdb::unique_xmalloc_ptr<char> saved_expansion;
if (def->kind == macro_object_like)
{
if (def->argc == macro_FILE)
{
saved_expansion = macro_stringify (filename);
- def->replacement = saved_expansion;
+ def->replacement = saved_expansion.get ();
}
else if (def->argc == macro_LINE)
{
- saved_expansion = xstrprintf ("%d", line);
- def->replacement = saved_expansion;
+ saved_expansion.reset (xstrprintf ("%d", line));
+ def->replacement = saved_expansion.get ();
}
}