summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-08-30 04:43:35 (GMT)
committerGuido van Rossum <guido@python.org>2001-08-30 04:43:35 (GMT)
commitc41418751fcef0a42f336ba91871827b45d558a7 (patch)
treee046712a00e38e94b2a60f5f1a6298ac5eebd460
parent31bcff8815f263ab25ac9458f7b45975d8ebecbc (diff)
downloadcpython-c41418751fcef0a42f336ba91871827b45d558a7.zip
cpython-c41418751fcef0a42f336ba91871827b45d558a7.tar.gz
cpython-c41418751fcef0a42f336ba91871827b45d558a7.tar.bz2
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.
-rw-r--r--Objects/typeobject.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 559c41b..719a0a4 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -712,6 +712,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
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 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
nslots++;
add_dict++;
}
- if (slots == NULL && base->tp_weaklistoffset == 0) {
+ if (slots == NULL && base->tp_weaklistoffset == 0 &&
+ base->tp_itemsize == 0) {
nslots++;
add_weak++;
}