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

David Levin levin at chromium.org
Thu Sep 29 12:38:00 PDT 2011


On Thu, Sep 29, 2011 at 12: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.
>
> Simon
>

Perhaps you'll find some inspiration in
http://trac.webkit.org/browser/trunk/Source/JavaScriptCore/wtf/SizeLimits.cppwhere
this is done for a few structs in wtf.

I tried to use sizeof(int*) where I needed to deal with 32 vs 64 pointer
issues and I put in an ifdef for a debug related size thing.

dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20110929/29114ade/attachment.html>


More information about the webkit-dev mailing list