[Python-checkins] r87255 - in python/branches/release27-maint: Lib/test/test_import.py Misc/NEWS Python/modsupport.c
r.david.murray
python-checkins at python.org
Wed Dec 15 02:36:04 CET 2010
Author: r.david.murray
Date: Wed Dec 15 02:36:03 2010
New Revision: 87255
Log:
Merged revisions 87251 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r87251 | r.david.murray | 2010-12-14 18:06:25 -0500 (Tue, 14 Dec 2010) | 4 lines
#4236: avoid possible Fatal Error when import is called from __del__
Patch by Simon Cross, crasher test code by Martin von Löwis.
........
Modified:
python/branches/release27-maint/ (props changed)
python/branches/release27-maint/Lib/test/test_import.py
python/branches/release27-maint/Misc/NEWS
python/branches/release27-maint/Python/modsupport.c
Modified: python/branches/release27-maint/Lib/test/test_import.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_import.py (original)
+++ python/branches/release27-maint/Lib/test/test_import.py Wed Dec 15 02:36:03 2010
@@ -8,7 +8,8 @@
import unittest
from test.test_support import (unlink, TESTFN, unload, run_unittest, rmtree,
is_jython, check_warnings, EnvironmentVarGuard)
-
+import textwrap
+from test import script_helper
def remove_files(name):
for f in (name + os.extsep + "py",
@@ -253,6 +254,17 @@
self.assertEqual("Import by filename is not supported.",
c.exception.args[0])
+ def test_import_in_del_does_not_crash(self):
+ # Issue 4236
+ testfn = script_helper.make_script('', TESTFN, textwrap.dedent("""\
+ import sys
+ class C:
+ def __del__(self):
+ import imp
+ sys.argv.insert(0, C())
+ """))
+ script_helper.assert_python_ok(testfn)
+
class PycRewritingTests(unittest.TestCase):
# Test that the `co_filename` attribute on code objects always points
Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS (original)
+++ python/branches/release27-maint/Misc/NEWS Wed Dec 15 02:36:03 2010
@@ -9,6 +9,10 @@
Core and Builtins
-----------------
+- Issue #4236: Py_InitModule4 now checks the import machinery directly
+ rather than the Py_IsInitialized flag, avoiding a Fatal Python
+ error in certain circumstances when an import is done in __del__.
+
- Issue #10674: Remove unused 'dictmaker' rule from grammar.
- Issue #10596: Fix float.__mod__ to have the same behaviour as
Modified: python/branches/release27-maint/Python/modsupport.c
==============================================================================
--- python/branches/release27-maint/Python/modsupport.c (original)
+++ python/branches/release27-maint/Python/modsupport.c Wed Dec 15 02:36:03 2010
@@ -34,8 +34,9 @@
{
PyObject *m, *d, *v, *n;
PyMethodDef *ml;
- if (!Py_IsInitialized())
- Py_FatalError("Interpreter not initialized (version mismatch?)");
+ PyInterpreterState *interp = PyThreadState_Get()->interp;
+ if (interp->modules == NULL)
+ Py_FatalError("Python import machinery not initialized");
if (module_api_version != PYTHON_API_VERSION) {
char message[512];
PyOS_snprintf(message, sizeof(message),
More information about the Python-checkins
mailing list