From: Steven Price <steven.price@arm.com>
To: Andrew Murray <andrew.murray@arm.com>,
Masahiro Yamada <yamada.masahiro@socionext.com>,
Arnd Bergmann <arnd@arndb.de>, Kees Cook <keescook@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
rjw@rjwysocki.net, linux-kernel@vger.kernel.org,
Will Deacon <will.deacon@arm.com>,
Grant Likely <Grant.Likely@arm.com>,
Dave P Martin <Dave.Martin@arm.com>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/3] kconfig.h: abstract empty functions with STUB_UNLESS macro
Date: Fri, 18 Jan 2019 16:27:35 +0000 [thread overview]
Message-ID: <830dafb3-7e93-e655-464f-8cb821de8dd5@arm.com> (raw)
In-Reply-To: <1547827230-55132-2-git-send-email-andrew.murray@arm.com>
On 18/01/2019 16:00, Andrew Murray wrote:
> A common pattern found in header files is a function declaration dependent
> on a CONFIG_ option being enabled, followed by an empty function for when
> that option isn't enabled. This can often take up a lot of space and impact
> code readability.
>
> Let's introduce the following STUB_UNLESS macro:
>
> STUB_UNLESS(CONFIG_FOO, [body], prototype)
>
> This evaluates to 'prototype' prepended with 'extern' if CONFIG_FOO is set
> to 'y'. Otherwise it will evaluate to 'prototype' prepended with 'static
> inline' followed by an empty function body. Where optional argument 'body'
> then 'body' will be used as the function body, intended to allow for simple
> return statements.
>
> Signed-off-by: Andrew Murray <andrew.murray@arm.com>
Seems like it should remove a lot of boilerplate code, so looks good to me.
Reviewed-by: Steven Price <steven.price@arm.com>
> ---
> include/linux/kconfig.h | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
> index cc8fa10..216a27f 100644
> --- a/include/linux/kconfig.h
> +++ b/include/linux/kconfig.h
> @@ -12,6 +12,7 @@
>
> #define __ARG_PLACEHOLDER_1 0,
> #define __take_second_arg(__ignored, val, ...) val
> +#define __take_fourth_arg(__ignored, __ignored2, __ignored3, val, ...) val
>
> /*
> * The use of "&&" / "||" is limited in certain expressions.
> @@ -70,4 +71,34 @@
> */
> #define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
>
> +
> +
> +/*
> + * Allow for __stub to be overloaded by making the second argument optional
> + */
> +#define __stub_overload(...) __take_fourth_arg(__VA_ARGS__, \
> + __stub_body, __stub_void)(__VA_ARGS__)
> +#define __stub_body(option, body, ptype) __stub(option, body, ptype)
> +#define __stub_void(option, ptype) __stub(option, , ptype)
> +
> +/*
> + * Using the same trick as __defined we use the config option to conditionally
> + * expand to an extern function declaration or a static stub function.
> + */
> +#define __stub(option, body, ptype) ___stub( \
> + __ARG_PLACEHOLDER_##option, body, ptype)
> +#define ___stub(arg1_or_junk, body, ptype) __take_second_arg( \
> + arg1_or_junk __extern_ptype(ptype), __static_ptype(body, ptype))
> +#define __static_ptype(body, ptype) static inline ptype { body; }
> +#define __extern_ptype(ptype) extern ptype
> +
> +/*
> + * STUB_UNLESS(CONFIG_FOO, [body], prototype) evaluates to 'prototype' prepended
> + * with 'extern' if CONFIG_FOO is set to 'y'. Otherwise it will evaluate to
> + * 'prototype' prepended with 'static inline' followed by an empty function
> + * body. Where optional argument 'body' is present then 'body' will be used
> + * as the function body, intended to allow for simple return statements.
> + */
> +#define STUB_UNLESS(...) __stub_overload(__VA_ARGS__)
> +
> #endif /* __LINUX_KCONFIG_H */
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-01-18 16:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-18 16:00 [Linux-eng] [RFC 0/3] Abstract empty functions with STUB_UNLESS macro Andrew Murray
2019-01-18 16:00 ` [PATCH 1/3] kconfig.h: abstract " Andrew Murray
2019-01-18 16:27 ` Steven Price [this message]
2019-01-18 16:00 ` [PATCH 2/3] cpufreq: update headers to use " Andrew Murray
2019-01-18 16:29 ` Steven Price
2019-01-18 16:00 ` [PATCH 3/3] arm64: " Andrew Murray
2019-01-18 16:46 ` Steven Price
2019-01-18 16:37 ` [Linux-eng] [RFC 0/3] Abstract empty functions with " Russell King - ARM Linux admin
2019-01-18 16:44 ` Dave Martin
2019-01-18 17:01 ` Andrew Murray
2019-01-19 3:44 ` Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=830dafb3-7e93-e655-464f-8cb821de8dd5@arm.com \
--to=steven.price@arm.com \
--cc=Dave.Martin@arm.com \
--cc=Grant.Likely@arm.com \
--cc=akpm@linux-foundation.org \
--cc=andrew.murray@arm.com \
--cc=arnd@arndb.de \
--cc=catalin.marinas@arm.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--cc=will.deacon@arm.com \
--cc=yamada.masahiro@socionext.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).