mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
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:
parent
97b8ebd06a
commit
d586b6f549
2 changed files with 32 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
2004-06-25 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* 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
|
||||
partial overlap with two others.
|
||||
|
||||
|
|
|
@ -37,6 +37,30 @@
|
|||
#define _array ((GSIArray)(self->_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.
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
SANITY();
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)aZone
|
||||
|
@ -742,12 +767,12 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
|||
/*
|
||||
* Range to remove is entirely within found range and
|
||||
* overlaps the start of the found range ... shrink it
|
||||
* and trhen we are finished.
|
||||
* and then we are finished.
|
||||
*/
|
||||
r.location += aRange.length;
|
||||
r.length -= aRange.length;
|
||||
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos);
|
||||
return;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -778,7 +803,7 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
|||
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, pos);
|
||||
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.
|
||||
*/
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SANITY();
|
||||
}
|
||||
|
||||
- (void) shiftIndexesStartingAtIndex: (unsigned int)anIndex by: (int)amount
|
||||
|
@ -923,6 +949,7 @@ static unsigned posForIndex(GSIArray array, unsigned index)
|
|||
}
|
||||
}
|
||||
}
|
||||
SANITY();
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue