This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 3a71eefe6688fbf3ddf09b698594d290153e392e
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 17:50:11 2019 +0300
python: Use PyBytes converter for set_event API
Also add a stub test for arguments parsing.
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 20 ++++++++++++--------
tests/python_test.py | 6 ++++++
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 8f99227..39a9fb6 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1617,29 +1617,33 @@ with -EBUSY error in this case.\n\
static PyObject *
py_set_event(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- const char *lockspace;
+ PyObject *lockspace = NULL;
struct sanlk_host_event he = {0};
uint32_t flags = 0;
- int rv;
+ int rv = -1;
static char *kwlist[] = {"lockspace", "host_id",
"generation", "event",
"data", "flags", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "sKKK|KI", kwlist,
- &lockspace, &he.host_id, &he.generation, &he.event,
&he.data,
- &flags)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&KKK|KI", kwlist,
+ convert_to_pybytes, &lockspace, &he.host_id, &he.generation,
&he.event,
+ &he.data, &flags)) {
+ goto finally;
}
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_set_event(lockspace, &he, flags);
+ rv = sanlock_set_event(PyBytes_AsString(lockspace), &he, flags);
Py_END_ALLOW_THREADS
if (rv < 0) {
__set_exception(rv, "Unable to set event");
- return NULL;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ if (rv < 0)
+ return NULL;
Py_RETURN_NONE;
}
diff --git a/tests/python_test.py b/tests/python_test.py
index 7406bcb..7093aac 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -607,6 +607,12 @@ def test_end_event_parse_args(no_sanlock_daemon, name):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_set_event_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.set_event(name, 1, 1, 1)
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
def test_init_lockspace_parse_args(no_sanlock_daemon, name):
with raises_sanlock_errno(errno.ENODEV):
sanlock.init_lockspace(name, "path")
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.