diff pycall.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 4c2b748eaea0
children 087e7bc3697f
line wrap: on
line diff
--- a/pycall.cc	Thu Aug 25 11:39:45 2016 -0700
+++ b/pycall.cc	Thu Aug 25 12:11:02 2016 -0700
@@ -103,22 +103,19 @@
     {
       PyObject *callable = 0;
       if (args(0).is_string ())
-        callable = pytave::py_find_function (args(0).string_value ());
+        {
+          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
         {
-          // FIXME: callable = get existing pyobject reference (args(0))
-          boost::python::object obj;
-          pytave::get_object_from_python (args(0), obj);
-          if (obj.is_none ())
-            error("pycall: FUNC must be a string or a Python reference");
-          callable = obj.ptr ();
-          Py_INCREF (callable);
+          callable = pytave::pyobject_unwrap_object (args(0));
+          if (! callable)
+            error("pycall: FUNC must be a valid Python reference");
         }
 
-      if (! callable)
-        error ("pycall: no such Python function or callable: %s",
-               args(0).string_value ().c_str ());
-
       octave_value_list arglist = args.slice (1, nargin - 1);
       PyObject *result = pytave::py_call_function (callable, arglist);
       object res = object (handle<PyObject> (result));