Update to ARC (probably introducing some leaks, probably fixing others).
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 26 Feb 2013 17:28:25 +0000 (18:28 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Tue, 26 Feb 2013 17:28:25 +0000 (18:28 +0100)
14 files changed:
ApplicationController.h
ApplicationController.m
ConfigsController.h
ConfigsController.m
Enjoy.xcodeproj/project.pbxproj
JSAction.h
JSActionAnalog.m
JSActionHat.m
Joystick.m
JoystickController.h
JoystickController.m
KeyInputTextView.h
SubAction.h
TargetConfig.h

index 9d1607f..e6e5614 100644 (file)
@@ -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;
index 4a4deea..2edac94 100644 (file)
@@ -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];
index 39f3a0d..7e79f15 100644 (file)
@@ -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;
index 3168f8d..cc16b6e 100644 (file)
                [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{
index 9fbdbb6..12361dc 100644 (file)
                        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 = (
                        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 = (
index 50e37e2..1e60cf2 100644 (file)
 @interface JSAction : NSObject {
        int usage, index;
        void* cookie;
-       NSArraysubActions;
+       NSArray *subActions;
        id base;
-       NSStringname;
+       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;
index 2931464..027bd5d 100644 (file)
@@ -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)];
    }
index 61241b9..13abcda 100644 (file)
@@ -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;
index fd08ee6..d6c4362 100644 (file)
@@ -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;
        }
 }
 
 -(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];
index aa95815..f0530dc 100644 (file)
@@ -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;
index 6b748df..5056b0e 100644 (file)
        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,
index 69d8f10..e327c78 100644 (file)
@@ -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;
index 48969ca..d09fa3a 100644 (file)
@@ -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;
index 0f164b9..b08e31b 100644 (file)
@@ -14,7 +14,7 @@
        Config *config;
 }
 
-@property(readwrite, retain) Config* config;
+@property(readwrite, strong) Config* config;
 +(TargetConfig*) unstringifyImpl: (NSArray*) comps withConfigList: (NSArray*) configs;
 
 @end