diff Objects/typeobject.c @ 19595:db36e396f043 legacy-trunk

Safety measures now that str and tuple are subclassable: If tp_itemsize of the basetype is nonzero, only allow empty __slots__ (declaring that no __dict__ should be added), and don't add a weakref offset.
author Guido van Rossum <guido@python.org>
date Thu, 30 Aug 2001 04:43:35 +0000
parents c48654959dc4
children 337b53679c73
line wrap: on
line diff
--- a/Objects/typeobject.c	Thu Aug 30 04:37:15 2001 +0000
+++ b/Objects/typeobject.c	Thu Aug 30 04:43:35 2001 +0000
@@ -712,6 +712,13 @@
 		if (slots == NULL)
 			return NULL;
 		nslots = PyTuple_GET_SIZE(slots);
+		if (nslots > 0 && base->tp_itemsize != 0) {
+			PyErr_Format(PyExc_TypeError,
+				     "nonempty __slots__ "
+				     "not supported for subtype of '%s'",
+				     base->tp_name);
+			return NULL;
+		}
 		for (i = 0; i < nslots; i++) {
 			if (!PyString_Check(PyTuple_GET_ITEM(slots, i))) {
 				PyErr_SetString(PyExc_TypeError,
@@ -728,7 +735,8 @@
 		nslots++;
 		add_dict++;
 	}
-	if (slots == NULL && base->tp_weaklistoffset == 0) {
+	if (slots == NULL && base->tp_weaklistoffset == 0 &&
+	    base->tp_itemsize == 0) {
 		nslots++;
 		add_weak++;
 	}