From b18744e8e78c1009142f10103c11568c58c6a8ef Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 13 Feb 2014 03:13:11 +0200 Subject: [PATCH] Add py_assert helper macros --- src/py/py_assert.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/py/py_assert.h diff --git a/src/py/py_assert.h b/src/py/py_assert.h new file mode 100644 index 000000000..ce17b2b3c --- /dev/null +++ b/src/py/py_assert.h @@ -0,0 +1,25 @@ +#ifndef __PY_ASSERT_H__ +#define __PY_ASSERT_H__ +#define PY_ASSERT_TRUE(cond) \ + do { \ + if ((cond) ==0){ \ + nlr_jump(mp_obj_new_exception_msg( \ + MP_QSTR_OSError, \ + "Operation not supported")); \ + } \ + } while(0) + +#define PY_ASSERT_TYPE(obj, type) \ + do { \ + __typeof__ (obj) _a = (obj); \ + __typeof__ (type) _b = (type); \ + if (!MP_OBJ_IS_TYPE(_a, _b)) { \ + nlr_jump(mp_obj_new_exception_msg_varg( \ + MP_QSTR_TypeError, \ + "can't convert %s to %s", \ + mp_obj_get_type_str(_a), \ + _b->name)); \ + } \ + } while(0) + +#endif /* __PY_ASSERT_H__ */