1. bugreport
  2. py2app

Commits

rona...@mac.com  committed 1dd9a94

* Add maintainer info to setup.py that points to me
instead of Bob as I do most (all?) maintainance
these days.

* Ensure that py2app works with a python loaded
from a virtualenv (lightly tested and using a patched
version of virtualenv).

* Add prebuilt executables for a number of build variants
of python, which makes it possible to build 64-bit
executables without patching py2app.

* Patch the TinyTinyEdit example to display information
about the python interpreter in "empty" documents,
used to verify that a 3-way build actually starts in
64-bit mode.

  • Participants
  • Parent commits dddcd83
  • Branches default

Comments (0)

Files changed (16)

File NEWS.txt

View file
-py2app 0.4.4
-------------
+py2app 0.5
+----------
 
-py2app 0.4.4 is a ...
+py2app 0.5 is a minor feature release.
 
 Features:
 - Add support for the ``--with-framework-name`` option of Python's
   configure script, that is: py2app now also works when the Python
   framework is not named 'Python.framework'.
+- Add support for various build flavours of Python (32bit, 3-way, ...)
+- py2app now actually works for me (ronaldoussoren@mac.com) with a 
+  python interpreter in a virtualenv environment.
 
 Bug fixes:
 - Use modern API's in the alias-build bootstrap code, without
 - Try both 'import Image' and 'from PIL import Image' in the PIL
   recipe.
   (Patch contributed by Christopher Barker)
-- Fix for broken alias builds on MacOSX 10.6 (Snow Leopard)
-  (Patch contributed by Jamer R Eagan)
+- The stub executable now works for 64-bit application bundles
+- (Lowlevel) The application stub was rewritten to use
+  ``dlopen`` instead of ``dyld`` APIs. This removes deprecation
+  warnings during compilation.
 
 py2app 0.4.3
 ------------

File examples/PyObjC/TinyTinyEdit/TinyTinyEdit.py

View file
 
 from Cocoa import *
 from PyObjCTools import AppHelper
+import sys
 
 class TinyTinyDocument(NSDocument):
     textView = objc.IBOutlet()
     def windowControllerDidLoadNib_(self, controller):
         if self.path:
             self.readFromUTF8(self.path)
+        else:
+            self.textView.setString_("Welcome to TinyTinyEdit in Python\nVersion: %s\nsys.maxint: %d\nbyteorder: %s"%(
+                sys.version, sys.maxint, sys.byteorder))
 
     def readFromUTF8(self, path):
         f = file(path)

File py2app/apptemplate/prebuilt/main

Binary file removed.

File py2app/apptemplate/prebuilt/main-32bit

Binary file added.

File py2app/apptemplate/prebuilt/main-intel

Binary file added.

File py2app/apptemplate/prebuilt/main-universal

Binary file added.

File py2app/apptemplate/setup.py

View file
 import os
+import re
 import distutils.sysconfig
+import distutils.util
+
+gPreBuildVariants = [
+    {
+        'name': 'main-universal',
+        'target': '10.5',
+        'cflags': '-isysroot /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch ppc -arch ppc64 -arch x86_64',
+        'cc': 'gcc-4.2',
+    },
+    {
+        'name': 'main-fat3',
+        'target': '10.5',
+        'cflags': '-isysroot / -arch i386 -arch ppc -arch x86_64',
+        'cc': 'gcc-4.2',
+    },
+    {
+        'name': 'main-intel',
+        'target': '10.5',
+        'cflags': '-isysroot / -arch i386 -arch x86_64',
+        'cc': 'gcc-4.2',
+    },
+    {
+        'name': 'main-32bit',
+        'target': '10.3',
+        'cflags': '-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc',
+        'cc': 'gcc-4.0',
+    },
+]
+
 
 def main():
     basepath = os.path.dirname(__file__)
     builddir = os.path.join(basepath, 'prebuilt')
     if not os.path.exists(builddir):
         os.makedirs(builddir)
-    dest = os.path.join(builddir, 'main')
     src = os.path.join(basepath, 'src', 'main.c')
-    if not os.path.exists(dest) or (
-            os.stat(dest).st_mtime < os.stat(src).st_mtime):
-        cfg = distutils.sysconfig.get_config_vars()
-        CC = cfg['CC']
-        CFLAGS = cfg['CFLAGS'].replace(' -dynamic', '')
-        os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
-        os.system('"%(CC)s" -arch i386 -arch ppc -o "%(dest)s" "%(src)s" %(CFLAGS)s' % locals())
-        #os.system('strip "%(dest)s"' % locals())
+
+    cfg = distutils.sysconfig.get_config_vars()
+
+    BASE_CFLAGS = cfg['CFLAGS']
+    BASE_CFLAGS = BASE_CFLAGS.replace('-dynamic', '')
+    while True:
+        x = re.sub('-arch\s+\S+', '', BASE_CFLAGS)
+        if x == BASE_CFLAGS:
+            break
+        BASE_CFLAGS=x
+
+    while True:
+        x = re.sub('-isysroot\s+\S+', '', BASE_CFLAGS)
+        if x == BASE_CFLAGS:
+            break
+        BASE_CFLAGS=x
+
+    for entry in gPreBuildVariants:
+        CC=entry['cc']
+        CFLAGS = BASE_CFLAGS + ' ' + entry['cflags']
+        os.environ['MACOSX_DEPLOYMENT_TARGET'] = entry['target']
+        dest = os.path.join(builddir, entry['name'])
+        if not os.path.exists(dest) or (
+                os.stat(dest).st_mtime < os.stat(src).st_mtime):
+            os.system('"%(CC)s" -arch i386 -arch ppc -o "%(dest)s" "%(src)s" %(CFLAGS)s' % locals())
+
+    dest = os.path.join(
+            builddir,
+            'main-' + distutils.util.get_platform().split('-')[-1]
+    )
+
     return dest
 
+
 if __name__ == '__main__':
     main()

File py2app/apptemplate/src/main.c

View file
 #include <unistd.h>
 #include <sys/stat.h>
 #include <pwd.h>
+#include <dlfcn.h>
 #include <mach-o/dyld.h>
 #include <CoreFoundation/CoreFoundation.h>
 #include <ApplicationServices/ApplicationServices.h>
 */
 
 typedef int PyObject;
-typedef void (*Py_DecRefPtr)(PyObject *);
 typedef void (*Py_SetProgramNamePtr)(const char *);
 typedef void (*Py_InitializePtr)(void); 
 typedef int (*PyRun_SimpleFilePtr)(FILE *, const char *);
 typedef PyObject *(*PyObject_StrPtr)(PyObject *);
 typedef const char *(*PyString_AsStringPtr)(PyObject *);
 typedef PyObject *(*PyObject_GetAttrStringPtr)(PyObject *, const char *);
-static void DefaultDecRef(PyObject *op) {
-    if (op != NULL) --(*op);
-}
 
 typedef CFTypeRef id;
-typedef const char *SEL;
+typedef const char * SEL;
 typedef signed char BOOL;
 #define NSAlertAlternateReturn 0
 
     Forward declarations
 */
 static int report_error(const char *);
-static CFTypeRef getKey(const char *key);
+static CFTypeRef py2app_getKey(const char *key);
 
 /*
     Strings
 static const char *ERR_TITLEFORMAT = "%@ has encountered a fatal error, and will now terminate.";
 static const char *ERR_NONAME = "The Info.plist file must have values for the CFBundleName or CFBundleExecutable strings.";
 static const char *ERR_PYRUNTIMELOCATIONS = "The Info.plist file must have a PyRuntimeLocations array containing string values for preferred Python runtime locations.  These strings should be \"otool -L\" style mach ids; \"@executable_stub\" and \"~\" prefixes will be translated accordingly.";
-static const char *ERR_NOPYTHONRUNTIME = "A Python runtime could be located.  You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this application's Info.plist file.";
+static const char *ERR_NOPYTHONRUNTIME = "A Python runtime not could be located.  You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this application's Info.plist file.";
 static const char *ERR_NOPYTHONSCRIPT = "A main script could not be located in the Resources folder.;";
 static const char *ERR_LINKERRFMT = "An internal error occurred while attempting to link with:\r\r%s\r\rSee the Console for a detailed dyld error message";
-static const char *ERR_UNKNOWNPYTHONEXCEPTION = "An uncaught exception was raised during execution of the main script, but its class or name could not be determined";
-static const char *ERR_PYTHONEXCEPTION = "An uncaught exception was raised during execution of the main script:\r\r%@: %@\r\rThis may mean that an unexpected error has occurred, or that you do not have all of the dependencies for this application.\r\rSee the Console for a detailed traceback.";
+static const char *ERR_PYTHONEXCEPTION = "An uncaught exception was raised during execution of the main script.\r\rThis may mean that an unexpected error has occurred, or that you do not have all of the dependencies for this application.\r\rSee the Console for a detailed traceback.";
 static const char *ERR_COLONPATH = "Python applications can not currently run from paths containing a '/' (or ':' from the Terminal).";
 static const char *ERR_DEFAULTURLTITLE = "Visit Website";
 static const char *ERR_CONSOLEAPP = "Console.app";
 static const char *ERR_TERMINATE = "Terminate";
 
 /*
-    Constants
-*/
-
-#define PYMACAPP_NSIMAGEFLAGS ( \
-    NSADDIMAGE_OPTION_RETURN_ON_ERROR | \
-    NSADDIMAGE_OPTION_WITH_SEARCHING)
-#define PYMACAPP_NSLOOKUPSYMBOLINIMAGEFLAGS ( \
-    NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | \
-    NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR)
-
-/*
     Globals
 */
