cleanup fast enumeration issues

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29647 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-02-15 16:56:31 +00:00
parent 18a15f7c71
commit c31dd73a90
9 changed files with 27 additions and 136 deletions

View file

@ -54,99 +54,6 @@ extern "C" {
#if OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
@class NSMutableSet;
@class NSString;
/* ------------------------------------------------------------------------
* Macros
*/
// Following are also defined in base/Headers/Foundation/NSDebug.h
#ifdef DEBUG
#define NSDebugLLog(level, format, args...) \
do { if (GSDebugSet(level) == YES) \
NSLog(format , ## args); } while (0)
#define NSDebugLog(format, args...) \
do { if (GSDebugSet(@"dflt") == YES) \
NSLog(format , ## args); } while (0)
#define NSDebugFLLog(level, format, args...) \
do { if (GSDebugSet(level) == YES) { \
NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
NSLog(fmt , ## args); }} while (0)
#define NSDebugFLog(format, args...) \
do { if (GSDebugSet(@"dflt") == YES) { \
NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
NSLog(fmt , ## args); }} while (0)
#define NSDebugMLLog(level, format, args...) \
do { if (GSDebugSet(level) == YES) { \
NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt , ## args); }} while (0)
#define NSDebugMLog(format, args...) \
do { if (GSDebugSet(@"dflt") == YES) { \
NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt , ## args); }} while (0)
#else
#define NSDebugLLog(level, format, args...)
#define NSDebugLog(format, args...)
#define NSDebugFLLog(level, format, args...)
#define NSDebugFLog(format, args...)
#define NSDebugMLLog(level, format, args...)
#define NSDebugMLog(format, args...)
#endif /* DEBUG */
#define GSOnceFLog(format, args...) \
do { static BOOL beenHere = NO; if (beenHere == NO) {\
NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
beenHere = YES; \
NSLog(fmt , ## args); }} while (0)
#define GSOnceMLog(format, args...) \
do { static BOOL beenHere = NO; if (beenHere == NO) {\
NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \
beenHere = YES; \
NSLog(fmt , ## args); }} while (0)
#ifdef GSWARN
#define NSWarnLog(format, args...) \
do { if (GSDebugSet(@"NoWarn") == NO) { \
NSLog(format , ## args); }} while (0)
#define NSWarnFLog(format, args...) \
do { if (GSDebugSet(@"NoWarn") == NO) { \
NSString *fmt = GSDebugFunctionMsg( \
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
NSLog(fmt , ## args); }} while (0)
#define NSWarnMLog(format, args...) \
do { if (GSDebugSet(@"NoWarn") == NO) { \
NSString *fmt = GSDebugMethodMsg( \
self, _cmd, __FILE__, __LINE__, format); \
NSLog(fmt , ## args); }} while (0)
#else
#define NSWarnLog(format, args...)
#define NSWarnFLog(format, args...)
#define NSWarnMLog(format, args...)
#endif /* GSWARN */
#define GS_RANGE_CHECK(RANGE, SIZE) \
if (RANGE.location > SIZE || RANGE.length > (SIZE - RANGE.location)) \
[NSException raise: NSRangeException \
format: @"in %s, range { %u, %u } extends beyond size (%u)", \
GSNameFromSelector(_cmd), RANGE.location, RANGE.length, SIZE]
/* Taken from base/Headers/Foundation/NSString.h */
typedef enum _NSGNUstepStringEncoding
{
@ -190,29 +97,6 @@ typedef enum _NSGNUstepStringEncoding
} NSGNUstepStringEncoding;
/* Taken from base/Headers/Foundation/NSLock.h */
#define GS_INITIALIZED_LOCK(IDENT,CLASSNAME) \
(IDENT != nil ? IDENT : [CLASSNAME newLockAt: &IDENT])
/* ------------------------------------------------------------------------
* Class/Method Extensions
*/
/*
GSCategory extensions are implemented in
Source/Additions/GSCategory.m
for both gnustep-base and gnustep-baseadd.
*/
/*
GSCompatibility methods are implemented in
Source/Additions/GSCompatibility.m
for gnustep-baseadd only.
The implementations for gnustep-base reside in the
corresponding source files of -base.
*/
/* ------------------------------------------------------------------------
* Functions

View file

@ -932,7 +932,7 @@ GSIMapEnumeratorNextNode(GSIMapEnumerator enumerator)
/**
* Used to implement fast enumeration methods in classes that use GSIMap for
* their data storaae.
* their data storage.
*/
static INLINE NSUInteger
GSIMapCountByEnumeratingWithStateObjectsCount(GSIMapTable map,
@ -965,11 +965,11 @@ GSIMapCountByEnumeratingWithStateObjectsCount(GSIMapTable map,
else
{
enumerator.map = map;
enumerator.node = ((struct GSPartMapEnumerator*)&(state->extra))->node;
enumerator.bucket = ((struct GSPartMapEnumerator*)&(state->extra))->bucket;
enumerator.node = ((struct GSPartMapEnumerator*)(state->extra))->node;
enumerator.bucket = ((struct GSPartMapEnumerator*)(state->extra))->bucket;
}
/* Get the next count objects and put them in the stack buffer. */
for (i=0 ; i<count ; i++)
for (i = 0; i < count; i++)
{
GSIMapNode node = GSIMapEnumeratorNextNode(&enumerator);
if (0 != node)
@ -978,12 +978,12 @@ GSIMapCountByEnumeratingWithStateObjectsCount(GSIMapTable map,
* will only work with things that are id-sized, however, so don't
* try using it with non-object collections.
*/
stackbuf[i] = *(id*)&node->key;
stackbuf[i] = *(id*)&node->key.bool;
}
}
/* Store the important bits of the enumerator in the caller. */
((struct GSPartMapEnumerator*)&(state->extra))->node = enumerator.node;
((struct GSPartMapEnumerator*)&(state->extra))->bucket = enumerator.bucket;
((struct GSPartMapEnumerator*)(state->extra))->node = enumerator.node;
((struct GSPartMapEnumerator*)(state->extra))->bucket = enumerator.bucket;
/* Update the rest of the state. */
state->state += count;
state->itemsPtr = stackbuf;

View file

@ -121,6 +121,7 @@ typedef union {
#if defined(GSUNION_EXTRA)
GSUNION_EXTRA ext;
#endif
BOOL bool; /* Guaranteed present */
} GSUNION;
#endif

View file

@ -386,11 +386,13 @@ static GC_descr nodeDesc; // Type descriptor for map node.
_version++;
return result;
}
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
objects: (id*)stackbuf
count: (NSUInteger)len
{
state->mutationsPtr = (unsigned long *)&_version;
return GSIMapCountByEnumeratingWithStateObjectsCount(&map, state, stackbuf, len);
state->mutationsPtr = (unsigned long *)&_version;
return GSIMapCountByEnumeratingWithStateObjectsCount
(&map, state, stackbuf, len);
}
@end

View file

@ -354,14 +354,15 @@ static SEL objSel;
}
return nil;
}
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*)state
objects: (id*)stackbuf
count: (NSUInteger)len
{
state->mutationsPtr = (unsigned long *)self;
return GSIMapCountByEnumeratingWithStateObjectsCount(&map, state, stackbuf, len);
state->mutationsPtr = (unsigned long *)self;
return GSIMapCountByEnumeratingWithStateObjectsCount
(&map, state, stackbuf, len);
}
@end
@implementation GSMutableDictionary
@ -468,8 +469,9 @@ static SEL objSel;
objects: (id*)stackbuf
count: (NSUInteger)len
{
state->mutationsPtr = (unsigned long *)&_version;
return GSIMapCountByEnumeratingWithStateObjectsCount(&map, state, stackbuf, len);
state->mutationsPtr = (unsigned long *)&_version;
return GSIMapCountByEnumeratingWithStateObjectsCount
(&map, state, stackbuf, len);
}
@end

View file

@ -235,7 +235,7 @@ typedef enum {
/* Get error information.
*/
@interface NSError (GSCategories)
@interface NSError (GNUstepBase)
+ (NSError*) _last;
+ (NSError*) _systemError: (long)number;
@end

View file

@ -527,8 +527,9 @@ static Class mutableSetClass;
objects: (id*)stackbuf
count: (NSUInteger)len
{
state->mutationsPtr = (unsigned long *)self;
return GSIMapCountByEnumeratingWithStateObjectsCount(&map, state, stackbuf, len);
state->mutationsPtr = (unsigned long *)self;
return GSIMapCountByEnumeratingWithStateObjectsCount
(&map, state, stackbuf, len);
}
@end
@ -735,8 +736,9 @@ static Class mutableSetClass;
objects: (id*)stackbuf
count: (NSUInteger)len
{
state->mutationsPtr = (unsigned long *)&_version;
return GSIMapCountByEnumeratingWithStateObjectsCount(&map, state, stackbuf, len);
state->mutationsPtr = (unsigned long *)&_version;
return GSIMapCountByEnumeratingWithStateObjectsCount
(&map, state, stackbuf, len);
}
@end

View file

@ -33,6 +33,7 @@
#import "Foundation/NSStream.h"
#import "Foundation/NSTimer.h"
#import "Foundation/NSValue.h"
#import "GNUstepBase/NSObject+GNUstepBase.h"
#if defined(_REENTRANT)
#import "GNUstepBase/GSLock.h"
#endif

View file

@ -39,7 +39,6 @@
#import "Foundation/NSDebug.h"
// For private method _decodeArrayOfObjectsForKey:
#import "Foundation/NSKeyedArchiver.h"
#import "GNUstepBase/GSCategories.h"
#import "GSPrivate.h"
#import "GNUstepBase/NSObject+GNUstepBase.h"