C-API question: Memory returned by PyString_AsString

Brian Quinlan brian at sweetapp.com
Fri Jul 19 04:01:09 EDT 2002


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

According to the docs (which you should read :-):

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. It must not be de-allocated.

Cheers,
Brian






More information about the Python-list mailing list