mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
This commit is contained in:
parent
0fbab7ff8d
commit
d1a1d1ed80
15 changed files with 134 additions and 54 deletions
|
@ -181,12 +181,23 @@ _set_int(const char *name, int *target, PyObject *src, int dflt)
|
|||
if (src == NULL)
|
||||
*target = dflt;
|
||||
else {
|
||||
if (!PyInt_CheckExact(src)) {
|
||||
long value;
|
||||
if (!PyLong_CheckExact(src)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"\"%s\" must be an integer", name);
|
||||
return -1;
|
||||
}
|
||||
*target = PyLong_AsLong(src);
|
||||
value = PyLong_AsLong(src);
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
*target = (int)value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1385,12 +1396,16 @@ csv_field_size_limit(PyObject *module, PyObject *args)
|
|||
if (!PyArg_UnpackTuple(args, "field_size_limit", 0, 1, &new_limit))
|
||||
return NULL;
|
||||
if (new_limit != NULL) {
|
||||
if (!PyInt_CheckExact(new_limit)) {
|
||||
if (!PyLong_CheckExact(new_limit)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"limit must be an integer");
|
||||
return NULL;
|
||||
}
|
||||
field_limit = PyLong_AsLong(new_limit);
|
||||
if (field_limit == -1 && PyErr_Occurred()) {
|
||||
field_limit = old_limit;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return PyLong_FromLong(old_limit);
|
||||
}
|
||||
|
|
|
@ -196,8 +196,13 @@ PyCursesCheckERR(int code, char *fname)
|
|||
static int
|
||||
PyCurses_ConvertToChtype(PyObject *obj, chtype *ch)
|
||||
{
|
||||
if (PyInt_CheckExact(obj)) {
|
||||
*ch = (chtype) PyLong_AsLong(obj);
|
||||
if (PyLong_CheckExact(obj)) {
|
||||
int overflow;
|
||||
/* XXX should the truncation by the cast also be reported
|
||||
as an error? */
|
||||
*ch = (chtype) PyLong_AsLongAndOverflow(obj, &overflow);
|
||||
if (overflow)
|
||||
return 0;
|
||||
} else if(PyString_Check(obj)
|
||||
&& (PyString_Size(obj) == 1)) {
|
||||
*ch = (chtype) *PyString_AsString(obj);
|
||||
|
|
|
@ -863,14 +863,21 @@ static Tcl_Obj*
|
|||
AsObj(PyObject *value)
|
||||
{
|
||||
Tcl_Obj *result;
|
||||
long longVal;
|
||||
int overflow;
|
||||
|
||||
if (PyString_Check(value))
|
||||
return Tcl_NewStringObj(PyString_AS_STRING(value),
|
||||
PyString_GET_SIZE(value));
|
||||
else if (PyBool_Check(value))
|
||||
return Tcl_NewBooleanObj(PyObject_IsTrue(value));
|
||||
else if (PyInt_CheckExact(value))
|
||||
return Tcl_NewLongObj(PyLong_AS_LONG(value));
|
||||
else if (PyLong_CheckExact(value) &&
|
||||
((longVal = PyLong_AsLongAndOverflow(value, &overflow)),
|
||||
!overflow)) {
|
||||
/* If there is an overflow in the long conversion,
|
||||
fall through to default object handling. */
|
||||
return Tcl_NewLongObj(longVal);
|
||||
}
|
||||
else if (PyFloat_Check(value))
|
||||
return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value));
|
||||
else if (PyTuple_Check(value)) {
|
||||
|
|
|
@ -3827,7 +3827,7 @@ datetime_strptime(PyObject *cls, PyObject *args)
|
|||
Py_DECREF(module);
|
||||
|
||||
if (obj != NULL) {
|
||||
int i, good_timetuple = 1;
|
||||
int i, good_timetuple = 1, overflow;
|
||||
long int ia[6];
|
||||
if (PySequence_Check(obj) && PySequence_Size(obj) >= 6)
|
||||
for (i=0; i < 6; i++) {
|
||||
|
@ -3836,8 +3836,11 @@ datetime_strptime(PyObject *cls, PyObject *args)
|
|||
Py_DECREF(obj);
|
||||
return NULL;
|
||||
}
|
||||
if (PyInt_CheckExact(p))
|
||||
ia[i] = PyLong_AsLong(p);
|
||||
if (PyLong_CheckExact(p)) {
|
||||
ia[i] = PyLong_AsLongAndOverflow(p, &overflow);
|
||||
if (overflow)
|
||||
good_timetuple = 0;
|
||||
}
|
||||
else
|
||||
good_timetuple = 0;
|
||||
Py_DECREF(p);
|
||||
|
|
|
@ -3595,8 +3595,11 @@ socket_getaddrinfo(PyObject *self, PyObject *args)
|
|||
"getaddrinfo() argument 1 must be string or None");
|
||||
return NULL;
|
||||
}
|
||||
if (PyInt_CheckExact(pobj)) {
|
||||
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", PyLong_AsLong(pobj));
|
||||
if (PyLong_CheckExact(pobj)) {
|
||||
long value = PyLong_AsLong(pobj);
|
||||
if (value == -1 && PyErr_Occurred())
|
||||
goto err;
|
||||
PyOS_snprintf(pbuf, sizeof(pbuf), "%ld", value);
|
||||
pptr = pbuf;
|
||||
} else if (PyUnicode_Check(pobj)) {
|
||||
pptr = PyUnicode_AsString(pobj);
|
||||
|
|
|
@ -392,8 +392,8 @@ gettmarg(PyObject *args, struct tm *p)
|
|||
if (y < 1900) {
|
||||
PyObject *accept = PyDict_GetItemString(moddict,
|
||||
"accept2dyear");
|
||||
if (accept == NULL || !PyInt_CheckExact(accept) ||
|
||||
PyLong_AsLong(accept) == 0) {
|
||||
if (accept == NULL || !PyLong_CheckExact(accept) ||
|
||||
!PyObject_IsTrue(accept)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"year >= 1900 required");
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue