X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fpython-systemd%2Fid128.c;h=6dadf7b2fd14d3770a73e9ccbf6a239afa702eb3;hb=136aa3b444ab5025ebb265b056c5c7ef55688774;hp=f82b0afb9900766eb92affe5005fc817c792001e;hpb=927e96326c195ad39a45b091f98e9c635f400982;p=elogind.git diff --git a/src/python-systemd/id128.c b/src/python-systemd/id128.c index f82b0afb9..6dadf7b2f 100644 --- a/src/python-systemd/id128.c +++ b/src/python-systemd/id128.c @@ -23,43 +23,39 @@ #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" +#include "log.h" +#include "util.h" +#include "macro.h" PyDoc_STRVAR(module__doc__, "Python interface to the libsystemd-id128 library.\n\n" "Provides SD_MESSAGE_* constants and functions to query and generate\n" - "128bit unique identifiers." + "128-bit unique identifiers." ); PyDoc_STRVAR(randomize__doc__, "randomize() -> UUID\n\n" - "Return a new random 128bit unique identifier.\n" + "Return a new random 128-bit unique identifier.\n" "Wraps sd_id128_randomize(3)." ); PyDoc_STRVAR(get_machine__doc__, "get_machine() -> UUID\n\n" - "Return a 128bit unique identifier for this machine.\n" + "Return a 128-bit unique identifier for this machine.\n" "Wraps sd_id128_get_machine(3)." ); PyDoc_STRVAR(get_boot__doc__, "get_boot() -> UUID\n\n" - "Return a 128bit unique identifier for this boot.\n" + "Return a 128-bit unique identifier for this boot.\n" "Wraps sd_id128_get_boot(3)." ); static PyObject* make_uuid(sd_id128_t id) { - PyObject _cleanup_Py_DECREF_ + _cleanup_Py_DECREF_ PyObject *uuid = NULL, *UUID = NULL, *bytes = NULL, - *args = NULL, *kwargs = NULL, *obj = NULL; + *args = NULL, *kwargs = NULL; uuid = PyImport_ImportModule("uuid"); if (!uuid) @@ -106,20 +102,18 @@ 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 -#pragma GCC diagnostic ignored "-Wmissing-prototypes" - #if PY_MAJOR_VERSION < 3 +DISABLE_WARNING_MISSING_PROTOTYPES; PyMODINIT_FUNC initid128(void) { PyObject *m; @@ -127,8 +121,13 @@ PyMODINIT_FUNC initid128(void) { if (m == NULL) return; + /* a series of lines like 'add_id() ;' follow */ +#define JOINER ; #include "id128-constants.h" +#undef JOINER + PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION); } +REENABLE_WARNING; #else @@ -136,10 +135,11 @@ static struct PyModuleDef module = { 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 }; +DISABLE_WARNING_MISSING_PROTOTYPES; PyMODINIT_FUNC PyInit_id128(void) { PyObject *m; @@ -147,11 +147,17 @@ 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 + PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) { + Py_DECREF(m); + return NULL; + } return m; } +REENABLE_WARNING; #endif - -#pragma GCC diagnostic pop