Skip to content

Commit 1dc2756

Browse files
committed
address review: use _PyTuple_FromArray()
1 parent ac67ef3 commit 1dc2756

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Modules/gcmodule.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "pycore_gc.h"
99
#include "pycore_object.h" // _PyObject_IS_GC()
1010
#include "pycore_pystate.h" // _PyInterpreterState_GET()
11+
#include "pycore_tuple.h" // _PyTuple_FromArray()
1112

1213
typedef struct _gc_runtime_state GCState;
1314

@@ -225,15 +226,11 @@ gc_get_referrers_impl(PyObject *module, Py_ssize_t nargs,
225226
PyObject *const *args)
226227
/*[clinic end generated code: output=1d44a7695ea25c40 input=bae96961b14a0922]*/
227228
{
228-
PyObject *varargs = PyTuple_New(nargs);
229+
PyObject *varargs = _PyTuple_FromArray(args, nargs);
229230

230231
if (!varargs) {
231232
return NULL;
232233
}
233-
for (Py_ssize_t i = 0; i < nargs; i++) {
234-
PyTuple_SET_ITEM(varargs, i, Py_NewRef(args[i]));
235-
}
236-
237234
if (PySys_Audit("gc.get_referrers", "(O)", varargs) < 0) {
238235
Py_DECREF(varargs);
239236
return NULL;
@@ -287,15 +284,11 @@ gc_get_referents_impl(PyObject *module, Py_ssize_t nargs,
287284
PyObject *const *args)
288285
/*[clinic end generated code: output=e459f3e8c0d19311 input=b3ceab0c34038cbf]*/
289286
{
290-
PyObject *varargs = PyTuple_New(nargs);
287+
PyObject *varargs = _PyTuple_FromArray(args, nargs);
291288

292289
if (!varargs) {
293290
return NULL;
294291
}
295-
for (Py_ssize_t i = 0; i < nargs; i++) {
296-
PyTuple_SET_ITEM(varargs, i, Py_NewRef(args[i]));
297-
}
298-
299292
if (PySys_Audit("gc.get_referents", "(O)", varargs) < 0) {
300293
Py_DECREF(varargs);
301294
return NULL;

0 commit comments

Comments
 (0)