This is the mail archive of the mailing list for the elfutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 0/4] Improve elfutils diagnostics

Hi Frank,

On Fri, 2015-05-15 at 12:10 -0400, Frank Ch. Eigler wrote:
> On Thu, May 14, 2015 at 01:16:57PM +0200, Mark Wielaard wrote:
> > [...]
> > > How would such a list-of-strings be represented?  Considering that
> > > this is C, and the list arity will vary, we'd be doing dynamic
> > > allocation anyway, right?
> > 
> > Less allocation is better than more, especially if there are situations
> > where the extra allocations might not be used anyway.
> Note that a single concatenated string involves one allocated block at
> a time; an array or linked list containing structs and strings(!)
> involves many more.  It suffers in terms of copying only.

The array will most likely be preallocated already and not having to
turn each error number into a string and then concatenating it into the
file/detail string, plus any earlier such strings, is still a win.

> > [...]  So the ideal way to represent it might be an array plus
> > length of pairs typedef struct Dwfl_ErrDetail { int errno, const
> > char *detail }.  [...]
> That "char *detail;" brings its own memory allocation / lifetime
> headaches.  In fact, since the elfutils library would have to strdup
> those strings internally (since they can't be assumed to be static),
> it's really not much better than just constructing the formatted
> string in the first place.

I think it is better. The detail string will just be the file name
already constructed and allocated, so ownership is clear, it won't have
to be strduped normally. Think of it as "this is the file I tried" plus
"this is the error that happened". Both values are already constructed
and handy. No need to do any additional memory allocation, the lifetime
is just transferred to the lifetime of the Dwfl_ErrDetail.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]