[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sanlock-devel
Subject:    [sanlock] 01/08: python: Use Py_BuildValue to create event dicts
From:       pagure () pagure ! io
Date:       2019-06-25 15:53:33
Message-ID: 20190625155332.532612547045 () pagure01 ! fedoraproject ! org
[Download RAW message or body]

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@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@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.
_______________________________________________
sanlock-devel mailing list -- sanlock-devel@lists.fedorahosted.org
To unsubscribe send an email to sanlock-devel-leave@lists.fedorahosted.org
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedorahosted.org/archives/list/sanlock-devel@lists.fedorahosted.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic