A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-December/151465.html below:

[Python-Dev] When val=b'', but val == b'' returns False

[Python-Dev] When val=b'', but val == b'' returns False - bytes initializationAntoine Pitrou solipsis at pitrou.net
Wed Dec 27 11:28:41 EST 2017
On Wed, 27 Dec 2017 14:19:16 +0000
Jonathan Underwood <jonathan.underwood at gmail.com> wrote:
> Hello,
> 
> I am not sure if this is expected behaviour, or a bug.
> 
> In a C extension module, if I create and return an empty bytes object like this:
> 
>     val = PyBytes_FromStringAndSize (NULL, 20);
>     Py_SIZE(val) = 0;

I wouldn't call it "expected", but bytes objects are supposed to be
NULL-terminated internally, so your code technically creates an invalid
bytes object.  The NULL-terminated constraint may be relied on by some
code, for example when the string gets passed to a third-party C
function.

Perhaps that should be mentioned in the C API docs.

Regards

Antoine.


More information about the Python-Dev mailing list

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