@@ -852,6 +852,7 @@ object_dealloc(PyObject *self)
852852}
853853
854854#if 0
855+ /* XXX These should be made smarter before they can be used */
855856static PyObject *
856857object_repr (PyObject * self )
857858{
@@ -1036,6 +1037,20 @@ inherit_special(PyTypeObject *type, PyTypeObject *base)
10361037 }
10371038 }
10381039 PyType_SET_BASICSIZE (type , newsize );
1040+
1041+ /* Copy other non-function slots */
1042+
1043+ #undef COPYVAL
1044+ #define COPYVAL (SLOT ) \
1045+ if (type->SLOT == 0) type->SLOT = base->SLOT
1046+
1047+ COPYVAL (tp_itemsize );
1048+ if (type -> tp_flags & base -> tp_flags & Py_TPFLAGS_HAVE_WEAKREFS ) {
1049+ COPYVAL (tp_weaklistoffset );
1050+ }
1051+ if (type -> tp_flags & base -> tp_flags & Py_TPFLAGS_HAVE_CLASS ) {
1052+ COPYVAL (tp_dictoffset );
1053+ }
10391054}
10401055
10411056static void
@@ -1136,7 +1151,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
11361151
11371152 basebase = base -> tp_base ;
11381153
1139- COPYSLOT (tp_itemsize );
11401154 COPYSLOT (tp_dealloc );
11411155 COPYSLOT (tp_print );
11421156 if (type -> tp_getattr == NULL && type -> tp_getattro == NULL ) {
@@ -1153,7 +1167,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
11531167 COPYSLOT (tp_call );
11541168 COPYSLOT (tp_str );
11551169 COPYSLOT (tp_as_buffer );
1156- COPYSLOT (tp_flags );
11571170 if (type -> tp_flags & base -> tp_flags & Py_TPFLAGS_HAVE_RICHCOMPARE ) {
11581171 if (type -> tp_compare == NULL && type -> tp_richcompare == NULL ) {
11591172 type -> tp_compare = base -> tp_compare ;
@@ -1163,9 +1176,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
11631176 else {
11641177 COPYSLOT (tp_compare );
11651178 }
1166- if (type -> tp_flags & base -> tp_flags & Py_TPFLAGS_HAVE_WEAKREFS ) {
1167- COPYSLOT (tp_weaklistoffset );
1168- }
11691179 if (type -> tp_flags & base -> tp_flags & Py_TPFLAGS_HAVE_ITER ) {
11701180 COPYSLOT (tp_iter );
11711181 COPYSLOT (tp_iternext );
@@ -2244,6 +2254,8 @@ SLOT0(slot_nb_absolute, "__abs__")
22442254static int
22452255slot_nb_nonzero (PyObject * self )
22462256{
2257+ /* XXX This should cope with a missing __nonzero__ */
2258+ /* XXX Should it also look for __len__? */
22472259 PyObject * res = PyObject_CallMethod (self , "__nonzero__" , "" );
22482260
22492261 if (res == NULL )
@@ -2283,6 +2295,7 @@ SLOT1(slot_nb_inplace_true_divide, "__itruediv__", PyObject *, "O")
22832295static int
22842296slot_tp_compare (PyObject * self , PyObject * other )
22852297{
2298+ /* XXX Should this cope with a missing __cmp__? */
22862299 PyObject * res = PyObject_CallMethod (self , "__cmp__" , "O" , other );
22872300 long r ;
22882301
@@ -2293,11 +2306,13 @@ slot_tp_compare(PyObject *self, PyObject *other)
22932306 return (int )r ;
22942307}
22952308
2309+ /* XXX This should cope with a missing __repr__, and also look for __str__ */
22962310SLOT0 (slot_tp_repr , "__repr__" )
22972311
22982312static long
22992313slot_tp_hash (PyObject * self )
23002314{
2315+ /* XXX This should cope with a missing __hash__ */
23012316 PyObject * res = PyObject_CallMethod (self , "__hash__" , "" );
23022317 long h ;
23032318
@@ -2322,6 +2337,7 @@ slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds)
23222337 return res ;
23232338}
23242339
2340+ /* XXX This should cope with a missing __str__, and also look for __repr__ */
23252341SLOT0 (slot_tp_str , "__str__" )
23262342
23272343static PyObject *
@@ -2371,6 +2387,7 @@ static char *name_op[] = {
23712387static PyObject *
23722388slot_tp_richcompare (PyObject * self , PyObject * other , int op )
23732389{
2390+ /* XXX How should this cope with missing __xx__? */
23742391 PyObject * meth = PyObject_GetAttrString (self , name_op [op ]);
23752392 PyObject * res ;
23762393
0 commit comments