Kaydet (Commit) 7a6dbb71 authored tarafından Victor Stinner's avatar Victor Stinner

_csv: use _PyLong_AsInt()

üst af48a917
...@@ -209,23 +209,17 @@ _set_int(const char *name, int *target, PyObject *src, int dflt) ...@@ -209,23 +209,17 @@ _set_int(const char *name, int *target, PyObject *src, int dflt)
if (src == NULL) if (src == NULL)
*target = dflt; *target = dflt;
else { else {
long value; int value;
if (!PyLong_CheckExact(src)) { if (!PyLong_CheckExact(src)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"\"%s\" must be an integer", name); "\"%s\" must be an integer", name);
return -1; return -1;
} }
value = PyLong_AsLong(src); value = _PyLong_AsInt(src);
if (value == -1 && PyErr_Occurred()) if (value == -1 && PyErr_Occurred()) {
return -1;
#if SIZEOF_LONG > SIZEOF_INT
if (value > INT_MAX || value < INT_MIN) {
PyErr_Format(PyExc_ValueError,
"integer out of range for \"%s\"", name);
return -1; return -1;
} }
#endif *target = value;
*target = (int)value;
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment