This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients rhettinger, serhiy.storchaka
Date 2015-03-01.05:39:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1425188386.54.0.539730831229.issue23553@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-03-01 05:39:46serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger
2015-03-01 05:39:46serhiy.storchakasetmessageid: <1425188386.54.0.539730831229.issue23553@psf.upfronthosting.co.za>
2015-03-01 05:39:46serhiy.storchakalinkissue23553 messages
2015-03-01 05:39:45serhiy.storchakacreate