Fixes for multiple insertion of same value.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13046 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-03-08 07:11:10 +00:00
parent 8c0d705d47
commit f2c6708cf5
3 changed files with 30 additions and 2 deletions

View file

@ -6,6 +6,8 @@
* Source/Unicode.m: Added some standard string handling for iconv.
* Source/NSString.m: ([-initWithData:encoding:]) return nil on
failure to handle encoding.
* Source/NSMapTable.m: NSMapInsert() fixed to conform to spec.
* Source/NSHashTable.m: NSHashInsert() fixed to conform to spec.
Reports by Alexander Malmberg
2002-03-07 Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>

View file

@ -309,6 +309,7 @@ void
NSHashInsert(NSHashTable *table, const void *element)
{
GSIMapTable t = (GSIMapTable)table;
GSIMapNode n;
if (table == 0)
{
@ -320,7 +321,19 @@ NSHashInsert(NSHashTable *table, const void *element)
[NSException raise: NSInvalidArgumentException
format: @"Attempt to place nul in hash table"];
}
GSIMapAddKey(t, (GSIMapKey)element);
n = GSIMapNodeForKey(t, (GSIMapKey)element);
if (n == 0)
{
GSIMapAddKey(t, (GSIMapKey)element);
}
else
{
GSIMapKey tmp = n->key;
n->key = (GSIMapKey)element;
GSI_MAP_RETAIN_KEY(t, n->key);
GSI_MAP_RELEASE_KEY(t, tmp);
}
}
/**

View file

@ -367,6 +367,7 @@ void
NSMapInsert(NSMapTable *table, const void *key, const void *value)
{
GSIMapTable t = (GSIMapTable)table;
GSIMapNode n;
if (table == 0)
{
@ -378,7 +379,19 @@ NSMapInsert(NSMapTable *table, const void *key, const void *value)
[NSException raise: NSInvalidArgumentException
format: @"Attempt to place notAKeyMarker in map table"];
}
GSIMapAddPair(t, (GSIMapKey)key, (GSIMapVal)value);
n = GSIMapNodeForKey(t, (GSIMapKey)key);
if (n == 0)
{
GSIMapAddPair(t, (GSIMapKey)key, (GSIMapVal)value);
}
else
{
GSIMapVal tmp = n->value;
n->value = (GSIMapVal)value;
GSI_MAP_RETAIN_VAL(t, n->value);
GSI_MAP_RELEASE_VAL(t, tmp);
}
}
/**