Commit 4b247264 authored by Fred Drake's avatar Fred Drake

Clarified the error cases and Unicode handling of PyString_AsString(),

PyString_AsStringAndSize(), and PyString_AS_STRING().
Closes SF bug #606463.
parent 4c486bc0
...@@ -533,36 +533,45 @@ parameter and are called with a non-string parameter. ...@@ -533,36 +533,45 @@ parameter and are called with a non-string parameter.
\end{cfuncdesc} \end{cfuncdesc}
\begin{cfuncdesc}{char*}{PyString_AsString}{PyObject *string} \begin{cfuncdesc}{char*}{PyString_AsString}{PyObject *string}
Returns a null-terminated representation of the contents of Returns a NUL-terminated representation of the contents of
\var{string}. The pointer refers to the internal buffer of \var{string}. The pointer refers to the internal buffer of
\var{string}, not a copy. The data must not be modified in any way, \var{string}, not a copy. The data must not be modified in any way,
unless the string was just created using unless the string was just created using
\code{PyString_FromStringAndSize(NULL, \var{size})}. \code{PyString_FromStringAndSize(NULL, \var{size})}.
It must not be deallocated. It must not be deallocated. If \var{string} is a Unicode object,
this function computes the default encoding of \var{string} and
operates on that. If \var{string} is not a string object at all,
\cfunction{PyString_AsString()} returns \NULL{} and raises
\exception{TypeError}.
\end{cfuncdesc} \end{cfuncdesc}
\begin{cfuncdesc}{char*}{PyString_AS_STRING}{PyObject *string} \begin{cfuncdesc}{char*}{PyString_AS_STRING}{PyObject *string}
Macro form of \cfunction{PyString_AsString()} but without error Macro form of \cfunction{PyString_AsString()} but without error
checking. checking. Only string objects are supported; no Unicode objects
should be passed.
\end{cfuncdesc} \end{cfuncdesc}
\begin{cfuncdesc}{int}{PyString_AsStringAndSize}{PyObject *obj, \begin{cfuncdesc}{int}{PyString_AsStringAndSize}{PyObject *obj,
char **buffer, char **buffer,
int *length} int *length}
Returns a null-terminated representation of the contents of the Returns a NUL-terminated representation of the contents of the
object \var{obj} through the output variables \var{buffer} and object \var{obj} through the output variables \var{buffer} and
\var{length}. \var{length}.
The function accepts both string and Unicode objects as input. For The function accepts both string and Unicode objects as input. For
Unicode objects it returns the default encoded version of the Unicode objects it returns the default encoded version of the
object. If \var{length} is set to \NULL, the resulting buffer may object. If \var{length} is \NULL, the resulting buffer may not
not contain null characters; if it does, the function returns -1 and contain NUL characters; if it does, the function returns \code{-1}
a \exception{TypeError} is raised. and a \exception{TypeError} is raised.
The buffer refers to an internal string buffer of \var{obj}, not a The buffer refers to an internal string buffer of \var{obj}, not a
copy. The data must not be modified in any way, unless the string copy. The data must not be modified in any way, unless the string
was just created using \code{PyString_FromStringAndSize(NULL, was just created using \code{PyString_FromStringAndSize(NULL,
\var{size})}. It must not be deallocated. \var{size})}. It must not be deallocated. If \var{string} is a
Unicode object, this function computes the default encoding of
\var{string} and operates on that. If \var{string} is not a string
object at all, \cfunction{PyString_AsString()} returns \NULL{} and
raises \exception{TypeError}.
\end{cfuncdesc} \end{cfuncdesc}
\begin{cfuncdesc}{void}{PyString_Concat}{PyObject **string, \begin{cfuncdesc}{void}{PyString_Concat}{PyObject **string,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment