[webkit-dev] Compile-time assertions for object sizes

Andreas Kling kling at webkit.org
Thu Sep 29 13:40:50 PDT 2011


On Thu, Sep 29, 2011 at 9:11 PM, Simon Fraser <simon.fraser at apple.com>wrote:

>
> On Sep 29, 2011, at 11:40 AM, Andreas Kling wrote:
>
> > Dear WebKittens,
> >
> > I'd like to add some compile-time assertions for the sizes of various
> objects. The motivation comes a patch fixing bloat in InlineBox[1].
> >
> > There are two major problems with this:
> >
> > 1. The sizes will differ on 32- and 64-bit platforms.
> > 2. The sizes will differ based on compiler flags.
> >
> > One idea is to add a file that would only be built on (for example)
> 64-bit Mac and then at least that bot would break if an object changes size.
> That's obviously not ideal though.
> >
> > Any suggestions? :)
>
> You could group the bits together into a struct:
>
>  struct {
>    m_foo: 1;
>    m_bar: 1;
>    ...
>  } m_bits;
>
> COMPILE_ASSERT(sizeof(m_bits) <= sizeof(uint32_t), Too_many_bits);
>
> This wouldn't' be sensitive to architecture.
>


Good idea in general, though it doesn't work for InlineBox since its bits
are spread across public, protected and private.
I'm not sure it's worth losing those classifications for the sake of the
anti-bloat mechanism.

-Kling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20110929/919cde75/attachment.html>


More information about the webkit-dev mailing list