diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2020-07-02 20:38:47 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2020-07-03 22:27:09 -0400 |
commit | 14d960c82a6094551a0c463973b676136e4e60de (patch) | |
tree | efc7275422c30ffaa44a9de146f29b4e30174968 /gdb/macroexp.c | |
parent | 211d5b1c18eb96459289e17b58e91fad46708173 (diff) | |
download | gdb-14d960c82a6094551a0c463973b676136e4e60de.zip gdb-14d960c82a6094551a0c463973b676136e4e60de.tar.gz gdb-14d960c82a6094551a0c463973b676136e4e60de.tar.bz2 |
gdb: make macro_expand_next return a gdb::unique_xmalloc_ptr<char>
For some reason, macro_expand_next does not return a
gdb::unique_xmalloc_ptr<char>, like its counterparts macro_expand and
macro_expand_once. This patch fixes that.
macro_buffer::release now returns a gdb::unique_xmalloc_ptr<char> too,
which required updating the other callers. The `.release (). release
()` in macro_stringify looks a bit funny, but it's because one release
is for the macro_buffer, and the other is for the unique ptr.
I removed the ATTRIBUTE_UNUSED_RESULT on macro_buffer::release, I don't
really understand why it's there. I don't see how this method could be
called without using the result, that would be an obvious memory leak.
The commit that introduced it (4e4a8b932b7 "Add ATTRIBUTE_UNUSED_RESULT
to macro_buffer") doesn't give any details.
gdb/ChangeLog:
* c-exp.y (scan_macro_expansion): Don't free `expansion`.
(lex_one_token): Update.
* macroexp.c (struct macro_buffer) <release>: Return
gdb::unique_xmalloc_ptr<char>.
(macro_stringify): Update.
(macro_expand): Update.
(macro_expand_next): Return gdb::unique_xmalloc_ptr<char>.
* macroexp.h (macro_expand_next): Likewise.
Change-Id: I67a74d0d479d2c20cdc82161ead7c54cea034f56
Diffstat (limited to 'gdb/macroexp.c')
-rw-r--r-- | gdb/macroexp.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/gdb/macroexp.c b/gdb/macroexp.c index 9282380..e1d185d 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -128,15 +128,14 @@ struct macro_buffer xfree (text); } - /* Release the text of the buffer to the caller, which is now - responsible for freeing it. */ - ATTRIBUTE_UNUSED_RESULT char *release () + /* Release the text of the buffer to the caller. */ + gdb::unique_xmalloc_ptr<char> release () { gdb_assert (! shared); gdb_assert (size); char *result = text; text = NULL; - return result; + return gdb::unique_xmalloc_ptr<char> (result); } /* Resize the buffer to be at least N bytes long. Raise an error if @@ -708,7 +707,7 @@ macro_stringify (const char *str) stringify (&buffer, str, len); buffer.appendc ('\0'); - return buffer.release (); + return buffer.release ().release (); } @@ -1429,7 +1428,7 @@ macro_expand (const char *source, const macro_scope &scope) dest.appendc ('\0'); - return gdb::unique_xmalloc_ptr<char> (dest.release ()); + return dest.release (); } @@ -1439,8 +1438,7 @@ macro_expand_once (const char *source, const macro_scope &scope) error (_("Expand-once not implemented yet.")); } - -char * +gdb::unique_xmalloc_ptr<char> macro_expand_next (const char **lexptr, const macro_scope &scope) { struct macro_buffer tok; @@ -1454,7 +1452,7 @@ macro_expand_next (const char **lexptr, const macro_scope &scope) /* Get the text's first preprocessing token. */ if (! get_token (&tok, &src)) - return 0; + return nullptr; /* If it's a macro invocation, expand it. */ if (maybe_expand (&dest, &tok, &src, 0, scope)) @@ -1469,6 +1467,6 @@ macro_expand_next (const char **lexptr, const macro_scope &scope) else { /* It wasn't a macro invocation. */ - return 0; + return nullptr; } } |