Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tp_new, tp_alloc, tp_init

34 views
Skip to first unread message

Michael Hennebry

unread,
Nov 30, 2011, 12:10:09 PM11/30/11
to
I've been reading about writing extension types in C and am rather
fuzzy about the relationship between tp_new, tp_alloc and tp_init.
Most especially, why tp_new? It seems to me that tp_alloc and tp_init
would be sufficient.

Most of my reading has been in the Noddy and Shoddy portions of
docs.python.,org .

Gregory Ewing

unread,
Dec 8, 2011, 4:33:10 PM12/8/11
to
Michael Hennebry wrote:
> I've been reading about writing extension types in C and am rather
> fuzzy about the relationship between tp_new, tp_alloc and tp_init.
> Most especially, why tp_new? It seems to me that tp_alloc and tp_init
> would be sufficient.

tp_new and tp_init correspond to the Python methods
__new__ and __init__, and they're separated for the
same reasons they are in Python.

tp_alloc is separate because it allows a type to
use a custom memory allocator without disturbing the
rest of the initialisation mechanism.

--
Greg
0 new messages