mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Change more ints to Py_ssize_t.
This commit is contained in:
parent
80d2e591d5
commit
412fb67368
1 changed files with 39 additions and 40 deletions
|
@ -154,8 +154,7 @@ int unicode_resize(register PyUnicodeObject *unicode,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
unicode->str[length] = 0;
|
unicode->str[length] = 0;
|
||||||
assert(length < INT_MAX);
|
unicode->length = length;
|
||||||
unicode->length = (int)length;
|
|
||||||
|
|
||||||
reset:
|
reset:
|
||||||
/* Reset the object caches */
|
/* Reset the object caches */
|
||||||
|
@ -368,7 +367,7 @@ PyObject *PyUnicode_FromWideChar(register const wchar_t *w,
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
register Py_UNICODE *u;
|
register Py_UNICODE *u;
|
||||||
register int i;
|
register Py_ssize_t i;
|
||||||
u = PyUnicode_AS_UNICODE(unicode);
|
u = PyUnicode_AS_UNICODE(unicode);
|
||||||
for (i = size; i > 0; i--)
|
for (i = size; i > 0; i--)
|
||||||
*u++ = *w++;
|
*u++ = *w++;
|
||||||
|
@ -396,7 +395,7 @@ Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode,
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
register Py_UNICODE *u;
|
register Py_UNICODE *u;
|
||||||
register int i;
|
register Py_ssize_t i;
|
||||||
u = PyUnicode_AS_UNICODE(unicode);
|
u = PyUnicode_AS_UNICODE(unicode);
|
||||||
for (i = size; i > 0; i--)
|
for (i = size; i > 0; i--)
|
||||||
*w++ = *u++;
|
*w++ = *u++;
|
||||||
|
@ -1358,7 +1357,7 @@ PyUnicode_EncodeUTF8(const Py_UNICODE *s,
|
||||||
PyObject *v; /* result string object */
|
PyObject *v; /* result string object */
|
||||||
char *p; /* next free byte in output buffer */
|
char *p; /* next free byte in output buffer */
|
||||||
Py_ssize_t nallocated; /* number of result bytes allocated */
|
Py_ssize_t nallocated; /* number of result bytes allocated */
|
||||||
int nneeded; /* number of result bytes needed */
|
Py_ssize_t nneeded; /* number of result bytes needed */
|
||||||
char stackbuf[MAX_SHORT_UNICHARS * 4];
|
char stackbuf[MAX_SHORT_UNICHARS * 4];
|
||||||
|
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
@ -1427,13 +1426,13 @@ encodeUCS4:
|
||||||
|
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
/* This was stack allocated. */
|
/* This was stack allocated. */
|
||||||
nneeded = Py_SAFE_DOWNCAST(p - stackbuf, long, int);
|
nneeded = p - stackbuf;
|
||||||
assert(nneeded <= nallocated);
|
assert(nneeded <= nallocated);
|
||||||
v = PyString_FromStringAndSize(stackbuf, nneeded);
|
v = PyString_FromStringAndSize(stackbuf, nneeded);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Cut back to size actually needed. */
|
/* Cut back to size actually needed. */
|
||||||
nneeded = Py_SAFE_DOWNCAST(p - PyString_AS_STRING(v), long, int);
|
nneeded = p - PyString_AS_STRING(v);
|
||||||
assert(nneeded <= nallocated);
|
assert(nneeded <= nallocated);
|
||||||
_PyString_Resize(&v, nneeded);
|
_PyString_Resize(&v, nneeded);
|
||||||
}
|
}
|
||||||
|
@ -1934,7 +1933,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
|
||||||
nextByte:
|
nextByte:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (_PyUnicode_Resize(&v, (int)(p - PyUnicode_AS_UNICODE(v))) < 0)
|
if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
|
||||||
goto onError;
|
goto onError;
|
||||||
Py_XDECREF(errorHandler);
|
Py_XDECREF(errorHandler);
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
|
@ -2003,7 +2002,7 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
|
||||||
#ifdef Py_UNICODE_WIDE
|
#ifdef Py_UNICODE_WIDE
|
||||||
/* Map 21-bit characters to '\U00xxxxxx' */
|
/* Map 21-bit characters to '\U00xxxxxx' */
|
||||||
else if (ch >= 0x10000) {
|
else if (ch >= 0x10000) {
|
||||||
int offset = p - PyString_AS_STRING(repr);
|
Py_ssize_t offset = p - PyString_AS_STRING(repr);
|
||||||
|
|
||||||
/* Resize the string if necessary */
|
/* Resize the string if necessary */
|
||||||
if (offset + 12 > PyString_GET_SIZE(repr)) {
|
if (offset + 12 > PyString_GET_SIZE(repr)) {
|
||||||
|
@ -2205,7 +2204,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
|
||||||
nextByte:
|
nextByte:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (_PyUnicode_Resize(&v, (int)(p - PyUnicode_AS_UNICODE(v))) < 0)
|
if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
|
||||||
goto onError;
|
goto onError;
|
||||||
Py_XDECREF(errorHandler);
|
Py_XDECREF(errorHandler);
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
|
@ -2348,7 +2347,7 @@ PyObject *_PyUnicode_DecodeUnicodeInternal(const char *s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyUnicode_Resize(&v, (int)(p - PyUnicode_AS_UNICODE(v))) < 0)
|
if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
|
||||||
goto onError;
|
goto onError;
|
||||||
Py_XDECREF(errorHandler);
|
Py_XDECREF(errorHandler);
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
|
@ -2723,7 +2722,7 @@ PyObject *PyUnicode_DecodeASCII(const char *s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p - PyUnicode_AS_UNICODE(v) < PyString_GET_SIZE(v))
|
if (p - PyUnicode_AS_UNICODE(v) < PyString_GET_SIZE(v))
|
||||||
if (_PyUnicode_Resize(&v, (int)(p - PyUnicode_AS_UNICODE(v))) < 0)
|
if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
|
||||||
goto onError;
|
goto onError;
|
||||||
Py_XDECREF(errorHandler);
|
Py_XDECREF(errorHandler);
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
|
@ -2982,7 +2981,7 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p - PyUnicode_AS_UNICODE(v) < PyUnicode_GET_SIZE(v))
|
if (p - PyUnicode_AS_UNICODE(v) < PyUnicode_GET_SIZE(v))
|
||||||
if (_PyUnicode_Resize(&v, (int)(p - PyUnicode_AS_UNICODE(v))) < 0)
|
if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
|
||||||
goto onError;
|
goto onError;
|
||||||
Py_XDECREF(errorHandler);
|
Py_XDECREF(errorHandler);
|
||||||
Py_XDECREF(exc);
|
Py_XDECREF(exc);
|
||||||
|
@ -3336,9 +3335,9 @@ static PyObject *unicode_translate_call_errorhandler(const char *errors,
|
||||||
Py_ssize_t startpos, Py_ssize_t endpos,
|
Py_ssize_t startpos, Py_ssize_t endpos,
|
||||||
Py_ssize_t *newpos)
|
Py_ssize_t *newpos)
|
||||||
{
|
{
|
||||||
static char *argparse = "O!i;translating error handler must return (unicode, int) tuple";
|
static char *argparse = "O!n;translating error handler must return (unicode, int) tuple";
|
||||||
|
|
||||||
int i_newpos;
|
Py_ssize_t i_newpos;
|
||||||
PyObject *restuple;
|
PyObject *restuple;
|
||||||
PyObject *resunicode;
|
PyObject *resunicode;
|
||||||
|
|
||||||
|
@ -3798,7 +3797,7 @@ Py_ssize_t count(PyUnicodeObject *self,
|
||||||
Py_ssize_t end,
|
Py_ssize_t end,
|
||||||
PyUnicodeObject *substring)
|
PyUnicodeObject *substring)
|
||||||
{
|
{
|
||||||
int count = 0;
|
Py_ssize_t count = 0;
|
||||||
|
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
start += self->length;
|
start += self->length;
|
||||||
|
@ -4157,7 +4156,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
|
||||||
PyObject *fseq; /* PySequence_Fast(seq) */
|
PyObject *fseq; /* PySequence_Fast(seq) */
|
||||||
Py_ssize_t seqlen; /* len(fseq) -- number of items in sequence */
|
Py_ssize_t seqlen; /* len(fseq) -- number of items in sequence */
|
||||||
PyObject *item;
|
PyObject *item;
|
||||||
int i;
|
Py_ssize_t i;
|
||||||
|
|
||||||
fseq = PySequence_Fast(seq, "");
|
fseq = PySequence_Fast(seq, "");
|
||||||
if (fseq == NULL) {
|
if (fseq == NULL) {
|
||||||
|
@ -4206,7 +4205,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get space. */
|
/* Get space. */
|
||||||
res = _PyUnicode_New((int)res_alloc);
|
res = _PyUnicode_New(res_alloc);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
res_p = PyUnicode_AS_UNICODE(res);
|
res_p = PyUnicode_AS_UNICODE(res);
|
||||||
|
@ -4236,11 +4235,11 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
|
||||||
/* Make sure we have enough space for the separator and the item. */
|
/* Make sure we have enough space for the separator and the item. */
|
||||||
itemlen = PyUnicode_GET_SIZE(item);
|
itemlen = PyUnicode_GET_SIZE(item);
|
||||||
new_res_used = res_used + itemlen;
|
new_res_used = res_used + itemlen;
|
||||||
if (new_res_used < res_used || new_res_used > INT_MAX)
|
if (new_res_used < res_used || new_res_used > PY_SSIZE_T_MAX)
|
||||||
goto Overflow;
|
goto Overflow;
|
||||||
if (i < seqlen - 1) {
|
if (i < seqlen - 1) {
|
||||||
new_res_used += seplen;
|
new_res_used += seplen;
|
||||||
if (new_res_used < res_used || new_res_used > INT_MAX)
|
if (new_res_used < res_used || new_res_used > PY_SSIZE_T_MAX)
|
||||||
goto Overflow;
|
goto Overflow;
|
||||||
}
|
}
|
||||||
if (new_res_used > res_alloc) {
|
if (new_res_used > res_alloc) {
|
||||||
|
@ -4248,10 +4247,10 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
|
||||||
do {
|
do {
|
||||||
size_t oldsize = res_alloc;
|
size_t oldsize = res_alloc;
|
||||||
res_alloc += res_alloc;
|
res_alloc += res_alloc;
|
||||||
if (res_alloc < oldsize || res_alloc > INT_MAX)
|
if (res_alloc < oldsize || res_alloc > PY_SSIZE_T_MAX)
|
||||||
goto Overflow;
|
goto Overflow;
|
||||||
} while (new_res_used > res_alloc);
|
} while (new_res_used > res_alloc);
|
||||||
if (_PyUnicode_Resize(&res, (int)res_alloc) < 0) {
|
if (_PyUnicode_Resize(&res, res_alloc) < 0) {
|
||||||
Py_DECREF(item);
|
Py_DECREF(item);
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
|
@ -4259,10 +4258,10 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy item, and maybe the separator. */
|
/* Copy item, and maybe the separator. */
|
||||||
Py_UNICODE_COPY(res_p, PyUnicode_AS_UNICODE(item), (int)itemlen);
|
Py_UNICODE_COPY(res_p, PyUnicode_AS_UNICODE(item), itemlen);
|
||||||
res_p += itemlen;
|
res_p += itemlen;
|
||||||
if (i < seqlen - 1) {
|
if (i < seqlen - 1) {
|
||||||
Py_UNICODE_COPY(res_p, sep, (int)seplen);
|
Py_UNICODE_COPY(res_p, sep, seplen);
|
||||||
res_p += seplen;
|
res_p += seplen;
|
||||||
}
|
}
|
||||||
Py_DECREF(item);
|
Py_DECREF(item);
|
||||||
|
@ -4272,7 +4271,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
|
||||||
/* Shrink res to match the used area; this probably can't fail,
|
/* Shrink res to match the used area; this probably can't fail,
|
||||||
* but it's cheap to check.
|
* but it's cheap to check.
|
||||||
*/
|
*/
|
||||||
if (_PyUnicode_Resize(&res, (int)res_used) < 0)
|
if (_PyUnicode_Resize(&res, res_used) < 0)
|
||||||
goto onError;
|
goto onError;
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
|
@ -4605,7 +4604,7 @@ PyObject *split(PyUnicodeObject *self,
|
||||||
PyObject *list;
|
PyObject *list;
|
||||||
|
|
||||||
if (maxcount < 0)
|
if (maxcount < 0)
|
||||||
maxcount = INT_MAX;
|
maxcount = PY_SSIZE_T_MAX;
|
||||||
|
|
||||||
list = PyList_New(0);
|
list = PyList_New(0);
|
||||||
if (!list)
|
if (!list)
|
||||||
|
@ -4634,7 +4633,7 @@ PyObject *rsplit(PyUnicodeObject *self,
|
||||||
PyObject *list;
|
PyObject *list;
|
||||||
|
|
||||||
if (maxcount < 0)
|
if (maxcount < 0)
|
||||||
maxcount = INT_MAX;
|
maxcount = PY_SSIZE_T_MAX;
|
||||||
|
|
||||||
list = PyList_New(0);
|
list = PyList_New(0);
|
||||||
if (!list)
|
if (!list)
|
||||||
|
@ -4664,10 +4663,10 @@ PyObject *replace(PyUnicodeObject *self,
|
||||||
PyUnicodeObject *u;
|
PyUnicodeObject *u;
|
||||||
|
|
||||||
if (maxcount < 0)
|
if (maxcount < 0)
|
||||||
maxcount = INT_MAX;
|
maxcount = PY_SSIZE_T_MAX;
|
||||||
|
|
||||||
if (str1->length == 1 && str2->length == 1) {
|
if (str1->length == 1 && str2->length == 1) {
|
||||||
int i;
|
Py_ssize_t i;
|
||||||
|
|
||||||
/* replace characters */
|
/* replace characters */
|
||||||
if (!findchar(self->str, self->length, str1->str[0]) &&
|
if (!findchar(self->str, self->length, str1->str[0]) &&
|
||||||
|
@ -5088,7 +5087,7 @@ unicode_count(PyUnicodeObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyUnicodeObject *substring;
|
PyUnicodeObject *substring;
|
||||||
Py_ssize_t start = 0;
|
Py_ssize_t start = 0;
|
||||||
Py_ssize_t end = INT_MAX;
|
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring,
|
if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring,
|
||||||
|
@ -5265,7 +5264,7 @@ unicode_find(PyUnicodeObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyUnicodeObject *substring;
|
PyUnicodeObject *substring;
|
||||||
Py_ssize_t start = 0;
|
Py_ssize_t start = 0;
|
||||||
Py_ssize_t end = INT_MAX;
|
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|O&O&:find", &substring,
|
if (!PyArg_ParseTuple(args, "O|O&O&:find", &substring,
|
||||||
|
@ -5331,7 +5330,7 @@ unicode_index(PyUnicodeObject *self, PyObject *args)
|
||||||
Py_ssize_t result;
|
Py_ssize_t result;
|
||||||
PyUnicodeObject *substring;
|
PyUnicodeObject *substring;
|
||||||
Py_ssize_t start = 0;
|
Py_ssize_t start = 0;
|
||||||
Py_ssize_t end = INT_MAX;
|
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|O&O&:index", &substring,
|
if (!PyArg_ParseTuple(args, "O|O&O&:index", &substring,
|
||||||
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
|
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
|
||||||
|
@ -5669,10 +5668,10 @@ done using the specified fill character (default is a space).");
|
||||||
static PyObject *
|
static PyObject *
|
||||||
unicode_ljust(PyUnicodeObject *self, PyObject *args)
|
unicode_ljust(PyUnicodeObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int width;
|
Py_ssize_t width;
|
||||||
Py_UNICODE fillchar = ' ';
|
Py_UNICODE fillchar = ' ';
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "i|O&:ljust", &width, convert_uc, &fillchar))
|
if (!PyArg_ParseTuple(args, "n|O&:ljust", &width, convert_uc, &fillchar))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (self->length >= width && PyUnicode_CheckExact(self)) {
|
if (self->length >= width && PyUnicode_CheckExact(self)) {
|
||||||
|
@ -5996,7 +5995,7 @@ unicode_rfind(PyUnicodeObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyUnicodeObject *substring;
|
PyUnicodeObject *substring;
|
||||||
Py_ssize_t start = 0;
|
Py_ssize_t start = 0;
|
||||||
Py_ssize_t end = INT_MAX;
|
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|O&O&:rfind", &substring,
|
if (!PyArg_ParseTuple(args, "O|O&O&:rfind", &substring,
|
||||||
|
@ -6024,7 +6023,7 @@ unicode_rindex(PyUnicodeObject *self, PyObject *args)
|
||||||
Py_ssize_t result;
|
Py_ssize_t result;
|
||||||
PyUnicodeObject *substring;
|
PyUnicodeObject *substring;
|
||||||
Py_ssize_t start = 0;
|
Py_ssize_t start = 0;
|
||||||
Py_ssize_t end = INT_MAX;
|
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|O&O&:rindex", &substring,
|
if (!PyArg_ParseTuple(args, "O|O&O&:rindex", &substring,
|
||||||
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
|
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
|
||||||
|
@ -6053,10 +6052,10 @@ done using the specified fill character (default is a space).");
|
||||||
static PyObject *
|
static PyObject *
|
||||||
unicode_rjust(PyUnicodeObject *self, PyObject *args)
|
unicode_rjust(PyUnicodeObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int width;
|
Py_ssize_t width;
|
||||||
Py_UNICODE fillchar = ' ';
|
Py_UNICODE fillchar = ' ';
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "i|O&:rjust", &width, convert_uc, &fillchar))
|
if (!PyArg_ParseTuple(args, "n|O&:rjust", &width, convert_uc, &fillchar))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (self->length >= width && PyUnicode_CheckExact(self)) {
|
if (self->length >= width && PyUnicode_CheckExact(self)) {
|
||||||
|
@ -6318,7 +6317,7 @@ unicode_startswith(PyUnicodeObject *self,
|
||||||
{
|
{
|
||||||
PyUnicodeObject *substring;
|
PyUnicodeObject *substring;
|
||||||
Py_ssize_t start = 0;
|
Py_ssize_t start = 0;
|
||||||
Py_ssize_t end = INT_MAX;
|
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &substring,
|
if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &substring,
|
||||||
|
@ -6349,7 +6348,7 @@ unicode_endswith(PyUnicodeObject *self,
|
||||||
{
|
{
|
||||||
PyUnicodeObject *substring;
|
PyUnicodeObject *substring;
|
||||||
Py_ssize_t start = 0;
|
Py_ssize_t start = 0;
|
||||||
Py_ssize_t end = INT_MAX;
|
Py_ssize_t end = PY_SSIZE_T_MAX;
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &substring,
|
if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &substring,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue