Check the keys of the locals dict -- they need not be a list.

This commit is contained in:
Georg Brandl 2007-03-12 13:15:14 +00:00
parent e32b4224d0
commit ed3b838988
1 changed files with 12 additions and 1 deletions

View File

@ -1349,6 +1349,7 @@ merge_class_dict(PyObject* dict, PyObject* aclass)
static PyObject *
_dir_locals()
{
PyObject *names;
PyObject *locals = PyEval_GetLocals();
if (locals == NULL) {
@ -1356,8 +1357,18 @@ _dir_locals()
return NULL;
}
names = PyMapping_Keys(locals);
if (!names)
return NULL;
if (!PyList_Check(names)) {
PyErr_Format(PyExc_TypeError,
"dir(): expected keys() of locals to be a list, "
"not '%.200s'", names->ob_type->tp_name);
Py_DECREF(names);
return NULL;
}
/* the locals don't need to be DECREF'd */
return PyMapping_Keys(locals);
return names;
}
/* Helper for PyObject_Dir of type objects: returns __dict__ and __bases__.