/Lib/test/crashers/borrowed_ref_2.py

http://unladen-swallow.googlecode.com/ · Python · 38 lines · 24 code · 8 blank · 6 comment · 1 complexity · 488e09f4a8f771ea4b0fba4c1db7da6e MD5 · raw file

  1. """
  2. _PyType_Lookup() returns a borrowed reference.
  3. This attacks PyObject_GenericSetAttr().
  4. NB. on my machine this crashes in 2.5 debug but not release.
  5. """
  6. class A(object):
  7. pass
  8. class B(object):
  9. def __del__(self):
  10. print "hi"
  11. del C.d
  12. class D(object):
  13. def __set__(self, obj, value):
  14. self.hello = 42
  15. class C(object):
  16. d = D()
  17. def g():
  18. pass
  19. c = C()
  20. a = A()
  21. a.cycle = a
  22. a.other = B()
  23. lst = [None] * 1000000
  24. i = 0
  25. del a
  26. while 1:
  27. c.d = 42 # segfaults in PyMethod_New(im_func=D.__set__, im_self=d)
  28. lst[i] = c.g # consume the free list of instancemethod objects
  29. i += 1