diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2020-07-02 20:38:53 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2020-07-03 22:27:09 -0400 |
commit | a36158ec0c5145bc3988d9513081a2819353b179 (patch) | |
tree | 96be65e9fb7d4a78c8154ed74d2efc7820265db2 /gdb | |
parent | 14d960c82a6094551a0c463973b676136e4e60de (diff) | |
download | gdb-a36158ec0c5145bc3988d9513081a2819353b179.zip gdb-a36158ec0c5145bc3988d9513081a2819353b179.tar.gz gdb-a36158ec0c5145bc3988d9513081a2819353b179.tar.bz2 |
gdb: make macro_stringify return a gdb::unique_xmalloc_ptr<char>
The change to macro_stringify is straightforward. This allows removing
the manual memory management in fixup_definition.
gdb/ChangeLog:
* macroexp.h (macro_stringify): Return
gdb::unique_xmalloc_ptr<char>.
* macroexp.c (macro_stringify): Likewise.
* macrotab.c (fixup_definition): Update.
Change-Id: Id7db8988bdbd569dd51c4f4655b00eb26db277cb
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/macroexp.c | 4 | ||||
-rw-r--r-- | gdb/macroexp.h | 6 | ||||
-rw-r--r-- | gdb/macrotab.c | 14 |
4 files changed, 15 insertions, 16 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3cede90..8178e16 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 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`. (lex_one_token): Update. * macroexp.c (struct macro_buffer) <release>: Return diff --git a/gdb/macroexp.c b/gdb/macroexp.c index e1d185d..5f749ff 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -698,7 +698,7 @@ stringify (struct macro_buffer *dest, const char *arg, int len) /* See macroexp.h. */ -char * +gdb::unique_xmalloc_ptr<char> macro_stringify (const char *str) { int len = strlen (str); @@ -707,7 +707,7 @@ macro_stringify (const char *str) stringify (&buffer, str, len); buffer.appendc ('\0'); - return buffer.release ().release (); + return buffer.release (); } diff --git a/gdb/macroexp.h b/gdb/macroexp.h index 511991c..2e29d02 100644 --- a/gdb/macroexp.h +++ b/gdb/macroexp.h @@ -78,9 +78,7 @@ int macro_is_identifier_nondigit (int c); 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 */ diff --git a/gdb/macrotab.c b/gdb/macrotab.c index 63cd301..9ada436 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -882,25 +882,19 @@ macro_undef (struct macro_source_file *source, int line, 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 (); } } |