diff options
author | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 2003-05-12 20:46:52 +0000 |
---|---|---|
committer | Mikael Djurfeldt <djurfeldt@nada.kth.se> | 2003-05-12 20:46:52 +0000 |
commit | dfd03fb91b66599064c51c2924ead945b00852c5 (patch) | |
tree | f62ff3e0e588f50477cd44d38f800a523f848c94 /libguile/backtrace.c | |
parent | 7aaf8dc9f768bce59b295fc09df50ed5cd7efdf1 (diff) | |
download | guile-dfd03fb91b66599064c51c2924ead945b00852c5.tar.gz |
* backtrace.c (scm_display_error_message): Introduced fancy
printing with max level 7 and length 10. (Purpose: avoid printing
gigantic objects in error messages.)
* print.c, print.h (scm_i_port_with_print_state): New function.
* print.c (scm_iprin1, scm_printer_apply,
scm_port_with_print_state): Use scm_i_port_with_print_state.
(scm_simple_format): Modified not to destroy print states.
(print_state_mutex): New mutex.
(scm_make_print_state, scm_free_print_state, scm_prin1):
Lock/unlock print_state_mutex.
Diffstat (limited to 'libguile/backtrace.c')
-rw-r--r-- | libguile/backtrace.c | 89 |
1 files changed, 75 insertions, 14 deletions
diff --git a/libguile/backtrace.c b/libguile/backtrace.c index 4ec2895b0..f73c80dcc 100644 --- a/libguile/backtrace.c +++ b/libguile/backtrace.c @@ -1,5 +1,5 @@ /* Printing of backtraces and error messages - * Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation + * Copyright (C) 1996,1997,1998,1999,2000,2001, 2003 Free Software Foundation * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -40,6 +40,7 @@ #include "libguile/fluids.h" #include "libguile/ports.h" #include "libguile/strings.h" +#include "libguile/dynwind.h" #include "libguile/validate.h" #include "libguile/lang.h" @@ -47,11 +48,22 @@ #include "libguile/filesys.h" /* {Error reporting and backtraces} - * (A first approximation.) * * Note that these functions shouldn't generate errors themselves. */ +/* Print parameters for error messages. */ + +#define DISPLAY_ERROR_MESSAGE_MAX_LEVEL 7 +#define DISPLAY_ERROR_MESSAGE_MAX_LENGTH 10 + +/* Print parameters for failing expressions in error messages. + * (See also `print_params' below for backtrace print parameters.) + */ + +#define DISPLAY_EXPRESSION_MAX_LEVEL 2 +#define DISPLAY_EXPRESSION_MAX_LENGTH 3 + #undef SCM_ASSERT #define SCM_ASSERT(_cond, _arg, _pos, _subr) \ if (!(_cond)) \ @@ -91,19 +103,68 @@ display_header (SCM source, SCM port) } +struct display_error_message_data { + SCM message; + SCM args; + SCM port; + scm_print_state *pstate; + int old_fancyp; + int old_level; + int old_length; +}; + +static SCM +display_error_message (struct display_error_message_data *d) +{ + if (SCM_STRINGP (d->message) && !SCM_FALSEP (scm_list_p (d->args))) + scm_simple_format (d->port, d->message, d->args); + else + scm_display (d->message, d->port); + scm_newline (d->port); + return SCM_UNSPECIFIED; +} + +static void +before_display_error_message (struct display_error_message_data *d) +{ + scm_print_state *pstate = d->pstate; + d->old_fancyp = pstate->fancyp; + d->old_level = pstate->level; + d->old_length = pstate->length; + pstate->fancyp = 1; + pstate->level = DISPLAY_ERROR_MESSAGE_MAX_LEVEL; + pstate->length = DISPLAY_ERROR_MESSAGE_MAX_LENGTH; +} + +static void +after_display_error_message (struct display_error_message_data *d) +{ + scm_print_state *pstate = d->pstate; + pstate->fancyp = d->old_fancyp; + pstate->level = d->old_level; + pstate->length = d->old_length; +} + void scm_display_error_message (SCM message, SCM args, SCM port) { - if (SCM_STRINGP (message) && !SCM_FALSEP (scm_list_p (args))) - { - scm_simple_format (port, message, args); - scm_newline (port); - } - else - { - scm_display (message, port); - scm_newline (port); - } + struct display_error_message_data d; + SCM print_state; + scm_print_state *pstate; + + port = scm_i_port_with_print_state (port, SCM_UNDEFINED); + print_state = SCM_PORT_WITH_PS_PS (port); + pstate = SCM_PRINT_STATE (print_state); + + d.message = message; + d.args = args; + d.port = port; + d.pstate = pstate; + scm_internal_dynamic_wind ((scm_t_guard) before_display_error_message, + (scm_t_inner) display_error_message, + (scm_t_guard) after_display_error_message, + &d, + &d); } static void @@ -113,8 +174,8 @@ display_expression (SCM frame, SCM pname, SCM source, SCM port) scm_print_state *pstate = SCM_PRINT_STATE (print_state); pstate->writingp = 0; pstate->fancyp = 1; - pstate->level = 2; - pstate->length = 3; + pstate->level = DISPLAY_EXPRESSION_MAX_LEVEL; + pstate->length = DISPLAY_EXPRESSION_MAX_LENGTH; if (SCM_SYMBOLP (pname) || SCM_STRINGP (pname)) { if (SCM_FRAMEP (frame) |