diff Python/getargs.c @ 46389:7c99cedc3e54

Issue 2440: fix the handling of %n in Python/getargs.c's convertsimple(), extend Objects/abstract.c's PyNumber_Index() to accept PyObjects that have nb_int slots, and update test_getargs2 to test that an exception is thrown when __int__() returns a non-int object.
author Trent Nelson <trent.nelson@snakebite.org>
date Thu, 10 Apr 2008 16:25:37 +0000
parents 72dc16e80179
children 3653fbdd4483
line wrap: on
line diff
--- a/Python/getargs.c	Thu Apr 10 03:06:53 2008 +0000
+++ b/Python/getargs.c	Thu Apr 10 16:25:37 2008 +0000
@@ -663,7 +663,6 @@
 	}
 
 	case 'n': /* Py_ssize_t */
-#if SIZEOF_SIZE_T != SIZEOF_LONG
 	{
 		PyObject *iobj;
 		Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *);
@@ -672,14 +671,13 @@
 			return converterr("integer<n>", arg, msgbuf, bufsize);
 		iobj = PyNumber_Index(arg);
 		if (iobj != NULL)
-			ival = PyLong_AsSsize_t(arg);
+			ival = PyLong_AsSsize_t(iobj);
 		if (ival == -1 && PyErr_Occurred())
 			return converterr("integer<n>", arg, msgbuf, bufsize);
 		*p = ival;
 		break;
 	}
-#endif
-	/* Fall through from 'n' to 'l' if Py_ssize_t is int */
+
 	case 'l': {/* long int */
 		long *p = va_arg(*p_va, long *);
 		long ival;