Serhiy Storchaka added the comment:
Yes, this is a technique commonly used in STL implementations. This is why
sizes and indices in STL are unsigned.
But in CPython implementation sizes are signed (Py_ssize_t). The problem with
using this optimization (rather low-level than high-level) is that we need to
know unsigned version of the type of compared values.
> - if (i < 0 || i >= Py_SIZE(a)) {
> + if ((unsigned)i >= (unsigned)(Py_SIZE(a))) {
Here is a bug. The type of i and Py_SIZE(a) is Py_ssize_t, so when casted to
unsigned int, highest bits are lost. The correct casting type is size_t.
In changeset 5942fd9ab335 you introduced a bug.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue23553>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com