summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-07 14:54:11 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-07 14:54:11 (GMT)
commit04d73c495ef132a898af997d33fac0badfc3c519 (patch)
tree4c850347d84ff9900051afb64ce50351eb5dea95
parent79378ffd91a38e220a5421a04ff8a593ce4a7c7a (diff)
downloadcpython-04d73c495ef132a898af997d33fac0badfc3c519.zip
cpython-04d73c495ef132a898af997d33fac0badfc3c519.tar.gz
cpython-04d73c495ef132a898af997d33fac0badfc3c519.tar.bz2
Check that all base classes are indeed class objects, rather than
expecting the caller to do so.
-rw-r--r--Objects/classobject.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 1cbbcf7..d10cbe6 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -43,7 +43,7 @@ PyObject *
PyClass_New(bases, dict, name)
PyObject *bases; /* NULL or tuple of classobjects! */
PyObject *dict;
- PyObject *name; /* String; NULL if unknown */
+ PyObject *name;
{
PyClassObject *op, *dummy;
static PyObject *getattrstr, *setattrstr, *delattrstr;
@@ -63,6 +63,16 @@ PyClass_New(bases, dict, name)
if (namestr == NULL)
return NULL;
}
+ if (name == NULL || !PyString_Check(name)) {
+ PyErr_SetString(PyExc_SystemError,
+ "PyClass_New: name must be a string");
+ return NULL;
+ }
+ if (dict == NULL || !PyDict_Check(dict)) {
+ PyErr_SetString(PyExc_SystemError,
+ "PyClass_New: dict must be a dictionary");
+ return NULL;
+ }
if (PyDict_GetItem(dict, docstr) == NULL) {
if (PyDict_SetItem(dict, docstr, Py_None) < 0)
return NULL;
@@ -70,9 +80,9 @@ PyClass_New(bases, dict, name)
if (PyDict_GetItem(dict, modstr) == NULL) {
PyObject *globals = PyEval_GetGlobals();
if (globals != NULL) {
- PyObject *name = PyDict_GetItem(globals, namestr);
- if (name != NULL) {
- if (PyDict_SetItem(dict, modstr, name) < 0)
+ PyObject *modname = PyDict_GetItem(globals, namestr);
+ if (modname != NULL) {
+ if (PyDict_SetItem(dict, modstr, modname) < 0)
return NULL;
}
}
@@ -82,8 +92,23 @@ PyClass_New(bases, dict, name)
if (bases == NULL)
return NULL;
}
- else
+ else {
+ int i;
+ if (!PyTuple_Check(bases)) {
+ PyErr_SetString(PyExc_SystemError,
+ "PyClass_New: bases must be a tuple");
+ return NULL;
+ }
+ i = PyTuple_Size(bases);
+ while (--i >= 0) {
+ if (!PyClass_Check(PyTuple_GetItem(bases, i))) {
+ PyErr_SetString(PyExc_SystemError,
+ "PyClass_New: base must be a class");
+ return NULL;
+ }
+ }
Py_INCREF(bases);
+ }
op = PyObject_NEW(PyClassObject, &PyClass_Type);
if (op == NULL) {
Py_DECREF(bases);