tuple creation in C extensions

Louis M. Pecora pecora at anvil.nrl.navy.mil
Sun Jun 11 09:25:56 EDT 2000


In article <3942B267.C769395 at stud.ntnu.no>, Peter Schneider-Kamp
<petersc at stud.ntnu.no> wrote:

> Peter Schneider-Kamp wrote:
> > 
> > I have to create a tuple (of two integer values) in a
> > C extension. At the moment I use the following (rather
> > ugly in my eyes) construction:
> 
> As an afterthought. Are there any reference counting things I
> have to deal with in this example?

Yes, usually when you _create_ a Python object in C you have to handle
the references or call routines that do that for you. Trouble is, it is
something that is not always clear on how to do it.  I would say you
need to INCREF your tuple after creation, unless you know the routine
that creates it already does that.  If you return the tuple, do
nothing.  If you do not return it, you should DECREF it.  How sure am I
of all this?  Not very.  I'm just learning.  Best to check out all
advice from the experts on this helpful NG and dig up all the examples
you can, especially using the same C-Python routines you do.  Sorry I
can't help more.  Do keep digging. Ref-counting is important.



More information about the Python-list mailing list