X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fpython-systemd%2Fid128.c;h=a6711a5bd5f6b6a24f00a0eaf80a979a312d601e;hb=082cca735b831228a465e9c8e3af65d239b286af;hp=04db786b66dc649c359ee9cfd1d776d2b3e5e5aa;hpb=2c07646764384545e5303222729d5ff93dec4347;p=elogind.git diff --git a/src/python-systemd/id128.c b/src/python-systemd/id128.c index 04db786b6..a6711a5bd 100644 --- a/src/python-systemd/id128.c +++ b/src/python-systemd/id128.c @@ -19,18 +19,13 @@ along with systemd; If not, see . ***/ +#include + #include #include -#define _cleanup_Py_DECREF_ __attribute__((cleanup(cleanup_Py_DECREFp))) - -static void cleanup_Py_DECREFp(PyObject **p) { - if (!*p) - return; - - Py_DECREF(*p); -} +#include "pyutil.h" PyDoc_STRVAR(module__doc__, "Python interface to the libsystemd-id128 library.\n\n" @@ -106,13 +101,13 @@ static PyMethodDef methods[] = { }; static int add_id(PyObject *module, const char* name, sd_id128_t id) { - PyObject _cleanup_Py_DECREF_ *obj; + PyObject *obj; obj = make_uuid(id); if (!obj) return -1; - return PyObject_SetAttrString(module, name, obj); + return PyModule_AddObject(module, name, obj); } #pragma GCC diagnostic push @@ -127,7 +122,10 @@ PyMODINIT_FUNC initid128(void) { if (m == NULL) return; + /* a series of lines like 'add_id() ;' follow */ +#define JOINER ; #include "id128-constants.h" +#undef JOINER } #else @@ -147,7 +145,14 @@ PyMODINIT_FUNC PyInit_id128(void) { if (m == NULL) return NULL; + if ( /* a series of lines like 'add_id() ||' follow */ +#define JOINER || #include "id128-constants.h" +#undef JOINER + false) { + Py_DECREF(m); + return NULL; + } return m; }