Ronald Oussoren avatar Ronald Oussoren committed 3684cf5

Updates for protocol handling broke python3 support

Comments (0)

Files changed (4)

pyobjc-core/Modules/objc/formal-protocol.m

 	}
 
 	for (i = 0; i < method_count; i++) {
+		char buf[512];
+		PyObjCRT_SimplifySignature(methods[i].types, buf, sizeof(buf));
 		PyObject* item = Py_BuildValue(
 #if PY_MAJOR_VERSION == 2
 			"{sssssO}",
 			"{sysysO}",
 #endif
 			"selector", sel_getName(methods[i].name),
-			"typestr",  methods[i].types,
+			"typestr",  buf,
 			"required", isRequired?Py_True:Py_False);
 		if (item == NULL) {
 			free(methods);
 		Py_DECREF(bytes);
 
 #endif
-	} else if (PyString_Check(sel)) {
-		char* s = PyString_AsString(sel);
+	} else if (PyBytes_Check(sel)) {
+		char* s = PyBytes_AsString(sel);
 		if (*s == '\0') {
 			PyErr_SetString(PyExc_ValueError, 
 					"empty selector name");
 		return Py_None;
 
 	} else {
-		return Py_BuildValue("(ss)",
-				sel_getName(descr.name),
-				descr.types);
+		char buf[512];
+		PyObjCRT_SimplifySignature(descr.types, buf, sizeof(buf));
+		return Py_BuildValue(
+#if PY_MAJOR_VERSION == 2
+			"(ss)",
+#else
+			"(yy)",
+#endif
+			sel_getName(descr.name),
+			buf);
 	}
 }
 
 		Py_DECREF(bytes);
 
 #endif
-	} else if (PyString_Check(sel)) {
-		char* s = PyString_AsString(sel);
+	} else if (PyBytes_Check(sel)) {
+		char* s = PyBytes_AsString(sel);
 		if (*s == '\0') {
 			PyErr_SetString(PyExc_ValueError, 
 					"empty selector name");
 		Py_INCREF(Py_None);
 		return Py_None;
 	} else {
-		return Py_BuildValue("(ss)",
+		char buf[256];
+		PyObjCRT_SimplifySignature(descr.types, buf, sizeof(buf));
+		return Py_BuildValue(
+#if PY_MAJOR_VERSION == 2
+			"(ss)",
+#else
+			"(yy)",
+#endif
 			sel_getName(descr.name),
-			descr.types);
+			buf);
 	}
 }
 

pyobjc-core/PyObjCTest/test3_protocol.py

                 ])
 
         def testMethodInfo(self):
+            self.assertEqual(MyProtocol3.instanceMethods(), [
+                {'typestr': b'I@:', 'required': True, 'selector': b'protoMethod'},
+                {'typestr': b'v@:ii', 'required': True, 'selector': b'anotherProto:with:'},
+            ])
+            self.assertEqual(MyProtocol3.classMethods(), [
+            ])
             self.assertEqual(
-                    MyProtocol3.descriptionForInstanceMethod_("protoMethod"),
-                        ("protoMethod", "I@:"))
+                    MyProtocol3.descriptionForInstanceMethod_(b"protoMethod"),
+                        (b"protoMethod", b"I@:"))
 
             self.assertEqual(
-                    MyProtocol3.descriptionForInstanceMethod_("nosuchmethod"),
+                    MyProtocol3.descriptionForInstanceMethod_(b"nosuchmethod"),
                         None)
 
+            self.assertEqual(MyClassProtocol3.classMethods(), [
+                {'required': True, 'selector': b'aClassOne:', 'typestr': b'@@:i'}
+            ])
+            self.assertEqual(MyProtocol3.classMethods(), [
+            ])
             self.assertEqual(
-                    MyClassProtocol3.descriptionForClassMethod_("aClassOne:"),
-                        ("aClassOne:", "@@:i"))
+                    MyClassProtocol3.descriptionForClassMethod_(b"aClassOne:"),
+                        (b"aClassOne:", b"@@:i"))
 
             self.assertEqual(
-                    MyClassProtocol3.descriptionForClassMethod_("nosuchmethod"),
+                    MyClassProtocol3.descriptionForClassMethod_(b"nosuchmethod"),
                         None)
 
 

pyobjc-core/PyObjCTest/test_protocol.py

                 actual = OC_TestProtocol.instanceMethods()
                 actual.sort(key=lambda item: item['selector'])
                 expected = [
-                    {'required': True, 'selector': b'method1', 'typestr': b'i16@0:8'},
-                    {'required': True, 'selector': b'method2:', 'typestr': b'v20@0:8i16'}
+                    {'required': True, 'selector': b'method1', 'typestr': b'i@:'},
+                    {'required': True, 'selector': b'method2:', 'typestr': b'v@:i'}
                 ]
                 self.assertEqual(actual, expected)
                 self.assertEqual(OC_TestProtocol.classMethods(), [])
 
-                self.assertEqual(OC_TestProtocol.descriptionForInstanceMethod_(b"method1"), (b"method1", b"i16@0:8"))
-                self.assertEqual(OC_TestProtocol.descriptionForInstanceMethod_(b"method2:"), (b"method2:", b"v20@0:8i16"))
+                self.assertEqual(OC_TestProtocol.descriptionForInstanceMethod_(b"method1"), (b"method1", b"i@:"))
+                self.assertEqual(OC_TestProtocol.descriptionForInstanceMethod_(b"method2:"), (b"method2:", b"v@:i"))
             
             def testImplementFormalProtocol(self):
 

pyobjc-framework-Quartz/PyObjCTest/test_cgremoteoperation.py

         v = CGAssociateMouseAndMouseCursorPosition(0)
         self.assertEqual(v, 0)
 
+        # For some reason there are 2 NSMachPort classes on OSX 10.8
+        classes = tuple([cls for cls in objc.getClassList() if cls.__name__ == 'NSMachPort'])
+
         v = CGWindowServerCFMachPort()
-        self.assertIsInstance(v, CFMachPortRef)
+        self.assertIsInstance(v, classes)
 
         self.assertTrue(CGSetLocalEventsFilterDuringSupressionState is CGSetLocalEventsFilterDuringSuppressionState)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.