From: Amit Bawer <abawer(a)redhat.com>
Allow to pass it PyExc_XXX object as well for raising different
exception types along with message and tested object for printout.
---
python/sanlock.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 5d228e8..cec5c9b 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -33,11 +33,11 @@
#define MODULE_NAME "sanlock"
/* Functions prototypes */
static void __set_exception(int en, char *msg) __sets_exception;
static int __parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
__neg_sets_exception;
-static void set_value_error(const char* format, PyObject* obj);
+static void set_error(PyObject *exception, const char* format, PyObject* obj);
/* Sanlock module */
PyDoc_STRVAR(pydoc_sanlock, "\
Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved.\n\
This copyrighted material is made available to anyone wishing to use,\n\
@@ -129,18 +129,18 @@ __parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
uint64_t offset;
disk = PyList_GetItem(obj, i);
if (!PyTuple_Check(disk)) {
- set_value_error("Invalid disk %s", disk);
+ set_error(PyExc_ValueError, "Invalid disk %s", disk);
goto exit_fail;
}
if (!PyArg_ParseTuple(disk, "sK", &path, &offset)) {
/* Override the error since it confusing in this context. */
- set_value_error("Invalid disk %s", disk);
+ set_error(PyExc_ValueError, "Invalid disk %s", disk);
goto exit_fail;
}
strncpy(res->disks[i].path, path, SANLK_PATH_LEN - 1);
res->disks[i].offset = offset;
@@ -202,17 +202,17 @@ add_align_flag(long align, uint32_t *flags)
}
return 0;
}
static void
-set_value_error(const char* format, PyObject* obj)
+set_error(PyObject* exception, const char* format, PyObject* obj)
{
const char* str_rep = "";
PyObject* rep = PyObject_Repr(obj);
if (rep)
str_rep = pystring_as_cstring(rep);
- PyErr_Format(PyExc_ValueError, format, str_rep);
+ PyErr_Format(exception, format, str_rep);
Py_XDECREF(rep);
}
static PyObject *
__hosts_to_list(struct sanlk_host *hss, int hss_count)
--
2.17.2