[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.31,2.32

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 14 Aug 2001 13:04:51 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv25069

Modified Files:
	typeobject.c 
Log Message:
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.


Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.31
retrieving revision 2.32
diff -C2 -d -r2.31 -r2.32
*** typeobject.c	2001/08/12 05:17:56	2.31
--- typeobject.c	2001/08/14 20:04:48	2.32
***************
*** 853,856 ****
--- 853,857 ----
  
  #if 0
+ /* XXX These should be made smarter before they can be used */
  static PyObject *
  object_repr(PyObject *self)
***************
*** 1037,1040 ****
--- 1038,1055 ----
  	}
  	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);
+ 	}
  }
  
***************
*** 1137,1141 ****
  	basebase = base->tp_base;
  
- 	COPYSLOT(tp_itemsize);
  	COPYSLOT(tp_dealloc);
  	COPYSLOT(tp_print);
--- 1152,1155 ----
***************
*** 1154,1158 ****
  	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) {
--- 1168,1171 ----
***************
*** 1164,1170 ****
  		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);
--- 1177,1180 ----
***************
*** 2245,2248 ****
--- 2255,2260 ----
  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__", "");
  
***************
*** 2284,2287 ****
--- 2296,2300 ----
  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;
***************
*** 2294,2297 ****
--- 2307,2311 ----
  }
  
+ /* XXX This should cope with a missing __repr__, and also look for __str__ */
  SLOT0(slot_tp_repr, "__repr__")
  
***************
*** 2299,2302 ****
--- 2313,2317 ----
  slot_tp_hash(PyObject *self)
  {
+ 	/* XXX This should cope with a missing __hash__ */
  	PyObject *res = PyObject_CallMethod(self, "__hash__", "");
  	long h;
***************
*** 2323,2326 ****
--- 2338,2342 ----
  }
  
+ /* XXX This should cope with a missing __str__, and also look for __repr__ */
  SLOT0(slot_tp_str, "__str__")
  
***************
*** 2372,2375 ****
--- 2388,2392 ----
  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;