Mercurial > pytave
diff pycall.cc @ 423:6b9de18b4bdd
Eliminate remaining custom exception handling in favor of Octave errors
* oct-py-error.cc, oct-py-error.h (pytave::error_python_exception): New function
to generate an Octave error from an active Python error condition, based on
pytave::fetch_exception_message.
* oct-py-eval.cc (pytave::py_call_function, pytave::py_run_string_safe): Use it.
* oct-py-types.cc (pytave::make_py_dict): Likewise.
* oct-py-util.cc (pytave::py_objstore): Likewise.
* pycall.cc (Fpycall): Remove exception handling logic.
* pyeval.cc (Fpyeval): Likewise.
* pyexec.cc (Fpyexec): Likewise.
* exceptions.cc, exceptions.h: Delete.
* Makefile.am (COMMON_SOURCE_FILES, PYTAVE_HEADER_FILES): Remove them.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 04 May 2017 21:15:07 -0700 |
parents | 8247f298fd16 |
children | 3af3665348a1 |
line wrap: on
line diff
--- a/pycall.cc Thu May 04 17:13:38 2017 -0700 +++ b/pycall.cc Thu May 04 21:15:07 2017 -0700 @@ -27,7 +27,6 @@ #include <Python.h> #include <octave/oct.h> -#include "exceptions.h" #include "oct-py-eval.h" #include "oct-py-init.h" #include "oct-py-object.h" @@ -89,35 +88,27 @@ pytave::py_init (); - try + pytave::python_object callable; + if (args(0).is_string ()) + { + callable = pytave::py_find_function (args(0).string_value ()); + if (! callable) + error ("pycall: no such Python function or callable: %s", + args(0).string_value ().c_str ()); + } + else { - pytave::python_object callable; - if (args(0).is_string ()) - { - callable = pytave::py_find_function (args(0).string_value ()); - if (! callable) - error ("pycall: no such Python function or callable: %s", - args(0).string_value ().c_str ()); - } - else - { - callable = pytave::pyobject_unwrap_object (args(0)); - if (! callable) - error("pycall: FUNC must be a valid Python reference"); - } + callable = pytave::pyobject_unwrap_object (args(0)); + if (! callable) + error("pycall: FUNC must be a valid Python reference"); + } - octave_value_list arglist = args.slice (1, nargin - 1); - pytave::python_object res = pytave::py_call_function (callable, arglist); + octave_value_list arglist = args.slice (1, nargin - 1); + pytave::python_object res = pytave::py_call_function (callable, arglist); - // Ensure reasonable "ans" behaviour, consistent with Python's "_". - if (nargout > 0 || ! res.is_none ()) - retval(0) = pytave::py_implicitly_convert_return_value (res); - } - catch (pytave::error_already_set const &) - { - std::string message = pytave::fetch_exception_message (); - error ("pycall: %s", message.c_str ()); - } + // Ensure reasonable "ans" behaviour, consistent with Python's "_". + if (nargout > 0 || ! res.is_none ()) + retval(0) = pytave::py_implicitly_convert_return_value (res); return retval; }