From: Joe Wreschnig Date: Tue, 26 Feb 2013 17:28:25 +0000 (+0100) Subject: Update to ARC (probably introducing some leaks, probably fixing others). X-Git-Tag: version-1.0~119 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=5a79f9f05829ca1aecc70aeadb8c980ec4f3556d;p=enjoyable.git Update to ARC (probably introducing some leaks, probably fixing others). --- diff --git a/ApplicationController.h b/ApplicationController.h index 9d1607f..e6e5614 100644 --- a/ApplicationController.h +++ b/ApplicationController.h @@ -24,9 +24,9 @@ } @property(readwrite) BOOL active; -@property(readonly) JoystickController * jsController; -@property(readonly) TargetController * targetController; -@property(readonly) ConfigsController * configsController; +@property(strong, readonly) JoystickController * jsController; +@property(strong, readonly) TargetController * targetController; +@property(strong, readonly) ConfigsController * configsController; -(IBAction) toggleActivity: (id)sender; -(void) configsChanged; -(void) configChanged; diff --git a/ApplicationController.m b/ApplicationController.m index 4a4deea..2edac94 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -24,7 +24,7 @@ pascal OSStatus appSwitch(EventHandlerCallRef handlerChain, EventRef event, void et.eventClass = kEventClassApplication; et.eventKind = kEventAppFrontSwitched; EventHandlerUPP handler = NewEventHandlerUPP(appSwitch); - InstallApplicationEventHandler(handler, 1, &et, self, NULL); + InstallApplicationEventHandler(handler, 1, &et, (void *)CFBridgingRetain(self), NULL); } -(void) applicationWillTerminate: (NSNotification *)aNotification { @@ -39,7 +39,7 @@ pascal OSStatus appSwitch(EventHandlerCallRef handlerChain, EventRef event, void } pascal OSStatus appSwitch(EventHandlerCallRef handlerChain, EventRef event, void* userData) { - ApplicationController* self = (ApplicationController*)userData; + ApplicationController* self = (__bridge ApplicationController*)userData; NSDictionary* currentApp = [[NSWorkspace sharedWorkspace] activeApplication]; ProcessSerialNumber psn; psn.lowLongOfPSN = [currentApp[@"NSApplicationProcessSerialNumberLow"] longValue]; diff --git a/ConfigsController.h b/ConfigsController.h index 39f3a0d..7e79f15 100644 --- a/ConfigsController.h +++ b/ConfigsController.h @@ -27,8 +27,8 @@ -(NSDictionary*) dumpAll; -(void) loadAllFrom: (NSDictionary*) dict; -@property(readonly) Config* currentConfig; -@property(readonly) Config* currentNeutralConfig; +@property(strong, readonly) Config* currentConfig; +@property(strong, readonly) Config* currentNeutralConfig; @property(readonly) NSArray* configs; @property(readonly) ProcessSerialNumber* targetApplication; -(void) save; diff --git a/ConfigsController.m b/ConfigsController.m index 3168f8d..cc16b6e 100644 --- a/ConfigsController.m +++ b/ConfigsController.m @@ -139,7 +139,7 @@ [ary addObject: cfgInfo]; } envelope[@"configurationList"] = ary; - envelope[@"selectedIndex"] = [NSNumber numberWithInt: [configs indexOfObject: [self currentNeutralConfig] ] ]; + envelope[@"selectedIndex"] = @([configs indexOfObject: [self currentNeutralConfig] ]); return envelope; } -(void) loadAllFrom: (NSDictionary*) envelope{ diff --git a/Enjoy.xcodeproj/project.pbxproj b/Enjoy.xcodeproj/project.pbxproj index 9fbdbb6..12361dc 100644 --- a/Enjoy.xcodeproj/project.pbxproj +++ b/Enjoy.xcodeproj/project.pbxproj @@ -337,6 +337,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -360,6 +361,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + CLANG_ENABLE_OBJC_ARC = YES; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( diff --git a/JSAction.h b/JSAction.h index 50e37e2..1e60cf2 100644 --- a/JSAction.h +++ b/JSAction.h @@ -12,17 +12,17 @@ @interface JSAction : NSObject { int usage, index; void* cookie; - NSArray* subActions; + NSArray *subActions; id base; - NSString* name; + NSString *name; } @property(readwrite) int usage; @property(readwrite) void* cookie; @property(readonly) int index; -@property(readonly) NSArray* subActions; -@property(readwrite, retain) id base; -@property(readonly) NSString* name; +@property(copy) NSArray* subActions; +@property(readwrite, strong) id base; +@property(copy) NSString* name; @property(readonly) BOOL active; -(void) notifyEvent: (IOHIDValueRef) value; diff --git a/JSActionAnalog.m b/JSActionAnalog.m index 2931464..027bd5d 100644 --- a/JSActionAnalog.m +++ b/JSActionAnalog.m @@ -12,7 +12,6 @@ subActions = @[[[SubAction alloc] initWithIndex: 0 name: @"Low" base: self], [[SubAction alloc] initWithIndex: 1 name: @"High" base: self], [[SubAction alloc] initWithIndex: 2 name: @"Analog" base: self]]; - [subActions retain]; index = newIndex; name = [[NSString alloc] initWithFormat: @"Axis %d", (index+1)]; } diff --git a/JSActionHat.m b/JSActionHat.m index 61241b9..13abcda 100644 --- a/JSActionHat.m +++ b/JSActionHat.m @@ -32,7 +32,6 @@ NO, NO, YES, NO , // W [[SubAction alloc] initWithIndex: 1 name: @"Down" base: self], [[SubAction alloc] initWithIndex: 2 name: @"Left" base: self], [[SubAction alloc] initWithIndex: 3 name: @"Right" base: self]]; - [subActions retain]; name = @"Hat switch"; } return self; diff --git a/Joystick.m b/Joystick.m index fd08ee6..d6c4362 100644 --- a/Joystick.m +++ b/Joystick.m @@ -15,9 +15,9 @@ children = [[NSMutableArray alloc]init]; device = newDevice; - productName = (NSString*)IOHIDDeviceGetProperty( device, CFSTR(kIOHIDProductKey) ); - vendorId = [(NSNumber*)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue]; - productId = [(NSNumber*)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue]; + productName = (__bridge NSString*)IOHIDDeviceGetProperty( device, CFSTR(kIOHIDProductKey) ); + vendorId = [(__bridge NSNumber*)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue]; + productId = [(__bridge NSNumber*)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue]; name = productName; } @@ -42,13 +42,13 @@ } -(void) populateActions { - NSArray* elements = (NSArray*)IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); + NSArray* elements = (NSArray*)CFBridgingRelease(IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone)); int buttons = 0; int axes = 0; for(int i=0; i<[elements count]; i++) { - IOHIDElementRef element = (IOHIDElementRef)elements[i]; + IOHIDElementRef element = (__bridge IOHIDElementRef)elements[i]; int type = IOHIDElementGetType(element); int usage = IOHIDElementGetUsage(element); int usagePage = IOHIDElementGetUsagePage(element); @@ -70,7 +70,7 @@ } if((max - min == 1) || usagePage == kHIDPage_Button || type == kIOHIDElementTypeInput_Button) { - action = [[JSActionButton alloc] initWithIndex: buttons++ andName: (NSString *)elName]; + action = [[JSActionButton alloc] initWithIndex: buttons++ andName: (__bridge NSString *)elName]; [(JSActionButton*)action setMax: max]; } else if(usage == 0x39) action = [[JSActionHat alloc] init]; diff --git a/JoystickController.h b/JoystickController.h index aa95815..f0530dc 100644 --- a/JoystickController.h +++ b/JoystickController.h @@ -31,7 +31,7 @@ -(void) setup; -(Joystick*) findJoystickByRef: (IOHIDDeviceRef) device; -@property(readonly) id selectedAction; +@property(strong, readonly) id selectedAction; @property(readonly) NSMutableArray *joysticks; @property(readonly) NSMutableArray *runningTargets; @property(readwrite) BOOL frontWindowOnly; diff --git a/JoystickController.m b/JoystickController.m index 6b748df..5056b0e 100644 --- a/JoystickController.m +++ b/JoystickController.m @@ -21,20 +21,19 @@ return self; } --(void) finalize { +-(void) dealloc { for(int i=0; i<[joysticks count]; i++) { [joysticks[i] invalidate]; } IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone); CFRelease(hidManager); - [super finalize]; } static NSMutableDictionary* create_criterion( UInt32 inUsagePage, UInt32 inUsage ) { NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; - dict[(NSString*)CFSTR(kIOHIDDeviceUsagePageKey)] = [NSNumber numberWithInt: inUsagePage]; - dict[(NSString*)CFSTR(kIOHIDDeviceUsageKey)] = [NSNumber numberWithInt: inUsage]; + dict[(NSString*)CFSTR(kIOHIDDeviceUsagePageKey)] = @(inUsagePage); + dict[(NSString*)CFSTR(kIOHIDDeviceUsageKey)] = @(inUsage); return dict; } @@ -53,7 +52,7 @@ BOOL objInArray(NSMutableArray *array, id object) { } void timer_callback(CFRunLoopTimerRef timer, void *ctx) { - JoystickController *jc = (JoystickController *)ctx; + JoystickController *jc = (__bridge JoystickController *)ctx; jc->mouseLoc = [NSEvent mouseLocation]; for (Target *target in [jc runningTargets]) { [target update: jc]; @@ -61,7 +60,7 @@ void timer_callback(CFRunLoopTimerRef timer, void *ctx) { } void input_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDValueRef value) { - JoystickController* self = (JoystickController*)inContext; + JoystickController* self = (__bridge JoystickController*)inContext; IOHIDDeviceRef device = IOHIDQueueGetDevice((IOHIDQueueRef) inSender); Joystick* js = [self findJoystickByRef: device]; @@ -133,10 +132,10 @@ int findAvailableIndex(id list, Joystick* js) { } void add_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDDeviceRef device) { - JoystickController* self = (JoystickController*)inContext; + JoystickController* self = (__bridge JoystickController*)inContext; IOHIDDeviceOpen(device, kIOHIDOptionsTypeNone); - IOHIDDeviceRegisterInputValueCallback(device, input_callback, (void*) self); + IOHIDDeviceRegisterInputValueCallback(device, input_callback, (void*) CFBridgingRetain(self)); Joystick *js = [[Joystick alloc] initWithDevice: device]; [js setIndex: findAvailableIndex([self joysticks], js)]; @@ -155,7 +154,7 @@ void add_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDDevic } void remove_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDDeviceRef device) { - JoystickController* self = (JoystickController*)inContext; + JoystickController* self = CFBridgingRelease(inContext); Joystick* match = [self findJoystickByRef: device]; if(!match) @@ -173,14 +172,14 @@ void remove_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDDe create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad), create_criterion(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController)]; - IOHIDManagerSetDeviceMatchingMultiple(hidManager, (CFArrayRef)criteria); + IOHIDManagerSetDeviceMatchingMultiple(hidManager, (CFArrayRef)CFBridgingRetain(criteria)); IOHIDManagerScheduleWithRunLoop( hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode ); IOReturn tIOReturn = IOHIDManagerOpen( hidManager, kIOHIDOptionsTypeNone ); (void)tIOReturn; - IOHIDManagerRegisterDeviceMatchingCallback( hidManager, add_callback, (void*)self ); - IOHIDManagerRegisterDeviceRemovalCallback(hidManager, remove_callback, (void*) self); + IOHIDManagerRegisterDeviceMatchingCallback( hidManager, add_callback, (__bridge void*)self ); + IOHIDManagerRegisterDeviceRemovalCallback(hidManager, remove_callback, (__bridge void*) self); // IOHIDManagerRegisterInputValueCallback(hidManager, input_callback, (void*)self); // register individually so we can find the device more easily @@ -188,7 +187,7 @@ void remove_callback(void* inContext, IOReturn inResult, void* inSender, IOHIDDe // Setup timer for continuous targets CFRunLoopTimerContext ctx = { - 0, (void*)self, NULL, NULL, NULL + 0, (__bridge void*)self, NULL, NULL, NULL }; CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(), 1.0/80.0, diff --git a/KeyInputTextView.h b/KeyInputTextView.h index 69d8f10..e327c78 100644 --- a/KeyInputTextView.h +++ b/KeyInputTextView.h @@ -20,7 +20,7 @@ @property(readonly) BOOL hasKey; @property(readwrite) int vk; -@property(readonly) NSString* descr; +@property(copy) NSString* descr; @property(readwrite) BOOL enabled; -(void) clear; diff --git a/SubAction.h b/SubAction.h index 48969ca..d09fa3a 100644 --- a/SubAction.h +++ b/SubAction.h @@ -18,7 +18,7 @@ -(id) initWithIndex:(int)newIndex name: (NSString*)newName base: (JSAction*)newBase; -@property(readwrite, assign) JSAction* base; +@property(readwrite, strong) JSAction* base; @property(readwrite, copy) NSString* name; @property(readwrite) int index; @property(readwrite) BOOL active; diff --git a/TargetConfig.h b/TargetConfig.h index 0f164b9..b08e31b 100644 --- a/TargetConfig.h +++ b/TargetConfig.h @@ -14,7 +14,7 @@ Config *config; } -@property(readwrite, retain) Config* config; +@property(readwrite, strong) Config* config; +(TargetConfig*) unstringifyImpl: (NSArray*) comps withConfigList: (NSArray*) configs; @end