1 $NetBSD: patch-el,v 1.2 2009/02/02 09:28:56 martin Exp $
3 # Ensure correct alignment for nsCSSValue objects inside nsCSSValue::Array.
6 --- layout/style/nsCSSValue.h.orig 2008-07-02 00:51:43.000000000 +0200
7 +++ layout/style/nsCSSValue.h 2009-02-01 21:43:29.000000000 +0100
10 static nsStringBuffer* BufferFromString(const nsString& aValue);
14 - // return |Array| with reference count of zero
15 - static Array* Create(PRUint16 aItemCount) {
16 - return new (aItemCount) Array(aItemCount);
19 - nsCSSValue& operator[](PRUint16 aIndex) {
20 - NS_ASSERTION(aIndex < mCount, "out of range");
21 - return *(First() + aIndex);
24 - const nsCSSValue& operator[](PRUint16 aIndex) const {
25 - NS_ASSERTION(aIndex < mCount, "out of range");
26 - return *(First() + aIndex);
29 - nsCSSValue& Item(PRUint16 aIndex) { return (*this)[aIndex]; }
30 - const nsCSSValue& Item(PRUint16 aIndex) const { return (*this)[aIndex]; }
32 - PRUint16 Count() const { return mCount; }
34 - PRBool operator==(const Array& aOther) const
36 - if (mCount != aOther.mCount)
38 - for (PRUint16 i = 0; i < mCount; ++i)
39 - if ((*this)[i] != aOther[i])
45 - if (mRefCnt == PR_UINT16_MAX) {
46 - NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
50 - NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Array", sizeof(*this));
53 - if (mRefCnt == PR_UINT16_MAX) {
54 - NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
58 - NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Array");
68 - void* operator new(size_t aSelfSize, PRUint16 aItemCount) CPP_THROW_NEW {
69 - return ::operator new(aSelfSize + sizeof(nsCSSValue)*aItemCount);
72 - void operator delete(void* aPtr) { ::operator delete(aPtr); }
74 - nsCSSValue* First() {
75 - return (nsCSSValue*) (((char*)this) + sizeof(*this));
78 - const nsCSSValue* First() const {
79 - return (const nsCSSValue*) (((const char*)this) + sizeof(*this));
82 -#define CSSVALUE_LIST_FOR_VALUES(var) \
83 - for (nsCSSValue *var = First(), *var##_end = var + mCount; \
84 - var != var##_end; ++var)
86 - Array(PRUint16 aItemCount)
88 - , mCount(aItemCount)
90 - MOZ_COUNT_CTOR(nsCSSValue::Array);
91 - CSSVALUE_LIST_FOR_VALUES(val) {
92 - new (val) nsCSSValue();
98 - MOZ_COUNT_DTOR(nsCSSValue::Array);
99 - CSSVALUE_LIST_FOR_VALUES(val) {
100 - val->~nsCSSValue();
104 -#undef CSSVALUE_LIST_FOR_VALUES
107 - Array(const Array& aOther); // not to be implemented
112 // Methods are not inline because using an nsIPrincipal means requiring
113 // caps, which leads to REQUIRES hell, since this header is included all
114 @@ -454,5 +357,102 @@
118 -#endif /* nsCSSValue_h___ */
119 +struct nsCSSValue::Array {
121 + // return |Array| with reference count of zero
122 + static Array* Create(PRUint16 aItemCount) {
123 + return new (aItemCount) Array(aItemCount);
126 + nsCSSValue& operator[](PRUint16 aIndex) {
127 + NS_ASSERTION(aIndex < mCount, "out of range");
128 + return mArray[aIndex];
131 + const nsCSSValue& operator[](PRUint16 aIndex) const {
132 + NS_ASSERTION(aIndex < mCount, "out of range");
133 + return mArray[aIndex];
136 + nsCSSValue& Item(PRUint16 aIndex) { return (*this)[aIndex]; }
137 + const nsCSSValue& Item(PRUint16 aIndex) const { return (*this)[aIndex]; }
139 + PRUint16 Count() const { return mCount; }
141 + PRBool operator==(const Array& aOther) const
143 + if (mCount != aOther.mCount)
145 + for (PRUint16 i = 0; i < mCount; ++i)
146 + if ((*this)[i] != aOther[i])
152 + if (mRefCnt == PR_UINT16_MAX) {
153 + NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
157 + NS_LOG_ADDREF(this, mRefCnt, "nsCSSValue::Array", sizeof(*this));
160 + if (mRefCnt == PR_UINT16_MAX) {
161 + NS_WARNING("refcount overflow, leaking nsCSSValue::Array");
165 + NS_LOG_RELEASE(this, mRefCnt, "nsCSSValue::Array");
173 + const PRUint16 mCount;
174 + // This must be the last sub-object, since we extend this array to
175 + // be of size mCount; it needs to be a sub-object so it gets proper
177 + nsCSSValue mArray[1];
179 + void* operator new(size_t aSelfSize, PRUint16 aItemCount) CPP_THROW_NEW {
180 + return ::operator new(aSelfSize + sizeof(nsCSSValue) * (aItemCount - 1));
183 + void operator delete(void* aPtr) { ::operator delete(aPtr); }
185 + nsCSSValue* First() { return mArray; }
187 + const nsCSSValue* First() const { return mArray; }
189 +#define CSSVALUE_LIST_FOR_EXTRA_VALUES(var) \
190 +for (nsCSSValue *var = First() + 1, *var##_end = First() + mCount; \
191 + var != var##_end; ++var)
193 + Array(PRUint16 aItemCount)
195 + , mCount(aItemCount)
197 + MOZ_COUNT_CTOR(nsCSSValue::Array);
198 + CSSVALUE_LIST_FOR_EXTRA_VALUES(val) {
199 + new (val) nsCSSValue();
205 + MOZ_COUNT_DTOR(nsCSSValue::Array);
206 + CSSVALUE_LIST_FOR_EXTRA_VALUES(val) {
207 + val->~nsCSSValue();
211 +#undef CSSVALUE_LIST_FOR_VALUES
214 + Array(const Array& aOther); // not to be implemented
217 +#endif /* nsCSSValue_h___ */