Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3513358

Browse files
committed
Issue 2440: remove the guard around the handling of case 'n' in getargs.c's convertsimple() such that we always treat it as an index type, regardless of whether or not sizeof(size_t) == sizeof(long). Fix the test_args2.Signed_TestCase.test_n() such that it tests for adherence to PEP 357 (don't try and coerce objects that don't have nb_index slots but do have nb_int slots (i.e. floats) into indexes 'just because we can'). Three other commits are related to this one: r62269 and r62279, which were changes to PyNumber_Index (among other things) to check for nb_int slots when we lack nb_index slots -- and r62292, which is when I reverted these changes after various people pointed out that the test was in fact wrong, not the code.
1 parent b9e2304 commit 3513358

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

Lib/test/test_getargs2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def test_n(self):
187187
# n returns 'Py_ssize_t', and does range checking
188188
# (PY_SSIZE_T_MIN ... PY_SSIZE_T_MAX)
189189
self.assertRaises(TypeError, getargs_n, 3.14)
190-
self.failUnlessEqual(99, getargs_n(Long()))
191-
self.failUnlessEqual(99, getargs_n(Int()))
190+
self.assertRaises(TypeError, getargs_n, Long())
191+
self.assertRaises(TypeError, getargs_n, Int())
192192

193193
self.assertRaises(OverflowError, getargs_n, PY_SSIZE_T_MIN-1)
194194
self.failUnlessEqual(PY_SSIZE_T_MIN, getargs_n(PY_SSIZE_T_MIN))

Python/getargs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
663663
}
664664

665665
case 'n': /* Py_ssize_t */
666-
#if SIZEOF_SIZE_T != SIZEOF_LONG
667666
{
668667
PyObject *iobj;
669668
Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *);
@@ -672,14 +671,12 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
672671
return converterr("integer<n>", arg, msgbuf, bufsize);
673672
iobj = PyNumber_Index(arg);
674673
if (iobj != NULL)
675-
ival = PyLong_AsSsize_t(arg);
674+
ival = PyLong_AsSsize_t(iobj);
676675
if (ival == -1 && PyErr_Occurred())
677676
return converterr("integer<n>", arg, msgbuf, bufsize);
678677
*p = ival;
679678
break;
680679
}
681-
#endif
682-
/* Fall through from 'n' to 'l' if Py_ssize_t is int */
683680
case 'l': {/* long int */
684681
long *p = va_arg(*p_va, long *);
685682
long ival;

0 commit comments

Comments
 (0)