diff options
author | Victor Stinner <vstinner@python.org> | 2020-02-05 12:12:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-05 12:12:19 (GMT) |
commit | f58bd7c1693fe041f7296a5778d0a11287895648 (patch) | |
tree | 066423d4c91278ace5f1f9159436fc2917ed2af8 /Objects | |
parent | 0fa4f43db086ac3459811cca4ec5201ffbee694a (diff) | |
download | cpython-f58bd7c1693fe041f7296a5778d0a11287895648.zip cpython-f58bd7c1693fe041f7296a5778d0a11287895648.tar.gz cpython-f58bd7c1693fe041f7296a5778d0a11287895648.tar.bz2 |
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()
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Objects/object.c b/Objects/object.c index 1884819..43b838a 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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; |