]> granicus.if.org Git - python/commitdiff
Merged revisions 74457 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 15 Aug 2009 13:23:05 +0000 (13:23 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 15 Aug 2009 13:23:05 +0000 (13:23 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74457 | benjamin.peterson | 2009-08-15 08:16:38 -0500 (Sat, 15 Aug 2009) | 1 line

  #6707 fix a crash with dir() on an uninitialized module
........

Lib/test/test_module.py
Misc/NEWS
Objects/object.c

index 225e954fc42d37f5c6d6b418bc5df690ad72089d..0e562906551455725e1016925673437a2db15ed8 100644 (file)
@@ -11,6 +11,7 @@ class ModuleTests(unittest.TestCase):
         # and __doc__ is None
         foo = ModuleType.__new__(ModuleType)
         self.assertTrue(foo.__dict__ is None)
+        self.assertRaises(SystemError, dir, foo)
         try:
             s = foo.__name__
             self.fail("__name__ = %s" % repr(s))
index a9fe8165226f7cf6c3caaab0aacdbb7cf256be54..ee5e62b263629126d470469f463071f4bf81df4d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 1?
 Core and Builtins
 -----------------
 
+- Issue #6707: dir() on an uninitialized module caused a crash.
+
 - Issue #6540: Fixed crash for bytearray.translate() with invalid parameters.
 
 - Issue #6573: set.union() stopped processing inputs if an instance of self
index 6845201c23fadec4e758e8f46e99d9b263b863ce..e8ac8a2e469559fbdc2a2b452bb4337509937734 100644 (file)
@@ -1265,9 +1265,11 @@ _specialized_dir_module(PyObject *obj)
                if (PyDict_Check(dict))
                        result = PyDict_Keys(dict);
                else {
-                       PyErr_Format(PyExc_TypeError,
-                                    "%.200s.__dict__ is not a dictionary",
-                                    PyModule_GetName(obj));
+                       const char *name = PyModule_GetName(obj);
+                       if (name)
+                               PyErr_Format(PyExc_TypeError,
+                                            "%.200s.__dict__ is not a dictionary",
+                                            name);
                }
        }