Python speed and `pcre'

Fredrik Lundh fredrik at pythonware.com
Mon Sep 6 10:40:00 EDT 1999


Aahz Maruch <aahz at netcom.com> wrote:
> >The design issues are more complicated than that, alas.  Here's one you
> >weren't thinking of <wink>:  for easy chatting with C, under the covers a
> >Python string is always terminated with a null byte.  You can't see that
> >from Python code (it's not counted in the string length, and you can't index
> >to it), but your C code can rely on it.
> 
> Hmmm....  From what I've seen, Python strings work perfectly well with
> null bytes in the middle.  Are there any circumstances under which that
> does not hold true?

from Include/stringobject.h:

    Type PyStringObject represents a character string.  An extra zero
    byte is reserved at the end to ensure it is zero-terminated, but a
    size is present so strings with null bytes in them can be represented.

in other words, any Python string can be passed directly to any
C function that expects a null terminated string, without having
to copy it to a separate buffer.

</F>





More information about the Python-list mailing list