-static CFMutableArrayRef pool;
+static CFMutableArrayRef py2app_pool;
 
-#define USES(NAME) static __typeof__(&NAME) x ## NAME
+#define USES(NAME) static __typeof__(&NAME) py2app_ ## NAME
 /* ApplicationServices */
 USES(LSOpenFSRef);
 USES(LSFindApplicationForInfo);
     objc
 */
 
-#define CLS(name) xobjc_getClass(name)
-#define MSG(receiver, selName, ...) \
-    xobjc_msgSend(receiver, xsel_getUid(selName), ## __VA_ARGS__)
-static id (*xobjc_getClass)(const char *name);
-static SEL (*xsel_getUid)(const char *str);
-static id (*xobjc_msgSend)(id self, SEL op, ...);
+static id (*py2app_objc_getClass)(const char *name);
+static SEL (*py2app_sel_getUid)(const char *str);
+static id (*py2app_objc_msgSend)(id self, SEL op, ...);
 
 /*
     Cocoa
 */
-static void (*xNSLog)(CFStringRef format, ...);
-static BOOL (*xNSApplicationLoad)(void);
-static int (*xNSRunAlertPanel)(CFStringRef title, CFStringRef msg, CFStringRef defaultButton, CFStringRef alternateButton, CFStringRef otherButton, ...);
+static void (*py2app_NSLog)(CFStringRef format, ...);
+static BOOL (*py2app_NSApplicationLoad)(void);
+static int (*py2app_NSRunAlertPanel)(CFStringRef title, CFStringRef msg, CFStringRef defaultButton, CFStringRef alternateButton, CFStringRef otherButton, ...);
 
 /*
     Functions
     static Boolean bound = false;
     if (bound) return 0;
     bound = true;
-    const struct mach_header *cf_dylib;
-    cf_dylib = NSAddImage("/usr/lib/libobjc.dylib", PYMACAPP_NSIMAGEFLAGS);
+    void* cf_dylib;
+    cf_dylib = dlopen("/usr/lib/libobjc.dylib", RTLD_LAZY);
     if (!cf_dylib) return -1;
+
 #define LOOKUP(NAME) do { \
-    NSSymbol tmpSymbol = NSLookupSymbolInImage( \
-        cf_dylib, "_" #NAME, \
-        PYMACAPP_NSLOOKUPSYMBOLINIMAGEFLAGS); \
-    if (!tmpSymbol) return -1; \
-    x ## NAME = (__typeof__(x ## NAME))NSAddressOfSymbol(tmpSymbol); \
+    py2app_ ## NAME = (__typeof__(py2app_ ## NAME))dlsym( \
+        cf_dylib, #NAME); \
+        if (!py2app_ ## NAME) return -1; \
     } while (0)
 
     LOOKUP(objc_getClass);
     LOOKUP(sel_getUid);
     LOOKUP(objc_msgSend);
 
-    cf_dylib = NSAddImage(
+    cf_dylib = dlopen(
         "/System/Library/Frameworks/Cocoa.framework/Cocoa",
-        PYMACAPP_NSIMAGEFLAGS);
+        RTLD_LAZY);
     if (!cf_dylib) return -1;
     LOOKUP(NSLog);
     LOOKUP(NSApplicationLoad);
     LOOKUP(NSRunAlertPanel);
 
-#undef LOOKUP
-
-    cf_dylib = NSAddImage(
+    cf_dylib = dlopen(
         "/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices",
-        PYMACAPP_NSIMAGEFLAGS);
+        RTLD_LAZY);
     if (!cf_dylib) return -1;
-#define LOOKUP(NAME) do { \
-    NSSymbol tmpSymbol = NSLookupSymbolInImage( \
-        cf_dylib, "_" #NAME, \
-        PYMACAPP_NSLOOKUPSYMBOLINIMAGEFLAGS); \
-    if (!tmpSymbol) return -1; \
-    x ## NAME = (__typeof__(&NAME))NSAddressOfSymbol(tmpSymbol); \
-    } while (0)
 
     LOOKUP(GetCurrentProcess);
     LOOKUP(SetFrontProcess);
     
 static int bind_CoreFoundation(void) {
     static Boolean bound = false;
-    const struct mach_header *cf_dylib;
+    void *cf_dylib;
     if (bound) return 0;
     bound = true;
-    cf_dylib = NSAddImage(
+    cf_dylib = dlopen(
         "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation",
-        PYMACAPP_NSIMAGEFLAGS);
+        RTLD_LAZY);
     if (!cf_dylib) return -1;
 
 #define LOOKUP(NAME) do { \
-    NSSymbol tmpSymbol = NSLookupSymbolInImage( \
-        cf_dylib, "_" #NAME, \
-        PYMACAPP_NSLOOKUPSYMBOLINIMAGEFLAGS); \
-    if (!tmpSymbol) return -1; \
-    x ## NAME = (__typeof__(&NAME))NSAddressOfSymbol(tmpSymbol); \
+    py2app_ ## NAME = (__typeof__(py2app_ ## NAME))dlsym( \
+        cf_dylib, #NAME); \
+        if (!py2app_ ## NAME) return -1; \
     } while (0)
 
     LOOKUP(CFArrayRemoveValueAtIndex);
 }
 
 #define AUTORELEASE(obj) ((obj == NULL) ? NULL : ( \
-    xCFArrayAppendValue(pool, (const void *)obj), \
-    xCFRelease(obj), \
+    py2app_CFArrayAppendValue(py2app_pool, (const void *)obj), \
+    py2app_CFRelease(obj), \
     obj))
     
-#define xCFSTR(s) AUTORELEASE( \
-    xCFStringCreateWithCString(NULL, s, kCFStringEncodingUTF8))
+#define py2app_CFSTR(s) AUTORELEASE( \
+    py2app_CFStringCreateWithCString(NULL, s, kCFStringEncodingUTF8))
 
-static int openConsole(void) {
+static int py2app_openConsole(void) {
     OSStatus err;
     FSRef consoleRef;
-    err = xLSFindApplicationForInfo(
+    err = py2app_LSFindApplicationForInfo(
         kLSUnknownCreator,
         NULL,
-        xCFSTR(ERR_CONSOLEAPP),
+        py2app_CFSTR(ERR_CONSOLEAPP),
         &consoleRef,
         NULL);
     if (err != noErr) return err;
-    return xLSOpenFSRef((const FSRef *)&consoleRef, NULL);
+    return py2app_LSOpenFSRef((const FSRef *)&consoleRef, NULL);
 }
 
-static CFTypeRef getKey(const char *key) {
+static CFTypeRef py2app_getKey(const char *key) {
     CFTypeRef rval;
-    CFStringRef cfKey = xCFStringCreateWithCString(NULL,
+    CFStringRef cfKey = py2app_CFStringCreateWithCString(NULL,
         key, kCFStringEncodingUTF8);
     if (!cfKey) return NULL;
-    rval = xCFBundleGetValueForInfoDictionaryKey(
-        xCFBundleGetMainBundle(),
+    rval = py2app_CFBundleGetValueForInfoDictionaryKey(
+        py2app_CFBundleGetMainBundle(),
         cfKey);
-    xCFRelease(cfKey);
+    py2app_CFRelease(cfKey);
     return rval;
 }
 
-static CFStringRef getApplicationName(void) {
+static CFStringRef py2app_getApplicationName(void) {
     static CFStringRef name = NULL;
     if (name) return name;
-    name = (CFStringRef)getKey("CFBundleName");
-    if (!name) name = (CFStringRef)getKey("CFBundleExecutable");
+    name = (CFStringRef)py2app_getKey("CFBundleName");
+    if (!name) name = (CFStringRef)py2app_getKey("CFBundleExecutable");
+    if (!name) name = py2app_CFSTR("py2app stub executable");
     return AUTORELEASE(name);
 }
 
 
-static CFStringRef getErrorTitle(CFStringRef applicationName) {
+static CFStringRef py2app_getErrorTitle(CFStringRef applicationName) {
     CFStringRef res;
-    if (!applicationName) return xCFSTR(ERR_REALLYBADTITLE);
-    res = xCFStringCreateWithFormat(
-        NULL, NULL, xCFSTR(ERR_TITLEFORMAT), applicationName);
+    if (!applicationName) return py2app_CFSTR(ERR_REALLYBADTITLE);
+    res = py2app_CFStringCreateWithFormat(
+        NULL, NULL, py2app_CFSTR(ERR_TITLEFORMAT), applicationName);
     AUTORELEASE(res);
     return res;
 }
 
 static void ensureGUI(void) {
     ProcessSerialNumber psn;
-    id app = MSG(CLS("NSApplication"), "sharedApplication");
-    xNSApplicationLoad();
-    MSG(app, "activateIgnoringOtherApps:", (BOOL)1);
-    if (xGetCurrentProcess(&psn) == noErr) {
-        xSetFrontProcess(&psn);
+    id app = ((id(*)(id, SEL))py2app_objc_msgSend)(py2app_objc_getClass("NSApplication"), py2app_sel_getUid("sharedApplication"));
+    py2app_NSApplicationLoad();
+    ((void(*)(id, SEL, BOOL))py2app_objc_msgSend)(app, py2app_sel_getUid("activateIgnoringOtherApps:"), 1);
+    if (py2app_GetCurrentProcess(&psn) == noErr) {
+        py2app_SetFrontProcess(&psn);
     }
 }
 
 static int report_error(const char *error) {
     int choice;
     id releasePool;
+
     if (bind_objc_Cocoa_ApplicationServices()) {
         fprintf(stderr, "%s\n", error);
         return -1;
     }
-    releasePool = MSG(MSG(CLS("NSAutoreleasePool"), "alloc"), "init");
-    xNSLog(xCFSTR("%@"), xCFSTR(error));
-    if (!xNSApplicationLoad()) {
-        xNSLog(xCFSTR("NSApplicationLoad() failed"));
+    releasePool = ((id(*)(id, SEL))py2app_objc_msgSend)(
+		    ((id(*)(id, SEL))py2app_objc_msgSend)(
+			    py2app_objc_getClass("NSAutoreleasePool"), 
+			    py2app_sel_getUid("alloc")), 
+		    py2app_sel_getUid("init"));
+    py2app_NSLog(py2app_CFSTR("%@"), py2app_CFSTR(error));
+
+    printf("%p\n", py2app_NSApplicationLoad);
+
+    if (!py2app_NSApplicationLoad()) {
+        py2app_NSLog(py2app_CFSTR("NSApplicationLoad() failed"));
     } else {
         ensureGUI();
-        choice = xNSRunAlertPanel(
-            getErrorTitle(getApplicationName()),
-            xCFSTR("%@"),
-            xCFSTR(ERR_TERMINATE),
-            xCFSTR(ERR_CONSOLEAPPTITLE),
+        choice = py2app_NSRunAlertPanel(
+            py2app_getErrorTitle(py2app_getApplicationName()),
+            py2app_CFSTR("%@"),
+            py2app_CFSTR(ERR_TERMINATE),
+            py2app_CFSTR(ERR_CONSOLEAPPTITLE),
             NULL,
-            xCFSTR(error));
-        if (choice == NSAlertAlternateReturn) openConsole();
+            py2app_CFSTR(error));
+        if (choice == NSAlertAlternateReturn) py2app_openConsole();
     }
-    MSG(releasePool, "release");
+    ((void(*)(id, SEL))py2app_objc_msgSend)(releasePool, py2app_sel_getUid("release"));
     return -1;
 }
 
 static CFStringRef pathFromURL(CFURLRef anURL) {
     UInt8 buf[PATH_MAX];
-    xCFURLGetFileSystemRepresentation(anURL, true, buf, sizeof(buf));
-    return xCFStringCreateWithCString(NULL, (char *)buf, kCFStringEncodingUTF8);
+    py2app_CFURLGetFileSystemRepresentation(anURL, true, buf, sizeof(buf));
+    return py2app_CFStringCreateWithCString(NULL, (char *)buf, kCFStringEncodingUTF8);
 }
 
 static CFStringRef pyStandardizePath(CFStringRef pyLocation) {
     CFURLRef locURL;
     CFStringRef subpath;
     static CFStringRef prefix = NULL;
-    if (!prefix) prefix = xCFSTR("@executable_path/");
-    foundRange = xCFStringFind(pyLocation, prefix, 0);
+    if (!prefix) prefix = py2app_CFSTR("@executable_path/");
+    foundRange = py2app_CFStringFind(pyLocation, prefix, 0);
     if (foundRange.location == kCFNotFound || foundRange.length == 0) {
         return NULL;
     }
-    fmwkURL = xCFBundleCopyPrivateFrameworksURL(xCFBundleGetMainBundle());
+    fmwkURL = py2app_CFBundleCopyPrivateFrameworksURL(py2app_CFBundleGetMainBundle());
     foundRange.location = foundRange.length;
-    foundRange.length = xCFStringGetLength(pyLocation) - foundRange.length;
-    subpath = xCFStringCreateWithSubstring(NULL, pyLocation, foundRange);
-    locURL = xCFURLCreateWithFileSystemPathRelativeToBase(
+    foundRange.length = py2app_CFStringGetLength(pyLocation) - foundRange.length;
+    subpath = py2app_CFStringCreateWithSubstring(NULL, pyLocation, foundRange);
+    locURL = py2app_CFURLCreateWithFileSystemPathRelativeToBase(
         NULL,
         subpath,
         kCFURLPOSIXPathStyle,
         false,
         fmwkURL);
-    xCFRelease(subpath);
-    xCFRelease(fmwkURL);
+    py2app_CFRelease(subpath);
+    py2app_CFRelease(fmwkURL);
     subpath = pathFromURL(locURL);
-    xCFRelease(locURL);
+    py2app_CFRelease(locURL);
     return subpath;
 }
 
     struct stat st;
     CFURLRef locURL;
     UInt8 buf[PATH_MAX];
-    locURL = xCFURLCreateWithFileSystemPath(
+    locURL = py2app_CFURLCreateWithFileSystemPath(
         NULL, path, kCFURLPOSIXPathStyle, false);
-    xCFURLGetFileSystemRepresentation(locURL, true, buf, sizeof(buf));
-    xCFRelease(locURL);
+    py2app_CFURLGetFileSystemRepresentation(locURL, true, buf, sizeof(buf));
+    py2app_CFRelease(locURL);
     return (stat((const char *)buf, &st) == -1 ? false : true);
 }
 
-static CFStringRef findPyLocation(CFArrayRef pyLocations) {
-    int i;
-    int cnt = xCFArrayGetCount(pyLocations);
+static CFStringRef py2app_findPyLocation(CFArrayRef pyLocations) {
+    CFIndex i;
+    CFIndex cnt = py2app_CFArrayGetCount(pyLocations);
     for (i = 0; i < cnt; i++) {
         CFStringRef newLoc;
-        CFStringRef pyLocation = xCFArrayGetValueAtIndex(pyLocations, i);
+        CFStringRef pyLocation = py2app_CFArrayGetValueAtIndex(pyLocations, i);
         newLoc = pyStandardizePath(pyLocation);
-        if (!newLoc) newLoc = pyLocation;
+        if (!newLoc) {
+		newLoc = pyLocation;
+		py2app_CFRetain(newLoc);
+	}
         if (doesPathExist(newLoc)) {
-            if (newLoc == pyLocation) xCFRetain(newLoc);
             return newLoc;
         }
-        if (newLoc) xCFRelease(newLoc);
+        if (newLoc) py2app_CFRelease(newLoc);
     }
     return NULL;
 }
     char *dir = NULL;
 
     
-    xCFStringGetCString(path, buf, sizeof(buf), kCFStringEncodingUTF8);
+    py2app_CFStringGetCString(path, buf, sizeof(buf), kCFStringEncodingUTF8);
 
     int i;
     if (buf[0] != '~') {
-        return xCFStringCreateWithCString(
+        return py2app_CFStringCreateWithCString(
             NULL, buf, kCFStringEncodingUTF8);
     }
     /* user in path */
         buf[i] = tmp;
     }
     if (!dir) {
-        return xCFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
+        return py2app_CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
     }
