tp_new, tp_alloc, tp_init

M

Michael Hennebry

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 .
 
G

Gregory Ewing

Michael said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top