+++ /dev/null
-\r
-# The cycle GC collector can be executed when any GC-tracked object is\r
-# allocated, e.g. during a call to PyList_New(), PyDict_New(), ...\r
-# Moreover, it can invoke arbitrary Python code via a weakref callback.\r
-# This means that there are many places in the source where an arbitrary\r
-# mutation could unexpectedly occur.\r
-\r
-# The example below shows list_slice() not expecting the call to\r
-# PyList_New to mutate the input list. (Of course there are many\r
-# more examples like this one.)\r
-\r
-\r
-import weakref\r
-\r
-class A(object):\r
- pass\r
-\r
-def callback(x):\r
- del lst[:]\r
-\r
-\r
-keepalive = []\r
-\r
-for i in range(100):\r
- lst = [str(i)]\r
- a = A()\r
- a.cycle = a\r
- keepalive.append(weakref.ref(a, callback))\r
- del a\r
- while lst:\r
- keepalive.append(lst[:])\r