-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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()
- Loading branch information
Showing
17 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import sys | ||
import types | ||
import unittest | ||
|
||
|
||
# bpo-46417: Test that structseq types used by the sys module are still | ||
# valid when Py_Finalize()/Py_Initialize() are called multiple times. | ||
class TestStructSeq(unittest.TestCase): | ||
# test PyTypeObject members | ||
def check_structseq(self, obj_type): | ||
# ob_refcnt | ||
self.assertGreaterEqual(sys.getrefcount(obj_type), 1) | ||
# tp_base | ||
self.assertTrue(issubclass(obj_type, tuple)) | ||
# tp_bases | ||
self.assertEqual(obj_type.__bases__, (tuple,)) | ||
# tp_dict | ||
self.assertIsInstance(obj_type.__dict__, types.MappingProxyType) | ||
# tp_mro | ||
self.assertEqual(obj_type.__mro__, (obj_type, tuple, object)) | ||
# tp_name | ||
self.assertIsInstance(type.__name__, str) | ||
# tp_subclasses | ||
self.assertEqual(obj_type.__subclasses__(), []) | ||
|
||
def test_sys_attrs(self): | ||
for attr_name in ( | ||
'flags', # FlagsType | ||
'float_info', # FloatInfoType | ||
'hash_info', # Hash_InfoType | ||
'int_info', # Int_InfoType | ||
'thread_info', # ThreadInfoType | ||
'version_info', # VersionInfoType | ||
): | ||
with self.subTest(attr=attr_name): | ||
attr = getattr(sys, attr_name) | ||
self.check_structseq(type(attr)) | ||
|
||
def test_sys_funcs(self): | ||
func_names = ['get_asyncgen_hooks'] # AsyncGenHooksType | ||
if hasattr(sys, 'getwindowsversion'): | ||
func_names.append('getwindowsversion') # WindowsVersionType | ||
for func_name in func_names: | ||
with self.subTest(func=func_name): | ||
func = getattr(sys, func_name) | ||
obj = func() | ||
self.check_structseq(type(obj)) | ||
|
||
|
||
try: | ||
unittest.main() | ||
except SystemExit as exc: | ||
if exc.args[0] != 0: | ||
raise | ||
print("Tests passed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters