[Python-Dev] When does `PyType_Type.tp_alloc get assigned to PyType_GenericAlloc ? (original) (raw)

Guido van Rossum guido at python.org
Sun Feb 7 14:45:12 EST 2016


I think it's probably line 2649 in typeobject.c, in type_new():

type->tp_alloc = PyType_GenericAlloc;

On Sun, Feb 7, 2016 at 5:58 AM, Randy Eels <randyeels at gmail.com> wrote:

Hi everyone,

I've a question about the implementation of the type builtin (in Python 3.5). In Objects/typeobject.c, the tpalloc slot of PyTypeType gets set to 0. However, I can see (using gdb) that it later gets assigned to &PyTypeGenericAlloc. I'd argue that this makes sense because, in typenew, there is a line where that member function gets called without previously checking whether that member points to something: _ _/* Allocate the type object */_ _type = (PyTypeObject *)metatype->tpalloc(metatype, nslots);_ _ Yet, I can't seem to understand where and when does the tpalloc slot of PyTypeType get re-assigned to PyTypeGenericAlloc. Does that even happen? Or am I missing something bigger? And, just out of further curiosity, why doesn't the aforementioned slot get initialised to PyTypeGenericAlloc in the first place? Thanks a lot.


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/guido%40python.org

-- --Guido van Rossum (python.org/~guido)



More information about the Python-Dev mailing list