diff Objects/typeobject.c @ 39222:b0cdcbcc5f45

Get rid of most of the flags (in tp_flags) that keep track of various variations of the type struct and its attachments. In Py3k, all type structs have to have all fields -- no binary backwards compatibility. Had to change the complex object to a new-style number!
author Guido van Rossum <guido@python.org>
date Thu, 27 Jul 2006 21:53:35 +0000
parents 29ae5e0fc348
children 654c380cf8b9
line wrap: on
line diff
--- a/Objects/typeobject.c	Thu Jun 08 15:35:45 2006 +0000
+++ b/Objects/typeobject.c	Thu Jul 27 21:53:35 2006 +0000
@@ -433,8 +433,7 @@
 		if (!PyType_IsSubtype(obj->ob_type, type))
 			return obj;
 		type = obj->ob_type;
-		if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS) &&
-		    type->tp_init != NULL &&
+		if (type->tp_init != NULL &&
 		    type->tp_init(obj, args, kwds) < 0) {
 			Py_DECREF(obj);
 			obj = NULL;
@@ -813,9 +812,6 @@
 {
 	PyObject *mro;
 
-	if (!(a->tp_flags & Py_TPFLAGS_HAVE_CLASS))
-		return b == a || b == &PyBaseObject_Type;
-
 	mro = a->tp_mro;
 	if (mro != NULL) {
 		/* Deal with multiple inheritance without recursion
@@ -1844,12 +1840,6 @@
 	if (base->tp_flags & Py_TPFLAGS_HAVE_GC)
 		type->tp_flags |= Py_TPFLAGS_HAVE_GC;
 
-	/* It's a new-style number unless it specifically inherits any
-	   old-style numeric behavior */
-	if ((base->tp_flags & Py_TPFLAGS_CHECKTYPES) ||
-	    (base->tp_as_number == NULL))
-		type->tp_flags |= Py_TPFLAGS_CHECKTYPES;
-
 	/* Initialize essential fields */
 	type->tp_as_number = &et->as_number;
 	type->tp_as_sequence = &et->as_sequence;
@@ -2881,39 +2871,11 @@
 {
 	Py_ssize_t oldsize, newsize;
 
-	/* Special flag magic */
-	if (!type->tp_as_buffer && base->tp_as_buffer) {
-		type->tp_flags &= ~Py_TPFLAGS_HAVE_GETCHARBUFFER;
-		type->tp_flags |=
-			base->tp_flags & Py_TPFLAGS_HAVE_GETCHARBUFFER;
-	}
-	if (!type->tp_as_sequence && base->tp_as_sequence) {
-		type->tp_flags &= ~Py_TPFLAGS_HAVE_SEQUENCE_IN;
-		type->tp_flags |= base->tp_flags & Py_TPFLAGS_HAVE_SEQUENCE_IN;
-	}
-	if ((type->tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS) !=
-	    (base->tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS)) {
-		if ((!type->tp_as_number && base->tp_as_number) ||
-		    (!type->tp_as_sequence && base->tp_as_sequence)) {
-			type->tp_flags &= ~Py_TPFLAGS_HAVE_INPLACEOPS;
-			if (!type->tp_as_number && !type->tp_as_sequence) {
-				type->tp_flags |= base->tp_flags &
-					Py_TPFLAGS_HAVE_INPLACEOPS;
-			}
-		}
-		/* Wow */
-	}
-	if (!type->tp_as_number && base->tp_as_number) {
-		type->tp_flags &= ~Py_TPFLAGS_CHECKTYPES;
-		type->tp_flags |= base->tp_flags & Py_TPFLAGS_CHECKTYPES;
-	}
-
 	/* Copying basicsize is connected to the GC flags */
 	oldsize = base->tp_basicsize;
 	newsize = type->tp_basicsize ? type->tp_basicsize : oldsize;
 	if (!(type->tp_flags & Py_TPFLAGS_HAVE_GC) &&
 	    (base->tp_flags & Py_TPFLAGS_HAVE_GC) &&
-	    (type->tp_flags & Py_TPFLAGS_HAVE_RICHCOMPARE/*GC slots exist*/) &&
 	    (!type->tp_traverse && !type->tp_clear)) {
 		type->tp_flags |= Py_TPFLAGS_HAVE_GC;
 		if (type->tp_traverse == NULL)
@@ -2921,7 +2883,7 @@
 		if (type->tp_clear == NULL)
 			type->tp_clear = base->tp_clear;
 	}
-	if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) {
+	{
 		/* The condition below could use some explanation.
 		   It appears that tp_new is not inherited for static types
 		   whose base class is 'object'; this seems to be a precaution
@@ -2947,12 +2909,8 @@
 	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);
-	}
+	COPYVAL(tp_weaklistoffset);
+	COPYVAL(tp_dictoffset);
 }
 
 static void
@@ -3022,10 +2980,7 @@
 		COPYNUM(nb_floor_divide);
 		COPYNUM(nb_inplace_true_divide);
 		COPYNUM(nb_inplace_floor_divide);
-		/* XXX(nnorwitz): we don't need to check flags do we? */
-		if (base->tp_flags & Py_TPFLAGS_HAVE_INDEX) {
-			COPYNUM(nb_index);
-		}
+		COPYNUM(nb_index);
 	}
 
 	if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) {
@@ -3080,7 +3035,7 @@
 	/* tp_hash see tp_richcompare */
 	COPYSLOT(tp_call);
 	COPYSLOT(tp_str);
-	if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_RICHCOMPARE) {
+	{
 		if (type->tp_compare == NULL &&
 		    type->tp_richcompare == NULL &&
 		    type->tp_hash == NULL)
@@ -3090,14 +3045,11 @@
 			type->tp_hash = base->tp_hash;
 		}
 	}
-	else {
-		COPYSLOT(tp_compare);
-	}
-	if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_ITER) {
+	{
 		COPYSLOT(tp_iter);
 		COPYSLOT(tp_iternext);
 	}
-	if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) {
+	{
 		COPYSLOT(tp_descr_get);
 		COPYSLOT(tp_descr_set);
 		COPYSLOT(tp_dictoffset);
@@ -3419,11 +3371,6 @@
 	if (!check_num_args(args, 1))
 		return NULL;
 	other = PyTuple_GET_ITEM(args, 0);
-	if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
-	    !PyType_IsSubtype(other->ob_type, self->ob_type)) {
-		Py_INCREF(Py_NotImplemented);
-		return Py_NotImplemented;
-	}
 	return (*func)(self, other);
 }
 
@@ -3436,8 +3383,7 @@
 	if (!check_num_args(args, 1))
 		return NULL;
 	other = PyTuple_GET_ITEM(args, 0);
-	if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
-	    !PyType_IsSubtype(other->ob_type, self->ob_type)) {
+	if (!PyType_IsSubtype(other->ob_type, self->ob_type)) {
 		Py_INCREF(Py_NotImplemented);
 		return Py_NotImplemented;
 	}