along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <stdbool.h>
+
#include <Python.h>
#include <systemd/sd-messages.h>
-#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"
static PyObject* make_uuid(sd_id128_t id) {
PyObject _cleanup_Py_DECREF_
*uuid = NULL, *UUID = NULL, *bytes = NULL,
- *args = NULL, *kwargs = NULL, *obj = NULL;
+ *args = NULL, *kwargs = NULL;
uuid = PyImport_ImportModule("uuid");
if (!uuid)
};
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
if (m == NULL)
return;
+ /* a series of lines like 'add_id() ;' follow */
+#define JOINER ;
#include "id128-constants.h"
+#undef JOINER
}
#else
PyModuleDef_HEAD_INIT,
"id128", /* name of module */
module__doc__, /* module documentation, may be NULL */
- 0, /* size of per-interpreter state of the module */
+ -1, /* size of per-interpreter state of the module */
methods
};
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;
}