This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit aafbc4d719ce3a2b87fa5326f062189f0b6ed9df
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sat May 18 16:40:01 2019 +0300
python: Refactor build of dictionary entries for py_read_lockspace
Use Py_BuildValue("{...}",...) for creating dictionary information
for lockspace.
Using helper to determine the build value format:
- Py2: Handle lockspace name as PyString with "s" format.
- Py3: Handle lockspace name as PyBytes with "y" format.
Current status:
- Py2: will build and pass tests.
- Py3: will fail to build for missing respective API calls.
---
python/sanlock.c | 37 ++++++++++++-------------------------
1 file changed, 12 insertions(+), 25 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index e4b1407..5870081 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -475,7 +475,7 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
uint32_t io_timeout = 0;
const char *path;
struct sanlk_lockspace ls;
- PyObject *ls_info = NULL, *ls_entry = NULL;
+ PyObject *ls_info = NULL;
static char *kwlist[] = {"path", "offset", "align",
"sector", NULL};
@@ -508,33 +508,20 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
return NULL;
}
- /* prepare the dictionary holding the information */
- if ((ls_info = PyDict_New()) == NULL)
- goto exit_fail;
-
- /* fill the dictionary information: lockspace */
- if ((ls_entry = PyString_FromString(ls.name)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_info, "lockspace", ls_entry);
- Py_DECREF(ls_entry);
- if (rv != 0)
- goto exit_fail;
-
- /* fill the dictionary information: iotimeout */
- if ((ls_entry = PyInt_FromLong(io_timeout)) == NULL)
- goto exit_fail;
- rv = PyDict_SetItemString(ls_info, "iotimeout", ls_entry);
- Py_DECREF(ls_entry);
- if (rv != 0)
- goto exit_fail;
+ /* fill the information dictionary */
+ ls_info = Py_BuildValue(
+#if PY_MAJOR_VERSION == 2
+ "{s:s,s:I}",
+#else
+ "{s:y,s:I}",
+#endif
+ "lockspace", ls.name,
+ "iotimeout", io_timeout);
+ if (ls_info == NULL)
+ return NULL;
/* success */
return ls_info;
-
- /* failure */
-exit_fail:
- Py_XDECREF(ls_info);
- return NULL;
}
/* read_resource */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.