# HG changeset patch # User jwe # Date 949054406 0 # Node ID fc5eac74640d661ad79203db3aa6e7c9c3ec9546 # Parent cbee5fbb696d44fbea7208abb850c8dd4c53c0ef [project @ 2000-01-28 10:13:25 by jwe] diff -r cbee5fbb696d -r fc5eac74640d src/ChangeLog --- a/src/ChangeLog Fri Jan 28 09:14:34 2000 +0000 +++ b/src/ChangeLog Fri Jan 28 10:13:26 2000 +0000 @@ -1,5 +1,16 @@ 2000-01-28 John W. Eaton + * pt-except.cc (do_catch_code): Unwind-protect buffer_error_messages. + Be sure to run all unwind-protects before returning. + (tree_try_catch_command::eval): Add do_catch_code cleanup function + to unwind-protect stack before resetting buffer_error_messages. + Use unwind-protect to save and restore buffer_error_messages. + If there is no catch code, discard the cleanup function and run + the unwind-protect for buffer_error_messages. + + * error.cc (bind_global_error_variable): Avoid dereferencing + error_message_buffer if it is NULL. + * parse.y (evaluating_function_body): New global flag. * ov-usr-fcn.cc (octave_user_function::do_index_op): Protect and set it here. diff -r cbee5fbb696d -r fc5eac74640d src/error.cc --- a/src/error.cc Fri Jan 28 09:14:34 2000 +0000 +++ b/src/error.cc Fri Jan 28 10:13:26 2000 +0000 @@ -375,17 +375,22 @@ void bind_global_error_variable (void) { - *error_message_buffer << ends; + if (error_message_buffer) + { + *error_message_buffer << ends; - char *error_text = error_message_buffer->str (); + char *error_text = error_message_buffer->str (); - bind_builtin_constant ("__error_text__", error_text, true); + bind_builtin_constant ("__error_text__", error_text, true); - delete [] error_text; + delete [] error_text; + + delete error_message_buffer; - delete error_message_buffer; - - error_message_buffer = 0; + error_message_buffer = 0; + } + else + bind_builtin_constant ("__error_text__", "", true); } void diff -r cbee5fbb696d -r fc5eac74640d src/pt-except.cc --- a/src/pt-except.cc Fri Jan 28 09:14:34 2000 +0000 +++ b/src/pt-except.cc Fri Jan 28 10:13:26 2000 +0000 @@ -53,11 +53,16 @@ { tree_statement_list *list = static_cast (ptr); + unwind_protect::begin_frame ("do_catch_code"); + // Set up for letting the user print any messages from errors that // occurred in the body of the try_catch statement. + unwind_protect_bool (buffer_error_messages); buffer_error_messages = false; + bind_global_error_variable (); + unwind_protect::add (clear_global_error_variable, 0); // Similarly, if we have seen a return or break statement, allow all @@ -92,7 +97,7 @@ else unwind_protect::run (); - unwind_protect::run (); + unwind_protect::run_frame ("do_catch_code"); } void @@ -100,16 +105,14 @@ { unwind_protect::begin_frame ("tree_try_catch::eval"); - unwind_protect::add (do_catch_code, catch_code); - - bool old_buffer_error_messages = buffer_error_messages; - if (catch_code) { unwind_protect_bool (buffer_error_messages); buffer_error_messages = true; } + unwind_protect::add (do_catch_code, catch_code); + if (try_code) try_code->eval (); @@ -121,8 +124,12 @@ else { error_state = 0; - buffer_error_messages = old_buffer_error_messages; - unwind_protect::discard_frame ("tree_try_catch::eval"); + + // For clearing the do_catch_code cleanup function. + unwind_protect::discard (); + + // For restoring buffer_error_messages. + unwind_protect::run (); } }