1"""
2The gc module can still invoke arbitrary Python code and crash.
3This is an attack against _PyInstance_Lookup(), which is documented
4as follows:
5
6    The point of this routine is that it never calls arbitrary Python
7    code, so is always "safe":  all it does is dict lookups.
8
9But of course dict lookups can call arbitrary Python code.
10The following code causes mutation of the object graph during
11the call to has_finalizer() in gcmodule.c, and that might
12segfault.
13"""
14
15import gc
16
17
18class A:
19    def __hash__(self):
20        return hash("__del__")
21    def __eq__(self, other):
22        del self.other
23        return False
24
25a = A()
26b = A()
27
28a.__dict__[b] = 'A'
29
30a.other = b
31b.other = a
32
33gc.collect()
34del a, b
35
36gc.collect()
37