Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b24726

Browse files
committed
Clarified the error cases and Unicode handling of PyString_AsString(),
PyString_AsStringAndSize(), and PyString_AS_STRING(). Closes SF bug #606463.
1 parent 4c486bc commit 4b24726

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

Doc/api/concrete.tex

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,36 +533,45 @@ \subsection{String Objects \label{stringObjects}}
533533
\end{cfuncdesc}
534534

535535
\begin{cfuncdesc}{char*}{PyString_AsString}{PyObject *string}
536-
Returns a null-terminated representation of the contents of
536+
Returns a NUL-terminated representation of the contents of
537537
\var{string}. The pointer refers to the internal buffer of
538538
\var{string}, not a copy. The data must not be modified in any way,
539539
unless the string was just created using
540540
\code{PyString_FromStringAndSize(NULL, \var{size})}.
541-
It must not be deallocated.
541+
It must not be deallocated. If \var{string} is a Unicode object,
542+
this function computes the default encoding of \var{string} and
543+
operates on that. If \var{string} is not a string object at all,
544+
\cfunction{PyString_AsString()} returns \NULL{} and raises
545+
\exception{TypeError}.
542546
\end{cfuncdesc}
543547

544548
\begin{cfuncdesc}{char*}{PyString_AS_STRING}{PyObject *string}
545549
Macro form of \cfunction{PyString_AsString()} but without error
546-
checking.
550+
checking. Only string objects are supported; no Unicode objects
551+
should be passed.
547552
\end{cfuncdesc}
548553

549554
\begin{cfuncdesc}{int}{PyString_AsStringAndSize}{PyObject *obj,
550555
char **buffer,
551556
int *length}
552-
Returns a null-terminated representation of the contents of the
557+
Returns a NUL-terminated representation of the contents of the
553558
object \var{obj} through the output variables \var{buffer} and
554559
\var{length}.
555560

556561
The function accepts both string and Unicode objects as input. For
557562
Unicode objects it returns the default encoded version of the
558-
object. If \var{length} is set to \NULL, the resulting buffer may
559-
not contain null characters; if it does, the function returns -1 and
560-
a \exception{TypeError} is raised.
563+
object. If \var{length} is \NULL, the resulting buffer may not
564+
contain NUL characters; if it does, the function returns \code{-1}
565+
and a \exception{TypeError} is raised.
561566

562567
The buffer refers to an internal string buffer of \var{obj}, not a
563568
copy. The data must not be modified in any way, unless the string
564569
was just created using \code{PyString_FromStringAndSize(NULL,
565-
\var{size})}. It must not be deallocated.
570+
\var{size})}. It must not be deallocated. If \var{string} is a
571+
Unicode object, this function computes the default encoding of
572+
\var{string} and operates on that. If \var{string} is not a string
573+
object at all, \cfunction{PyString_AsString()} returns \NULL{} and
574+
raises \exception{TypeError}.
566575
\end{cfuncdesc}
567576

568577
\begin{cfuncdesc}{void}{PyString_Concat}{PyObject **string,

0 commit comments

Comments
 (0)