Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16879

Re: tp_new, tp_alloc, tp_init

From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: tp_new, tp_alloc, tp_init
Date 2011-12-09 10:33 +1300
Message-ID <9kcoopFv41U1@mid.individual.net> (permalink)
References <f0bb1447-07b2-4f78-a1af-c702ff2ca31a@da3g2000vbb.googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

tp_new, tp_alloc, tp_init Michael Hennebry <egg1nog@gmail.com> - 2011-11-30 09:10 -0800
  Re: tp_new, tp_alloc, tp_init Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-12-09 10:33 +1300

csiph-web