# HG changeset patch # User Franz Glasner # Date 1641497849 -3600 # Node ID 2c211934d4b0b39f96b39e96516f9f2eb3095d5c # Parent f75c5b13a1d707e8b63a15a0b8228ecbdc7b7fb5 Some more helper functions (with regard to NULL PyObjects) diff -r f75c5b13a1d7 -r 2c211934d4b0 configmix/_py_helper.h --- a/configmix/_py_helper.h Thu Jan 06 20:13:10 2022 +0100 +++ b/configmix/_py_helper.h Thu Jan 06 20:37:29 2022 +0100 @@ -82,6 +82,19 @@ void py_assign(PyObject **dest, PyObject *src) { + Py_DECREF(*dest); + *dest = Py_NewRef(src); +} + + +/** + * Copy from source to destination and make an owned reference. + * Also clear the destination before. + */ +static inline +void +py_x_assign(PyObject **dest, PyObject *src) +{ Py_XDECREF(*dest); *dest = Py_NewRef(src); } @@ -89,11 +102,24 @@ /** * Copy from source to destination and make an owned reference. + * Also clear the destination before. The source object may be NULL. + */ +static inline +void +py_assign_x(PyObject **dest, PyObject *src) +{ + Py_DECREF(*dest); + *dest = Py_XNewRef(src); +} + + +/** + * Copy from source to destination and make an owned reference. * Also safely clear the destination before. The source object may be NULL. */ static inline void -py_assign_x(PyObject **dest, PyObject *src) +py_x_assign_x(PyObject **dest, PyObject *src) { Py_XDECREF(*dest); *dest = Py_XNewRef(src);