mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
bpo-32374: m_traverse may be called with m_state=NULL (GH-5140)
Multi-phase initialized modules allow m_traverse to be called while the module is still being initialized, so module authors may need to account for that.
This commit is contained in:
parent
d6e1404661
commit
c2b0b12d1a
5 changed files with 96 additions and 7 deletions
|
@ -9,7 +9,7 @@ import types
|
|||
import unittest
|
||||
import importlib.util
|
||||
import importlib
|
||||
|
||||
from test.support.script_helper import assert_python_failure
|
||||
|
||||
class LoaderTests(abc.LoaderTests):
|
||||
|
||||
|
@ -267,6 +267,20 @@ class MultiPhaseExtensionModuleTests(abc.LoaderTests):
|
|||
self.assertEqual(module.__name__, name)
|
||||
self.assertEqual(module.__doc__, "Module named in %s" % lang)
|
||||
|
||||
@unittest.skipIf(not hasattr(sys, 'gettotalrefcount'),
|
||||
'--with-pydebug has to be enabled for this test')
|
||||
def test_bad_traverse(self):
|
||||
''' Issue #32374: Test that traverse fails when accessing per-module
|
||||
state before Py_mod_exec was executed.
|
||||
(Multiphase initialization modules only)
|
||||
'''
|
||||
script = """if True:
|
||||
import importlib.util as util
|
||||
spec = util.find_spec('_testmultiphase')
|
||||
spec.name = '_testmultiphase_with_bad_traverse'
|
||||
m = spec.loader.create_module(spec)"""
|
||||
assert_python_failure("-c", script)
|
||||
|
||||
|
||||
(Frozen_MultiPhaseExtensionModuleTests,
|
||||
Source_MultiPhaseExtensionModuleTests
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue