casts and type specifications for Clang

Clang has more knowledge/assumptions on return types.
Therefore more casts are needed in some cases.
In some cases more specific types have to be specified.
Also Clang has found overrides of “-release” lacking the “oneway” keyword.
This commit is contained in:
Tilo Prütz 2012-04-18 17:10:35 +02:00
parent 7e9b6636a2
commit 5693564160
17 changed files with 78 additions and 63 deletions

View File

@ -267,7 +267,7 @@ CFIndex CFArrayBSearchValues(CFArrayRef self,CFRange range,const void *value,CFC
// mutable
CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks)
{
return [[__CFArray allocWithZone:NULL] initWithCallBacks:callBacks];
return (CFMutableArrayRef)[[__CFArray allocWithZone:NULL] initWithCallBacks:callBacks];
}

View File

@ -16,7 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
- initWithObjects:(id *)objects count:(NSUInteger)count
{
NSDeallocateObject(self);
return NSArray_concreteNew(NULL, objects, count);
return (NSArray_placeholder *)NSArray_concreteNew(NULL, objects, count);
}

View File

@ -18,7 +18,7 @@ static inline NSUInteger roundCapacityUp(NSUInteger capacity){
}
NSArray *NSMutableArray_concreteInit(NSMutableArray_concrete *self, id *objects, NSUInteger count, NSZone *zone)
NSMutableArray_concrete *NSMutableArray_concreteInit(NSMutableArray_concrete *self, id *objects, NSUInteger count, NSZone *zone)
{
NSUInteger i;
@ -33,7 +33,7 @@ NSArray *NSMutableArray_concreteInit(NSMutableArray_concrete *self, id *objects,
}
NSArray *NSMutableArray_concreteInitWithCapacity(NSMutableArray_concrete *self, NSUInteger capacity, NSZone *zone)
NSMutableArray_concrete *NSMutableArray_concreteInitWithCapacity(NSMutableArray_concrete *self, NSUInteger capacity, NSZone *zone)
{
self->_count = 0;
self->_capacity = roundCapacityUp(capacity);

View File

@ -70,7 +70,7 @@ NSData *NSData_concreteNewNoCopy(NSZone *zone,void *bytes,NSUInteger length) {
- initWithContentsOfMappedFile:(NSString *)path
{
[self dealloc];
return [[NSData_mapped alloc] initWithContentsOfMappedFile:path];
return (NSData_concrete *)[[NSData_mapped alloc] initWithContentsOfMappedFile:path];
}

View File

@ -21,7 +21,7 @@
// We should warn here, but this needs to be ignored for an app, maybe at least construct a float?
// NSUnimplementedMethod();
[self dealloc];
return [[NSNumber alloc] initWithInteger:0]; // NSNumber is implemented
return (NSDecimalNumberPlaceholder *)[[NSNumber alloc] initWithInteger:0]; // NSNumber is implemented
}

View File

@ -43,7 +43,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-initWithCoder:(NSCoder *)coder {
return self;
return self;
}
-(void)dealloc {
@ -59,9 +59,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return self;
}
-(void)release {
- (oneway void)release
{
}
// yes, it does this
-valueForKey:(NSString *)key {
return self;

View File

@ -35,7 +35,11 @@ NSNumber *NSNumber_BOOLNew(NSZone *zone,BOOL value) {
return self;
}
-(void)release {}
- (oneway void)release
{
}
-(id)autorelease {
return self;

View File

@ -139,7 +139,12 @@ NSNumber *NSNumber_doubleNew(NSZone *zone,double value) {
return self;
}
-(void)release {}
- (oneway void)release
{
// will never be released
}
-(id)autorelease {
return self;

View File

@ -54,7 +54,7 @@ static NSNumber_placeholder *sSharedInstance;
}
- (void)release
- (oneway void)release
{
}
@ -74,82 +74,82 @@ static NSNumber_placeholder *sSharedInstance;
- initWithChar:(char)value
{
return NSNumber_charNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_charNew(NULL, value);
}
- initWithUnsignedChar:(unsigned char)value
{
return NSNumber_unsignedCharNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_unsignedCharNew(NULL, value);
}
- initWithShort:(short)value
{
return NSNumber_shortNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_shortNew(NULL, value);
}
- initWithUnsignedShort:(unsigned short)value
{
return NSNumber_unsignedShortNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_unsignedShortNew(NULL, value);
}
- initWithInt:(int)value
{
return NSNumber_intNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_intNew(NULL, value);
}
- initWithUnsignedInt:(unsigned int)value
{
return NSNumber_unsignedIntNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_unsignedIntNew(NULL, value);
}
- initWithLong:(long)value
{
return NSNumber_longNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_longNew(NULL, value);
}
- initWithUnsignedLong:(unsigned long)value
{
return NSNumber_unsignedLongNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_unsignedLongNew(NULL, value);
}
- initWithLongLong:(long long)value
{
return NSNumber_longLongNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_longLongNew(NULL, value);
}
- initWithUnsignedLongLong:(unsigned long long)value
{
return NSNumber_unsignedLongLongNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_unsignedLongLongNew(NULL, value);
}
- initWithFloat:(float)value
{
return NSNumber_floatNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_floatNew(NULL, value);
}
- initWithDouble:(double)value
{
return NSNumber_doubleNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_doubleNew(NULL, value);
}
- initWithInteger:(NSInteger)value
{
#if defined(__LP64__)
return NSNumber_longNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_longNew(NULL, value);
#else
return NSNumber_intNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_intNew(NULL, value);
#endif
}
@ -157,16 +157,16 @@ static NSNumber_placeholder *sSharedInstance;
- initWithUnsignedInteger:(NSUInteger)value
{
#if defined(__LP64__)
return NSNumber_unsignedLongNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_unsignedLongNew(NULL, value);
#else
return NSNumber_unsignedIntNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_unsignedIntNew(NULL, value);
#endif
}
- initWithBool:(BOOL)value
{
return NSNumber_BOOLNew(NULL, value);
return (NSNumber_placeholder *)NSNumber_BOOLNew(NULL, value);
}

View File

@ -17,7 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
- init
{
[self dealloc];
return NSSet_concreteNew(NULL, NULL, 0);
return (NSSet_placeholder *)NSSet_concreteNew(NULL, NULL, 0);
}
@ -30,14 +30,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[self dealloc];
return NSSet_concreteNew(NULL, objects, count);
return (NSSet_placeholder *)NSSet_concreteNew(NULL, objects, count);
}
- initWithObjects:(id *)objects count:(NSUInteger)count
{
[self dealloc];
return NSSet_concreteNew(NULL, objects, count);
return (NSSet_placeholder *)NSSet_concreteNew(NULL, objects, count);
}
@ -69,7 +69,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[self dealloc];
return NSSet_concreteNew(NULL, objects, count);
return (NSSet_placeholder *)NSSet_concreteNew(NULL, objects, count);
}

View File

@ -214,7 +214,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
if (event != NSStreamEventNone) {
if (_callBack != NULL) {
if (_events & event) {
_callBack((CFReadStreamRef)self, event, _context.info);
_callBack((CFReadStreamRef)self, (CFStreamEventType)event, _context.info);
}
} else {
if ([_delegate respondsToSelector:@selector(stream:handleEvent:)]) {

View File

@ -211,7 +211,7 @@ static BOOL socketHasSpaceAvailable(NSSocket *socket){
if (event != NSStreamEventNone) {
if (_callBack != NULL) {
if (_events & event) {
_callBack((CFWriteStreamRef)self, event, _context.info);
_callBack((CFWriteStreamRef)self, (CFStreamEventType)event, _context.info);
}
} else {
if ([_delegate respondsToSelector:@selector(stream:handleEvent:)]) {

View File

@ -1,8 +1,8 @@
/* Copyright (c) 2008 Johannes Fortmann
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import "NSDarwinString.h"
@ -25,9 +25,12 @@
return self;
}
-(void)release {
- (oneway void)release
{
}
-autorelease {
return self;
}
@ -46,25 +49,25 @@
NSRaiseException(NSRangeException,self,_cmd,@"index %d beyond length %d",
location,[self length]);
}
return _bytes[location];
}
-(void)getCharacters:(unichar *)buffer {
int i;
for(i=0;i<_length;i++)
buffer[i]=_bytes[i];
}
-(void)getCharacters:(unichar *)buffer range:(NSRange)range {
NSInteger i,loc=range.location,len=range.length;
if(NSMaxRange(range)>_length){
NSRaiseException(NSRangeException,self,_cmd,@"range %@ beyond length %d",
NSStringFromRange(range),[self length]);
}
for(i=0;i<len;i++)
buffer[i]=_bytes[loc+i];
}

View File

@ -103,7 +103,7 @@ static inline NSUInteger roundCapacityUp(NSUInteger capacity){
}
NSString *NSMutableString_unicodePtrInitWithCString(NSMutableString_unicodePtr *self, const char *cString, NSUInteger length, NSZone *zone)
NSMutableString_unicodePtr *NSMutableString_unicodePtrInitWithCString(NSMutableString_unicodePtr *self, const char *cString, NSUInteger length, NSZone *zone)
{
self->_unicode = NSCharactersFromCString(cString, length, &(self->_length), zone);
self->_capacity = self->_length;
@ -112,7 +112,7 @@ NSString *NSMutableString_unicodePtrInitWithCString(NSMutableString_unicodePtr *
}
NSString *NSMutableString_unicodePtrInit(NSMutableString_unicodePtr *self, const unichar *unicode, NSUInteger length, NSZone *zone)
NSMutableString_unicodePtr *NSMutableString_unicodePtrInit(NSMutableString_unicodePtr *self, const unichar *unicode, NSUInteger length, NSZone *zone)
{
NSInteger i;
@ -127,7 +127,7 @@ NSString *NSMutableString_unicodePtrInit(NSMutableString_unicodePtr *self, const
}
NSString *NSMutableString_unicodePtrInitNoCopy(NSMutableString_unicodePtr *self, unichar *unicode, NSUInteger length, NSZone *zone)
NSMutableString_unicodePtr *NSMutableString_unicodePtrInitNoCopy(NSMutableString_unicodePtr *self, unichar *unicode, NSUInteger length, NSZone *zone)
{
self->_length = length;
self->_capacity = length;
@ -137,7 +137,7 @@ NSString *NSMutableString_unicodePtrInitNoCopy(NSMutableString_unicodePtr *self,
}
NSString *NSMutableString_unicodePtrInitWithCapacity(NSMutableString_unicodePtr *self, NSUInteger capacity, NSZone *zone)
NSMutableString_unicodePtr *NSMutableString_unicodePtrInitWithCapacity(NSMutableString_unicodePtr *self, NSUInteger capacity, NSZone *zone)
{
self->_length = 0;
self->_capacity = roundCapacityUp(capacity);
@ -194,7 +194,7 @@ NSString *NSMutableString_unicodePtrNewWithCapacity(NSZone *zone,
- initWithCharactersNoCopy:(unichar *)characters length:(NSUInteger)length freeWhenDone:(BOOL)freeWhenDone
{
NSString *string = NSMutableString_unicodePtrInit(self, characters, length, NSZoneFromPointer(self));
NSMutableString_unicodePtr *string = NSMutableString_unicodePtrInit(self, characters, length, NSZoneFromPointer(self));
if (freeWhenDone) {
NSZoneFree(NSZoneFromPointer(characters), characters);
@ -212,7 +212,7 @@ NSString *NSMutableString_unicodePtrNewWithCapacity(NSZone *zone,
- initWithCStringNoCopy:(char *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)freeWhenDone
{
NSString *string = NSMutableString_unicodePtrInitWithCString(self, bytes, length, NSZoneFromPointer(self));
NSMutableString_unicodePtr *string = NSMutableString_unicodePtrInitWithCString(self, bytes, length, NSZoneFromPointer(self));
if (freeWhenDone) {
NSZoneFree(NSZoneFromPointer(bytes), bytes);

View File

@ -33,14 +33,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
- init
{
NSDeallocateObject(self);
return @"";
return (NSString_placeholder *)@"";
}
- initWithCharactersNoCopy:(unichar *)characters length:(NSUInteger)length freeWhenDone:(BOOL)freeWhenDone
{
NSDeallocateObject(self);
return NSString_unicodePtrNewNoCopy(NULL, characters, length, freeWhenDone);
return (NSString_placeholder *)NSString_unicodePtrNewNoCopy(NULL, characters, length, freeWhenDone);
}
@ -50,7 +50,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
NSDeallocateObject(self);
if (encoding == defaultEncoding()) {
return NSString_cStringNewWithBytes(NULL, bytes, length);
return (NSString_placeholder *)NSString_cStringNewWithBytes(NULL, bytes, length);
}
switch(encoding) {
@ -59,40 +59,40 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
case NSUnicodeStringEncoding:
characters = NSUnicodeFromBytes(bytes, length, &resultLength);
return NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
return (NSString_placeholder *)NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
case NSNEXTSTEPStringEncoding:
return NSNEXTSTEPStringNewWithBytes(NULL, bytes, length);
return (NSString_placeholder *)NSNEXTSTEPStringNewWithBytes(NULL, bytes, length);
// FIX, not nextstep
case NSASCIIStringEncoding:
case NSNonLossyASCIIStringEncoding:
return NSNEXTSTEPStringNewWithBytes(NULL, bytes, length);
return (NSString_placeholder *)NSNEXTSTEPStringNewWithBytes(NULL, bytes, length);
case NSISOLatin1StringEncoding:
return NSString_isoLatin1NewWithBytes(NULL, bytes, length);
return (NSString_placeholder *)NSString_isoLatin1NewWithBytes(NULL, bytes, length);
case NSSymbolStringEncoding:
characters = NSSymbolToUnicode(bytes, length, &resultLength, NULL);
return NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
return (NSString_placeholder *)NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
case NSUTF8StringEncoding:
characters = NSUTF8ToUnicode(bytes, length, &resultLength, NULL);
return NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
return (NSString_placeholder *)NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
case NSWindowsCP1252StringEncoding:
return NSString_win1252NewWithBytes(NULL, bytes, length);
return (NSString_placeholder *)NSString_win1252NewWithBytes(NULL, bytes, length);
case NSMacOSRomanStringEncoding:
return NSString_macOSRomanNewWithBytes(NULL, bytes, length);
return (NSString_placeholder *)NSString_macOSRomanNewWithBytes(NULL, bytes, length);
case NSUTF16LittleEndianStringEncoding:
characters = NSUnicodeFromBytesUTF16LittleEndian(bytes, length, &resultLength);
return NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
return (NSString_placeholder *)NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
case NSUTF16BigEndianStringEncoding:
characters = NSUnicodeFromBytesUTF16BigEndian(bytes, length, &resultLength);
return NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
return (NSString_placeholder *)NSString_unicodePtrNewNoCopy(NULL, characters, resultLength, YES);
default:
NSRaiseException(NSInvalidArgumentException, nil, _cmd, @"encoding %d not (yet) implemented", encoding);
@ -107,7 +107,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
{
NSDeallocateObject(self);
return NSStringNewWithFormat(format, locale, arguments, NULL);
return (NSString_placeholder *)NSStringNewWithFormat(format, locale, arguments, NULL);
}

View File

@ -16,7 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
- initWithBytes:(const void *)value objCType:(const char *)type
{
[self dealloc];
return NSValue_concreteNew(NULL, value, type);
return (NSValue_placeholder *)NSValue_concreteNew(NULL, value, type);
}

View File

@ -188,7 +188,7 @@ static void transferNativeToSetWithOriginals(native_set *sset,NSMutableSet *set,
}
if (result == nil) {
NSSelectSet_bsd *outputSet = [[[NSSelectSet alloc] init] autorelease];
NSSelectSet_bsd *outputSet = (NSSelectSet_bsd *)[[[NSSelectSet alloc] init] autorelease];
if (numFds) {
transferNativeToSetWithOriginals(activeRead, outputSet->_readSet, _readSet, cheater);
transferNativeToSetWithOriginals(activeWrite, outputSet->_writeSet, _writeSet, cheater);