<div dir="ltr"><br class="">On Sun, Feb 7, 2016 at 8:45 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I think it's probably line 2649 in typeobject.c, in type_new():<br><br>    type->tp_alloc = PyType_GenericAlloc;</blockquote><div> </div><div>I pondered it but it doesn't seem to be that. Isn't `type_new` called <i>after</i> PyType_Type.tp_alloc has been called? I thought that line was only being executed for user-defined types, and maybe some built-in types, but certainly not PyType_Type.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 7, 2016 at 9:27 PM, eryk sun <span dir="ltr"><<a href="mailto:eryksun@gmail.com" target="_blank">eryksun@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Sun, Feb 7, 2016 at 7:58 AM, Randy Eels <<a href="mailto:randyeels@gmail.com">randyeels@gmail.com</a>> wrote:<br>
><br>
> Yet, I can't seem to understand where and when does the `tp_alloc` slot of<br>
> PyType_Type get re-assigned to PyType_GenericAlloc. Does that even happen?<br>
> Or am I missing something bigger?<br>
<br>
</span>_Py_InitializeEx_Private in Python/pylifecycle.c calls _Py_ReadyTypes<br>
in Objects/object.c. This calls PyType_Ready(&PyType_Type) in<br>
Objects/typeobject.c, which assigns type->tp_base = &PyBaseObject_Type<br>
and then calls inherit_slots. This executes COPYSLOT(tp_alloc), which<br>
assigns PyType_Type.tp_alloc = PyBaseObject_Type.tp_alloc, which is<br>
statically assigned as PyType_GenericAlloc.<br>
<br>
Debug trace on Windows:<br>
<br>
    0:000> bp python35!PyType_Ready<br>
    0:000> g<br>
    Breakpoint 0 hit<br>
    python35!PyType_Ready:<br>
    00000000`6502d160 4053            push    rbx<br>
    0:000> ?? ((PyTypeObject *)@rcx)->tp_name<br>
    char * 0x00000000`650e4044<br>
     "object"<br>
    0:000> g<br>
    Breakpoint 0 hit<br>
    python35!PyType_Ready:<br>
    00000000`6502d160 4053            push    rbx<br>
    0:000> ?? ((PyTypeObject *)@rcx)->tp_name<br>
    char * 0x00000000`651d8e5c<br>
     "type"<br>
    0:000> bp python35!inherit_slots<br>
    0:000> g<br>
    Breakpoint 1 hit<br>
    python35!inherit_slots:<br>
    00000000`6502c440 48895c2408      mov     qword ptr [rsp+8],rbx<br>
                                            ss:00000000`0028f960={<br>
                                            python35!PyType_Type<br>
                                            (00000000`6527cba0)}<br>
<br>
At entry to inherit_slots, PyType_Type.tp_alloc is NULL:<br>
<br>
    0:000> ?? python35!PyType_Type.tp_alloc<br>
    <function> * 0x00000000`00000000<br>
    0:000> pt<br>
    python35!inherit_slots+0xd17:<br>
    00000000`6502d157 c3              ret<br>
<br>
At exit it's set to PyType_GenericAlloc:<br>
<br>
    0:000> ?? python35!PyType_Type.tp_alloc<br>
    <function> * 0x00000000`65025580<br>
    0:000> ln 65025580<br>
    (00000000`65025580)   python35!PyType_GenericAlloc   |<br>
    (00000000`650256a0)   python35!PyType_GenericNew<br>
    Exact matches:<br>
        python35!PyType_GenericAlloc (void)<br></blockquote><div><br></div><div>This makes quite a bit of sense. I completely overlooked the interpreter init routines.</div><div><br></div><div>Thank you both Guido and eryk! </div></div><br></div></div>