Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74387f5

Browse files
committed
Use Py_ssize_t type for sizes in getargs.c
Fix compiler warnings on Windows 64-bit
1 parent cad876d commit 74387f5

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

Python/getargs.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
421421
int n = 0;
422422
const char *format = *p_format;
423423
int i;
424+
Py_ssize_t len;
424425

425426
for (;;) {
426427
int c = *format++;
@@ -450,12 +451,20 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
450451
return msgbuf;
451452
}
452453

453-
if ((i = PySequence_Size(arg)) != n) {
454+
len = PySequence_Size(arg);
455+
if (len != n) {
454456
levels[0] = 0;
455-
PyOS_snprintf(msgbuf, bufsize,
456-
toplevel ? "expected %d arguments, not %d" :
457-
"must be sequence of length %d, not %d",
458-
n, i);
457+
if (toplevel) {
458+
PyOS_snprintf(msgbuf, bufsize,
459+
"expected %d arguments, not %" PY_FORMAT_SIZE_T "d",
460+
n, len);
461+
}
462+
else {
463+
PyOS_snprintf(msgbuf, bufsize,
464+
"must be sequence of length %d, "
465+
"not %" PY_FORMAT_SIZE_T "d",
466+
n, len);
467+
}
459468
return msgbuf;
460469
}
461470

@@ -1426,7 +1435,8 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
14261435
const char *fname, *msg, *custom_msg, *keyword;
14271436
int min = INT_MAX;
14281437
int max = INT_MAX;
1429-
int i, len, nargs, nkeywords;
1438+
int i, len;
1439+
Py_ssize_t nargs, nkeywords;
14301440
PyObject *current_arg;
14311441
freelistentry_t static_entries[STATIC_FREELIST_ENTRIES];
14321442
freelist_t freelist = {static_entries, 0, 0};
@@ -1466,7 +1476,8 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
14661476
nkeywords = (keywords == NULL) ? 0 : PyDict_Size(keywords);
14671477
if (nargs + nkeywords > len) {
14681478
PyErr_Format(PyExc_TypeError,
1469-
"%s%s takes at most %d argument%s (%d given)",
1479+
"%s%s takes at most %d argument%s "
1480+
"(%" PY_FORMAT_SIZE_T "d given)",
14701481
(fname == NULL) ? "function" : fname,
14711482
(fname == NULL) ? "" : "()",
14721483
len,

0 commit comments

Comments
 (0)