[issue35059] Convert Py_INCREF() and PyObject_INIT() to inlined functions

STINNER Victor report at bugs.python.org
Fri Nov 23 10:14:49 EST 2018


STINNER Victor <vstinner at redhat.com> added the comment:

> Drawbacks: Require a specific type can introduce compiler warnings if the caller doesn't pass the proper type (PyObject* or PyVarObject*). _Py_NewReference() and _Py_ForgetReference() seem to be properly used, but not PyObject_INIT() and PyObject_INIT_VAR().

I worked around this issue by adding a macro to cast the argument and declare the static inline function with a different name. Example:

static inline void _Py_INCREF(PyObject *op)
{
    _Py_INC_REFTOTAL;
    op->ob_refcnt++;
}

#define Py_INCREF(op) _Py_INCREF(_PyObject_CAST(op))

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35059>
_______________________________________


More information about the Python-bugs-list mailing list