[PATCH] libdwfl: Move nested function in dwfl_segment_report_module.c

Mark Wielaard mark@klomp.org
Mon Jul 31 09:22:00 GMT 2017


On Fri, 2017-07-28 at 09:36 -0700, Yunlian Jiang via elfutils-devel
wrote:
> This moves part of nested functions in dwfl_segment_report_module.c to file
> scope.

Note that your email provides two variants of the patch, the first
having whitespace issues making it a bit hard to read and apply.

I am not a fan of replacing nested functions with variants that take
long argument lists, some of which aren't even used or are only used to
then pass through another function in a different order.

> +static inline bool
> +segment_read (int segndx, void **buffer, size_t *buffer_available,
> +      GElf_Addr addr, size_t minread, Dwfl *dwfl,
> +      Dwfl_Memory_Callback *memory_callback,
> +      void *memory_callback_arg)
> +{
> +  return ! (*memory_callback) (dwfl, segndx, buffer, buffer_available,
> +               addr, minread, memory_callback_arg);
> +}

For example in this case it would make more sense to just directly call
the memory_callback.

> +static inline void
> +release_buffer (void **buffer, size_t *buffer_available,
> + Dwfl *dwfl,
> + Dwfl_Memory_Callback *memory_callback,
> + void *memory_callback_arg)
> +{
> +  if (*buffer != NULL)
> +    (void) segment_read (-1, buffer, buffer_available, 0, 0, dwfl,
> +         memory_callback, memory_callback_arg);
> +}

Likewise, just include the if guard in the code directly. Especially
since this function only exists as helper function in two other helper
functions.

> +#define DO_REAL_FINISH finish(phdrsp, buffer, buffer_available, elf, fd, ndx, \
> + dwfl, memory_callback, memory_callback_arg)

I rather see this as a real functions. If the issue is passing all the
arguments (which I agree is somewhat ugly) then just put those that form
the relevant state in struct (Elf, fd, Dwfl, Dwfl_Memory_Callback,
callback_arg, buffer, buffer_available) that you pass by reference to
the new static functions.

Cheers,

Mark



More information about the Elfutils-devel mailing list