Commits

Ronald Oussoren  committed 95993d2

Add (or enhance the existing) C extension that uses all @protocols

This is needed because framework only export those protocol
definitions that are used by the code in that framework. Without
the extensions some protocols are not available to python code,
see issue #44 for more information.

Note: the various *_protocols.m files are generated.

Fixes issue #44

  • Participants
  • Parent commits 6a7b636
  • Branches pyobjc-2.5.x

Comments (0)

Files changed (37)

File pyobjc-core/Modules/objc/module.m

 	return protocols;
 }
 
+PyDoc_STRVAR(protocolNamed_doc,
+	"_protocolNamed(name) -> Protocol\n");
+static PyObject*
+protocolNamed(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
+{
+static 	char* keywords[] = { "name", NULL };
+	char* name;
+	Protocol* p;
+
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", keywords, &name)) {
+		return NULL;
+	}
+
+	p = objc_getProtocol(name);
+	if (p == NULL) {
+		PyErr_SetString(PyExc_AttributeError, name);
+		return NULL;
+	}
+	return PyObjCFormalProtocol_ForProtocol(p);
+}
+
 
 PyDoc_STRVAR(protocolsForClass_doc,
 	"protocolsForClass(cls) -> [Protocols]\n"
 	{ "allocateBuffer", (PyCFunction)allocateBuffer, METH_VARARGS|METH_KEYWORDS, allocateBuffer_doc },
 	{ "protocolsForClass", (PyCFunction)protocolsForClass, METH_VARARGS|METH_KEYWORDS, protocolsForClass_doc },
 	{ "protocolsForProcess", (PyCFunction)protocolsForProcess, METH_NOARGS, protocolsForProcess_doc },
+	{ "_protocolNamed", (PyCFunction)protocolNamed, METH_VARARGS|METH_KEYWORDS, protocolNamed_doc },
 	{ "registerCFSignature", (PyCFunction)registerCFSignature, METH_VARARGS|METH_KEYWORDS, registerCFSignature_doc },
 #if PY_MAJOR_VERSION == 2
 	{ "CFToObject", (PyCFunction)objc_CFToObject, METH_VARARGS|METH_KEYWORDS, objc_CFToObject_doc },

File pyobjc-core/Modules/objc/objc-runtime-compat.m

 	return protocols;
 }
 
