diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-10 10:23:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 10:23:36 (GMT) |
commit | 231d83b72435d61e929d6d62f2be7305e7b5b62b (patch) | |
tree | 17768fa10f1ade6bae9022d26e1470fd0b931366 /Python/bltinmodule.c | |
parent | d8f239d86eb70c31aa4c4ac46a1d0a27bdb14b20 (diff) | |
download | cpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.zip cpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.tar.gz cpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.tar.bz2 |
gh-99300: Use Py_NewRef() in Python/ directory (#99317)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in C files of the Python/ directory.
Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 2809b03..b23f52e 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -63,8 +63,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs) } for (j = 0; j < i; j++) { base = args[j]; - PyList_SET_ITEM(new_bases, j, base); - Py_INCREF(base); + PyList_SET_ITEM(new_bases, j, Py_NewRef(base)); } } j = PyList_GET_SIZE(new_bases); @@ -170,8 +169,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } if (winner != meta) { Py_DECREF(meta); - meta = winner; - Py_INCREF(meta); + meta = Py_NewRef(winner); } } /* else: meta is not a class, so we cannot do the metaclass @@ -804,8 +802,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, goto error; if (is_ast) { if (flags & PyCF_ONLY_AST) { - Py_INCREF(source); - result = source; + result = Py_NewRef(source); } else { PyArena *arena; @@ -1128,8 +1125,7 @@ builtin_getattr(PyObject *self, PyObject *const *args, Py_ssize_t nargs) if (nargs > 2) { if (_PyObject_LookupAttr(v, name, &result) == 0) { PyObject *dflt = args[2]; - Py_INCREF(dflt); - return dflt; + return Py_NewRef(dflt); } } else { @@ -1162,8 +1158,7 @@ builtin_globals_impl(PyObject *module) PyObject *d; d = PyEval_GetGlobals(); - Py_XINCREF(d); - return d; + return Py_XNewRef(d); } @@ -1390,12 +1385,10 @@ map_reduce(mapobject *lz, PyObject *Py_UNUSED(ignored)) Py_ssize_t i; if (args == NULL) return NULL; - Py_INCREF(lz->func); - PyTuple_SET_ITEM(args, 0, lz->func); + PyTuple_SET_ITEM(args, 0, Py_NewRef(lz->func)); for (i = 0; i<numargs; i++){ PyObject *it = PyTuple_GET_ITEM(lz->iters, i); - Py_INCREF(it); - PyTuple_SET_ITEM(args, i+1, it); + PyTuple_SET_ITEM(args, i+1, Py_NewRef(it)); } return Py_BuildValue("ON", Py_TYPE(lz), args); @@ -1486,8 +1479,7 @@ builtin_next(PyObject *self, PyObject *const *args, Py_ssize_t nargs) return NULL; PyErr_Clear(); } - Py_INCREF(def); - return def; + return Py_NewRef(def); } else if (PyErr_Occurred()) { return NULL; } else { @@ -1723,8 +1715,7 @@ builtin_locals_impl(PyObject *module) PyObject *d; d = PyEval_GetLocals(); - Py_XINCREF(d); - return d; + return Py_XNewRef(d); } @@ -1785,8 +1776,7 @@ min_max(PyObject *args, PyObject *kwds, int op) } /* no key function; the value is the item */ else { - val = item; - Py_INCREF(val); + val = Py_NewRef(item); } /* maximum value and item are unset; set them */ @@ -1816,8 +1806,7 @@ min_max(PyObject *args, PyObject *kwds, int op) if (maxval == NULL) { assert(maxitem == NULL); if (defaultval != NULL) { - Py_INCREF(defaultval); - maxitem = defaultval; + maxitem = Py_NewRef(defaultval); } else { PyErr_Format(PyExc_ValueError, "%s() arg is an empty sequence", name); @@ -2737,8 +2726,7 @@ zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } for (i=0 ; i < tuplesize ; i++) { - Py_INCREF(Py_None); - PyTuple_SET_ITEM(result, i, Py_None); + PyTuple_SET_ITEM(result, i, Py_NewRef(Py_None)); } /* create zipobject structure */ |