C-API question: Memory returned by PyString_AsString
Fredrik Lundh
fredrik at pythonware.com
Fri Jul 19 04:03:36 EDT 2002
Christoph Bennemann wrote:
> functions like PyString_AsString return a pointer to a character
> vector. Is this memory specially allocated when I call this function
> (which implies I have to take care of it in my program) or is this
> merely a pointer to a character vector stored by the Python
> interpreter (implying that I should not free the memory). I assume
> that the later is correct, but would like to have a definitive answer.
http://www.python.org/doc/current/api/stringObjects.html
char* PyString_AsString(PyObject *string)
Returns a null-terminated representation of the contents
of string. The pointer refers to the internal buffer of string,
not a copy. The data must not be modified in any way,
unless the string was just created using
PyString_FromStringAndSize(NULL, size).
It must not be deallocated.
</F>
More information about the Python-list
mailing list