mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Various updates
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38599 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9958374c34
commit
4bce4d2978
5 changed files with 291 additions and 123 deletions
|
@ -1,3 +1,11 @@
|
|||
2015-06-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSArray.m: Use NSUInteger rather than unsigned, use memory
|
||||
management macros.
|
||||
* Source/NSConnection.m: Changes to avoid compiler warnings.
|
||||
* Headers/Foundation/NSData.h:
|
||||
* Source/NSData.m: add base64 initialisation methods (bug #45240)
|
||||
|
||||
2015-06-01 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* Headers/Foundation/NSArray.h
|
||||
|
|
|
@ -39,6 +39,21 @@ extern "C" {
|
|||
@class NSURL;
|
||||
#endif
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9,GS_API_LATEST)
|
||||
enum {
|
||||
NSDataBase64DecodingIgnoreUnknownCharacters = (1UL << 0)
|
||||
};
|
||||
typedef NSUInteger NSDataBase64DecodingOptions;
|
||||
|
||||
enum {
|
||||
NSDataBase64Encoding64CharacterLineLength = (1UL << 0),
|
||||
NSDataBase64Encoding76CharacterLineLength = (1UL << 1),
|
||||
NSDataBase64EncodingEndLineWithCarriageReturn = (1UL << 4),
|
||||
NSDataBase64EncodingEndLineWithLineFeed = (1UL << 5),
|
||||
};
|
||||
typedef NSUInteger NSDataBase64EncodingOptions;
|
||||
#endif
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4,GS_API_LATEST)
|
||||
enum {
|
||||
NSMappedRead = 1,
|
||||
|
@ -73,6 +88,12 @@ enum {
|
|||
+ (id) dataWithContentsOfURL: (NSURL*)url;
|
||||
#endif
|
||||
+ (id) dataWithData: (NSData*)data;
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9,GS_API_LATEST)
|
||||
- (id) initWithBase64EncodedData: (NSData*)base64Data
|
||||
options: (NSDataBase64DecodingOptions)options;
|
||||
- (id) initWithBase64EncodedString: (NSString*)base64String
|
||||
options: (NSDataBase64DecodingOptions)options;
|
||||
#endif
|
||||
- (id) initWithBytes: (const void*)aBuffer
|
||||
length: (NSUInteger)bufferSize;
|
||||
- (id) initWithBytesNoCopy: (void*)aBuffer
|
||||
|
|
206
Source/NSArray.m
206
Source/NSArray.m
|
@ -66,9 +66,9 @@ extern void GSPropertyListMake(id,NSDictionary*,BOOL,BOOL,unsigned,id*);
|
|||
@interface NSArrayEnumerator : NSEnumerator
|
||||
{
|
||||
NSArray *array;
|
||||
unsigned pos;
|
||||
NSUInteger pos;
|
||||
IMP get;
|
||||
unsigned (*cnt)(NSArray*, SEL);
|
||||
NSUInteger (*cnt)(NSArray*, SEL);
|
||||
}
|
||||
- (id) initWithArray: (NSArray*)anArray;
|
||||
@end
|
||||
|
@ -285,7 +285,7 @@ static SEL rlSel;
|
|||
- (NSArray*) arrayByAddingObject: (id)anObject
|
||||
{
|
||||
id na;
|
||||
unsigned c = [self count];
|
||||
NSUInteger c = [self count];
|
||||
|
||||
if (anObject == nil)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
|
@ -316,9 +316,9 @@ static SEL rlSel;
|
|||
- (NSArray*) arrayByAddingObjectsFromArray: (NSArray*)anotherArray
|
||||
{
|
||||
id na;
|
||||
unsigned c;
|
||||
unsigned l;
|
||||
unsigned e;
|
||||
NSUInteger c;
|
||||
NSUInteger l;
|
||||
NSUInteger e;
|
||||
|
||||
c = [self count];
|
||||
l = [anotherArray count];
|
||||
|
@ -330,8 +330,8 @@ static SEL rlSel;
|
|||
[self getObjects: objects];
|
||||
if ([anotherArray isProxy])
|
||||
{
|
||||
unsigned i = c;
|
||||
unsigned j = 0;
|
||||
NSUInteger i = c;
|
||||
NSUInteger j = 0;
|
||||
|
||||
while (i < e)
|
||||
{
|
||||
|
@ -435,7 +435,7 @@ static SEL rlSel;
|
|||
*/
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
unsigned count = [self count];
|
||||
NSUInteger count = [self count];
|
||||
|
||||
if ([aCoder allowsKeyedCoding])
|
||||
{
|
||||
|
@ -449,7 +449,7 @@ static SEL rlSel;
|
|||
}
|
||||
else
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
|
@ -463,9 +463,10 @@ static SEL rlSel;
|
|||
}
|
||||
else
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(unsigned)
|
||||
at: &count];
|
||||
unsigned items = (unsigned)count;
|
||||
|
||||
[aCoder encodeValueOfObjCType: @encode(unsigned)
|
||||
at: &items];
|
||||
if (count > 0)
|
||||
{
|
||||
GS_BEGINIDBUF(a, count);
|
||||
|
@ -485,7 +486,7 @@ static SEL rlSel;
|
|||
*/
|
||||
- (void) getObjects: (__unsafe_unretained id[])aBuffer
|
||||
{
|
||||
unsigned i, c = [self count];
|
||||
NSUInteger i, c = [self count];
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
|
@ -498,7 +499,7 @@ static SEL rlSel;
|
|||
*/
|
||||
- (void) getObjects: (__unsafe_unretained id[])aBuffer range: (NSRange)aRange
|
||||
{
|
||||
unsigned i, j = 0, c = [self count], e = aRange.location + aRange.length;
|
||||
NSUInteger i, j = 0, c = [self count], e = aRange.location + aRange.length;
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
|
||||
GS_RANGE_CHECK(aRange, c);
|
||||
|
@ -521,12 +522,12 @@ static SEL rlSel;
|
|||
*/
|
||||
- (NSUInteger) indexOfObjectIdenticalTo: (id)anObject
|
||||
{
|
||||
unsigned c = [self count];
|
||||
NSUInteger c = [self count];
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
if (anObject == (*get)(self, oaiSel, i))
|
||||
|
@ -541,7 +542,7 @@ static SEL rlSel;
|
|||
*/
|
||||
- (NSUInteger) indexOfObjectIdenticalTo: anObject inRange: (NSRange)aRange
|
||||
{
|
||||
unsigned i, e = aRange.location + aRange.length, c = [self count];
|
||||
NSUInteger i, e = aRange.location + aRange.length, c = [self count];
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
|
||||
GS_RANGE_CHECK(aRange, c);
|
||||
|
@ -559,11 +560,11 @@ static SEL rlSel;
|
|||
*/
|
||||
- (NSUInteger) indexOfObject: (id)anObject
|
||||
{
|
||||
unsigned c = [self count];
|
||||
NSUInteger c = [self count];
|
||||
|
||||
if (c > 0 && anObject != nil)
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
BOOL (*eq)(id, SEL, id)
|
||||
= (BOOL (*)(id, SEL, id))[anObject methodForSelector: eqSel];
|
||||
|
@ -582,7 +583,7 @@ static SEL rlSel;
|
|||
*/
|
||||
- (NSUInteger) indexOfObject: (id)anObject inRange: (NSRange)aRange
|
||||
{
|
||||
unsigned i, e = aRange.location + aRange.length, c = [self count];
|
||||
NSUInteger i, e = aRange.location + aRange.length, c = [self count];
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
BOOL (*eq)(id, SEL, id)
|
||||
= (BOOL (*)(id, SEL, id))[anObject methodForSelector: eqSel];
|
||||
|
@ -636,12 +637,12 @@ static SEL rlSel;
|
|||
*/
|
||||
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy
|
||||
{
|
||||
unsigned c = [array count];
|
||||
NSUInteger c = [array count];
|
||||
GS_BEGINIDBUF(objects, c);
|
||||
|
||||
if ([array isProxy])
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
|
@ -654,7 +655,7 @@ static SEL rlSel;
|
|||
}
|
||||
if (shouldCopy == YES)
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
|
@ -683,12 +684,12 @@ static SEL rlSel;
|
|||
*/
|
||||
- (id) initWithArray: (NSArray*)array
|
||||
{
|
||||
unsigned c = [array count];
|
||||
NSUInteger c = [array count];
|
||||
GS_BEGINIDBUF(objects, c);
|
||||
|
||||
if ([array isProxy])
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
|
@ -718,7 +719,7 @@ static SEL rlSel;
|
|||
@"NS.objects"];
|
||||
if (array == nil)
|
||||
{
|
||||
unsigned i = 0;
|
||||
NSUInteger i = 0;
|
||||
NSString *key;
|
||||
id val;
|
||||
|
||||
|
@ -739,22 +740,22 @@ static SEL rlSel;
|
|||
}
|
||||
else
|
||||
{
|
||||
unsigned count;
|
||||
unsigned items;
|
||||
|
||||
[aCoder decodeValueOfObjCType: @encode(unsigned)
|
||||
at: &count];
|
||||
if (count > 0)
|
||||
at: &items];
|
||||
if (items > 0)
|
||||
{
|
||||
GS_BEGINIDBUF(contents, count);
|
||||
GS_BEGINIDBUF(contents, items);
|
||||
|
||||
[aCoder decodeArrayOfObjCType: @encode(id)
|
||||
count: count
|
||||
count: items
|
||||
at: contents];
|
||||
self = [self initWithObjects: contents count: count];
|
||||
self = [self initWithObjects: contents count: items];
|
||||
#if GS_WITH_GC == 0
|
||||
while (count-- > 0)
|
||||
while (items-- > 0)
|
||||
{
|
||||
[contents[count] release];
|
||||
[contents[items] release];
|
||||
}
|
||||
#endif
|
||||
GS_ENDIDBUF();
|
||||
|
@ -948,7 +949,7 @@ static SEL rlSel;
|
|||
*/
|
||||
- (BOOL) isEqualToArray: (NSArray*)otherArray
|
||||
{
|
||||
unsigned i, c;
|
||||
NSUInteger i, c;
|
||||
|
||||
if (self == (id)otherArray)
|
||||
return YES;
|
||||
|
@ -972,7 +973,7 @@ static SEL rlSel;
|
|||
*/
|
||||
- (id) lastObject
|
||||
{
|
||||
unsigned count = [self count];
|
||||
NSUInteger count = [self count];
|
||||
if (count == 0)
|
||||
return nil;
|
||||
return [self objectAtIndex: count-1];
|
||||
|
@ -995,12 +996,12 @@ static SEL rlSel;
|
|||
*/
|
||||
- (void) makeObjectsPerformSelector: (SEL)aSelector
|
||||
{
|
||||
unsigned c = [self count];
|
||||
NSUInteger c = [self count];
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
unsigned i = 0;
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
NSUInteger i = 0;
|
||||
|
||||
while (i < c)
|
||||
{
|
||||
|
@ -1023,12 +1024,12 @@ static SEL rlSel;
|
|||
*/
|
||||
- (void) makeObjectsPerformSelector: (SEL)aSelector withObject: (id)arg
|
||||
{
|
||||
unsigned c = [self count];
|
||||
NSUInteger c = [self count];
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
unsigned i = 0;
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
NSUInteger i = 0;
|
||||
|
||||
while (i < c)
|
||||
{
|
||||
|
@ -1112,8 +1113,8 @@ compare(id elem1, id elem2, void* context)
|
|||
{
|
||||
NSMutableArray *sortedArray;
|
||||
|
||||
sortedArray = [[[NSMutableArrayClass allocWithZone:
|
||||
NSDefaultMallocZone()] initWithArray: self copyItems: NO] autorelease];
|
||||
sortedArray = AUTORELEASE([[NSMutableArrayClass allocWithZone:
|
||||
NSDefaultMallocZone()] initWithArray: self copyItems: NO]);
|
||||
[sortedArray sortUsingFunction: comparator context: context];
|
||||
|
||||
return [sortedArray makeImmutableCopyOnFail: NO];
|
||||
|
@ -1125,8 +1126,8 @@ compare(id elem1, id elem2, void* context)
|
|||
{
|
||||
NSMutableArray *sortedArray;
|
||||
|
||||
sortedArray = [[[NSMutableArrayClass allocWithZone:
|
||||
NSDefaultMallocZone()] initWithArray: self copyItems: NO] autorelease];
|
||||
sortedArray = AUTORELEASE([[NSMutableArrayClass allocWithZone:
|
||||
NSDefaultMallocZone()] initWithArray: self copyItems: NO]);
|
||||
[sortedArray sortWithOptions: options usingComparator: comparator];
|
||||
|
||||
return [sortedArray makeImmutableCopyOnFail: NO];
|
||||
|
@ -1225,14 +1226,14 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (NSString*) componentsJoinedByString: (NSString*)separator
|
||||
{
|
||||
unsigned int c = [self count];
|
||||
NSUInteger c = [self count];
|
||||
NSMutableString *s;
|
||||
|
||||
s = [[[NSMutableString alloc] initWithCapacity: c] autorelease];
|
||||
s = [NSMutableString stringWithCapacity: c];
|
||||
if (c > 0)
|
||||
{
|
||||
unsigned l = [separator length];
|
||||
unsigned i;
|
||||
NSUInteger l = [separator length];
|
||||
NSUInteger i;
|
||||
|
||||
[s appendString: [[self objectAtIndex: 0] description]];
|
||||
for (i = 1; i < c; i++)
|
||||
|
@ -1254,8 +1255,8 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (NSArray*) pathsMatchingExtensions: (NSArray*)extensions
|
||||
{
|
||||
unsigned i, c = [self count];
|
||||
NSMutableArray *a = [[[NSMutableArray alloc] initWithCapacity: 1] autorelease];
|
||||
NSUInteger i, c = [self count];
|
||||
NSMutableArray *a = AUTORELEASE([[NSMutableArray alloc] initWithCapacity: 1]);
|
||||
Class cls = [NSString class];
|
||||
IMP get = [self methodForSelector: oaiSel];
|
||||
IMP add = [a methodForSelector: addSel];
|
||||
|
@ -1282,7 +1283,7 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (id) firstObjectCommonWithArray: (NSArray*)otherArray
|
||||
{
|
||||
unsigned i, c = [self count];
|
||||
NSUInteger i, c = [self count];
|
||||
id o;
|
||||
|
||||
for (i = 0; i < c; i++)
|
||||
|
@ -1302,7 +1303,7 @@ compare(id elem1, id elem2, void* context)
|
|||
- (NSArray*) subarrayWithRange: (NSRange)aRange
|
||||
{
|
||||
id na;
|
||||
unsigned c = [self count];
|
||||
NSUInteger c = [self count];
|
||||
|
||||
GS_RANGE_CHECK(aRange, c);
|
||||
|
||||
|
@ -1486,8 +1487,8 @@ compare(id elem1, id elem2, void* context)
|
|||
{
|
||||
NSMutableArray *results = nil;
|
||||
static NSNull *null = nil;
|
||||
unsigned i;
|
||||
unsigned count = [self count];
|
||||
NSUInteger i;
|
||||
NSUInteger count = [self count];
|
||||
volatile id object = nil;
|
||||
|
||||
results = [NSMutableArray arrayWithCapacity: count];
|
||||
|
@ -1539,7 +1540,7 @@ compare(id elem1, id elem2, void* context)
|
|||
{
|
||||
NSString *op = [path substringToIndex: r.location];
|
||||
NSString *rem = [path substringFromIndex: NSMaxRange(r)];
|
||||
unsigned count = [self count];
|
||||
NSUInteger count = [self count];
|
||||
|
||||
if ([op isEqualToString: @"@count"] == YES)
|
||||
{
|
||||
|
@ -1754,8 +1755,8 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) setValue: (id)value forKey: (NSString*)key
|
||||
{
|
||||
unsigned i;
|
||||
unsigned count = [self count];
|
||||
NSUInteger i;
|
||||
NSUInteger count = [self count];
|
||||
volatile id object = nil;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
|
@ -1820,13 +1821,11 @@ compare(id elem1, id elem2, void* context)
|
|||
passingTest: (GSPredicateBlock)predicate
|
||||
{
|
||||
/* TODO: Concurrency. */
|
||||
NSMutableIndexSet *set = [NSMutableIndexSet indexSet];
|
||||
BLOCK_SCOPE BOOL shouldStop = NO;
|
||||
NSMutableIndexSet *set = [NSMutableIndexSet indexSet];
|
||||
BLOCK_SCOPE BOOL shouldStop = NO;
|
||||
id<NSFastEnumeration> enumerator = self;
|
||||
NSUInteger count = 0;
|
||||
BLOCK_SCOPE NSLock *setLock = nil;
|
||||
|
||||
|
||||
NSUInteger count = 0;
|
||||
BLOCK_SCOPE NSLock *setLock = nil;
|
||||
|
||||
/* If we are enumerating in reverse, use the reverse enumerator for fast
|
||||
* enumeration. */
|
||||
|
@ -1835,9 +1834,9 @@ compare(id elem1, id elem2, void* context)
|
|||
enumerator = [self reverseObjectEnumerator];
|
||||
}
|
||||
if (opts & NSEnumerationConcurrent)
|
||||
{
|
||||
setLock = [NSLock new];
|
||||
}
|
||||
{
|
||||
setLock = [NSLock new];
|
||||
}
|
||||
{
|
||||
GS_DISPATCH_CREATE_QUEUE_AND_GROUP_FOR_ENUMERATION(enumQueue, opts)
|
||||
FOR_IN (id, obj, enumerator)
|
||||
|
@ -1871,7 +1870,7 @@ compare(id elem1, id elem2, void* context)
|
|||
END_FOR_IN(enumerator)
|
||||
GS_DISPATCH_TEARDOWN_QUEUE_AND_GROUP_FOR_ENUMERATION(enumQueue, opts);
|
||||
}
|
||||
[setLock release];
|
||||
RELEASE(setLock);
|
||||
return set;
|
||||
}
|
||||
|
||||
|
@ -1894,10 +1893,11 @@ compare(id elem1, id elem2, void* context)
|
|||
{
|
||||
/* TODO: Concurrency. */
|
||||
id<NSFastEnumeration> enumerator = self;
|
||||
BLOCK_SCOPE BOOL shouldStop = NO;
|
||||
NSUInteger count = 0;
|
||||
BLOCK_SCOPE BOOL shouldStop = NO;
|
||||
NSUInteger count = 0;
|
||||
BLOCK_SCOPE NSUInteger index = NSNotFound;
|
||||
BLOCK_SCOPE NSLock *indexLock = nil;
|
||||
BLOCK_SCOPE NSLock *indexLock = nil;
|
||||
|
||||
/* If we are enumerating in reverse, use the reverse enumerator for fast
|
||||
* enumeration. */
|
||||
if (opts & NSEnumerationReverse)
|
||||
|
@ -1906,9 +1906,9 @@ compare(id elem1, id elem2, void* context)
|
|||
}
|
||||
|
||||
if (opts & NSEnumerationConcurrent)
|
||||
{
|
||||
indexLock = [NSLock new];
|
||||
}
|
||||
{
|
||||
indexLock = [NSLock new];
|
||||
}
|
||||
{
|
||||
GS_DISPATCH_CREATE_QUEUE_AND_GROUP_FOR_ENUMERATION(enumQueue, opts)
|
||||
FOR_IN (id, obj, enumerator)
|
||||
|
@ -1945,7 +1945,7 @@ compare(id elem1, id elem2, void* context)
|
|||
END_FOR_IN(enumerator)
|
||||
GS_DISPATCH_TEARDOWN_QUEUE_AND_GROUP_FOR_ENUMERATION(enumQueue, opts);
|
||||
}
|
||||
[indexLock release];
|
||||
RELEASE(indexLock);
|
||||
return index;
|
||||
}
|
||||
|
||||
|
@ -2023,7 +2023,7 @@ compare(id elem1, id elem2, void* context)
|
|||
{
|
||||
id tmp = [self objectAtIndex: i1];
|
||||
|
||||
IF_NO_GC([tmp retain];)
|
||||
RETAIN(tmp);
|
||||
[self replaceObjectAtIndex: i1 withObject: [self objectAtIndex: i2]];
|
||||
[self replaceObjectAtIndex: i2 withObject: tmp];
|
||||
RELEASE(tmp);
|
||||
|
@ -2134,7 +2134,7 @@ compare(id elem1, id elem2, void* context)
|
|||
self = [self initWithCapacity: count];
|
||||
if (count > 0)
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
IMP add = [self methodForSelector: addSel];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
|
@ -2149,7 +2149,7 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) removeLastObject
|
||||
{
|
||||
unsigned count = [self count];
|
||||
NSUInteger count = [self count];
|
||||
|
||||
if (count == 0)
|
||||
[NSException raise: NSRangeException
|
||||
|
@ -2163,7 +2163,7 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) removeObjectIdenticalTo: (id)anObject
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
|
||||
if (anObject == nil)
|
||||
{
|
||||
|
@ -2198,9 +2198,9 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) removeObject: (id)anObject inRange: (NSRange)aRange
|
||||
{
|
||||
unsigned c;
|
||||
unsigned s;
|
||||
unsigned i;
|
||||
NSUInteger c;
|
||||
NSUInteger s;
|
||||
NSUInteger i;
|
||||
|
||||
if (anObject == nil)
|
||||
{
|
||||
|
@ -2235,7 +2235,7 @@ compare(id elem1, id elem2, void* context)
|
|||
* first equal object we don't get left with a bad object
|
||||
* pointer for later comparisons.
|
||||
*/
|
||||
IF_NO_GC([anObject retain];)
|
||||
RETAIN(anObject);
|
||||
}
|
||||
(*rem)(self, remSel, i);
|
||||
}
|
||||
|
@ -2255,9 +2255,9 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) removeObjectIdenticalTo: (id)anObject inRange: (NSRange)aRange
|
||||
{
|
||||
unsigned c;
|
||||
unsigned s;
|
||||
unsigned i;
|
||||
NSUInteger c;
|
||||
NSUInteger s;
|
||||
NSUInteger i;
|
||||
|
||||
if (anObject == nil)
|
||||
{
|
||||
|
@ -2298,7 +2298,7 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) removeObject: (id)anObject
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
|
||||
if (anObject == nil)
|
||||
{
|
||||
|
@ -2327,7 +2327,7 @@ compare(id elem1, id elem2, void* context)
|
|||
* first equal object we don't get left with a bad object
|
||||
* pointer for later comparisons.
|
||||
*/
|
||||
IF_NO_GC([anObject retain];)
|
||||
RETAIN(anObject);
|
||||
}
|
||||
(*rem)(self, remSel, i);
|
||||
}
|
||||
|
@ -2346,7 +2346,7 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) removeAllObjects
|
||||
{
|
||||
unsigned c = [self count];
|
||||
NSUInteger c = [self count];
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
|
@ -2364,11 +2364,11 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) addObjectsFromArray: (NSArray*)otherArray
|
||||
{
|
||||
unsigned c = [otherArray count];
|
||||
NSUInteger c = [otherArray count];
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
IMP get = [otherArray methodForSelector: oaiSel];
|
||||
IMP add = [self methodForSelector: addSel];
|
||||
|
||||
|
@ -2414,14 +2414,14 @@ compare(id elem1, id elem2, void* context)
|
|||
{
|
||||
if (count > 0)
|
||||
{
|
||||
unsigned to = 0;
|
||||
unsigned from = 0;
|
||||
unsigned i;
|
||||
NSUInteger to = 0;
|
||||
NSUInteger from = 0;
|
||||
NSUInteger i;
|
||||
GS_BEGINITEMBUF(sorted, count, NSUInteger);
|
||||
|
||||
while (from < count)
|
||||
{
|
||||
unsigned val = indices[from++];
|
||||
NSUInteger val = indices[from++];
|
||||
|
||||
i = to;
|
||||
while (i > 0 && sorted[i-1] > val)
|
||||
|
@ -2434,7 +2434,7 @@ compare(id elem1, id elem2, void* context)
|
|||
}
|
||||
else if (sorted[i] != val)
|
||||
{
|
||||
unsigned j = to++;
|
||||
NSUInteger j = to++;
|
||||
|
||||
if (sorted[i] < val)
|
||||
{
|
||||
|
@ -2468,11 +2468,11 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) removeObjectsInArray: (NSArray*)otherArray
|
||||
{
|
||||
unsigned c = [otherArray count];
|
||||
NSUInteger c = [otherArray count];
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
unsigned i;
|
||||
NSUInteger i;
|
||||
IMP get = [otherArray methodForSelector: oaiSel];
|
||||
IMP rem = [self methodForSelector: @selector(removeObject:)];
|
||||
|
||||
|
@ -2486,9 +2486,9 @@ compare(id elem1, id elem2, void* context)
|
|||
*/
|
||||
- (void) removeObjectsInRange: (NSRange)aRange
|
||||
{
|
||||
unsigned i;
|
||||
unsigned s = aRange.location;
|
||||
unsigned c = [self count];
|
||||
NSUInteger i;
|
||||
NSUInteger s = aRange.location;
|
||||
NSUInteger c = [self count];
|
||||
|
||||
i = aRange.location + aRange.length;
|
||||
|
||||
|
@ -2600,7 +2600,7 @@ compare(id elem1, id elem2, void* context)
|
|||
IF_NO_GC(RETAIN(array));
|
||||
pos = 0;
|
||||
get = [array methodForSelector: oaiSel];
|
||||
cnt = (unsigned (*)(NSArray*, SEL))[array methodForSelector: countSel];
|
||||
cnt = (NSUInteger (*)(NSArray*, SEL))[array methodForSelector: countSel];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -346,10 +346,10 @@ GS_PRIVATE_INTERNAL(NSConnection)
|
|||
- (void) _failInRmc: (NSPortCoder*)c;
|
||||
- (void) _failOutRmc: (NSPortCoder*)c;
|
||||
- (NSPortCoder*) _getReplyRmc: (int)sn;
|
||||
- (NSPortCoder*) _makeInRmc: (NSMutableArray*)components;
|
||||
- (NSPortCoder*) _makeOutRmc: (int)sequence generate: (int*)sno reply: (BOOL)f;
|
||||
- (NSPortCoder*) _newInRmc: (NSMutableArray*)components;
|
||||
- (NSPortCoder*) _newOutRmc: (int)sequence generate: (int*)sno reply: (BOOL)f;
|
||||
- (void) _portIsInvalid: (NSNotification*)notification;
|
||||
- (void) _sendOutRmc: (NSPortCoder*)c type: (int)msgid;
|
||||
- (void) _sendOutRmc: (NSPortCoder*) NS_CONSUMED c type: (int)msgid;
|
||||
|
||||
- (void) _service_forwardForProxy: (NSPortCoder*)rmc;
|
||||
- (void) _service_release: (NSPortCoder*)rmc;
|
||||
|
@ -1683,7 +1683,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
{
|
||||
return [self rootObject];
|
||||
}
|
||||
op = [self _makeOutRmc: 0 generate: &seq_num reply: YES];
|
||||
op = [self _newOutRmc: 0 generate: &seq_num reply: YES];
|
||||
[self _sendOutRmc: op type: ROOTPROXY_REQUEST];
|
||||
|
||||
ip = [self _getReplyRmc: seq_num];
|
||||
|
@ -2026,7 +2026,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
NSParameterAssert(type);
|
||||
NSParameterAssert(*type);
|
||||
|
||||
op = [self _makeOutRmc: 0 generate: (int*)&seq reply: YES];
|
||||
op = [self _newOutRmc: 0 generate: (int*)&seq reply: YES];
|
||||
|
||||
if (debug_connection > 4)
|
||||
NSLog(@"building packet seq %d", seq);
|
||||
|
@ -2222,7 +2222,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
|
||||
NSParameterAssert(IreceivePort);
|
||||
NSParameterAssert (IisValid);
|
||||
op = [self _makeOutRmc: 0 generate: &seq_num reply: YES];
|
||||
op = [self _newOutRmc: 0 generate: &seq_num reply: YES];
|
||||
[op encodeValueOfObjCType: ":" at: &sel];
|
||||
[op encodeValueOfObjCType: @encode(unsigned) at: &target];
|
||||
[self _sendOutRmc: op type: METHODTYPE_REQUEST];
|
||||
|
@ -2326,7 +2326,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
RELEASE(d);
|
||||
}
|
||||
|
||||
rmc = [conn _makeInRmc: components];
|
||||
rmc = [conn _newInRmc: components];
|
||||
if (debug_connection > 5)
|
||||
{
|
||||
NSLog(@"made rmc %p for %d", rmc, type);
|
||||
|
@ -2478,7 +2478,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
|
||||
/* Send out a root proxy request to ping the other end.
|
||||
*/
|
||||
op = [self _makeOutRmc: 0 generate: &IlastKeepalive reply: NO];
|
||||
op = [self _newOutRmc: 0 generate: &IlastKeepalive reply: NO];
|
||||
IkeepaliveWait = YES;
|
||||
[self _sendOutRmc: op type: ROOTPROXY_REQUEST];
|
||||
}
|
||||
|
@ -2764,7 +2764,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
/* We create a new coder object and encode a flag to
|
||||
* say that this is not an exception.
|
||||
*/
|
||||
encoder = [self _makeOutRmc: seq generate: 0 reply: NO];
|
||||
encoder = [self _newOutRmc: seq generate: 0 reply: NO];
|
||||
[encoder encodeValueOfObjCType: @encode(BOOL) at: &is_exception];
|
||||
|
||||
/* Only encode return values if there is a non-void return value,
|
||||
|
@ -2882,7 +2882,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
{
|
||||
[self _failOutRmc: encoder];
|
||||
}
|
||||
op = [self _makeOutRmc: seq generate: 0 reply: NO];
|
||||
op = [self _newOutRmc: seq generate: 0 reply: NO];
|
||||
[op encodeValueOfObjCType: @encode(BOOL)
|
||||
at: &is_exception];
|
||||
[op encodeBycopyObject: localException];
|
||||
|
@ -2911,7 +2911,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
|
||||
[rmc decodeValueOfObjCType: @encode(int) at: &sequence];
|
||||
[self _doneInRmc: rmc];
|
||||
op = [self _makeOutRmc: sequence generate: 0 reply: NO];
|
||||
op = [self _newOutRmc: sequence generate: 0 reply: NO];
|
||||
[op encodeObject: rootObject];
|
||||
[self _sendOutRmc: op type: ROOTPROXY_REPLY];
|
||||
}
|
||||
|
@ -2985,7 +2985,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
NSParameterAssert (IisValid);
|
||||
|
||||
[rmc decodeValueOfObjCType: @encode(int) at: &sequence];
|
||||
op = [self _makeOutRmc: sequence generate: 0 reply: NO];
|
||||
op = [self _newOutRmc: sequence generate: 0 reply: NO];
|
||||
|
||||
[rmc decodeValueOfObjCType: @encode(typeof(target)) at: &target];
|
||||
[self _doneInRmc: rmc];
|
||||
|
@ -3019,7 +3019,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
NSPortCoder *op;
|
||||
int sno;
|
||||
|
||||
op = [self _makeOutRmc: 0 generate: &sno reply: NO];
|
||||
op = [self _newOutRmc: 0 generate: &sno reply: NO];
|
||||
[self _sendOutRmc: op type: CONNECTION_SHUTDOWN];
|
||||
}
|
||||
NS_HANDLER
|
||||
|
@ -3049,7 +3049,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
NSParameterAssert (IisValid);
|
||||
|
||||
[rmc decodeValueOfObjCType: @encode(int) at: &sequence];
|
||||
op = [self _makeOutRmc: sequence generate: 0 reply: NO];
|
||||
op = [self _newOutRmc: sequence generate: 0 reply: NO];
|
||||
|
||||
[rmc decodeValueOfObjCType: ":" at: &sel];
|
||||
[rmc decodeValueOfObjCType: @encode(unsigned) at: &target];
|
||||
|
@ -3262,7 +3262,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
IrepInCount++;
|
||||
}
|
||||
|
||||
- (void) _doneInRmc: (NSPortCoder*)c
|
||||
- (void) _doneInRmc: (NSPortCoder*) NS_CONSUMED c
|
||||
{
|
||||
GS_M_LOCK(IrefGate);
|
||||
if (debug_connection > 5)
|
||||
|
@ -3316,7 +3316,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
GSM_UNLOCK(IrefGate);
|
||||
}
|
||||
|
||||
- (NSPortCoder*) _makeInRmc: (NSMutableArray*)components
|
||||
- (NSPortCoder*) _newInRmc: (NSMutableArray*)components
|
||||
{
|
||||
NSPortCoder *coder;
|
||||
NSUInteger count;
|
||||
|
@ -3351,7 +3351,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
* rep If this flag is YES, add a placeholder to the IreplyMap
|
||||
* so we handle an incoming reply for this sequence number.
|
||||
*/
|
||||
- (NSPortCoder*) _makeOutRmc: (int)sno generate: (int*)ret reply: (BOOL)rep
|
||||
- (NSPortCoder*) _newOutRmc: (int)sno generate: (int*)ret reply: (BOOL)rep
|
||||
{
|
||||
NSPortCoder *coder;
|
||||
NSUInteger count;
|
||||
|
@ -3651,7 +3651,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
unsigned i;
|
||||
int sequence;
|
||||
|
||||
op = [self _makeOutRmc: 0 generate: &sequence reply: NO];
|
||||
op = [self _newOutRmc: 0 generate: &sequence reply: NO];
|
||||
|
||||
[op encodeValueOfObjCType: @encode(unsigned) at: &number];
|
||||
|
||||
|
@ -3820,7 +3820,7 @@ static NSLock *cached_proxies_gate = nil;
|
|||
id result;
|
||||
int seq_num;
|
||||
|
||||
op = [self _makeOutRmc: 0 generate: &seq_num reply: YES];
|
||||
op = [self _newOutRmc: 0 generate: &seq_num reply: YES];
|
||||
[op encodeValueOfObjCType: @encode(typeof(target)) at: &target];
|
||||
[self _sendOutRmc: op type: PROXY_RETAIN];
|
||||
|
||||
|
|
141
Source/NSData.m
141
Source/NSData.m
|
@ -139,6 +139,14 @@ static Class mutableDataFinalized;
|
|||
static SEL appendSel;
|
||||
static IMP appendImp;
|
||||
|
||||
static inline void
|
||||
decodebase64(unsigned char *dst, const unsigned char *src)
|
||||
{
|
||||
dst[0] = (src[0] << 2) | ((src[1] & 0x30) >> 4);
|
||||
dst[1] = ((src[1] & 0x0F) << 4) | ((src[2] & 0x3C) >> 2);
|
||||
dst[2] = ((src[2] & 0x03) << 6) | (src[3] & 0x3F);
|
||||
}
|
||||
|
||||
static BOOL
|
||||
readContentsOfFile(NSString* path, void** buf, off_t* len, NSZone* zone)
|
||||
{
|
||||
|
@ -555,7 +563,138 @@ failure:
|
|||
|
||||
- (id) init
|
||||
{
|
||||
return [self initWithBytesNoCopy: 0 length: 0 freeWhenDone: YES];
|
||||
return [self initWithBytesNoCopy: 0 length: 0 freeWhenDone: YES];
|
||||
}
|
||||
|
||||
- (id) initWithBase64EncodedData: (NSData*)base64Data
|
||||
options: (NSDataBase64DecodingOptions)options
|
||||
{
|
||||
NSUInteger length;
|
||||
NSUInteger declen;
|
||||
const unsigned char *src;
|
||||
const unsigned char *end;
|
||||
unsigned char *result;
|
||||
unsigned char *dst;
|
||||
unsigned char buf[4];
|
||||
unsigned pos = 0;
|
||||
|
||||
if (nil == base64Data)
|
||||
{
|
||||
AUTORELEASE(self);
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-initWithBase64EncodedData:options:] called with "
|
||||
@"nil data", NSStringFromClass([self class])];
|
||||
return nil;
|
||||
}
|
||||
length = [base64Data length];
|
||||
if (length == 0)
|
||||
{
|
||||
return [self initWithBytesNoCopy: 0 length: 0 freeWhenDone: YES];
|
||||
}
|
||||
declen = ((length + 3) * 3)/4;
|
||||
src = (const unsigned char*)[base64Data bytes];
|
||||
end = &src[length];
|
||||
|
||||
result = (unsigned char*)malloc(declen);
|
||||
dst = result;
|
||||
|
||||
while ((src != end) && *src != '\0')
|
||||
{
|
||||
int c = *src++;
|
||||
|
||||
if (isupper(c))
|
||||
{
|
||||
c -= 'A';
|
||||
}
|
||||
else if (islower(c))
|
||||
{
|
||||
c = c - 'a' + 26;
|
||||
}
|
||||
else if (isdigit(c))
|
||||
{
|
||||
c = c - '0' + 52;
|
||||
}
|
||||
else if (c == '/')
|
||||
{
|
||||
c = 63;
|
||||
}
|
||||
else if (c == '+')
|
||||
{
|
||||
c = 62;
|
||||
}
|
||||
else if (c == '=')
|
||||
{
|
||||
c = -1;
|
||||
}
|
||||
else if (options & NSDataBase64DecodingIgnoreUnknownCharacters)
|
||||
{
|
||||
c = -1; /* ignore */
|
||||
}
|
||||
else
|
||||
{
|
||||
free(result);
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (c >= 0)
|
||||
{
|
||||
buf[pos++] = c;
|
||||
if (pos == 4)
|
||||
{
|
||||
pos = 0;
|
||||
decodebase64(dst, buf);
|
||||
dst += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pos > 0)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = pos; i < 4; i++)
|
||||
{
|
||||
buf[i] = '\0';
|
||||
}
|
||||
pos--;
|
||||
if (pos > 0)
|
||||
{
|
||||
unsigned char tail[3];
|
||||
decodebase64(tail, buf);
|
||||
memcpy(dst, tail, pos);
|
||||
dst += pos;
|
||||
}
|
||||
}
|
||||
length = dst - result;
|
||||
if (options & NSDataBase64DecodingIgnoreUnknownCharacters)
|
||||
{
|
||||
/* If the decoded length is a lot shorter than expected (because we
|
||||
* ignored a lot of characters), reallocate to get smaller memory.
|
||||
*/
|
||||
if ((((declen - length) * 100) / declen) > 5)
|
||||
{
|
||||
result = realloc(result, length);
|
||||
}
|
||||
}
|
||||
return [self initWithBytesNoCopy: result length: length freeWhenDone: YES];
|
||||
}
|
||||
|
||||
- (id) initWithBase64EncodedString: (NSString*)base64String
|
||||
options: (NSDataBase64DecodingOptions)options
|
||||
{
|
||||
NSData *data;
|
||||
|
||||
if (nil == base64String)
|
||||
{
|
||||
AUTORELEASE(self);
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-initWithBase64EncodedString:options:] called with "
|
||||
@"nil string", NSStringFromClass([self class])];
|
||||
return nil;
|
||||
}
|
||||
data = [base64String dataUsingEncoding: NSUTF8StringEncoding];
|
||||
return [self initWithBase64EncodedData: data options: options];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue