Mercurial > hgrepos > Python > libs > ConfigMix
changeset 563:2c211934d4b0
Some more helper functions (with regard to NULL PyObjects)
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 06 Jan 2022 20:37:29 +0100 |
| parents | f75c5b13a1d7 |
| children | 44e18fbf7741 |
| files | configmix/_py_helper.h |
| diffstat | 1 files changed, 27 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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);
