bpo-39542: Make PyObject_INIT() opaque in limited C API (GH-18363)

In the limited C API, PyObject_INIT() and PyObject_INIT_VAR() are now
defined as aliases to PyObject_Init() and PyObject_InitVar() to make
their implementation opaque. It avoids to leak implementation details
in the limited C API.

Exclude the following functions from the limited C API, move them
from object.h to cpython/object.h:

* _Py_NewReference()
* _Py_ForgetReference()
* _PyTraceMalloc_NewReference()
* _Py_GetRefTotal()
This commit is contained in:
Victor Stinner 2020-02-05 13:12:19 +01:00 committed by GitHub
parent 0fa4f43db0
commit f58bd7c169
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 51 deletions

View file

@ -139,9 +139,11 @@ Py_DecRef(PyObject *o)
PyObject *
PyObject_Init(PyObject *op, PyTypeObject *tp)
{
if (op == NULL)
/* Any changes should be reflected in PyObject_INIT() macro */
if (op == NULL) {
return PyErr_NoMemory();
/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
}
Py_TYPE(op) = tp;
if (PyType_GetFlags(tp) & Py_TPFLAGS_HEAPTYPE) {
Py_INCREF(tp);
@ -153,9 +155,11 @@ PyObject_Init(PyObject *op, PyTypeObject *tp)
PyVarObject *
PyObject_InitVar(PyVarObject *op, PyTypeObject *tp, Py_ssize_t size)
{
if (op == NULL)
/* Any changes should be reflected in PyObject_INIT_VAR() macro */
if (op == NULL) {
return (PyVarObject *) PyErr_NoMemory();
/* Any changes should be reflected in PyObject_INIT_VAR */
}
Py_SIZE(op) = size;
PyObject_Init((PyObject *)op, tp);
return op;