summaryrefslogtreecommitdiff
path: root/py/obj.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-12-06 14:29:09 +0200
committerDamien George <damien.p.george@gmail.com>2014-12-08 20:25:49 +0000
commit46c3ab20049af16e97863e90e5761fae329f872a (patch)
treecbe6230dcad6972d7d50c6d08c4e4c4da215abb1 /py/obj.c
parentd0caaadaeea48e8f76dca3125a2dea3465a58416 (diff)
modsys: Add sys.print_exception(exc, file=sys.stdout) function.
The function is modeled after traceback.print_exception(), but unbloated, and put into existing module to save overhead on adding another module. Compliant traceback.print_exception() is intended to be implemented in micropython-lib in terms of sys.print_exception(). This change required refactoring mp_obj_print_exception() to take pfenv_t interface arguments. Addresses #751.
Diffstat (limited to 'py/obj.c')
-rw-r--r--py/obj.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/py/obj.c b/py/obj.c
index c869a6546..d2801a396 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -85,31 +85,31 @@ void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) {
}
// helper function to print an exception with traceback
-void mp_obj_print_exception(mp_obj_t exc) {
+void mp_obj_print_exception(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t exc) {
if (mp_obj_is_exception_instance(exc)) {
mp_uint_t n, *values;
mp_obj_exception_get_traceback(exc, &n, &values);
if (n > 0) {
assert(n % 3 == 0);
- printf("Traceback (most recent call last):\n");
+ print(env, "Traceback (most recent call last):\n");
for (int i = n - 3; i >= 0; i -= 3) {
#if MICROPY_ENABLE_SOURCE_LINE
- printf(" File \"%s\", line %d", qstr_str(values[i]), (int)values[i + 1]);
+ print(env, " File \"%s\", line %d", qstr_str(values[i]), (int)values[i + 1]);
#else
- printf(" File \"%s\"", qstr_str(values[i]));
+ print(env, " File \"%s\"", qstr_str(values[i]));
#endif
// the block name can be NULL if it's unknown
qstr block = values[i + 2];
if (block == MP_QSTR_NULL) {
- printf("\n");
+ print(env, "\n");
} else {
- printf(", in %s\n", qstr_str(block));
+ print(env, ", in %s\n", qstr_str(block));
}
}
}
}
- mp_obj_print(exc, PRINT_EXC);
- printf("\n");
+ mp_obj_print_helper(print, env, exc, PRINT_EXC);
+ print(env, "\n");
}
bool mp_obj_is_true(mp_obj_t arg) {