[PyObjC-svn] r2416 - in trunk/pyobjc/pyobjc-core: Modules/objc PyObjCTest

[email protected] Tue, 23 Mar 2010 17:26:10 -0500
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Tue Mar 23 17:26:10 2010
New Revision: 2416

Log:
Further tweaks, all tests for hidden selectors
now pass.


Modified:
   trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m
   trunk/pyobjc/pyobjc-core/Modules/objc/method-accessor.m
   trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.h
   trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.m
   trunk/pyobjc/pyobjc-core/Modules/objc/selector.m
   trunk/pyobjc/pyobjc-core/PyObjCTest/test_hidden_selector.py

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m	Tue Mar 23 17:26:10 2010
@@ -1189,7 +1189,7 @@
 		value = PySequence_Fast_GET_ITEM(instance_methods, i);
 
 		if (PyBytes_Check(value)) {
-			int r = PySet_Add(hiddenSelectors, value);
+			int r = PyDict_SetItem(hiddenSelectors, value, Py_None);
 			if (r == -1) {
 				goto error_cleanup;
 			}
@@ -1224,7 +1224,8 @@
 				if (v == NULL) {
 					goto error_cleanup;
 				}
-				int r = PySet_Add(hiddenSelectors, v);
+				int r = PyDict_SetItem(hiddenSelectors, v, 
+						(PyObject*)PyObjCSelector_GetMetadata(value));
 				Py_DECREF(v);
 				if (r == -1) {
 					goto error_cleanup;
@@ -1236,7 +1237,7 @@
 		value = PySequence_Fast_GET_ITEM(class_methods, i);
 
 		if (PyBytes_Check(value)) {
-			int r = PySet_Add(hiddenClassSelectors, value);
+			int r = PyDict_SetItem(hiddenClassSelectors, value, Py_None);
 			if (r == -1) {
 				goto error_cleanup;
 			}
@@ -1272,7 +1273,8 @@
 				if (v == NULL) {
 					goto error_cleanup;
 				}
-				int r = PySet_Add(hiddenClassSelectors, v);
+				int r = PyDict_SetItem(hiddenClassSelectors, v, 
+						(PyObject*)PyObjCSelector_GetMetadata(value));
 				Py_DECREF(v);
 				if (r == -1) {
 					goto error_cleanup;

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/method-accessor.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/method-accessor.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/method-accessor.m	Tue Mar 23 17:26:10 2010
@@ -14,7 +14,8 @@
 	NSMethodSignature* methsig;
 	char  buf[1024];
 	volatile int   unbound_instance_method = 0;
-	char* flattened;
+	char* flattened = NULL;
+	PyObject* class_object;
 
 	if (name[0] == '_' && name[1] == '_') {
 		/*
@@ -28,11 +29,14 @@
 
 	if (PyObjCClass_Check(self)) {
 		objc_object = (id)PyObjCClass_GetClass(self);
+		class_object = self;
 
 		if (!class_method) {
 			unbound_instance_method = 1;
 		}
 	} else if (PyObjCObject_Check(self)) {
+		class_object = (PyObject*)Py_TYPE(self);
+
 		objc_object = PyObjCObject_GetObject(self);
 		if (objc_object == NULL) {
 			PyErr_SetString(PyExc_AttributeError, 
@@ -94,8 +98,14 @@
 		objc_object = (id)object_getClass(objc_object);
 	}
 
-	flattened = PyObjC_NSMethodSignatureToTypeString(
+	PyObject* meta = PyObjCClass_HiddenSelector(class_object, sel, class_method);
+	if (meta) {
+		flattened = (char*)((PyObjCMethodSignature*)meta)->signature;
+	} 
+	if (flattened == NULL) {
+		flattened = PyObjC_NSMethodSignatureToTypeString(
 			methsig, buf, sizeof(buf));
+	}
 	if (flattened == NULL) {
 		return NULL;
 	}

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.h
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.h	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.h	Tue Mar 23 17:26:10 2010
@@ -111,8 +111,8 @@
 void PyObjCClass_SetDelMethod(PyObject* cls, PyObject* newval);
 int  PyObjCClass_HasPythonImplementation(PyObject* cls);
 PyObject* PyObjCClass_ClassForMetaClass(PyObject* meta);
-BOOL PyObjCClass_HiddenSelector(PyObject* tp, SEL sel, BOOL classMethod);
-int PyObjCClass_SetHidden(PyObject* tp, SEL sel, BOOL classMethod);
+PyObject* PyObjCClass_HiddenSelector(PyObject* tp, SEL sel, BOOL classMethod); /* returns borrowed */
+int PyObjCClass_SetHidden(PyObject* tp, SEL sel, BOOL classMethod, PyObject* metadata);
 int PyObjCClass_AddMethods(PyObject* cls, PyObject** methods, Py_ssize_t count);
 
 PyObject* PyObjCClass_ListProperties(PyObject* cls);

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc-class.m	Tue Mar 23 17:26:10 2010
@@ -7,7 +7,7 @@
 
 #include <stddef.h>
 
-int PyObjCClass_SetHidden(PyObject* tp, SEL sel, BOOL classMethod)
+int PyObjCClass_SetHidden(PyObject* tp, SEL sel, BOOL classMethod, PyObject* metadata)
 {
 	PyObject* hidden;
 	if (classMethod) {
@@ -30,13 +30,14 @@
 		}
 	}
 	PyObject* v = PyBytes_InternFromString(sel_getName(sel));
-	int r = PySet_Add(hidden, v);
+	int r = PyDict_SetItem(hidden, v, metadata);
 	Py_DECREF(v);
 	return r;
 }
 
 
-BOOL PyObjCClass_HiddenSelector(PyObject* tp, SEL sel, BOOL classMethod)
+PyObject*
+PyObjCClass_HiddenSelector(PyObject* tp, SEL sel, BOOL classMethod)
 {
 	PyObject* mro = ((PyTypeObject*)tp)->tp_mro;
 	int i, n;
@@ -60,19 +61,19 @@
 				if (v == NULL) {
 					PyErr_Clear();
 				} else {
-					int r = PySet_Contains(hidden, v);
+					PyObject* r = PyDict_GetItem(hidden, v);
 					Py_DECREF(v);
-					if (r == -1) {
+					if (r == NULL) {
 						PyErr_Clear();
-					} else if (r == 1) {
-						return YES;
+					} else {
+						return r;
 					}
 				}
 			}
 		}
 	}
 
-	return NO;
+	return NULL;
 }
 
 /*
@@ -460,13 +461,13 @@
 		return NULL;
 	}
 
-	hiddenSelectors = PySet_New(NULL);
+	hiddenSelectors = PyDict_New();
 	if (hiddenSelectors == NULL) {
 		Py_DECREF(protectedMethods);
 		return NULL;
 	}
 
-	hiddenClassSelectors = PySet_New(NULL);
+	hiddenClassSelectors = PyDict_New();
 	if (hiddenClassSelectors == NULL) {
 		Py_DECREF(protectedMethods);
 		Py_DECREF(hiddenSelectors);
@@ -2001,6 +2002,7 @@
 	}
 
 	PyObjCClass_CheckMethodList(cls, 1);
+
 	
 	info = (PyObjCClassObject*)cls;
 	if (info->sel_to_py == NULL) {
@@ -2010,6 +2012,14 @@
 		}
 	}
 
+	if (PyObjCClass_HiddenSelector(cls, selector, class_method)) {
+		PyErr_Format(PyExc_AttributeError,
+			"No selector %s", sel_getName(selector));
+		PyDict_SetItemString(info->sel_to_py, 
+				(char*)sel_getName(selector), Py_None);
+		return NULL;
+	}
+
 	/* First check the cache */
 
 	result = PyDict_GetItemString(info->sel_to_py, 
@@ -2449,7 +2459,8 @@
 		}
 #endif
 		if (PyObjCSelector_IsHidden(aMethod)) {
-			r = PyObjCClass_SetHidden(classObject, objcMethod->name, PyObjCSelector_IsClassMethod(aMethod));
+			r = PyObjCClass_SetHidden(classObject, objcMethod->name, PyObjCSelector_IsClassMethod(aMethod),
+					(PyObject*)PyObjCSelector_GetMetadata(aMethod));
 			if (r == -1) {
 				goto cleanup_and_return_error;
 			}

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/selector.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/selector.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/selector.m	Tue Mar 23 17:26:10 2010
@@ -2061,7 +2061,12 @@
 
 		if (super_sel == NULL) {
 			/* FIXME: This isn't optimal when hiding methods with non-standard types */
-			typestr = method_getTypeEncoding(meth);
+			PyObject* met = PyObjCClass_HiddenSelector(template_class, selector, is_class_method);
+			if (met == NULL) {
+				typestr = method_getTypeEncoding(meth);
+			} else {
+				typestr = ((PyObjCMethodSignature*)met)->signature;
+			}
 		} else {
 			typestr = PyObjCSelector_Signature(super_sel);
 		}

Modified: trunk/pyobjc/pyobjc-core/PyObjCTest/test_hidden_selector.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/PyObjCTest/test_hidden_selector.py	(original)
+++ trunk/pyobjc/pyobjc-core/PyObjCTest/test_hidden_selector.py	Tue Mar 23 17:26:10 2010
@@ -195,8 +195,5 @@
         v = OCTestSubHidden.performSelector_(b'bodyclass')
         self.assertEquals(v, "BODYCLASS2")
 
-    def testTypes(self):
-        self.fail("Add tests with objc._C_CHAR_AS_INT, objc._C_UNICHAR and complex APIs")
-
 if __name__ == "__main__":
     main()

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev