Commits

Ronald Oussoren  committed d4b5098

- Fix bug #830342 (NSNib.instantiateNibWithOwner:topLevelObjects: signature)
- Fix bug #830343 (Type in PyObjCTools.AppHelper)
- Fix bug #828911 (Bad wrapping for NSModalSession type)
- check if the signature passed to objc.selector is valid.
- fix some in-line documentation
- fix Examples/HelloWorld.py
- remove call to abort in objc_support.m
- add a test for the fix for #828911, this is not yet part of the unittests
because it requires full GUI access.

  • Participants
  • Parent commits 3b8967f

Comments (0)

Files changed (28)

File pyobjc/Doc/TODO

 based on the Apple documentation on the layout of packages, there is no need
 to support 10.1-style packages. This new module should be donated to
 MacPython).
+
+Implement more of NSMutableDictionary in OC_PythonDictionary
+.............................................................
+
+The implementation of OC_PythonDictionary is very minimal, we should add
+additional methods in the NSMutableDictionary interface if those can be 
+implemented efficiently. The default implementation will take care of the
+methods we cannot implement efficiently.
+
+And the same is true of OC_PythonArray

File pyobjc/Doc/coding-style.txt

 C code
 ------
 
-The coding style for core Python is used (see `PEP 7`_). We use ``PyObjC`` instead
-of ``Py`` as the prefix for globally visible symbols.
+The coding style for core Python is used (see `PEP 7`_). We use ``PyObjC`` 
+instead of ``Py`` as the prefix for globally visible symbols.
+
+All (Objective-)C files in ``Modules/objc/`` should include ``"pyobjc.h"`` as
+their first include. The (Objective-)C files in the wrappers for frameworks
+should include ``"pyobjc-api.h"`` and should not use other include-files in
+``Modules/objc`` other than ``pyobjc-api.h`` and ``wrapper-const-table.h``.
 
 .. _`PEP 7`: http://www.python.org/peps/pep-0007.txt
 

File pyobjc/Examples/GUITests/00ReadMe.txt

+This directory contains a number of tests that require full GUI access. These
+tests should be integrated in the unittest framework.

File pyobjc/Examples/GUITests/test_modalsession.py

+"""
+Check if NSModalSessions are properly wrapped.
+
+XXX: This is not a proper unittest, it requires human eyes to check if the
+output is correct.
+"""
+import objc
+from Foundation import *
+from AppKit import *
+import time
+
+def doTest():
+    alertPanel = None
+    modalSession = None
+    app = NSApplication.sharedApplication()
+    try:
+        alertPanel = NSGetInformationalAlertPanel(
+                "Please wait", "Bla bla bla", None, None, None)
+        modalSession = app.beginModalSessionForWindow_(alertPanel)
+
+        print modalSession, modalSession.pointer
+        time.sleep(1)
+    finally:
+        if modalSession is not None:
+            app.endModalSession_(modalSession)
+            modalSession = None
+
+        if alertPanel is not None:
+            NSReleaseAlertPanel(alertPanel)
+            alertPanel = None
+
+
+
+class AppDelegate (NSObject):
+    def applicationDidFinishLaunching_(self, aNotification):
+        doTest()
+        aNotification.object().terminate_(None)
+
+def main():
+    app = NSApplication.sharedApplication()
+
+    delegate = AppDelegate.alloc().init()
+    NSApp().setDelegate_(delegate)
+
+    win = NSWindow.alloc()
+    frame = ((200.0, 300.0), (250.0, 100.0))
+    win.initWithContentRect_styleMask_backing_defer_ (frame, 15, 2, 0)
+    win.setTitle_ ('HelloWorld')
+
+    app.run()    
+
+if __name__ == '__main__' : 
+    main()

File pyobjc/Examples/HelloWorld.py

     # NSApp.setDelegate_() doesn't retain it. A local variable is
     # enough here.
     delegate = AppDelegate.alloc().init()
-    NSApp.setDelegate_(delegate)
+    NSApp().setDelegate_(delegate)
 
     win = NSWindow.alloc()
     frame = ((200.0, 300.0), (250.0, 100.0))

