mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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:
parent
4ce2a202c7
commit
c0feb99187
9 changed files with 77 additions and 156 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue