From: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
To: ofono@ofono.org
Subject: Re: [RFC patches 05/13] util.h: Add BUILD_BUG_ON() and friends for compile-time assert checking
Date: Tue, 08 Jun 2010 22:03:24 +0000 [thread overview]
Message-ID: <1276034868.2478.43.camel@localhost.localdomain> (raw)
In-Reply-To: <1275056264.4706.77.camel@aeonflux.t-mobile.de>
[-- Attachment #1: Type: text/plain, Size: 2281 bytes --]
On Fri, 2010-05-28 at 07:17 -0700, Marcel Holtmann wrote:
> Hi Inaky,
>
> > From: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
> >
> > These have been stolen from the Linux kernel source; come pretty handy
> > to make build-time consistency checks and thus avoid run-time
> > surprises.
> > ---
> > src/util.h | 29 +++++++++++++++++++++++++++++
> > 1 files changed, 29 insertions(+), 0 deletions(-)
> >
> > diff --git a/src/util.h b/src/util.h
> > index 2835b76..cf34b67 100644
> > --- a/src/util.h
> > +++ b/src/util.h
> > @@ -77,3 +77,32 @@ unsigned char *pack_7bit(const unsigned char *in, long len, int byte_offset,
> > long *items_written, unsigned char terminator);
> >
> > char *sim_string_to_utf8(const unsigned char *buffer, int length);
> > +
> > +/*
> > + * Build time consistency checks
> > + *
> > + * Stolen from the Linux kernel 2.6.35-rc; as most taken from the
> > + * Linux kernel, this is licensed GPL v2 or newer.
> > + */
> > +
> > +/* Force a compilation error if condition is true */
> > +#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
> > +
> > +/* Force a compilation error if condition is constant and true */
> > +#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
> > +
> > +/* Force a compilation error if a constant expression is not a power of 2 */
> > +#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> > + BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
> > +
> > +/* Force a compilation error if condition is true, but also produce a
> > + result (of value 0 and type size_t), so the expression can be used
> > + e.g. in a structure initializer (or where-ever else comma expressions
> > + aren't permitted). */
> > +#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
> > +#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
> > +
> > +/*
> > + * End of code stolen from the Linux kernel 2.6.35-rc. From now, code
> > + * is GPL v2 only.
> > + */
>
> sounds like a nice addition, but src/util.h is the wrong file. I prefer
> we make this compatible so that it can be applied to ConnMan and BlueZ
> as well.
>
> I think something like include/bug.h is better.
Sounds ok to me. Denis?
next prev parent reply other threads:[~2010-06-08 22:03 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-26 19:49 [RFC patches 00/13] misc cleanups and SMS ID API Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 01/13] Update .gitignore to ignore cscope databases and backup files Inaky Perez-Gonzalez
2010-05-28 14:08 ` Marcel Holtmann
2010-05-28 14:17 ` =?unknown-8bit?q?Jo=C3=A3o?= Paulo Rechi Vita
2010-05-28 14:29 ` Marcel Holtmann
2010-06-08 22:13 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 02/13] sms_send_message: add a short roadmap Inaky Perez-Gonzalez
2010-05-28 14:11 ` Marcel Holtmann
2010-06-08 22:00 ` Inaky Perez-Gonzalez
2010-05-28 14:34 ` Denis Kenzior
2010-06-08 22:37 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 03/13] documentation: add note about referencing standards Inaky Perez-Gonzalez
2010-05-28 14:13 ` Marcel Holtmann
2010-06-08 22:01 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 04/13] sms_assembly_add_fragment_backup: clarify how insertion spot is found Inaky Perez-Gonzalez
2010-05-28 14:27 ` Denis Kenzior
2010-06-08 22:10 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 05/13] util.h: Add BUILD_BUG_ON() and friends for compile-time assert checking Inaky Perez-Gonzalez
2010-05-28 14:17 ` Marcel Holtmann
2010-06-08 22:03 ` Inaky Perez-Gonzalez [this message]
2010-05-26 19:49 ` [RFC patches 06/13] smutil.h: add missing header file dependencies Inaky Perez-Gonzalez
2010-05-28 14:19 ` Marcel Holtmann
2010-06-08 22:04 ` Inaky Perez-Gonzalez
2010-05-28 14:31 ` Denis Kenzior
2010-06-08 22:30 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 07/13] write_file: make transaction-safe Inaky Perez-Gonzalez
2010-05-28 14:43 ` Denis Kenzior
2010-06-08 22:38 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 08/13] storage: add __attribute__((format)) to {write, read}_file() for printf-like variable arg verification Inaky Perez-Gonzalez
2010-05-28 14:45 ` Denis Kenzior
2010-06-08 22:43 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 09/13] Add function doc headers to ofono_sms_{create, register} Inaky Perez-Gonzalez
2010-05-28 14:47 ` Denis Kenzior
2010-06-08 22:58 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 10/13] doc: explain debugging options to -d, add a pointer in -h to manpage Inaky Perez-Gonzalez
2010-05-28 14:21 ` Marcel Holtmann
2010-06-08 22:07 ` Inaky Perez-Gonzalez
2010-06-08 23:13 ` Marcel Holtmann
2010-06-08 23:33 ` Inaky Perez-Gonzalez
2010-05-26 19:49 ` [RFC patches 11/13] automake: fix installation of udev rules in VPATH builds Inaky Perez-Gonzalez
2010-05-28 14:25 ` Marcel Holtmann
2010-05-28 14:50 ` Denis Kenzior
2010-05-26 19:49 ` [RFC patches 12/13] SMS: introduce message ID API Inaky Perez-Gonzalez
2010-05-28 14:27 ` Marcel Holtmann
2010-06-08 22:12 ` Inaky Perez-Gonzalez
2010-06-08 23:14 ` Marcel Holtmann
2010-05-26 19:49 ` [RFC patches 13/13] SMS: implement SHA256-based message IDs [incomplete] Inaky Perez-Gonzalez
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=1276034868.2478.43.camel@localhost.localdomain \
--to=inaky.perez-gonzalez@intel.com \
--cc=ofono@ofono.org \
/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