File pyobjc/Lib/AppKit/_AppKitSignatures.py

 setSignatureForSelector("NSView", "adjustPageHeightNew:top:bottom:limit:", "v@:o^ffff")
 setSignatureForSelector("NSView", "adjustPageWidthNew:left:right:limit:", "v@:o^ffff")
 setSignatureForSelector("NSView", "knowsPageRange:", "v@:N^{_NSRange=II}")
-setSignatureForSelector("NSNib", "instantiateNibWithOwner:topLevelObjects:", "c@:@o^@")
+setSignatureForSelector("NSNib", "instantiateNibWithOwner:topLevelObjects:", "c@:@N^@")
 setSignatureForSelector("NSWorkspace", "launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:", "c24@0:4@8I12@16o^@20")
 setSignatureForSelector("NSWorkspace", "openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:", "c28@0:4@8@12I16@20o^@24")
 setSignatureForSelector("NSTextRulerOptions", "sheetDidEnd:returnCode:contextInfo:", "v@:@ii")

File pyobjc/Lib/PyObjCTools/AppHelper.py

 
 Exported functions:
 * runEventLoop - run NSApplicationMain in a safer way
-* sheetEndMethod - set correct signature for NSSheet callbacks
+* endSheetMethod - set correct signature for NSSheet callbacks
 """
 
-__all__ = ( 'runEventLoop', 'sheetEndMethod' )
+__all__ = ( 'runEventLoop', 'endSheetMethod' )
 
 from AppKit import NSApplicationMain, NSApp, NSRunAlertPanel
 from Foundation import NSLog

File pyobjc/Modules/AddressBook/_AddressBook.m

 /*
  * Mapping of static items in the AddressBook framework
- * 
- * - constants 
- * - enumerations
  */
 #include <Python.h>
 

File pyobjc/Modules/AppKit/_AppKitMapping.m

-/*
- * This module contains custom mapping functions for problematic methods
- */
-
-#include <Python.h>
-#include <Foundation/Foundation.h>
-#include <AppKit/AppKit.h> // really should be Cocoa
-#include "pyobjc-api.h"
-
-
-
-PyDoc_STRVAR(mapping_doc,
-	"This module registers some utility functions with the PyObjC core \n"
-	"and is not used by 'normal' python code"
-);
-
-static PyMethodDef mapping_methods[] = {
-	{ 0, 0, 0, 0 }
-};
-
-
-void init_AppKitMapping(void);
-
-#include "_AppKitMapping_NSApplication.m"
-#include "_AppKitMapping_NSATSTypeSetter.m"
-#include "_AppKitMapping_NSBezierPath.m"
-#include "_AppKitMapping_NSBitmap.m"
-#include "_AppKitMapping_NSBitmapImageRep.m"
-#include "_AppKitMapping_NSFont.m"
-#include "_AppKitMapping_NSMatrix.m"
-#include "_AppKitMapping_NSLayoutManager.m"
-#include "_AppKitMapping_NSMovie.m"
-#include "_AppKitMapping_NSOpenGLContext.m"
-#include "_AppKitMapping_NSOpenGLPixelFormat.m"
-#include "_AppKitMapping_NSQuickDrawView.m"
-#include "_AppKitMapping_NSSimpleHorizontalTypesetter.m"
-#include "_AppKitMapping_NSView.m"
-#include "_AppKitMapping_NSWindow.m"
-
-void init_AppKitMapping(void)
-{
-	PyObject *m, *d;
-
-	m = Py_InitModule4("_AppKitMapping", mapping_methods, mapping_doc, 
-		NULL, PYTHON_API_VERSION);
-	if (!m) return;
-
-	d = PyModule_GetDict(m);
-	if (!d) return;
-	
-
-	if (PyObjC_ImportAPI(m) < 0) {
-		return;
-	}
-
-
-	/* register other specials */
-	if (_pyobjc_install_NSApplication() < 0) return;
-	if (_pyobjc_install_NSATSTypesetter() < 0) return;
-	if (_pyobjc_install_NSBezierPath() < 0) return;
-	if (_pyobjc_install_NSBitmap() < 0) return;
-	if (_pyobjc_install_NSBitmapImageRep() < 0) return;
-	if (_pyobjc_install_NSFont() < 0) return;
-	if (_pyobjc_install_NSLayoutManager() < 0) return;
-	if (_pyobjc_install_NSMatrix() < 0) return;
-	if (_pyobjc_install_NSMovie() < 0) return;
-	if (_pyobjc_install_NSOpenGLContext() < 0) return;
-	if (_pyobjc_install_NSOpenGLPixelFormat() < 0) return;
-	if (_pyobjc_install_NSQuickDrawView() < 0) return;
-	if (_pyobjc_install_NSSimpleHorizontalTypesetter() < 0) return;
-	if (_pyobjc_install_NSView() < 0) return;
-	if (_pyobjc_install_NSWindow() < 0) return;
-
-}

File pyobjc/Modules/AppKit/_AppKitMapping_NSApplication.m

 {
 	int r = 0;
 
-	r = PyObjCPointerWrapper_Register(@encode(NSModalSession*), 
+	r = PyObjCPointerWrapper_Register(@encode(NSModalSession), 
 		NSModalSession_New, NSModalSession_Convert);
 	if (r == -1) return -1;
 

File pyobjc/Modules/InterfaceBuilder/_InterfaceBuilder.m

 /*
  * Mapping of static items in the InterfaceBuilder framework
- * 
- * - constants 
- * - enumerations
  */
 #include <Python.h>
 

File pyobjc/Modules/PreferencePanes/_PreferencePanes.m

 /*
  * Mapping of static items in the PreferencePanes framework
- * 
- * - constants 
- * - enumerations
  */
 #include <Python.h>
 

File pyobjc/Modules/WebKit/_WebKit.m

 /*
  * Mapping of static items in the WebKit framework
- * 
- * - constants 
- * - enumerations
  */
 #include <Python.h>
 

File pyobjc/Modules/autoGIL.c

+/*
+ * autoGIL - automaticly give up the GIL when the runloop is sleeping
+ *
+ * This module exports one function: installAutoGIL. 
+ */
 #include "Python.h"
 #include <CoreFoundation/CFRunLoop.h>
 

File pyobjc/Modules/objc/OC_PythonDictionary.h

  * a subclass of NSMutableDictonary Python dictionaries can be used
  * whereever instances of NSDictionary or NSMutableDictionary are expected.
  *
- * TODO: Implement more methods of NSMutableDictionary: All methods that can
- * be efficiently mapped onto the Python C API for dictionaries.
- *
  * NOTE: We currently only proxy real 'dict' objects this way, the generic
  * PyMapping_* API is not flexible enough!
  */

File pyobjc/Modules/objc/OC_PythonObject.h

 /* Copyright (c) 1996,97 by Lele Gaifax.  All Rights Reserved
+ * Copyright (c) 2002,2003 Ronald Oussoren.
  *
  * This software may be used and distributed freely for any purpose
  * provided that this notice is included unchanged on any and all
  *       that was removed by Ronald because no-one was using or maintaining
  *       that functionality. OC_PythonObject is now a simple proxy for plain
  *       python objects.
+ *
  */
 
 #ifndef _OC_PythonObject_H

File pyobjc/Modules/objc/OC_PythonObject.m

 /* Copyright (c) 1996,97 by Lele Gaifax.  All Rights Reserved
+ * Copyright 2002, 2003 Ronald Oussoren, Jack Jansen
  *
  * This software may be used and distributed freely for any purpose
  * provided that this notice is included unchanged on any and all

File pyobjc/Modules/objc/ObjCPointer.h

 #ifndef PyObjC_OBJC_POINTER_H
 #define PyObjC_OBJC_POINTER_H
 
-/* Python wrapper around C pointer */
+/* Python wrapper around C pointer 
+ *
+ * NOTE: This class is almost never used, pointers in method interfaces are,
+ * or should be, treated differently and I've yet to run into a Cocoa structure 
+ * that contains pointers.
+ */
 
 typedef struct
 {

File pyobjc/Modules/objc/ObjCPointer.m

 /* Copyright (c) 1996,97 by Lele Gaifax.  All Rights Reserved
- * With various updates by Ronald Oussoren and others.
+ * With various updates by Ronald Oussoren and others ((C) 2002, 2003)
  *
  * This software may be used and distributed freely for any purpose
  * provided that this notice is included unchanged on any and all

File pyobjc/Modules/objc/class-builder.m

 	}
 
 	if (method_list) {
-		class_addMethods(&(new_class->class), method_list);
+		PyObjCRT_ClassAddMethodList(
+			&(new_class->class), 
+			method_list);
 	}
 	if (meta_method_list) {
-		class_addMethods(&(new_class->meta_class), meta_method_list);
+		PyObjCRT_ClassAddMethodList(
+			&(new_class->meta_class), 
+			meta_method_list);
 	}
 
 	Py_XDECREF(py_superclass);

File pyobjc/Modules/objc/module.m

 /*
- * This module implements an extension-class with a custom meta-class.
- *
- * The idea is to use a trick like this to perform our magic tasks with
- * Python subclasses of Objective-C classes.
+ * The module entry point for ``objc._objc``. This file contains ``init_objc``
+ * and the implementation of a number of exported functions.
  */
 #include "pyobjc.h"
 
 {
 static  char* keywords[] = { "module_name", "module_globals", "bundle_path", "bundle_identifier", NULL };
 	id        bundle;
-	id        strval;
+	NSString* strval;
 	int err;
 	PyObject* bundle_identifier = NULL;
 	PyObject* bundle_path = NULL;

File pyobjc/Modules/objc/objc-runtime-apple.h

 /* Copyright (c) 1996,97,98 by Lele Gaifax.  All Rights Reserved
+ * Copyright (c) 2003 Ronald Oussoren
  *
  * This software may be used and distributed freely for any purpose
  * provided that this notice is included unchanged on any and all
 	m->method_imp = imp;
 }
 
+static void
+PyObjCRT_ClassAddMethodList(Class cls, struct objc_method_list* lst)
+{
+	class_addMethods(cls, lst);
+}
+
+
 extern struct objc_method_list* PyObjCRT_AllocMethodList(int);
 
 typedef Method PyObjCRT_Method_t;

File pyobjc/Modules/objc/objc-runtime-gnu.h

    extern void __objc_add_class_to_hash(Class);
 #endif
 
+static void
+PyObjCRT_ClassAddMethodList(Class cls, MethodList_t lst)
+{
+	class_add_method_list(cls, lst);
+}
+
 #ifndef nil
 #define nil NULL
 #endif

File pyobjc/Modules/objc/objc_support.h

 /* Copyright (c) 1996,97,98 by Lele Gaifax.  All Rights Reserved
+ * Copyright (2) 2003 Ronald Oussoren
  *
  * This software may be used and distributed freely for any purpose
  * provided that this notice is included unchanged on any and all

File pyobjc/Modules/objc/objc_support.m

 /* Copyright (c) 1996,97,98 by Lele Gaifax.  All Rights Reserved
+ * Copyright (c) 2002, 2003 Ronald Oussoren
  *
  * This software may be used and distributed freely for any purpose
  * provided that this notice is included unchanged on any and all
 
 const char * 
 PyObjCRT_SkipTypeSpec (const char *type)
-
 {
 	type = PyObjCRT_SkipTypeQualifiers (type);
 
 	default:
 		ObjCErr_Set(ObjCExc_internal_error,
 			"PyObjCRT_SkipTypeSpec: Unhandled type '%#x'", *type); 
-		abort();
 		return NULL;
 	}
 
+	/* The compiler inserts a number after the actual signature, 
+	 * this number may or may not be usefull depending on the compiler
+	 * version. We never use it.
+	 */
 	while (type && isdigit(*type)) type++;
 	return type;
 }

File pyobjc/Modules/objc/py2.2bool.h

 /*
  *  A boolean type for python 2.2, this is basicly a copy of boolobject.h from
  *  Python 2.3. The python license applies.
+ *
+ *  Copyright PSF.
  */
 
 /* Boolean object interface */

File pyobjc/Modules/objc/pyobjc-compat.h

 #ifndef PyObjC_COMPAT_H
 #define PyObjC_COMPAT_H
 
-
 /* 
  * Compatibilty definitions 
  */

File pyobjc/Modules/objc/selector.m

 		signature = python_signature_to_objc(rettype, argtypes,
 			signature_buf, sizeof(signature_buf));
 		if (signature == NULL) return NULL;
+	} else {
+		/* Check if the signature string is valid */
+		char* cur;
+
+		cur = signature;
+		while (*cur != '\0') {
+			cur = PyObjCRT_SkipTypeSpec(cur);
+			if (cur == NULL) {
+				PyErr_SetString(
+					PyExc_ValueError, 
+					"invalid signature");
+				return NULL;
+			}
+		}
 	}