Commits

Ronald Oussoren committed 7b150bb

Ensure code compiles without warnings

Some minor code changes and addition off 'pragma ... diagnostic ignore ...'
to avoid compiler warnings.

The whole build for python 2.7 is now without warnings, except
for some warnings in Modules/objc/test/properties.m that cannot
be silenced using a pragma (and cannot be fixed by code changes
because the current code is intentional and needed for the tests)

Comments (0)

Files changed (15)

pyobjc-core/Modules/objc/test/copying.m

 @end
 
 @interface OC_CopyHelper : NSObject
-{ }
+{}
 +(NSObject<NSCopying>*)doCopySetup:(Class)aClass;
 +(NSObject*)newObjectOfClass:(Class)aClass;
 @end
 +(NSObject<NSCopying>*)doCopySetup:(Class)aClass
 {
 	NSObject<NSCopying>* tmp;
-	NSObject* retval;
+	NSObject<NSCopying>* retval;
 
 	tmp = (NSObject<NSCopying>*)[[aClass alloc] init];
 	[tmp modify];
 	[tmp release];
 	return [retval autorelease];
 }
+
 +(NSObject*)newObjectOfClass:(Class)aClass
 {
 	return [[aClass alloc] init];
 {
 	int intVal;
 }
--init;
--initWithInt:(int)intVal;
+-(instancetype)init;
+-(instancetype)initWithInt:(int)intVal;
 -(int)intVal;
 -(void)setIntVal:(int)val;
--copyWithZone:(NSZone*)zone;
+-(instancetype)copyWithZone:(NSZone*)zone;
 @end
 
 @implementation OC_CopyBase
--init
+-(instancetype)init
 {
 	return [self initWithInt:0];
 }
 
--initWithInt:(int)value
+-(instancetype)initWithInt:(int)value
 {
 	self = [super init];
 	if (self == nil) return nil;
 	intVal = val;
 }
 
--copyWithZone:(NSZone*)zone
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+-(instancetype)copyWithZone:(NSZone*)zone
 {
 	return NSCopyObject(self, 0, zone);
 	

pyobjc-core/Modules/objc/test/corefoundation.m

 	CFLocaleRef currentLocale = CFLocaleCopyCurrent();
 	CFDateFormatterRef formatter = CFDateFormatterCreate(
 			NULL, currentLocale, 
-			kCFDateFormatterShortStyle, NSDateFormatterNoStyle  );
+			kCFDateFormatterShortStyle, kCFDateFormatterNoStyle  );
 
 	if (currentLocale != NULL) {
 		CFRelease(currentLocale);

pyobjc-core/Modules/objc/test/fsref.m

 #include "Python.h"
 #include "pyobjc-api.h"
 
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
 #import <CoreServices/CoreServices.h>
 
 #import <Foundation/Foundation.h>

pyobjc-core/Modules/objc/test/initialize.m

 {
 	int       isInitialized;
 }
--init;
--retain;
+-(instancetype)init;
+-(instancetype)retain;
 -(void)release;
--autorelease;
+-(instancetype)autorelease;
 -(int)isInitialized;
 +(int)numUninitialized;
 -(id)dummy;
 
 @implementation OC_TestInitialize 
 
--init
+-(instancetype)init
 {
 	self = [super init];
 	if (!self) return self;
 	return self;
 }
 
--retain
+-(instancetype)retain
 {
 	if (!isInitialized) {
 		numUninitialized ++;
 	[super release];
 }
 
--(id)autorelease
+-(instancetype)autorelease
 {
 	if (!isInitialized) {
 		numUninitialized ++;

pyobjc-core/Modules/objc/test/instanceVariables.m

 	PyObject* pyValue;
 	NSObject* objValue;
 }
--init;
+-(instancetype)init;
 -(void)dealloc;
 @end
 
 @implementation ClassWithVariables
--init
+-(instancetype)init
 {
 	self = [super init];
 	if (self == nil) return nil;

pyobjc-core/Modules/objc/test/metadata.m

 			NULL];
 }
 
+#pragma GCC diagnostic push
+#pragma clang diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+
 -(NSArray*)makeArrayWithCFormat:(char*)fmt, ...
 {
 	va_list ap;
 			[NSString stringWithUTF8String:buffer], 
 			NULL];
 }
+#pragma GCC diagnostic pop
+#pragma clang diagnostic pop
 
 -(NSArray*)makeArrayWithArguments:(id)arg, ...
 {

pyobjc-core/Modules/objc/test/metadatafunction.m

 			NULL];
 }
 
+#pragma GCC   diagnostic push
+#pragma clang   diagnostic push
+#pragma GCC   diagnostic ignored "-Wformat-nonliteral"
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+
 static NSArray* makeArrayWithCFormat_(char* fmt, ...)
 {
 	va_list ap;
 			NULL];
 }
 
