Mercurial > cpython-lru_cache-weakref
diff Objects/object.c @ 41124:211201e6b045
Check the keys of the locals dict -- they need not be a list.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Mon, 12 Mar 2007 13:15:14 +0000 |
| parents | cf452027073e |
| children | d1c3dd184e38 |
line wrap: on
line diff
--- a/Objects/object.c Sat Mar 10 22:13:27 2007 +0000 +++ b/Objects/object.c Mon Mar 12 13:15:14 2007 +0000 @@ -1349,6 +1349,7 @@ static PyObject * _dir_locals() { + PyObject *names; PyObject *locals = PyEval_GetLocals(); if (locals == NULL) { @@ -1356,8 +1357,18 @@ 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__.
