summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDavid Lechner <david@lechnology.com>2017-09-24 20:15:48 -0500
committerDamien George <damien.p.george@gmail.com>2017-09-26 11:59:11 +1000
commit62849b7010abffb7b0a9c9875930efe7cb77519c (patch)
treedf719db4ca96bffd7bad42f0823feaf9cc30f81a /py
parent9d836fedbdb1d28bdfc4ba475bbdfc1adb3f007a (diff)
downloadmicropython-62849b7010abffb7b0a9c9875930efe7cb77519c.tar.gz
micropython-62849b7010abffb7b0a9c9875930efe7cb77519c.zip
py: Add config option to print warnings/errors to stderr.
This adds a new configuration option to print runtime warnings and errors to stderr. On Unix, CPython prints warnings and unhandled exceptions to stderr, so the unix port here is configured to use this option. The unix port already printed unhandled exceptions on the main thread to stderr. This patch fixes unhandled exceptions on other threads and warnings (issue #2838) not printing on stderr. Additionally, a couple tests needed to be fixed to handle this new behavior. This is done by also capturing stderr when running tests.
Diffstat (limited to 'py')
-rw-r--r--py/modthread.c8
-rw-r--r--py/mpconfig.h5
-rw-r--r--py/warning.c6
3 files changed, 12 insertions, 7 deletions
diff --git a/py/modthread.c b/py/modthread.c
index bf74128e81..cb071d0f86 100644
--- a/py/modthread.c
+++ b/py/modthread.c
@@ -192,10 +192,10 @@ STATIC void *thread_entry(void *args_in) {
// swallow exception silently
} else {
// print exception out
- mp_printf(&mp_plat_print, "Unhandled exception in thread started by ");
- mp_obj_print_helper(&mp_plat_print, args->fun, PRINT_REPR);
- mp_printf(&mp_plat_print, "\n");
- mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(exc));
+ mp_printf(MICROPY_ERROR_PRINTER, "Unhandled exception in thread started by ");
+ mp_obj_print_helper(MICROPY_ERROR_PRINTER, args->fun, PRINT_REPR);
+ mp_printf(MICROPY_ERROR_PRINTER, "\n");
+ mp_obj_print_exception(MICROPY_ERROR_PRINTER, MP_OBJ_FROM_PTR(exc));
}
}
diff --git a/py/mpconfig.h b/py/mpconfig.h
index b93f851d6c..44de3beebe 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -533,6 +533,11 @@ typedef long long mp_longint_impl_t;
#define MICROPY_WARNINGS (0)
#endif
+// This macro is used when printing runtime warnings and errors
+#ifndef MICROPY_ERROR_PRINTER
+#define MICROPY_ERROR_PRINTER (&mp_plat_print)
+#endif
+
// Float and complex implementation
#define MICROPY_FLOAT_IMPL_NONE (0)
#define MICROPY_FLOAT_IMPL_FLOAT (1)
diff --git a/py/warning.c b/py/warning.c
index 46b31ecca7..12d0f9c99b 100644
--- a/py/warning.c
+++ b/py/warning.c
@@ -35,9 +35,9 @@
void mp_warning(const char *msg, ...) {
va_list args;
va_start(args, msg);
- mp_print_str(&mp_plat_print, "Warning: ");
- mp_vprintf(&mp_plat_print, msg, args);
- mp_print_str(&mp_plat_print, "\n");
+ mp_print_str(MICROPY_ERROR_PRINTER, "Warning: ");
+ mp_vprintf(MICROPY_ERROR_PRINTER, msg, args);
+ mp_print_str(MICROPY_ERROR_PRINTER, "\n");
va_end(args);
}