[Python-checkins] CVS: python/dist/src/Objects object.c,2.124.4.5,2.124.4.6

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 04 May 2001 09:50:24 -0700


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

Modified Files:
      Tag: descr-branch
	object.c 
Log Message:
- Remove now-redundant #ifdef WITH_CYCLE_GCs.

- Add _PyObject_TypeCheck(), support for PyObject_TypeCheck().

- Disambiguate a complex Boolean expression in debug-only code.
  (Yes I had to use some heavy-duty debugging tools to figure out a
  simple problem. :-)


Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.124.4.5
retrieving revision 2.124.4.6
diff -C2 -r2.124.4.5 -r2.124.4.6
*** object.c	2001/05/03 19:51:35	2.124.4.5
--- object.c	2001/05/04 16:50:22	2.124.4.6
***************
*** 94,101 ****
  		return op;
    	}
- #ifdef WITH_CYCLE_GC
  	if (PyType_IS_GC(tp))
  		op = (PyObject *) PyObject_FROM_GC(op);
- #endif
  	/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
  	op->ob_type = tp;
--- 94,99 ----
***************
*** 112,119 ****
  		return op;
  	}
- #ifdef WITH_CYCLE_GC
  	if (PyType_IS_GC(tp))
  		op = (PyVarObject *) PyObject_FROM_GC(op);
- #endif
  	/* Any changes should be reflected in PyObject_INIT_VAR */
  	op->ob_size = size;
--- 110,115 ----
***************
*** 130,137 ****
  	if (op == NULL)
  		return PyErr_NoMemory();
- #ifdef WITH_CYCLE_GC
  	if (PyType_IS_GC(tp))
  		op = (PyObject *) PyObject_FROM_GC(op);
- #endif
  	return PyObject_INIT(op, tp);
  }
--- 126,131 ----
***************
*** 144,151 ****
  	if (op == NULL)
  		return (PyVarObject *)PyErr_NoMemory();
- #ifdef WITH_CYCLE_GC
  	if (PyType_IS_GC(tp))
  		op = (PyVarObject *) PyObject_FROM_GC(op);
- #endif
  	return PyObject_INIT_VAR(op, tp, size);
  }
--- 138,143 ----
***************
*** 154,162 ****
  _PyObject_Del(PyObject *op)
  {
- #ifdef WITH_CYCLE_GC
  	if (op && PyType_IS_GC(op->ob_type)) {
  		op = (PyObject *) PyObject_AS_GC(op);
  	}
- #endif
  	PyObject_FREE(op);
  }
--- 146,152 ----
***************
*** 1240,1243 ****
--- 1230,1251 ----
  
  
+ /* type test with subclassing support */
+ 
+ int
+ _PyObject_TypeCheck(PyObject *obj, PyTypeObject *type)
+ {
+ 	PyTypeObject *tp = obj->ob_type;
+ 
+ 	do {
+ 		if (tp == type)
+ 			return 1;
+ 		if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_CLASS))
+ 			return 0;
+ 		tp = tp->tp_base;
+ 	} while (tp != NULL);
+ 	return 0;
+ }
+ 
+ 
  /*
  NoObject is usable as a non-NULL undefined value, used by the macro None.
***************
*** 1406,1410 ****
  	for (i = 0; (n == 0 || i < n) && op != &refchain; i++) {
  		while (op == self || op == args || op == res || op == t ||
! 		       t != NULL && op->ob_type != (PyTypeObject *) t) {
  			op = op->_ob_next;
  			if (op == &refchain)
--- 1414,1418 ----
  	for (i = 0; (n == 0 || i < n) && op != &refchain; i++) {
  		while (op == self || op == args || op == res || op == t ||
! 		       (t != NULL && op->ob_type != (PyTypeObject *) t)) {
  			op = op->_ob_next;
  			if (op == &refchain)