comparison pyeval.cc @ 364:1470ed26917a

Use pyobject_unwrap_object when an existing PyObject is expected * pycall.cc (Fpycall): Use pyobject_unwrap_object when argument is an object. * pyeval.cc (Fpyeval): Use pyobject_unwrap_object on optional argument. Clean up imports no longer necessary. * pyeval.cc (Fpyeval): Likewise. * oct-py-util.cc, oct-py-util.h (pytave::get_builtins_module, pytave::get_object_from_python): Delete unused functions. Update copyright notice, file has been completely rewritten.
author Mike Miller <mtmiller@octave.org>
date Thu, 25 Aug 2016 12:11:02 -0700
parents 77ffcaaf8000
children 087e7bc3697f
comparison
equal deleted inserted replaced
363:445df7f96fbc 364:1470ed26917a
75 return retval; 75 return retval;
76 } 76 }
77 77
78 std::string code = args(0).string_value (); 78 std::string code = args(0).string_value ();
79 79
80 std::string id;
81
82 Py_Initialize (); 80 Py_Initialize ();
83 81
84 object main_module = import ("__main__"); 82 PyObject *local_namespace = 0;
85 object main_namespace = main_module.attr ("__dict__");
86 object local_namespace;
87 if (nargin > 1) 83 if (nargin > 1)
88 { 84 {
89 pytave::get_object_from_python (args(1), local_namespace); 85 local_namespace = pytave::pyobject_unwrap_object (args(1));
90 if (local_namespace.is_none ()) 86 if (! local_namespace)
91 error ("pyeval: NAMESPACE must be a string or a Python reference"); 87 error ("pyeval: NAMESPACE must be a valid Python reference");
92 } 88 }
93 else
94 local_namespace = main_namespace;
95 89
96 try 90 try
97 { 91 {
98 PyObject *obj = pytave::py_eval_string (code, main_namespace.ptr (), 92 PyObject *obj = pytave::py_eval_string (code, 0, local_namespace);
99 local_namespace.ptr ());
100 boost::python::object res { boost::python::handle<> (obj) }; 93 boost::python::object res { boost::python::handle<> (obj) };
101 94
102 if (nargout > 0 || ! res.is_none ()) 95 if (nargout > 0 || ! res.is_none ())
103 { 96 {
104 octave_value val; 97 octave_value val;