Some questions about C extensions

Alex cut_me_out at hotmail.com
Tue Jun 6 22:03:52 EDT 2000


Hi.  I'm trying to write some C extensions, and have run across a couple
of mysterious things.  I was wondering whether anyone could explain
them:

-- Deallocation of memory for strings returned by python functions:
   Do I have to do it, or is it somehow taken care of?  If I have
   something like 

      if (!PyArg_ParseTuple (args, "s", &sequence)) {
           return NULL;}

   do I have to do a free (sequence); at some point?  I would have
   thought so, but it seems to be giving me a Seg fault.

-- Reference counts for elements of brand new tuples.  Why do I have to
   do a Py_INCREF on an object before I assign it to a new tuple with
   PyTuple_SetItem?  Since it seems as though you have to do a Py_INCREF
   every time anyway, is there a function like PyTuple_SetItem that will
   do it for you?  The comment in the C API manual about this is very
   cryptic, BTW.

Alex.



More information about the Python-list mailing list