Skip to content

Commit 3161b80

Browse files
author
martin.v.loewis
committed
Use Py_ssize_t to count the
git-svn-id: http://svn.python.org/projects/python/trunk@42414 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 85bbddc commit 3161b80

7 files changed

Lines changed: 24 additions & 22 deletions

File tree

Python/bltinmodule.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ static PyObject *
193193
builtin_filter(PyObject *self, PyObject *args)
194194
{
195195
PyObject *func, *seq, *result, *it, *arg;
196-
int len; /* guess for result list size */
197-
register int j;
196+
Py_ssize_t len; /* guess for result list size */
197+
register Py_ssize_t j;
198198

199199
if (!PyArg_UnpackTuple(args, "filter", 2, 2, &func, &seq))
200200
return NULL;
@@ -860,7 +860,7 @@ builtin_map(PyObject *self, PyObject *args)
860860
len = 0;
861861
for (i = 0, sqp = seqs; i < n; ++i, ++sqp) {
862862
PyObject *curseq;
863-
int curlen;
863+
Py_ssize_t curlen;
864864

865865
/* Get iterator. */
866866
curseq = PyTuple_GetItem(args, i+1);
@@ -1338,7 +1338,7 @@ static PyObject *
13381338
builtin_ord(PyObject *self, PyObject* obj)
13391339
{
13401340
long ord;
1341-
int size;
1341+
Py_ssize_t size;
13421342

13431343
if (PyString_Check(obj)) {
13441344
size = PyString_GET_SIZE(obj);
@@ -1363,7 +1363,7 @@ builtin_ord(PyObject *self, PyObject* obj)
13631363

13641364
PyErr_Format(PyExc_TypeError,
13651365
"ord() expected a character, "
1366-
"but string of length %d found",
1366+
"but string of length %zd found",
13671367
size);
13681368
return NULL;
13691369
}
@@ -2094,10 +2094,10 @@ static PyObject*
20942094
builtin_zip(PyObject *self, PyObject *args)
20952095
{
20962096
PyObject *ret;
2097-
const int itemsize = PySequence_Length(args);
2098-
int i;
2097+
const Py_ssize_t itemsize = PySequence_Length(args);
2098+
Py_ssize_t i;
20992099
PyObject *itlist; /* tuple of iterators */
2100-
int len; /* guess at result length */
2100+
Py_ssize_t len; /* guess at result length */
21012101

21022102
if (itemsize == 0)
21032103
return PyList_New(0);
@@ -2111,7 +2111,7 @@ builtin_zip(PyObject *self, PyObject *args)
21112111
len = -1; /* unknown */
21122112
for (i = 0; i < itemsize; ++i) {
21132113
PyObject *item = PyTuple_GET_ITEM(args, i);
2114-
int thislen = _PyObject_LengthHint(item);
2114+
Py_ssize_t thislen = _PyObject_LengthHint(item);
21152115
if (thislen < 0) {
21162116
if (!PyErr_ExceptionMatches(PyExc_TypeError) &&
21172117
!PyErr_ExceptionMatches(PyExc_AttributeError)) {
@@ -2460,7 +2460,7 @@ filterstring(PyObject *func, PyObject *strobj)
24602460
Py_DECREF(good);
24612461
}
24622462
if (ok) {
2463-
int reslen;
2463+
Py_ssize_t reslen;
24642464
if (!PyString_Check(item)) {
24652465
PyErr_SetString(PyExc_TypeError, "can't filter str to str:"
24662466
" __getitem__ returned different type");
@@ -2473,7 +2473,7 @@ filterstring(PyObject *func, PyObject *strobj)
24732473
PyString_AS_STRING(item)[0];
24742474
} else {
24752475
/* do we need more space? */
2476-
int need = j + reslen + len-i-1;
2476+
Py_ssize_t need = j + reslen + len-i-1;
24772477
if (need > outlen) {
24782478
/* overallocate, to avoid reallocations */
24792479
if (need<2*outlen)
@@ -2513,8 +2513,8 @@ filterunicode(PyObject *func, PyObject *strobj)
25132513
{
25142514
PyObject *result;
25152515
register int i, j;
2516-
int len = PyUnicode_GetSize(strobj);
2517-
int outlen = len;
2516+
Py_ssize_t len = PyUnicode_GetSize(strobj);
2517+
Py_ssize_t outlen = len;
25182518

25192519
if (func == Py_None) {
25202520
/* If it's a real string we can return the original,
@@ -2554,7 +2554,7 @@ filterunicode(PyObject *func, PyObject *strobj)
25542554
Py_DECREF(good);
25552555
}
25562556
if (ok) {
2557-
int reslen;
2557+
Py_ssize_t reslen;
25582558
if (!PyUnicode_Check(item)) {
25592559
PyErr_SetString(PyExc_TypeError,
25602560
"can't filter unicode to unicode:"
@@ -2568,7 +2568,7 @@ filterunicode(PyObject *func, PyObject *strobj)
25682568
PyUnicode_AS_UNICODE(item)[0];
25692569
else {
25702570
/* do we need more space? */
2571-
int need = j + reslen + len - i - 1;
2571+
Py_ssize_t need = j + reslen + len - i - 1;
25722572
if (need > outlen) {
25732573
/* overallocate,
25742574
to avoid reallocations */

Python/errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)
8383
return 0;
8484
}
8585
if (PyTuple_Check(exc)) {
86-
int i, n;
86+
Py_ssize_t i, n;
8787
n = PyTuple_Size(exc);
8888
for (i = 0; i < n; i++) {
8989
/* Test recursively */

Python/getargs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ cleanreturn(int retval, PyObject *freelist)
153153
{
154154
if(freelist) {
155155
if((retval) == 0) {
156-
int len = PyList_GET_SIZE(freelist), i;
156+
Py_ssize_t len = PyList_GET_SIZE(freelist), i;
157157
for (i = 0; i < len; i++)
158158
PyMem_FREE(PyCObject_AsVoidPtr(
159159
PyList_GET_ITEM(freelist, i)));
@@ -176,7 +176,7 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
176176
int level = 0;
177177
int endfmt = 0;
178178
const char *formatsave = format;
179-
int i, len;
179+
Py_ssize_t i, len;
180180
char *msg;
181181
PyObject *freelist = NULL;
182182
int compat = flags & FLAG_COMPAT;

Python/modsupport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ do_mkvalue(const char **p_format, va_list *p_va)
315315

316316
case 'n':
317317
#if SIZEOF_SIZE_T!=SIZEOF_LONG
318-
return PyLong_FromSsize_t(va_arg(*p_va, Py_Ssize_t));
318+
return PyInt_FromSsize_t(va_arg(*p_va, Py_ssize_t));
319319
#endif
320320
/* Fall through from 'n' to 'l' if Py_ssize_t is long */
321321
case 'l':

Python/symtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ symtable_warn(struct symtable *st, char *msg, int lineno)
715715
static int
716716
symtable_exit_block(struct symtable *st, void *ast)
717717
{
718-
int end;
718+
Py_ssize_t end;
719719

720720
Py_DECREF(st->st_cur);
721721
end = PyList_GET_SIZE(st->st_stack) - 1;

Python/sysmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,8 @@ static void
947947
svnversion_init(void)
948948
{
949949
const char *python, *br_start, *br_end, *br_end2, *svnversion;
950-
int len, istag;
950+
Py_ssize_t len;
951+
int istag;
951952

952953
if (svn_initialized)
953954
return;

Python/traceback.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ tb_displayline(PyObject *f, char *filename, int lineno, char *name)
153153
tail++;
154154
path = PySys_GetObject("path");
155155
if (path != NULL && PyList_Check(path)) {
156-
int npath = PyList_Size(path);
156+
Py_ssize_t _npath = PyList_Size(path);
157+
int npath = Py_SAFE_DOWNCAST(_npath, Py_ssize_t, int);
157158
size_t taillen = strlen(tail);
158159
char namebuf[MAXPATHLEN+1];
159160
for (i = 0; i < npath; i++) {

0 commit comments

Comments
 (0)