Skip to content

Commit e11a6ab

Browse files
committed
bpo-46323 Address Victor's suggestion
1 parent eba3eea commit e11a6ab

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Modules/_ctypes/callbacks.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,34 +146,34 @@ static void _CallPythonObject(void *mem,
146146
int flags,
147147
void **pArgs)
148148
{
149-
PyObject *result;
149+
PyObject *result = NULL;
150150
PyObject **args = NULL;
151-
Py_ssize_t nArgs;
151+
Py_ssize_t i = 0, j = 0, n_args = 0;
152152
PyObject *error_object = NULL;
153153
int *space;
154154
PyGILState_STATE state = PyGILState_Ensure();
155155

156-
nArgs = PySequence_Length(converters);
156+
n_args = PySequence_Length(converters);
157157
/* Hm. What to return in case of error?
158158
For COM, 0xFFFFFFFF seems better than 0.
159159
*/
160-
if (nArgs < 0) {
160+
if (n_args < 0) {
161161
PrintError("BUG: PySequence_Length");
162162
goto Done;
163163
}
164164

165165
PyObject *args_stack[_PY_FASTCALL_SMALL_STACK];
166-
if (nArgs <= (Py_ssize_t)Py_ARRAY_LENGTH(args_stack)) {
166+
if (n_args <= (Py_ssize_t)Py_ARRAY_LENGTH(args_stack)) {
167167
args = args_stack;
168168
}
169169
else {
170-
args = PyMem_Malloc(nArgs * sizeof(PyObject *));
170+
args = PyMem_Malloc(n_args * sizeof(PyObject *));
171171
if (args == NULL) {
172172
PyErr_NoMemory();
173173
goto Done;
174174
}
175175
}
176-
for (Py_ssize_t i = 0; i < nArgs; ++i) {
176+
for (i = 0; i < n_args; i++) {
177177
/* Note: new reference! */
178178
PyObject *cnv = PySequence_GetItem(converters, i);
179179
StgDictObject *dict;
@@ -246,7 +246,7 @@ static void _CallPythonObject(void *mem,
246246
#endif
247247
}
248248

249-
result = PyObject_Vectorcall(callable, args, nArgs, NULL);
249+
result = PyObject_Vectorcall(callable, args, n_args, NULL);
250250
if (result == NULL) {
251251
_PyErr_WriteUnraisableMsg("on calling ctypes callback function",
252252
callable);
@@ -313,8 +313,8 @@ static void _CallPythonObject(void *mem,
313313
Py_XDECREF(result);
314314

315315
Done:
316-
for (Py_ssize_t i = 0; i < nArgs; i++) {
317-
Py_XDECREF(args[i]);
316+
for (j = 0; j < i; j++) {
317+
Py_DECREF(args[j]);
318318
}
319319
if (args != args_stack) {
320320
PyMem_Free(args);

0 commit comments

Comments
 (0)