From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5108 invoked by alias); 31 Jul 2017 09:22:11 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 5078 invoked by uid 89); 31 Jul 2017 09:22:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=Hx-languages-length:1927 X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 31 Jul 2017 09:22:07 +0000 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 83422302BB02; Mon, 31 Jul 2017 11:22:05 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 728A8413CE20; Mon, 31 Jul 2017 11:22:05 +0200 (CEST) Message-ID: <1501492925.3741.59.camel@klomp.org> Subject: Re: [PATCH] libdwfl: Move nested function in dwfl_segment_report_module.c From: Mark Wielaard To: Yunlian Jiang Cc: elfutils-devel@sourceware.org Date: Mon, 31 Jul 2017 09:22:00 -0000 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Evolution 3.12.11 (3.12.11-22.el7) Mime-Version: 1.0 X-IsSubscribed: yes X-SW-Source: 2017-q3/txt/msg00062.txt.bz2 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 fi= le > 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 !=3D 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