mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Change int to Py_ssize_t in several places.
Add (int) casts to silence compiler warnings. Raise Python exceptions for overflows.
This commit is contained in:
parent
8eb8a829c1
commit
725507b52e
11 changed files with 57 additions and 32 deletions
|
@ -216,7 +216,7 @@ static PyObject *
|
|||
reversed_next(reversedobject *ro)
|
||||
{
|
||||
PyObject *item;
|
||||
long index = ro->index;
|
||||
Py_ssize_t index = ro->index;
|
||||
|
||||
if (index >= 0) {
|
||||
item = PySequence_GetItem(ro->seq, index);
|
||||
|
|
|
@ -177,7 +177,7 @@ gen_del(PyObject *self)
|
|||
* never happened.
|
||||
*/
|
||||
{
|
||||
int refcnt = self->ob_refcnt;
|
||||
Py_ssize_t refcnt = self->ob_refcnt;
|
||||
_Py_NewReference(self);
|
||||
self->ob_refcnt = refcnt;
|
||||
}
|
||||
|
|
|
@ -1172,7 +1172,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
|
|||
PyObject **
|
||||
_PyObject_GetDictPtr(PyObject *obj)
|
||||
{
|
||||
long dictoffset;
|
||||
Py_ssize_t dictoffset;
|
||||
PyTypeObject *tp = obj->ob_type;
|
||||
|
||||
if (!(tp->tp_flags & Py_TPFLAGS_HAVE_CLASS))
|
||||
|
@ -1212,7 +1212,7 @@ PyObject_GenericGetAttr(PyObject *obj, PyObject *name)
|
|||
PyObject *descr = NULL;
|
||||
PyObject *res = NULL;
|
||||
descrgetfunc f;
|
||||
long dictoffset;
|
||||
Py_ssize_t dictoffset;
|
||||
PyObject **dictptr;
|
||||
|
||||
if (!PyString_Check(name)){
|
||||
|
|
|
@ -3679,6 +3679,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
|
|||
Py_ssize_t i;
|
||||
int sign; /* 1 if '-', else 0 */
|
||||
int len; /* number of characters */
|
||||
Py_ssize_t llen;
|
||||
int numdigits; /* len == numnondigits + numdigits */
|
||||
int numnondigits = 0;
|
||||
|
||||
|
@ -3707,7 +3708,12 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
|
|||
return NULL;
|
||||
}
|
||||
buf = PyString_AsString(result);
|
||||
len = PyString_Size(result);
|
||||
llen = PyString_Size(result);
|
||||
if (llen > INT_MAX) {
|
||||
PyErr_SetString(PyExc_ValueError, "string too large in _PyString_FormatLong");
|
||||
return NULL;
|
||||
}
|
||||
len = (int)llen;
|
||||
if (buf[len-1] == 'L') {
|
||||
--len;
|
||||
buf[len] = '\0';
|
||||
|
@ -3941,12 +3947,12 @@ PyString_Format(PyObject *format, PyObject *args)
|
|||
PyObject *temp = NULL;
|
||||
char *pbuf;
|
||||
int sign;
|
||||
int len;
|
||||
Py_ssize_t len;
|
||||
char formatbuf[FORMATBUFLEN];
|
||||
/* For format{float,int,char}() */
|
||||
#ifdef Py_USING_UNICODE
|
||||
char *fmt_start = fmt;
|
||||
int argidx_start = argidx;
|
||||
Py_ssize_t argidx_start = argidx;
|
||||
#endif
|
||||
|
||||
fmt++;
|
||||
|
@ -4139,8 +4145,10 @@ PyString_Format(PyObject *format, PyObject *args)
|
|||
if (c == 'i')
|
||||
c = 'd';
|
||||
if (PyLong_Check(v)) {
|
||||
int ilen;
|
||||
temp = _PyString_FormatLong(v, flags,
|
||||
prec, c, &pbuf, &len);
|
||||
prec, c, &pbuf, &ilen);
|
||||
len = ilen;
|
||||
if (!temp)
|
||||
goto error;
|
||||
sign = 1;
|
||||
|
|
|
@ -4244,7 +4244,8 @@ slot_sq_contains(PyObject *self, PyObject *value)
|
|||
}
|
||||
}
|
||||
else if (! PyErr_Occurred()) {
|
||||
result = _PySequence_IterSearch(self, value,
|
||||
/* Possible results: -1 and 1 */
|
||||
result = (int)_PySequence_IterSearch(self, value,
|
||||
PY_ITERSEARCH_CONTAINS);
|
||||
}
|
||||
return result;
|
||||
|
@ -4880,7 +4881,7 @@ slot_tp_del(PyObject *self)
|
|||
* never happened.
|
||||
*/
|
||||
{
|
||||
int refcnt = self->ob_refcnt;
|
||||
Py_ssize_t refcnt = self->ob_refcnt;
|
||||
_Py_NewReference(self);
|
||||
self->ob_refcnt = refcnt;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue