Index: Python/getargs.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v retrieving revision 2.95 diff -u -r2.95 getargs.c --- Python/getargs.c 24 Jan 2003 22:15:21 -0000 2.95 +++ Python/getargs.c 27 Jan 2003 05:50:02 -0000 @@ -387,6 +387,19 @@ #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 formatted as "must be , not ". @@ -409,8 +422,8 @@ 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); + if (float_argument_error(arg)) + return NULL; ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return converterr("integer", arg, msgbuf, bufsize); @@ -433,8 +446,8 @@ values allowed */ char *p = va_arg(*p_va, char *); long ival; - if (PyFloat_Check(arg)) - return converterr("integer", arg, msgbuf, bufsize); + if (float_argument_error(arg)) + return NULL; ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return converterr("integer", arg, msgbuf, bufsize); @@ -456,8 +469,8 @@ case 'h': {/* signed short int */ short *p = va_arg(*p_va, short *); long ival; - if (PyFloat_Check(arg)) - return converterr("integer", arg, msgbuf, bufsize); + if (float_argument_error(arg)) + return NULL; ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return converterr("integer", arg, msgbuf, bufsize); @@ -480,8 +493,8 @@ unsigned allowed */ unsigned short *p = va_arg(*p_va, unsigned short *); long ival; - if (PyFloat_Check(arg)) - return converterr("integer", arg, msgbuf, bufsize); + if (float_argument_error(arg)) + return NULL; ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return converterr("integer", arg, msgbuf, bufsize); @@ -503,8 +516,8 @@ case 'i': {/* signed int */ int *p = va_arg(*p_va, int *); long ival; - if (PyFloat_Check(arg)) - return converterr("integer", arg, msgbuf, bufsize); + if (float_argument_error(arg)) + return NULL; ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return converterr("integer", arg, msgbuf, bufsize); @@ -526,8 +539,8 @@ case 'l': {/* long int */ long *p = va_arg(*p_va, long *); long ival; - if (PyFloat_Check(arg)) - return converterr("integer", arg, msgbuf, bufsize); + if (float_argument_error(arg)) + return NULL; ival = PyInt_AsLong(arg); if (ival == -1 && PyErr_Occurred()) return converterr("integer", arg, msgbuf, bufsize);