From 50cabdcb8f52b84948263c62e06a4d6f19287444 Mon Sep 17 00:00:00 2001 From: Amit Bawer Date: Jun 03 2019 20:23:59 +0000 Subject: python: Use PyBytes converter for reg_event API Implications: - Py2 : no difference - Py3 : if used, only accept bytes for lockspace name. --- diff --git a/python/sanlock.c b/python/sanlock.c index ed9b4f0..1f2960e 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -1396,21 +1396,26 @@ unregister the event listener using end_event."); static PyObject * py_reg_event(PyObject *self __unused, PyObject *args) { - const char *lockspace = NULL; + PyObject *lockspace = NULL; int fd = -1; - if (!PyArg_ParseTuple(args, "s", &lockspace)) - return NULL; + if (!PyArg_ParseTuple(args, "O&", convert_to_pybytes, &lockspace)) { + goto finally; + } Py_BEGIN_ALLOW_THREADS - fd = sanlock_reg_event(lockspace, NULL /* event */, 0 /* flags */); + fd = sanlock_reg_event(PyBytes_AsString(lockspace), NULL /* event */, 0 /* flags */); Py_END_ALLOW_THREADS if (fd < 0) { __set_exception(fd, "Unable to register event fd"); - return NULL; + goto finally; } +finally: + Py_XDECREF(lockspace); + if (fd < 0) + return NULL; return Py_BuildValue("i", fd); }