classification
Title: [easy C] array.array.index() method downcasts Py_ssize_t to long
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, WildCard65, miss-islington, paul.moore, steve.dower, tim.golden, vstinner, zach.ware
Priority: normal Keywords: easy (C), newcomer friendly, patch

Created on 2020-06-23 00:44 by WildCard65, last changed 2020-06-23 14:37 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
test_output.log WildCard65, 2020-06-23 00:44 Log of tests that were ran at time of upload.
Pull Requests
URL Status Linked Edit
PR 21071 merged WildCard65, 2020-06-23 11:59
PR 21076 merged miss-islington, 2020-06-23 13:21
PR 21077 merged miss-islington, 2020-06-23 13:21
Messages (9)
msg372135 - (view) Author: William Pickard (WildCard65) * Date: 2020-06-23 00:44
Here's the verbose stack trace of the failing test:

======================================================================
FAIL: test_index (test.test_array.LargeArrayTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "L:\GIT\cpython\lib\test\support\__init__.py", line 837, in wrapper
    return f(self, maxsize)
  File "L:\GIT\cpython\lib\test\test_array.py", line 1460, in test_index
    self.assertEqual(example.index(11), size+3)
AssertionError: -2147483645 != 2147483651
msg372140 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2020-06-23 05:16
This looks like an overflow failure in a bigmem test (though the given limit 24Gb should accommodate that?). Do bigmem tests work on Windows?

William, you've made some sort of modifications to the versioned files, what are those?
msg372153 - (view) Author: William Pickard (WildCard65) * Date: 2020-06-23 10:42
The only modification I made was to "rt.bat" to have the value of '-u' work properly.
msg372155 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-23 10:47
It's Python 3.10 on Windows built in 64-bit with Visual Studio.

Extract of test_output.log:

L:\GIT\cpython\PCbuild>"L:\GIT\cpython\PCbuild\amd64\python_d.exe"  -u -Wd -E -bb -m test -u all,-curses -v -M 24Gb --header

== CPython 3.10.0a0 (heads/master-dirty:c96d00e88e, Jun 22 2020, 19:15:48) [MSC v.1926 64 bit (AMD64)]
== Windows-10-10.0.19041-SP0 little-endian
== cwd: L:\GIT\cpython\build\test_python_20756
== CPU count: 8
== encodings: locale=cp1252, FS=utf-8
(...)
test_index (test.test_array.LargeArrayTest) ... 
 ... expected peak memory use: 4.2G
FAIL
(...)
======================================================================
FAIL: test_index (test.test_array.LargeArrayTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "L:\GIT\cpython\lib\test\support\__init__.py", line 837, in wrapper
    return f(self, maxsize)
  File "L:\GIT\cpython\lib\test\test_array.py", line 1460, in test_index
    self.assertEqual(example.index(11), size+3)
AssertionError: -2147483645 != 2147483651
msg372156 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-23 10:47
That's a bug in array_array_index() which downcasts "Py_ssize_t i" to long:

static PyObject *
array_array_index(arrayobject *self, PyObject *v)
/*[clinic end generated code: output=d48498d325602167 input=cf619898c6649d08]*/
{
    Py_ssize_t i;

    for (i = 0; i < Py_SIZE(self); i++) {
        PyObject *selfi;
        int cmp;

        selfi = getarrayitem((PyObject *)self, i);
        if (selfi == NULL)
            return NULL;
        cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
        Py_DECREF(selfi);
        if (cmp > 0) {
            return PyLong_FromLong((long)i); // <===== HERE ===
        }
        else if (cmp < 0)
            return NULL;
    }
    PyErr_SetString(PyExc_ValueError, "array.index(x): x not in array");
    return NULL;
}
msg372164 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-23 13:21
New changeset 1d3dad5f96ed445b958ec53dfa0d46812f2162d9 by WildCard65 in branch 'master':
bpo-41085: Fix array.array.index() on 64-bit Windows (GH-21071)
https://github.com/python/cpython/commit/1d3dad5f96ed445b958ec53dfa0d46812f2162d9
msg372166 - (view) Author: miss-islington (miss-islington) Date: 2020-06-23 13:40
New changeset c6e24e7420a03a1751004e255a6f6c14265b9ea1 by Miss Islington (bot) in branch '3.8':
bpo-41085: Fix array.array.index() on 64-bit Windows (GH-21071)
https://github.com/python/cpython/commit/c6e24e7420a03a1751004e255a6f6c14265b9ea1
msg372167 - (view) Author: miss-islington (miss-islington) Date: 2020-06-23 13:41
New changeset 92f8b480bab408be09bc1631cf2e0e5a4641b731 by Miss Islington (bot) in branch '3.9':
bpo-41085: Fix array.array.index() on 64-bit Windows (GH-21071)
https://github.com/python/cpython/commit/92f8b480bab408be09bc1631cf2e0e5a4641b731
msg372175 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-23 14:37
Thanks William Pickard for the bug report and the fix!
History
Date User Action Args
2020-06-23 14:37:17vstinnersetmessages: + msg372175
components: + Library (Lib), - Tests, Windows
versions: + Python 3.8, Python 3.9
2020-06-23 13:52:54WildCard65setstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-06-23 13:41:31miss-islingtonsetmessages: + msg372167
2020-06-23 13:40:55miss-islingtonsetmessages: + msg372166
2020-06-23 13:21:51miss-islingtonsetpull_requests: + pull_request20245
2020-06-23 13:21:42miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request20244
2020-06-23 13:21:20vstinnersetmessages: + msg372164
2020-06-23 11:59:05WildCard65setkeywords: + patch
stage: patch review
pull_requests: + pull_request20240
2020-06-23 10:48:20vstinnersettitle: [easy C] Array regression test fails -> [easy C] array.array.index() method downcasts Py_ssize_t to long
2020-06-23 10:47:55vstinnersetkeywords: + newcomer friendly
2020-06-23 10:47:49vstinnersetkeywords: + easy (C)
title: Array regression test fails -> [easy C] Array regression test fails
2020-06-23 10:47:37vstinnersetmessages: + msg372156
2020-06-23 10:47:08vstinnersetnosy: + vstinner
messages: + msg372155
2020-06-23 10:42:42WildCard65setmessages: + msg372153
2020-06-23 05:16:04SilentGhostsetnosy: + paul.moore, tim.golden, SilentGhost, zach.ware, steve.dower
messages: + msg372140
components: + Windows
2020-06-23 00:44:44WildCard65create