SV: PyArg_ParseTuple() & Py_DECREF()
Fredrik Lundh
effbot at telia.com
Sat Mar 4 11:03:54 EST 2000
(hey, what's this obsession with "charset=koi8-r"?)
Alex Farber <farber at cpan.org> wrote:
> > no. PyArg_ParseTuple returns borrowed references.
>
> 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.
The C string is null-terminated. The Python
string must not contain embedded null bytes;
if it does, a TypeError exception is raised.
"s#" (string) [char *, int]
This variant on "s" stores into two C variables,
the first one a pointer to a character string,
the second one its length. In this case the
Python string may contain embedded null bytes.
> Where is str stored?
that's up to you...
> Will it be overwritten after calling PyArg_ParseTuple
> (val, "sO", &str2, &obj)?
no. see above.
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list