Commits

illume committed b838777

python3.1 support for OSX.

Comments (0)

Files changed (4)

     elif sys.platform == 'darwin':
         print_('Using Darwin configuration...\n')
         import config_darwin as CFG
-        additional_platform_setup = file("Setup_Darwin.in", "r").readlines()
+        additional_platform_setup = open("Setup_Darwin.in", "r").readlines()
     else:
         print_('Using UNIX configuration...\n')
         import config_unix as CFG
 
     def configure(self, incdirs, libdirs):
         incname = self.checkhead
-        libnames = self.checklib, string.lower(self.name)
+        libnames = self.checklib, self.name.lower()
         for dir in incdirs:
             path = os.path.join(dir, incname)
             if os.path.isfile(path):
                     self.lib_dir = dir
                     break
         if self.lib_dir and self.inc_dir:
-            print self.name + '        '[len(self.name):] + ': found'
+            print (self.name + '        '[len(self.name):] + ': found')
             self.found = 1
         else:
-            print self.name + '        '[len(self.name):] + ': not found'
+            print (self.name + '        '[len(self.name):] + ': not found')
 
 class FrameworkDependency(Dependency):
     def configure(self, incdirs, libdirs):
             n += 'Library/Frameworks/'
             fmwk = n + self.libs + '.framework/Versions/Current/'
             if os.path.isfile(fmwk + self.libs):
-                print 'Framework ' + self.libs + ' found'
+                print ('Framework ' + self.libs + ' found')
                 self.found = 1
                 self.inc_dir = fmwk + 'Headers'
                 self.cflags = (
                 self.origlib = self.libs
                 self.libs = ''
                 return
-        print 'Framework ' + self.libs + ' not found'
+        print ('Framework ' + self.libs + ' not found')
 
 
 class DependencyPython:
             else:
                 self.inc_dir = os.path.split(fullpath)[0]
         if self.found:
-            print self.name + '        '[len(self.name):] + ': found', self.ver
+            print (self.name + '        '[len(self.name):] + ': found', self.ver)
         else:
-            print self.name + '        '[len(self.name):] + ': not found'
+            print (self.name + '        '[len(self.name):] + ': not found')
 
 DEPS = [
     FrameworkDependency('SDL', 'SDL.h', 'libSDL', 'SDL'),
 def main():
     global DEPS
 
-    print 'Hunting dependencies...'
+    print ('Hunting dependencies...')
     incdirs = ['/usr/local/include','/opt/local/include']
     libdirs = ['/usr/local/lib','/opt/local/lib']
     newconfig = []
 
 
 if __name__ == '__main__':
-    print """This is the configuration subscript for OSX Darwin.
-             Please run "config.py" for full configuration."""
+    print ("""This is the configuration subscript for OSX Darwin.
+             Please run "config.py" for full configuration.""")
 import os, sys
-import MacOS
+
+try:
+    import MacOS
+except:
+    MacOS = None
+
 from pygame.pkgdata import getResource
 
 from pygame import sdlmain_osx
 def Video_AutoInit():
     """This is a function that's called from the c extension code
        just before the display module is initialized"""
-    if not MacOS.WMAvailable():
+    if MacOS and not MacOS.WMAvailable():
         if not sdlmain_osx.WMEnable():
             raise ImportError("Can not access the window manager.  Use py2app or execute with the pythonw script.")
     if not sdlmain_osx.RunningFromBundleWithNSApplication():

src/sdlmain_osx.m

 /* Mac OS X functions to accommodate the fact SDLMain.m is not included */
 
 #include "pygame.h"
+
 #include <Carbon/Carbon.h>
 #include <Foundation/Foundation.h>
 #include <AppKit/NSApplication.h>
 #include <Foundation/NSData.h>
 #include <AppKit/NSImage.h>
 
+#include "pgcompat.h"
+
 struct CPSProcessSerNum
 {
 	UInt32 lo;
     { NULL, NULL, 0, NULL}
 };
 
-PYGAME_EXPORT
-void initsdlmain_osx (void)
+
+
+MODINIT_DEFINE (sdlmain_osx)
 {
-    PyObject *mod;
+    PyObject *module;
 
     /* create the module */
-    mod = Py_InitModule3 ("sdlmain_osx", macosx_builtins, NULL);
+
+#if PY3
+    static struct PyModuleDef _module = {
+        PyModuleDef_HEAD_INIT,
+        MODPREFIX "sdlmain_osx",
+        NULL,
+        -1,
+        macosx_builtins,
+        NULL, NULL, NULL, NULL
+    };
+#endif
+
+
+#if PY3
+    module = PyModule_Create (&_module);
+#else
+    #error "hi";
+    module = Py_InitModule3 (MODPREFIX "sdlmain_osx", macosx_builtins, NULL);
+#endif
+
 
     /*imported needed apis*/
     import_pygame_base ();
+    if (PyErr_Occurred ()) {
+        MODINIT_ERROR;
+    }
+
+
+    MODINIT_RETURN (module);
 }