+#pragma GCC   diagnostic pop
+#pragma clang   diagnostic pop
+
 static int maybeFillArray_(int* data)
 {       
 	int i;  

pyobjc-core/Modules/objc/test/protected.m

 
 @interface PyObjCTest_Protected : NSObject
 {}
--publicMethod;
--_protectedMethod;
+-(id)publicMethod;
+-(id)_protectedMethod;
 @end
 
 @implementation PyObjCTest_Protected 
--publicMethod
+-(id)publicMethod
 {
 	return nil;
 }
 
--_protectedMethod
+-(id)_protectedMethod
 {
 	return nil;
 }
 	}
 	INITDONE();
 }
-

pyobjc-core/Modules/objc/test/pyobjc-unittest.h

 
 #define FAIL_IF(expr) do { if ((expr)) goto error; } while(0)
 
+#pragma GCC diagnostic push
+#pragma clang diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+
 static inline void
 unittest_assert_failed(const char* file, int line, char* msg, ...)
 {
 	PyErr_Format(PyExc_AssertionError, "%s:%d %s", file, line, buf);
 }
 
+#pragma GCC diagnostic pop
+#pragma clang diagnostic pop
+
 #define ASSERT(expr) \
 	do { \
 		if (!(expr)) { \

pyobjc-core/Modules/objc/test/specialtypecodes.m

 static char gTextCharValues[] = { 'a', 55, 'z' };
 static char gNumCharValues[] = { 1, 2, 3, 4 };
 
--init 
+-(instancetype)init 
 {
 	[super init];
 	_idx = 0;

pyobjc-core/Modules/objc/test/testbndl.m

 @interface PyObjC_TestClass3 : NSObject
 {
 }
-+createAHostWithAddress:(NSString*)address;
-+copyValue:source;
-#if 0
-+newDataWithBytes:(Class)cls method:(int)i;
-+makeDictFromClass:(Class)cls method:(int)i;
-#endif
-+getBytes:(NSData*)data;
-+keyValue:(int)idx forObject: value key: id;
++(NSHost*)createAHostWithAddress:(NSString*)address;
++(id)copyValue:(id<NSCopying>)source;
++(NSData*)getBytes:(NSData*)data;
++(id)keyValue:(int)idx forObject: value key: id;
 +(void)setKeyValue:(int)idx forObject: object key: key value: value;
 @end
 
 @implementation PyObjC_TestClass3
 
-+createAHostWithAddress:(NSString*)address
++(NSHost*)createAHostWithAddress:(NSString*)address
 {
 	return [NSHost hostWithAddress:address];
 }
 
-+getBytes:(NSData*)data
++(NSData*)getBytes:(NSData*)data
 {
 	const void* bytes = [data bytes];
 
 	}
 }
 
-#if 0
-+newDataWithBytes:(Class)cls method:(int)i
-{
-	if (i == 0) {
-		return [cls dataWithBytes:"hello world" length:sizeof("hello world")-1];
-	} else {
-		id o = [cls alloc];
-		return [o initWithBytes:"hello world" length:sizeof("hello world")-1];
-	}
-}
-#endif
-
-#if 0
-+makeDictFromClass:(Class)cls method:(int)i
-{
-	id objects[4];
-	id keys[4];
-
-	objects[0] = [[NSObject alloc] init];
-	objects[1] = [[NSObject alloc] init];
-	objects[2] = [[NSObject alloc] init];
-	objects[3] = [[NSObject alloc] init];
-
-	keys[0] = [[NSObject alloc] init];
-	keys[1] = [[NSObject alloc] init];
-	keys[2] = [[NSObject alloc] init];
-	keys[3] = [[NSObject alloc] init];
-
-	if (i == 0) {
-		return [cls 
-				dictionaryWithObjects:objects 
-				forKeys:keys count:4];
-	} else {
-		return [[cls alloc] 
-				initWithObjects:objects 
-				forKeys:keys count:4];
-	}
-}
-#endif
-
-
-+copyValue:source
++(id)copyValue:(NSObject<NSCopying>*)source
 {
 	id theCopy;
 	id pool;
 	return theCopy;
 }
 
-+keyValue:(int)idx forObject: object key: key
++(id)keyValue:(int)idx forObject: object key: key
 {
 	switch (idx) {
 	case 0: return [object valueForKey: key];
 @end
 
 @interface NSObject (IKnowWhatImDoing)
-- call;
+- (id)call;
 @end
 
 @implementation PyObjC_TestClass4
 @end
 
 @implementation PyObjCTest_KVBaseClass
-- init
+- (instancetype)init
 {
     self = [super init];
     if (!self) return nil;
 @end
 
 @implementation PyObjCTest_KVPathClass
-- init
+- (instancetype)init
 {
     self = [super init];
     if (!self) return nil;
 	NSString* key;
 	id value;
 }
--initWithInstanceOfClass:(Class)cls withKey:(NSString*)key;
--getValue;
+-(instancetype)initWithInstanceOfClass:(Class)cls withKey:(NSString*)key;
+-(id)getValue;
 -(void)dealloc;
 -(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context;
 @end
 
 @implementation PyObjCTest_KeyValueObserver
 
--initWithInstanceOfClass:(Class)cls withKey:(NSString*)aKey
+-(instancetype)initWithInstanceOfClass:(Class)cls withKey:(NSString*)aKey
 {
 	self = [super init];
 	if (self == nil) return nil;
 	[super dealloc];
 }
 
--getValue
+-(id)getValue
 {
 	return value;
 }

pyobjc-core/Modules/objc/test/testclassandinst.m

 @end
 
 @implementation PyObjC_TestUnallocatable
-+ allocWithZone:(NSZone *)zone 
++ (id)allocWithZone:(NSZone *)zone 
 {
     (void)&zone; /* Force use */
     return nil;

pyobjc-core/Modules/objc/test/testoutputinitializer.m

     int _priv;
 }
 
--initWithBooleanOutput:(BOOL *)outBool;
+-(instancetype)initWithBooleanOutput:(BOOL *)outBool;
 -(BOOL)isInitialized;
 @end
 
 @implementation PyObjC_TestOutputInitializer
--initWithBooleanOutput:(BOOL *)outBool
+-(instancetype)initWithBooleanOutput:(BOOL *)outBool
 {
     self = [self init];
     *outBool = YES;

pyobjc-core/Modules/objc/test/voidpointer.m

 @end
 
 @implementation OC_TestVoidPointer
--init 
+-(instancetype)init 
 {
 	self = [super init];
 	if (self) {

pyobjc-core/setup.py

 # Enable 'PyObjC_STRICT_DEBUGGING' to enable some costly internal 
 # assertions. 
 CFLAGS.extend([
+    "-fdiagnostics-show-option",
     
     # Use this to analyze with clang
     #"--analyze",