This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master in repository sanlock.
commit 520b21849bff16c7bff3a0be8e6816549ce56242 Author: Amit Bawer abawer@redhat.com AuthorDate: Sun Jun 2 17:04:56 2019 +0300
python: Use PyBytes converter for resource release API
Implications:
- Py2 : no difference - Py3 : if used, only accept bytes for lockspace/resource name. --- python/sanlock.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index 7bdbd69..b43d635 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -1103,28 +1103,29 @@ The disks must be in the format: [(path, offset), ... ]"); static PyObject * py_release(PyObject *self __unused, PyObject *args, PyObject *keywds) { - int rv, sanlockfd = -1, pid = -1; - const char *lockspace, *resource; - struct sanlk_resource *res; + int rv = -1, sanlockfd = -1, pid = -1; + PyObject *lockspace = NULL, *resource = NULL; + struct sanlk_resource *res = NULL; PyObject *disks;
static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd", "pid", NULL};
/* parse python tuple */ - if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|ii", kwlist, - &lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid)) { - return NULL; + if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|ii", kwlist, + convert_to_pybytes, &lockspace, convert_to_pybytes, &resource, + &PyList_Type, &disks, &sanlockfd, &pid)) { + goto finally; }
/* parse and check sanlock resource */ if (__parse_resource(disks, &res) < 0) { - return NULL; + goto finally; }
/* prepare sanlock names */ - strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN); - strncpy(res->name, resource, SANLK_NAME_LEN); + strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN); + strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
/* release sanlock resource (gil disabled) */ Py_BEGIN_ALLOW_THREADS @@ -1133,15 +1134,16 @@ py_release(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) { __set_exception(rv, "Sanlock resource not released"); - goto exit_fail; + goto finally; }
+finally: + Py_XDECREF(lockspace); + Py_XDECREF(resource); free(res); + if (rv != 0) + return NULL; Py_RETURN_NONE; - -exit_fail: - free(res); - return NULL; }
/* request */
sanlock-devel@lists.fedorahosted.org