-    pathURL = xCFURLCreateFromFileSystemRepresentation(
+    pathURL = py2app_CFURLCreateFromFileSystemRepresentation(
         NULL, (const UInt8*)dir, strlen(dir), false);
-    fullPathURL = xCFURLCreateFromFileSystemRepresentationRelativeToBase(
+    fullPathURL = py2app_CFURLCreateFromFileSystemRepresentationRelativeToBase(
         NULL, (const UInt8*)&buf[i + 1], strlen(&buf[i + 1]), false, pathURL);
-    xCFRelease(pathURL);
+    py2app_CFRelease(pathURL);
     path = pathFromURL(fullPathURL);
-    xCFRelease(fullPathURL);
+    py2app_CFRelease(fullPathURL);
     return path;
 }
 
 static void setcfenv(char *name, CFStringRef value) {
     char buf[PATH_MAX];
-    xCFStringGetCString(value, buf, sizeof(buf), kCFStringEncodingUTF8);
+    py2app_CFStringGetCString(value, buf, sizeof(buf), kCFStringEncodingUTF8);
     setenv(name, buf, 1);
 }
 
-static void setPythonPath(void) {
+static void py2app_setPythonPath(void) {
     CFMutableArrayRef paths;
     CFURLRef resDir;
     CFStringRef resPath;
     CFArrayRef resPackages;
     CFDictionaryRef options;
 
-    paths = xCFArrayCreateMutable(NULL, 0, xkCFTypeArrayCallBacks);
+    paths = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
 
-    resDir = xCFBundleCopyResourcesDirectoryURL(xCFBundleGetMainBundle());
+    resDir = py2app_CFBundleCopyResourcesDirectoryURL(py2app_CFBundleGetMainBundle());
     resPath = pathFromURL(resDir);
-    xCFArrayAppendValue(paths, resPath);
-    xCFRelease(resPath);
+    py2app_CFArrayAppendValue(paths, resPath);
+    py2app_CFRelease(resPath);
 
-    resPackages = getKey("PyResourcePackages");
+    resPackages = py2app_getKey("PyResourcePackages");
     if (resPackages) {
         int i;
-        int cnt = xCFArrayGetCount(resPackages);
+        int cnt = py2app_CFArrayGetCount(resPackages);
         for (i = 0; i < cnt; i++) {
-            resPath = tildeExpand(xCFArrayGetValueAtIndex(resPackages, i));
-            if (xCFStringGetLength(resPath)) {
-                if (xCFStringGetCharacterAtIndex(resPath, 0) != '/') {
-                    CFURLRef absURL = xCFURLCreateWithString(
+            resPath = tildeExpand(py2app_CFArrayGetValueAtIndex(resPackages, i));
+            if (py2app_CFStringGetLength(resPath)) {
+                if (py2app_CFStringGetCharacterAtIndex(resPath, 0) != '/') {
+                    CFURLRef absURL = py2app_CFURLCreateWithString(
                         NULL, resPath, resDir);
-                    xCFRelease(resPath);
+                    py2app_CFRelease(resPath);
                     resPath = pathFromURL(absURL);
-                    xCFRelease(absURL);
+                    py2app_CFRelease(absURL);
                 }
-                xCFArrayAppendValue(paths, resPath);
+                py2app_CFArrayAppendValue(paths, resPath);
             }
-            xCFRelease(resPath);
+            py2app_CFRelease(resPath);
         }
     }
 
-    xCFRelease(resDir);
+    py2app_CFRelease(resDir);
 
-    options = getKey("PyOptions");
+    options = py2app_getKey("PyOptions");
     if (options) {
         CFBooleanRef use_pythonpath;
-        use_pythonpath = xCFDictionaryGetValue(
-            options, xCFSTR("use_pythonpath"));
-        if (use_pythonpath && xCFBooleanGetValue(use_pythonpath)) {
+        use_pythonpath = py2app_CFDictionaryGetValue(
+            options, py2app_CFSTR("use_pythonpath"));
+        if (use_pythonpath && py2app_CFBooleanGetValue(use_pythonpath)) {
             char *ppath = getenv("PYTHONPATH");
             if (ppath) {
                 CFArrayRef oldPath;
-                oldPath = xCFStringCreateArrayBySeparatingStrings(
-                    NULL, xCFSTR(ppath), xCFSTR(":"));
+                oldPath = py2app_CFStringCreateArrayBySeparatingStrings(
+                    NULL, py2app_CFSTR(ppath), py2app_CFSTR(":"));
                 if (oldPath) {
                     CFRange rng;
                     rng.location = 0;
-                    rng.length = xCFArrayGetCount(oldPath);
-                    xCFArrayAppendArray(paths, oldPath, rng);
-                    xCFRelease(oldPath);
+                    rng.length = py2app_CFArrayGetCount(oldPath);
+                    py2app_CFArrayAppendArray(paths, oldPath, rng);
+                    py2app_CFRelease(oldPath);
                 }
             }
         }
     }
 
-    if (xCFArrayGetCount(paths)) {
-        resPath = xCFStringCreateByCombiningStrings(NULL, paths, xCFSTR(":"));
+    if (py2app_CFArrayGetCount(paths)) {
+        resPath = py2app_CFStringCreateByCombiningStrings(NULL, paths, py2app_CFSTR(":"));
         setcfenv("PYTHONPATH", resPath);
-        xCFRelease(resPath);
+        py2app_CFRelease(resPath);
     }
-    xCFRelease(paths);
+    py2app_CFRelease(paths);
 }
 
 
 static void setResourcePath(void) {
     CFURLRef resDir;
     CFStringRef resPath;
-    resDir = xCFBundleCopyResourcesDirectoryURL(xCFBundleGetMainBundle());
+    resDir = py2app_CFBundleCopyResourcesDirectoryURL(py2app_CFBundleGetMainBundle());
     resPath = pathFromURL(resDir);
-    xCFRelease(resDir);
+    py2app_CFRelease(resDir);
     setcfenv("RESOURCEPATH", resPath);
-    xCFRelease(resPath);
+    py2app_CFRelease(resPath);
 }
 
 static void setExecutablePath(void) {
     CFBundleRef bndl;
     CFStringRef e_py, e_pyc, e_pyo, path;
     int i, cnt;
-    possibleMains = xCFArrayCreateMutable(NULL, 0, xkCFTypeArrayCallBacks);
-    CFArrayRef firstMains = getKey("PyMainFileNames");
+    possibleMains = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
+    CFArrayRef firstMains = py2app_getKey("PyMainFileNames");
     if (firstMains) {
         CFRange rng;
         rng.location = 0;
-        rng.length = xCFArrayGetCount(firstMains);
-        xCFArrayAppendArray(possibleMains, firstMains, rng);
+        rng.length = py2app_CFArrayGetCount(firstMains);
+        py2app_CFArrayAppendArray(possibleMains, firstMains, rng);
     }
-    xCFArrayAppendValue(possibleMains, xCFSTR("__main__"));
-    xCFArrayAppendValue(possibleMains, xCFSTR("__realmain__"));
-    xCFArrayAppendValue(possibleMains, xCFSTR("Main"));
+    py2app_CFArrayAppendValue(possibleMains, py2app_CFSTR("__main__"));
+    py2app_CFArrayAppendValue(possibleMains, py2app_CFSTR("__realmain__"));
+    py2app_CFArrayAppendValue(possibleMains, py2app_CFSTR("Main"));
 
-    e_py = xCFSTR("py");
-    e_pyc = xCFSTR("pyc");
-    e_pyo = xCFSTR("pyo");
+    e_py = py2app_CFSTR("py");
+    e_pyc = py2app_CFSTR("pyc");
+    e_pyo = py2app_CFSTR("pyo");
 
-    cnt = xCFArrayGetCount(possibleMains);
-    bndl = xCFBundleGetMainBundle();
+    cnt = py2app_CFArrayGetCount(possibleMains);
+    bndl = py2app_CFBundleGetMainBundle();
     path = NULL;
     for (i = 0; i < cnt; i++) {
         CFStringRef base;
         CFURLRef resURL;
-        base = xCFArrayGetValueAtIndex(possibleMains, i);
-        resURL = xCFBundleCopyResourceURL(bndl, base, e_py, NULL);
+        base = py2app_CFArrayGetValueAtIndex(possibleMains, i);
+        resURL = py2app_CFBundleCopyResourceURL(bndl, base, e_py, NULL);
         if (resURL == NULL) {
-            resURL = xCFBundleCopyResourceURL(bndl, base, e_pyc, NULL);
+            resURL = py2app_CFBundleCopyResourceURL(bndl, base, e_pyc, NULL);
         }
         if (resURL == NULL) {
-            resURL = xCFBundleCopyResourceURL(bndl, base, e_pyo, NULL);
+            resURL = py2app_CFBundleCopyResourceURL(bndl, base, e_pyo, NULL);
         }
         if (resURL != NULL) {
             path = pathFromURL(resURL);
-            xCFRelease(resURL);
+            py2app_CFRelease(resURL);
             break;
         }
     }
-    xCFRelease(possibleMains);
+    py2app_CFRelease(possibleMains);
     return path;
 }
 
 static int report_linkEdit_error(void) {
-    NSLinkEditErrors errorClass;
-    int errorNumber;
     CFStringRef errString;
-    const char *fileName;
     const char *errorString;
-    char *buf;
-    NSLinkEditError(&errorClass, &errorNumber, &fileName, &errorString);
-    fprintf(stderr, errorString);
-    errString = xCFStringCreateWithFormat(
-        NULL, NULL, xCFSTR(ERR_LINKERRFMT), fileName);
-    buf = alloca(xCFStringGetMaximumSizeForEncoding(
-            xCFStringGetLength(errString), kCFStringEncodingUTF8));
-    xCFStringGetCString(errString, buf, sizeof(buf), kCFStringEncodingUTF8);
-    xCFRelease(errString);
+    char* buf;
+    errorString = dlerror();
+    fputs(errorString, stderr);
+    errString = py2app_CFStringCreateWithFormat(
+        NULL, NULL, py2app_CFSTR(ERR_LINKERRFMT), errorString);
+    buf = alloca(py2app_CFStringGetMaximumSizeForEncoding(
+            py2app_CFStringGetLength(errString), kCFStringEncodingUTF8));
+    py2app_CFStringGetCString(errString, buf, sizeof(buf), kCFStringEncodingUTF8);
+    py2app_CFRelease(errString);
     return report_error(buf);
 }
 
     CFURLRef auxURL;
     CFStringRef path;
 
-    auxName = getKey("PyExecutableName");
-    if (!auxName) auxName = xCFSTR("python");
-    bndl = xCFBundleGetMainBundle();
-    auxURL = xCFBundleCopyAuxiliaryExecutableURL(bndl, auxName);
+    auxName = py2app_getKey("PyExecutableName");
+    if (!auxName) auxName = py2app_CFSTR("python");
+    bndl = py2app_CFBundleGetMainBundle();
+    auxURL = py2app_CFBundleCopyAuxiliaryExecutableURL(bndl, auxName);
     if (auxURL) {
         path = pathFromURL(auxURL);
-        xCFRelease(auxURL);
+        py2app_CFRelease(auxURL);
         return path;
     }
     return NULL;
     CFBundleRef bndl;
     CFStringRef path;
     int i, cnt;
-    errorScripts = xCFArrayCreateMutable(NULL, 0, xkCFTypeArrayCallBacks);
-    CFArrayRef firstErrorScripts = getKey("PyErrorScripts");
+    errorScripts = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
+    CFArrayRef firstErrorScripts = py2app_getKey("PyErrorScripts");
     if (firstErrorScripts) {
         CFRange rng;
         rng.location = 0;
-        rng.length = xCFArrayGetCount(firstErrorScripts);
-        xCFArrayAppendArray(errorScripts, firstErrorScripts, rng);
+        rng.length = py2app_CFArrayGetCount(firstErrorScripts);
+        py2app_CFArrayAppendArray(errorScripts, firstErrorScripts, rng);
     }
-    xCFArrayAppendValue(errorScripts, xCFSTR("__error__"));
-    xCFArrayAppendValue(errorScripts, xCFSTR("__error__.py"));
-    xCFArrayAppendValue(errorScripts, xCFSTR("__error__.pyc"));
-    xCFArrayAppendValue(errorScripts, xCFSTR("__error__.pyo"));
-    xCFArrayAppendValue(errorScripts, xCFSTR("__error__.sh"));
+    py2app_CFArrayAppendValue(errorScripts, py2app_CFSTR("__error__"));
+    py2app_CFArrayAppendValue(errorScripts, py2app_CFSTR("__error__.py"));
+    py2app_CFArrayAppendValue(errorScripts, py2app_CFSTR("__error__.pyc"));
+    py2app_CFArrayAppendValue(errorScripts, py2app_CFSTR("__error__.pyo"));
+    py2app_CFArrayAppendValue(errorScripts, py2app_CFSTR("__error__.sh"));
 
-    cnt = xCFArrayGetCount(errorScripts);
-    bndl = xCFBundleGetMainBundle();
+    cnt = py2app_CFArrayGetCount(errorScripts);
+    bndl = py2app_CFBundleGetMainBundle();
     path = NULL;
     for (i = 0; i < cnt; i++) {
         CFStringRef base;
         CFURLRef resURL;
-        base = xCFArrayGetValueAtIndex(errorScripts, i);
-        resURL = xCFBundleCopyResourceURL(bndl, base, NULL, NULL);
+        base = py2app_CFArrayGetValueAtIndex(errorScripts, i);
+        resURL = py2app_CFBundleCopyResourceURL(bndl, base, NULL, NULL);
         if (resURL) {
             path = pathFromURL(resURL);
-            xCFRelease(resURL);
+            py2app_CFRelease(resURL);
             break;
         }
     }
-    xCFRelease(errorScripts);
+    py2app_CFRelease(errorScripts);
     return path;
  
 }
     CFMutableArrayRef lines;
     CFArrayRef tmp;
     CFRange rng;
-    lines = xCFArrayCreateMutable(NULL, 0, xkCFTypeArrayCallBacks);
-    tmp = xCFStringCreateArrayBySeparatingStrings(
-        NULL, output, xCFSTR("\n"));
+    lines = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
+    tmp = py2app_CFStringCreateArrayBySeparatingStrings(
+        NULL, output, py2app_CFSTR("\n"));
     rng.location = 0;
-    rng.length = xCFArrayGetCount(tmp);
-    xCFArrayAppendArray(lines, tmp, rng);
+    rng.length = py2app_CFArrayGetCount(tmp);
+    py2app_CFArrayAppendArray(lines, tmp, rng);
     while (true) {
-        CFIndex cnt = xCFArrayGetCount(lines);
+        CFIndex cnt = py2app_CFArrayGetCount(lines);
         CFStringRef last;
         /* Nothing on stdout means pass silently */
         if (cnt <= 0) {
-            xCFRelease(lines);
+            py2app_CFRelease(lines);
             return NULL;
         }
-        last = xCFArrayGetValueAtIndex(lines, cnt - 1);
-        if (xCFStringGetLength(last) > 0) break;
-        xCFArrayRemoveValueAtIndex(lines, cnt - 1);
+        last = py2app_CFArrayGetValueAtIndex(lines, cnt - 1);
+        if (py2app_CFStringGetLength(last) > 0) break;
+        py2app_CFArrayRemoveValueAtIndex(lines, cnt - 1);
     }
     return lines;
 }
 
-static int report_script_error(const char *msg, CFStringRef cls, CFStringRef name) {
+static int report_script_error(const char *msg) {
     CFStringRef errorScript;
     CFMutableArrayRef lines;
     CFRange foundRange;
     id releasePool;
     int errBinding;
     int status = 0;
-    char *buf;
-
-
-    if (cls && name) {
-        CFStringRef errString = xCFStringCreateWithFormat(
-            NULL, NULL, xCFSTR(msg), cls, name);
-        buf = alloca(xCFStringGetMaximumSizeForEncoding(
-                xCFStringGetLength(errString), kCFStringEncodingUTF8));
-        xCFStringGetCString(
-            errString, buf, sizeof(buf), kCFStringEncodingUTF8);
-        xCFRelease(errString);
-    } else {
-        buf = (char *)msg;
-    }
 
     errorScript = getErrorScript();
-    if (!errorScript) return report_error(buf);
+    if (!errorScript) return report_error(msg);
 
     errBinding = bind_objc_Cocoa_ApplicationServices();
     if (!errBinding) {
         id task, stdoutPipe, taskData;
         CFMutableArrayRef argv;
-        releasePool = MSG(MSG(CLS("NSAutoreleasePool"), "alloc"), "init");
-        task = MSG(MSG(CLS("NSTask"), "alloc"), "init");
-        stdoutPipe = MSG(CLS("NSPipe"), "pipe");
-        MSG(task, "setLaunchPath:", xCFSTR("/bin/sh"));
-        MSG(task, "setStandardOutput:", stdoutPipe);
-        argv = xCFArrayCreateMutable(NULL, 0, xkCFTypeArrayCallBacks);
-        xCFArrayAppendValue(argv, errorScript);
-        xCFArrayAppendValue(argv, getApplicationName());
-        if (cls && name) {
-            xCFArrayAppendValue(argv, cls);
-            xCFArrayAppendValue(argv, name);
-        }
-        MSG(task, "setArguments:", argv);
+        releasePool = ((id(*)(id, SEL))py2app_objc_msgSend)(
+		    ((id(*)(id, SEL))py2app_objc_msgSend)(
+			    py2app_objc_getClass("NSAutoreleasePool"), 
+			    py2app_sel_getUid("alloc")), 
+		    py2app_sel_getUid("init"));
+        task = ((id(*)(id, SEL))py2app_objc_msgSend)(
+		    ((id(*)(id, SEL))py2app_objc_msgSend)(
+			    py2app_objc_getClass("NSTask"), 
+			    py2app_sel_getUid("alloc")), 
+		    py2app_sel_getUid("init"));
+        stdoutPipe = ((id(*)(id, SEL))py2app_objc_msgSend)(py2app_objc_getClass("NSPipe"), py2app_sel_getUid("pipe"));
+        ((void(*)(id, SEL, id))py2app_objc_msgSend)(task, py2app_sel_getUid("setLaunchPath:"), py2app_CFSTR("/bin/sh"));
+        ((void(*)(id, SEL, id))py2app_objc_msgSend)(task, py2app_sel_getUid("setStandardOutput:"), stdoutPipe);
+        argv = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
+        py2app_CFArrayAppendValue(argv, errorScript);
+        py2app_CFArrayAppendValue(argv, py2app_getApplicationName());
+        ((void(*)(id, SEL, id))py2app_objc_msgSend)(task, py2app_sel_getUid("setArguments:"), argv);
         /* This could throw, in theory, but /bin/sh should prevent that */
-        MSG(task, "launch");
-        MSG(task, "waitUntilExit");
-        taskData = MSG(
-            MSG(stdoutPipe, "fileHandleForReading"),
-            "readDataToEndOfFile");
-        xCFRelease(argv);
+        ((void(*)(id, SEL))py2app_objc_msgSend)(task, py2app_sel_getUid("launch"));
+        ((void(*)(id, SEL))py2app_objc_msgSend)(task, py2app_sel_getUid("waitUntilExit"));
+        taskData = ((id(*)(id, SEL))py2app_objc_msgSend)(
+            ((id(*)(id, SEL))py2app_objc_msgSend)(stdoutPipe, py2app_sel_getUid("fileHandleForReading")),
+            py2app_sel_getUid("readDataToEndOfFile"));
+        py2app_CFRelease(argv);
 
-        status = (int)MSG(task, "terminationStatus");
-        xCFRelease(task);
+        status = ((int(*)(id, SEL))py2app_objc_msgSend)(task, py2app_sel_getUid("terminationStatus"));
+        py2app_CFRelease(task);
         if (!status && taskData) {
-            output = xCFStringCreateFromExternalRepresentation(
+            output = py2app_CFStringCreateFromExternalRepresentation(
                 NULL, taskData, kCFStringEncodingUTF8);
         }
 
-        MSG(releasePool, "release");
+        ((void(*)(id, SEL))py2app_objc_msgSend)(releasePool, py2app_sel_getUid("release"));
     }
 
-    xCFRelease(errorScript);
-    if (status || !output) return report_error(buf);
+    py2app_CFRelease(errorScript);
+    if (status || !output) return report_error(msg);
 
     lines = get_trimmed_lines(output);
-    xCFRelease(output);
+    py2app_CFRelease(output);
     /* Nothing on stdout means pass silently */
     if (!lines) return -1;
-    lineCount = xCFArrayGetCount(lines);
-    lastLine = xCFArrayGetValueAtIndex(lines, lineCount - 1);
-    foundRange = xCFStringFind(lastLine, xCFSTR("ERRORURL: "), 0);
+    lineCount = py2app_CFArrayGetCount(lines);
+    lastLine = py2app_CFArrayGetValueAtIndex(lines, lineCount - 1);
+    foundRange = py2app_CFStringFind(lastLine, py2app_CFSTR("ERRORURL: "), 0);
     if (foundRange.location != kCFNotFound && foundRange.length != 0) {
         CFMutableArrayRef buttonArr;
         CFArrayRef tmp;
         CFRange rng;
-        buttonArr = xCFArrayCreateMutable(NULL, 0, xkCFTypeArrayCallBacks);
-        tmp = xCFStringCreateArrayBySeparatingStrings(
-            NULL, lastLine, xCFSTR(" "));
+        buttonArr = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
+        tmp = py2app_CFStringCreateArrayBySeparatingStrings(
+            NULL, lastLine, py2app_CFSTR(" "));
         lineCount -= 1;
-        xCFArrayRemoveValueAtIndex(lines, lineCount);
+        py2app_CFArrayRemoveValueAtIndex(lines, lineCount);
         rng.location = 1;
-        rng.length = xCFArrayGetCount(tmp) - 1;
-        xCFArrayAppendArray(buttonArr, tmp, rng);
-        xCFRelease(tmp);
+        rng.length = py2app_CFArrayGetCount(tmp) - 1;
+        py2app_CFArrayAppendArray(buttonArr, tmp, rng);
+        py2app_CFRelease(tmp);
         while (true) {
             CFStringRef tmpstr;
-            if (xCFArrayGetCount(buttonArr) <= 0) break;
-            tmpstr = xCFArrayGetValueAtIndex(buttonArr, 0);
-            if (xCFStringGetLength(tmpstr) == 0) {
-                xCFArrayRemoveValueAtIndex(buttonArr, 0);
+            if (py2app_CFArrayGetCount(buttonArr) <= 0) break;
+            tmpstr = py2app_CFArrayGetValueAtIndex(buttonArr, 0);
+            if (py2app_CFStringGetLength(tmpstr) == 0) {
+                py2app_CFArrayRemoveValueAtIndex(buttonArr, 0);
             } else {
                 break;
             }
         }
 
-        buttonURL = xCFURLCreateWithString(
-            NULL, xCFArrayGetValueAtIndex(buttonArr, 0), NULL);
+        buttonURL = py2app_CFURLCreateWithString(
+            NULL, py2app_CFArrayGetValueAtIndex(buttonArr, 0), NULL);
         if (buttonURL) {
-            xCFArrayRemoveValueAtIndex(buttonArr, 0);
+            py2app_CFArrayRemoveValueAtIndex(buttonArr, 0);
             while (true) {
                 CFStringRef tmpstr;
-                if (xCFArrayGetCount(buttonArr) <= 0) break;
-                tmpstr = xCFArrayGetValueAtIndex(buttonArr, 0);
-                if (xCFStringGetLength(tmpstr) == 0) {
-                    xCFArrayRemoveValueAtIndex(buttonArr, 0);
+                if (py2app_CFArrayGetCount(buttonArr) <= 0) break;
+                tmpstr = py2app_CFArrayGetValueAtIndex(buttonArr, 0);
+                if (py2app_CFStringGetLength(tmpstr) == 0) {
+                    py2app_CFArrayRemoveValueAtIndex(buttonArr, 0);
                 } else {
                     break;
                 }
             }
-            if (xCFArrayGetCount(buttonArr) > 0) {
-                buttonString = xCFStringCreateByCombiningStrings(
-                    NULL, buttonArr, xCFSTR(" "));
+            if (py2app_CFArrayGetCount(buttonArr) > 0) {
+                buttonString = py2app_CFStringCreateByCombiningStrings(
+                    NULL, buttonArr, py2app_CFSTR(" "));
             }
-            if (!buttonString) buttonString = xCFSTR(ERR_DEFAULTURLTITLE);
+            if (!buttonString) buttonString = py2app_CFSTR(ERR_DEFAULTURLTITLE);
         }
-        xCFRelease(buttonArr);
+        py2app_CFRelease(buttonArr);
         
     }
     if (lineCount <= 0 || errBinding) {
-        xCFRelease(lines);
-        return report_error(buf);
+        py2app_CFRelease(lines);
+        return report_error(msg);
     }
 
-    releasePool = MSG(MSG(CLS("NSAutoreleasePool"), "alloc"), "init");
+    releasePool = ((id(*)(id, SEL))py2app_objc_msgSend)(
+		    ((id(*)(id, SEL))py2app_objc_msgSend)(
+			    py2app_objc_getClass("NSAutoreleasePool"), 
+			    py2app_sel_getUid("alloc")), 
+		    py2app_sel_getUid("init"));
 
-    title = xCFArrayGetValueAtIndex(lines, 0);
-    xCFRetain(title);
+    title = py2app_CFArrayGetValueAtIndex(lines, 0);
+    py2app_CFRetain(title);
     AUTORELEASE(title);
     lineCount -= 1;
-    xCFArrayRemoveValueAtIndex(lines, lineCount);
-    xNSLog(xCFSTR("%@"), title);
+    py2app_CFArrayRemoveValueAtIndex(lines, lineCount);
+    py2app_NSLog(py2app_CFSTR("%@"), title);
     if (lineCount > 0) {
         CFStringRef showerr;
-        errmsg = xCFStringCreateByCombiningStrings(
-            NULL, lines, xCFSTR("\r"));
+        errmsg = py2app_CFStringCreateByCombiningStrings(
+            NULL, lines, py2app_CFSTR("\r"));
         AUTORELEASE(errmsg);
-        showerr = MSG(
-            MSG(errmsg, "componentsSeparatedByString:", xCFSTR("\r")),
-            "componentsJoinedByString:", xCFSTR("\n"));
-        xNSLog(xCFSTR("%@"), showerr);
+        showerr = ((id(*)(id, SEL, id))py2app_objc_msgSend)(
+            ((id(*)(id, SEL, id))py2app_objc_msgSend)(errmsg, py2app_sel_getUid("componentsSeparatedByString:"), py2app_CFSTR("\r")),
+            py2app_sel_getUid("componentsJoinedByString:"), py2app_CFSTR("\n"));
+        py2app_NSLog(py2app_CFSTR("%@"), showerr);
     } else {
-        errmsg = xCFSTR("");
+        errmsg = py2app_CFSTR("");
     }
 
     ensureGUI();
     if (!buttonURL) {
-        int choice = xNSRunAlertPanel(
-            title, xCFSTR("%@"), xCFSTR(ERR_TERMINATE),
-            xCFSTR(ERR_CONSOLEAPPTITLE), NULL, errmsg);
-        if (choice == NSAlertAlternateReturn) openConsole();
+        int choice = py2app_NSRunAlertPanel(
+            title, py2app_CFSTR("%@"), py2app_CFSTR(ERR_TERMINATE),
+            py2app_CFSTR(ERR_CONSOLEAPPTITLE), NULL, errmsg);
+        if (choice == NSAlertAlternateReturn) py2app_openConsole();
     } else {
-        int choice = xNSRunAlertPanel(
-            title, xCFSTR("%@"), xCFSTR(ERR_TERMINATE),
+        int choice = py2app_NSRunAlertPanel(
+            title, py2app_CFSTR("%@"), py2app_CFSTR(ERR_TERMINATE),
             buttonString, NULL, errmsg);
         if (choice == NSAlertAlternateReturn) {
-            id ws = MSG(CLS("NSWorkspace"), "sharedWorkspace");
-            MSG(ws, "openURL:", buttonURL);
+            id ws = ((id(*)(id, SEL))py2app_objc_msgSend)(py2app_objc_getClass("NSWorkspace"), py2app_sel_getUid("sharedWorkspace"));
+            ((void(*)(id, SEL, id))py2app_objc_msgSend)(ws, py2app_sel_getUid("openURL:"), buttonURL);
         }
     }
-    MSG(releasePool, "release");
-    xCFRelease(lines);
+    ((void(*)(id, SEL))py2app_objc_msgSend)(releasePool, py2app_sel_getUid("release"));
+    py2app_CFRelease(lines);
     return -1;
 }
 
     char c_mainScript[PATH_MAX];
     char **argv_new;
     struct stat sb;
-    const struct mach_header *py_dylib;
-    NSSymbol tmpSymbol;
+    void *py_dylib;
     int rval;
     FILE *mainScriptFile;
 
 
-    if (!getApplicationName()) return report_error(ERR_NONAME);
-    pyLocations = (CFArrayRef)getKey("PyRuntimeLocations");
+    if (!py2app_getApplicationName()) return report_error(ERR_NONAME);
+    pyLocations = (CFArrayRef)py2app_getKey("PyRuntimeLocations");
     if (!pyLocations) return report_error(ERR_PYRUNTIMELOCATIONS);
-    pyLocation = findPyLocation(pyLocations);
+    pyLocation = py2app_findPyLocation(pyLocations);
     if (!pyLocation) return report_error(ERR_NOPYTHONRUNTIME);
 
     setExecutablePath();
     if ((resource_path == NULL) || (strchr(resource_path, ':') != NULL)) {
         return report_error(ERR_COLONPATH);
     }
-    setPythonPath();
+    py2app_setPythonPath();
     setenv("ARGVZERO", argv[0], 1);
 
     mainScript = getMainScript();
     if (!mainScript) return report_error(ERR_NOPYTHONSCRIPT);
 
     pythonInterpreter = getPythonInterpreter(pyLocation);
-    xCFStringGetCString(
+    py2app_CFStringGetCString(
         pythonInterpreter, c_pythonInterpreter,
         sizeof(c_pythonInterpreter), kCFStringEncodingUTF8);
-    xCFRelease(pythonInterpreter);
+    py2app_CFRelease(pythonInterpreter);
     if (lstat(c_pythonInterpreter, &sb) == 0) {
         if (!((sb.st_mode & S_IFLNK) == S_IFLNK)) {
             setenv("PYTHONHOME", resource_path, 1);
         }
     }
 
-    xCFStringGetCString(pyLocation, buf, sizeof(buf), kCFStringEncodingUTF8);
-    py_dylib = NSAddImage(buf, PYMACAPP_NSIMAGEFLAGS);
+    py2app_CFStringGetCString(pyLocation, buf, sizeof(buf), kCFStringEncodingUTF8);
+    py_dylib = dlopen(buf, RTLD_LAZY);
     if (!py_dylib) return report_linkEdit_error();
 
-#define LOOKUP_SYMBOL(NAME) \
-    tmpSymbol = NSLookupSymbolInImage(py_dylib, "_" # NAME, PYMACAPP_NSLOOKUPSYMBOLINIMAGEFLAGS)
-#define LOOKUP_DEFINEADDRESS(NAME, ADDRESS) \
-    NAME ## Ptr NAME = (NAME ## Ptr)ADDRESS
-#define LOOKUP_DEFINE(NAME) \
-    LOOKUP_DEFINEADDRESS(NAME, NSAddressOfSymbol(tmpSymbol))
 #define LOOKUP(NAME) \
-    LOOKUP_SYMBOL(NAME); \
-    if ( !tmpSymbol ) \
-        return report_linkEdit_error(); \
-    LOOKUP_DEFINE(NAME)
+	    NAME ## Ptr py2app_ ## NAME = (NAME ## Ptr)dlsym(py_dylib, #NAME); \
+	    if (!py2app_ ## NAME) { \
+		return report_linkEdit_error(); \
+	    } 
     
-    LOOKUP_SYMBOL(Py_DecRef);
-    LOOKUP_DEFINEADDRESS(Py_DecRef, (tmpSymbol ? NSAddressOfSymbol(tmpSymbol) : &DefaultDecRef));
     LOOKUP(Py_SetProgramName);
     LOOKUP(Py_Initialize);
     LOOKUP(PyRun_SimpleFile);
     LOOKUP(PyObject_GetAttrString);
 
 #undef LOOKUP
-#undef LOOKUP_DEFINE
-#undef LOOKUP_DEFINEADDRESS
-#undef LOOKUP_SYMBOL
 
-    Py_SetProgramName(c_pythonInterpreter);
+    py2app_Py_SetProgramName(c_pythonInterpreter);
 
-    Py_Initialize();
+    py2app_Py_Initialize();
 
-    xCFStringGetCString(
+    py2app_CFStringGetCString(
         mainScript, c_mainScript,
         sizeof(c_mainScript), kCFStringEncodingUTF8);
-    xCFRelease(mainScript);
+    py2app_CFRelease(mainScript);
 
     argv_new = alloca((argc + 1) * sizeof(char *));
     argv_new[argc] = NULL;
     argv_new[0] = c_mainScript;
     memcpy(&argv_new[1], &argv[1], (argc - 1) * sizeof(char *));
-    PySys_SetArgv(argc, argv_new);
+    py2app_PySys_SetArgv(argc, argv_new);
 
     mainScriptFile = fopen(c_mainScript, "r");
-    rval = PyRun_SimpleFile(mainScriptFile, c_mainScript);
+    rval = py2app_PyRun_SimpleFile(mainScriptFile, c_mainScript);
     fclose(mainScriptFile);
     
-    while (rval) {
-        PyObject *exc, *exceptionClassName, *v, *exceptionName;
-        CFStringRef clsName, excName;
-
-        exc = PySys_GetObject("last_type");
-        if ( !exc ) {
-            rval = report_error(ERR_UNKNOWNPYTHONEXCEPTION);
-            break;
-        }
-
-        exceptionClassName = PyObject_GetAttrString(exc, "__name__");
-        if (!exceptionClassName) {
-            rval = report_error(ERR_UNKNOWNPYTHONEXCEPTION);
-            break;
-        }
-
-        v = PySys_GetObject("last_value");
-        exceptionName = (v ? PyObject_Str(v) : NULL);
-
-        clsName = xCFSTR(PyString_AsString(exceptionClassName));
-        Py_DecRef(exceptionClassName);
-        if (exceptionName) {
-            excName = xCFSTR(PyString_AsString(exceptionName));
-            Py_DecRef(exceptionName);
-        } else {
-            excName = xCFSTR("");
-        }
-        rval = report_script_error(ERR_PYTHONEXCEPTION, clsName, excName);
-        break;
+    if (rval) {
+        rval = report_script_error(ERR_PYTHONEXCEPTION);
     }
 
-    Py_Finalize();
+    py2app_Py_Finalize();
 
     return rval;
 }
         fprintf(stderr, "CoreFoundation not found or functions missing\n");
         return -1;
     }
-    if (!xCFBundleGetMainBundle()) {
+    if (!py2app_CFBundleGetMainBundle()) {
         fprintf(stderr, "Not bundled, exiting\n");
         return -1;
     }
-    pool = xCFArrayCreateMutable(NULL, 0, xkCFTypeArrayCallBacks);
-    if (!pool) {
+    py2app_pool = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
+    if (!py2app_pool) {
         fprintf(stderr, "Couldn't create global pool\n");
         return -1;
     }
     rval = py2app_main(argc, argv, envp);
-    xCFRelease(pool);
+    py2app_CFRelease(py2app_pool);
     return rval;
 }

File py2app/build_app.py

View file
             version = sys.version
         version = version[:3]
         info = None
+        if os.path.exists(os.path.join(prefix, ".Python")):
+            # We're in a virtualenv environment, locate the real prefix
+            fn = os.path.join(prefix, "lib", "python%d.%d"%(sys.version_info[:2]), "orig-prefix.txt")
+            if os.path.exists(fn):
+                prefix = open(fn, 'rU').read().strip()
+
         try:
             fmwk = macholib.dyld.framework_find(prefix)
         except ValueError:
             info = None
         else:
             info = macholib.dyld.framework_info(fmwk)
+
+
         if info is not None:
             dylib = info['name']
             runtime = os.path.join(info['location'], info['name'])

File py2app/bundletemplate/prebuilt/main

Binary file removed.

File py2app/bundletemplate/prebuilt/main-32bit

Binary file added.

File py2app/bundletemplate/prebuilt/main-fat3

Binary file added.

File py2app/bundletemplate/prebuilt/main-intel

Binary file added.

File py2app/bundletemplate/prebuilt/main-universal

Binary file added.

File py2app/bundletemplate/setup.py

View file
 import os
+import re
 import distutils.sysconfig
 
+gPreBuildVariants = [
+    {
+        'name': 'main-universal',
+        'target': '10.5',
+        'cflags': '-isysroot /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch ppc -arch ppc64 -arch x86_64',
+        'cc': 'gcc-4.2',
+    },
+    {
+        'name': 'main-fat3',
+        'target': '10.5',
+        'cflags': '-isysroot / -arch i386 -arch ppc -arch x86_64',
+        'cc': 'gcc-4.2',
+    },
+    {
+        'name': 'main-intel',
+        'target': '10.5',
+        'cflags': '-isysroot / -arch i386 -arch x86_64',
+        'cc': 'gcc-4.2',
+    },
+    {
+        'name': 'main-32bit',
+        'target': '10.3',
+        'cflags': '-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc',
+        'cc': 'gcc-4.0',
+    },
+]
+
+
 def main():
     basepath = os.path.dirname(__file__)
     builddir = os.path.join(basepath, 'prebuilt')
     if not os.path.exists(builddir):
         os.makedirs(builddir)
-    dest = os.path.join(builddir, 'main')
     src = os.path.join(basepath, 'src', 'main.m')
-    if not os.path.exists(dest) or os.stat(dest).st_mtime < os.stat(src).st_mtime:
-        cfg = distutils.sysconfig.get_config_vars()
-        CC = cfg['CC']
-        CFLAGS = cfg['CFLAGS'].replace(' -dynamic', '')
-        LDFLAGS = cfg['LDFLAGS'] + ' -bundle -framework Foundation -framework AppKit'
 
-        #CC = os.environ.get("CC", "cc")
-        #CFLAGS = '-Os -Wall'
-        #LDFLAGS = '-g -bundle -framework Foundation -framework AppKit'
-        os.environ['MACOSX_DEPLOYMENT_TARGET']='10.3'
-        os.system('"%(CC)s" -arch i386 -arch ppc -o "%(dest)s" "%(src)s" %(CFLAGS)s %(LDFLAGS)s' % locals())
-        os.system('strip -Sx "%(dest)s"' % locals())
+    cfg = distutils.sysconfig.get_config_vars()
+
+    BASE_CFLAGS = cfg['CFLAGS']
+    BASE_CFLAGS = BASE_CFLAGS.replace('-dynamic', '')
+    while True:
+        x = re.sub('-arch\s+\S+', '', BASE_CFLAGS)
+        if x == BASE_CFLAGS:
+            break
+        BASE_CFLAGS=x
+
+    while True:
+        x = re.sub('-isysroot\s+\S+', '', BASE_CFLAGS)
+        if x == BASE_CFLAGS:
+            break
+        BASE_CFLAGS=x
+
+    BASE_CFLAGS += ' -bundle -framework Foundation -framework AppKit'
+
+    for entry in gPreBuildVariants:
+        CC=entry['cc']
+        CFLAGS = BASE_CFLAGS + ' ' + entry['cflags']
+        os.environ['MACOSX_DEPLOYMENT_TARGET'] = entry['target']
+        dest = os.path.join(builddir, entry['name'])
+        if not os.path.exists(dest) or (
+                os.stat(dest).st_mtime < os.stat(src).st_mtime):
+            os.system('"%(CC)s" -arch i386 -arch ppc -o "%(dest)s" "%(src)s" %(CFLAGS)s' % locals())
+
+    dest = os.path.join(
+        builddir,
+        'main-' + distutils.util.get_platform().split('-')[-1]
+    )
+
     return dest
 
 if __name__ == '__main__':

File setup.py

View file
     description='Create standalone Mac OS X applications with Python',
     author='Bob Ippolito',
     author_email='bob@redivi.com',
+    maintainer='Ronald Oussoren',
+    maintainer_email="ronaldoussoren@mac.com",
     url='http://undefined.org/python/#py2app',
     download_url='http://undefined.org/python/#py2app',
     license='MIT or PSF License',
     platforms=['MacOS X'],
     long_description=LONG_DESCRIPTION,
     classifiers=CLASSIFIERS,
-    #setup_requires=[
-    #    "bdist_mpkg>=0.4.2",
-    #],
     install_requires=[
         "altgraph>=0.6.7",
         "modulegraph>=0.7.3",
-        "macholib>=1.2.1",
-    #    "bdist_mpkg>=0.4",
+        "macholib>=1.2.2",
     ],
 
     # sources