From bug-octave-request at bevo dot che dot wisc dot edu Thu Apr 19 14:43:30 2001 Subject: eval() tramples on __error_text__ From: "John W. Eaton" To: Christoph Spiel Cc: bug-octave at bevo dot che dot wisc dot edu Date: Thu, 19 Apr 2001 14:43:18 -0500 On 19-Apr-2001, Christoph Spiel wrote: | After John provided such a magnificent fix for | setting __error_text__ in a catch block, I have | looked at the behavior of the catch-string in | eval(). While | | try clear a; a; catch e=__error_text__; end_try_catch; e | | now works, | | eval("clear a; a;", "e=__error_text__"); e | | does not: | | octave:1> try clear a; a; catch e=__error_text__; end_try_catch; e | e = `a' undefined near line 1 column 14 | | octave:2> eval("clear a; a;", "e=__error_text__;"); e | e = | octave:3> Please try the following patch. Thanks, jwe 2001-04-19 John W. Eaton * parse.y (fold (tree_binary_expression *)): Set discard_error_messages here instead of buffer_error_messages. Don't add clear_global_error_variable to the unwind_protect stack. (fold (tree_unary_expression *)): Likewise. (finish_colon_expression): Likewise. (finish_matrix): Likewise. * error.cc (panic): Set discard_error_messages to false here. (verror): Return immediately if discard_error_messages is true. * error.cc (discard_error_messages): New global variable. * error.h: Provide declaration. Index: error.h =================================================================== RCS file: /usr/local/cvsroot/octave/src/error.h,v retrieving revision 1.27 diff -u -r1.27 error.h --- error.h 2001/04/18 03:44:30 1.27 +++ error.h 2001/04/19 19:40:53 at @ -47,6 +47,9 @@ // the `unwind_protect' statement. extern bool buffer_error_messages; +// TRUE means error messages are turned off. +extern bool discard_error_messages; + #endif /* Index: error.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/error.cc,v retrieving revision 1.81 diff -u -r1.81 error.cc --- error.cc 2001/04/18 03:44:30 1.81 +++ error.cc 2001/04/19 19:40:58 at @ -68,6 +68,9 @@ // the `unwind_protect' statement. bool buffer_error_messages = false; +// TRUE means error messages are turned off. +bool discard_error_messages = false; + // The message buffer. static std::ostrstream *error_message_buffer = 0; at @ -99,6 +102,9 @@ static void verror (const char *name, const char *fmt, va_list args) { + if (discard_error_messages) + return; + if (! buffer_error_messages) flush_octave_stdout (); at @ -358,6 +364,7 @@ va_list args; va_start (args, fmt); buffer_error_messages = false; + discard_error_messages = false; verror ("panic", fmt, args); va_end (args); abort (); Index: parse.y =================================================================== RCS file: /usr/local/cvsroot/octave/src/parse.y,v retrieving revision 1.164 diff -u -r1.164 parse.y --- parse.y 2001/02/26 20:26:15 1.164 +++ parse.y 2001/04/19 19:41:21 at @ -1654,11 +1654,9 @@ unwind_protect_int (error_state); - unwind_protect_bool (buffer_error_messages); - buffer_error_messages = true; + unwind_protect_bool (discard_error_messages); + discard_error_messages = true; - unwind_protect::add (clear_global_error_variable, 0); - tree_expression *op1 = e->lhs (); tree_expression *op2 = e->rhs (); at @ -1703,11 +1701,9 @@ unwind_protect::begin_frame ("fold_unary_expression"); unwind_protect_int (error_state); - - unwind_protect_bool (buffer_error_messages); - buffer_error_messages = true; - unwind_protect::add (clear_global_error_variable, 0); + unwind_protect_bool (discard_error_messages); + discard_error_messages = true; tree_expression *op = e->operand (); at @ -1754,11 +1750,9 @@ unwind_protect::begin_frame ("finish_colon_expression"); unwind_protect_int (error_state); - - unwind_protect_bool (buffer_error_messages); - buffer_error_messages = true; - unwind_protect::add (clear_global_error_variable, 0); + unwind_protect_bool (discard_error_messages); + discard_error_messages = true; tree_expression *base = e->base (); tree_expression *limit = e->limit (); at @ -2633,11 +2627,9 @@ unwind_protect_int (error_state); - unwind_protect_bool (buffer_error_messages); - buffer_error_messages = true; + unwind_protect_bool (discard_error_messages); + discard_error_messages = true; - unwind_protect::add (clear_global_error_variable, 0); - if (m->all_elements_are_constant ()) { octave_value tmp = m->rvalue (); at @ -3528,7 +3520,9 @@ // errors that occurred in the first part of this eval(). buffer_error_messages = false; + bind_global_error_variable (); + unwind_protect::add (clear_global_error_variable, 0); eval_string (args(1), 0, parse_status, nargout); ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------