Showing content from http://mail.python.org/pipermail/python-dev/attachments/20140428/cb255b49/attachment-0001.html below:
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.<br>
<br>On Monday, April 28, 2014, Nikolaus Rath <<a href="mailto:Nikolaus@rath.org">Nikolaus@rath.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I was surprised to find the following in bytesobject.c:<br>
<br>
,----<br>
| [...]<br>
| Â Â As always, an extra byte is allocated for a trailing \0 byte (newsize<br>
| Â Â does *not* include that), and a trailing \0 byte is stored.<br>
| */<br>
|<br>
| int<br>
| _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)<br>
| {<br>
| [...]<br>
|<br>
`----<br>
<br>
Does this mean that bytes objects are internally stored with a trailing<br>
\0? Why is that? Isn't that just wasting a byte, because \0 might also<br>
be in the middle of the byte sequence, and the bytes objects stores its<br>
length explicitly anyway?<br>
<br>
<br>
Best,<br>
-Nikolaus<br>
--<br>
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F<br>
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F<br>
<br>
       »Time flies like an arrow, fruit flies like a Banana.«<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'Python-Dev@python.org')">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
</blockquote><br><br>-- <br>--Guido van Rossum (on iPad)<br>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4