Mercurial > hg > octave-lojdl
changeset 6680:cd39d4a0b671
[project @ 2007-05-31 20:23:45 by jwe]
author | jwe |
---|---|
date | Thu, 31 May 2007 20:23:45 +0000 |
parents | a40b4060efff |
children | 0458599c50d7 |
files | liboctave/ChangeLog src/ChangeLog src/octave.cc src/toplev.cc |
diffstat | 4 files changed, 84 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2007-05-31 John W. Eaton <jwe@octave.org> + + * Array.cc (Array::get_size): Throw std::bad_alloc exception if + the computed size is too large for the size of Octave's index type. + 2007-05-23 John W. Eaton <jwe@octave.org> * oct-sparse.h: Don't surround included files with extern "C" { ... }.
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,17 @@ +2007-05-31 John W. Eaton <jwe@octave.org> + + * toplev.cc (main_loop): Improve bad_alloc error message. + + * octave.cc (execute_command_line_file, execute_eval_option_code): + Likewise. + 2007-05-31 Michael Goffioul <michael.goffioul@swing.be> + * toplev.cc (octave_atexit_functions): + Now std::list instead of std::stack. + (do_octave_atexit): Adapte to octave_atexit_functions as list. + (Fatexit): Allow second arg of false to remove element from list. + * DLD-FUNCTIONS/symrcm.cc: Use ! instead of "not". * sysdep.cc (same_file_internal) [OCTAVE_USE_WINDOWS_API]:
--- a/src/octave.cc +++ b/src/octave.cc @@ -375,7 +375,8 @@ } catch (std::bad_alloc) { - std::cerr << "error: memory exhausted -- eval failed\n"; + std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- eval failed" + << std::endl; } unwind_protect::run_frame ("execute_eval_option_code"); @@ -420,8 +421,8 @@ } catch (std::bad_alloc) { - std::cerr << "error: memory exhausted -- execution of " - << fname << " failed\n"; + std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- execution of " + << fname << " failed" << std::endl; } unwind_protect::run_frame ("execute_command_line_file");
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -275,7 +275,8 @@ { recover_from_exception (); std::cerr - << "error: memory exhausted -- trying to return to prompt\n"; + << "error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt" + << std::endl; } } while (retval == 0); @@ -602,7 +603,7 @@ // FIXME -- this should really be static, but that causes // problems on some systems. -std::stack<std::string> octave_atexit_functions; +std::list<std::string> octave_atexit_functions; void do_octave_atexit (void) @@ -611,9 +612,9 @@ while (! octave_atexit_functions.empty ()) { - std::string fcn = octave_atexit_functions.top (); + std::string fcn = octave_atexit_functions.front (); - octave_atexit_functions.pop (); + octave_atexit_functions.pop_front (); reset_error_handler (); @@ -658,7 +659,7 @@ } } -DEFUN (atexit, args, , +DEFUN (atexit, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ Register a function to be called when Octave exits. For example,\n\ @@ -674,20 +675,74 @@ \n\ @noindent\n\ will print the message \"Bye bye\" when Octave exits.\n\ +\n\ +@deftypefnx {Built-in Function} {} atexit (@var{fcn}, @var{flag})\n\ +Register or unregister a function to be called when Octave exits,\n\ +depending on @var{flag}. If @var{flag} is true, the function is\n\ +registered, if @var{flag} is false, it is unregistered. For example,\n\ +after registering the function @code{bye_bye} as above,\n\ +\n\ +@example\n\ +atexit (\"bye_bye\", false);\n\ +@end example\n\ +\n\ +@noindent\n\ +will remove the function from the list and Octave will not call\n\ +the function @code{bye_by} when it exits.\n\ +\n\ +Note that @code{atexit} only removes the first occurence of a function\n\ +from the list, so if a function was placed in the list multiple\n\ +times with @code{atexit}, it must also be removed from the list\n\ +multiple times.\n\ @end deftypefn") { octave_value_list retval; int nargin = args.length (); - if (nargin == 1) + if (nargin == 1 || nargin == 2) { std::string arg = args(0).string_value (); if (! error_state) - octave_atexit_functions.push (arg); + { + bool add_mode = true; + + if (nargin == 2) + { + add_mode = args(1).bool_value (); + + if (error_state) + error ("atexit: second argument must be a logical value"); + } + + if (! error_state) + { + if (add_mode) + octave_atexit_functions.push_front (arg); + else + { + bool found = false; + std::list<std::string>::iterator it; + + for (std::list<std::string>::iterator p = octave_atexit_functions.begin (); + p != octave_atexit_functions.end (); p++) + { + if (*p == arg) + { + octave_atexit_functions.erase (p); + found = true; + break; + } + } + + if (nargout > 0) + retval(0) = found; + } + } + } else - error ("atexit: argument must be a string"); + error ("atexit: argument must be a string"); } else print_usage ();