Author: mattip <matti.pi...@gmail.com> Branch: cpyext-ext Changeset: r81935:df9304236c27 Date: 2016-01-25 21:58 +0200 http://bitbucket.org/pypy/pypy/changeset/df9304236c27/
Log: add passing test for multiple inheritance diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c --- a/pypy/module/cpyext/test/foo.c +++ b/pypy/module/cpyext/test/foo.c @@ -371,6 +371,12 @@ 0 /*tp_weaklist*/ }; +PyTypeObject UnicodeSubtype3 = { + PyObject_HEAD_INIT(NULL) + 0, + "foo.fuu3", + sizeof(UnicodeSubclassObject) +}; /* A Metatype */ @@ -777,6 +783,14 @@ CustomType.ob_type = &MetaType; if (PyType_Ready(&CustomType) < 0) return; + + UnicodeSubtype3.tp_flags = Py_TPFLAGS_DEFAULT; + UnicodeSubtype3.tp_base = &UnicodeSubtype; + UnicodeSubtype3.tp_bases = Py_BuildValue("(OO)", &UnicodeSubtype, + &CustomType); + if (PyType_Ready(&UnicodeSubtype3) < 0) + return; + m = Py_InitModule("foo", foo_functions); if (m == NULL) return; @@ -789,6 +803,8 @@ return; if (PyDict_SetItemString(d, "UnicodeSubtype2", (PyObject *) &UnicodeSubtype2) < 0) return; + if (PyDict_SetItemString(d, "UnicodeSubtype3", (PyObject *) &UnicodeSubtype3) < 0) + return; if (PyDict_SetItemString(d, "MetaType", (PyObject *) &MetaType) < 0) return; if (PyDict_SetItemString(d, "InitErrType", (PyObject *) &InitErrType) < 0) diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py --- a/pypy/module/cpyext/test/test_typeobject.py +++ b/pypy/module/cpyext/test/test_typeobject.py @@ -150,6 +150,14 @@ assert fuu2(u"abc").baz().escape() raises(TypeError, module.fooType.object_member.__get__, 1) + def test_multiple_inheritance(self): + module = self.import_module(name='foo') + obj = module.UnicodeSubtype(u'xyz') + obj2 = module.UnicodeSubtype2() + obj3 = module.UnicodeSubtype3() + assert obj3.get_val() == 42 + assert len(type(obj3).mro()) == 6 + def test_init(self): module = self.import_module(name="foo") newobj = module.UnicodeSubtype() @@ -416,15 +424,15 @@ module = self.import_extension('foo', [ ("test_tp_getattro", "METH_VARARGS", ''' - PyObject *obj = PyTuple_GET_ITEM(args, 0); - PyIntObject *value = PyTuple_GET_ITEM(args, 1); + PyObject *name, *obj = PyTuple_GET_ITEM(args, 0); + PyIntObject *attr, *value = PyTuple_GET_ITEM(args, 1); if (!obj->ob_type->tp_getattro) { PyErr_SetString(PyExc_ValueError, "missing tp_getattro"); return NULL; } - PyObject *name = PyString_FromString("attr1"); - PyIntObject *attr = obj->ob_type->tp_getattro(obj, name); + name = PyString_FromString("attr1"); + attr = obj->ob_type->tp_getattro(obj, name); if (attr->ob_ival != value->ob_ival) { PyErr_SetString(PyExc_ValueError, @@ -705,13 +713,13 @@ static PyObject * intlike_nb_add(PyObject *self, PyObject *other) { - long val1 = ((IntLikeObject *)(self))->ival; + long val2, val1 = ((IntLikeObject *)(self))->ival; if (PyInt_Check(other)) { long val2 = PyInt_AsLong(other); return PyInt_FromLong(val1+val2); } - long val2 = ((IntLikeObject *)(other))->ival; + val2 = ((IntLikeObject *)(other))->ival; return PyInt_FromLong(val1+val2); } _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit