mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
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.
This commit is contained in:
parent
d8f239d86e
commit
231d83b724
10 changed files with 169 additions and 327 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue