Mercurial > pytave
comparison pyeval.cc @ 411:3613ffbd52b2
Overhaul implicit conversion of arguments and return values
* oct-py-types.cc, oct-py-types.h (pytave::py_implicitly_convert_argument,
pytave::py_implicitly_convert_return_value): New functions.
* __py_struct_from_dict__.cc, oct-py-eval.cc, pycall.cc, pyeval.cc, pyexec.cc:
Use them instead of legacy conversion functions. Add necessary #includes,
remove #includes of legacy header files.
* @pyobject/subsasgn.m, @pyobject/subsref.m: Change %!tests that depend on
NumPy implicit conversion into %!xtests.
* octave_to_python.cc, octave_to_python.h, python_to_octave.cc,
python_to_octave.h: Delete, no longer used.
* Makefile.am (COMMON_SOURCE_FILES, PYTAVE_HEADER_FILES): Remove the files.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Wed, 03 May 2017 16:30:45 -0700 |
parents | 95c6ad0be828 |
children | 9bf8ba050122 |
comparison
equal
deleted
inserted
replaced
410:95c6ad0be828 | 411:3613ffbd52b2 |
---|---|
31 #include <octave/parse.h> | 31 #include <octave/parse.h> |
32 | 32 |
33 #include "exceptions.h" | 33 #include "exceptions.h" |
34 #include "oct-py-eval.h" | 34 #include "oct-py-eval.h" |
35 #include "oct-py-init.h" | 35 #include "oct-py-init.h" |
36 #include "oct-py-object.h" | |
37 #include "oct-py-types.h" | |
36 #include "oct-py-util.h" | 38 #include "oct-py-util.h" |
37 #include "python_to_octave.h" | |
38 | 39 |
39 DEFUN_DLD (pyeval, args, nargout, | 40 DEFUN_DLD (pyeval, args, nargout, |
40 "-*- texinfo -*-\n\ | 41 "-*- texinfo -*-\n\ |
41 @deftypefn {} {} pyeval (@var{expr})\n\ | 42 @deftypefn {} {} pyeval (@var{expr})\n\ |
42 @deftypefnx {} {} pyeval (@var{expr}, @var{localns})\n\ | 43 @deftypefnx {} {} pyeval (@var{expr}, @var{localns})\n\ |
83 error ("pyeval: NAMESPACE must be a valid Python reference"); | 84 error ("pyeval: NAMESPACE must be a valid Python reference"); |
84 } | 85 } |
85 | 86 |
86 try | 87 try |
87 { | 88 { |
88 PyObject *obj = pytave::py_eval_string (code, 0, local_namespace); | 89 pytave::python_object res = pytave::py_eval_string (code, 0, local_namespace); |
89 boost::python::object res { boost::python::handle<> (obj) }; | |
90 | 90 |
91 if (nargout > 0 || ! res.is_none ()) | 91 if (nargout > 0 || ! res.is_none ()) |
92 { | 92 retval(0) = pytave::py_implicitly_convert_return_value (res); |
93 octave_value val; | |
94 pytave::pyobj_to_octvalue (val, res); | |
95 retval(0) = val; | |
96 } | |
97 } | 93 } |
98 catch (pytave::object_convert_exception const &) | 94 catch (pytave::object_convert_exception const &) |
99 { | 95 { |
100 error ("pyexec: error in return value type conversion"); | 96 error ("pyexec: error in return value type conversion"); |
101 } | 97 } |