Skip to content

Commit

Permalink
Fix misc MacVim warnings and treat warnings as errors in CI
Browse files Browse the repository at this point in the history
In CI, turn on warnings as errors, but ignore deprecated warnings as we
are still using NSConnection right now and we won't be fixing that for
now. Don't turn on warnings as errors for development (similar to Vim
itself) / outside of CI, because it could make it annoying to build
MacVim locally and across different Xcode versions.

Fix the misc warnings. A lot of 64/32-bit warnings due to careless casts
of NSInteger/NSUInteger.

Also fix up MacVimTests so the waiting for Vim window is more robust
when waiting for 2 windows in a row in vim tutor. Otherwise sometimes
the tests would randomly fail in CI.
  • Loading branch information
ychin committed Nov 5, 2023
1 parent 0f293b5 commit cf4e252
Show file tree
Hide file tree
Showing 30 changed files with 264 additions and 269 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-macvim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
./configure "${CONFOPT[@]}" --enable-fail-if-missing
sed -i.bak -f ci/config.mk.sed -f ci/config.mk.clang.sed src/auto/config.mk
sed -i.bak -f ci/config.mk.sed -f ci/config.mk.clang.sed -f ci/config.mk.xcode.sed src/auto/config.mk
if clang --version | grep -qs '^Apple clang version \(1[3-9]\|[2-9]\d\)\.'; then
sed -i.bak -f ci/config.mk.clang-12.sed src/auto/config.mk
fi
Expand Down
1 change: 1 addition & 0 deletions ci/config.mk.xcode.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/^XCODEFLAGS[[:blank:]]*=/s/$/ GCC_TREAT_WARNINGS_AS_ERRORS="YES" GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS="NO"/
64 changes: 31 additions & 33 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender

// The user default MMUntitledWindow can be set to control whether an
// untitled window should open on 'Open' and 'Reopen' events.
int untitledWindowFlag = [ud integerForKey:MMUntitledWindowKey];
NSInteger untitledWindowFlag = [ud integerForKey:MMUntitledWindowKey];

BOOL isAppOpenEvent = [desc eventID] == kAEOpenApplication;
if (isAppOpenEvent && (untitledWindowFlag & MMUntitledWindowOnOpen) == 0)
Expand Down Expand Up @@ -700,7 +700,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:
boolForKey:MMSuppressTerminationAlertKey]) {
// No unmodified buffers, but give a warning if there are multiple
// windows and/or tabs open.
int numWindows = [vimControllers count];
int numWindows = (int)[vimControllers count];
int numTabs = 0;

// Count the number of open tabs
Expand Down Expand Up @@ -1065,7 +1065,7 @@ - (void)refreshMainMenu
[fileMenu removeItemAtIndex:dummyIdx];

NSMenu *recentFilesParentMenu = [recentFilesMenuItem menu];
int idx = [recentFilesParentMenu indexOfItem:recentFilesMenuItem];
NSInteger idx = [recentFilesParentMenu indexOfItem:recentFilesMenuItem];
if (idx >= 0) {
[[recentFilesMenuItem retain] autorelease];
[recentFilesParentMenu removeItemAtIndex:idx];
Expand Down Expand Up @@ -1133,7 +1133,7 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args

// The meaning of "layout" is defined by the WIN_* defines in main.c.
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
int layout = [ud integerForKey:MMOpenLayoutKey];
NSInteger layout = [ud integerForKey:MMOpenLayoutKey];
BOOL splitVert = [ud boolForKey:MMVerticalSplitKey];
BOOL openInCurrentWindow = [ud boolForKey:MMOpenInCurrentWindowKey];

Expand Down Expand Up @@ -1166,7 +1166,7 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
// selection will be lost when selectionRange is set.
NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys:
firstFile, @"filename",
[NSNumber numberWithInt:layout], @"layout",
[NSNumber numberWithInt:(int)layout], @"layout",
nil];
[vc sendMessage:SelectAndFocusOpenedFileMsgID data:[args dictionaryAsData]];
}
Expand All @@ -1188,7 +1188,7 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
// b) Open any remaining files
//

[arguments setObject:[NSNumber numberWithInt:layout] forKey:@"layout"];
[arguments setObject:[NSNumber numberWithInt:(int)layout] forKey:@"layout"];
[arguments setObject:filenames forKey:@"filenames"];
// (Indicate that files should be opened from now on.)
[arguments setObject:[NSNumber numberWithBool:NO] forKey:@"dontOpen"];
Expand All @@ -1202,7 +1202,7 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
}

BOOL openOk = YES;
int numFiles = [filenames count];
int numFiles = (int)[filenames count];
if (MMLayoutWindows == layout && numFiles > 1) {
// Open one file at a time in a new window, but don't open too many at
// once (at most cap+1 windows will open). If the user has increased
Expand Down Expand Up @@ -1246,7 +1246,7 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args

- (void)refreshAllAppearances
{
unsigned count = [vimControllers count];
const NSUInteger count = [vimControllers count];
for (unsigned i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
[vc.windowController refreshApperanceMode];
Expand All @@ -1256,7 +1256,7 @@ - (void)refreshAllAppearances
/// Refresh all Vim text views' fonts.
- (void)refreshAllFonts
{
unsigned count = [vimControllers count];
const NSUInteger count = [vimControllers count];
for (unsigned i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
[vc.windowController refreshFonts];
Expand All @@ -1267,7 +1267,7 @@ - (void)refreshAllFonts
/// and resize the windows to match the constraints.
- (void)refreshAllResizeConstraints
{
const unsigned count = [vimControllers count];
const NSUInteger count = [vimControllers count];
for (unsigned i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
[vc.windowController updateResizeConstraints:YES];
Expand All @@ -1278,7 +1278,7 @@ - (void)refreshAllResizeConstraints
/// cmdline alignment properties to make sure they are pinned properly.
- (void)refreshAllTextViews
{
unsigned count = [vimControllers count];
const NSUInteger count = [vimControllers count];
for (unsigned i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
[vc.windowController.vimView.textView updateCmdlineRow];
Expand Down Expand Up @@ -1408,7 +1408,7 @@ - (IBAction)selectNextWindow:(id)sender
{
ASLogDebug(@"Select next window");

unsigned i, count = [vimControllers count];
NSUInteger i, count = [vimControllers count];
if (!count) return;

NSWindow *keyWindow = [NSApp keyWindow];
Expand All @@ -1430,7 +1430,7 @@ - (IBAction)selectPreviousWindow:(id)sender
{
ASLogDebug(@"Select previous window");

unsigned i, count = [vimControllers count];
NSUInteger i, count = [vimControllers count];
if (!count) return;

NSWindow *keyWindow = [NSApp keyWindow];
Expand Down Expand Up @@ -1542,7 +1542,7 @@ - (IBAction)coreTextButtonClicked:(id)sender
// any new Vim process will pick up on the changed setting.
CFPreferencesSetAppValue(
(CFStringRef)MMRendererKey,
(CFPropertyListRef)[NSNumber numberWithInt:renderer],
(CFPropertyListRef)[NSNumber numberWithInt:(int)renderer],
kCFPreferencesCurrentApplication);
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);

Expand Down Expand Up @@ -1578,7 +1578,7 @@ - (MMVimController *)keyVimController
{
NSWindow *keyWindow = [NSApp keyWindow];
if (keyWindow) {
unsigned i, count = [vimControllers count];
NSUInteger i, count = [vimControllers count];
for (i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
if ([[[vc windowController] window] isEqual:keyWindow])
Expand Down Expand Up @@ -1660,7 +1660,7 @@ - (NSArray *)serverList
{
NSMutableArray *array = [NSMutableArray array];

unsigned i, count = [vimControllers count];
NSUInteger i, count = [vimControllers count];
for (i = 0; i < count; ++i) {
MMVimController *controller = [vimControllers objectAtIndex:i];
if ([controller serverName])
Expand Down Expand Up @@ -1931,15 +1931,15 @@ - (MMVimController *)topmostVimController
NSEnumerator *e = [[NSApp orderedWindows] objectEnumerator];
id window;
while ((window = [e nextObject]) && [window isVisible]) {
unsigned i, count = [vimControllers count];
NSUInteger i, count = [vimControllers count];
for (i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
if ([[[vc windowController] window] isEqual:window])
return vc;
}
}

unsigned i, count = [vimControllers count];
NSUInteger i, count = [vimControllers count];
for (i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
if ([[[vc windowController] window] isVisible]) {
Expand Down Expand Up @@ -2016,7 +2016,7 @@ - (NSArray *)filterFilesAndNotify:(NSArray *)filenames

NSString *firstMissingFile = nil;
NSMutableArray *files = [NSMutableArray array];
unsigned i, count = [filenames count];
NSUInteger i, count = [filenames count];

for (i = 0; i < count; ++i) {
NSString *name = [filenames objectAtIndex:i];
Expand Down Expand Up @@ -2076,7 +2076,7 @@ - (NSArray *)filterOpenFiles:(NSArray *)filenames
@"map([\"%@\"],\"bufloaded(v:val)\")",
[files componentsJoinedByString:@"\",\""]];

unsigned i, count = [vimControllers count];
NSUInteger i, count = [vimControllers count];
for (i = 0; i < count && [files count] > 0; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];

Expand Down Expand Up @@ -2428,12 +2428,12 @@ - (int)maxPreloadCacheSize
{
// The maximum number of Vim processes to keep in the cache can be
// controlled via the user default "MMPreloadCacheSize".
int maxCacheSize = [[NSUserDefaults standardUserDefaults]
NSInteger maxCacheSize = [[NSUserDefaults standardUserDefaults]
integerForKey:MMPreloadCacheSizeKey];
if (maxCacheSize < 0) maxCacheSize = 0;
else if (maxCacheSize > 10) maxCacheSize = 10;

return maxCacheSize;
return (int)maxCacheSize;
}

- (MMVimController *)takeVimControllerFromCache
Expand All @@ -2445,7 +2445,7 @@ - (MMVimController *)takeVimControllerFromCache
// This method may return nil even though the cache might be non-empty; the
// caller should handle this by starting a new Vim process.

int i, count = [cachedVimControllers count];
NSUInteger i, count = [cachedVimControllers count];
if (0 == count) return nil;

// Locate the first Vim controller with up-to-date rc-files sourced.
Expand All @@ -2461,7 +2461,7 @@ - (MMVimController *)takeVimControllerFromCache
// Clear out cache entries whose vimrc/gvimrc files were sourced before
// the latest modification date for those files. This ensures that the
// latest rc-files are always sourced for new windows.
[self clearPreloadCacheWithCount:i];
[self clearPreloadCacheWithCount:(int)i];
}

if ([cachedVimControllers count] == 0) {
Expand Down Expand Up @@ -2497,7 +2497,7 @@ - (void)clearPreloadCacheWithCount:(int)count
return;

if (count < 0)
count = [cachedVimControllers count];
count = (int)[cachedVimControllers count];

// Make sure the preloaded Vim processes get killed or they'll just hang
// around being useless until MacVim is terminated.
Expand Down Expand Up @@ -2618,9 +2618,7 @@ - (void)startWatchingVimDir
(CFArrayRef)pathsToWatch, kFSEventStreamEventIdSinceNow,
MMEventStreamLatency, kFSEventStreamCreateFlagNone);

FSEventStreamScheduleWithRunLoop(fsEventStream,
[[NSRunLoop currentRunLoop] getCFRunLoop],
kCFRunLoopDefaultMode);
FSEventStreamSetDispatchQueue(fsEventStream, dispatch_get_main_queue());

FSEventStreamStart(fsEventStream);
ASLogDebug(@"Started FS event stream");
Expand Down Expand Up @@ -2734,9 +2732,9 @@ - (int)executeInLoginShell:(NSString *)path arguments:(NSArray *)args

// Send input to execute to the child process
[input appendString:@"\n"];
int bytes = [input lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
NSUInteger bytes = [input lengthOfBytesUsingEncoding:NSUTF8StringEncoding];

if (write(ds[1], [input UTF8String], bytes) != bytes) return -1;
if (write(ds[1], [input UTF8String], (size_t)bytes) != (ssize_t)bytes) return -1;
if (close(ds[1]) == -1) return -1;

++numChildProcesses;
Expand Down Expand Up @@ -2797,7 +2795,7 @@ - (void)processInputQueues:(id)sender
NSNumber *key;
while ((key = [e nextObject])) {
unsigned long ukey = [key unsignedLongValue];
int i = 0, count = [vimControllers count];
NSUInteger i = 0, count = [vimControllers count];
for (i = 0; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
if (ukey == [vc vimControllerId]) {
Expand Down Expand Up @@ -2882,7 +2880,7 @@ - (NSDictionary *)convertVimControllerArguments:(NSDictionary *)args
*cmdline = nil;

NSArray *filenames = [args objectForKey:@"filenames"];
int numFiles = filenames ? [filenames count] : 0;
NSUInteger numFiles = filenames ? [filenames count] : 0;
BOOL openFiles = ![[args objectForKey:@"dontOpen"] boolValue];

if (numFiles <= 0 || !openFiles)
Expand Down Expand Up @@ -3029,7 +3027,7 @@ - (void)removeInputSourceChangedObserver

- (void)inputSourceChanged:(NSNotification *)notification
{
unsigned i, count = [vimControllers count];
NSUInteger i, count = [vimControllers count];
for (i = 0; i < count; ++i) {
MMVimController *controller = [vimControllers objectAtIndex:i];
MMWindowController *wc = [controller windowController];
Expand Down
2 changes: 1 addition & 1 deletion src/MacVim/MMApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ @implementation MMApplication
- (void)sendEvent:(NSEvent *)event
{
NSEventType type = [event type];
unsigned flags = [event modifierFlags];
NSUInteger flags = [event modifierFlags];

// HACK! Intercept 'help' key presses and clear the 'help key flag', else
// Cocoa turns the mouse cursor into a question mark and goes into 'context
Expand Down
28 changes: 14 additions & 14 deletions src/MacVim/MMBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
static unsigned MMServerMax = 1000;

// TODO: Move to separate file.
static int eventModifierFlagsToVimModMask(int modifierFlags);
static int eventModifierFlagsToVimMouseModMask(int modifierFlags);
static unsigned eventModifierFlagsToVimModMask(unsigned modifierFlags);
static unsigned eventModifierFlagsToVimMouseModMask(unsigned modifierFlags);
static int eventButtonNumberToVimMouseButton(int buttonNumber);

// In gui_macvim.m
Expand Down Expand Up @@ -2081,7 +2081,7 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data

int row = *((int*)bytes); bytes += sizeof(int);
int col = *((int*)bytes); bytes += sizeof(int);
int flags = *((int*)bytes); bytes += sizeof(int);
unsigned flags = *((unsigned*)bytes); bytes += sizeof(unsigned);
float dy = *((float*)bytes); bytes += sizeof(float);
float dx = *((float*)bytes); bytes += sizeof(float);

Expand Down Expand Up @@ -2122,7 +2122,7 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data
int row = *((int*)bytes); bytes += sizeof(int);
int col = *((int*)bytes); bytes += sizeof(int);
int button = *((int*)bytes); bytes += sizeof(int);
int flags = *((int*)bytes); bytes += sizeof(int);
unsigned flags = *((unsigned*)bytes); bytes += sizeof(unsigned);
int repeat = *((int*)bytes); bytes += sizeof(int);

button = eventButtonNumberToVimMouseButton(button);
Expand All @@ -2136,7 +2136,7 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data

int row = *((int*)bytes); bytes += sizeof(int);
int col = *((int*)bytes); bytes += sizeof(int);
int flags = *((int*)bytes); bytes += sizeof(int);
unsigned flags = *((unsigned*)bytes); bytes += sizeof(unsigned);

flags = eventModifierFlagsToVimMouseModMask(flags);

Expand All @@ -2147,7 +2147,7 @@ - (void)handleInputEvent:(int)msgid data:(NSData *)data

int row = *((int*)bytes); bytes += sizeof(int);
int col = *((int*)bytes); bytes += sizeof(int);
int flags = *((int*)bytes); bytes += sizeof(int);
unsigned flags = *((unsigned*)bytes); bytes += sizeof(unsigned);

flags = eventModifierFlagsToVimMouseModMask(flags);

Expand Down Expand Up @@ -2607,7 +2607,7 @@ - (void)handleScrollbarEvent:(NSData *)data

const void *bytes = [data bytes];
int32_t ident = *((int32_t*)bytes); bytes += sizeof(int32_t);
int hitPart = *((int*)bytes); bytes += sizeof(int);
unsigned hitPart = *((unsigned*)bytes); bytes += sizeof(unsigned);
float fval = *((float*)bytes); bytes += sizeof(float);
scrollbar_T *sb = gui_find_scrollbar(ident);

Expand Down Expand Up @@ -2765,7 +2765,7 @@ - (void)handleDropString:(NSData *)data
#ifdef FEAT_DND
char_u dropkey[3] = { CSI, KS_EXTRA, (char_u)KE_DROP };
const void *bytes = [data bytes];
int len = *((int*)bytes); bytes += sizeof(int);
int len = *((int*)bytes); bytes += sizeof(int); // unused
NSMutableString *string = [NSMutableString stringWithUTF8String:bytes];

// Replace unrecognized end-of-line sequences with \x0a (line feed).
Expand All @@ -2778,7 +2778,7 @@ - (void)handleDropString:(NSData *)data
options:0 range:range];
}

len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
len = (int)[string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
char_u *s = (char_u*)[string UTF8String];
if (input_conv.vc_type != CONV_NONE)
s = string_convert(&input_conv, s, &len);
Expand Down Expand Up @@ -3517,9 +3517,9 @@ - (void)handleMarkedText:(NSData *)data
- (void)handleGesture:(NSData *)data
{
const void *bytes = [data bytes];
int flags = *((int*)bytes); bytes += sizeof(int);
unsigned flags = *((int*)bytes); bytes += sizeof(int);
int gesture = *((int*)bytes); bytes += sizeof(int);
int modifiers = eventModifierFlagsToVimModMask(flags);
unsigned modifiers = eventModifierFlagsToVimModMask(flags);
char_u string[6];

string[3] = CSI;
Expand Down Expand Up @@ -3761,7 +3761,7 @@ - (NSComparisonResult)serverNameCompare:(NSString *)string



static int eventModifierFlagsToVimModMask(int modifierFlags)
static unsigned eventModifierFlagsToVimModMask(unsigned modifierFlags)
{
int modMask = 0;

Expand All @@ -3777,9 +3777,9 @@ static int eventModifierFlagsToVimModMask(int modifierFlags)
return modMask;
}

static int eventModifierFlagsToVimMouseModMask(int modifierFlags)
static unsigned eventModifierFlagsToVimMouseModMask(unsigned modifierFlags)
{
int modMask = 0;
unsigned modMask = 0;

if (modifierFlags & NSEventModifierFlagShift)
modMask |= MOUSE_SHIFT;
Expand Down
Loading

0 comments on commit cf4e252

Please sign in to comment.