[Patches] Re: issues with int/long on 64bit platforms - eg stringobject (PR#306)

M.-A. Lemburg mal@lemburg.com
Mon, 01 May 2000 12:56:23 +0200


This is a multi-part message in MIME format.
--------------0B731F6F3B362F9549B80A95
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Patch Set Contents:
-------------------

Python/getargs.c:

Added silent truncation to 'i' parser marker to enable the use 
of sys.maxint as argument on 64-bit platforms. Values outside
the range INT_MIN - INT_MAX are silently truncated to the
resp. maximum values for int(egers).

The fix is needed to get e.g. string methods with sys.maxint
slicing default values to work on 64-bit platforms.

____________________________________________________________________
Disclaimer:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under copyright,
patent or other rights or interests ("claims").  To the extent that I
have any such claims, I hereby grant to CNRI a nonexclusive,
irrevocable, royalty-free, worldwide license to reproduce, distribute,
perform and/or display publicly, prepare derivative versions, and
otherwise use this contribution as part of the Python software and its
related documentation, or any derivative versions thereof, at no cost
to CNRI or its licensed users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or
not to incorporate this contribution in the Python software and its
related documentation.  I further grant CNRI permission to use my name
and other identifying information provided to CNRI by me for use in
connection with the Python software and its related documentation.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/
--------------0B731F6F3B362F9549B80A95
Content-Type: text/plain; charset=us-ascii;
 name="getargs.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="getargs.patch"

--- CVS-Python/Python/getargs.c	Mon May  1 12:39:42 2000
+++ Python+Unicode/Python/getargs.c	Mon May  1 12:46:16 2000
@@ -38,10 +38,16 @@ PERFORMANCE OF THIS SOFTWARE.
 
 #include "Python.h"
 
 #include <ctype.h>
 
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#else
+#define INT_MAX 2147483647
+#define INT_MIN (-INT_MAX - 1)
+#endif
 
 int PyArg_Parse Py_PROTO((PyObject *, char *, ...));
 int PyArg_ParseTuple Py_PROTO((PyObject *, char *, ...));
 int PyArg_VaParse Py_PROTO((PyObject *, char *, va_list));
 
@@ -491,12 +497,20 @@ convertsimple1(arg, p_format, p_va)
 		{
 			int *p = va_arg(*p_va, int *);
 			long ival = PyInt_AsLong(arg);
 			if (ival == -1 && PyErr_Occurred())
 				return "integer<i>";
-			else
-				*p = ival;
+			/* Silently truncate to INT_MAX/INT_MIN to
+			   make passing sys.maxint to 'i' parser
+			   markers work on 64-bit platforms work just
+			   like on 32-bit platforms. Overflow errors
+			   are not raised. */
+			else if (ival > INT_MAX)
+				ival = INT_MAX;
+			else if (ival < INT_MIN)
+				ival = INT_MIN;
+			*p = ival;
 			break;
 		}
 	
 	case 'l': /* long int */
 		{

--------------0B731F6F3B362F9549B80A95--