This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit d7eaa34ac37d1c9ec5676c1432c74bb445d2bd51
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 17:33:05 2019 +0300
python: Use PyBytes converter for read_resource_owners API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 0964671..ed9b4f0 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1228,10 +1228,10 @@ Sector can be one of (512, 4096).");
static PyObject *
py_read_resource_owners(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, hss_count = 0;
+ int rv = -1, hss_count = 0;
int sector = SECTOR_SIZE_512;
long align = ALIGNMENT_1M;
- const char *lockspace, *resource;
+ PyObject *lockspace = NULL, *resource = NULL;
struct sanlk_resource *res = NULL;
struct sanlk_host *hss = NULL;
PyObject *disks, *ls_list = NULL;
@@ -1240,27 +1240,28 @@ py_read_resource_owners(PyObject *self __unused, PyObject *args,
PyObject *keywd
"sector", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|li", kwlist,
- &lockspace, &resource, &PyList_Type, &disks, &align,
§or)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|li",
kwlist,
+ convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
+ &PyList_Type, &disks, &align, §or)) {
+ 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);
/* set resource alignment and sector flags */
if (add_align_flag(align, &res->flags) == -1)
- goto exit_fail;
+ goto finally;
if (add_sector_flag(sector, &res->flags) == -1)
- goto exit_fail;
+ goto finally;
/* read resource owners (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -1269,14 +1270,18 @@ py_read_resource_owners(PyObject *self __unused, PyObject *args,
PyObject *keywd
if (rv != 0) {
__set_exception(rv, "Unable to read resource owners");
- goto exit_fail;
+ goto finally;
}
ls_list = __hosts_to_list(hss, hss_count);
-exit_fail:
- if (res) free(res);
- if (hss) free(hss);
+finally:
+ Py_XDECREF(lockspace);
+ Py_XDECREF(resource);
+ free(res);
+ free(hss);
+ if (rv != 0)
+ return NULL;
return ls_list;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.