Bug 732607 - make nsTArray assertions fatal. r=bz
authorJesse Ruderman <jruderman@gmail.com>
Sat, 03 Mar 2012 13:16:13 -0800
changeset 88209 c51dbd19871b64531b2e24d1bbebb6fe3d35e29f
parent 88208 55e360715d7676060b99db6b3319b04c92d57521
child 88210 9fbe111ef1c3e274ff99884cbbcfc8555aa4f595
push id6739
push userjruderman@mozilla.com
push dateSat, 03 Mar 2012 21:16:22 +0000
treeherdermozilla-inbound@c51dbd19871b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs732607
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 732607 - make nsTArray assertions fatal. r=bz
xpcom/glue/nsTArray-inl.h
xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray-inl.h
+++ b/xpcom/glue/nsTArray-inl.h
@@ -177,18 +177,18 @@ nsTArray_base<Alloc>::EnsureCapacity(siz
     bytesToAlloc = minBytes - 1;
     bytesToAlloc |= bytesToAlloc >> 1;
     bytesToAlloc |= bytesToAlloc >> 2;
     bytesToAlloc |= bytesToAlloc >> 4;
     bytesToAlloc |= bytesToAlloc >> 8;
     bytesToAlloc |= bytesToAlloc >> 16;
     bytesToAlloc++;
 
-    NS_ASSERTION((bytesToAlloc & (bytesToAlloc - 1)) == 0,
-                 "nsTArray's allocation size should be a power of two!");
+    MOZ_ASSERT((bytesToAlloc & (bytesToAlloc - 1)) == 0,
+               "nsTArray's allocation size should be a power of two!");
   }
 
   Header *header;
   if (UsesAutoArrayBuffer()) {
     // Malloc() and copy
     header = static_cast<Header*>(Alloc::Malloc(bytesToAlloc));
     if (!header)
       return false;
@@ -198,17 +198,17 @@ nsTArray_base<Alloc>::EnsureCapacity(siz
     // Realloc() existing data
     header = static_cast<Header*>(Alloc::Realloc(mHdr, bytesToAlloc));
     if (!header)
       return false;
   }
 
   // How many elements can we fit in bytesToAlloc?
   PRUint32 newCapacity = (bytesToAlloc - sizeof(Header)) / elemSize;
-  NS_ASSERTION(newCapacity >= capacity, "Didn't enlarge the array enough!");
+  MOZ_ASSERT(newCapacity >= capacity, "Didn't enlarge the array enough!");
   header->mCapacity = newCapacity;
 
   mHdr = header;
 
   return true;
 }
 
 template<class Alloc>
@@ -230,17 +230,17 @@ nsTArray_base<Alloc>::ShrinkCapacity(siz
     memcpy(header + 1, mHdr + 1, length * elemSize);
 
     Alloc::Free(mHdr);
     mHdr = header;
     return;
   }
 
   if (length == 0) {
-    NS_ASSERTION(!IsAutoArray(), "autoarray should have fit 0 elements");
+    MOZ_ASSERT(!IsAutoArray(), "autoarray should have fit 0 elements");
     Alloc::Free(mHdr);
     mHdr = EmptyHdr();
     return;
   }
 
   size_type size = sizeof(Header) + length * elemSize;
   void *ptr = Alloc::Realloc(mHdr, size);
   if (!ptr)
@@ -277,17 +277,17 @@ nsTArray_base<Alloc>::ShiftData(index_ty
     memmove(base + newLen, base + oldLen, num);
   }
 }
 
 template<class Alloc>
 bool
 nsTArray_base<Alloc>::InsertSlotsAt(index_type index, size_type count,
                                     size_type elementSize, size_t elemAlign)  {
-  NS_ASSERTION(index <= Length(), "Bogus insertion index");
+  MOZ_ASSERT(index <= Length(), "Bogus insertion index");
   size_type newLen = Length() + count;
 
   EnsureCapacity(newLen, elementSize);
 
   // Check for out of memory conditions
   if (Capacity() < newLen)
     return false;
 
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -269,17 +269,17 @@ protected:
   void ShiftData(index_type start, size_type oldLen, size_type newLen,
                  size_type elemSize, size_t elemAlign);
 
   // This method increments the length member of the array's header.
   // Note that mHdr may actually be sEmptyHdr in the case where a
   // zero-length array is inserted into our array. But then n should
   // always be 0.
   void IncrementLength(PRUint32 n) {
-    NS_ASSERTION(mHdr != EmptyHdr() || n == 0, "bad data pointer");
+    MOZ_ASSERT(mHdr != EmptyHdr() || n == 0, "bad data pointer");
     mHdr->mLength += n;
   }
 
   // This method inserts blank slots into the array.
   // @param index the place to insert the new elements. This must be no
   //              greater than the current length of the array.
   // @param count the number of slots to insert
   // @param elementSize the size of an array element.
@@ -311,21 +311,21 @@ protected:
 
   // Returns true if this nsTArray is an nsAutoTArray with a built-in buffer.
   bool IsAutoArray() const {
     return mHdr->mIsAutoArray;
   }
 
   // Returns a Header for the built-in buffer of this nsAutoTArray.
   Header* GetAutoArrayBuffer(size_t elemAlign) {
-    NS_ASSERTION(IsAutoArray(), "Should be an auto array to call this");
+    MOZ_ASSERT(IsAutoArray(), "Should be an auto array to call this");
     return GetAutoArrayBufferUnsafe(elemAlign);
   }
   const Header* GetAutoArrayBuffer(size_t elemAlign) const {
-    NS_ASSERTION(IsAutoArray(), "Should be an auto array to call this");
+    MOZ_ASSERT(IsAutoArray(), "Should be an auto array to call this");
     return GetAutoArrayBufferUnsafe(elemAlign);
   }
 
   // Returns a Header for the built-in buffer of this nsAutoTArray, but doesn't
   // assert that we are an nsAutoTArray.
   Header* GetAutoArrayBufferUnsafe(size_t elemAlign) {
     return const_cast<Header*>(static_cast<const nsTArray_base<Alloc>*>(this)->
                                GetAutoArrayBufferUnsafe(elemAlign));
@@ -568,26 +568,26 @@ public:
     return reinterpret_cast<const elem_type *>(Hdr() + 1);
   }
     
   // This method provides direct access to the i'th element of the array.
   // The given index must be within the array bounds.
   // @param i  The index of an element in the array.
   // @return   A reference to the i'th element of the array.
   elem_type& ElementAt(index_type i) {
-    NS_ASSERTION(i < Length(), "invalid array index");
+    MOZ_ASSERT(i < Length(), "invalid array index");
     return Elements()[i];
   }
 
   // This method provides direct, readonly access to the i'th element of the
   // array.  The given index must be within the array bounds.
   // @param i  The index of an element in the array.
   // @return   A const reference to the i'th element of the array.
   const elem_type& ElementAt(index_type i) const {
-    NS_ASSERTION(i < Length(), "invalid array index");
+    MOZ_ASSERT(i < Length(), "invalid array index");
     return Elements()[i];
   }
 
   // This method provides direct access to the i'th element of the array in
   // a bounds safe manner. If the requested index is out of bounds the
   // provided default value is returned.
   // @param i  The index of an element in the array.
   // @param def The value to return if the index is out of bounds.
@@ -936,33 +936,33 @@ public:
     return AppendElements(1);
   }
 
   // Move all elements from another array to the end of this array without 
   // calling copy constructors or destructors.
   // @return A pointer to the newly appended elements, or null on OOM.
   template<class Item, class Allocator>
   elem_type *MoveElementsFrom(nsTArray<Item, Allocator>& array) {
-    NS_PRECONDITION(&array != this, "argument must be different array");
+    MOZ_ASSERT(&array != this, "argument must be different array");
     index_type len = Length();
     index_type otherLen = array.Length();
     if (!this->EnsureCapacity(len + otherLen, sizeof(elem_type)))
       return nsnull;
     memcpy(Elements() + len, array.Elements(), otherLen * sizeof(elem_type));
     this->IncrementLength(otherLen);      
     array.ShiftData(0, otherLen, 0, sizeof(elem_type), MOZ_ALIGNOF(elem_type));
     return Elements() + len;
   }
 
   // This method removes a range of elements from this array.
   // @param start  The starting index of the elements to remove.
   // @param count  The number of elements to remove.
   void RemoveElementsAt(index_type start, size_type count) {
-    NS_ASSERTION(count == 0 || start < Length(), "Invalid start index");
-    NS_ASSERTION(start + count <= Length(), "Invalid length");
+    MOZ_ASSERT(count == 0 || start < Length(), "Invalid start index");
+    MOZ_ASSERT(start + count <= Length(), "Invalid length");
     DestructRange(start, count);
     this->ShiftData(start, count, 0, sizeof(elem_type), MOZ_ALIGNOF(elem_type));
   }
 
   // A variation on the RemoveElementsAt method defined above.
   void RemoveElementAt(index_type index) {
     RemoveElementsAt(index, 1);
   }
@@ -1338,19 +1338,19 @@ private:
                       "can't handle alignments greater than 8, "
                       "see nsTArray_base::UsesAutoArrayBuffer()");
 
     *base_type::PtrToHdr() = reinterpret_cast<Header*>(&mAutoBuf);
     base_type::Hdr()->mLength = 0;
     base_type::Hdr()->mCapacity = N;
     base_type::Hdr()->mIsAutoArray = 1;
 
-    NS_ASSERTION(base_type::GetAutoArrayBuffer(MOZ_ALIGNOF(elem_type)) ==
-                 reinterpret_cast<Header*>(&mAutoBuf),
-                 "GetAutoArrayBuffer needs to be fixed");
+    MOZ_ASSERT(base_type::GetAutoArrayBuffer(MOZ_ALIGNOF(elem_type)) ==
+               reinterpret_cast<Header*>(&mAutoBuf),
+               "GetAutoArrayBuffer needs to be fixed");
   }
 
   // Declare mAutoBuf aligned to the maximum of the header's alignment and
   // elem_type's alignment.  We need to use a union rather than
   // MOZ_ALIGNED_DECL because GCC is picky about what goes into
   // __attribute__((aligned(foo))).
   union {
     char mAutoBuf[sizeof(nsTArrayHeader) + N * sizeof(elem_type)];