summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-08-14 20:04:48 (GMT)
committerGuido van Rossum <guido@python.org>2001-08-14 20:04:48 (GMT)
commit4dd64ab5eae7de3074b9cb94e22e80f43653e232 (patch)
treed6c1e05364313bfdad9b88b4e7ea9aea71950c57
parent481081e3693e1a7169cf8127725f7dc0e1750f29 (diff)
downloadcpython-4dd64ab5eae7de3074b9cb94e22e80f43653e232.zip
cpython-4dd64ab5eae7de3074b9cb94e22e80f43653e232.tar.gz
cpython-4dd64ab5eae7de3074b9cb94e22e80f43653e232.tar.bz2
Non-function fields, like tp_dictoffset and tp_weaklistoffset, should
be inherited in inherit_special(), otherwise dynamic types don't inherit these. Also added some XXX comments about open ends.
-rw-r--r--Objects/typeobject.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index e8b634e..8f48b39 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -852,6 +852,7 @@ object_dealloc(PyObject *self)
}
#if 0
+/* XXX These should be made smarter before they can be used */
static PyObject *
object_repr(PyObject *self)
{
@@ -1036,6 +1037,20 @@ inherit_special(PyTypeObject *type, PyTypeObject *base)
}
}
PyType_SET_BASICSIZE(type, newsize);
+
+ /* Copy other non-function slots */
+
+#undef COPYVAL
+#define COPYVAL(SLOT) \
+ if (type->SLOT == 0) type->SLOT = base->SLOT
+
+ COPYVAL(tp_itemsize);
+ if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_WEAKREFS) {
+ COPYVAL(tp_weaklistoffset);
+ }
+ if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) {
+ COPYVAL(tp_dictoffset);
+ }
}
static void
@@ -1136,7 +1151,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
basebase = base->tp_base;
- COPYSLOT(tp_itemsize);
COPYSLOT(tp_dealloc);
COPYSLOT(tp_print);
if (type->tp_getattr == NULL && type->tp_getattro == NULL) {
@@ -1153,7 +1167,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
COPYSLOT(tp_call);
COPYSLOT(tp_str);
COPYSLOT(tp_as_buffer);
- COPYSLOT(tp_flags);
if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_RICHCOMPARE) {
if (type->tp_compare == NULL && type->tp_richcompare == NULL) {
type->tp_compare = base->tp_compare;
@@ -1163,9 +1176,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
else {
COPYSLOT(tp_compare);
}
- if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_WEAKREFS) {
- COPYSLOT(tp_weaklistoffset);
- }
if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_ITER) {
COPYSLOT(tp_iter);
COPYSLOT(tp_iternext);
@@ -2244,6 +2254,8 @@ SLOT0(slot_nb_absolute, "__abs__")
static int
slot_nb_nonzero(PyObject *self)
{
+ /* XXX This should cope with a missing __nonzero__ */
+ /* XXX Should it also look for __len__? */
PyObject *res = PyObject_CallMethod(self, "__nonzero__", "");
if (res == NULL)
@@ -2283,6 +2295,7 @@ SLOT1(slot_nb_inplace_true_divide, "__itruediv__", PyObject *, "O")
static int
slot_tp_compare(PyObject *self, PyObject *other)
{
+ /* XXX Should this cope with a missing __cmp__? */
PyObject *res = PyObject_CallMethod(self, "__cmp__", "O", other);
long r;
@@ -2293,11 +2306,13 @@ slot_tp_compare(PyObject *self, PyObject *other)
return (int)r;
}
+/* XXX This should cope with a missing __repr__, and also look for __str__ */
SLOT0(slot_tp_repr, "__repr__")
static long
slot_tp_hash(PyObject *self)
{
+ /* XXX This should cope with a missing __hash__ */
PyObject *res = PyObject_CallMethod(self, "__hash__", "");
long h;
@@ -2322,6 +2337,7 @@ slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds)
return res;
}
+/* XXX This should cope with a missing __str__, and also look for __repr__ */
SLOT0(slot_tp_str, "__str__")
static PyObject *
@@ -2371,6 +2387,7 @@ static char *name_op[] = {
static PyObject *
slot_tp_richcompare(PyObject *self, PyObject *other, int op)
{
+ /* XXX How should this cope with missing __xx__? */
PyObject *meth = PyObject_GetAttrString(self, name_op[op]);
PyObject *res;