RESOLVED FIXED 75635
Add a compile-time assertion for the size of CSSValue
https://bugs.webkit.org/show_bug.cgi?id=75635
Summary Add a compile-time assertion for the size of CSSValue
Tony Chang
Reported 2012-01-05 11:19:43 PST
From CSSValue.h: protected: // The bits in this section are only used by specific subclasses but kept here // to maximize struct packing. // CSSPrimitiveValue bits: unsigned char m_primitiveUnitType : 7; // CSSPrimitiveValue::UnitTypes mutable bool m_hasCachedCSSText : 1; bool m_isQuirkValue : 1; // CSSInitialValue bits: bool m_isImplicitInitialValue : 1; // CSSValueList bits: bool m_isSpaceSeparatedValueList : 1; private: unsigned char m_classType : ClassTypeBits; // ClassType ClassTypeBits is 5 bits. Swapping between bools and unsigned chars is bad for MSVC.
Attachments
Tightens the assertion (2.67 KB, patch)
2012-01-05 15:50 PST, Ryosuke Niwa
no flags
Ryosuke Niwa
Comment 1 2012-01-05 14:50:40 PST
It turned out that Visual Studio can pack them nicely as is because the only other POD type used here is unsigned char, which has the same size as bool inside bitfields on Visual Studio.
Ryosuke Niwa
Comment 2 2012-01-05 15:14:17 PST
It appears that http://trac.webkit.org/changeset/101119/trunk/Source/WebCore/css/CSSValue.cpp added a compile-time assertion to make sure CSSValue is less than 4 bytes but this isn't tight enough on some platforms where it can fit in 2 bytes.
Luke Macpherson
Comment 3 2012-01-05 15:27:48 PST
Don't forget that CSSValue extends RefCounted<CSSValue>, so best case is 6 bytes for CSSValue, and on some platforms it is 8 bytes due to alignment.
Ryosuke Niwa
Comment 4 2012-01-05 15:50:37 PST
Created attachment 121355 [details] Tightens the assertion
Tony Chang
Comment 5 2012-01-05 15:55:33 PST
Comment on attachment 121355 [details] Tightens the assertion View in context: https://bugs.webkit.org/attachment.cgi?id=121355&action=review > Source/WebCore/WebCore.xcodeproj/project.pbxproj:26946 > - 07A6D1EB1491137700051D0C /* MediaFragmentURIParser.cpp in Sources */, > + 07A6D1EB1491137700051D0C /* MediaFragmentURIParser.cpp in Sources */, Not sure if you meant to include this in the change, but it seems harmless (I would probably commit it in a separate change w/o review).
Ryosuke Niwa
Comment 6 2012-01-05 16:22:07 PST
Note You need to log in before you can comment on or make changes to this bug.