[pypy-issue] Issue #2599: Py_XINCREF/Py_XDECREF use argument twice (pypy/pypy)

Marian Beermann issues-reply at bitbucket.org
Sun Jul 2 09:13:14 EDT 2017


New issue 2599: Py_XINCREF/Py_XDECREF use argument twice
https://bitbucket.org/pypy/pypy/issues/2599/py_xincref-py_xdecref-use-argument-twice

Marian Beermann:

This isn't documented, but in CPython these are implemented to never use the macro's argument twice:

```
#define Py_XDECREF(op)                                \
    do {                                              \
        PyObject *_py_xdecref_tmp = (PyObject *)(op); \
        if (_py_xdecref_tmp != NULL)                  \
            Py_DECREF(_py_xdecref_tmp);               \
    } while (0)
```

PyPy does:

```
#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
```

I didn't notice this in my code, and it's bad style (and I'll fix it in my code ;), but Google suggests that writing `Py_XDECREF(PyObject_CallMethod(...` is somewhat common.




More information about the pypy-issue mailing list