py/obj.h: Fix mp_seq_replace_slice_no_grow to use memmove not memcpy.

Because the argument arrays may overlap, as show by the new tests in this
commit.

Also remove the debugging comments for these macros, add a new comment
about overlapping regions, and separate the macros by blank lines to make
them easier to read.

Fixes issue #6244.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2020-07-16 23:23:42 +10:00
parent 895b1dbdda
commit a853fff838
2 changed files with 28 additions and 4 deletions

View File

@@ -61,3 +61,27 @@ try:
memoryview(array.array('i'))[0:2] = b'1234'
except ValueError:
print('ValueError')
# test shift left of bytearray
b = bytearray(range(10))
mv = memoryview(b)
mv[1:] = mv[:-1]
print(b)
# test shift right of bytearray
b = bytearray(range(10))
mv = memoryview(b)
mv[:-1] = mv[1:]
print(b)
# test shift left of array
a = array.array('I', range(10))
mv = memoryview(a)
mv[1:] = mv[:-1]
print(a)
# test shift right of array
a = array.array('I', range(10))
mv = memoryview(a)
mv[:-1] = mv[1:]
print(a)