SV: PyArg_ParseTuple() & Py_DECREF()

Alex Farber farber at cpan.org
Sat Mar 4 13:01:08 EST 2000


Hi,

Fredrik Lundh wrote:
> (hey, what's this obsession with "charset=koi8-r"?)

I am reading Russian newsgroups 
and am too lazy to switch Netscape.

> Alex Farber <farber at cpan.org> wrote:
> > Do you have to call free(str) after
> > PyArg_ParseTuple (val, "sO", &str, &obj)?
> 
> the fine manual has the answer:
> 
>     "s" (string) [char *]
> 
>     Convert a Python string to a C pointer to a
>     character string. You must not provide storage
>     for the string itself; a pointer to an existing
>     string is stored into the character pointer
>     variable whose address you pass.
> 
> > Will it be overwritten after calling PyArg_ParseTuple
> > (val, "sO", &str2, &obj)?
> 
> no.  see above.

Thanks for your answer, but I still don't understand: 
if Python reserves some memory via malloc() for that string 
and assigns it to the pointer str, who will free that memory?
Py__Finalize()? And if Python does not allocate any memory
and uses some static storage, why won't it get overwritten
by subsequent calls of PyArg_ParseTuple()?

Best regards
Alex



More information about the Python-list mailing list