~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Lib/test/crashers/mutation_inside_cyclegc.py

  • Committer: armin.rigo
  • Date: 2008-04-25 09:35:18 UTC
  • Revision ID: svn-v3-trunk1:6015fed2-1504-0410-9fe1-9d1591cc4771:python%2Ftrunk:62497
A new crasher.

Show diffs side-by-side

added added

removed removed

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