[Python-Dev] When does `PyType_Type.tp_alloc get assigned to PyType_GenericAlloc ? (original) (raw)
Randy Eels randyeels at gmail.com
Wed Feb 17 17:24:02 EST 2016
- Previous message (by thread): [Python-Dev] When does `PyType_Type.tp_alloc get assigned to PyType_GenericAlloc ?
- Next message (by thread): [Python-Dev] Windows: Remove support of bytes filenames in the os module?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Feb 7, 2016 at 8:45 PM, Guido van Rossum <guido at python.org> wrote:
I think it's probably line 2649 in typeobject.c, in typenew():
type->tpalloc = PyTypeGenericAlloc;
I pondered it but it doesn't seem to be that. Isn't type_new
called
after 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.
On Sun, Feb 7, 2016 at 9:27 PM, eryk sun <eryksun at gmail.com> wrote:
On Sun, Feb 7, 2016 at 7:58 AM, Randy Eels <randyeels at gmail.com> wrote: > > 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?PyInitializeExPrivate in Python/pylifecycle.c calls PyReadyTypes in Objects/object.c. This calls PyTypeReady(&PyTypeType) in Objects/typeobject.c, which assigns type->tpbase = &PyBaseObjectType and then calls inheritslots. This executes COPYSLOT(tpalloc), which assigns PyTypeType.tpalloc = PyBaseObjectType.tpalloc, which is statically assigned as PyTypeGenericAlloc. Debug trace on Windows: 0:000> bp python35!PyTypeReady 0:000> g Breakpoint 0 hit python35!PyTypeReady: 00000000
6502d160 4053 push rbx_ _0:000> ?? ((PyTypeObject *)@rcx)->tpname_ _char * 0x00000000
650e4044 "object" 0:000> g Breakpoint 0 hit python35!PyTypeReady: 000000006502d160 4053 push rbx_ _0:000> ?? ((PyTypeObject *)@rcx)->tpname_ _char * 0x00000000
651d8e5c "type" 0:000> bp python35!inheritslots 0:000> g Breakpoint 1 hit python35!inheritslots: 000000006502c440 48895c2408 mov qword ptr [rsp+8],rbx_ _ss:00000000
0028f960={ python35!PyTypeType (000000006527cba0)}_ _At entry to inheritslots, PyTypeType.tpalloc is NULL:_ _0:000> ?? python35!PyTypeType.tpalloc_ _<function> * 0x00000000
00000000 0:000> pt python35!inheritslots+0xd17: 000000006502d157 c3 ret_ _At exit it's set to PyTypeGenericAlloc:_ _0:000> ?? python35!PyTypeType.tpalloc_ _<function> * 0x00000000
65025580 0:000> ln 65025580 (0000000065025580) python35!PyTypeGenericAlloc |_ _(00000000
650256a0) python35!PyTypeGenericNew Exact matches: python35!PyTypeGenericAlloc (void)
This makes quite a bit of sense. I completely overlooked the interpreter init routines.
Thank you both Guido and eryk! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160217/01f5956a/attachment.html>
- Previous message (by thread): [Python-Dev] When does `PyType_Type.tp_alloc get assigned to PyType_GenericAlloc ?
- Next message (by thread): [Python-Dev] Windows: Remove support of bytes filenames in the os module?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]