Hi everyone,

I've a question about the implementation of the `type` builtin (in Python
3.5).

In Objects/typeobject.c, the `tp_alloc` slot of PyType_Type gets set to 0.
However, I can see (using gdb) that it later gets assigned to
`&PyType_GenericAlloc`. I'd argue that this makes sense because, in
`type_new`, 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->tp_alloc(metatype, nslots);
```

Yet, I can't seem to understand where and when does the `tp_alloc` slot of
PyType_Type get re-assigned to PyType_GenericAlloc. 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 `PyType_GenericAlloc` in the first place?

Thanks a lot.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to