Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,22 @@ def test_byteswap(self):
b.byteswap()
self.assertEqual(a, b)

def test_byteswap_single_call_result(self):
# A single byteswap() must swap each item's two halves (real,
# imag) independently. test_byteswap above only checks that
# byteswap() twice round-trips to the original, which passes
# even if a single call scrambles multi-item arrays.
a = array.array(self.typecode, self.example)
original = a.tobytes()
a.byteswap()
itemsize = a.itemsize
half = itemsize // 2
expected = bytearray()
for i in range(0, len(original), itemsize):
item = original[i:i + itemsize]
expected += item[half - 1::-1] + item[itemsize - 1:half - 1:-1]
self.assertEqual(a.tobytes(), bytes(expected))


class HalfFloatTest(FPTest, unittest.TestCase):
example = [-42.0, 0, 42, 1e2, -1e4]
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def test_with_extension(ext):
forget(TESTFN)
unlink(source)
unlink(pyc)
rmtree('__pycache__')

sys.path.insert(0, os.curdir)
try:
Expand Down Expand Up @@ -668,6 +669,7 @@ def __del__(self):
import importlib
sys.argv.insert(0, C())
"""))
self.addCleanup(unlink, testfn)
script_helper.assert_python_ok(testfn)

@skip_if_dont_write_bytecode
Expand Down Expand Up @@ -2033,6 +2035,7 @@ def test_unencodable_filename(self):
# encode filenames, especially on Windows
pyname = script_helper.make_script('', TESTFN_UNENCODABLE, 'pass')
self.addCleanup(unlink, pyname)
self.addCleanup(rmtree, '__pycache__')
name = pyname[:-3]
script_helper.assert_python_ok("-c", "mod = __import__(%a)" % name,
__isolated=False)
Expand Down
5 changes: 1 addition & 4 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -2682,11 +2682,8 @@ def test_fma_infinities(self):
@unittest.skipIf(
sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten", "cygwin"))
or (sys.platform == "android" and platform.machine() == "x86_64")
or support.linked_to_musl(), # gh-131032
or (support.linked_to_musl() and support.linked_to_musl() < (1, 2, 6)), # gh-131032
f"this platform doesn't implement IEE 754-2008 properly")
# gh-131032: musl is fixed but the fix is not yet released; when the fixed
# version is known change this to:
# or support.linked_to_musl() < (1, <m>, <p>)
def test_fma_zero_result(self):
nonnegative_finites = [0.0, 1e-300, 2.3, 1e300]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix :meth:`array.array.byteswap` corrupting data for ``'Zd'`` (complex
double) arrays with more than one element: the 16-byte item loop advanced
the buffer pointer by only 8 bytes per iteration, causing items after the
first to be scrambled.
2 changes: 1 addition & 1 deletion Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ array_array_byteswap_impl(arrayobject *self)
break;
case 16:
assert(strcmp(self->ob_descr->typecode, "Zd") == 0);
for (p = self->ob_item, i = Py_SIZE(self); --i >= 0; p += 8) {
for (p = self->ob_item, i = Py_SIZE(self); --i >= 0; p += 16) {
char t0 = p[0];
char t1 = p[1];
char t2 = p[2];
Expand Down
Loading