Mercurial > pytave
changeset 93:737d78f8495c
don't crash on out-of-memory exceptions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 19 Nov 2009 14:46:17 +0100 |
parents | 758d1a140c61 |
children | c84200cc395a 9ddccdf6d318 |
files | ChangeLog pytave.cc |
diffstat | 2 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sun Sep 27 11:13:22 2009 +0200 +++ b/ChangeLog Thu Nov 19 14:46:17 2009 +0100 @@ -1,3 +1,8 @@ +2009-11-19 Jaroslav Hajek <highegg@gmail.com> + + * pytave.cc (func_eval): Catch & rethrow std::bad_alloc. + (str_eval): Likewise. + 2009-09-27 David Grundberg <individ@acc.umu.se> * configure.ac: Fix typo.
--- a/pytave.cc Sun Sep 27 11:13:22 2009 +0200 +++ b/pytave.cc Thu Nov 19 14:46:17 2009 +0100 @@ -175,8 +175,13 @@ locale_t old_locale = uselocale(c_locale); #endif + bool bad_alloc_state = false; Py_BEGIN_ALLOW_THREADS - retval = feval(funcname, octave_args, (nargout >= 0) ? nargout : 0); + try { + retval = feval(funcname, octave_args, (nargout >= 0) ? nargout : 0); + } catch (bad_alloc) { + bad_alloc_state = true; + } Py_END_ALLOW_THREADS #ifdef HAVE_USELOCALE @@ -184,7 +189,10 @@ uselocale(old_locale); #endif - if (error_state != 0) { + if (bad_alloc_state) + throw bad_alloc (); // Translated to MemoryError by boost::python + + else if (error_state != 0) { // error_state values: // -2 error without traceback // -1 traceback @@ -228,9 +236,14 @@ locale_t old_locale = uselocale(c_locale); #endif + bool bad_alloc_state = false; Py_BEGIN_ALLOW_THREADS - retval = eval_string(code, silent, parse_status, - (nargout >= 0) ? nargout : 0); + try { + retval = eval_string(code, silent, parse_status, + (nargout >= 0) ? nargout : 0); + } catch (bad_alloc) { + bad_alloc_state = true; + } Py_END_ALLOW_THREADS #ifdef HAVE_USELOCALE @@ -238,6 +251,9 @@ uselocale(old_locale); #endif + if (bad_alloc_state) + throw bad_alloc (); // Translated to MemoryError by boost::python + if (parse_status != 0 || error_state != 0) { // error_state values: // -2 error without traceback