Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 29360893df0931703cb2fe0c0fbc0fc963e64ead authored by Georg Brandl on 20 February 2011, 10:31:59 UTC
Make a 3.2 maintenance branch.
Tip revision: 2936089
borrowed_ref_2.py
"""
_PyType_Lookup() returns a borrowed reference.
This attacks PyObject_GenericSetAttr().

NB. on my machine this crashes in 2.5 debug but not release.
"""

class A(object):
    pass

class B(object):
    def __del__(self):
        print("hi")
        del C.d

class D(object):
    def __set__(self, obj, value):
        self.hello = 42

class C(object):
    d = D()

    def g():
        pass


c = C()
a = A()
a.cycle = a
a.other = B()

lst = [None] * 1000000
i = 0
del a
while 1:
    c.d = 42         # segfaults in PyMethod_New(__func__=D.__set__, __self__=d)
    lst[i] = c.g     # consume the free list of instancemethod objects
    i += 1
back to top