diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-10 21:22:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 21:22:02 (GMT) |
commit | 584e55bd34a38a0bd4b6ed3534fdbf7dc35c64b0 (patch) | |
tree | 3eb2005170635a27dc24516ace42a4cca741be38 /Objects/genericaliasobject.c | |
parent | 2f4af2d99cffed6ba81e4b8fd886de6ae8625a3f (diff) | |
download | cpython-584e55bd34a38a0bd4b6ed3534fdbf7dc35c64b0.zip cpython-584e55bd34a38a0bd4b6ed3534fdbf7dc35c64b0.tar.gz cpython-584e55bd34a38a0bd4b6ed3534fdbf7dc35c64b0.tar.bz2 |
gh-99300: Use Py_NewRef() in Objects/ directory (#99335)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in C files of the Objects/ directory.
Diffstat (limited to 'Objects/genericaliasobject.c')
-rw-r--r-- | Objects/genericaliasobject.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index 77acd1b..675fd49 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -183,8 +183,7 @@ static int tuple_add(PyObject *self, Py_ssize_t len, PyObject *item) { if (tuple_index(self, len, item) < 0) { - Py_INCREF(item); - PyTuple_SET_ITEM(self, len, item); + PyTuple_SET_ITEM(self, len, Py_NewRef(item)); return 1; } return 0; @@ -201,8 +200,7 @@ tuple_extend(PyObject **dst, Py_ssize_t dstindex, assert(dstindex + count <= PyTuple_GET_SIZE(*dst)); for (Py_ssize_t i = 0; i < count; ++i) { PyObject *item = src[i]; - Py_INCREF(item); - PyTuple_SET_ITEM(*dst, dstindex + i, item); + PyTuple_SET_ITEM(*dst, dstindex + i, Py_NewRef(item)); } return dstindex + count; } @@ -304,8 +302,7 @@ subs_tvars(PyObject *obj, PyObject *params, continue; } } - Py_INCREF(arg); - PyTuple_SET_ITEM(subargs, j, arg); + PyTuple_SET_ITEM(subargs, j, Py_NewRef(arg)); j++; } assert(j == PyTuple_GET_SIZE(subargs)); @@ -347,8 +344,7 @@ _unpacked_tuple_args(PyObject *arg) ((gaobject *)arg)->origin == (PyObject *)&PyTuple_Type) { result = ((gaobject *)arg)->args; - Py_INCREF(result); - return result; + return Py_NewRef(result); } if (_PyObject_LookupAttr(arg, &_Py_ID(__typing_unpacked_tuple_args__), &result) > 0) { @@ -459,8 +455,7 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje for (Py_ssize_t iarg = 0, jarg = 0; iarg < nargs; iarg++) { PyObject *arg = PyTuple_GET_ITEM(args, iarg); if (PyType_Check(arg)) { - Py_INCREF(arg); - PyTuple_SET_ITEM(newargs, jarg, arg); + PyTuple_SET_ITEM(newargs, jarg, Py_NewRef(arg)); jarg++; continue; } @@ -767,8 +762,7 @@ ga_parameters(PyObject *self, void *unused) return NULL; } } - Py_INCREF(alias->parameters); - return alias->parameters; + return Py_NewRef(alias->parameters); } static PyObject * @@ -776,8 +770,7 @@ ga_unpacked_tuple_args(PyObject *self, void *unused) { gaobject *alias = (gaobject *)self; if (alias->starred && alias->origin == (PyObject *)&PyTuple_Type) { - Py_INCREF(alias->args); - return alias->args; + return Py_NewRef(alias->args); } Py_RETURN_NONE; } @@ -803,8 +796,7 @@ setup_ga(gaobject *alias, PyObject *origin, PyObject *args) { Py_INCREF(args); } - Py_INCREF(origin); - alias->origin = origin; + alias->origin = Py_NewRef(origin); alias->args = args; alias->parameters = NULL; alias->weakreflist = NULL; |