➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients eric.snow, h.venev
Date 2018-06-13.16:21:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528906899.92.0.947875510639.issue23869@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for bringing this up, Hristo!

"Initialization" (in this context, and hopefully everywhere in the C-API docs) is referring specifically to setting fields on a custom instance, much as you would expect in __init__ (or sometimes even __new__).  In that regard PyType_GenericAlloc does not do any initialization.  Instead, what it does is at a low level which is consistent with allocating a basic object for use in the CPython object machinery:

  * allocate the memory
  * NULL out the allocated memory
  * set initial refcount to 1
  * fill in the fundamental PyObject fields (e.g. type)
  * register with GC

Most of that relates directly to memory management and definitely belongs in PyType_GenericAlloc.  I suppose you could argue that filling in the fundamental PyObject fields could go into PyType_GenericNew.  However, doing so would leave the "allocated" object in an inconsistent state for the object machinery, to be resolved by the type's tp_new implementation.  This could lead to problems for types that have a custom tp_new that does not use PyType_GenericNew.  In that case moving anything from PyType_GenericAlloc to PyType_GenericNew would be a backward-incompatible change (and add complexity to the object creation workflow).  Even though the chance for breakage is small, there would have to be a really strong reason to make such a change.

Consequently, there isn't a whole lot to be done here and I'm closing this issue.  If I've misunderstood then please let us know.  We can re-open the issue then.

FTR, PyType_GenericAlloc is implemented here:

  https://github.com/python/cpython/blob/master/Objects/typeobject.c#L963
History
Date User Action Args
2018-06-13 16:21:39eric.snowsetrecipients: + eric.snow, h.venev
2018-06-13 16:21:39eric.snowsetmessageid: <1528906899.92.0.947875510639.issue23869@psf.upfronthosting.co.za>
2018-06-13 16:21:39eric.snowlinkissue23869 messages
2018-06-13 16:21:39eric.snowcreate