From be45005f255360f993a7ba602668ec679e634a3b Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Mon, 28 Sep 2009 22:55:16 +0200 Subject: [PATCH] Prepare for 64 bit Mostly fixes problems involving NSUInteger. --- src/MacVim/AuthorizedShellCommand.m | 3 +- src/MacVim/MMAppController.m | 66 +++++++++++++++++------------ src/MacVim/MMTextStorage.h | 4 +- src/MacVim/MMTextStorage.m | 8 ++-- src/MacVim/MMTypesetter.m | 12 +++--- src/MacVim/MMVimController.h | 2 +- src/MacVim/MMVimController.m | 6 +-- src/MacVim/MMVimView.m | 28 ++++++------ src/MacVim/MMWindow.h | 2 +- src/MacVim/MMWindow.m | 4 +- src/MacVim/Miscellaneous.h | 7 +-- src/MacVim/Miscellaneous.m | 13 +++--- 12 files changed, 86 insertions(+), 69 deletions(-) diff --git a/src/MacVim/AuthorizedShellCommand.m b/src/MacVim/AuthorizedShellCommand.m index 5148efbf46..1b90cdb630 100644 --- a/src/MacVim/AuthorizedShellCommand.m +++ b/src/MacVim/AuthorizedShellCommand.m @@ -54,8 +54,7 @@ NSEnumerator* myIterator = [commands objectEnumerator]; NSDictionary* currCommand; - while (currCommand = [myIterator nextObject]) - { + while ((currCommand = [myIterator nextObject])) { /* do something useful with currCommand */ FILE *ioPipe = NULL; char junk[256]; diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 50427ec5e4..50d4a4ca9b 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -72,17 +72,19 @@ static float MMCascadeHorizontalOffset = 21; static float MMCascadeVerticalOffset = 23; -#pragma options align=mac68k +#pragma pack(push,1) +// The alignment and sizes of these fields are based on trial-and-error. It +// may be necessary to adjust them to fit if Xcode ever changes this struct. typedef struct { - short unused1; // 0 (not used) - short lineNum; // line to select (< 0 to specify range) - long startRange; // start of selection range (if line < 0) - long endRange; // end of selection range (if line < 0) - long unused2; // 0 (not used) - long theDate; // modification date/time -} MMSelectionRange; -#pragma options align=reset + int16_t unused1; // 0 (not used) + int16_t lineNum; // line to select (< 0 to specify range) + int32_t startRange; // start of selection range (if line < 0) + int32_t endRange; // end of selection range (if line < 0) + int32_t unused2; // 0 (not used) + int32_t theDate; // modification date/time +} MMXcodeSelectionRange; +#pragma pack(pop) // This is a private AppKit API gleaned from class-dump. @@ -694,9 +696,9 @@ fsEventCallback(ConstFSEventStreamRef streamRef, - (void)removeVimController:(id)controller { ASLogDebug(@"Remove Vim controller pid=%d id=%d (processingFlag=%d)", - [controller pid], [controller identifier], processingFlag); + [controller pid], [controller vimControllerId], processingFlag); - int idx = [vimControllers indexOfObject:controller]; + NSUInteger idx = [vimControllers indexOfObject:controller]; if (NSNotFound == idx) { ASLogDebug(@"Controller not found, probably due to duplicate removal"); return; @@ -1231,7 +1233,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, [vc release]; - return [vc identifier]; + return [vc vimControllerId]; } - (oneway void)processInput:(in bycopy NSArray *)queue @@ -1618,7 +1620,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, NSArray *queries = [[url query] componentsSeparatedByString:@"&"]; NSEnumerator *enumerator = [queries objectEnumerator]; NSString *param; - while( param = [enumerator nextObject] ) { + while ((param = [enumerator nextObject])) { NSArray *arr = [param componentsSeparatedByString:@"="]; if ([arr count] == 2) { [dict setValue:[[arr lastObject] @@ -1739,19 +1741,30 @@ fsEventCallback(ConstFSEventStreamRef streamRef, [desc paramDescriptorForKeyword:keyAEPosition]; if (xcodedesc) { NSRange range; - MMSelectionRange *sr = (MMSelectionRange*)[[xcodedesc data] bytes]; + NSData *data = [xcodedesc data]; + NSUInteger length = [data length]; - if (sr->lineNum < 0) { - // Should select a range of lines. - range.location = sr->startRange + 1; - range.length = sr->endRange - sr->startRange + 1; + if (length == sizeof(MMXcodeSelectionRange)) { + MMXcodeSelectionRange *sr = (MMXcodeSelectionRange*)[data bytes]; + ASLogDebug(@"Xcode selection range (%d,%d,%d,%d,%d,%d)", + sr->unused1, sr->lineNum, sr->startRange, sr->endRange, + sr->unused2, sr->theDate); + + if (sr->lineNum < 0) { + // Should select a range of lines. + range.location = sr->startRange + 1; + range.length = sr->endRange - sr->startRange + 1; + } else { + // Should only move cursor to a line. + range.location = sr->lineNum + 1; + range.length = 0; + } + + [dict setObject:NSStringFromRange(range) forKey:@"selectionRange"]; } else { - // Should only move cursor to a line. - range.location = sr->lineNum + 1; - range.length = 0; + ASLogErr(@"Xcode selection range size mismatch! got=%d expected=%d", + length, sizeof(MMXcodeSelectionRange)); } - - [dict setObject:NSStringFromRange(range) forKey:@"selectionRange"]; } // 3. Extract Spotlight search text (if any) @@ -2266,7 +2279,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, int i = 0, count = [vimControllers count]; for (i = 0; i < count; ++i) { MMVimController *vc = [vimControllers objectAtIndex:i]; - if (ukey == [vc identifier]) { + if (ukey == [vc vimControllerId]) { [vc processInputQueue:[queues objectForKey:key]]; // !exceptions break; } @@ -2277,7 +2290,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, count = [cachedVimControllers count]; for (i = 0; i < count; ++i) { MMVimController *vc = [cachedVimControllers objectAtIndex:i]; - if (ukey == [vc identifier]) { + if (ukey == [vc vimControllerId]) { [vc processInputQueue:[queues objectForKey:key]]; // !exceptions break; } @@ -2305,7 +2318,8 @@ fsEventCallback(ConstFSEventStreamRef streamRef, - (void)addVimController:(MMVimController *)vc { - ASLogDebug(@"Add Vim controller pid=%d id=%d", [vc pid], [vc identifier]); + ASLogDebug(@"Add Vim controller pid=%d id=%d", + [vc pid], [vc vimControllerId]); int pid = [vc pid]; NSNumber *pidKey = [NSNumber numberWithInt:pid]; diff --git a/src/MacVim/MMTextStorage.h b/src/MacVim/MMTextStorage.h index c75c27dfd4..c87d6b330d 100644 --- a/src/MacVim/MMTextStorage.h +++ b/src/MacVim/MMTextStorage.h @@ -48,7 +48,7 @@ typedef struct { } - (NSString *)string; -- (NSDictionary *)attributesAtIndex:(unsigned)index +- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange; - (id)attribute:(NSString *)attrib atIndex:(unsigned)index effectiveRange:(NSRangePointer)range; @@ -89,7 +89,7 @@ typedef struct { - (NSSize)cellSize; - (NSRect)rectForRowsInRange:(NSRange)range; - (NSRect)rectForColumnsInRange:(NSRange)range; -- (unsigned)characterIndexForRow:(int)row column:(int)col; +- (NSUInteger)characterIndexForRow:(int)row column:(int)col; - (BOOL)resizeToFitSize:(NSSize)size; - (NSSize)fitToSize:(NSSize)size; - (NSSize)fitToSize:(NSSize)size rows:(int *)rows columns:(int *)columns; diff --git a/src/MacVim/MMTextStorage.m b/src/MacVim/MMTextStorage.m index 0d272b2bde..0c6408dc9b 100644 --- a/src/MacVim/MMTextStorage.m +++ b/src/MacVim/MMTextStorage.m @@ -112,7 +112,7 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; return [attribString string]; } -- (NSDictionary *)attributesAtIndex:(unsigned)index +- (NSDictionary *)attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)range { if (index >= [attribString length]) { @@ -777,7 +777,7 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; - (NSRect)rectForRowsInRange:(NSRange)range { - NSRect rect = { 0, 0, 0, 0 }; + NSRect rect = { {0, 0}, {0, 0} }; unsigned start = range.location > maxRows ? maxRows : range.location; unsigned length = range.length; @@ -792,7 +792,7 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; - (NSRect)rectForColumnsInRange:(NSRange)range { - NSRect rect = { 0, 0, 0, 0 }; + NSRect rect = { {0, 0}, {0, 0} }; unsigned start = range.location > maxColumns ? maxColumns : range.location; unsigned length = range.length; @@ -805,7 +805,7 @@ static NSString *MMWideCharacterAttributeName = @"MMWideChar"; return rect; } -- (unsigned)characterIndexForRow:(int)row column:(int)col +- (NSUInteger)characterIndexForRow:(int)row column:(int)col { int cells = 1; NSRange range = [self charRangeForRow:row column:&col cells:&cells]; diff --git a/src/MacVim/MMTypesetter.m b/src/MacVim/MMTypesetter.m index dd1bc5cbff..41fa6d448d 100644 --- a/src/MacVim/MMTypesetter.m +++ b/src/MacVim/MMTypesetter.m @@ -26,7 +26,7 @@ - (void)willSetLineFragmentRect:(NSRectPointer)lineRect forGlyphRange:(NSRange)glyphRange usedRect:(NSRectPointer)usedRect - baselineOffset:(float *)baselineOffset + baselineOffset:(CGFloat *)baselineOffset { MMTextStorage *ts = (MMTextStorage*)[[self layoutManager] textStorage]; float h = [ts cellSize].height; @@ -103,9 +103,9 @@ // height and that EOL glyphs are hidden. // - (void)layoutGlyphsInLayoutManager:(NSLayoutManager *)lm - startingAtGlyphIndex:(unsigned)startGlyphIdx - maxNumberOfLineFragments:(unsigned)maxNumLines - nextGlyphIndex:(unsigned *)nextGlyph + startingAtGlyphIndex:(NSUInteger)startGlyphIdx + maxNumberOfLineFragments:(NSUInteger)maxNumLines + nextGlyphIndex:(NSUInteger *)nextGlyph { // TODO: Check that it really is an MMTextStorage? MMTextStorage *ts = (MMTextStorage*)[lm textStorage]; @@ -160,8 +160,8 @@ NSRange lineRange = { lineIdx, 0 }; NSRange glyphRange = { startGlyphIdx, 0 }; - NSRect lineRect = { 0, line*cellSize.height, - [ts actualColumns]*cellSize.width, cellSize.height }; + NSRect lineRect = { {0, line*cellSize.height}, + {[ts actualColumns]*cellSize.width, cellSize.height} }; int endLine = line + maxNumLines; if (endLine > actualRows) endLine = actualRows; diff --git a/src/MacVim/MMVimController.h b/src/MacVim/MMVimController.h index be2d3ec1a9..982d2d2ae8 100644 --- a/src/MacVim/MMVimController.h +++ b/src/MacVim/MMVimController.h @@ -44,7 +44,7 @@ } - (id)initWithBackend:(id)backend pid:(int)processIdentifier; -- (unsigned)identifier; +- (unsigned)vimControllerId; - (id)backendProxy; - (int)pid; - (void)setServerName:(NSString *)name; diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index bd4d5a0950..8c90550ef4 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -184,7 +184,7 @@ static BOOL isUnsafeMessage(int msgid); [super dealloc]; } -- (unsigned)identifier +- (unsigned)vimControllerId { return identifier; } @@ -986,7 +986,7 @@ static BOOL isUnsafeMessage(int msgid); if (!toolbar) { // NOTE! Each toolbar must have a unique identifier, else each // window will have the same toolbar. - NSString *ident = [NSString stringWithFormat:@"%d", (int)self]; + NSString *ident = [NSString stringWithFormat:@"%d", identifier]; toolbar = [[NSToolbar alloc] initWithIdentifier:ident]; [toolbar setShowsBaselineSeparator:NO]; @@ -1106,7 +1106,7 @@ static BOOL isUnsafeMessage(int msgid); // Only remove toolbar items, never actually remove the toolbar // itself or strange things may happen. if ([desc count] == 2) { - int idx = [toolbar indexOfItemWithItemIdentifier:title]; + NSUInteger idx = [toolbar indexOfItemWithItemIdentifier:title]; if (idx != NSNotFound) [toolbar removeItemAtIndex:idx]; } diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index deeab7d865..c9979ffe4a 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -43,7 +43,7 @@ enum { NSRange range; } - (id)initWithIdentifier:(int32_t)ident type:(int)type; -- (int32_t)identifier; +- (int32_t)scrollerId; - (int)type; - (NSRange)range; - (void)setRange:(NSRange)newRange; @@ -55,7 +55,7 @@ enum { - (BOOL)leftScrollbarVisible; - (BOOL)rightScrollbarVisible; - (void)placeScrollbars; -- (int)representedIndexOfTabViewItem:(NSTabViewItem *)tvi; +- (NSUInteger)representedIndexOfTabViewItem:(NSTabViewItem *)tvi; - (MMScroller *)scrollbarForIdentifier:(int32_t)ident index:(unsigned *)idx; - (NSSize)vimViewSizeForTextViewSize:(NSSize)textViewSize; - (NSRect)textViewRectForVimViewSize:(NSSize)contentSize; @@ -430,7 +430,7 @@ enum { - (void)scroll:(id)sender { NSMutableData *data = [NSMutableData data]; - int32_t ident = [(MMScroller*)sender identifier]; + int32_t ident = [(MMScroller*)sender scrollerId]; int hitPart = [sender hitPart]; float value = [sender floatValue]; @@ -478,9 +478,10 @@ enum { // flag is set when Vim initiated the selection. if (!vimTaskSelectedTab) { // Propagate the selection message to Vim. - int idx = [self representedIndexOfTabViewItem:tabViewItem]; + NSUInteger idx = [self representedIndexOfTabViewItem:tabViewItem]; if (NSNotFound != idx) { - NSData *data = [NSData dataWithBytes:&idx length:sizeof(int)]; + int i = (int)idx; // HACK! Never more than MAXINT tabs?! + NSData *data = [NSData dataWithBytes:&i length:sizeof(int)]; [vimController sendMessage:SelectTabMsgID data:data]; } } @@ -496,8 +497,9 @@ enum { // HACK! This method is only called when the user clicks the close button // on the tab. Instead of letting the tab bar close the tab, we return NO // and pass a message on to Vim to let it handle the closing. - int idx = [self representedIndexOfTabViewItem:tabViewItem]; - NSData *data = [NSData dataWithBytes:&idx length:sizeof(int)]; + NSUInteger idx = [self representedIndexOfTabViewItem:tabViewItem]; + int i = (int)idx; // HACK! Never more than MAXINT tabs?! + NSData *data = [NSData dataWithBytes:&i length:sizeof(int)]; [vimController sendMessage:CloseTabMsgID data:data]; return NO; @@ -514,7 +516,7 @@ enum { - (NSDragOperation)tabBarControl:(PSMTabBarControl *)theTabBarControl draggingEntered:(id )sender - forTabAtIndex:(unsigned)tabIndex + forTabAtIndex:(NSUInteger)tabIndex { NSPasteboard *pb = [sender draggingPasteboard]; return [[pb types] containsObject:NSFilenamesPboardType] @@ -524,7 +526,7 @@ enum { - (BOOL)tabBarControl:(PSMTabBarControl *)theTabBarControl performDragOperation:(id )sender - forTabAtIndex:(unsigned)tabIndex + forTabAtIndex:(NSUInteger)tabIndex { NSPasteboard *pb = [sender draggingPasteboard]; if ([[pb types] containsObject:NSFilenamesPboardType]) { @@ -748,7 +750,7 @@ enum { } } -- (int)representedIndexOfTabViewItem:(NSTabViewItem *)tvi +- (NSUInteger)representedIndexOfTabViewItem:(NSTabViewItem *)tvi { NSArray *tabViewItems = [[self tabBarControl] representedTabViewItems]; return [tabViewItems indexOfObject:tvi]; @@ -759,7 +761,7 @@ enum { unsigned i, count = [scrollbars count]; for (i = 0; i < count; ++i) { MMScroller *scroller = [scrollbars objectAtIndex:i]; - if ([scroller identifier] == ident) { + if ([scroller scrollerId] == ident) { if (idx) *idx = i; return scroller; } @@ -787,7 +789,7 @@ enum { - (NSRect)textViewRectForVimViewSize:(NSSize)contentSize { - NSRect rect = { 0, 0, contentSize.width, contentSize.height }; + NSRect rect = { {0, 0}, {contentSize.width, contentSize.height} }; if (![[self tabBarControl] isHidden]) rect.size.height -= [[self tabBarControl] frame].size.height; @@ -892,7 +894,7 @@ enum { return self; } -- (int32_t)identifier +- (int32_t)scrollerId { return identifier; } diff --git a/src/MacVim/MMWindow.h b/src/MacVim/MMWindow.h index 69eb3fb147..246656374f 100644 --- a/src/MacVim/MMWindow.h +++ b/src/MacVim/MMWindow.h @@ -18,7 +18,7 @@ } - (id)initWithContentRect:(NSRect)rect - styleMask:(unsigned int)style + styleMask:(NSUInteger)style backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag; diff --git a/src/MacVim/MMWindow.m b/src/MacVim/MMWindow.m index 9644a511c9..25c8e7d8bb 100644 --- a/src/MacVim/MMWindow.m +++ b/src/MacVim/MMWindow.m @@ -35,7 +35,7 @@ @implementation MMWindow - (id)initWithContentRect:(NSRect)rect - styleMask:(unsigned int)style + styleMask:(NSUInteger)style backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { @@ -47,7 +47,7 @@ [self setReleasedWhenClosed:NO]; - NSRect tabSepRect = { 0, rect.size.height - 1, rect.size.width, 1 }; + NSRect tabSepRect = { {0, rect.size.height - 1}, {rect.size.width, 1} }; tablineSeparator = [[NSBox alloc] initWithFrame:tabSepRect]; [tablineSeparator setBoxType:NSBoxSeparator]; diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index c650870747..daac869c80 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -116,8 +116,8 @@ enum { @interface NSToolbar (MMExtras) -- (int)indexOfItemWithItemIdentifier:(NSString *)identifier; -- (NSToolbarItem *)itemAtIndex:(int)idx; +- (NSUInteger)indexOfItemWithItemIdentifier:(NSString *)identifier; +- (NSToolbarItem *)itemAtIndex:(NSUInteger)idx; - (NSToolbarItem *)itemWithItemIdentifier:(NSString *)identifier; @end @@ -128,7 +128,8 @@ enum { @interface NSNumber (MMExtras) -- (int)tag; +// HACK to allow font size to be changed via menu (bound to Cmd+/Cmd-) +- (NSInteger)tag; @end diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index 5e60cf9b98..3271c0549b 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -203,10 +203,10 @@ NSString *MMUseInlineImKey = @"MMUseInlineIm"; @implementation NSToolbar (MMExtras) -- (int)indexOfItemWithItemIdentifier:(NSString *)identifier +- (NSUInteger)indexOfItemWithItemIdentifier:(NSString *)identifier { NSArray *items = [self items]; - int i, count = [items count]; + NSUInteger i, count = [items count]; for (i = 0; i < count; ++i) { id item = [items objectAtIndex:i]; if ([[item itemIdentifier] isEqual:identifier]) @@ -216,7 +216,7 @@ NSString *MMUseInlineImKey = @"MMUseInlineIm"; return NSNotFound; } -- (NSToolbarItem *)itemAtIndex:(int)idx +- (NSToolbarItem *)itemAtIndex:(NSUInteger)idx { NSArray *items = [self items]; if (idx < 0 || idx >= [items count]) @@ -227,7 +227,7 @@ NSString *MMUseInlineImKey = @"MMUseInlineIm"; - (NSToolbarItem *)itemWithItemIdentifier:(NSString *)identifier { - int idx = [self indexOfItemWithItemIdentifier:identifier]; + NSUInteger idx = [self indexOfItemWithItemIdentifier:identifier]; return idx != NSNotFound ? [self itemAtIndex:idx] : nil; } @@ -243,7 +243,7 @@ NSString *MMUseInlineImKey = @"MMUseInlineIm"; NSArray *existingItems = [self tabViewItems]; NSEnumerator *e = [existingItems objectEnumerator]; NSTabViewItem *item; - while (item = [e nextObject]){ + while ((item = [e nextObject])) { [self removeTabViewItem:item]; } } @@ -255,7 +255,8 @@ NSString *MMUseInlineImKey = @"MMUseInlineIm"; @implementation NSNumber (MMExtras) -- (int)tag +// HACK to allow font size to be changed via menu (bound to Cmd+/Cmd-) +- (NSInteger)tag { return [self intValue]; }