return -1;
}
unicode->str[length] = 0;
- assert(length < INT_MAX);
- unicode->length = (int)length;
+ unicode->length = length;
reset:
/* Reset the object caches */
#else
{
register Py_UNICODE *u;
- register int i;
+ register Py_ssize_t i;
u = PyUnicode_AS_UNICODE(unicode);
for (i = size; i > 0; i--)
*u++ = *w++;
#else
{
register Py_UNICODE *u;
- register int i;
+ register Py_ssize_t i;
u = PyUnicode_AS_UNICODE(unicode);
for (i = size; i > 0; i--)
*w++ = *u++;
PyObject *v; /* result string object */
char *p; /* next free byte in output buffer */
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];
assert(s != NULL);
if (v == NULL) {
/* This was stack allocated. */
- nneeded = Py_SAFE_DOWNCAST(p - stackbuf, long, int);
+ nneeded = p - stackbuf;
assert(nneeded <= nallocated);
v = PyString_FromStringAndSize(stackbuf, nneeded);
}
else {
/* 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);
_PyString_Resize(&v, nneeded);
}
nextByte:
;
}
- if (_PyUnicode_Resize(&v, (int)(p - PyUnicode_AS_UNICODE(v))) < 0)
+ if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
goto onError;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
#ifdef Py_UNICODE_WIDE
/* Map 21-bit characters to '\U00xxxxxx' */
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 */
if (offset + 12 > PyString_GET_SIZE(repr)) {
nextByte:
;
}
- if (_PyUnicode_Resize(&v, (int)(p - PyUnicode_AS_UNICODE(v))) < 0)
+ if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
goto onError;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
}
}
- if (_PyUnicode_Resize(&v, (int)(p - PyUnicode_AS_UNICODE(v))) < 0)
+ if (_PyUnicode_Resize(&v, p - PyUnicode_AS_UNICODE(v)) < 0)
goto onError;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
}
}
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;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
}
}
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;
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
Py_ssize_t startpos, Py_ssize_t endpos,
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 *resunicode;
Py_ssize_t end,
PyUnicodeObject *substring)
{
- int count = 0;
+ Py_ssize_t count = 0;
if (start < 0)
start += self->length;
PyObject *fseq; /* PySequence_Fast(seq) */
Py_ssize_t seqlen; /* len(fseq) -- number of items in sequence */
PyObject *item;
- int i;
+ Py_ssize_t i;
fseq = PySequence_Fast(seq, "");
if (fseq == NULL) {
}
/* Get space. */
- res = _PyUnicode_New((int)res_alloc);
+ res = _PyUnicode_New(res_alloc);
if (res == NULL)
goto onError;
res_p = PyUnicode_AS_UNICODE(res);
/* Make sure we have enough space for the separator and the item. */
itemlen = PyUnicode_GET_SIZE(item);
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;
if (i < seqlen - 1) {
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;
}
if (new_res_used > res_alloc) {
do {
size_t oldsize = 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;
} while (new_res_used > res_alloc);
- if (_PyUnicode_Resize(&res, (int)res_alloc) < 0) {
+ if (_PyUnicode_Resize(&res, res_alloc) < 0) {
Py_DECREF(item);
goto onError;
}
}
/* 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;
if (i < seqlen - 1) {
- Py_UNICODE_COPY(res_p, sep, (int)seplen);
+ Py_UNICODE_COPY(res_p, sep, seplen);
res_p += seplen;
}
Py_DECREF(item);
/* Shrink res to match the used area; this probably can't fail,
* but it's cheap to check.
*/
- if (_PyUnicode_Resize(&res, (int)res_used) < 0)
+ if (_PyUnicode_Resize(&res, res_used) < 0)
goto onError;
Done:
PyObject *list;
if (maxcount < 0)
- maxcount = INT_MAX;
+ maxcount = PY_SSIZE_T_MAX;
list = PyList_New(0);
if (!list)
PyObject *list;
if (maxcount < 0)
- maxcount = INT_MAX;
+ maxcount = PY_SSIZE_T_MAX;
list = PyList_New(0);
if (!list)
PyUnicodeObject *u;
if (maxcount < 0)
- maxcount = INT_MAX;
+ maxcount = PY_SSIZE_T_MAX;
if (str1->length == 1 && str2->length == 1) {
- int i;
+ Py_ssize_t i;
/* replace characters */
if (!findchar(self->str, self->length, str1->str[0]) &&
{
PyUnicodeObject *substring;
Py_ssize_t start = 0;
- Py_ssize_t end = INT_MAX;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring,
{
PyUnicodeObject *substring;
Py_ssize_t start = 0;
- Py_ssize_t end = INT_MAX;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:find", &substring,
Py_ssize_t result;
PyUnicodeObject *substring;
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,
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
static PyObject *
unicode_ljust(PyUnicodeObject *self, PyObject *args)
{
- int width;
+ Py_ssize_t width;
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;
if (self->length >= width && PyUnicode_CheckExact(self)) {
{
PyUnicodeObject *substring;
Py_ssize_t start = 0;
- Py_ssize_t end = INT_MAX;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:rfind", &substring,
Py_ssize_t result;
PyUnicodeObject *substring;
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,
_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
static PyObject *
unicode_rjust(PyUnicodeObject *self, PyObject *args)
{
- int width;
+ Py_ssize_t width;
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;
if (self->length >= width && PyUnicode_CheckExact(self)) {
{
PyUnicodeObject *substring;
Py_ssize_t start = 0;
- Py_ssize_t end = INT_MAX;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &substring,
{
PyUnicodeObject *substring;
Py_ssize_t start = 0;
- Py_ssize_t end = INT_MAX;
+ Py_ssize_t end = PY_SSIZE_T_MAX;
PyObject *result;
if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &substring,