From 9cb048f0adae86bbb04e0e0bdfde2229cfb58324 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 13 Apr 2008 04:50:17 +0000 Subject: [PATCH] Date: Sat, 5 Apr 2008 19:54:28 -0700 From: "Chris Peterson" To: sdl@lists.libsdl.org Subject: [SDL] [PATCH] SDLMain.m: fix a bug and some warnings for Mac OS X Here are some small fixes for the src/main/macosx/SDLMain.m source file used by Mac OS X apps: 1. setupWorkingDirectory() called chdir() within an assert(), which gets compiled out in non-debug builds. 2. When some of gcc's optional warnings are enabled, it complains about some implicit casts and the use of #import in SDLMain.m. --- src/main/macosx/SDLMain.m | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/macosx/SDLMain.m b/src/main/macosx/SDLMain.m index 2eaa1c11e..b065a2009 100644 --- a/src/main/macosx/SDLMain.m +++ b/src/main/macosx/SDLMain.m @@ -5,10 +5,10 @@ Feel free to customize this file to suit your needs */ -#import "SDL.h" -#import "SDLMain.h" -#import /* for MAXPATHLEN */ -#import +#include "SDL.h" +#include "SDLMain.h" +#include /* for MAXPATHLEN */ +#include /* For some reaon, Apple removed setAppleMenu from the headers in 10.4, but the method still is there and works. To avoid warnings, we declare @@ -43,11 +43,11 @@ - (void)setAppleMenu:(NSMenu *)menu; static NSString *getApplicationName(void) { - NSDictionary *dict; + const NSDictionary *dict; NSString *appName = 0; /* Determine the application name */ - dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); + dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); if (dict) appName = [dict objectForKey: @"CFBundleName"]; @@ -87,15 +87,14 @@ - (void) setupWorkingDirectory:(BOOL)shouldChdir if (shouldChdir) { char parentdir[MAXPATHLEN]; - CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); - CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); - if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) { - assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ - } - CFRelease(url); - CFRelease(url2); - } - + CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); + if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) { + chdir(parentdir); /* chdir to the binary app's parent */ + } + CFRelease(url); + CFRelease(url2); + } } #if SDL_USE_NIB_FILE @@ -319,7 +318,7 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString NSString *result; bufferSize = selfLen + aStringLen - aRange.length; - buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar)); + buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar)); /* Get first part into buffer */ localRange.location = 0;