Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Automatic Reference Counting (ARC) #1190

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/MacVim/DBPrefsWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ - (void)windowDidLoad
// Create a new window to display the preference views.
// If the developer attached a window to this controller
// in Interface Builder, it gets replaced with this one.
NSPanel *window = [[[NSPanel alloc] initWithContentRect:NSMakeRect(0,0,1000,1000)
NSPanel *window = [[NSPanel alloc] initWithContentRect:NSMakeRect(0,0,1000,1000)
styleMask:(NSWindowStyleMaskTitled |
NSWindowStyleMaskClosable)
backing:NSBackingStoreBuffered
defer:YES] autorelease];
defer:YES];
[window setHidesOnDeactivate:NO];
[self setWindow:window];
contentSubview = [[[NSView alloc] initWithFrame:[[[self window] contentView] frame]] autorelease];
contentSubview = [[NSView alloc] initWithFrame:[[[self window] contentView] frame]];
[contentSubview setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)];
[[[self window] contentView] addSubview:contentSubview];
[[self window] setShowsToolbarButton:NO];
Expand All @@ -91,13 +91,6 @@ - (void)windowDidLoad



- (void) dealloc {
[toolbarIdentifiers release];
[toolbarViews release];
[toolbarItems release];
[viewAnimation release];
[super dealloc];
}



Expand Down Expand Up @@ -130,12 +123,12 @@ - (void)addView:(NSView *)view label:(NSString *)label image:(NSImage *)image
NSAssert (view != nil,
@"Attempted to add a nil view when calling -addView:label:image:.");

NSString *identifier = [[label copy] autorelease];
NSString *identifier = [label copy];

[toolbarIdentifiers addObject:identifier];
[toolbarViews setObject:view forKey:identifier];

NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:identifier] autorelease];
NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier:identifier];
[item setLabel:label];
[item setImage:image];
[item setTarget:self];
Expand Down Expand Up @@ -227,7 +220,6 @@ - (IBAction)showWindow:(id)sender
[toolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel];
[toolbar setDelegate:self];
[[self window] setToolbar:toolbar];
[toolbar release];
}

if ([toolbarItems objectForKey:[self currentPaneIdentifier]] == nil) {
Expand Down
66 changes: 16 additions & 50 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#import "MMVimController.h"
#import "MMWindowController.h"
#import "MMTextView.h"
#import "MMVimView.h"
#import "Miscellaneous.h"
#import "Sparkle.framework/Headers/Sparkle.h"
#import <unistd.h>
Expand Down Expand Up @@ -297,7 +298,7 @@ - (id)init
[[NSBundle mainBundle] bundlePath]];
if (![connection registerName:name]) {
ASLogCrit(@"Failed to register connection with name '%@'", name);
[connection release]; connection = nil;
connection = nil;
}

// Register help search handler to support search Vim docs via the Help menu
Expand All @@ -315,22 +316,6 @@ - (id)init
- (void)dealloc
{
ASLogDebug(@"");

[connection release]; connection = nil;
[inputQueues release]; inputQueues = nil;
[pidArguments release]; pidArguments = nil;
[vimControllers release]; vimControllers = nil;
[cachedVimControllers release]; cachedVimControllers = nil;
[openSelectionString release]; openSelectionString = nil;
[recentFilesMenuItem release]; recentFilesMenuItem = nil;
[defaultMainMenu release]; defaultMainMenu = nil;
currentMainMenu = nil;
[appMenuItemTemplate release]; appMenuItemTemplate = nil;
#if !DISABLE_SPARKLE
[updater release]; updater = nil;
#endif

[super dealloc];
}

- (void)applicationWillFinishLaunching:(NSNotification *)notification
Expand All @@ -342,7 +327,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification

// Remember the default menu so that it can be restored if the user closes
// all editor windows.
defaultMainMenu = [[NSApp mainMenu] retain];
defaultMainMenu = [NSApp mainMenu];

// Store a copy of the default app menu so we can use this as a template
// for all other menus. We make a copy here because the "Services" menu
Expand All @@ -368,14 +353,12 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification
int idx = [fileMenu indexOfItemWithAction:@selector(fileOpen:)];
if (idx >= 0 && idx+1 < [fileMenu numberOfItems])

recentFilesMenuItem = [fileMenu itemWithTag:15432];
[[recentFilesMenuItem submenu] performSelector:@selector(_setMenuName:)
withObject:@"NSRecentDocumentsMenu"];

// Note: The "Recent Files" menu must be moved around since there is no
// -[NSApp setRecentFilesMenu:] method. We keep a reference to it to
// facilitate this move (see setMainMenu: below).
[recentFilesMenuItem retain];
recentFilesMenuItem = [fileMenu itemWithTag:15432];
[[recentFilesMenuItem submenu] performSelector:@selector(_setMenuName:)
withObject:@"NSRecentDocumentsMenu"];
}

#if MM_HANDLE_XCODE_MOD_EVENT
Expand Down Expand Up @@ -568,8 +551,6 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:

if ([alert runModal] != NSAlertFirstButtonReturn)
reply = NSTerminateCancel;

[alert release];
} else if (![[NSUserDefaults standardUserDefaults]
boolForKey:MMSuppressTerminationAlertKey]) {
// No unmodified buffers, but give a warning if there are multiple
Expand Down Expand Up @@ -627,7 +608,6 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:
setBool:YES forKey:MMSuppressTerminationAlertKey];
}

[alert release];
}
}

Expand Down Expand Up @@ -747,10 +727,8 @@ - (void)removeVimController:(id)controller
return;
}

[controller retain];
[vimControllers removeObjectAtIndex:idx];
[controller cleanup];
[controller release];

if (![vimControllers count]) {
// The last editor window just closed so restore the main menu back to
Expand Down Expand Up @@ -861,7 +839,6 @@ - (void)windowControllerWillOpen:(MMWindowController *)windowController
// There is some text to paste into this window as a result of the
// services menu "Open selection ..." being used.
[[windowController vimController] dropString:openSelectionString];
[openSelectionString release];
openSelectionString = nil;
}

Expand Down Expand Up @@ -908,7 +885,7 @@ - (void)refreshMainMenu
// of Screen" to the Window menu, and on repeated calls it will keep adding
// the same item over and over again, without resolving for duplicates. Using
// copies help keep the source menu clean.
NSMenu *mainMenu = [[currentMainMenu copy] autorelease];
NSMenu *mainMenu = [currentMainMenu copy];

// If the new menu has a "Recent Files" dummy item, then swap the real item
// for the dummy. We are forced to do this since Cocoa initializes the
Expand All @@ -919,19 +896,17 @@ - (void)refreshMainMenu
int dummyIdx =
[fileMenu indexOfItemWithAction:@selector(recentFilesDummy:)];
if (dummyIdx >= 0) {
NSMenuItem *dummyItem = [[fileMenu itemAtIndex:dummyIdx] retain];
NSMenuItem *dummyItem = [fileMenu itemAtIndex:dummyIdx];
[fileMenu removeItemAtIndex:dummyIdx];

NSMenu *recentFilesParentMenu = [recentFilesMenuItem menu];
int idx = [recentFilesParentMenu indexOfItem:recentFilesMenuItem];
if (idx >= 0) {
[[recentFilesMenuItem retain] autorelease];
[recentFilesParentMenu removeItemAtIndex:idx];
[recentFilesParentMenu insertItem:dummyItem atIndex:idx];
}

[fileMenu insertItem:recentFilesMenuItem atIndex:dummyIdx];
[dummyItem release];
}
}

Expand Down Expand Up @@ -977,7 +952,7 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
// arguments for each launching process can be looked up by its PID (in the
// pidArguments dictionary).

NSMutableDictionary *arguments = (args ? [[args mutableCopy] autorelease]
NSMutableDictionary *arguments = (args ? [args mutableCopy]
: [NSMutableDictionary dictionary]);

filenames = normalizeFilenames(filenames);
Expand Down Expand Up @@ -1078,7 +1053,7 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
// NOTE: We have to copy the args since we'll mutate them in the
// next loop and the below call may retain the arguments while
// waiting for a process to start.
NSDictionary *args = [[arguments copy] autorelease];
NSDictionary *args = [arguments copy];

openOk = [self openVimControllerWithArguments:args];
if (!openOk) break;
Expand Down Expand Up @@ -1387,8 +1362,6 @@ - (unsigned)connectBackend:(byref in id <MMBackendProtocol>)proxy pid:(int)pid
modes:[NSArray arrayWithObject:
NSDefaultRunLoopMode]];

[vc release];

return [vc vimControllerId];
}

Expand Down Expand Up @@ -1470,7 +1443,7 @@ - (void)searchForItemsWithSearchString:(NSString *)searchString

@synchronized (self) {
if (!parsed) {
parsedLineComponents = [[NSMutableArray alloc]init];
parsedLineComponents = [NSMutableArray array];

NSString *tagsFilePath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"vim/runtime/doc/tags"];
Expand All @@ -1493,7 +1466,7 @@ - (void)searchForItemsWithSearchString:(NSString *)searchString
// substring in the tag. Don't do fuzzy matching or regex for simplicity for now.
NSArray<NSString *> *searchStrings = [searchString componentsSeparatedByString:@" "];

NSMutableArray *ret = [[[NSMutableArray alloc]init] autorelease];
NSMutableArray *ret = [NSMutableArray array];
for (NSArray<NSString *> *line in parsedLineComponents) {
BOOL found = YES;
for (NSString *curSearchString in searchStrings) {
Expand Down Expand Up @@ -1565,7 +1538,6 @@ - (void)openSelection:(NSPasteboard *)pboard userData:(NSString *)userData
// Save the text, open a new window, and paste the text when the next
// window opens. (If this is called several times in a row, then all
// but the last call may be ignored.)
if (openSelectionString) [openSelectionString release];
openSelectionString = [[pboard stringForType:NSStringPboardType] copy];

[self newWindow:self];
Expand Down Expand Up @@ -1784,7 +1756,6 @@ - (NSArray *)filterFilesAndNotify:(NSArray *)filenames
[alert setAlertStyle:NSAlertStyleWarning];

[alert runModal];
[alert release];

[NSApp replyToOpenOrPrint:NSApplicationDelegateReplyFailure];
}
Expand Down Expand Up @@ -1819,7 +1790,7 @@ - (NSArray *)filterOpenFiles:(NSArray *)filenames
NSIndexSet *idxSet = [NSIndexSet indexSetWithVimList:eval];
if ([idxSet count] > 0) {
[dict setObject:[files objectsAtIndexes:idxSet]
forKey:[NSValue valueWithPointer:vc]];
forKey:[NSValue valueWithPointer:(__bridge void *)vc]];

// Remove all the files that were open in this Vim process and
// create a new expression to evaluate.
Expand All @@ -1833,7 +1804,7 @@ - (NSArray *)filterOpenFiles:(NSArray *)filenames
if (openFiles != nil)
*openFiles = dict;

return [files autorelease];
return files;
}

#if MM_HANDLE_XCODE_MOD_EVENT
Expand Down Expand Up @@ -1985,7 +1956,6 @@ - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event

[alert setAlertStyle:NSAlertStyleWarning];
[alert runModal];
[alert release];
}
} else {
NSAlert *alert = [[NSAlert alloc] init];
Expand All @@ -2001,7 +1971,6 @@ - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event

[alert setAlertStyle:NSAlertStyleWarning];
[alert runModal];
[alert release];
}
}
} else {
Expand All @@ -2019,7 +1988,6 @@ - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event

[alert setAlertStyle:NSAlertStyleWarning];
[alert runModal];
[alert release];
}
}

Expand Down Expand Up @@ -2338,7 +2306,7 @@ - (void)startWatchingVimDir
NSArray *pathsToWatch = [NSArray arrayWithObject:path];

fsEventStream = FSEventStreamCreate(NULL, &fsEventCallback, NULL,
(CFArrayRef)pathsToWatch, kFSEventStreamEventIdSinceNow,
(__bridge CFArrayRef)pathsToWatch, kFSEventStreamEventIdSinceNow,
MMEventStreamLatency, kFSEventStreamCreateFlagNone);

FSEventStreamScheduleWithRunLoop(fsEventStream,
Expand Down Expand Up @@ -2545,8 +2513,6 @@ - (void)processInputQueues:(id)sender
}
}

[queues release];

// If new input arrived while we were processing it would have been
// blocked so we have to schedule it to be processed again.
if (processingFlag < 0)
Expand Down Expand Up @@ -2612,7 +2578,7 @@ - (NSDictionary *)convertVimControllerArguments:(NSDictionary *)args
return args;

NSMutableArray *a = [NSMutableArray array];
NSMutableDictionary *d = [[args mutableCopy] autorelease];
NSMutableDictionary *d = [args mutableCopy];

// Search for text and highlight it (this Vim script avoids warnings in
// case there is no match for the search text).
Expand Down
3 changes: 1 addition & 2 deletions src/MacVim/MMCoreTextView+ToolTip.m
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ - (void)setToolTipAtMousePoint:(NSString *)string
}
if (oldToolTip) {
[self _sendToolTipMouseExited];
[oldToolTip release];
}
toolTip_ = [toolTip copy];
if (toolTip) {
Expand All @@ -225,7 +224,7 @@ - (NSString *)view:(NSView *)view
point:(NSPoint)point
userData:(void *)data
{
return [[toolTip_ copy] autorelease];
return [toolTip_ copy];
}

@end
Loading