gh-99300: Use Py_NewRef() in Objects/ directory (#99332)

Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in C files of the Objects/ directory.
This commit is contained in:
Victor Stinner 2022-11-10 16:27:32 +01:00 committed by GitHub
parent 4ce2a202c7
commit c0feb99187
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 77 additions and 156 deletions

View file

@ -11,8 +11,7 @@ PyCell_New(PyObject *obj)
op = (PyCellObject *)PyObject_GC_New(PyCellObject, &PyCell_Type);
if (op == NULL)
return NULL;
op->ob_ref = obj;
Py_XINCREF(obj);
op->ob_ref = Py_XNewRef(obj);
_PyObject_GC_TRACK(op);
return (PyObject *)op;
@ -68,8 +67,7 @@ PyCell_Set(PyObject *op, PyObject *value)
return -1;
}
PyObject *old_value = PyCell_GET(op);
Py_XINCREF(value);
PyCell_SET(op, value);
PyCell_SET(op, Py_XNewRef(value));
Py_XDECREF(old_value);
return 0;
}
@ -135,15 +133,13 @@ cell_get_contents(PyCellObject *op, void *closure)
PyErr_SetString(PyExc_ValueError, "Cell is empty");
return NULL;
}
Py_INCREF(op->ob_ref);
return op->ob_ref;
return Py_NewRef(op->ob_ref);
}
static int
cell_set_contents(PyCellObject *op, PyObject *obj, void *Py_UNUSED(ignored))
{
Py_XINCREF(obj);
Py_XSETREF(op->ob_ref, obj);
Py_XSETREF(op->ob_ref, Py_XNewRef(obj));
return 0;
}