Mercurial > pytave
comparison 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 |
comparison
equal
deleted
inserted
replaced
422:8247f298fd16 | 423:6b9de18b4bdd |
---|---|
25 #endif | 25 #endif |
26 | 26 |
27 #include <Python.h> | 27 #include <Python.h> |
28 #include <octave/oct.h> | 28 #include <octave/oct.h> |
29 | 29 |
30 #include "exceptions.h" | |
31 #include "oct-py-eval.h" | 30 #include "oct-py-eval.h" |
32 #include "oct-py-init.h" | 31 #include "oct-py-init.h" |
33 #include "oct-py-object.h" | 32 #include "oct-py-object.h" |
34 #include "oct-py-types.h" | 33 #include "oct-py-types.h" |
35 #include "oct-py-util.h" | 34 #include "oct-py-util.h" |
87 && args(0).class_name () == "pyobject"))) | 86 && args(0).class_name () == "pyobject"))) |
88 error ("pycall: FUNC must be a string or a Python reference"); | 87 error ("pycall: FUNC must be a string or a Python reference"); |
89 | 88 |
90 pytave::py_init (); | 89 pytave::py_init (); |
91 | 90 |
92 try | 91 pytave::python_object callable; |
92 if (args(0).is_string ()) | |
93 { | 93 { |
94 pytave::python_object callable; | 94 callable = pytave::py_find_function (args(0).string_value ()); |
95 if (args(0).is_string ()) | 95 if (! callable) |
96 { | 96 error ("pycall: no such Python function or callable: %s", |
97 callable = pytave::py_find_function (args(0).string_value ()); | 97 args(0).string_value ().c_str ()); |
98 if (! callable) | |
99 error ("pycall: no such Python function or callable: %s", | |
100 args(0).string_value ().c_str ()); | |
101 } | |
102 else | |
103 { | |
104 callable = pytave::pyobject_unwrap_object (args(0)); | |
105 if (! callable) | |
106 error("pycall: FUNC must be a valid Python reference"); | |
107 } | |
108 | |
109 octave_value_list arglist = args.slice (1, nargin - 1); | |
110 pytave::python_object res = pytave::py_call_function (callable, arglist); | |
111 | |
112 // Ensure reasonable "ans" behaviour, consistent with Python's "_". | |
113 if (nargout > 0 || ! res.is_none ()) | |
114 retval(0) = pytave::py_implicitly_convert_return_value (res); | |
115 } | 98 } |
116 catch (pytave::error_already_set const &) | 99 else |
117 { | 100 { |
118 std::string message = pytave::fetch_exception_message (); | 101 callable = pytave::pyobject_unwrap_object (args(0)); |
119 error ("pycall: %s", message.c_str ()); | 102 if (! callable) |
103 error("pycall: FUNC must be a valid Python reference"); | |
120 } | 104 } |
105 | |
106 octave_value_list arglist = args.slice (1, nargin - 1); | |
107 pytave::python_object res = pytave::py_call_function (callable, arglist); | |
108 | |
109 // Ensure reasonable "ans" behaviour, consistent with Python's "_". | |
110 if (nargout > 0 || ! res.is_none ()) | |
111 retval(0) = pytave::py_implicitly_convert_return_value (res); | |
121 | 112 |
122 return retval; | 113 return retval; |
123 } | 114 } |
124 | 115 |
125 /* | 116 /* |