mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Issue #22079: PyType_Ready() now checks that statically allocated type has
no dynamically allocated bases.
This commit is contained in:
		
							parent
							
								
									db07164053
								
							
						
					
					
						commit
						e09bcc874a
					
				
					 2 changed files with 21 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -4680,6 +4680,20 @@ PyType_Ready(PyTypeObject *type)
 | 
			
		|||
            inherit_slots(type, (PyTypeObject *)b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* All bases of statically allocated type should be statically allocated */
 | 
			
		||||
    if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
 | 
			
		||||
        for (i = 0; i < n; i++) {
 | 
			
		||||
            PyObject *b = PyTuple_GET_ITEM(bases, i);
 | 
			
		||||
            if (PyType_Check(b) &&
 | 
			
		||||
                (((PyTypeObject *)b)->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
 | 
			
		||||
                PyErr_Format(PyExc_TypeError,
 | 
			
		||||
                             "type '%.100s' is not dynamically allocated but "
 | 
			
		||||
                             "its base type '%.100s' is dynamically allocated",
 | 
			
		||||
                             type->tp_name, ((PyTypeObject *)b)->tp_name);
 | 
			
		||||
                goto error;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    /* Sanity check for tp_free. */
 | 
			
		||||
    if (PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) &&
 | 
			
		||||
        (type->tp_free == NULL || type->tp_free == PyObject_Del)) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue