mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	 ff737954f3
			
		
	
	
		ff737954f3
		
	
	
	
	
		
			
			Also removed im_class and renamed im_self to __self__ and im_func to __func__. im_class can be substituted with method.__self__.__class__. I've also updated some parts of the documenation.
		
			
				
	
	
		
			38 lines
		
	
	
	
		
			647 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
	
		
			647 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| """
 | |
| _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
 |