[Python-checkins] python/dist/src/Python getargs.c,2.94,2.95

nascheme@users.sourceforge.net nascheme@users.sourceforge.net
Fri, 24 Jan 2003 14:15:25 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv9306/Python

Modified Files:
	getargs.c 
Log Message:
Raise a TypeError if a float is passed when an integer is specified.
Calling PyInt_AsLong() on a float truncates it which is almost never
the desired behavior.  This closes SF bug #660144.


Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.94
retrieving revision 2.95
diff -C2 -d -r2.94 -r2.95
*** getargs.c	21 Nov 2002 20:23:11 -0000	2.94
--- getargs.c	24 Jan 2003 22:15:21 -0000	2.95
***************
*** 409,413 ****
  	case 'b': { /* unsigned byte -- very short int */
  		char *p = va_arg(*p_va, char *);
! 		long ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<b>", arg, msgbuf, bufsize);
--- 409,416 ----
  	case 'b': { /* unsigned byte -- very short int */
  		char *p = va_arg(*p_va, char *);
! 		long ival;
! 		if (PyFloat_Check(arg))
! 			return converterr("integer", arg, msgbuf, bufsize);
! 		ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<b>", arg, msgbuf, bufsize);
***************
*** 430,434 ****
  		      values allowed */  
  		char *p = va_arg(*p_va, char *);
! 		long ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<b>", arg, msgbuf, bufsize);
--- 433,440 ----
  		      values allowed */  
  		char *p = va_arg(*p_va, char *);
! 		long ival;
! 		if (PyFloat_Check(arg))
! 			return converterr("integer", arg, msgbuf, bufsize);
! 		ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<b>", arg, msgbuf, bufsize);
***************
*** 450,454 ****
  	case 'h': {/* signed short int */
  		short *p = va_arg(*p_va, short *);
! 		long ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<h>", arg, msgbuf, bufsize);
--- 456,463 ----
  	case 'h': {/* signed short int */
  		short *p = va_arg(*p_va, short *);
! 		long ival;
! 		if (PyFloat_Check(arg))
! 			return converterr("integer", arg, msgbuf, bufsize);
! 		ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<h>", arg, msgbuf, bufsize);
***************
*** 471,475 ****
  		       unsigned allowed */ 
  		unsigned short *p = va_arg(*p_va, unsigned short *);
! 		long ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<H>", arg, msgbuf, bufsize);
--- 480,487 ----
  		       unsigned allowed */ 
  		unsigned short *p = va_arg(*p_va, unsigned short *);
! 		long ival;
! 		if (PyFloat_Check(arg))
! 			return converterr("integer", arg, msgbuf, bufsize);
! 		ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<H>", arg, msgbuf, bufsize);
***************
*** 491,495 ****
  	case 'i': {/* signed int */
  		int *p = va_arg(*p_va, int *);
! 		long ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<i>", arg, msgbuf, bufsize);
--- 503,510 ----
  	case 'i': {/* signed int */
  		int *p = va_arg(*p_va, int *);
! 		long ival;
! 		if (PyFloat_Check(arg))
! 			return converterr("integer", arg, msgbuf, bufsize);
! 		ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<i>", arg, msgbuf, bufsize);
***************
*** 511,515 ****
  	case 'l': {/* long int */
  		long *p = va_arg(*p_va, long *);
! 		long ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<l>", arg, msgbuf, bufsize);
--- 526,533 ----
  	case 'l': {/* long int */
  		long *p = va_arg(*p_va, long *);
! 		long ival;
! 		if (PyFloat_Check(arg))
! 			return converterr("integer", arg, msgbuf, bufsize);
! 		ival = PyInt_AsLong(arg);
  		if (ival == -1 && PyErr_Occurred())
  			return converterr("integer<l>", arg, msgbuf, bufsize);