[issue2440] Issues with getargs_n(), PyNumber_Index and PyLong_AsSize_t.

Trent Nelson report at bugs.python.org
Thu Mar 20 23:00:42 CET 2008


New submission from Trent Nelson <tnelson at onresolve.com>:

test_getargs2 fails on Win x64:

test_getargs2 is failing on Windows x64:
test test_getargs2 failed -- Traceback (most recent call last):
  File
"S:\buildbots\python.x64\3.0.nelson-win64\build\lib\test\test_getargs2.py",
line 190, in test_n
    self.failUnlessEqual(99, getargs_n(Long()))
TypeError: 'Long' object cannot be interpreted as an integer

The problem is twofold: case 'n' on Win x64 (where SIZEOF_SIZE_T !=
SIZEOF_LONG) had a broken code path and needed updating.  Also, the
fallback to 'l' for systems where SIZEOF_SIZE_T == SIZEOF_LONG wasn't
correct -- it should still do a PyNumber_Index() check, and then use
PyLong_AsSize_t() to extract the value.

The attached patch corrects the behaviour on 32-bit and 64-bit systems,
including Windows.  However, it has now uncovered another bug in Windows
x64:

>>> from _testcapi import getargs_n
>>> getargs_n(sys.maxsize)
9223372036854775807
>>> getargs_n(-sys.maxsize)
1
>>> getargs_n(-sys.maxsize-1)
0

After a bit of investigation with Martin, the logic in PyLong_AsSize_t()
is incorrect and needs to be reworked to handle negative maximums properly.

----------
components: Interpreter Core
files: getargs_and_abstract.patch
keywords: patch, patch
messages: 64212
nosy: Trent.Nelson, loewis
severity: normal
status: open
title: Issues with getargs_n(), PyNumber_Index and PyLong_AsSize_t.
versions: Python 3.0
Added file: http://bugs.python.org/file9793/getargs_and_abstract.patch

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2440>
__________________________________


More information about the Python-bugs-list mailing list