Add comments to avoid confusion.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28390 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-07-11 14:02:00 +00:00
parent bcf438e21a
commit 974a65cb15
5 changed files with 84 additions and 27 deletions

View file

@ -1,3 +1,10 @@
2009-07-11 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSConcreteMapTable.m: Add some comments.
* Source/NSConcreteHashTable.m: Dito
* Headers/Additions/GNUstepBase/GSIMap.h: Make explicit that fields in
enumerator are all big enough to hold pointers.
2009-07-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSProcessInfo.m: Add daignostic check.

View file

@ -307,7 +307,7 @@ struct _GSIMapNode {
};
struct _GSIMapBucket {
size_t nodeCount; /* Number of nodes in bucket. */
uintptr_t nodeCount; /* Number of nodes in bucket. */
GSIMapNode firstNode; /* The linked list of nodes. */
};
@ -319,13 +319,13 @@ typedef GSIMapTable_t *GSIMapTable;
struct _GSIMapTable {
NSZone *zone;
size_t nodeCount; /* Number of used nodes in map. */
size_t bucketCount; /* Number of buckets in map. */
uintptr_t nodeCount; /* Number of used nodes in map. */
uintptr_t bucketCount; /* Number of buckets in map. */
GSIMapBucket buckets; /* Array of buckets. */
GSIMapNode freeNodes; /* List of unused nodes. */
size_t chunkCount; /* Number of chunks in array. */
uintptr_t chunkCount; /* Number of chunks in array. */
GSIMapNode *nodeChunks; /* Chunks of allocated memory. */
size_t increment;
uintptr_t increment;
#ifdef GSI_MAP_EXTRA
GSI_MAP_EXTRA extra;
#endif
@ -335,7 +335,7 @@ struct _GSIMapTable {
typedef struct _GSIMapEnumerator {
GSIMapTable map; /* the map being enumerated. */
GSIMapNode node; /* The next node to use. */
size_t bucket; /* The next bucket to use. */
uintptr_t bucket; /* The next bucket to use. */
} *_GSIE;
#ifdef GSI_MAP_ENUMERATOR
@ -346,7 +346,7 @@ typedef struct _GSIMapEnumerator GSIMapEnumerator_t;
typedef GSIMapEnumerator_t *GSIMapEnumerator;
static INLINE GSIMapBucket
GSIMapPickBucket(unsigned hash, GSIMapBucket buckets, size_t bucketCount)
GSIMapPickBucket(unsigned hash, GSIMapBucket buckets, uintptr_t bucketCount)
{
return buckets + hash % bucketCount;
}
@ -431,7 +431,7 @@ GSIMapFreeNode(GSIMapTable map, GSIMapNode node)
}
static INLINE GSIMapNode
GSIMapRemoveAndFreeNode(GSIMapTable map, size_t bkt, GSIMapNode node)
GSIMapRemoveAndFreeNode(GSIMapTable map, uintptr_t bkt, GSIMapNode node)
{
GSIMapNode next = node->nextInBucket;
GSIMapRemoveNodeFromMap(map, &(map->buckets[bkt]), node);
@ -441,8 +441,8 @@ GSIMapRemoveAndFreeNode(GSIMapTable map, size_t bkt, GSIMapNode node)
static INLINE void
GSIMapRemangleBuckets(GSIMapTable map,
GSIMapBucket old_buckets, size_t old_bucketCount,
GSIMapBucket new_buckets, size_t new_bucketCount)
GSIMapBucket old_buckets, uintptr_t old_bucketCount,
GSIMapBucket new_buckets, uintptr_t new_bucketCount)
{
#if GS_WITH_GC
if (GSI_MAP_ZEROED(map))
@ -494,7 +494,7 @@ static INLINE void
GSIMapMoreNodes(GSIMapTable map, unsigned required)
{
GSIMapNode *newArray;
size_t arraySize = (map->chunkCount+1)*sizeof(GSIMapNode);
uintptr_t arraySize = (map->chunkCount+1)*sizeof(GSIMapNode);
#if GS_WITH_GC
/* We don't want our nodes collected before we have finished with them,
@ -507,7 +507,7 @@ GSIMapMoreNodes(GSIMapTable map, unsigned required)
if (newArray)
{
GSIMapNode newNodes;
size_t chunkCount;
uintptr_t chunkCount;
if (map->nodeChunks != 0)
{
@ -602,8 +602,8 @@ GSIMapFirstNode(GSIMapTable map)
{
if (map->nodeCount > 0)
{
size_t count = map->bucketCount;
size_t bucket = 0;
uintptr_t count = map->bucketCount;
uintptr_t bucket = 0;
GSIMapNode node = 0;
#if GS_WITH_GC
@ -686,18 +686,18 @@ GSIMapNodeForSimpleKey(GSIMapTable map, GSIMapKey key)
#endif
static INLINE void
GSIMapResize(GSIMapTable map, size_t new_capacity)
GSIMapResize(GSIMapTable map, uintptr_t new_capacity)
{
GSIMapBucket new_buckets;
size_t size = 1;
size_t old = 1;
uintptr_t size = 1;
uintptr_t old = 1;
/*
* Find next size up in the fibonacci series
*/
while (size < new_capacity)
{
size_t tmp = old;
uintptr_t tmp = old;
old = size;
size += tmp;
@ -742,7 +742,7 @@ GSIMapResize(GSIMapTable map, size_t new_capacity)
}
static INLINE void
GSIMapRightSizeMap(GSIMapTable map, size_t capacity)
GSIMapRightSizeMap(GSIMapTable map, uintptr_t capacity)
{
/* FIXME: Now, this is a guess, based solely on my intuition. If anyone
* knows of a better ratio (or other test, for that matter) and can
@ -861,8 +861,8 @@ GSIMapEnumeratorNextNode(GSIMapEnumerator enumerator)
*/
if (node != 0 && GSI_MAP_ZEROED(map) && node->key.addr == 0)
{
size_t bucketCount = map->bucketCount;
size_t bucket = ((_GSIE)enumerator)->bucket;
uintptr_t bucketCount = map->bucketCount;
uintptr_t bucket = ((_GSIE)enumerator)->bucket;
while (node != 0 && node->key.addr == 0)
{
@ -888,7 +888,7 @@ GSIMapEnumeratorNextNode(GSIMapEnumerator enumerator)
#if GS_WITH_GC
if (GSI_MAP_ZEROED(map))
{
size_t bucket = ((_GSIE)enumerator)->bucket;
uintptr_t bucket = ((_GSIE)enumerator)->bucket;
while (next != 0 && next->key.addr == 0)
{
@ -899,8 +899,8 @@ GSIMapEnumeratorNextNode(GSIMapEnumerator enumerator)
if (next == 0)
{
size_t bucketCount = map->bucketCount;
size_t bucket = ((_GSIE)enumerator)->bucket;
uintptr_t bucketCount = map->bucketCount;
uintptr_t bucket = ((_GSIE)enumerator)->bucket;
#if GS_WITH_GC
if (GSI_MAP_ZEROED(map))
@ -1129,7 +1129,7 @@ GSIMapEmptyMap(GSIMapTable map)
}
static INLINE void
GSIMapInitWithZoneAndCapacity(GSIMapTable map, NSZone *zone, size_t capacity)
GSIMapInitWithZoneAndCapacity(GSIMapTable map, NSZone *zone, uintptr_t capacity)
{
map->zone = zone;
map->nodeCount = 0;

View file

@ -409,6 +409,14 @@ static gnutls_anon_client_credentials_t anoncred;
output: (GSSocketOutputStream*)o
{
NSString *proto = [i propertyForKey: NSStreamSocketSecurityLevelKey];
BOOL server = NO;
/* FIXME
if ([[o propertyForKey: NSStreamSocketCertificateServerKey] boolValue] == YES)
{
server = YES;
}
*/
if (GSDebugSet(@"NSStream") == YES)
{
@ -421,6 +429,7 @@ static gnutls_anon_client_credentials_t anoncred;
if ([[o propertyForKey: NSStreamSocketSecurityLevelKey] isEqual: proto] == NO)
{
NSLog(@"NSStreamSocketSecurityLevel on input stream does not match output stream");
DESTROY(self);
return nil;
}
@ -470,7 +479,15 @@ static gnutls_anon_client_credentials_t anoncred;
/* Initialise session and set default priorities foir key exchange.
*/
gnutls_init (&session, GNUTLS_CLIENT);
if (server)
{
gnutls_init (&session, GNUTLS_SERVER);
/* FIXME ... need to set up DH information and key/certificate. */
}
else
{
gnutls_init (&session, GNUTLS_CLIENT);
}
gnutls_set_default_priority (session);
if ([proto isEqualToString: NSStreamSocketSecurityLevelTLSv1] == YES)

View file

@ -341,10 +341,17 @@ NSEndHashTableEnumeration(NSHashEnumerator *enumerator)
}
if (enumerator->map != 0)
{
/* The 'map' field is non-null, so this NSHashEnumerator is actually
* a GSIMapEnumerator.
*/
GSIMapEndEnumerator((GSIMapEnumerator)enumerator);
}
else if (enumerator->node != 0)
{
/* The 'map' field is null but the 'node' field is not, so the
* NSHashEnumerator structure actually contains an NSEnumerator
* in the 'node' field.
*/
[(id)enumerator->node release];
memset(enumerator, '\0', sizeof(GSIMapEnumerator));
}
@ -612,6 +619,9 @@ NSNextHashEnumeratorItem(NSHashEnumerator *enumerator)
{
GSIMapNode n;
/* The 'map' field is non-null, so this NSHashEnumerator is actually
* a GSIMapEnumerator.
*/
n = GSIMapEnumeratorNextNode((GSIMapEnumerator)enumerator);
if (n == 0)
{
@ -624,6 +634,11 @@ NSNextHashEnumeratorItem(NSHashEnumerator *enumerator)
}
else if (enumerator->node != 0) // Got an enumerator object
{
/* The 'map' field is null but the 'node' field is not, so the
* NSHashEnumerator structure actually contains an NSEnumerator
* in the 'node' field, and the map table being enumerated in the
* 'bucket' field.
*/
return (void*)[(id)enumerator->node nextObject];
}
else

View file

@ -486,10 +486,18 @@ NSEndMapTableEnumeration(NSMapEnumerator *enumerator)
}
if (enumerator->map != 0)
{
/* The 'map' field is non-null, so this NSMapEnumerator is actually
* a GSIMapEnumerator.
*/
GSIMapEndEnumerator((GSIMapEnumerator)enumerator);
}
else if (enumerator->node != 0)
{
/* The 'map' field is null but the 'node' field is not, so the
* NSMapEnumerator structure actually contains an NSEnumerator
* in the 'node' field, and the map table being enumerated in the
* 'bucket' field.
*/
[(id)enumerator->node release];
memset(enumerator, '\0', sizeof(GSIMapEnumerator));
}
@ -838,6 +846,10 @@ NSNextMapEnumeratorPair(NSMapEnumerator *enumerator,
{
GSIMapNode n;
/* The 'map' field is non-null, so this NSMapEnumerator is actually
* a GSIMapEnumerator and we can use the GSIMap... functions to work
* with it.
*/
n = GSIMapEnumeratorNextNode((GSIMapEnumerator)enumerator);
if (n == 0)
{
@ -867,8 +879,14 @@ NSNextMapEnumeratorPair(NSMapEnumerator *enumerator,
}
else if (enumerator->node != 0)
{
id k = [(NSEnumerator*)enumerator->node nextObject];
id k;
/* The 'map' field is null but the 'node' field is not, so the
* NSMapEnumerator structure actually contains an NSEnumerator
* in the 'node' field, and the map table being enumerated in the
* 'bucket' field.
*/
k = [(NSEnumerator*)enumerator->node nextObject];
if (k == nil)
{
return NO;