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

Skip to content

Commit 0fcab4a

Browse files
author
Victor Stinner
committed
Issue #9566: use Py_ssize_t instead of int
1 parent 6ab8e82 commit 0fcab4a

14 files changed

Lines changed: 32 additions & 33 deletions

Modules/_ctypes/_ctypes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3925,14 +3925,14 @@ PyTypeObject PyCFuncPtr_Type = {
39253925
39263926
Returns -1 on error, or the index of next argument on success.
39273927
*/
3928-
static int
3928+
static Py_ssize_t
39293929
_init_pos_args(PyObject *self, PyTypeObject *type,
39303930
PyObject *args, PyObject *kwds,
3931-
int index)
3931+
Py_ssize_t index)
39323932
{
39333933
StgDictObject *dict;
39343934
PyObject *fields;
3935-
int i;
3935+
Py_ssize_t i;
39363936

39373937
if (PyType_stgdict((PyObject *)type->tp_base)) {
39383938
index = _init_pos_args(self, type->tp_base,

Modules/_testcapimodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ argparsing(PyObject *o, PyObject *args)
21882188
/* argument converter not called? */
21892189
return NULL;
21902190
/* Should be 1 */
2191-
res = PyLong_FromLong(Py_REFCNT(str2));
2191+
res = PyLong_FromSsize_t(Py_REFCNT(str2));
21922192
Py_DECREF(str2);
21932193
PyErr_Clear();
21942194
return res;

Modules/audioop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ audioop_check_size(int size)
309309
}
310310

311311
static int
312-
audioop_check_parameters(int len, int size)
312+
audioop_check_parameters(Py_ssize_t len, int size)
313313
{
314314
if (!audioop_check_size(size))
315315
return 0;

Modules/md5module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ void md5_init(struct md5_state *md5)
228228
@param inlen The length of the data (octets)
229229
*/
230230
void md5_process(struct md5_state *md5,
231-
const unsigned char *in, unsigned long inlen)
231+
const unsigned char *in, Py_ssize_t inlen)
232232
{
233-
unsigned long n;
233+
Py_ssize_t n;
234234

235235
assert(md5 != NULL);
236236
assert(in != NULL);

Modules/pyexpat.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ readinst(char *buf, int buf_size, PyObject *meth)
800800
PyObject *arg = NULL;
801801
PyObject *bytes = NULL;
802802
PyObject *str = NULL;
803-
int len = -1;
803+
Py_ssize_t len = -1;
804804
char *ptr;
805805

806806
if ((bytes = PyLong_FromLong(buf_size)) == NULL)
@@ -831,15 +831,15 @@ readinst(char *buf, int buf_size, PyObject *meth)
831831
if (len > buf_size) {
832832
PyErr_Format(PyExc_ValueError,
833833
"read() returned too much data: "
834-
"%i bytes requested, %i returned",
834+
"%i bytes requested, %zi returned",
835835
buf_size, len);
836836
goto finally;
837837
}
838838
memcpy(buf, ptr, len);
839839
finally:
840840
Py_XDECREF(arg);
841841
Py_XDECREF(str);
842-
return len;
842+
return (int)len;
843843
}
844844

845845
PyDoc_STRVAR(xmlparse_ParseFile__doc__,
@@ -1807,7 +1807,7 @@ MODULE_INITFUNC(void)
18071807
Py_XDECREF(rev_codes_dict);
18081808
return NULL;
18091809
}
1810-
1810+
18111811
#define MYCONST(name) \
18121812
if (PyModule_AddStringConstant(errors_module, #name, \
18131813
(char *)XML_ErrorString(name)) < 0) \
@@ -1873,7 +1873,7 @@ MODULE_INITFUNC(void)
18731873
return NULL;
18741874
if (PyModule_AddObject(errors_module, "messages", rev_codes_dict) < 0)
18751875
return NULL;
1876-
1876+
18771877
#undef MYCONST
18781878

18791879
#define MYCONST(c) PyModule_AddIntConstant(m, #c, c)

Modules/selectmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ reap_obj(pylist fd2obj[FD_SETSIZE + 1])
8181
static int
8282
seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
8383
{
84-
int i;
8584
int max = -1;
8685
int index = 0;
87-
int len = -1;
86+
Py_ssize_t i, len = -1;
8887
PyObject* fast_seq = NULL;
8988
PyObject* o = NULL;
9089

Modules/sha1module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ void sha1_init(struct sha1_state *sha1)
203203
@param inlen The length of the data (octets)
204204
*/
205205
void sha1_process(struct sha1_state *sha1,
206-
const unsigned char *in, unsigned long inlen)
206+
const unsigned char *in, Py_ssize_t inlen)
207207
{
208-
unsigned long n;
208+
Py_ssize_t n;
209209

210210
assert(sha1 != NULL);
211211
assert(in != NULL);

Modules/sha256module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ sha224_init(SHAobject *sha_info)
265265
/* update the SHA digest */
266266

267267
static void
268-
sha_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
268+
sha_update(SHAobject *sha_info, SHA_BYTE *buffer, Py_ssize_t count)
269269
{
270-
int i;
270+
Py_ssize_t i;
271271
SHA_INT32 clo;
272272

273273
clo = sha_info->count_lo + ((SHA_INT32) count << 3);

Modules/sha512module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ sha384_init(SHAobject *sha_info)
291291
/* update the SHA digest */
292292

293293
static void
294-
sha512_update(SHAobject *sha_info, SHA_BYTE *buffer, int count)
294+
sha512_update(SHAobject *sha_info, SHA_BYTE *buffer, Py_ssize_t count)
295295
{
296-
int i;
296+
Py_ssize_t i;
297297
SHA_INT32 clo;
298298

299299
clo = sha_info->count_lo + ((SHA_INT32) count << 3);

Modules/unicodedata.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
403403
{
404404
PyUnicodeObject *v;
405405
char decomp[256];
406-
int code, index, count, i;
406+
int code, index, count;
407+
size_t i;
407408
unsigned int prefix_index;
408409
Py_UCS4 c;
409410

@@ -450,15 +451,12 @@ unicodedata_decomposition(PyObject *self, PyObject *args)
450451
while (count-- > 0) {
451452
if (i)
452453
decomp[i++] = ' ';
453-
assert((size_t)i < sizeof(decomp));
454+
assert(i < sizeof(decomp));
454455
PyOS_snprintf(decomp + i, sizeof(decomp) - i, "%04X",
455456
decomp_data[++index]);
456457
i += strlen(decomp + i);
457458
}
458-
459-
decomp[i] = '\0';
460-
461-
return PyUnicode_FromString(decomp);
459+
return PyUnicode_FromStringAndSize(decomp, i);
462460
}
463461

464462
static void

0 commit comments

Comments
 (0)