From c8b80e4740baa0f3bdf025a23f92c3a1ff2bf6fc Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky <pfalcon@users.sourceforge.net> Date: Sat, 30 Jul 2016 00:35:50 +0300 Subject: [PATCH] lib/embed/abort_: Implementation of abort_() function raising uPy exception. Helpful when porting existing C libraries to MicroPython. abort()ing in embedded environment isn't a good idea, so when compiling such library, -Dabort=abort_ option can be given to redirect standard abort() to this "safe" version. --- lib/embed/abort_.c | 5 +++++ py/py.mk | 1 + 2 files changed, 6 insertions(+) create mode 100644 lib/embed/abort_.c diff --git a/lib/embed/abort_.c b/lib/embed/abort_.c new file mode 100644 index 000000000..b54d08f2c --- /dev/null +++ b/lib/embed/abort_.c @@ -0,0 +1,5 @@ +#include <py/runtime.h> + +void abort_(void) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "abort() called")); +} diff --git a/py/py.mk b/py/py.mk index 678150429..948d7a67f 100644 --- a/py/py.mk +++ b/py/py.mk @@ -221,6 +221,7 @@ PY_O_BASENAME = \ ../extmod/vfs_fat_lexer.o \ ../extmod/vfs_fat_misc.o \ ../extmod/moduos_dupterm.o \ + ../lib/embed/abort_.o \ # prepend the build destination prefix to the py object files PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME)) -- GitLab