+static Protocol*  compat_objc_getProtocol(char* name)
+{
+	uint32_t image_count, image_index;
+	image_count = _dyld_image_count();
+	for (image_index = 0; image_index < image_count; image_index++) {
+		uint32_t size = 0;
+		const struct mach_header *mh = _dyld_get_image_header(image_index);
+		intptr_t slide = _dyld_get_image_vmaddr_slide(image_index);
+		ProtocolTemplate *protos = (ProtocolTemplate*)(
+			((char *)getsectdatafromheader(mh, SEG_OBJC, "__protocol", &size)) +
+			slide);
+		uint32_t nprotos = size / sizeof(ProtocolTemplate);
+		uint32_t i;
+
+		if (nprotos == 0) continue;
+
+		for (i = 0; i < nprotos; i++) {
+			Protocol* p = (Protocol*)&protos[i];
+			if (strcmp([protocol name], name) == 0) {
+				return p;
+			}
+		}
+	}
+	return protocols;
+}
+
+
 static void
 compat_objc_registerClassPair(Class cls)
 {
 void (*PyObjC_objc_registerClassPair)(Class) = NULL;
 void (*PyObjC_objc_disposeClassPair)(Class) = NULL;
 Protocol** (*PyObjC_objc_copyProtocolList)(unsigned int*) = NULL;
+Protocol*  (*PyObjC_objc_getProtocol)(char* name) = NULL;
 
 BOOL (*PyObjC_preclass_addMethod)(Class, SEL, IMP, const char*) = NULL;
 BOOL (*PyObjC_preclass_addIvar)(Class cls, 
 	SETUP(objc_registerClassPair);
 	SETUP(objc_disposeClassPair);
 	SETUP(objc_copyProtocolList);
+	SETUP(objc_getProtocol);
 
 	SETUP(object_getClass);
 	SETUP(object_setClass);

File pyobjc-core/NEWS.txt

 - Issue #41: the 'install.py' script in the root of pyobjc repository 
   failed to perform an install when running in a clean checkout of the tree.
 
+- Issue #44: the various Cocoa frameworks only export @protocol defintions when
+  they happen to be used by code in the framework. Added extensions to the
+  various framework wrappers to ensure that all protocols are available to
+  python code.
+
 Version 2.5
 -----------
 

File pyobjc-framework-AddressBook/Lib/AddressBook/__init__.py

 import Foundation
 
 from AddressBook import _metadata
+from AddressBook._AddressBook import *
 
 sys.modules['AddressBook'] = mod = objc.ObjCLazyModule(
     "AddressBook",

File pyobjc-framework-AddressBook/Modules/_AddressBook.m

+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include "pyobjc-api.h"
+
+#import <AddressBook/AddressBook.h>
+
+/* We include the source code here instead of 
+ * using the linker due to limitations in pyobjc-api.h
+ */
+#include "_AddressBook_protocols.m"
+
+
+static PyMethodDef mod_methods[] = {
+	{ 0, 0, 0, 0 } /* sentinel */
+};
+
+
+/* Python glue */
+PyObjC_MODULE_INIT(_AddressBook)
+{
+	PyObject* m;
+	m = PyObjC_MODULE_CREATE(_AddressBook)
+	if (!m) { 
+		PyObjC_INITERROR();
+	}
+
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
+
+	PyObjC_INITDONE();
+}

File pyobjc-framework-AddressBook/Modules/_AddressBook_protocols.m

+/* 
+ * This file is generated by objective.metadata
+ *
+ * Last update: Tue Jan 15 18:56:43 2013
+ */
+
+static void __attribute__((__used__)) use_protocols(void)
+{
+    PyObject* p;
+    p = PyObjC_IdToPython(@protocol(ABImageClient)); Py_XDECREF(p);
+}

File pyobjc-framework-AddressBook/setup.py

 and (Objective-)C frameworks
 '''
 
-from pyobjc_setup import setup
+from pyobjc_setup import setup, Extension
+import os
 
 setup(
     name='pyobjc-framework-AddressBook',
         'pyobjc-core>=2.5.1b1',
         'pyobjc-framework-Cocoa>=2.5.1b1',
     ],
+    ext_modules = [
+        Extension("AddressBook._AddressBook",
+            [ "Modules/_AddressBook.m" ],
+            extra_link_args=["-framework", "AddressBook"],
+            depends=[
+                os.path.join('Modules', fn)
+                    for fn in os.listdir('Modules')
+                    if fn.startswith('_AddressBook') 
+            ]
+        ),
+    ]
 )

File pyobjc-framework-Cocoa/Modules/_AppKit.m

 #include "_AppKit_nsquickdrawview.m"
 #include "_AppKit_nsview.m"
 #include "_AppKit_nswindow.m"
+#include "_AppKit_protocols.m"
 
 
 static PyMethodDef mod_methods[] = {
 PyObjC_MODULE_INIT(_AppKit)
 {
 	PyObject* m;
+	Protocol* p;
 	m = PyObjC_MODULE_CREATE(_AppKit)
 	if (!m) { 
 		PyObjC_INITERROR();
 	if (setup_nsview(m) == -1) PyObjC_INITERROR();
 	if (setup_nswindows(m) == -1) PyObjC_INITERROR();
 
+	p = @protocol(NSSpeechSynthesizerDelegate);
+	if (p != nil) {
+		PyObject* r = PyObjC_ObjCToPython("@", p);
+		Py_XDECREF(r);
+		if (r == NULL) {
+			PyObjC_INITERROR();
+		}
+	}
+
 	PyObjC_INITDONE();
 }

File pyobjc-framework-Cocoa/Modules/_AppKit_protocols.m

+/* 
+ * This file is generated by objective.metadata
+ *
+ * Last update: Tue Jan 15 18:57:46 2013
+ */
+
+static void __attribute__((__used__)) use_protocols(void)
+{
+    PyObject* p;
+    p = PyObjC_IdToPython(@protocol(NSAlertDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSAnimatablePropertyContainer)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSAnimationDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSApplicationDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSBrowserDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSChangeSpelling)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSCollectionViewDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSColorPickingCustom)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSColorPickingDefault)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSComboBoxCellDataSource)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSComboBoxDataSource)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSComboBoxDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSControlTextEditingDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSDatePickerCellDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSDockTilePlugIn)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSDraggingInfo)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSDrawerDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSGlyphStorage)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSIgnoreMisspelledWords)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSImageDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSInputServerMouseTracker)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSInputServiceProvider)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSLayoutManagerDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSMatrixDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSMenuDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSOpenSavePanelDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSOutlineViewDataSource)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSOutlineViewDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPasteboardItemDataProvider)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPasteboardReading)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPasteboardWriting)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPathCellDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPathControlDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPrintPanelAccessorizing)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSRuleEditorDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSSoundDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSSpeechRecognizerDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSSpeechSynthesizerDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSSplitViewDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTabViewDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTableViewDataSource)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTableViewDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextAttachmentCell)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextFieldDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextInput)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextInputClient)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextStorageDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextViewDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTokenFieldCellDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTokenFieldDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSToolbarDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSUserInterfaceItemSearching)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSUserInterfaceValidations)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSValidatedUserInterfaceItem)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSWindowDelegate)); Py_XDECREF(p);
+#if defined(MAC_OS_X_VERSION_10_7)
+    p = PyObjC_IdToPython(@protocol(NSDraggingDestination)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSDraggingSource)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPopoverDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextFinderBarContainer)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextFinderClient)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSTextLayoutOrientationProvider)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSUserInterfaceItemIdentification)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSWindowRestoration)); Py_XDECREF(p);
+#endif /* defined(MAC_OS_X_VERSION_10_7) */
+#if defined(MAC_OS_X_VERSION_10_8)
+    p = PyObjC_IdToPython(@protocol(NSPageControllerDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSSharingServiceDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSSharingServicePickerDelegate)); Py_XDECREF(p);
+#endif /* defined(MAC_OS_X_VERSION_10_8) */
+}

File pyobjc-framework-Cocoa/Modules/_Foundation.m

 #include "_Foundation_nscoder.m"
 #include "_Foundation_string.m"
 #include "_Foundation_typecode.m"
+#include "_Foundation_protocols.m"
 
 static PyMethodDef mod_methods[] = {
 	FOUNDATION_TYPECODE_METHODS

File pyobjc-framework-Cocoa/Modules/_Foundation_protocols.m

+/* 
+ * This file is generated by objective.metadata
+ *
+ * Last update: Tue Jan 15 18:57:44 2013
+ */
+
+static void __attribute__((__used__)) use_protocols(void)
+{
+    PyObject* p;
+    p = PyObjC_IdToPython(@protocol(NSCacheDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSConnectionDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSDiscardableContent)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSKeyedArchiverDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSKeyedUnarchiverDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSMachPortDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSMetadataQueryDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSNetServiceBrowserDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSNetServiceDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPortDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSSpellServerDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSStreamDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSXMLParserDelegate)); Py_XDECREF(p);
+#if defined(MAC_OS_X_VERSION_10_5)
+    p = PyObjC_IdToPython(@protocol(NSCoding)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSCopying)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSDecimalNumberBehaviors)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSFastEnumeration)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSLocking)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSMutableCopying)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSObject)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSURLAuthenticationChallengeSender)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSURLHandleClient)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSURLProtocolClient)); Py_XDECREF(p);
+#endif /* defined(MAC_OS_X_VERSION_10_5) */
+#if defined(MAC_OS_X_VERSION_10_7)
+    p = PyObjC_IdToPython(@protocol(NSFileManagerDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSFilePresenter)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSURLConnectionDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSURLDownloadDelegate)); Py_XDECREF(p);
+#endif /* defined(MAC_OS_X_VERSION_10_7) */
+#if defined(MAC_OS_X_VERSION_10_8)
+    p = PyObjC_IdToPython(@protocol(NSSecureCoding)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSURLConnectionDataDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSURLConnectionDownloadDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSUserNotificationCenterDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSXPCListenerDelegate)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSXPCProxyCreating)); Py_XDECREF(p);
+#endif /* defined(MAC_OS_X_VERSION_10_8) */
+}

File pyobjc-framework-Cocoa/PyObjCTest/test_appkit_protocols.py

+from PyObjCTools.TestSupport import *
+import Cocoa
+
+class TestProtocolsExisting (TestCase):
+    def testProtocols(self):
+        objc.protocolNamed('NSAlertDelegate')
+        objc.protocolNamed('NSAnimatablePropertyContainer')
+        objc.protocolNamed('NSAnimationDelegate')
+        objc.protocolNamed('NSApplicationDelegate')
+        objc.protocolNamed('NSBrowserDelegate')
+        objc.protocolNamed('NSChangeSpelling')
+        objc.protocolNamed('NSCollectionViewDelegate')
+        objc.protocolNamed('NSColorPickingCustom')
+        objc.protocolNamed('NSColorPickingDefault')
+        objc.protocolNamed('NSComboBoxCellDataSource')
+        objc.protocolNamed('NSComboBoxDataSource')
+        objc.protocolNamed('NSComboBoxDelegate')
+        objc.protocolNamed('NSControlTextEditingDelegate')
+        objc.protocolNamed('NSDatePickerCellDelegate')
+        objc.protocolNamed('NSDockTilePlugIn')
+        objc.protocolNamed('NSDraggingInfo')
+        objc.protocolNamed('NSDrawerDelegate')
+        objc.protocolNamed('NSGlyphStorage')
+        objc.protocolNamed('NSIgnoreMisspelledWords')
+        objc.protocolNamed('NSImageDelegate')
+        objc.protocolNamed('NSInputServerMouseTracker')
+        objc.protocolNamed('NSInputServiceProvider')
+        objc.protocolNamed('NSLayoutManagerDelegate')
+        objc.protocolNamed('NSMatrixDelegate')
+        objc.protocolNamed('NSMenuDelegate')
+        objc.protocolNamed('NSOpenSavePanelDelegate')
+        objc.protocolNamed('NSOutlineViewDataSource')
+        objc.protocolNamed('NSOutlineViewDelegate')
+        objc.protocolNamed('NSPasteboardItemDataProvider')
+        objc.protocolNamed('NSPasteboardReading')
+        objc.protocolNamed('NSPasteboardWriting')
+        objc.protocolNamed('NSPathCellDelegate')
+        objc.protocolNamed('NSPathControlDelegate')
+        objc.protocolNamed('NSPrintPanelAccessorizing')
+        objc.protocolNamed('NSRuleEditorDelegate')
+        objc.protocolNamed('NSSoundDelegate')
+        objc.protocolNamed('NSSpeechRecognizerDelegate')
+        objc.protocolNamed('NSSpeechSynthesizerDelegate')
+        objc.protocolNamed('NSSplitViewDelegate')
+        objc.protocolNamed('NSTabViewDelegate')
+        objc.protocolNamed('NSTableViewDataSource')
+        objc.protocolNamed('NSTableViewDelegate')
+        objc.protocolNamed('NSTextAttachmentCell')
+        objc.protocolNamed('NSTextDelegate')
+        objc.protocolNamed('NSTextFieldDelegate')
+        objc.protocolNamed('NSTextInput')
+        objc.protocolNamed('NSTextInputClient')
+        objc.protocolNamed('NSTextStorageDelegate')
+        objc.protocolNamed('NSTextViewDelegate')
+        objc.protocolNamed('NSTokenFieldCellDelegate')
+        objc.protocolNamed('NSTokenFieldDelegate')
+        objc.protocolNamed('NSToolbarDelegate')
+        objc.protocolNamed('NSUserInterfaceItemSearching')
+        objc.protocolNamed('NSUserInterfaceValidations')
+        objc.protocolNamed('NSValidatedUserInterfaceItem')
+        objc.protocolNamed('NSWindowDelegate')
+
+    @min_os_level('10.7')
+    def testProtocols10_7(self):
+        objc.protocolNamed('NSDraggingDestination')
+        objc.protocolNamed('NSDraggingSource')
+        objc.protocolNamed('NSPopoverDelegate')
+        objc.protocolNamed('NSTextFinderBarContainer')
+        objc.protocolNamed('NSTextFinderClient')
+        objc.protocolNamed('NSTextLayoutOrientationProvider')
+        objc.protocolNamed('NSUserInterfaceItemIdentification')
+        objc.protocolNamed('NSWindowRestoration')
+
+    @min_os_level('10.8')
+    def testProtocols10_8(self):
+        objc.protocolNamed('NSPageControllerDelegate')
+        objc.protocolNamed('NSSharingServiceDelegate')
+        objc.protocolNamed('NSSharingServicePickerDelegate')
+
+if __name__ == "__main__":
+    main()

File pyobjc-framework-CoreLocation/Lib/CoreLocation/__init__.py

 import Foundation
 
 from CoreLocation import _metadata
+from CoreLocation._CoreLocation import *
 import os
 
 if int(os.uname()[2].split('.')[0]) < 12:

File pyobjc-framework-CoreLocation/Modules/_CoreLocation.m

+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include "pyobjc-api.h"
+
+#import <CoreLocation/CoreLocation.h>
+
+/* We include the source code here instead of 
+ * using the linker due to limitations in pyobjc-api.h
+ */
+#include "_CoreLocation_protocols.m"
+
+
+static PyMethodDef mod_methods[] = {
+	{ 0, 0, 0, 0 } /* sentinel */
+};
+
+
+/* Python glue */
+PyObjC_MODULE_INIT(_CoreLocation)
+{
+	PyObject* m;
+	m = PyObjC_MODULE_CREATE(_CoreLocation)
+	if (!m) { 
+		PyObjC_INITERROR();
+	}
+
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
+
+	PyObjC_INITDONE();
+}

File pyobjc-framework-CoreLocation/Modules/_CoreLocation_protocols.m

+/* 
+ * This file is generated by objective.metadata
+ *
+ * Last update: Tue Jan 15 18:57:31 2013
+ */
+
+static void __attribute__((__used__)) use_protocols(void)
+{
+    PyObject* p;
+    p = PyObjC_IdToPython(@protocol(CLLocationManagerDelegate)); Py_XDECREF(p);
+}

File pyobjc-framework-CoreLocation/setup.py

 for general tips and tricks regarding the translation between Python
 and (Objective-)C frameworks
 '''
-from pyobjc_setup import setup
+from pyobjc_setup import setup, Extension
+import os
 
 setup(
     min_os_level='10.6',
         'pyobjc-core>=2.5.1b1',
         'pyobjc-framework-Cocoa>=2.5.1b1',
     ],
+    ext_modules = [
+        Extension("CoreLocation._CoreLocation",
+                [ "Modules/_CoreLocation.m" ],
+                extra_link_args=["-framework", "CoreLocation"],
+                depends=[
+                    os.path.join('Modules', fn)
+                        for fn in os.listdir('Modules')
+                        if fn.startswith('_CoreLocation')
+                ]
+        ),
+    ]
 )

File pyobjc-framework-InputMethodKit/Lib/InputMethodKit/__init__.py

 import Foundation
 
 from InputMethodKit import _metadata
+from InputMethodKit._InputMethodKit import *
 
 sys.modules['InputMethodKit'] = mod = objc.ObjCLazyModule('InputMethodKit',
     "com.apple.InputMethodKit",

File pyobjc-framework-InputMethodKit/Modules/_InputMethodKit.m

+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include "pyobjc-api.h"
+
+#import <InputMethodKit/InputMethodKit.h>
+
+/* We include the source code here instead of 
+ * using the linker due to limitations in pyobjc-api.h
+ */
+#include "_InputMethodKit_protocols.m"
+
+
+static PyMethodDef mod_methods[] = {
+	{ 0, 0, 0, 0 } /* sentinel */
+};
+
+
+/* Python glue */
+PyObjC_MODULE_INIT(_InputMethodKit)
+{
+	PyObject* m;
+	m = PyObjC_MODULE_CREATE(_InputMethodKit)
+	if (!m) { 
+		PyObjC_INITERROR();
+	}
+
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
+
+	PyObjC_INITDONE();
+}

File pyobjc-framework-InputMethodKit/Modules/_InputMethodKit_protocols.m

+/* 
+ * This file is generated by objective.metadata
+ *
+ * Last update: Tue Jan 15 18:32:26 2013
+ */
+
+static void __attribute__((__used__)) use_protocols(void)
+{
+    PyObject* p;
+    p = PyObjC_IdToPython(@protocol(IMKMouseHandling)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(IMKStateSetting)); Py_XDECREF(p);
+}

File pyobjc-framework-InputMethodKit/PyObjCTest/test_inputmethodkit.py

         self.assert_( hasattr(InputMethodKit.protocols, 'IMKServerInput') )
         self.assert_( isinstance(InputMethodKit.protocols.IMKServerInput, objc.informal_protocol) )
 
+    def testProtocols2(self):
+        objc.protocolNamed('IMKMouseHandling')
+        objc.protocolNamed('IMKStateSetting')
+
 
 
 if __name__ == "__main__":

File pyobjc-framework-InputMethodKit/setup.py

 for general tips and tricks regarding the translation between Python
 and (Objective-)C frameworks
 '''
-from pyobjc_setup import setup
+from pyobjc_setup import setup, Extension
+import os
 
 setup(
     min_os_level='10.5',
         'pyobjc-core>=2.5.1b1',
         'pyobjc-framework-Cocoa>=2.5.1b1',
     ],
+    ext_modules = [
+        Extension("InputMethodKit._InputMethodKit",
+            [ "Modules/_InputMethodKit.m" ],
+            extra_link_args=["-framework", "InputMethodKit"],
+            depends=[
+                os.path.join('Modules', fn)
+                    for fn in os.listdir('Modules')
+                    if fn.startswith('_InputMethodKit')
+            ]
+       ),
+   ]
 )

File pyobjc-framework-OpenDirectory/PyObjCTest/test_opendirectory.py

 from PyObjCTools.TestSupport import *
-
+import objc
 import OpenDirectory
 
 try:
     def testConstants(self):
         self.assertIsInstance(OpenDirectory.ODFrameworkErrorDomain, unicode)
 
+    def testProtocols(self):
+        objc.protocolNamed('ODQueryDelegate')
+
 
 if __name__ == "__main__":
     main()

File pyobjc-framework-ScriptingBridge/Lib/ScriptingBridge/__init__.py

 import Foundation
 
 from ScriptingBridge import _metadata
+from ScriptingBridge._ScriptingBridge import *
 
 sys.modules['ScriptingBridge'] = mod = objc.ObjCLazyModule('ScriptingBridge',
     "com.apple.ScriptingBridge",

File pyobjc-framework-ScriptingBridge/Modules/_ScriptingBridge.m

+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include "pyobjc-api.h"
+
+#import <ScriptingBridge/ScriptingBridge.h>
+
+/* We include the source code here instead of 
+ * using the linker due to limitations in pyobjc-api.h
+ */
+#include "_ScriptingBridge_protocols.m"
+
+
+static PyMethodDef mod_methods[] = {
+	{ 0, 0, 0, 0 } /* sentinel */
+};
+
+
+/* Python glue */
+PyObjC_MODULE_INIT(_ScriptingBridge)
+{
+	PyObject* m;
+	m = PyObjC_MODULE_CREATE(_ScriptingBridge)
+	if (!m) { 
+		PyObjC_INITERROR();
+	}
+
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
+
+	PyObjC_INITDONE();
+}

File pyobjc-framework-ScriptingBridge/Modules/_ScriptingBridge_protocols.m

+/* 
+ * This file is generated by objective.metadata
+ *
+ * Last update: Tue Jan 15 18:40:50 2013
+ */
+
+static void __attribute__((__used__)) use_protocols(void)
+{
+    PyObject* p;
+    p = PyObjC_IdToPython(@protocol(SBApplicationDelegate)); Py_XDECREF(p);
+}

File pyobjc-framework-ScriptingBridge/PyObjCTest/test_scriptingbridge.py

-
 from PyObjCTools.TestSupport import *
+import objc
 from ScriptingBridge import *
 
 class TestSBApplicationHelper (NSObject):
     def testMethods(self):
         self.assertResultIsBOOL(SBApplication.isRunning)
 
+    def testProtocols(self):
+        objc.protocolNamed('SBApplicationDelegate')
+
 
 if __name__ == "__main__":
     main()

File pyobjc-framework-ScriptingBridge/setup.py

 for general tips and tricks regarding the translation between Python
 and (Objective-)C frameworks
 '''
-from pyobjc_setup import *
+from pyobjc_setup import setup, Extension
+import os
 
 setup(
     min_os_level='10.5',
         'pyobjc-core>=2.5.1b1',
         'pyobjc-framework-Cocoa>=2.5.1b1',
     ],
+    ext_modules = [
+        Extension("ScriptingBridge._ScriptingBridge",
+            [ "Modules/_ScriptingBridge.m" ],
+            extra_link_args=["-framework", "ScriptingBridge"],
+            depends=[
+                os.path.join('Modules', fn)
+                    for fn in os.listdir('Modules')
+                    if fn.startswith('_ScriptingBridge')
+            ]
+        ),
+    ]
 )

File pyobjc-framework-SyncServices/Lib/SyncServices/__init__.py

 import CoreData
 
 from SyncServices import _metadata
+from SyncServices._SyncServices import *
 
 sys.modules['SyncServices'] = mod = objc.ObjCLazyModule('SyncServices',
     "com.apple.syncservices",

File pyobjc-framework-SyncServices/Modules/_SyncServices.m

+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include "pyobjc-api.h"
+
+#import <SyncServices/SyncServices.h>
+
+/* We include the source code here instead of 
+ * using the linker due to limitations in pyobjc-api.h
+ */
+#include "_SyncServices_protocols.m"
+
+
+static PyMethodDef mod_methods[] = {
+	{ 0, 0, 0, 0 } /* sentinel */
+};
+
+
+/* Python glue */
+PyObjC_MODULE_INIT(_SyncServices)
+{
+	PyObject* m;
+	m = PyObjC_MODULE_CREATE(_SyncServices)
+	if (!m) { 
+		PyObjC_INITERROR();
+	}
+
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
+
+	PyObjC_INITDONE();
+}

File pyobjc-framework-SyncServices/Modules/_SyncServices_protocols.m

+/* 
+ * This file is generated by objective.metadata
+ *
+ * Last update: Tue Jan 15 18:45:59 2013
+ */
+
+static void __attribute__((__used__)) use_protocols(void)
+{
+    PyObject* p;
+    p = PyObjC_IdToPython(@protocol(ISyncFiltering)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(ISyncSessionDriverDataSource)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(NSPersistentStoreCoordinatorSyncing)); Py_XDECREF(p);
+}

File pyobjc-framework-SyncServices/PyObjCTest/test_syncservices.py

         self.assertHasAttr(SyncServices, 'ISyncClient')
         self.assertIsInstance(SyncServices.ISyncClient, objc.objc_class)
 
+    def testProtocols(self):
+        objc.protocolNamed('ISyncFiltering')
+        objc.protocolNamed('ISyncSessionDriverDataSource')
+        objc.protocolNamed('NSPersistentStoreCoordinatorSyncing')
+
 
 if __name__ == "__main__":
     main()

File pyobjc-framework-SyncServices/setup.py

 for general tips and tricks regarding the translation between Python
 and (Objective-)C frameworks
 '''
-from pyobjc_setup import setup
+from pyobjc_setup import setup, Extension
+import os
 
 setup(
     name='pyobjc-framework-SyncServices',
         'pyobjc-framework-Cocoa>=2.5.1b1',
         'pyobjc-framework-CoreData>=2.5.1b1',
     ],
+    ext_modules = [
+        Extension("SyncServices._SyncServices",
+            [ "Modules/_SyncServices.m" ],
+            extra_link_args=["-framework", "SyncServices"],
+            depends=[
+                os.path.join('Modules', fn)
+                    for fn in os.listdir('Modules')
+                    if fn.startswith('_SyncServices')
+            ]
+        ),
+    ]
 )

File pyobjc-framework-WebKit/Lib/WebKit/__init__.py

 import Foundation
 
 from WebKit import _metadata
+from WebKit._WebKit import *
 
 sys.modules['WebKit'] = mod = objc.ObjCLazyModule(
     "WebKit",

File pyobjc-framework-WebKit/Modules/_WebKit.m

+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include "pyobjc-api.h"
+
+#import <WebKit/WebKit.h>
+
+/* We include the source code here instead of 
+ * using the linker due to limitations in pyobjc-api.h
+ */
+#include "_WebKit_protocols.m"
+
+
+static PyMethodDef mod_methods[] = {
+	{ 0, 0, 0, 0 } /* sentinel */
+};
+
+
+/* Python glue */
+PyObjC_MODULE_INIT(_WebKit)
+{
+	PyObject* m;
+	m = PyObjC_MODULE_CREATE(_WebKit)
+	if (!m) { 
+		PyObjC_INITERROR();
+	}
+
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
+
+	PyObjC_INITDONE();
+}

File pyobjc-framework-WebKit/Modules/_WebKit_protocols.m

+/* 
+ * This file is generated by objective.metadata
+ *
+ * Last update: Tue Jan 15 18:52:03 2013
+ */
+
+static void __attribute__((__used__)) use_protocols(void)
+{
+    PyObject* p;
+#if defined(MAC_OS_X_VERSION_10_5)
+    p = PyObjC_IdToPython(@protocol(DOMEventListener)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(DOMEventTarget)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(DOMNodeFilter)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(DOMXPathNSResolver)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(WebDocumentRepresentation)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(WebDocumentSearching)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(WebDocumentText)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(WebDocumentView)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(WebOpenPanelResultListener)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(WebPlugInViewFactory)); Py_XDECREF(p);
+    p = PyObjC_IdToPython(@protocol(WebPolicyDecisionListener)); Py_XDECREF(p);
+#endif /* defined(MAC_OS_X_VERSION_10_5) */
+}

File pyobjc-framework-WebKit/PyObjCTest/test_webkit.py

         self.assert_( hasattr(WebKit, 'WebConvertNSImageToCGImageRef') )
         self.assert_(isinstance(WebKit.WebConvertNSImageToCGImageRef, objc.function) )
 
+    def testProtocols(self):
+        objc.protocolNamed('DOMEventListener')
+        objc.protocolNamed('DOMEventTarget')
+        objc.protocolNamed('DOMNodeFilter')
+        objc.protocolNamed('DOMXPathNSResolver')
+        objc.protocolNamed('WebDocumentRepresentation')
+        objc.protocolNamed('WebDocumentSearching')
+        objc.protocolNamed('WebDocumentText')
+        objc.protocolNamed('WebDocumentView')
+        objc.protocolNamed('WebOpenPanelResultListener')
+        objc.protocolNamed('WebPlugInViewFactory')
+        objc.protocolNamed('WebPolicyDecisionListener')
 
 
 if __name__ == "__main__":

File pyobjc-framework-WebKit/setup.py

 for general tips and tricks regarding the translation between Python
 and (Objective-)C frameworks
 '''
-from pyobjc_setup import setup
+from pyobjc_setup import setup, Extension
+import os
 
 setup(
     name='pyobjc-framework-WebKit',
         'pyobjc-core>=2.5.1b1',
         'pyobjc-framework-Cocoa>=2.5.1b1',
     ],
+    ext_modules = [
+        Extension("WebKit._WebKit",
+            [ "Modules/_WebKit.m" ],
+            extra_link_args=["-framework", "WebKit"],
+            depends=[
+                os.path.join('Modules', fn)
+                    for fn in os.listdir('Modules')
+                    if fn.startswith('_WebKit')
+            ]
+        ),
+    ]
 )