[PATCH] Create assertion function to return PyErrors.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 dmraid.c    |    8 ++++++++
 pyhelpers.h |   20 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/dmraid.c b/dmraid.c
index b9121f4..02c6615 100644
--- a/dmraid.c
+++ b/dmraid.c
@@ -577,6 +577,8 @@ pydmraid_raidset_repr_method(PyObject *self)
 static PyObject *
 pydmraid_raidset_get_children(PyObject *self, void *data)
 {
+	PYBLOCK_RS_CTX_CHECK(((PydmraidRaidSetObject *)self), return NULL);
+
 	PydmraidRaidSetObject *set = (PydmraidRaidSetObject *)self;
 	struct lib_context *lc = set->ctx->lc;
 	PyObject *t;
@@ -645,6 +647,8 @@ pydmraid_raidset_get_spares(PyObject *self, void *data)
 static PyObject *
 pydmraid_raidset_get_table(PyObject *self, void *data)
 {
+	PYBLOCK_RS_CTX_CHECK(((PydmraidRaidSetObject *)self), return NULL);
+
 	PydmraidRaidSetObject *set = (PydmraidRaidSetObject *)self;
 	struct lib_context *lc = set->ctx->lc;
 	struct raid_set *rs = set->rs;
@@ -699,6 +703,8 @@ pydmraid_raidset_get_table(PyObject *self, void *data)
 static PyObject *
 pydmraid_raidset_get_dm_table(PyObject *self, void *data)
 {
+	PYBLOCK_RS_CTX_CHECK(((PydmraidRaidSetObject *)self), return NULL);
+
 	PydmraidRaidSetObject *set = (PydmraidRaidSetObject *)self;
 	struct lib_context *lc = set->ctx->lc;
 	struct raid_set *rs = set->rs;
@@ -899,6 +905,8 @@ out:
 static PyObject *
 pydmraid_raidset_get(PyObject *self, void *data)
 {
+	PYBLOCK_RS_CTX_CHECK(((PydmraidRaidSetObject *)self), return NULL);
+
 	PydmraidRaidSetObject *set = (PydmraidRaidSetObject *)self;
 	struct lib_context *lc = set->ctx->lc;
 	struct raid_set *rs = set->rs;
diff --git a/pyhelpers.h b/pyhelpers.h
index 7822981..af5b31a 100644
--- a/pyhelpers.h
+++ b/pyhelpers.h
@@ -19,6 +19,26 @@
 #ifndef _PYBLOCK_PYHELPERS_H
 #define _PYBLOCK_PYHELPERS_H 1
 
+#define PYBLOCK_ASSERT(cond, message, action)\
+	if(!(cond)){\
+		PyErr_SetString(PyExc_AssertionError, message);\
+		action;\
+	}
+
+/*
+ * ASSERT the non-NULL state of pyblock raidset structure, dmraid raidset
+ * structure, pyblock context structure and dmraid context structure.
+ */
+#define PYBLOCK_RS_CTX_CHECK(pyblock_rs, action)\
+	PYBLOCK_ASSERT(pyblock_rs != NULL,\
+			"The pyblock raidset structure is NULL.", action);\
+	PYBLOCK_ASSERT(pyblock_rs->rs != NULL,\
+			"The raidset dmraid structure is NULL.", action);\
+	PYBLOCK_ASSERT(pyblock_rs->ctx != NULL,\
+			"The pyblock context is NULL.", action);\
+	PYBLOCK_ASSERT(pyblock_rs->ctx->lc != NULL,\
+			"The dmraid context is NULL.", action);
+
 extern PyObject *
 pyblock_PyString_FromFormatV(const char *format, va_list)
 	__attribute__ ((format(printf, 1, 0)));
-- 
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux