From b4435e20a92af474f117b78b98ddc6f515363af5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 26 Oct 2018 14:35:00 +0200 Subject: 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*. --- Include/objimpl.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'Include/objimpl.h') 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 ) -- cgit v1.2.1