ยปCore Development>Code coverage>Lib/test/crashers/mutation_inside_cyclegc.py

Python code coverage for Lib/test/crashers/mutation_inside_cyclegc.py

#countcontent
1n/a
2n/a# The cycle GC collector can be executed when any GC-tracked object is
3n/a# allocated, e.g. during a call to PyList_New(), PyDict_New(), ...
4n/a# Moreover, it can invoke arbitrary Python code via a weakref callback.
5n/a# This means that there are many places in the source where an arbitrary
6n/a# mutation could unexpectedly occur.
7n/a
8n/a# The example below shows list_slice() not expecting the call to
9n/a# PyList_New to mutate the input list. (Of course there are many
10n/a# more examples like this one.)
11n/a
12n/a
13n/aimport weakref
14n/a
15n/aclass A(object):
16n/a pass
17n/a
18n/adef callback(x):
19n/a del lst[:]
20n/a
21n/a
22n/akeepalive = []
23n/a
24n/afor i in range(100):
25n/a lst = [str(i)]
26n/a a = A()
27n/a a.cycle = a
28n/a keepalive.append(weakref.ref(a, callback))
29n/a del a
30n/a while lst:
31n/a keepalive.append(lst[:])