Date: Sat, 5 Apr 2008 19:54:28 -0700 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sun, 13 Apr 2008 04:50:17 +0000
branchSDL-1.2
changeset 4145f00b6b19d57e
parent 4144 904defc0792e
child 4146 dc726b233f5f
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
     1.1 --- a/src/main/macosx/SDLMain.m	Mon Mar 31 05:27:21 2008 +0000
     1.2 +++ b/src/main/macosx/SDLMain.m	Sun Apr 13 04:50:17 2008 +0000
     1.3 @@ -5,10 +5,10 @@
     1.4      Feel free to customize this file to suit your needs
     1.5  */
     1.6  
     1.7 -#import "SDL.h"
     1.8 -#import "SDLMain.h"
     1.9 -#import <sys/param.h> /* for MAXPATHLEN */
    1.10 -#import <unistd.h>
    1.11 +#include "SDL.h"
    1.12 +#include "SDLMain.h"
    1.13 +#include <sys/param.h> /* for MAXPATHLEN */
    1.14 +#include <unistd.h>
    1.15  
    1.16  /* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
    1.17   but the method still is there and works. To avoid warnings, we declare
    1.18 @@ -43,11 +43,11 @@
    1.19  
    1.20  static NSString *getApplicationName(void)
    1.21  {
    1.22 -    NSDictionary *dict;
    1.23 +    const NSDictionary *dict;
    1.24      NSString *appName = 0;
    1.25  
    1.26      /* Determine the application name */
    1.27 -    dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
    1.28 +    dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
    1.29      if (dict)
    1.30          appName = [dict objectForKey: @"CFBundleName"];
    1.31      
    1.32 @@ -87,15 +87,14 @@
    1.33      if (shouldChdir)
    1.34      {
    1.35          char parentdir[MAXPATHLEN];
    1.36 -		CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    1.37 -		CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
    1.38 -		if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
    1.39 -	        assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
    1.40 -		}
    1.41 -		CFRelease(url);
    1.42 -		CFRelease(url2);
    1.43 -	}
    1.44 -
    1.45 +        CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    1.46 +        CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
    1.47 +        if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
    1.48 +            chdir(parentdir);   /* chdir to the binary app's parent */
    1.49 +        }
    1.50 +        CFRelease(url);
    1.51 +        CFRelease(url2);
    1.52 +    }
    1.53  }
    1.54  
    1.55  #if SDL_USE_NIB_FILE
    1.56 @@ -319,7 +318,7 @@
    1.57      NSString *result;
    1.58  
    1.59      bufferSize = selfLen + aStringLen - aRange.length;
    1.60 -    buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
    1.61 +    buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
    1.62      
    1.63      /* Get first part into buffer */
    1.64      localRange.location = 0;