Mercurial > pytave
comparison pycall.cc @ 404:aef165ff92b0
Adopt pytave::python_object where objects are local or created and returned
* __py_struct_from_dict__.cc, exceptions.cc, oct-py-eval.cc, oct-py-types.cc,
pycall.cc: Use pytave::python_object in place of PyObject where objects are
created locally and destroyed or returned to the caller.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Fri, 28 Apr 2017 16:21:39 -0700 |
parents | 3644df6564bc |
children | 478d83448b0b |
comparison
equal
deleted
inserted
replaced
403:3644df6564bc | 404:aef165ff92b0 |
---|---|
32 | 32 |
33 #define PYTAVE_DO_DECLARE_SYMBOL | 33 #define PYTAVE_DO_DECLARE_SYMBOL |
34 #include "arrayobjectdefs.h" | 34 #include "arrayobjectdefs.h" |
35 #include "exceptions.h" | 35 #include "exceptions.h" |
36 #include "oct-py-eval.h" | 36 #include "oct-py-eval.h" |
37 #include "oct-py-object.h" | |
37 #include "oct-py-util.h" | 38 #include "oct-py-util.h" |
38 #include "octave_to_python.h" | 39 #include "octave_to_python.h" |
39 #include "python_to_octave.h" | 40 #include "python_to_octave.h" |
40 | 41 |
41 using namespace boost::python; | 42 using namespace boost::python; |
98 numeric::array::set_module_and_type ("numpy", "ndarray"); | 99 numeric::array::set_module_and_type ("numpy", "ndarray"); |
99 _import_array (); | 100 _import_array (); |
100 | 101 |
101 try | 102 try |
102 { | 103 { |
103 PyObject *callable = nullptr; | 104 pytave::python_object callable; |
104 if (args(0).is_string ()) | 105 if (args(0).is_string ()) |
105 { | 106 { |
106 callable = pytave::py_find_function (args(0).string_value ()); | 107 callable = pytave::py_find_function (args(0).string_value ()); |
107 if (! callable) | 108 if (! callable) |
108 error ("pycall: no such Python function or callable: %s", | 109 error ("pycall: no such Python function or callable: %s", |
116 } | 117 } |
117 | 118 |
118 octave_value_list arglist = args.slice (1, nargin - 1); | 119 octave_value_list arglist = args.slice (1, nargin - 1); |
119 PyObject *result = pytave::py_call_function (callable, arglist); | 120 PyObject *result = pytave::py_call_function (callable, arglist); |
120 object res = object (handle<PyObject> (result)); | 121 object res = object (handle<PyObject> (result)); |
121 Py_DECREF (callable); | |
122 | 122 |
123 // Ensure reasonable "ans" behaviour, consistent with Python's "_". | 123 // Ensure reasonable "ans" behaviour, consistent with Python's "_". |
124 if (nargout > 0 || ! res.is_none ()) | 124 if (nargout > 0 || ! res.is_none ()) |
125 { | 125 { |
126 octave_value val; | 126 octave_value val; |