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 9d1607fd8cf3f7c797fb703db9fa460aba10305a..e6e5614b158c9c79588916828b24950b25baf878 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 4a4deeaeede3cde0d189299c9bd6f5f29aedda0c..2edac94393594e30464bfa5a59c5b3d98dc36a64 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 39f3a0dee2162767485f5c691af256226fe6efa0..7e79f15e88dc4fbc931a41556fb8d856fd27be25 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 3168f8d31bb7df7b99f4a654d245171364efc316..cc16b6eadf61b2edb591e7571098dd5173c8e338 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 9fbdbb6f2dd70fdd757d4afee78da568a2dc2a5d..12361dcad91266c7b4c9274cf4d3a84e067ca024 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 50e37e2311a1092bd44b8747b4d82d36f831788d..1e60cf2e11f3ec9bb86d80e13e5f225918e9fbd9 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 293146421ba1477028ba6ec4d987a9ceb84a2ed1..027bd5db95f8436a7f7040e9057e7f95e6e869ab 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 61241b99c17bbaa9de8a155161bb8f186cf43f32..13abcda9d3958a72d347525ad566261345d555fa 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 fd08ee6748ddcdbfb9266da3711613bd786a8130..d6c436224221dd25787c1a15ddcc7109f19a7481 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 aa95815bdd92b6cf8990422a14d2c5c7793411b6..f0530dcafc4ffe4d8ba01393498d23da8c30d785 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 6b748df7a33eaae1322268b63f4bbd59951e03df..5056b0ea72971e99dc3ece00ac5f079cad136acb 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 69d8f10f2d82591e984fdfdc743b53e02e21bd19..e327c7851ba19602595f21af851932bcbd7627e3 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 48969ca90ab9d06586831b514bb906874e463fc9..d09fa3a472d4ac64139fd53f1eea0980e4430f0d 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 0f164b9ccd0f39fe22498d9c1f34ae7f40b5aa40..b08e31bb2f7972f6b55773f2882740ed6585910e 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