[Python-3000-checkins] r54286 - python/branches/p3yk/Objects/object.c

georg.brandl python-3000-checkins at python.org
Mon Mar 12 14:15:18 CET 2007


Author: georg.brandl
Date: Mon Mar 12 14:15:14 2007
New Revision: 54286

Modified:
   python/branches/p3yk/Objects/object.c
Log:
Check the keys of the locals dict -- they need not be a list.


Modified: python/branches/p3yk/Objects/object.c
==============================================================================
--- python/branches/p3yk/Objects/object.c	(original)
+++ python/branches/p3yk/Objects/object.c	Mon Mar 12 14:15:14 2007
@@ -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__.


More information about the Python-3000-checkins mailing list