Skip to content

Commit 43cc3d8

Browse files
committed
bpo-46323: Use PySequence_Fast_ITEMS if possible
1 parent e11a6ab commit 43cc3d8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Modules/_ctypes/callbacks.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,15 @@ static void _CallPythonObject(void *mem,
173173
goto Done;
174174
}
175175
}
176+
177+
PyObject **cnvs = PySequence_Fast_ITEMS(converters);
176178
for (i = 0; i < n_args; i++) {
177-
/* Note: new reference! */
178-
PyObject *cnv = PySequence_GetItem(converters, i);
179+
PyObject *cnv = cnvs[i];
179180
StgDictObject *dict;
180-
if (cnv)
181+
if (cnv) {
182+
Py_INCREF(cnv);
181183
dict = PyType_stgdict(cnv);
184+
}
182185
else {
183186
PrintError("Getting argument converter %zd\n", i);
184187
goto Done;
@@ -388,10 +391,12 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
388391
}
389392

390393
p->flags = flags;
394+
PyObject **cnvs = PySequence_Fast_ITEMS(converters);
391395
for (i = 0; i < nArgs; ++i) {
392-
PyObject *cnv = PySequence_GetItem(converters, i);
396+
PyObject *cnv = cnvs[i];
393397
if (cnv == NULL)
394398
goto error;
399+
Py_INCREF(cnv);
395400
p->atypes[i] = _ctypes_get_ffi_type(cnv);
396401
Py_DECREF(cnv);
397402
}

0 commit comments

Comments
 (0)