]> granicus.if.org Git - python/commit
Armin asked for a list_ass_slice review in his checkin, so here's the
authorTim Peters <tim.peters@gmail.com>
Sat, 31 Jul 2004 02:24:20 +0000 (02:24 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 31 Jul 2004 02:24:20 +0000 (02:24 +0000)
commit8d9eb10c299cfaf2f4f8c887ead55da0d24d5050
tree5bd69e56069e842216b75e66819adfe70ad56077
parentbcc95cb7cb8fc26923a089b8606fb46b331bd825
Armin asked for a list_ass_slice review in his checkin, so here's the
result.

list_resize():  Document the intent.  Code is increasingly relying on
subtle aspects of its behavior, and they deserve to be spelled out.

list_ass_slice():  A bit more simplification, by giving it a common
error exit and initializing more values.

Be clearer in comments about what "size" means (# of elements?  # of
bytes?).

While the number of elements in a list slice must fit in an int, there's
no guarantee that the number of bytes occupied by the slice will.  That
malloc() and memmove() take size_t arguments is a hint about that <wink>.
So changed to use size_t where appropriate.

ihigh - ilow should always be >= 0, but we never asserted that.  We do
now.

The loop decref'ing the recycled slice had a subtle insecurity:  C doesn't
guarantee that a pointer one slot *before* an array will compare "less
than" to a pointer within the array (it does guarantee that a pointer
one beyond the end of the array compares as expected).  This was actually
an issue in KSR's C implementation, so isn't purely theoretical.  Python
probably has other "go backwards" loops with a similar glitch.
list_clear() is OK (it marches an integer backwards, not a pointer).
Objects/listobject.c