Commits

Ronald Oussoren committed 475c6c7

Multiple-inheritance didn't work if the base-class is an old-style class.
(bug #785980)

The original poster seems to have been lucky, I got segmentation faults on
the new testcase.

  • Participants
  • Parent commits 23adfd2

Comments (0)

Files changed (2)

File pyobjc/Lib/objc/test/test_subclass.py

         self.assert_(isinstance(c, MyCopyClass))
         self.assertEquals(c.foobar, 2)
 
+
+    def testMultipleInheritance1(self):
+        # New-style class mixin
+        class MixinClass1 (object):
+            def mixinMethod(self):
+                return "foo"
+
+        class MITestClass1 (objc.runtime.NSObject, MixinClass1):
+            def init(self):
+                return NSObject.init(self)
+
+        self.assert_(hasattr(MITestClass1, 'mixinMethod'))
+
+        o = MITestClass1.alloc().init()
+        self.assertEquals(o.mixinMethod(), "foo")
+
+    def testMultipleInheritance2(self):
+        # old-style class mixin
+        class MixinClass2:
+            def mixinMethod(self):
+                return "foo"
+
+        class MITestClass2 (objc.runtime.NSObject, MixinClass2):
+            def init(self):
+                return NSObject.init(self)
+
+        self.assert_(hasattr(MITestClass2, 'mixinMethod'))
+
+        o = MITestClass2.alloc().init()
+        self.assertEquals(o.mixinMethod(), "foo")
+
+
+
 if __name__ == '__main__':
     unittest.main()

File pyobjc/Modules/objc/objc-object.m

 		base = PyTuple_GET_ITEM(mro, i);
 		assert(PyType_Check(base));
 
-		if (PyObjCClass_Check(base)) {
-			PyObjCClass_CheckMethodList(base, 0);
+		if (PyClass_Check(base)) {
+			dict = ((PyClassObject*)base)->cl_dict;
+		} else {
+			if (PyObjCClass_Check(base)) {
+				PyObjCClass_CheckMethodList(base, 0);
+			}
+
+			dict = ((PyTypeObject *)base)->tp_dict;
 		}
-
-		dict = ((PyTypeObject *)base)->tp_dict;
 		assert(dict && PyDict_Check(dict));
 		descr = PyDict_GetItem(dict, name);
 		if (descr != NULL) {