summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_embed.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-01-21 00:42:25 (GMT)
committerGitHub <noreply@github.com>2022-01-21 00:42:25 (GMT)
commite9e3eab0b868c7d0b48e472705024240d5c39d5c (patch)
tree65c254d948a37dd822085887ebb84f390ad48d94 /Lib/test/test_embed.py
parent27df7566bc19699b967e0e30d7808637b90141f6 (diff)
downloadcpython-e9e3eab0b868c7d0b48e472705024240d5c39d5c.zip
cpython-e9e3eab0b868c7d0b48e472705024240d5c39d5c.tar.gz
cpython-e9e3eab0b868c7d0b48e472705024240d5c39d5c.tar.bz2
bpo-46417: Finalize structseq types at exit (GH-30645)
Add _PyStructSequence_FiniType() and _PyStaticType_Dealloc() functions to finalize a structseq static type in Py_Finalize(). Currrently, these functions do nothing if Python is built in release mode. Clear static types: * AsyncGenHooksType: sys.set_asyncgen_hooks() * FlagsType: sys.flags * FloatInfoType: sys.float_info * Hash_InfoType: sys.hash_info * Int_InfoType: sys.int_info * ThreadInfoType: sys.thread_info * UnraisableHookArgsType: sys.unraisablehook * VersionInfoType: sys.version * WindowsVersionType: sys.getwindowsversion()
Diffstat (limited to 'Lib/test/test_embed.py')
-rw-r--r--Lib/test/test_embed.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 9fed0a5..204b194 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -329,6 +329,18 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase):
self.assertEqual(out, "Py_RunMain(): sys.argv=['-c', 'arg2']\n" * nloop)
self.assertEqual(err, '')
+ def test_finalize_structseq(self):
+ # bpo-46417: Py_Finalize() clears structseq static types. Check that
+ # sys attributes using struct types still work when
+ # Py_Finalize()/Py_Initialize() is called multiple times.
+ # print() calls type->tp_repr(instance) and so checks that the types
+ # are still working properly.
+ script = support.findfile('_test_embed_structseq.py')
+ with open(script, encoding="utf-8") as fp:
+ code = fp.read()
+ out, err = self.run_embedded_interpreter("test_repeated_init_exec", code)
+ self.assertEqual(out, 'Tests passed\n' * INIT_LOOPS)
+
class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
maxDiff = 4096