It is to improve the experience of passing bytes to a C function that expects a trailing \0. For example syscalls taking filenames. The wrapper must still check for embedded \0 but the bytes don't need to be copied.
On Monday, April 28, 2014, Nikolaus Rath <nikol...@rath.org> wrote: > Hello, > > I was surprised to find the following in bytesobject.c: > > ,---- > | [...] > | As always, an extra byte is allocated for a trailing \0 byte (newsize > | does *not* include that), and a trailing \0 byte is stored. > | */ > | > | int > | _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize) > | { > | [...] > | > `---- > > Does this mean that bytes objects are internally stored with a trailing > \0? Why is that? Isn't that just wasting a byte, because \0 might also > be in the middle of the byte sequence, and the bytes objects stores its > length explicitly anyway? > > > Best, > -Nikolaus > -- > GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F > Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F > > »Time flies like an arrow, fruit flies like a Banana.« > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org <javascript:;> > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/guido%40python.org > -- --Guido van Rossum (on iPad)
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com