bpo-39542: Make PyObject_INIT() opaque in limited C API (GH-18363) · python/cpython@f58bd7c (original) (raw)
`@@ -127,40 +127,21 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
`
127
127
`#define PyObject_NewVar(type, typeobj, n) \
`
128
128
` ( (type *) _PyObject_NewVar((typeobj), (n)) )
`
129
129
``
130
``
`-
/* Inline functions trading binary compatibility for speed:
`
131
``
`-
PyObject_INIT() is the fast version of PyObject_Init(), and
`
132
``
`-
PyObject_INIT_VAR() is the fast version of PyObject_InitVar.
`
133
``
`-
See also pymem.h.
`
134
``
-
135
``
`-
These inline functions expect non-NULL object pointers. */
`
136
``
`-
static inline PyObject*
`
137
``
`-
_PyObject_INIT(PyObject *op, PyTypeObject *typeobj)
`
138
``
`-
{
`
139
``
`-
assert(op != NULL);
`
140
``
`-
Py_TYPE(op) = typeobj;
`
141
``
`-
if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
`
142
``
`-
Py_INCREF(typeobj);
`
143
``
`-
}
`
144
``
`-
_Py_NewReference(op);
`
145
``
`-
return op;
`
146
``
`-
}
`
147
``
-
148
``
`-
#define PyObject_INIT(op, typeobj) \
`
149
``
`-
_PyObject_INIT(_PyObject_CAST(op), (typeobj))
`
``
130
`+
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
`
150
131
``
151
``
`-
static inline PyVarObject*
`
152
``
`-
_PyObject_INIT_VAR(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
`
153
``
`-
{
`
154
``
`-
assert(op != NULL);
`
155
``
`-
Py_SIZE(op) = size;
`
156
``
`-
PyObject_INIT((PyObject *)op, typeobj);
`
157
``
`-
return op;
`
158
``
`-
}
`
159
132
``
160
``
`-
#define PyObject_INIT_VAR(op, typeobj, size) \
`
161
``
`-
_PyObject_INIT_VAR(_PyVarObject_CAST(op), (typeobj), (size))
`
``
133
`+
#ifdef Py_LIMITED_API
`
``
134
`+
/* Define PyObject_INIT() and PyObject_INIT_VAR() as aliases to PyObject_Init()
`
``
135
`+
and PyObject_InitVar() in the limited C API for compatibility with the
`
``
136
`+
CPython C API. */
`
``
137
`+
define PyObject_INIT(op, typeobj) \
`
``
138
`+
PyObject_Init(_PyObject_CAST(op), (typeobj))
`
``
139
`+
define PyObject_INIT_VAR(op, typeobj, size) \
`
``
140
`+
PyObject_InitVar(_PyVarObject_CAST(op), (typeobj), (size))
`
``
141
`+
#else
`
``
142
`+
/* PyObject_INIT() and PyObject_INIT_VAR() are defined in cpython/objimpl.h */
`
``
143
`+
#endif
`
162
144
``
163
``
`-
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
`
164
145
``
165
146
`/* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a
`
166
147
` vrbl-size object with nitems items, exclusive of gc overhead (if any). The
`