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

nascheme@users.sourceforge.net nascheme@users.sourceforge.net
2003年2月04日 12:55:46 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv8360/Python
Modified Files:
	getargs.c 
Log Message:
If a float is passed where a int is expected, issue a DeprecationWarning
instead of raising a TypeError. Closes #660144 (again).
Index: getargs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v
retrieving revision 2.95
retrieving revision 2.96
diff -C2 -d -r2.95 -r2.96
*** getargs.c	24 Jan 2003 22:15:21 -0000	2.95
--- getargs.c	4 Feb 2003 20:55:40 -0000	2.96
***************
*** 388,391 ****
--- 388,404 ----
 #define CONV_UNICODE "(unicode conversion error)"
 
+ /* explicitly check for float arguments when integers are expected. For now
+ * signal a warning. Returns true if an exception was raised. */
+ static int
+ float_argument_error(PyObject *arg)
+ {
+ 	if (PyFloat_Check(arg) &&
+ 	 PyErr_Warn(PyExc_DeprecationWarning,
+ 		 "integer argument expected, got float" ))
+ 		return 1;
+ 	else
+ 		return 0;
+ }
+ 
 /* Convert a non-tuple argument. Return NULL if conversion went OK,
 or a string with a message describing the failure. The message is
***************
*** 410,415 ****
 		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())
--- 423,428 ----
 		char *p = va_arg(*p_va, char *);
 		long ival;
! 		if (float_argument_error(arg))
! 			return NULL;
 		ival = PyInt_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
***************
*** 434,439 ****
 		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())
--- 447,452 ----
 		char *p = va_arg(*p_va, char *);
 		long ival;
! 		if (float_argument_error(arg))
! 			return NULL;
 		ival = PyInt_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
***************
*** 457,462 ****
 		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())
--- 470,475 ----
 		short *p = va_arg(*p_va, short *);
 		long ival;
! 		if (float_argument_error(arg))
! 			return NULL;
 		ival = PyInt_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
***************
*** 481,486 ****
 		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())
--- 494,499 ----
 		unsigned short *p = va_arg(*p_va, unsigned short *);
 		long ival;
! 		if (float_argument_error(arg))
! 			return NULL;
 		ival = PyInt_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
***************
*** 504,509 ****
 		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())
--- 517,522 ----
 		int *p = va_arg(*p_va, int *);
 		long ival;
! 		if (float_argument_error(arg))
! 			return NULL;
 		ival = PyInt_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())
***************
*** 527,532 ****
 		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())
--- 540,545 ----
 		long *p = va_arg(*p_va, long *);
 		long ival;
! 		if (float_argument_error(arg))
! 			return NULL;
 		ival = PyInt_AsLong(arg);
 		if (ival == -1 && PyErr_Occurred())

AltStyle によって変換されたページ (->オリジナル) /