gh-89653: PEP 670: Functions don't cast pointers (#91697)

In the limited C API version 3.11 and newer, the following functions
no longer cast their object pointer argument with _PyObject_CAST() or
_PyObject_CAST_CONST():

* Py_REFCNT(), Py_TYPE(), Py_SIZE()
* Py_SET_REFCNT(), Py_SET_TYPE(), Py_SET_SIZE()
* Py_IS_TYPE()
* Py_INCREF(), Py_DECREF()
* Py_XINCREF(), Py_XDECREF()
* Py_NewRef(), Py_XNewRef()
* PyObject_TypeCheck()
* PyType_Check()
* PyType_CheckExact()

Split Py_DECREF() implementation in 3 versions to make the code more
readable.

Update the xxlimited.c extension, which uses the limited C API
version 3.11, to pass PyObject* to these functions.
This commit is contained in:
Victor Stinner 2022-04-26 00:11:34 +02:00 committed by GitHub
parent 1cd8c29dac
commit 61381d7da1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 119 additions and 56 deletions

View file

@ -110,12 +110,13 @@ newXxoObject(PyObject *module)
/* Xxo finalization */
static int
Xxo_traverse(XxoObject *self, visitproc visit, void *arg)
Xxo_traverse(PyObject *self_obj, visitproc visit, void *arg)
{
// Visit the type
Py_VISIT(Py_TYPE(self));
Py_VISIT(Py_TYPE(self_obj));
// Visit the attribute dict
XxoObject *self = (XxoObject *)self_obj;
Py_VISIT(self->x_attr);
return 0;
}
@ -128,13 +129,14 @@ Xxo_clear(XxoObject *self)
}
static void
Xxo_finalize(XxoObject *self)
Xxo_finalize(PyObject *self_obj)
{
XxoObject *self = (XxoObject *)self_obj;
Py_CLEAR(self->x_attr);
}
static void
Xxo_dealloc(XxoObject *self)
Xxo_dealloc(PyObject *self)
{
Xxo_finalize(self);
PyTypeObject *tp = Py_TYPE(self);