summaryrefslogtreecommitdiff
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-10-26 14:35:00 +0200
committerGitHub <noreply@github.com>2018-10-26 14:35:00 +0200
commitb4435e20a92af474f117b78b98ddc6f515363af5 (patch)
tree4383bfb9ba3f9ec21a2d0cbdd726b38c5a9e1956 /Include
parent7cd25434164882c2093ea41ccfc7b95a05cd5cbd (diff)
downloadcpython-git-b4435e20a92af474f117b78b98ddc6f515363af5.tar.gz
bpo-35059: Convert PyObject_INIT() to function (GH-10077)
* Convert PyObject_INIT() and PyObject_INIT_VAR() macros to static inline functions. * Fix usage of these functions: cast to PyObject* or PyVarObject*.
Diffstat (limited to 'Include')
-rw-r--r--Include/objimpl.h29
1 files changed, 23 insertions, 6 deletions
diff --git a/Include/objimpl.h b/Include/objimpl.h
index 4eeb8dfe50..6ce6455040 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -138,12 +138,29 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
#define PyObject_NewVar(type, typeobj, n) \
( (type *) _PyObject_NewVar((typeobj), (n)) )
-/* Macros trading binary compatibility for speed. See also pymem.h.
- Note that these macros expect non-NULL object pointers.*/
-#define PyObject_INIT(op, typeobj) \
- ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
-#define PyObject_INIT_VAR(op, typeobj, size) \
- ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
+/* Inline functions trading binary compatibility for speed:
+ PyObject_INIT() is the fast version of PyObject_Init(), and
+ PyObject_INIT_VAR() is the fast version of PyObject_InitVar.
+ See also pymem.h.
+
+ These inline functions expect non-NULL object pointers. */
+Py_STATIC_INLINE(PyObject*)
+PyObject_INIT(PyObject *op, PyTypeObject *typeobj)
+{
+ assert(op != NULL);
+ Py_TYPE(op) = typeobj;
+ _Py_NewReference(op);
+ return op;
+}
+
+Py_STATIC_INLINE(PyVarObject*)
+PyObject_INIT_VAR(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
+{
+ assert(op != NULL);
+ Py_SIZE(op) = size;
+ PyObject_INIT((PyObject *)op, typeobj);
+ return op;
+}
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )