This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit cacc09c02d2c0824ffbb0df9c48ecae703f8da60
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Sun Jun 16 19:44:43 2019 +0300
python: Use Py_BuildValue to create event dicts
Replace complex and error prone code to build event dict with
Py_BuildValue().
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 58 +++++++++-----------------------------------------------
1 file changed, 9 insertions(+), 49 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 9192395..e740f89 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1527,7 +1527,6 @@ py_get_event(PyObject *self __unused, PyObject *args)
uint64_t from_generation;
PyObject *events = NULL;
PyObject *item = NULL;
- PyObject *value = NULL;
int rv;
if (!PyArg_ParseTuple(args, "i", &fd))
@@ -1549,55 +1548,16 @@ py_get_event(PyObject *self __unused, PyObject *args)
goto exit_fail;
}
- if ((item = PyDict_New()) == NULL)
- goto exit_fail;
+ item = Py_BuildValue(
+ "{s:K,s:K,s:K,s:K,s:K,s:K}",
+ "from_host_id", from_host_id,
+ "from_generation", from_generation,
+ "host_id", he.host_id,
+ "generation", he.generation,
+ "event", he.event,
+ "data", he.data);
- /* from_host_id */
- if ((value = PyLong_FromUnsignedLongLong(from_host_id)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(item, "from_host_id", value);
- Py_DECREF(value);
- if (rv != 0)
- goto exit_fail;
-
- /* from_generation */
- if ((value = PyLong_FromUnsignedLongLong(from_generation)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(item, "from_generation", value);
- Py_DECREF(value);
- if (rv != 0)
- goto exit_fail;
-
- /* host_id */
- if ((value = PyLong_FromUnsignedLongLong(he.host_id)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(item, "host_id", value);
- Py_DECREF(value);
- if (rv != 0)
- goto exit_fail;
-
- /* generation */
- if ((value = PyLong_FromUnsignedLongLong(he.generation)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(item, "generation", value);
- Py_DECREF(value);
- if (rv != 0)
- goto exit_fail;
-
- /* event */
- if ((value = PyLong_FromUnsignedLongLong(he.event)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(item, "event", value);
- Py_DECREF(value);
- if (rv != 0)
- goto exit_fail;
-
- /* data */
- if ((value = PyLong_FromUnsignedLongLong(he.data)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(item, "data", value);
- Py_DECREF(value);
- if (rv != 0)
+ if (item == NULL)
goto exit_fail;
if (PyList_Append(events, item) != 0)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
Show replies by thread