Some questions about C extensions

Louis M. Pecora pecora at anvil.nrl.navy.mil
Thu Jun 8 07:48:31 EDT 2000


In article <etdu2f69rhz.fsf at w20-575-109.mit.edu>, Alex
<cut_me_out at hotmail.com> wrote:

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

I will try these out:

ParseTuple just sets pointers to data already allocated in Python and
hence handled automatically there.

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

Hmmm...not sure about that one.  Sorry I can't be more helpful.



More information about the Python-list mailing list