diff options
author | Jeroen Demeyer <J.Demeyer@UGent.be> | 2019-05-22 11:09:35 (GMT) |
---|---|---|
committer | Petr Viktorin <encukou@gmail.com> | 2019-05-22 11:09:35 (GMT) |
commit | 77aa396bb9415428de09112ddf6b34bb843811eb (patch) | |
tree | 6e30eb4a5671e2cfb086985b4b8412b337af320d /Lib | |
parent | b892d3ea468101d35e2fb081002fa693bd86eca9 (diff) | |
download | cpython-77aa396bb9415428de09112ddf6b34bb843811eb.zip cpython-77aa396bb9415428de09112ddf6b34bb843811eb.tar.gz cpython-77aa396bb9415428de09112ddf6b34bb843811eb.tar.bz2 |
bpo-36907: fix refcount bug in _PyStack_UnpackDict() (GH-13381)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_call.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index 0da0719..e4ab33c 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -8,6 +8,7 @@ except ImportError: import struct import collections import itertools +import gc class FunctionCalls(unittest.TestCase): @@ -457,6 +458,22 @@ class FastCallTests(unittest.TestCase): result = _testcapi.pyobject_fastcallkeywords(func, args, kwnames) self.check_result(result, expected) + def test_fastcall_clearing_dict(self): + # Test bpo-36907: the point of the test is just checking that this + # does not crash. + class IntWithDict: + __slots__ = ["kwargs"] + def __init__(self, **kwargs): + self.kwargs = kwargs + def __index__(self): + self.kwargs.clear() + gc.collect() + return 0 + x = IntWithDict(dont_inherit=IntWithDict()) + # We test the argument handling of "compile" here, the compilation + # itself is not relevant. When we pass flags=x below, x.__index__() is + # called, which changes the keywords dict. + compile("pass", "", "exec", x, **x.kwargs) if __name__ == "__main__": unittest.main() |