On 29-11-18 19:17, Ian Lance Taylor wrote:
> On Thu, Nov 29, 2018 at 4:33 AM, Tom de Vries <tdevr...@suse.de> wrote:
>> On 29-11-18 00:26, Ian Lance Taylor wrote:
>>> On Wed, Nov 28, 2018 at 3:15 PM, Tom de Vries <tdevr...@suse.de> wrote:
>>>>
>>>> this patch factors out new function backtrace_vector_free.
>>>>
>>>> Bootstrapped and reg-tested on x86_64.
>>>>
>>>> OK for trunk?
>>>
>>> We should only add new files if we really absolutely must, as this
>>> package is copied around to a lot of places (e.g.,
>>> libsanitizer/libbacktrace) and adding files here requires
>>> modifications in all those places.
>>>
>>
>> I see, thanks for the explanation.
>>
>> How about his patch? It does not add a file, though it does add an
>> external function which requires a rename in libsanitizer/libbacktrace
>> (I don't know whether that requires changes in any other places).
>>
>> [ Also, it inlines backtrace-vector.c into alloc.c and mmap.c, so it
>> duplicates code. If that is not acceptable, I could move it to
>> internal.h as static inline or static ATTRIBUTE_UNUSED. ]
> 
> Yes, let's just use a static inline function or a macro.  Thanks.

Committed as static inline.

Thanks,
- Tom
[libbacktrace] Factor out backtrace_vector_free

Factor out new function backtrace_vector_free.

Bootstrapped and reg-tested on x86_64.

2018-11-28  Tom de Vries  <tdevr...@suse.de>

	* internal.h (backtrace_vector_free): New static inline fuction,
	factored out of ...
	* dwarf.c (read_line_info): ... here.

---
 libbacktrace/dwarf.c    |  4 +---
 libbacktrace/internal.h | 12 ++++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c
index 34543747c8f..48ef3638a5f 100644
--- a/libbacktrace/dwarf.c
+++ b/libbacktrace/dwarf.c
@@ -2057,9 +2057,7 @@ read_line_info (struct backtrace_state *state, struct dwarf_data *ddata,
   return 1;
 
  fail:
-  vec.vec.alc += vec.vec.size;
-  vec.vec.size = 0;
-  backtrace_vector_release (state, &vec.vec, error_callback, data);
+  backtrace_vector_free (state, &vec.vec, error_callback, data);
   free_line_header (state, hdr, error_callback, data);
   *lines = (struct line *) (uintptr_t) -1;
   *lines_count = 0;
diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h
index bff8ed470e4..548f9d70905 100644
--- a/libbacktrace/internal.h
+++ b/libbacktrace/internal.h
@@ -257,6 +257,18 @@ extern int backtrace_vector_release (struct backtrace_state *state,
 				     backtrace_error_callback error_callback,
 				     void *data);
 
+/* Free the space managed by VEC.  This will reset VEC.  */
+
+static inline void
+backtrace_vector_free (struct backtrace_state *state,
+		       struct backtrace_vector *vec,
+		       backtrace_error_callback error_callback, void *data)
+{
+  vec->alc += vec->size;
+  vec->size = 0;
+  backtrace_vector_release (state, vec, error_callback, data);
+}
+
 /* Read initial debug data from a descriptor, and set the
    fileline_data, syminfo_fn, and syminfo_data fields of STATE.
    Return the fileln_fn field in *FILELN_FN--this is done this way so

Reply via email to