mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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:
parent
0fa4f43db0
commit
f58bd7c169
6 changed files with 79 additions and 51 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue