Add some optional sanity check code.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19616 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-06-25 09:06:02 +00:00
parent 8cdcd4c253
commit 9a686ff388
2 changed files with 32 additions and 5 deletions

View file

@ -1,7 +1,7 @@
2004-06-25 Richard Frith-Macdonald <rfm@gnu.org> 2004-06-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSIndexSet.m: Rewrite range removal to fix bug reported * Source/NSIndexSet.m: Rewrite range removal to fix bug reported
by Fred Kiefer. by Fred Kiefer. Add optional sanity check for debugging
* Testing/nsindexset.m: Add test for deletion of range which has * Testing/nsindexset.m: Add test for deletion of range which has
partial overlap with two others. partial overlap with two others.

View file

@ -37,6 +37,30 @@
#define _array ((GSIArray)(self->_data)) #define _array ((GSIArray)(self->_data))
#define _other ((GSIArray)(aSet->_data)) #define _other ((GSIArray)(aSet->_data))
#ifdef SANITY_CHECKS
static void sanity(GSIArray array)
{
if (array != 0)
{
unsigned c = GSIArrayCount(array);
unsigned i;
unsigned last = 0;
for (i = 0; i < c; i++)
{
NSRange r = GSIArrayItemAtIndex(array, i).ext;
NSCAssert(r.location >= last, @"Overlap ranges");
NSCAssert(NSMaxRange(r) > r.location, @"Bad range length");
last = NSMaxRange(r);
}
}
}
#define SANITY() sanity(_array)
#else
#define SANITY()
#endif
/* /*
* Returns the position in the array at which the index should be inserted. * Returns the position in the array at which the index should be inserted.
* This may be the position of a range containing the index if it is already * This may be the position of a range containing the index if it is already
@ -668,6 +692,7 @@ static unsigned posForIndex(GSIArray array, unsigned index)
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos); GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos);
} }
} }
SANITY();
} }
- (id) copyWithZone: (NSZone*)aZone - (id) copyWithZone: (NSZone*)aZone
@ -742,12 +767,12 @@ static unsigned posForIndex(GSIArray array, unsigned index)
/* /*
* Range to remove is entirely within found range and * Range to remove is entirely within found range and
* overlaps the start of the found range ... shrink it * overlaps the start of the found range ... shrink it
* and trhen we are finished. * and then we are finished.
*/ */
r.location += aRange.length; r.location += aRange.length;
r.length -= aRange.length; r.length -= aRange.length;
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos); GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos);
return; pos++;
} }
} }
else else
@ -778,7 +803,7 @@ static unsigned posForIndex(GSIArray array, unsigned index)
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos); GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos);
pos++; pos++;
GSIArrayInsertItem(_array, (GSIArrayItem)next, pos); GSIArrayInsertItem(_array, (GSIArrayItem)next, pos);
return; pos++;
} }
} }
} }
@ -814,9 +839,10 @@ static unsigned posForIndex(GSIArray array, unsigned index)
/* /*
* Found range extends beyond range to remove ... finished. * Found range extends beyond range to remove ... finished.
*/ */
return; break;
} }
} }
SANITY();
} }
- (void) shiftIndexesStartingAtIndex: (unsigned int)anIndex by: (int)amount - (void) shiftIndexesStartingAtIndex: (unsigned int)anIndex by: (int)amount
@ -923,6 +949,7 @@ static unsigned posForIndex(GSIArray array, unsigned index)
} }
} }
} }
SANITY();
} }
@end @end